Paste P196

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Apr 25 2018, 2:24 PM.
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp
index 041780257..7a06d986f 100644
--- a/src/quick/handlers/qquickdraghandler.cpp
+++ b/src/quick/handlers/qquickdraghandler.cpp
@@ -142,8 +142,12 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point)
m_pressTargetPos = localTargetPosition(point);
}
m_pressScenePos = point->scenePosition();
+ m_longPressTimer.start(m_longPressThreshold, this);
setPassiveGrab(point);
break;
+ case QQuickEventPoint::Released:
+ m_longPressTimer.stop();
+ break;
case QQuickEventPoint::Updated: {
QVector2D accumulatedDragDelta = QVector2D(point->scenePosition() - m_pressScenePos);
if (active()) {
@@ -168,18 +172,10 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point)
enforceAxisConstraints(&pos);
moveTarget(pos, point);
}
- } else if (!point->exclusiveGrabber() &&
+ } else if (!point->exclusiveGrabber() && !m_longPressTimer.isActive() && //timer & distance need to be triggered to start drag
((m_xAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(accumulatedDragDelta.x(), Qt::XAxis, point)) ||
(m_yAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(accumulatedDragDelta.y(), Qt::YAxis, point)))) {
- setExclusiveGrab(point);
- if (auto parent = parentItem()) {
- if (point->pointerEvent()->asPointerTouchEvent())
- parent->setKeepTouchGrab(true);
- // tablet and mouse are treated the same by Item's legacy event handling, and
- // touch becomes synth-mouse for Flickable, so we need to prevent stealing
- // mouse grab too, whenever dragging occurs in an enabled direction
- parent->setKeepMouseGrab(true);
- }
+ doDrag(point);
}
} break;
default:
@@ -187,6 +183,31 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point)
}
}
+void QQuickDragHandler::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() != m_longPressTimer.timerId())
+ return;
+
+// auto point = point();
+// if (!point.exclusiveGrabber()) {
+// doDrag(&point);
+ m_longPressTimer.stop();
+// }
+}
+
+void QQuickDragHandler::doDrag(QQuickEventPoint *point)
+{
+ setExclusiveGrab(point);
+ if (auto parent = parentItem()) {
+ if (point->pointerEvent()->asPointerTouchEvent())
+ parent->setKeepTouchGrab(true);
+ // tablet and mouse are treated the same by Item's legacy event handling, and
+ // touch becomes synth-mouse for Flickable, so we need to prevent stealing
+ // mouse grab too, whenever dragging occurs in an enabled direction
+ parent->setKeepMouseGrab(true);
+ }
+}
+
void QQuickDragHandler::enforceConstraints()
{
if (!target() || !target()->parentItem())
@@ -214,6 +235,14 @@ void QQuickDragHandler::setTranslation(const QVector2D &trans)
emit translationChanged();
}
+void QQuickDragHandler::setLongPressThreshold(int threshold)
+{
+ if (threshold == m_longPressThreshold)
+ return;
+ m_longPressThreshold = threshold;
+ emit longPressThresholdChanged();
+}
+
/*!
\qmlpropertygroup QtQuick::DragHandler::xAxis
\qmlproperty real QtQuick::DragHandler::xAxis.minimum
diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h
index 363df31a6..78fdce588 100644
--- a/src/quick/handlers/qquickdraghandler_p.h
+++ b/src/quick/handlers/qquickdraghandler_p.h
@@ -40,6 +40,8 @@
#ifndef QQUICKDRAGHANDLER_H
#define QQUICKDRAGHANDLER_H
+#include <QtCore/qbasictimer.h>
+
//
// W A R N I N G
// -------------
@@ -90,6 +92,7 @@ class Q_AUTOTEST_EXPORT QQuickDragHandler : public QQuickSinglePointHandler
Q_OBJECT
Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT)
Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT)
+ Q_PROPERTY(int longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged)
Q_PROPERTY(QVector2D translation READ translation NOTIFY translationChanged)
public:
@@ -104,22 +107,29 @@ public:
QVector2D translation() const { return m_translation; }
void setTranslation(const QVector2D &trans);
+ int longPressThreshold() const { return m_longPressThreshold; }
+ void setLongPressThreshold(int dragDelay);
+
Q_INVOKABLE void enforceConstraints();
Q_SIGNALS:
// void gestureStarted(QQuickGestureEvent *gesture);
void translationChanged();
+ void longPressThresholdChanged();
protected:
+ void timerEvent(QTimerEvent *event) override;
bool wantsEventPoint(QQuickEventPoint *point) override;
void onActiveChanged() override;
void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point) override;
private:
+ void doDrag(QQuickEventPoint *point);
void ungrab();
void enforceAxisConstraints(QPointF *localPos);
bool targetContains(QQuickEventPoint *point);
QPointF localTargetPosition(QQuickEventPoint *point);
+ QPointer<QPointerDevice> m_pressedDevice;
private:
QPointF m_pressScenePos;
@@ -130,6 +140,8 @@ private:
QQuickDragAxis m_xAxis;
QQuickDragAxis m_yAxis;
+ int m_longPressThreshold = 0;
+ QBasicTimer m_longPressTimer;
bool m_pressedInsideTarget = false;
friend class QQuickDragAxis;
diff --git a/tests/auto/qml/ecmascripttests/test262 b/tests/auto/qml/ecmascripttests/test262
index e505c11ee..d60c4ed97 160000
--- a/tests/auto/qml/ecmascripttests/test262
+++ b/tests/auto/qml/ecmascripttests/test262
@@ -1 +1 @@
-Subproject commit e505c11eebe5a389a7d47a4bf570c66469740b01
+Subproject commit d60c4ed97e69639bc5bc1db43a98828debf80c8a
davidedmundson edited the content of this paste. (Show Details)Apr 25 2018, 2:24 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.
davidedmundson updated the paste's language from autodetect to autodetect.