From: Peter Penz Date: Fri, 3 Aug 2007 18:46:49 +0000 (+0000) Subject: further selection model fixes X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/b5a12004172e2a84fd4b2765e70546baa063e184?ds=sidebyside further selection model fixes svn path=/trunk/KDE/kdebase/apps/; revision=696076 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 3389e15bf..59a36d9f6 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -30,6 +30,7 @@ #include #include +#include #include /** @@ -57,6 +58,9 @@ public: inline const KUrl& url() const; + void obtainSelectionModel(); + void releaseSelectionModel(); + protected: virtual QStyleOptionViewItem viewOptions() const; virtual void dragEnterEvent(QDragEnterEvent* event); @@ -135,6 +139,12 @@ void ColumnWidget::setDecorationSize(const QSize& size) void ColumnWidget::setActive(bool active) { + if (active) { + obtainSelectionModel(); + } else { + releaseSelectionModel(); + } + if (m_active == active) { return; } @@ -158,6 +168,22 @@ const KUrl& ColumnWidget::url() const return m_url; } +void ColumnWidget::obtainSelectionModel() +{ + if (selectionModel() != m_view->selectionModel()) { + selectionModel()->deleteLater(); + setSelectionModel(m_view->selectionModel()); + } +} + +void ColumnWidget::releaseSelectionModel() +{ + if (selectionModel() == m_view->selectionModel()) { + QItemSelectionModel* replacementModel = new QItemSelectionModel(model()); + setSelectionModel(replacementModel); + } +} + QStyleOptionViewItem ColumnWidget::viewOptions() const { return m_viewOptions; @@ -207,6 +233,9 @@ void ColumnWidget::dropEvent(QDropEvent* event) void ColumnWidget::mousePressEvent(QMouseEvent* event) { + m_view->requestSelectionModel(this); + + bool swallowMousePressEvent = false; const QModelIndex index = indexAt(event->pos()); if (index.isValid()) { // A click on an item has been done. Only request an activation @@ -216,12 +245,31 @@ void ColumnWidget::mousePressEvent(QMouseEvent* event) const QModelIndex dirIndex = proxyModel->mapToSource(index); KFileItem* item = dirModel->itemForIndex(dirIndex); if (item != 0) { - if (item->isDir()) { + QItemSelectionModel* selModel = selectionModel(); + + const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); + if (modifier & Qt::ControlModifier) { + m_view->requestActivation(this); + selModel->select(index, QItemSelectionModel::Select); + swallowMousePressEvent = true; + } else if (item->isDir()) { m_childUrl = item->url(); viewport()->update(); - } else { + } else { m_view->requestActivation(this); } + + // TODO: check behavior with ShiftModifier + //if (modifier & Qt::ShiftModifier) + + // TODO: is the assumption OK that Qt::RightButton always represents the context menu button? + if (event->button() == Qt::RightButton) { + swallowMousePressEvent = true; + if (!selModel->isSelected(index)) { + clearSelection(); + } + selModel->select(index, QItemSelectionModel::Select); + } } } else { // a click on the viewport has been done @@ -230,9 +278,12 @@ void ColumnWidget::mousePressEvent(QMouseEvent* event) // Swallow mouse move events if a click is done on the viewport. Otherwise the QColumnView // triggers an unwanted loading of directories on hovering folder items. m_swallowMouseMoveEvents = true; + clearSelection(); } - QListView::mousePressEvent(event); + if (!swallowMousePressEvent) { + QListView::mousePressEvent(event); + } } void ColumnWidget::mouseMoveEvent(QMouseEvent* event) @@ -342,6 +393,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control setAcceptDrops(true); setDragDropMode(QAbstractItemView::DragDrop); setDropIndicatorShown(false); + setSelectionMode(ExtendedSelection); if (KGlobalSettings::singleClick()) { connect(this, SIGNAL(clicked(const QModelIndex&)), @@ -540,7 +592,21 @@ void DolphinColumnView::requestActivation(QWidget* column) if (isActive) { m_controller->setUrl(widget->url()); } - } + } + } +} + +void DolphinColumnView::requestSelectionModel(QAbstractItemView* view) +{ + foreach (QObject* object, viewport()->children()) { + if (object->inherits("QListView")) { + ColumnWidget* widget = static_cast(object); + if (widget == view) { + widget->obtainSelectionModel(); + } else { + widget->releaseSelectionModel(); + } + } } } diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index a3290cc2c..03f210229 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -73,10 +73,19 @@ private: /** * Requests the activation for the column \a column. The URL - * navigator will be changed to represent the column. + * navigator will be changed to represent the column. It is + * assured that the selection model of \a column will be set + * to the selection model of the Column View. */ void requestActivation(QWidget* column); + /** + * Requests the selection model from the Column View for \a view. + * If another column has already obtained the Column View selection + * model, it will be replaced by a default selection model. + */ + void requestSelectionModel(QAbstractItemView* view); + private: DolphinController* m_controller;