Debian Codegraph @

src/filebrowser.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "filebrowser.h"
19 #include <QFileSystemModel>
20 #include <QTreeView>
21 #include <QVBoxLayout>
22 #include <QHeaderView>
23 #include <QApplication>
24 #if QT_VERSION >= 0x050000
25 #include <QStandardPaths>
26 #else
27 #include <QDesktopServices>
28 #endif
29
30
31 struct FileBrowserPrivate
32 {
33 QVBoxLayout *layout;
34 QTreeView *filetree;
35 QFileSystemModel *model;
36 };
37
38 FileBrowser::FileBrowser(QWidget *parent) :
39 QWidget(parent)
40 , p( new FileBrowserPrivate )
41 {
42 p->layout = new QVBoxLayout;
43
44 // ToDo: maybe we add some buttons and links here
45
46 p->model = new QFileSystemModel;
47 p->model->setRootPath(QDir::currentPath());
48 p->filetree = new QTreeView(this);
49 p->filetree->setModel(p->model);
50 p->filetree->setDragEnabled(true);
51 p->filetree->setSelectionMode(QAbstractItemView::ContiguousSelection);
52 p->filetree->header()->resizeSection(0,400);
53
54 #if QT_VERSION >= 0x050000
55 p->filetree->setRootIndex(p->model->index(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).at(0)));
56 #else
57 p->filetree->setRootIndex(p->model->index(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)));
58 #endif
59
60
61 p->filetree->setAttribute(Qt::WA_MacShowFocusRect, false);
62 p->layout->addWidget(p->filetree);
63
64 setLayout(p->layout);
65 setAttribute(Qt::WA_MacShowFocusRect, false);
66 }
67
68 void FileBrowser::setRootPath(QString path){
69
70 p->filetree->setRootIndex(p->model->setRootPath(path));
71
72 }