X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/afca8efa2601d9566c8d34d7b67dfb5abc729956..7c99bf5f6b6285c47dc4fa90d2bd2425287747d5:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 207535ce1..09c7d8d46 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -48,7 +48,8 @@ KItemListController::KItemListController(QObject* parent) : m_pressedMousePos(), m_oldSelection() { - connect(m_keyboardManager, SIGNAL(requestItemActivation(QString,bool)), this, SLOT(slotKeyboardActivationRequested(QString,bool))); + connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)), + this, SLOT(slotChangeCurrentItem(QString,bool))); } KItemListController::~KItemListController() @@ -200,6 +201,11 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } break; + case Qt::Key_Enter: + case Qt::Key_Return: + emit itemActivated(index); + break; + case Qt::Key_Space: if (controlPressed) { m_selectionManager->endAnchoredSelection(); @@ -232,7 +238,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) return true; } -void KItemListController::slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem) +void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem) { if (!m_model) { return; @@ -240,7 +246,7 @@ void KItemListController::slotKeyboardActivationRequested(const QString& text, b const int currentIndex = m_selectionManager->currentItem(); int index; if (searchFromNextItem) { - index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); + index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); } else { index = m_model->indexForKeyboardSearch(text, currentIndex); @@ -301,6 +307,11 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const if (controlPressed) { m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); m_selectionManager->beginAnchoredSelection(m_pressedIndex); + } else if (event->buttons() & Qt::RightButton) { + // Only clear the selection if a context menu is requested above a non-selected item + if (!m_selectionManager->selectedItems().contains(m_pressedIndex)) { + m_selectionManager->setSelectedItems(QSet() << m_pressedIndex); + } } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { // Select the pressed item and start a new anchored selection m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); @@ -315,6 +326,10 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const return true; } else { + if (event->buttons() & Qt::RightButton) { + m_selectionManager->clearSelection(); + } + KItemListRubberBand* rubberBand = m_view->rubberBand(); QPointF startPos = m_pressedMousePos; if (m_view->scrollOrientation() == Qt::Vertical) { @@ -386,7 +401,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con const bool shiftOrControlPressed = event->modifiers() & Qt::ShiftModifier || event->modifiers() & Qt::ControlModifier; - bool clearSelection = !shiftOrControlPressed && !m_dragging && !(event->button() == Qt::RightButton); + bool clearSelection = !shiftOrControlPressed && !m_dragging && event->button() != Qt::RightButton; KItemListRubberBand* rubberBand = m_view->rubberBand(); if (rubberBand->isActive()) { @@ -411,18 +426,24 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con m_selectionManager->setSelectedItems(QSet() << index); } - bool emitItemClicked = true; if (event->button() & Qt::LeftButton) { + bool emitItemActivated = true; if (m_view->isAboveExpansionToggle(index, pos)) { emit itemExpansionToggleClicked(index); - emitItemClicked = false; - } else if (shiftOrControlPressed || !KGlobalSettings::singleClick()) { - emitItemClicked = false; + emitItemActivated = false; + } else if (shiftOrControlPressed) { + // The mouse click should only update the selection, not trigger the item + emitItemActivated = false; + } else if (!KGlobalSettings::singleClick()) { + emitItemActivated = false; } - } - - if (emitItemClicked) { - emit itemClicked(index, event->button()); + if (emitItemActivated) { + emit itemActivated(index); + } + } else if (event->button() & Qt::MidButton) { + emit itemMiddleClicked(index); + } else if (event->button() & Qt::RightButton) { + emit contextMenuRequested(index, QPointF(event->pos())); } } else if (clearSelection) { m_selectionManager->clearSelection(); @@ -439,11 +460,11 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QPointF pos = transform.map(event->pos()); const int index = m_view->itemAt(pos); - bool emitItemClicked = !KGlobalSettings::singleClick() && + bool emitItemActivated = !KGlobalSettings::singleClick() && (event->button() & Qt::LeftButton) && index >= 0 && index < m_model->count(); - if (emitItemClicked) { - emit itemClicked(index, event->button()); + if (emitItemActivated) { + emit itemActivated(index); } return false; }