34bdd6e9a49c727e37d3268381c6525d2d0c17e0
[case] / src / pane.cpp
1 // case - file manager for N900
2 // Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
3 // 
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 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 General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 #include "pane.h"
19
20 #include <QHeaderView>
21 #include <QVBoxLayout>
22 #include <QMessageBox>
23 #include <QInputDialog>
24 #include <QDesktopServices>
25 #include <QUrl>
26 #include <QProcess>
27 #include <QPainter>
28 #include <QEvent>
29
30
31 Pane::Pane(QWidget *theCase, QWidget *parent) :
32     QWidget(parent),
33     active(false),
34     theCase(theCase),
35     location(new AddressBar),
36     up(new Button("go_up", 0, 70, 60)),
37     fileList(new FileList)
38 {
39     QVBoxLayout *layout = new QVBoxLayout;
40     layout->setContentsMargins(2, 1, 2, 2);
41     layout->setSpacing(0);
42     setLayout(layout);
43
44     QHBoxLayout *topLine = new QHBoxLayout;
45
46     location->setText(fileList->path());
47
48     topLine->addWidget(location);
49     topLine->addWidget(up);
50     layout->addLayout(topLine);
51     layout->addWidget(fileList);
52
53     connect(location, SIGNAL(pathEntered(QString)), fileList, SLOT(changePath(QString)));
54     connect(up, SIGNAL(pressed()), fileList, SLOT(goUp()));
55     connect(fileList, SIGNAL(pathChanged(QString)), location, SLOT(setText(QString)));
56
57     location->installEventFilter(this);
58     up->installEventFilter(this);
59     // doesn't work in QT 4.6.2 - mouse events wont get through the kinetic scroller
60     //fileList->installEventFilter(this);
61     connect(fileList, SIGNAL(mousePressed()), this, SLOT(fileListMouseHackaround()));
62 }
63
64
65 const QString Pane::path() const {
66     return fileList->path();
67 }
68
69
70 const QFileInfoList Pane::selection() const {
71     return fileList->selection();
72 }
73
74
75 void Pane::paintEvent(QPaintEvent *) {
76     if (active) {
77         QPainter painter(this);
78         painter.setPen(palette().highlight().color());
79         QRect g = this->geometry();
80         g.moveTo(0, 0);
81         g.adjust(0, 0, -1, -1);
82         painter.drawRoundedRect(g, 3, 3);
83     }
84 }
85
86
87 bool Pane::eventFilter(QObject *object, QEvent *event) {
88     if (!active && event->type() == QEvent::MouseButtonPress) {
89         emit switchPanes();
90         if (object == fileList) return true;
91     }
92     return false;
93 }
94
95
96 void Pane::toggleActive() {
97     active = !active;
98     update();
99 }
100
101
102 void Pane::toggleShowHiddenFiles() {
103     fileList->toggleShowHiddenFiles();
104 }
105
106
107 void Pane::fileListMouseHackaround() {
108     if (!active) {
109         fileList->preventNextSelection();
110         emit switchPanes();
111     }
112 }
113
114
115 bool Pane::changePath(QString path) {
116     location->setText(path);
117     return fileList->changePath(path);
118 }