X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7f5fb3ae2c8db3fe513f280282b98db65ccbce6a..7c99bf5f6b6285c47dc4fa90d2bd2425287747d5:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 5eae95e6d..09c7d8d46 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -25,6 +25,7 @@ #include "kitemlistview.h" #include "kitemlistrubberband_p.h" #include "kitemlistselectionmanager.h" +#include "kitemlistkeyboardsearchmanager_p.h" #include #include @@ -42,10 +43,13 @@ KItemListController::KItemListController(QObject* parent) : m_model(0), m_view(0), m_selectionManager(new KItemListSelectionManager(this)), + m_keyboardManager(new KItemListKeyboardSearchManager(this)), m_pressedIndex(-1), m_pressedMousePos(), m_oldSelection() { + connect(m_keyboardManager, SIGNAL(changeCurrentItem(QString,bool)), + this, SLOT(slotChangeCurrentItem(QString,bool))); } KItemListController::~KItemListController() @@ -197,15 +201,22 @@ 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(); m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); m_selectionManager->beginAnchoredSelection(index); + break; } default: - break; + m_keyboardManager->addKeys(event->text()); + return false; } if (m_selectionManager->currentItem() != index) { @@ -227,6 +238,27 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) return true; } +void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem) +{ + if (!m_model) { + return; + } + const int currentIndex = m_selectionManager->currentItem(); + int index; + if (searchFromNextItem) { + index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); + } + else { + index = m_model->indexForKeyboardSearch(text, currentIndex); + } + if (index >= 0) { + m_selectionManager->setCurrentItem(index); + m_selectionManager->clearSelection(); + m_selectionManager->setSelected(index, 1); + m_selectionManager->beginAnchoredSelection(index); + } +} + bool KItemListController::inputMethodEvent(QInputMethodEvent* event) { Q_UNUSED(event); @@ -275,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); @@ -289,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) { @@ -360,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()) { @@ -385,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(); @@ -413,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; } @@ -678,7 +725,16 @@ void KItemListController::slotRubberBandChanged() } } while (!selectionFinished); - m_selectionManager->setSelectedItems(selectedItems + m_oldSelection); + if (QApplication::keyboardModifiers() & Qt::ControlModifier) { + // If Control is pressed, the selection state of all items in the rubberband is toggled. + // Therefore, the new selection contains: + // 1. All previously selected items which are not inside the rubberband, and + // 2. all items inside the rubberband which have not been selected previously. + m_selectionManager->setSelectedItems((m_oldSelection - selectedItems) + (selectedItems - m_oldSelection)); + } + else { + m_selectionManager->setSelectedItems(selectedItems + m_oldSelection); + } } bool KItemListController::startDragging()