X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e9d29bcf30ccbd7c76ba37ce9efcfac1649fc46e..c756bc6c8946a05dc4c61169ca3a677618e39256:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index b8d719d3b..c8c0fc5f1 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -40,13 +40,16 @@ #include #include #include +#include KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : QObject(parent), - m_singleClickActivation(KGlobalSettings::singleClick()), + m_singleClickActivationEnforced(false), m_selectionTogglePressed(false), m_clearSelectionIfItemsAreNotDragged(false), m_selectionBehavior(NoSelection), + m_autoActivationBehavior(ActivationAndExpansion), + m_mouseDoubleClickAction(ActivateItemOnly), m_model(0), m_view(0), m_selectionManager(new KItemListSelectionManager(this)), @@ -157,6 +160,26 @@ KItemListController::SelectionBehavior KItemListController::selectionBehavior() return m_selectionBehavior; } +void KItemListController::setAutoActivationBehavior(AutoActivationBehavior behavior) +{ + m_autoActivationBehavior = behavior; +} + +KItemListController::AutoActivationBehavior KItemListController::autoActivationBehavior() const +{ + return m_autoActivationBehavior; +} + +void KItemListController::setMouseDoubleClickAction(MouseDoubleClickAction action) +{ + m_mouseDoubleClickAction = action; +} + +KItemListController::MouseDoubleClickAction KItemListController::mouseDoubleClickAction() const +{ + return m_mouseDoubleClickAction; +} + void KItemListController::setAutoActivationDelay(int delay) { m_autoActivationTimer->setInterval(delay); @@ -167,14 +190,14 @@ int KItemListController::autoActivationDelay() const return m_autoActivationTimer->interval(); } -void KItemListController::setSingleClickActivation(bool singleClick) +void KItemListController::setSingleClickActivationEnforced(bool singleClick) { - m_singleClickActivation = singleClick; + m_singleClickActivationEnforced = singleClick; } -bool KItemListController::singleClickActivation() const +bool KItemListController::singleClickActivationEnforced() const { - return m_singleClickActivation; + return m_singleClickActivationEnforced; } bool KItemListController::showEvent(QShowEvent* event) @@ -251,7 +274,15 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) case Qt::Key_Left: if (index > 0) { - --index; + const int expandedParentsCount = m_model->expandedParentsCount(index); + if (expandedParentsCount == 0) { + --index; + } else { + // Go to the parent of the current item. + do { + --index; + } while (index > 0 && m_model->expandedParentsCount(index) == expandedParentsCount); + } m_keyboardAnchorIndex = index; m_keyboardAnchorPos = keyboardAnchorPos(index); } @@ -389,6 +420,8 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) default: m_keyboardManager->addKeys(event->text()); + // Make sure unconsumed events get propagated up the chain. #302329 + event->ignore(); return false; } @@ -459,11 +492,20 @@ void KItemListController::slotAutoActivationTimeout() return; } - if (m_model->supportsDropping(index)) { + /* m_view->isUnderMouse() fixes a bug in the Folder-View-Panel and in the + * Places-Panel. + * + * Bug: When you drag a file onto a Folder-View-Item or a Places-Item and + * then move away before the auto-activation timeout triggers, than the + * item still becomes activated/expanded. + * + * See Bug 293200 and 305783 + */ + if (m_model->supportsDropping(index) && m_view->isUnderMouse()) { if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { const bool expanded = m_model->isExpanded(index); m_model->setExpanded(index, !expanded); - } else { + } else if (m_autoActivationBehavior != ExpansionOnly) { emit itemActivated(index); } } @@ -545,7 +587,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const break; case MultiSelection: - if (controlPressed) { + if (controlPressed && !shiftPressed) { m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); m_selectionManager->beginAnchoredSelection(m_pressedIndex); } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { @@ -714,7 +756,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con } else if (shiftOrControlPressed) { // The mouse click should only update the selection, not trigger the item emitItemActivated = false; - } else if (!m_singleClickActivation) { + } else if (!(KGlobalSettings::singleClick() || m_singleClickActivationEnforced)) { emitItemActivated = false; } if (emitItemActivated) { @@ -736,7 +778,15 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QPointF pos = transform.map(event->pos()); const int index = m_view->itemAt(pos); - bool emitItemActivated = !m_singleClickActivation && + // Expand item if desired - See Bug 295573 + if (m_mouseDoubleClickAction != ActivateItemOnly) { + if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { + const bool expanded = m_model->isExpanded(index); + m_model->setExpanded(index, !expanded); + } + } + + bool emitItemActivated = !(KGlobalSettings::singleClick() || m_singleClickActivationEnforced) && (event->button() & Qt::LeftButton) && index >= 0 && index < m_model->count(); if (emitItemActivated) { @@ -758,6 +808,7 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con Q_UNUSED(transform); m_view->setAutoScroll(false); + m_view->hideDropIndicator(); KItemListWidget* widget = hoveredWidget(); if (widget) { @@ -769,7 +820,6 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) { - Q_UNUSED(transform); if (!m_model || !m_view) { return false; } @@ -788,17 +838,35 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons oldHoveredWidget->setHovered(false); emit itemUnhovered(oldHoveredWidget->index()); } + } - if (newHoveredWidget) { - const int index = newHoveredWidget->index(); + if (newHoveredWidget) { + bool droppingBetweenItems = false; + if (m_model->sortRole().isEmpty()) { + // The model supports inserting items between other items. + droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0); + } + + const int index = newHoveredWidget->index(); + if (!droppingBetweenItems) { if (m_model->supportsDropping(index)) { - newHoveredWidget->setHovered(true); - } - emit itemHovered(index); + // Something has been dragged on an item. + m_view->hideDropIndicator(); + if (!newHoveredWidget->isHovered()) { + newHoveredWidget->setHovered(true); + emit itemHovered(index); + } - if (m_autoActivationTimer->interval() >= 0) { - m_autoActivationTimer->setProperty("index", index); - m_autoActivationTimer->start(); + if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) { + m_autoActivationTimer->setProperty("index", index); + m_autoActivationTimer->start(); + } + } + } else { + m_autoActivationTimer->stop(); + if (newHoveredWidget && newHoveredWidget->isHovered()) { + newHoveredWidget->setHovered(false); + emit itemUnhovered(index); } } } @@ -808,7 +876,6 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) { - Q_UNUSED(transform) if (!m_view) { return false; } @@ -817,8 +884,23 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT m_view->setAutoScroll(false); const QPointF pos = transform.map(event->pos()); - const int index = m_view->itemAt(pos); - emit itemDropEvent(index, event); + + int dropAboveIndex = -1; + if (m_model->sortRole().isEmpty()) { + // The model supports inserting of items between other items. + dropAboveIndex = m_view->showDropIndicator(pos); + } + + if (dropAboveIndex >= 0) { + // Something has been dropped between two items. + m_view->hideDropIndicator(); + emit aboveItemDropEvent(dropAboveIndex, event); + } else { + // Something has been dropped on an item or on an empty part of the view. + emit itemDropEvent(m_view->itemAt(pos), event); + } + + QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropEnd); return true; } @@ -1063,12 +1145,11 @@ void KItemListController::startDragging() const QPixmap pixmap = m_view->createDragPixmap(selectedItems); drag->setPixmap(pixmap); - // TODO: The vertical hotspot of -24 should be replaced by the - // height of the QCursor-pixmap. - const QPoint hotSpot(pixmap.width() / 2, -24); + const QPoint hotSpot(pixmap.width() / 2, 0); drag->setHotSpot(hotSpot); drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); + QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropStart); } KItemListWidget* KItemListController::hoveredWidget() const