diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/quick/handlers/qquickdraghandler.cpp | 3 | ||||
| -rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 7 | ||||
| -rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 69 | ||||
| -rw-r--r-- | src/quick/handlers/qquickpointerhandler_p.h | 6 | ||||
| -rw-r--r-- | src/quick/handlers/qquickpointerhandler_p_p.h | 7 | ||||
| -rw-r--r-- | src/quick/handlers/qquicktaphandler.cpp | 9 | ||||
| -rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 3 | ||||
| -rw-r--r-- | src/quick/items/qquickwindow_p.h | 20 |
8 files changed, 92 insertions, 32 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index 61b66beff4..492897b68b 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -39,6 +39,7 @@ #include "qquickdraghandler_p.h" #include <private/qquickwindow_p.h> +#include <private/qquickmultipointhandler_p_p.h> #include <QDebug> QT_BEGIN_NAMESPACE @@ -228,7 +229,7 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event) accumulatedDragDelta.setY(0); } qreal angle = std::atan2(accumulatedDragDelta.y(), accumulatedDragDelta.x()) * 180 / M_PI; - bool overThreshold = QQuickWindowPrivate::dragOverThreshold(accumulatedDragDelta); + bool overThreshold = d_func()->dragOverThreshold(accumulatedDragDelta); qCDebug(lcDragHandler) << "movement" << accumulatedDragDelta << "angle" << angle << "of point" << point << "pressed @" << point->scenePressPosition() << "over threshold?" << overThreshold; minAngle = qMin(angle, minAngle); diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index a5a867015c..20ad95b0d7 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -43,6 +43,7 @@ #include <private/qsgadaptationlayer_p.h> #include <private/qquickitem_p.h> #include <private/qguiapplication_p.h> +#include <private/qquickmultipointhandler_p_p.h> #include <private/qquickwindow_p.h> #include <QEvent> #include <QMouseEvent> @@ -338,8 +339,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) const QVector2D currentCentroid(centroid().scenePosition()); const QVector2D pressCentroid(centroid().scenePressPosition()); - QStyleHints *styleHints = QGuiApplication::styleHints(); - const int dragThreshold = styleHints->startDragDistance(); + const int dragThreshold = QQuickPointerHandler::dragThreshold(); const int dragThresholdSquared = dragThreshold * dragThreshold; double accumulatedCentroidDistance = 0; // Used to detect scale @@ -399,7 +399,8 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) point->setAccepted(false); // don't stop propagation setPassiveGrab(point); } - if (QQuickWindowPrivate::dragOverThreshold(point)) + Q_D(QQuickMultiPointHandler); + if (d->dragOverThreshold(point)) ++numberOfPointsDraggedOverThreshold; } diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index 12c06aa179..9d4fae1a71 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -113,6 +113,47 @@ void QQuickPointerHandler::setMargin(qreal pointDistanceThreshold) } /*! + \qmlproperty int PointerHandler::dragThreshold + \since 5.15 + + The distance in pixels that the user must drag an event point in order to + have it treated as a drag gesture. + + The default value depends on the platform and screen resolution. + It can be reset back to the default value by setting it to undefined. + The behavior when a drag gesture begins varies in different handlers. +*/ +int QQuickPointerHandler::dragThreshold() const +{ + Q_D(const QQuickPointerHandler); + if (d->dragThreshold < 0) + return qApp->styleHints()->startDragDistance(); + return d->dragThreshold; +} + +void QQuickPointerHandler::setDragThreshold(int t) +{ + Q_D(QQuickPointerHandler); + if (d->dragThreshold == t) + return; + + if (t > std::numeric_limits<qint16>::max()) + qWarning() << "drag threshold cannot exceed" << std::numeric_limits<qint16>::max(); + d->dragThreshold = qint16(t); + emit dragThresholdChanged(); +} + +void QQuickPointerHandler::resetDragThreshold() +{ + Q_D(QQuickPointerHandler); + if (d->dragThreshold < 0) + return; + + d->dragThreshold = -1; + emit dragThresholdChanged(); +} + +/*! Notification that the grab has changed in some way which is relevant to this handler. The \a grabber (subject) will be the Input Handler whose state is changing, or null if the state change regards an Item. @@ -547,4 +588,32 @@ QQuickPointerHandlerPrivate::QQuickPointerHandlerPrivate() { } +template <typename TEventPoint> +bool QQuickPointerHandlerPrivate::dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint *p) const +{ + Q_Q(const QQuickPointerHandler); + QStyleHints *styleHints = qApp->styleHints(); + bool overThreshold = qAbs(d) > q->dragThreshold(); + const bool dragVelocityLimitAvailable = (styleHints->startDragVelocity() > 0); + if (!overThreshold && dragVelocityLimitAvailable) { + qreal velocity = qreal(axis == Qt::XAxis ? p->velocity().x() : p->velocity().y()); + overThreshold |= qAbs(velocity) > styleHints->startDragVelocity(); + } + return overThreshold; +} + +bool QQuickPointerHandlerPrivate::dragOverThreshold(QVector2D delta) const +{ + Q_Q(const QQuickPointerHandler); + const float threshold = q->dragThreshold(); + return qAbs(delta.x()) > threshold || qAbs(delta.y()) > threshold; +} + +bool QQuickPointerHandlerPrivate::dragOverThreshold(const QQuickEventPoint *point) const +{ + QPointF delta = point->scenePosition() - point->scenePressPosition(); + return (dragOverThreshold(delta.x(), Qt::XAxis, point) || + dragOverThreshold(delta.y(), Qt::YAxis, point)); +} + QT_END_NAMESPACE diff --git a/src/quick/handlers/qquickpointerhandler_p.h b/src/quick/handlers/qquickpointerhandler_p.h index c600e42491..995db9c1dc 100644 --- a/src/quick/handlers/qquickpointerhandler_p.h +++ b/src/quick/handlers/qquickpointerhandler_p.h @@ -71,6 +71,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerHandler : public QObject, public QQmlP Q_PROPERTY(QQuickItem * parent READ parentItem CONSTANT) Q_PROPERTY(GrabPermissions grabPermissions READ grabPermissions WRITE setGrabPermissions NOTIFY grabPermissionChanged) Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged) + Q_PROPERTY(int dragThreshold READ dragThreshold WRITE setDragThreshold RESET resetDragThreshold NOTIFY dragThresholdChanged REVISION 15) public: explicit QQuickPointerHandler(QQuickItem *parent = nullptr); @@ -110,11 +111,16 @@ public: qreal margin() const; void setMargin(qreal pointDistanceThreshold); + int dragThreshold() const; + void setDragThreshold(int t); + void resetDragThreshold(); + Q_SIGNALS: void enabledChanged(); void activeChanged(); void targetChanged(); void marginChanged(); + Q_REVISION(15) void dragThresholdChanged(); void grabChanged(QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point); void grabPermissionChanged(); void canceled(QQuickEventPoint *point); diff --git a/src/quick/handlers/qquickpointerhandler_p_p.h b/src/quick/handlers/qquickpointerhandler_p_p.h index 2ea4905643..5727b1ef55 100644 --- a/src/quick/handlers/qquickpointerhandler_p_p.h +++ b/src/quick/handlers/qquickpointerhandler_p_p.h @@ -68,9 +68,16 @@ public: QQuickPointerHandlerPrivate(); + template<typename TEventPoint> + bool dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint *p) const; + + bool dragOverThreshold(QVector2D delta) const; + bool dragOverThreshold(const QQuickEventPoint *point) const; + QQuickPointerEvent *currentEvent = nullptr; QQuickItem *target = nullptr; qreal m_margin = 0; + qint16 dragThreshold = -1; // -1 means use the platform default uint8_t grabPermissions : 8; bool enabled : 1; bool active : 1; diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp index a10064a665..5f9d2151d7 100644 --- a/src/quick/handlers/qquicktaphandler.cpp +++ b/src/quick/handlers/qquicktaphandler.cpp @@ -97,13 +97,6 @@ QQuickTapHandler::QQuickTapHandler(QQuickItem *parent) } } -static bool dragOverThreshold(const QQuickEventPoint *point) -{ - QPointF delta = point->scenePosition() - point->scenePressPosition(); - return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || - QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); -} - bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) { if (!point->pointerEvent()->asPointerMouseEvent() && @@ -115,7 +108,7 @@ bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) // (e.g. DragHandler) gets a chance to take over. // Don't forget to emit released in case of a cancel. bool ret = false; - bool overThreshold = dragOverThreshold(point); + bool overThreshold = d_func()->dragOverThreshold(point); if (overThreshold) { m_longPressTimer.stop(); m_holdTimer.invalidate(); diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index f2098f6732..fbfb7521ea 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -497,6 +497,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) QQuickPointerHandler::tr("ImageBase is an abstract base class")); qmlRegisterType<QQuickImage, 14>(uri, 2, 14, "Image"); qmlRegisterType<QQuickDragHandler, 14>(uri, 2, 14, "DragHandler"); + + qmlRegisterUncreatableType<QQuickPointerHandler, 15>(uri, 2, 15, "PointerHandler", + QQuickPointerHandler::tr("PointerHandler is an abstract base class")); } static void initResources() diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index becbae7fe3..5d44e28bac 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -288,26 +288,6 @@ public: static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int startDragThreshold = -1); - template <typename TEventPoint> - static bool dragOverThreshold(qreal d, Qt::Axis axis, const TEventPoint *p, int startDragThreshold = -1) - { - QStyleHints *styleHints = qApp->styleHints(); - bool overThreshold = qAbs(d) > (startDragThreshold >= 0 ? startDragThreshold : styleHints->startDragDistance()); - const bool dragVelocityLimitAvailable = (styleHints->startDragVelocity() > 0); - if (!overThreshold && dragVelocityLimitAvailable) { - qreal velocity = axis == Qt::XAxis ? p->velocity().x() : p->velocity().y(); - overThreshold |= qAbs(velocity) > styleHints->startDragVelocity(); - } - return overThreshold; - } - - static bool dragOverThreshold(const QQuickEventPoint *point) - { - QPointF delta = point->scenePosition() - point->scenePressPosition(); - return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || - QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); - } - static bool dragOverThreshold(QVector2D delta); // data property |
