#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);
-}