Ctrl-H shortcut to toggle hidden files' visibility
[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
29
30 Pane::Pane(QWidget *theCase, QWidget *parent) :
31     QWidget(parent),
32     theCase(theCase),
33     active(false),
34     location(new AddressBar),
35     up(new Button("^", 0, 70, 60)),
36     fileList(new FileList)
37 {
38     QVBoxLayout *layout = new QVBoxLayout;
39     layout->setContentsMargins(3, 3, 3, 3);
40     layout->setSpacing(0);
41     setLayout(layout);
42
43     QHBoxLayout *topLine = new QHBoxLayout;
44
45     location->setText(fileList->path());
46     layout->setSpacing(0);
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     activationConnect();
58 }
59
60
61 void Pane::paintEvent(QPaintEvent *) {
62     if (active) {
63         QPainter painter(this);
64         painter.setPen(palette().color(QPalette::Highlight));
65         QRect g = this->geometry();
66         g.moveTo(1, 1);
67         g.setWidth(g.width() - 3);
68         g.setHeight(g.height() - 3);
69         painter.drawRect(g);
70     }
71 }
72
73
74 void Pane::activationConnect() {
75     connect(up, SIGNAL(clicked()), theCase, SLOT(switchActivePane()));
76     connect(location, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
77     connect(fileList, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
78 }
79
80
81 void Pane::activationDisconnect() {
82     disconnect(up, SIGNAL(clicked()), theCase, SLOT(switchActivePane()));
83     disconnect(location, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
84     disconnect(fileList, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
85 }
86
87
88 void Pane::toggleActive() {
89     active = !active;
90     if (active) activationDisconnect(); else activationConnect();
91     update();
92 }
93
94
95 void Pane::toggleShowHiddenFiles() {
96     fileList->toggleShowHiddenFiles();
97 }
98
99
100 const QFileInfoList Pane::selection() const {
101     return fileList->selection();
102 }
103
104
105 bool Pane::changePath(QString path) {
106     location->setText(path);
107     return fileList->changePath(path);
108 }
109
110
111 const QString Pane::path() const {
112     return fileList->path();
113 }