X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a6db5029acc09639fd8c7c20a7676b1ac9f36539..67ebd66f94356b4e66005b1072919cb7b5e858bb:/src/kitemviews/kitemlistcontroller.cpp diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 61f520641..ca385899b 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -1,45 +1,28 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * Copyright (C) 2012 by Frank Reininghaus * - * * - * Based on the Itemviews NG project from Trolltech Labs: * - * http://qt.gitorious.org/qt-labs/itemviews-ng * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * SPDX-FileCopyrightText: 2012 Frank Reininghaus + * + * Based on the Itemviews NG project from Trolltech Labs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #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), @@ -64,6 +47,8 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v this, &KItemListController::slotChangeCurrentItem); connect(m_selectionManager, &KItemListSelectionManager::currentChanged, m_keyboardManager, &KItemListKeyboardSearchManager::slotCurrentChanged); + connect(m_selectionManager, &KItemListSelectionManager::selectionChanged, + m_keyboardManager, &KItemListKeyboardSearchManager::slotSelectionChanged); m_autoActivationTimer = new QTimer(this); m_autoActivationTimer->setSingleShot(true); @@ -179,6 +164,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 +198,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 +219,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 +238,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 +410,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 +447,9 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } break; } + } + if (navigationPressed) { m_view->scrollToItem(index); } return true; @@ -471,19 +460,18 @@ void KItemListController::slotChangeCurrentItem(const QString& text, bool search if (!m_model || m_model->count() == 0) { return; } - const int currentIndex = m_selectionManager->currentItem(); int index; if (searchFromNextItem) { + const int currentIndex = m_selectionManager->currentItem(); index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); } else { - index = m_model->indexForKeyboardSearch(text, currentIndex); + index = m_model->indexForKeyboardSearch(text, 0); } if (index >= 0) { m_selectionManager->setCurrentItem(index); if (m_selectionBehavior != NoSelection) { - m_selectionManager->clearSelection(); - m_selectionManager->setSelected(index, 1); + m_selectionManager->replaceSelection(index); m_selectionManager->beginAnchoredSelection(index); } @@ -523,7 +511,7 @@ void KItemListController::slotAutoActivationTimeout() bool KItemListController::inputMethodEvent(QInputMethodEvent* event) { - Q_UNUSED(event); + Q_UNUSED(event) return false; } @@ -595,6 +583,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); @@ -782,7 +780,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con if (emitItemActivated) { emit itemActivated(index); } - } else if (event->button() & Qt::MidButton) { + } else if (event->button() & Qt::MiddleButton) { emit itemMiddleClicked(index); } } @@ -833,15 +831,18 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) + + DragAndDropHelper::clearUrlListMatchesUrlCache(); + return false; } bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) m_autoActivationTimer->stop(); m_view->setAutoScroll(false); @@ -915,8 +916,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons m_view->hideDropIndicator(); } - event->setAccepted(!DragAndDropHelper::urlListMatchesUrl(event->mimeData()->urls(), hoveredDir)); - + if (DragAndDropHelper::urlListMatchesUrl(event->mimeData()->urls(), hoveredDir)) { + event->setDropAction(Qt::IgnoreAction); + event->ignore(); + } else { + event->setDropAction(event->proposedAction()); + event->accept(); + } return false; } @@ -954,14 +960,14 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT bool KItemListController::hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) return false; } bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) { - Q_UNUSED(transform); + Q_UNUSED(transform) if (!m_model || !m_view) { return false; } @@ -992,8 +998,8 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) if (!m_model || !m_view) { return false; @@ -1010,15 +1016,15 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const bool KItemListController::wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) return false; } bool KItemListController::resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform) { - Q_UNUSED(event); - Q_UNUSED(transform); + Q_UNUSED(event) + Q_UNUSED(transform) return false; }