5#include <private/qquickwindow_p.h>
6#include <private/qquickmultipointhandler_p_p.h>
63QPointF QQuickDragHandler::targetCentroidPosition()
87 }
else if (m_pressTargetPos.
isNull()) {
88 m_pressTargetPos = targetCentroidPosition();
114 if (
mode == m_snapMode)
117 emit snapModeChanged();
123 const bool curActive =
active();
137 m_pressedInsideTarget =
false;
156#if QT_CONFIG(gestures)
170 event->setAccepted(
true);
177 accumulatedDragDelta.setX(0);
179 accumulatedDragDelta.setY(0);
185 qreal minAngle = 361;
186 qreal maxAngle = -361;
190 QVector<QEventPoint> chosenPoints;
192 if (
event->isBeginEvent())
196 if (!allOverThreshold)
198 auto point =
event->pointById(
p.id());
200 chosenPoints << *point;
204 QVector2D accumulatedDragDelta =
QVector2D(point->scenePosition() - point->scenePressPosition());
208 if (
qAbs(accumulatedDragDelta.x()) >
qAbs(accumulatedDragDelta.y()))
209 accumulatedDragDelta.setY(0);
210 accumulatedDragDelta.setX(0);
215 if (
qAbs(accumulatedDragDelta.y()) >
qAbs(accumulatedDragDelta.x()))
216 accumulatedDragDelta.setX(0);
217 accumulatedDragDelta.setY(0);
219 qreal angle = std::atan2(accumulatedDragDelta.y(), accumulatedDragDelta.x()) * 180 /
M_PI;
220 bool overThreshold = d_func()->dragOverThreshold(accumulatedDragDelta);
221 qCDebug(lcDragHandler) <<
"movement" << accumulatedDragDelta <<
"angle" <<
angle <<
"of point" << point
222 <<
"pressed @" << point->scenePressPosition() <<
"over threshold?" << overThreshold;
225 if (allOverThreshold && !overThreshold)
226 allOverThreshold =
false;
228 if (
event->isBeginEvent()) {
235 m_pressTargetPos = targetCentroidPosition();
244 if (allOverThreshold) {
245 qreal angleDiff = maxAngle - minAngle;
247 angleDiff = 360 - angleDiff;
248 qCDebug(lcDragHandler) <<
"angle min" << minAngle <<
"max" << maxAngle <<
"range" << angleDiff;
254 const QPointF newTargetTopLeft = targetCentroidPosition() - m_pressTargetPos;
256 const QPointF targetXformOrigin = newTargetTopLeft + xformOrigin;
263 pos.setY(targetItemPos.y());
264 enforceAxisConstraints(&
pos);
269void QQuickDragHandler::enforceAxisConstraints(
QPointF *localPos)
296 qCDebug(lcDragHandler) <<
"translation: delta" << delta
373#include "moc_qquickdraghandler_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
qsizetype size() const noexcept
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
constexpr void setY(qreal y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr void setX(qreal x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
A base class for pointer events.
GrabTransition
This enum represents a transition of exclusive or passive grab from one object (possibly nullptr) to ...
static bool isTouchEvent(const QPointerEvent *ev)
static bool isMouseEvent(const QPointerEvent *ev)
void onActiveChanged(bool active, qreal initActiveValue)
void updateValue(qreal activeValue, qreal accumulatedValue, qreal delta=0)
qreal persistentValue() const
void setSnapMode(QQuickDragHandler::SnapMode mode)
void setPersistentTranslation(const QVector2D &trans)
@ SnapIfPressedOutsideTarget
QVector2D activeTranslation
void translationChanged(QVector2D delta)
void onActiveChanged() override
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
void setActiveTranslation(const QVector2D &trans)
void handlePointerEventImpl(QPointerEvent *event) override
This function can be overridden to implement whatever behavior a specific subclass is intended to hav...
void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override
Notification that the grab has changed in some way which is relevant to this handler.
QVector2D persistentTranslation
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setKeepTouchGrab(bool)
Sets whether the touch points grabbed by this item should remain exclusively with this item.
Q_INVOKABLE QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in item's coordinate system to the equivalent point within this item's coordinat...
QPointF mapFromScene(const QPointF &point) const
Maps the given point in the scene's coordinate system to the equivalent point within this item's coor...
virtual Q_INVOKABLE bool contains(const QPointF &point) const
\qmlmethod bool QtQuick::Item::contains(point point)
QQuickItem * parentItem() const
void setKeepMouseGrab(bool)
Sets whether the mouse input should remain exclusively with this item.
bool isAncestorOf(const QQuickItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child's parent,...
QPointF transformOriginPoint
void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override
Notification that the grab has changed in some way which is relevant to this handler.
void handlePointerEventImpl(QPointerEvent *event) override
This function can be overridden to implement whatever behavior a specific subclass is intended to hav...
QList< QQuickHandlerPoint > & currentPoints()
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
void onActiveChanged() override
QQuickHandlerPoint centroid
bool grabPoints(QPointerEvent *event, const QVector< QEventPoint > &points)
void moveTarget(QPointF pos)
QQuickItem * parentItem() const
\qmlproperty Item QtQuick::PointerHandler::parent
void setPassiveGrab(QPointerEvent *event, const QEventPoint &point, bool grab=true)
Acquire or give up a passive grab of the given point, according to the grab state.
QPointerEvent * currentEvent()
void setActive(bool active)
The QTouchEvent class contains parameters that describe a touch event.
bool isEndEvent() const override
Returns true if this event includes at least one newly-released touchpoint.
The QVector2D class represents a vector or vertex in 2D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLint GLsizei GLsizei height
static QT_BEGIN_NAMESPACE const qreal DragAngleToleranceDegrees