Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosgesturerecognizer.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qevent.h"
5#include "qgesture.h"
7#include <QtCore/qcoreapplication.h>
8
9#ifndef QT_NO_GESTURES
10
12
14{
15public:
16 QGesture *create(QObject *target) override;
19 void reset(QGesture *gesture) override;
20};
21
23{
24 return new QPinchGesture;
25}
26
27QGestureRecognizer::Result
28QOhosPinchGestureRecognizer::recognize(QGesture *gesture, QObject *, QEvent *event)
29{
30 auto *g = static_cast<QPinchGesture *>(gesture);
31
32 QGestureRecognizer::Result result = QGestureRecognizer::Ignore;
33 if (event->type() == QEvent::NativeGesture) {
34 const auto *ev = static_cast<QNativeGestureEvent *>(event);
35
36 switch (ev->gestureType()) {
37 case Qt::BeginNativeGesture:
38 g->setStartCenterPoint(ev->globalPosition().toPoint());
39 result = QGestureRecognizer::MayBeGesture;
40 reset(g);
41 break;
42 case Qt::EndNativeGesture:
43 result = (g->state() != Qt::NoGesture)
44 ? QGestureRecognizer::FinishGesture
45 : QGestureRecognizer::CancelGesture;
46 break;
47 case Qt::ZoomNativeGesture:
48 g->setChangeFlags({});
49 g->setHotSpot(ev->globalPosition());
50
51 if (g->centerPoint() != ev->globalPosition().toPoint()) {
52 g->setLastCenterPoint(g->centerPoint());
53 g->setCenterPoint(ev->globalPosition().toPoint());
54 g->setChangeFlags(g->changeFlags() | QPinchGesture::CenterPointChanged);
55 }
56
57 // value is an incremental delta, so the per-event scale factor is (1.0 + value).
58 if (!qFuzzyIsNull(ev->value())) {
59 g->setLastScaleFactor(g->scaleFactor());
60 g->setScaleFactor(1.0 + ev->value());
61 g->setTotalScaleFactor(g->totalScaleFactor() * g->scaleFactor());
62 g->setChangeFlags(g->changeFlags() | QPinchGesture::ScaleFactorChanged);
63 }
64
65 if (g->changeFlags() != 0)
66 result = QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
67 break;
68 case Qt::RotateNativeGesture:
69 g->setChangeFlags({});
70 g->setHotSpot(ev->globalPosition());
71
72 if (g->centerPoint() != ev->globalPosition().toPoint()) {
73 g->setLastCenterPoint(g->centerPoint());
74 g->setCenterPoint(ev->globalPosition().toPoint());
75 g->setChangeFlags(g->changeFlags() | QPinchGesture::CenterPointChanged);
76 }
77
78 // value is an incremental delta, so accumulate it into the angle.
79 if (!qFuzzyIsNull(ev->value())) {
80 g->setLastRotationAngle(g->rotationAngle());
81 g->setRotationAngle(g->rotationAngle() + ev->value());
82 g->setTotalRotationAngle(g->totalRotationAngle() + ev->value());
83 g->setChangeFlags(g->changeFlags() | QPinchGesture::RotationAngleChanged);
84 }
85
86 if (g->changeFlags() != 0)
87 result = QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
88 break;
89 default:
90 break;
91 };
92 }
93
94 g->setTotalChangeFlags(g->totalChangeFlags() |= g->changeFlags());
95
96 return result;
97}
98
99void QOhosPinchGestureRecognizer::reset(QGesture *gesture)
100{
101 auto *g = static_cast<QPinchGesture *>(gesture);
102 g->setChangeFlags({});
103 g->setTotalChangeFlags({});
104 g->setScaleFactor(1.0f);
105 g->setTotalScaleFactor(1.0f);
106 g->setLastScaleFactor(1.0f);
107 g->setRotationAngle(0.0f);
108 g->setTotalRotationAngle(0.0f);
109 g->setLastRotationAngle(0.0f);
110 g->setCenterPoint(QPointF());
111 g->setStartCenterPoint(QPointF());
112 g->setLastCenterPoint(QPointF());
113 QGestureRecognizer::reset(gesture);
114}
115
120
121QT_END_NAMESPACE
122
123#endif // QT_NO_GESTURES
QGesture * create(QObject *target) override
This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraph...
void reset(QGesture *gesture) override
This function is called by Qt to reset a given gesture.
Combined button and popup list for selecting options.
std::unique_ptr< QGestureRecognizer > makeQOhosPinchGestureRecognizer()