7#include <QtCore/qmath.h>
8#include <QtGui/qevent.h>
9#include <QtGui/qguiapplication.h>
10#include <QtGui/qstylehints.h>
11#include <qpa/qplatformintegration.h>
12#include <qpa/qplatformnativeinterface.h>
13#include <private/qguiapplication_p.h>
120 : m_target(
nullptr), m_minScale(1.0), m_maxScale(1.0)
121 , m_minRotation(0.0), m_maxRotation(0.0)
122 , m_axis(NoDrag), m_xmin(-FLT_MAX), m_xmax(FLT_MAX)
273 if (
a !=
d->enabled) {
300 switch (
event->type()) {
303 d->touchPoints.clear();
304 for (
int i = 0;
i <
event->pointCount(); ++
i) {
305 auto &tp =
event->point(
i);
307 d->touchPoints << tp;
311 updatePinch(
event,
false);
328 d->touchPoints.clear();
333 pe.setStartCenter(
d->pinchStartCenter);
334 pe.setPreviousCenter(pinchCenter);
335 pe.setPreviousAngle(
d->pinchLastAngle);
336 pe.setPreviousScale(
d->pinchLastScale);
342 if (
d->pinch &&
d->pinch->target())
343 d->pinch->setActive(
false);
345 d->pinchStartDist = 0;
346 d->pinchActivated =
false;
347 d->initPinch =
false;
348 d->pinchRejected =
false;
352 if (
event->exclusiveGrabber(point) ==
this)
353 event->setExclusiveGrabber(point,
nullptr);
364 d->touchPoints.clear();
368 QQuickPinchEvent pe(
d->pinchStartCenter,
d->pinchStartScale,
d->pinchStartAngle,
d->pinchStartRotation);
369 pe.setStartCenter(
d->pinchStartCenter);
370 pe.setPreviousCenter(pinchCenter);
371 pe.setPreviousAngle(
d->pinchLastAngle);
372 pe.setPreviousScale(
d->pinchLastScale);
375 pe.setPoint1(pe.startPoint1());
376 pe.setPoint2(pe.startPoint2());
379 d->pinchLastScale =
d->pinchStartScale;
380 d->sceneLastCenter =
d->sceneStartCenter;
381 d->pinchLastAngle =
d->pinchStartAngle;
382 d->lastPoint1 = pe.startPoint1();
383 d->lastPoint2 = pe.startPoint2();
386 if (
d->pinch &&
d->pinch->target())
387 d->pinch->setActive(
false);
389 d->pinchStartDist = 0;
390 d->pinchActivated =
false;
391 d->initPinch =
false;
392 d->pinchRejected =
false;
395 if (
event->exclusiveGrabber(point) ==
this)
396 event->setExclusiveGrabber(point,
nullptr);
406 if (
d->touchPoints.size() < 2) {
416 if (filtering && !
d->touchPoints.isEmpty() &&
event->exclusiveGrabber(
d->touchPoints.first()) ==
this)
417 event->setExclusiveGrabber(
d->touchPoints.first(),
nullptr);
420 if (
d->touchPoints.size() == 0) {
425 pe.setStartCenter(
d->pinchStartCenter);
426 pe.setPreviousCenter(pinchCenter);
427 pe.setPreviousAngle(
d->pinchLastAngle);
428 pe.setPreviousScale(
d->pinchLastScale);
436 d->pinchStartDist = 0;
437 d->pinchActivated =
false;
438 if (
d->pinch &&
d->pinch->target())
439 d->pinch->setActive(
false);
441 d->initPinch =
false;
442 d->pinchRejected =
false;
447 QEventPoint touchPoint2 =
d->touchPoints.at(
d->touchPoints.size() >= 2 ? 1 : 0);
455 qCDebug(lcPA) <<
"updating based on" << touchPoint1 << touchPoint2;
461 if (
d->touchPoints.size() == 2
464 d->id1 = touchPoint1.
id();
465 if (!
d->pinchActivated)
466 qCDebug(lcPA,
"pinch activating");
467 d->pinchActivated =
true;
469 event->setExclusiveGrabber(touchPoint1,
this);
470 event->setExclusiveGrabber(touchPoint2,
this);
474 if (
d->pinchActivated && !
d->pinchRejected) {
477 QPointF p2 = touchPoint2.scenePosition();
483 if (
d->touchPoints.size() == 1) {
485 if (
d->id1 == touchPoint1.
id())
486 sceneCenter =
d->sceneLastCenter + touchPoint1.
scenePosition() -
d->lastPoint1;
488 sceneCenter =
d->sceneLastCenter + touchPoint2.scenePosition() -
d->lastPoint2;
489 angle =
d->pinchLastAngle;
491 d->id1 = touchPoint1.
id();
494 qCDebug(lcPA,
"pinch \u2316 %.1lf,%.1lf \u21e4%.1lf\u21e5 \u2220 %.1lf",
496 if (!
d->inPinch ||
d->initPinch) {
497 if (
d->touchPoints.size() >= 2) {
500 d->pinchStartDist =
dist;
501 d->initPinch =
false;
503 d->sceneStartCenter = sceneCenter;
504 d->sceneLastCenter = sceneCenter;
506 d->pinchStartAngle =
angle;
507 d->pinchLastScale = 1.0;
508 d->pinchLastAngle =
angle;
509 d->pinchRotation = 0.0;
512 if (
qAbs(
dist -
d->pinchStartDist) >= dragThreshold ||
514 (
qAbs(
p1.x()-
d->sceneStartPoint1.x()) >= dragThreshold
515 ||
qAbs(
p1.y()-
d->sceneStartPoint1.y()) >= dragThreshold
516 ||
qAbs(
p2.x()-
d->sceneStartPoint2.x()) >= dragThreshold
517 ||
qAbs(
p2.y()-
d->sceneStartPoint2.y()) >= dragThreshold))) {
519 d->pinchStartDist =
dist;
520 pe.setStartCenter(
d->pinchStartCenter);
521 pe.setPreviousCenter(
d->pinchStartCenter);
522 pe.setPreviousAngle(
d->pinchLastAngle);
523 pe.setPreviousScale(
d->pinchLastScale);
528 pe.setPointCount(
d->touchPoints.size());
532 event->setExclusiveGrabber(touchPoint1,
this);
533 event->setExclusiveGrabber(touchPoint2,
this);
539 if (
d->pinch &&
d->pinch->target()) {
541 d->pinchStartPos = targetParent ?
544 d->pinchStartScale =
d->pinch->target()->scale();
545 d->pinchStartRotation =
d->pinch->target()->rotation();
546 d->pinch->setActive(
true);
549 d->pinchRejected =
true;
553 }
else if (
d->pinchStartDist > 0) {
560 d->pinchRotation += da;
563 pe.setStartCenter(
d->pinchStartCenter);
565 pe.setPreviousAngle(
d->pinchLastAngle);
566 pe.setPreviousScale(
d->pinchLastScale);
569 pe.setPoint1(touchPoint1.
position());
570 pe.setPoint2(touchPoint2.position());
571 pe.setPointCount(
d->touchPoints.size());
572 d->pinchLastScale =
scale;
573 d->sceneLastCenter = sceneCenter;
574 d->pinchLastAngle =
angle;
576 d->lastPoint2 = touchPoint2.scenePosition();
583void QQuickPinchArea::updatePinchTarget()
586 if (
d->pinch &&
d->pinch->target()) {
587 qreal s =
d->pinchStartScale *
d->pinchLastScale;
590 QPointF pos =
d->sceneLastCenter -
d->sceneStartCenter +
d->pinchStartPos;
592 pos = targetParent->mapFromScene(
pos);
598 else if (
x >
pinch()->xmax())
606 else if (
y >
pinch()->ymax())
610 if (
d->pinchStartRotation >=
pinch()->minimumRotation()
611 &&
d->pinchStartRotation <=
pinch()->maximumRotation()) {
612 qreal r =
d->pinchRotation +
d->pinchStartRotation;
639 const auto &
points = te->points();
640 d->touchPoints.clear();
643 d->touchPoints << tp;
645 updatePinch(te,
true);
647 e->setAccepted(
d->inPinch);
675 switch (
event->type()) {
676#if QT_CONFIG(gestures)
679 switch (gesture->gestureType()) {
682 d->pinchStartCenter = gesture->position();
683 d->pinchStartAngle = 0.0;
684 d->pinchStartRotation = 0.0;
685 d->pinchRotation = 0.0;
686 d->pinchStartScale = 1.0;
687 d->pinchLastAngle = 0.0;
688 d->pinchLastScale = 1.0;
689 d->sceneStartPoint1 = gesture->scenePosition();
690 d->sceneStartPoint2 = gesture->scenePosition();
691 d->lastPoint1 = gesture->scenePosition();
692 d->lastPoint2 = gesture->scenePosition();
693 if (
d->pinch &&
d->pinch->target()) {
694 d->pinchStartPos =
d->pinch->target()->position();
695 d->pinchStartScale =
d->pinch->target()->scale();
696 d->pinchStartRotation =
d->pinch->target()->rotation();
697 d->pinch->setActive(
true);
704 if (
d->pinchRejected)
706 qreal scale =
d->pinchLastScale * (1.0 + gesture->value());
717 d->pinchLastScale =
scale;
726 d->pinchRejected =
true;
729 if (gesture->value() > 0.0 &&
d->pinch &&
d->pinch->target()) {
732 d->pinchStartScale =
d->pinch->target()->scale();
733 d->pinchStartRotation =
d->pinch->target()->rotation();
734 d->pinchLastScale =
d->pinchStartScale =
d->pinch->target()->scale();
735 d->pinchLastAngle =
d->pinchStartRotation =
d->pinch->target()->rotation();
737 QQuickPinchEvent pe(gesture->position(), gesture->value(),
d->pinchLastAngle, 0.0);
750 if (
d->pinchRejected)
752 qreal angle =
d->pinchLastAngle + gesture->value();
763 d->pinchLastAngle =
angle;
773 d->pinchRejected =
true;
800#include "moc_qquickpincharea_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
int id
the ID number of this event point.
QPointF scenePosition
the scene position of this point.
State state
the current state of the event point.
QPointF position
the position of this point.
static QStyleHints * styleHints()
Returns the application's style hints.
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
\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.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
bool event(QEvent *) override
\reimp
void setKeepTouchGrab(bool)
Sets whether the touch points grabbed by this item should remain exclusively with this item.
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
Q_INVOKABLE QPointF mapToItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in this item's coordinate system to the equivalent point within item's coordinat...
void setAcceptHoverEvents(bool enabled)
If enabled is true, this sets the item to accept hover events; otherwise, hover events are not accept...
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...
void setAcceptTouchEvents(bool accept)
If enabled is true, this sets the item to accept touch events; otherwise, touch events are not accept...
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
QQuickItem * parentItem() const
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
void setKeepMouseGrab(bool)
Sets whether the mouse input should remain exclusively with this item.
virtual void touchEvent(QTouchEvent *event)
This event handler can be reimplemented in a subclass to receive touch events for an item.
virtual bool childMouseEventFilter(QQuickItem *, QEvent *)
Reimplement this method to filter the pointer events that are received by this item's children.
virtual QRectF clipRect() const
Returns the rectangular area within this item that is currently visible in \l viewportItem(),...
qreal scale
\qmlproperty real QtQuick::Item::scale This property holds the scale factor for this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
~QQuickPinchAreaPrivate()
bool event(QEvent *) override
\reimp
bool isEnabled() const
\qmlproperty bool QtQuick::PinchArea::enabled This property holds whether the item accepts pinch gest...
bool childMouseEventFilter(QQuickItem *i, QEvent *e) override
void pinchFinished(QQuickPinchEvent *pinch)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void pinchUpdated(QQuickPinchEvent *pinch)
QQuickPinchArea(QQuickItem *parent=nullptr)
\qmltype PinchArea \instantiates QQuickPinchArea \inqmlmodule QtQuick\inherits Item
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
void pinchStarted(QQuickPinchEvent *pinch)
void touchEvent(QTouchEvent *event) override
This event handler can be reimplemented in a subclass to receive touch events for an item.
void setPreviousCenter(QPointF c)
void setPreviousScale(qreal s)
void setStartPoint2(QPointF p)
void setStartPoint1(QPointF p)
void setPoint1(QPointF p)
void setStartCenter(QPointF c)
void setPoint2(QPointF p)
void setPointCount(int count)
void setPreviousAngle(qreal a)
\inmodule QtCore\reentrant
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
int startDragDistance
the distance, in pixels, that the mouse must be moved with a button held down before a drag and drop ...
The QTouchEvent class contains parameters that describe a touch event.
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qfloat16 qSqrt(qfloat16 f)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLfixed GLfixed GLint GLint GLfixed points
GLenum GLenum GLenum GLenum GLenum scale
std::uniform_real_distribution dist(1, 2.5)
[2]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent