use alternating row colors in list views.
[Rockbox.git] / rbutil / rbutilqt / browsedirtree.cpp
blob43232cf355e60b6c951d92a9dbacd62f5b704ee2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id: installrb.cpp 13990 2007-07-25 22:26:10Z Dominik Wenger $
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 ****************************************************************************/
20 #include <QtGui>
22 #include "browsedirtree.h"
23 #include "ui_browsedirtreefrm.h"
26 BrowseDirtree::BrowseDirtree(QWidget *parent) : QDialog(parent)
28 ui.setupUi(this);
29 this->setModal(true);
30 ui.tree->setModel(&model);
31 model.setReadOnly(true);
32 // disable size / date / type columns
33 ui.tree->setColumnHidden(1, true);
34 ui.tree->setColumnHidden(2, true);
35 ui.tree->setColumnHidden(3, true);
36 ui.tree->setAlternatingRowColors(true);
40 void BrowseDirtree::setDir(QDir &dir)
42 qDebug() << "BrowseDirtree::setDir()" << model.index(dir.absolutePath());
44 // do not try to hilight directory if it's not valid.
45 if(!dir.exists()) return;
46 // hilight the set directory if it's valid
47 if(model.index(dir.absolutePath()).isValid()) {
48 QModelIndex p = model.index(dir.absolutePath());
49 ui.tree->setCurrentIndex(p);
50 ui.tree->scrollTo(p);
51 ui.tree->resizeColumnToContents(0);
56 void BrowseDirtree::setFilter(QDir::Filters filters)
58 model.setFilter(filters);
62 void BrowseDirtree::accept()
64 QString path;
65 path = model.filePath(ui.tree->currentIndex());
67 this->close();
68 emit itemChanged(QDir::toNativeSeparators(path));
69 setResult(QDialog::Accepted);
72 QString BrowseDirtree::getSelected()
74 QString path;
75 path = model.filePath(ui.tree->currentIndex());
76 return QDir::toNativeSeparators(path);