click to inactive file list won't change selection
authorLukas Hrazky <lukkash@email.cz>
Sat, 14 Aug 2010 10:30:45 +0000 (12:30 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sat, 14 Aug 2010 10:30:45 +0000 (12:30 +0200)
Plus a slight revamp of the pane switching. Far from ideal though.

Signed-off-by: Lukas Hrazky <lukkash@email.cz>

src/case.cpp
src/case.h
src/filelist.cpp
src/filelist.h
src/pane.cpp
src/pane.h

index bac6bac..721bdaf 100644 (file)
@@ -67,8 +67,8 @@ Case::Case(QWidget *parent) :
 
     layout->addWidget(fileOperator);
 
-    connect(this, SIGNAL(activePaneSwitched()), leftPane, SLOT(toggleActive()));
-    connect(this, SIGNAL(activePaneSwitched()), rightPane, SLOT(toggleActive()));
+    connect(leftPane, SIGNAL(switchPanes()), this, SLOT(switchActivePane()));
+    connect(rightPane, SIGNAL(switchPanes()), this, SLOT(switchActivePane()));
 
     connect(cloneBtn, SIGNAL(pressed()), this, SLOT(clonePane()));
     connect(swapBtn, SIGNAL(pressed()), this, SLOT(swapPanes()));
@@ -89,7 +89,8 @@ void Case::switchActivePane() {
     moveBtn->swapIcon();
     delBtn->swapIcon();
 
-    emit activePaneSwitched();
+    activePane->toggleActive();
+    inactivePane->toggleActive();
 }
 
 
index 7e55fd0..2a95186 100644 (file)
@@ -29,9 +29,6 @@
 class Case : public QMainWindow {
     Q_OBJECT
 
-signals:
-    void activePaneSwitched();
-
 public:
     Case(QWidget *parent = 0);
 
index 9b52332..a4927b8 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <QProcess>
 #include <QUrl>
+#include <QEvent>
 
 #include <hildon-mime.h>
 #include <dbus/dbus.h>
@@ -28,7 +29,8 @@
 
 FileList::FileList(QWidget *parent) :
     QListView(parent),
-    fileSystemModel(new QFileSystemModel)
+    fileSystemModel(new QFileSystemModel),
+    dontSelect(0)
 {
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
@@ -85,14 +87,40 @@ void FileList::toggleShowHiddenFiles() {
 }
 
 
+void FileList::preventNextSelection() {
+    dontSelect = 2;
+}
+
+
+void FileList::mousePressEvent(QMouseEvent *event) {
+    emit mousePressed();
+    QListView::mousePressEvent(event);
+}
+
+
+QItemSelectionModel::SelectionFlags FileList::selectionCommand(const QModelIndex &index, const QEvent *event) const {
+    if (dontSelect && event && event->type() == QEvent::MouseButtonPress) {
+        --dontSelect;
+    }
+
+    if (dontSelect && event &&
+        (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseMove))
+    {
+        return QItemSelectionModel::NoUpdate;
+    }
+
+    return QListView::selectionCommand(index, event);
+}
+
+
 void FileList::activateItem(QModelIndex index) {
     const QFileInfo &file = fileSystemModel->fileInfo(index);
 
     if(file.isDir()) {
         changePath(file.absoluteFilePath());
-        // hack: we reset it to MultiSelection again in the mousePressEvent
-        // without this, the item under the cursor gets selected right after changing the directory
-        setSelectionMode(QAbstractItemView::NoSelection);
+        // hack: this will prevent selecting the item under the cursor on the second click
+        // of the doubleclick that changed the directory
+        dontSelect = 1;
     } else if(file.isExecutable()) {
         QProcess::startDetached(file.absoluteFilePath());
     } else {
@@ -106,11 +134,3 @@ void FileList::activateItem(QModelIndex index) {
         //QDesktopServices::openUrl(QUrl::fromLocalFile(file.absoluteFilePath()));
     }
 }
-
-
-void FileList::mousePressEvent(QMouseEvent *event) {
-    emit mousePressed();
-    QListView::mousePressEvent(event);
-    // need to reset the selection mode in case it was set to NoSelection in activateItem(...)
-    setSelectionMode(QAbstractItemView::MultiSelection);
-}
index dd6fda9..ec51cbc 100644 (file)
@@ -40,11 +40,14 @@ public slots:
     bool changePath(QString path);
     bool goUp();
     void toggleShowHiddenFiles();
+    void preventNextSelection();
 
 protected:
     QFileSystemModel *fileSystemModel;
+    mutable int dontSelect;
 
     void mousePressEvent(QMouseEvent *event);
+    virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *event = 0) const;
 
 private slots:
     void activateItem(QModelIndex index);
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();
-}
index a565b8d..07c03bf 100644 (file)
 class Pane : public QWidget {
     Q_OBJECT
 
+signals:
+    void switchPanes();
+
 public:
+    bool active;
+
     explicit Pane(QWidget *theCase, QWidget *parent = 0);
 
     const QString path() const;
@@ -39,18 +44,16 @@ public slots:
     bool changePath(QString path);
     void toggleActive();
     void toggleShowHiddenFiles();
+    void fileListMouseHackaround();
 
 protected:
     void paintEvent(QPaintEvent *);
 
-    void activationConnect();
-    void activationDisconnect();
+    bool eventFilter(QObject *object, QEvent *event);
 
 private:
     QWidget *theCase;
 
-    bool active;
-
     AddressBar *location;
     Button *up;
     FileList *fileList;