]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Simplify implementation of mouse long-press detection
authorFelix Ernst <fe.a.ernst@gmail.com>
Thu, 26 May 2022 10:56:03 +0000 (12:56 +0200)
committerFelix Ernst <fe.a.ernst@gmail.com>
Sun, 14 Aug 2022 14:42:40 +0000 (14:42 +0000)
Now uses the same method as for touch long-press detection.

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistcontroller.h

index 2c407dbe2d9afb7a9afbfca05b841636116fe3d1..b589ac356ee902fd409b6fbfed41bd88fe866430 100644 (file)
@@ -53,7 +53,6 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v
     m_pressedIndex(std::nullopt),
     m_pressedMousePos(),
     m_autoActivationTimer(nullptr),
-    m_longPressDetectionTimer(nullptr),
     m_swipeGesture(Qt::CustomGesture),
     m_twoFingerTapGesture(Qt::CustomGesture),
     m_oldSelection(),
@@ -72,15 +71,6 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v
     m_autoActivationTimer->setInterval(-1);
     connect(m_autoActivationTimer, &QTimer::timeout, this, &KItemListController::slotAutoActivationTimeout);
 
-    m_longPressDetectionTimer = new QTimer(this);
-    m_longPressDetectionTimer->setSingleShot(true);
-    m_longPressDetectionTimer->setInterval(QGuiApplication::styleHints()->mousePressAndHoldInterval());
-    connect(m_longPressDetectionTimer, &QTimer::timeout, this, [this]() {
-        if (!m_selectionMode) {
-            Q_EMIT selectionModeChangeRequested(true);
-        }
-    });
-
     setModel(model);
     setView(view);
 
@@ -601,9 +591,6 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const
     }
 
     const QPointF pos = transform.map(event->pos());
-    if ((pos - m_pressedMousePos).manhattanLength() >= QApplication::startDragDistance()) {
-        m_longPressDetectionTimer->stop();
-    }
 
     if (m_pressedIndex.has_value() && !m_view->rubberBand()->isActive()) {
         // Check whether a dragging should be started
@@ -667,8 +654,6 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
         m_view->m_tapAndHoldIndicator->setActive(false);
     }
 
-    m_longPressDetectionTimer->stop();
-
     KItemListRubberBand* rubberBand = m_view->rubberBand();
     if (event->source() == Qt::MouseEventSynthesizedByQt && !rubberBand->isActive() && m_isTouchEvent) {
         return false;
@@ -1075,6 +1060,7 @@ void KItemListController::tapAndHoldTriggered(QGestureEvent* event, const QTrans
 
     //the Qt TabAndHold gesture is triggerable with a mouse click, we don't want this
     if (!m_isTouchEvent) {
+        Q_EMIT selectionModeChangeRequested(true);
         return;
     }
 
@@ -1553,10 +1539,6 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c
     const bool leftClick = buttons & Qt::LeftButton;
     const bool rightClick = buttons & Qt::RightButton;
 
-    if (leftClick) {
-        m_longPressDetectionTimer->start();
-    }
-
     // The previous selection is cleared if either
     // 1. The selection mode is SingleSelection, or
     // 2. the selection mode is MultiSelection, and *none* of the following conditions are met:
index 515511f863ff3e1825fb420fa9a4c80c8af8a855..b6a2f05feeec5986c7843f5b488d4c289df72826 100644 (file)
@@ -363,7 +363,6 @@ private:
     QPointF m_pressedMousePos;
 
     QTimer* m_autoActivationTimer;
-    QTimer* m_longPressDetectionTimer;
 
     Qt::GestureType m_swipeGesture;
     Qt::GestureType m_twoFingerTapGesture;