X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/99e80c1c7e6e77aa26ccbca4fbb0430b35974544..0c4f58328f1c72aee100a568b4315c1d5c91fdf0:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 008b6c4c6..82553ddda 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -23,23 +23,20 @@ #include "kitemlistcontroller.h" - -#include "kitemlistview.h" #include "kitemlistselectionmanager.h" - -#include "private/kitemlistrubberband.h" +#include "kitemlistview.h" #include "private/kitemlistkeyboardsearchmanager.h" +#include "private/kitemlistrubberband.h" +#include "views/draganddrophelper.h" +#include #include #include -#include #include #include #include #include #include -#include -#include KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : QObject(parent), @@ -49,13 +46,13 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v m_selectionBehavior(NoSelection), m_autoActivationBehavior(ActivationAndExpansion), m_mouseDoubleClickAction(ActivateItemOnly), - m_model(0), - m_view(0), + m_model(nullptr), + m_view(nullptr), m_selectionManager(new KItemListSelectionManager(this)), m_keyboardManager(new KItemListKeyboardSearchManager(this)), m_pressedIndex(-1), m_pressedMousePos(), - m_autoActivationTimer(0), + m_autoActivationTimer(nullptr), m_oldSelection(), m_keyboardAnchorIndex(-1), m_keyboardAnchorPos(0) @@ -76,10 +73,10 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v KItemListController::~KItemListController() { - setView(0); + setView(nullptr); Q_ASSERT(!m_view); - setModel(0); + setModel(nullptr); Q_ASSERT(!m_model); } @@ -179,6 +176,20 @@ KItemListController::MouseDoubleClickAction KItemListController::mouseDoubleClic return m_mouseDoubleClickAction; } +int KItemListController::indexCloseToMousePressedPosition() const +{ + QHashIterator it(m_view->m_visibleGroups); + while (it.hasNext()) { + it.next(); + KItemListGroupHeader *groupHeader = it.value(); + const QPointF mappedToGroup = groupHeader->mapFromItem(nullptr, m_pressedMousePos); + if (groupHeader->contains(mappedToGroup)) { + return it.key()->index(); + } + } + return -1; +} + void KItemListController::setAutoActivationDelay(int delay) { m_autoActivationTimer->setInterval(delay); @@ -199,18 +210,6 @@ bool KItemListController::singleClickActivationEnforced() const return m_singleClickActivationEnforced; } -bool KItemListController::showEvent(QShowEvent* event) -{ - Q_UNUSED(event); - return false; -} - -bool KItemListController::hideEvent(QHideEvent* event) -{ - Q_UNUSED(event); - return false; -} - bool KItemListController::keyPressEvent(QKeyEvent* event) { int index = m_selectionManager->currentItem(); @@ -232,6 +231,10 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; const bool controlPressed = event->modifiers() & Qt::ControlModifier; const bool shiftOrControlPressed = shiftPressed || controlPressed; + const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || + key == Qt::Key_PageUp || key == Qt::Key_PageDown || + key == Qt::Key_Up || key == Qt::Key_Down || + key == Qt::Key_Left || key == Qt::Key_Right; const int itemCount = m_model->count(); @@ -247,11 +250,8 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } } - const bool selectSingleItem = m_selectionBehavior != NoSelection && - itemCount == 1 && - (key == Qt::Key_Home || key == Qt::Key_End || - key == Qt::Key_Up || key == Qt::Key_Down || - key == Qt::Key_Left || key == Qt::Key_Right); + const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed; + if (selectSingleItem) { const int current = m_selectionManager->currentItem(); m_selectionManager->setSelected(current); @@ -422,8 +422,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } } } - // Fall through to the default case and add the Space to the current search string. - + Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string. default: m_keyboardManager->addKeys(event->text()); // Make sure unconsumed events get propagated up the chain. #302329 @@ -460,7 +459,9 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } break; } + } + if (navigationPressed) { m_view->scrollToItem(index); } return true; @@ -595,6 +596,16 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const m_selectionManager->endAnchoredSelection(); } + if (event->buttons() & Qt::RightButton) { + // Stop rubber band from persisting after right-clicks + KItemListRubberBand* rubberBand = m_view->rubberBand(); + if (rubberBand->isActive()) { + disconnect(rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListController::slotRubberBandChanged); + rubberBand->setActive(false); + m_view->setAutoScroll(false); + } + } + if (m_pressedIndex >= 0) { m_selectionManager->setCurrentItem(m_pressedIndex); @@ -835,6 +846,9 @@ bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, con { Q_UNUSED(event); Q_UNUSED(transform); + + DragAndDropHelper::clearUrlListMatchesUrlCache(); + return false; } @@ -1216,7 +1230,7 @@ KItemListWidget* KItemListController::hoveredWidget() const } } - return 0; + return nullptr; } KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const @@ -1233,7 +1247,7 @@ KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const } } - return 0; + return nullptr; } void KItemListController::updateKeyboardAnchor()