From 9aa0e84d974d86cf9366714107e9c84dcde15490 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Fri, 23 Dec 2016 15:35:43 +0100 Subject: Add a DragHandler::translation property This allows the application developer to get the translation of the dragged pointer, and apply it in a custom way. This should usually be combined with setting target to null. This will for instance be needed when we want to drag QtLocations map, where a map is dragged by specifying the geo location of the center of the map. The map2.qml example demonstrates this. Change-Id: I652d9fc92fa9b6dfd3796c7147832f25af0cc5bc Reviewed-by: Shawn Rutledge --- src/quick/handlers/qquickdraghandler.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/quick/handlers/qquickdraghandler.cpp') diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp index dc3116e300..945d60119d 100644 --- a/src/quick/handlers/qquickdraghandler.cpp +++ b/src/quick/handlers/qquickdraghandler.cpp @@ -88,6 +88,7 @@ void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point) if (!m_yAxis.enabled()) delta.setY(0); if (active()) { + setTranslation(delta); if (target() && target()->parentItem()) { QPointF pos = target()->parentItem()->mapFromScene(m_startPos + delta); enforceAxisConstraints(&pos); @@ -122,6 +123,15 @@ void QQuickDragHandler::enforceAxisConstraints(QPointF *localPos) localPos->setY(qBound(m_yAxis.minimum(), localPos->y(), m_yAxis.maximum())); } +void QQuickDragHandler::setTranslation(const QPointF &trans) +{ + if (trans == m_translation) // fuzzy compare? + return; + m_translation = trans; + emit translationChanged(); +} + + QQuickDragAxis::QQuickDragAxis() : m_minimum(-DBL_MAX) , m_maximum(DBL_MAX) -- cgit v1.2.3