X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/83c5692f5e33c2bb239e1122811ce64ed1f144a3..aff9b9570edf833eed12850c19b6833291822ea9:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 0cf62f8e0..fedbe61a9 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -41,7 +41,9 @@ KItemListController::KItemListController(QObject* parent) : QObject(parent), + m_singleClickActivation(KGlobalSettings::singleClick()), m_selectionTogglePressed(false), + m_clearSelectionIfItemsAreNotDragged(false), m_selectionBehavior(NoSelection), m_model(0), m_view(0), @@ -52,7 +54,7 @@ KItemListController::KItemListController(QObject* parent) : m_autoActivationTimer(0), m_oldSelection(), m_keyboardAnchorIndex(-1), - m_keyboardAnchorXPos(0) + m_keyboardAnchorPos(0) { connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)), this, SLOT(slotChangeCurrentItem(QString,bool))); @@ -142,6 +144,16 @@ int KItemListController::autoActivationDelay() const return m_autoActivationTimer->interval(); } +void KItemListController::setSingleClickActivation(bool singleClick) +{ + m_singleClickActivation = singleClick; +} + +bool KItemListController::singleClickActivation() const +{ + return m_singleClickActivation; +} + bool KItemListController::showEvent(QShowEvent* event) { Q_UNUSED(event); @@ -213,7 +225,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) if (index > 0) { --index; m_keyboardAnchorIndex = index; - m_keyboardAnchorXPos = keyboardAnchorPos(index); + m_keyboardAnchorPos = keyboardAnchorPos(index); } break; @@ -221,7 +233,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) if (index < itemCount - 1) { ++index; m_keyboardAnchorIndex = index; - m_keyboardAnchorXPos = keyboardAnchorPos(index); + m_keyboardAnchorPos = keyboardAnchorPos(index); } break; @@ -369,7 +381,9 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const } if (m_view->isAboveExpansionToggle(m_pressedIndex, m_pressedMousePos)) { + m_selectionManager->endAnchoredSelection(); m_selectionManager->setCurrentItem(m_pressedIndex); + m_selectionManager->beginAnchoredSelection(m_pressedIndex); return true; } @@ -400,6 +414,13 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const (!shiftOrControlPressed && !pressedItemAlreadySelected); if (clearSelection) { m_selectionManager->clearSelection(); + } else if (pressedItemAlreadySelected && (event->buttons() & Qt::LeftButton)) { + // The user might want to start dragging multiple items, but if he clicks the item + // in order to trigger it instead, the other selected items must be deselected. + // However, we do not know yet what the user is going to do. + // -> remember that the user pressed an item which had been selected already and + // clear the selection in mouseReleaseEvent(), unless the items are dragged. + m_clearSelectionIfItemsAreNotDragged = true; } if (!shiftPressed) { @@ -492,7 +513,12 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const // done on the mouse-press event, but when using the selection-toggle on a // selected item the dragged item is not selected yet. m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + } else { + // A selected item has been clicked to drag all selected items + // -> the selection should not be cleared when the mouse button is released. + m_clearSelectionIfItemsAreNotDragged = false; } + startDragging(); } } @@ -566,6 +592,14 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con if (index >= 0 && index == m_pressedIndex) { // The release event is done above the same item as the press event + if (m_clearSelectionIfItemsAreNotDragged) { + // A selected item has been clicked, but no drag operation has been started + // -> clear the rest of the selection. + m_selectionManager->clearSelection(); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); + m_selectionManager->beginAnchoredSelection(m_pressedIndex); + } + if (event->button() & Qt::LeftButton) { bool emitItemActivated = true; if (m_view->isAboveExpansionToggle(index, pos)) { @@ -577,7 +611,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 (!KGlobalSettings::singleClick()) { + } else if (!m_singleClickActivation) { emitItemActivated = false; } if (emitItemActivated) { @@ -590,6 +624,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con m_pressedMousePos = QPointF(); m_pressedIndex = -1; + m_clearSelectionIfItemsAreNotDragged = false; return false; } @@ -598,7 +633,7 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QPointF pos = transform.map(event->pos()); const int index = m_view->itemAt(pos); - bool emitItemActivated = !KGlobalSettings::singleClick() && + bool emitItemActivated = !m_singleClickActivation && (event->button() & Qt::LeftButton) && index >= 0 && index < m_model->count(); if (emitItemActivated) { @@ -914,7 +949,7 @@ void KItemListController::startDragging() const QPixmap pixmap = m_view->createDragPixmap(selectedItems); drag->setPixmap(pixmap); - drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::IgnoreAction); + drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); } KItemListWidget* KItemListController::hoveredWidget() const @@ -951,11 +986,11 @@ void KItemListController::updateKeyboardAnchor() { const bool validAnchor = m_keyboardAnchorIndex >= 0 && m_keyboardAnchorIndex < m_model->count() && - keyboardAnchorPos(m_keyboardAnchorIndex) == m_keyboardAnchorXPos; + keyboardAnchorPos(m_keyboardAnchorIndex) == m_keyboardAnchorPos; if (!validAnchor) { const int index = m_selectionManager->currentItem(); m_keyboardAnchorIndex = index; - m_keyboardAnchorXPos = keyboardAnchorPos(index); + m_keyboardAnchorPos = keyboardAnchorPos(index); } } @@ -984,10 +1019,10 @@ int KItemListController::nextRowIndex() const // that is below the current index int nextRowIndex = lastColumnIndex + 1; int searchIndex = nextRowIndex; - qreal minDiff = qAbs(m_keyboardAnchorXPos - keyboardAnchorPos(nextRowIndex)); + qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(nextRowIndex)); while (searchIndex < maxIndex && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex)) { ++searchIndex; - const qreal searchDiff = qAbs(m_keyboardAnchorXPos - keyboardAnchorPos(searchIndex)); + const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex)); if (searchDiff < minDiff) { minDiff = searchDiff; nextRowIndex = searchIndex; @@ -1017,10 +1052,10 @@ int KItemListController::previousRowIndex() const // that is above the current index int previousRowIndex = firstColumnIndex - 1; int searchIndex = previousRowIndex; - qreal minDiff = qAbs(m_keyboardAnchorXPos - keyboardAnchorPos(previousRowIndex)); + qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(previousRowIndex)); while (searchIndex > 0 && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex)) { --searchIndex; - const qreal searchDiff = qAbs(m_keyboardAnchorXPos - keyboardAnchorPos(searchIndex)); + const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex)); if (searchDiff < minDiff) { minDiff = searchDiff; previousRowIndex = searchIndex;