From: Lukas Hrazky Date: Sat, 14 Aug 2010 10:30:45 +0000 (+0200) Subject: click to inactive file list won't change selection X-Git-Tag: v0.3.0~9 X-Git-Url: https://vcs.maemo.org/git/?p=case;a=commitdiff_plain;h=17b7f9ef9141bfb49bc224cbbc7b3eece045784d click to inactive file list won't change selection Plus a slight revamp of the pane switching. Far from ideal though. Signed-off-by: Lukas Hrazky --- diff --git a/src/case.cpp b/src/case.cpp index bac6bac..721bdaf 100644 --- a/src/case.cpp +++ b/src/case.cpp @@ -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(); } diff --git a/src/case.h b/src/case.h index 7e55fd0..2a95186 100644 --- a/src/case.h +++ b/src/case.h @@ -29,9 +29,6 @@ class Case : public QMainWindow { Q_OBJECT -signals: - void activePaneSwitched(); - public: Case(QWidget *parent = 0); diff --git a/src/filelist.cpp b/src/filelist.cpp index 9b52332..a4927b8 100644 --- a/src/filelist.cpp +++ b/src/filelist.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -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); -} diff --git a/src/filelist.h b/src/filelist.h index dd6fda9..ec51cbc 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -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); diff --git a/src/pane.cpp b/src/pane.cpp index 67039c0..4b192a3 100644 --- a/src/pane.cpp +++ b/src/pane.cpp @@ -25,12 +25,13 @@ #include #include #include +#include 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(); -} diff --git a/src/pane.h b/src/pane.h index a565b8d..07c03bf 100644 --- a/src/pane.h +++ b/src/pane.h @@ -29,7 +29,12 @@ 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;