1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "browsedirtree.h"
23 #include "ui_browsedirtreefrm.h"
26 BrowseDirtree::BrowseDirtree(QWidget
*parent
, const QString
&caption
) : QDialog(parent
)
30 ui
.tree
->setModel(&model
);
31 model
.setReadOnly(true);
32 model
.setSorting(QDir::Name
| QDir::DirsFirst
| QDir::IgnoreCase
);
35 setWindowTitle(caption
);
37 // disable size / date / type columns
38 ui
.tree
->setColumnHidden(1, true);
39 ui
.tree
->setColumnHidden(2, true);
40 ui
.tree
->setColumnHidden(3, true);
41 ui
.tree
->setAlternatingRowColors(true);
42 ui
.tree
->setLayoutDirection(Qt::LeftToRight
);
46 void BrowseDirtree::setDir(const QDir
&dir
)
48 qDebug() << "[BrowseDirtree] setDir()" << model
.index(dir
.absolutePath());
50 // do not try to hilight directory if it's not valid.
51 if(!dir
.exists()) return;
52 // hilight the set directory if it's valid
53 if(model
.index(dir
.absolutePath()).isValid()) {
54 QModelIndex p
= model
.index(dir
.absolutePath());
55 ui
.tree
->setCurrentIndex(p
);
58 ui
.tree
->resizeColumnToContents(0);
62 void BrowseDirtree::setDir(const QString
&dir
)
68 void BrowseDirtree::setRoot(const QString
&dir
)
70 ui
.tree
->setRootIndex(model
.index(dir
));
73 void BrowseDirtree::setFilter(const QDir::Filters
&filters
)
75 model
.setFilter(filters
);
79 void BrowseDirtree::accept()
82 path
= model
.filePath(ui
.tree
->currentIndex());
85 emit
itemChanged(QDir::toNativeSeparators(path
));
86 setResult(QDialog::Accepted
);
89 QString
BrowseDirtree::getSelected()
92 path
= model
.filePath(ui
.tree
->currentIndex());
93 return QDir::toNativeSeparators(path
);