X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5e20f374e306e75aa4881e598eb72bf8ffeeb1e7..60d555fa55f025f3ecaa82cf95f012cbbbeb8ddc:/src/dolphindetailsview.cpp diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index e527a4f79..ad362914a 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -56,6 +56,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr m_controller(controller), m_selectionManager(0), m_autoScroller(0), + m_expandableFoldersAction(0), m_font(), m_decorationSize(), m_band() @@ -153,6 +154,11 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr this, SLOT(slotGlobalSettingsChanged(int))); m_useDefaultIndexAt = false; + + m_expandableFoldersAction = new QAction(i18nc("@option:check", "Expandable Folders"), this); + m_expandableFoldersAction->setCheckable(true); + connect(m_expandableFoldersAction, SIGNAL(toggled(bool)), + this, SLOT(setFoldersExpandable(bool))); } DolphinDetailsView::~DolphinDetailsView() @@ -187,7 +193,11 @@ QStyleOptionViewItem DolphinDetailsView::viewOptions() const void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event) { QTreeView::contextMenuEvent(event); - m_controller->triggerContextMenuRequest(event->pos()); + + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + m_expandableFoldersAction->setChecked(settings->expandableFolders()); + m_controller->triggerContextMenuRequest(event->pos(), + QList() << m_expandableFoldersAction); } void DolphinDetailsView::mousePressEvent(QMouseEvent* event) @@ -197,20 +207,14 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event) const QModelIndex current = currentIndex(); QTreeView::mousePressEvent(event); - m_expandingTogglePressed = false; + m_expandingTogglePressed = isAboveExpandingToggle(event->pos()); + const QModelIndex index = indexAt(event->pos()); const bool updateState = index.isValid() && (index.column() == DolphinModel::Name) && (event->button() == Qt::LeftButton); if (updateState) { - // TODO: See comment in DolphinIconsView::mousePressEvent(). Only update - // the state if no expanding/collapsing area has been hit: - const QRect rect = visualRect(index); - if (event->pos().x() >= rect.x() + indentation()) { - setState(QAbstractItemView::DraggingState); - } else { - m_expandingTogglePressed = true; - } + setState(QAbstractItemView::DraggingState); } if (!index.isValid() || (index.column() != DolphinModel::Name)) { @@ -219,8 +223,8 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event) m_controller->replaceUrlByClipboard(); } - const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); - if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) { + const Qt::KeyboardModifiers mod = QApplication::keyboardModifiers(); + if (!m_expandingTogglePressed && !(mod & Qt::ShiftModifier) && !(mod & Qt::ControlModifier)) { clearSelection(); } @@ -246,6 +250,14 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event) void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event) { + if (m_expandingTogglePressed) { + // Per default QTreeView starts either a selection or a drag operation when dragging + // the expanding toggle button (Qt-issue - see TODO comment in DolphinIconsView::mousePressEvent()). + // Turn off this behavior in Dolphin to stay predictable: + setState(QAbstractItemView::NoState); + return; + } + if (m_band.show) { const QPoint mousePos = event->pos(); const QModelIndex index = indexAt(mousePos); @@ -267,31 +279,25 @@ void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event) // QTreeView::mouseMoveEvent(event); QAbstractItemView::mouseMoveEvent(event); } - - if (m_expandingTogglePressed) { - // Per default QTreeView starts either a selection or a drag operation when dragging - // the expanding toggle button (Qt-issue - see TODO comment in DolphinIconsView::mousePressEvent()). - // Turn off this behavior in Dolphin to stay predictable: - clearSelection(); - setState(QAbstractItemView::NoState); - } } void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event) { - const QModelIndex index = indexAt(event->pos()); - if (index.isValid() && (index.column() == DolphinModel::Name)) { - QTreeView::mouseReleaseEvent(event); - } else { - // don't change the current index if the cursor is released - // above any other column than the name column, as the other - // columns act as viewport - const QModelIndex current = currentIndex(); - QTreeView::mouseReleaseEvent(event); - selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current); + if (!m_expandingTogglePressed) { + const QModelIndex index = indexAt(event->pos()); + if (index.isValid() && (index.column() == DolphinModel::Name)) { + QTreeView::mouseReleaseEvent(event); + } else { + // don't change the current index if the cursor is released + // above any other column than the name column, as the other + // columns act as viewport + const QModelIndex current = currentIndex(); + QTreeView::mouseReleaseEvent(event); + selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current); + } } - m_expandingTogglePressed = false; + if (m_band.show) { setState(NoState); updateElasticBand(); @@ -572,27 +578,8 @@ void DolphinDetailsView::configureSettings(const QPoint& pos) } popup.addSeparator(); - // add a checkbox item for the "Expandable Folders" setting - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - QAction* expandableFoldersAction = popup.addAction(i18nc("@option:check", "Expandable Folders")); - expandableFoldersAction->setCheckable(true); - expandableFoldersAction->setChecked(settings->expandableFolders()); - QAction* activatedAction = popup.exec(header()->mapToGlobal(pos)); - if (activatedAction == expandableFoldersAction) { - const bool expand = expandableFoldersAction->isChecked(); - if (!expand) { - // collapse all expanded folders, as QTreeView::setItemsExpandable(false) - // does not do this task - const int rowCount = model()->rowCount(); - for (int row = 0; row < rowCount; ++row) { - setExpanded(model()->index(row, 0), false); - } - } - settings->setExpandableFolders(expand); - setRootIsDecorated(expand); - setItemsExpandable(expand); - } else if (activatedAction != 0) { + if (activatedAction != 0) { const bool show = activatedAction->isChecked(); const int columnIndex = activatedAction->data().toInt(); @@ -859,6 +846,22 @@ void DolphinDetailsView::updateElasticBandSelection() m_band.ignoreOldInfo = false; } +void DolphinDetailsView::setFoldersExpandable(bool expandable) +{ + if (!expandable) { + // collapse all expanded folders, as QTreeView::setItemsExpandable(false) + // does not do this task + const int rowCount = model()->rowCount(); + for (int row = 0; row < rowCount; ++row) { + setExpanded(model()->index(row, 0), false); + } + } + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + settings->setExpandableFolders(expandable); + setRootIsDecorated(expandable); + setItemsExpandable(expandable); +} + void DolphinDetailsView::updateDecorationSize(bool showPreview) { DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); @@ -955,6 +958,34 @@ QRect DolphinDetailsView::nameColumnRect(const QModelIndex& index) const return rect; } +bool DolphinDetailsView::isAboveExpandingToggle(const QPoint& pos) const +{ + // QTreeView offers no public API to get the information whether an index has an + // expanding toggle and what boundaries the toggle has. The following approach + // also assumes a toggle for file items. + if (itemsExpandable()) { + const QModelIndex index = QTreeView::indexAt(pos); + if (index.isValid() && (index.column() == KDirModel::Name)) { + QRect rect = nameColumnRect(index); + const int toggleSize = rect.height(); + if (isRightToLeft()) { + rect.moveRight(rect.right()); + } else { + rect.moveLeft(rect.x() - toggleSize); + } + rect.setWidth(toggleSize); + + QStyleOption opt; + opt.initFrom(this); + opt.rect = rect; + rect = style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, this); + + return rect.contains(pos); + } + } + return false; +} + DolphinDetailsView::ElasticBand::ElasticBand() : show(false), origin(),