-void ColumnWidget::mousePressEvent(QMouseEvent* event)
-{
- // On each mouse press event QColumnView triggers the loading of the
- // current folder in the next column. This is not wanted for Dolphin when
- // opening a context menu or when the CTRL modifier is pressed. Beside usability
- // aspects the loading of the folder also implies losing the current selection,
- // which makes it impossible to select folders from the current column. To bypass
- // this behavior QListView::mousePressEvent() is not invoked in those cases, which
- // is not a nice solution. Maybe another solution can be found in future versions
- // of QColumnView.
-
- m_view->requestSelectionModel(this);
-
- bool swallowMousePressEvent = false;
- const QModelIndex index = indexAt(event->pos());
- if (index.isValid()) {
- // a click on an item has been done
- const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model());
- const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
- const QModelIndex dirIndex = proxyModel->mapToSource(index);
- KFileItem item = dirModel->itemForIndex(dirIndex);
- if (!item.isNull()) {
- QItemSelectionModel* selModel = selectionModel();
-
- bool activate = true;
- const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
- if (modifier & Qt::ControlModifier) {
- m_view->requestActivation(this);
- if (!selModel->hasSelection()) {
- // Assure to set the current index, so that a selection by the SHIFT key
- // will work. TODO: If the index specifies a folder, the loading of the folder will
- // be triggered by QColumnView although this is not wanted by Dolphin.
- selModel->setCurrentIndex(index, QItemSelectionModel::Select);
- }
- selModel->select(index, QItemSelectionModel::Toggle);
- swallowMousePressEvent = true;
- } else if (item.isDir()) {
- m_childUrl = item.url();
- viewport()->update();
-
- // Only request the activation if not the left button is pressed.
- // The left button on a directory opens a new column, hence requesting
- // an activation is useless as the new column will request the activation
- // afterwards.
- if (event->button() == Qt::LeftButton) {
- activate = false;
- }
- }
-
- if (activate) {
- m_view->requestActivation(this);
- }
-
- // 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
- m_view->requestActivation(this);
-
- // 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();
- }
-
- if (!swallowMousePressEvent) {
- QListView::mousePressEvent(event);
- }
-}
-
-void ColumnWidget::mouseMoveEvent(QMouseEvent* event)
-{
- // see description in ColumnView::mousePressEvent()
- if (!m_swallowMouseMoveEvents) {
- QListView::mouseMoveEvent(event);
- }
-}
-
-void ColumnWidget::mouseReleaseEvent(QMouseEvent* event)
-{
- QListView::mouseReleaseEvent(event);
- m_swallowMouseMoveEvents = false;
-}
-
-