click to inactive file list won't change selection
[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(3, 3, 3, 3);
41     layout->setSpacing(0);
42     setLayout(layout);
43
44     QHBoxLayout *topLine = new QHBoxLayout;
45
46     location->setText(fileList->path());
47     layout->setSpacing(0);
48
49     topLine->addWidget(location);
50     topLine->addWidget(up);
51     layout->addLayout(topLine);
52     layout->addWidget(fileList);
53
54     connect(location, SIGNAL(pathEntered(QString)), fileList, SLOT(changePath(QString)));
55     connect(up, SIGNAL(pressed()), fileList, SLOT(goUp()));
56     connect(fileList, SIGNAL(pathChanged(QString)), location, SLOT(setText(QString)));
57
58     location->installEventFilter(this);
59     up->installEventFilter(this);
60     // doesn't work in QT 4.6.2 - mouse events wont get through the kinetic scroller
61     //fileList->installEventFilter(this);
62     connect(fileList, SIGNAL(mousePressed()), this, SLOT(fileListMouseHackaround()));
63 }
64
65
66 const QString Pane::path() const {
67     return fileList->path();
68 }
69
70
71 const QFileInfoList Pane::selection() const {
72     return fileList->selection();
73 }
74
75
76 void Pane::paintEvent(QPaintEvent *) {
77     if (active) {
78         QPainter painter(this);
79         painter.setPen(palette().color(QPalette::Highlight));
80         QRect g = this->geometry();
81         g.moveTo(1, 1);
82         g.setWidth(g.width() - 3);
83         g.setHeight(g.height() - 3);
84         painter.drawRect(g);
85     }
86 }
87
88
89 bool Pane::eventFilter(QObject *object, QEvent *event) {
90     if (!active && event->type() == QEvent::MouseButtonPress) {
91         emit switchPanes();
92         if (object == fileList) return true;
93     }
94     return false;
95 }
96
97
98 void Pane::toggleActive() {
99     active = !active;
100     update();
101 }
102
103
104 void Pane::toggleShowHiddenFiles() {
105     fileList->toggleShowHiddenFiles();
106 }
107
108
109 void Pane::fileListMouseHackaround() {
110     if (!active) {
111         fileList->preventNextSelection();
112         emit switchPanes();
113     }
114 }
115
116
117 bool Pane::changePath(QString path) {
118     location->setText(path);
119     return fileList->changePath(path);
120 }