Plus a slight revamp of the pane switching. Far from ideal though.
Signed-off-by: Lukas Hrazky <lukkash@email.cz>
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()));
moveBtn->swapIcon();
delBtn->swapIcon();
- emit activePaneSwitched();
+ activePane->toggleActive();
+ inactivePane->toggleActive();
}
class Case : public QMainWindow {
Q_OBJECT
-signals:
- void activePaneSwitched();
-
public:
Case(QWidget *parent = 0);
#include <QProcess>
#include <QUrl>
+#include <QEvent>
#include <hildon-mime.h>
#include <dbus/dbus.h>
FileList::FileList(QWidget *parent) :
QListView(parent),
- fileSystemModel(new QFileSystemModel)
+ fileSystemModel(new QFileSystemModel),
+ dontSelect(0)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
+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 {
//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);
-}
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);
#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)
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();
}
}
-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();
}
}
-const QFileInfoList Pane::selection() const {
- return fileList->selection();
+void Pane::fileListMouseHackaround() {
+ if (!active) {
+ fileList->preventNextSelection();
+ emit switchPanes();
+ }
}
location->setText(path);
return fileList->changePath(path);
}
-
-
-const QString Pane::path() const {
- return fileList->path();
-}
class Pane : public QWidget {
Q_OBJECT
+signals:
+ void switchPanes();
+
public:
+ bool active;
+
explicit Pane(QWidget *theCase, QWidget *parent = 0);
const QString path() const;
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;