]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Remove unnecessary semicolons after Q_UNUSED
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index c8e109a05f00ca6046ef081b59dbaf3689f33cb2..a80869dfcb8a09f6e99761e30e0cd882dd0becc2 100644 (file)
 
 #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 <QAccessible>
 #include <QApplication>
 #include <QDrag>
 #include <QGraphicsScene>
@@ -37,8 +37,6 @@
 #include <QGraphicsView>
 #include <QMimeData>
 #include <QTimer>
-#include <QAccessible>
-#include <views/draganddrophelper.h>
 
 KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) :
     QObject(parent),
@@ -63,6 +61,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);
@@ -212,18 +212,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();
@@ -245,6 +233,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();
 
@@ -260,11 +252,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);
@@ -435,8 +424,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
@@ -473,7 +461,9 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
             }
             break;
         }
+    }
 
+    if (navigationPressed) {
         m_view->scrollToItem(index);
     }
     return true;
@@ -484,19 +474,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);
         }
 
@@ -536,7 +525,7 @@ void KItemListController::slotAutoActivationTimeout()
 
 bool KItemListController::inputMethodEvent(QInputMethodEvent* event)
 {
-    Q_UNUSED(event);
+    Q_UNUSED(event)
     return false;
 }
 
@@ -608,6 +597,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);
 
@@ -846,8 +845,8 @@ 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();
 
@@ -856,8 +855,8 @@ bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, con
 
 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);
@@ -970,14 +969,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;
     }
@@ -1008,8 +1007,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;
@@ -1026,15 +1025,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;
 }