click to inactive file list won't change selection
[case] / src / pane.cpp
index 67039c0..4b192a3 100644 (file)
 #include <QUrl>
 #include <QProcess>
 #include <QPainter>
+#include <QEvent>
 
 
 Pane::Pane(QWidget *theCase, QWidget *parent) :
     QWidget(parent),
-    theCase(theCase),
     active(false),
+    theCase(theCase),
     location(new AddressBar),
     up(new Button("go_up", 0, 70, 60)),
     fileList(new FileList)
@@ -54,7 +55,21 @@ Pane::Pane(QWidget *theCase, QWidget *parent) :
     connect(up, SIGNAL(pressed()), fileList, SLOT(goUp()));
     connect(fileList, SIGNAL(pathChanged(QString)), location, SLOT(setText(QString)));
 
-    activationConnect();
+    location->installEventFilter(this);
+    up->installEventFilter(this);
+    // doesn't work in QT 4.6.2 - mouse events wont get through the kinetic scroller
+    //fileList->installEventFilter(this);
+    connect(fileList, SIGNAL(mousePressed()), this, SLOT(fileListMouseHackaround()));
+}
+
+
+const QString Pane::path() const {
+    return fileList->path();
+}
+
+
+const QFileInfoList Pane::selection() const {
+    return fileList->selection();
 }
 
 
@@ -71,23 +86,17 @@ void Pane::paintEvent(QPaintEvent *) {
 }
 
 
-void Pane::activationConnect() {
-    connect(up, SIGNAL(clicked()), theCase, SLOT(switchActivePane()));
-    connect(location, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
-    connect(fileList, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
-}
-
-
-void Pane::activationDisconnect() {
-    disconnect(up, SIGNAL(clicked()), theCase, SLOT(switchActivePane()));
-    disconnect(location, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
-    disconnect(fileList, SIGNAL(mousePressed()), theCase, SLOT(switchActivePane()));
+bool Pane::eventFilter(QObject *object, QEvent *event) {
+    if (!active && event->type() == QEvent::MouseButtonPress) {
+        emit switchPanes();
+        if (object == fileList) return true;
+    }
+    return false;
 }
 
 
 void Pane::toggleActive() {
     active = !active;
-    if (active) activationDisconnect(); else activationConnect();
     update();
 }
 
@@ -97,8 +106,11 @@ void Pane::toggleShowHiddenFiles() {
 }
 
 
-const QFileInfoList Pane::selection() const {
-    return fileList->selection();
+void Pane::fileListMouseHackaround() {
+    if (!active) {
+        fileList->preventNextSelection();
+        emit switchPanes();
+    }
 }
 
 
@@ -106,8 +118,3 @@ bool Pane::changePath(QString path) {
     location->setText(path);
     return fileList->changePath(path);
 }
-
-
-const QString Pane::path() const {
-    return fileList->path();
-}