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 if (g->scaleFactor() != ev->value()) {
58 g->setLastScaleFactor(g->scaleFactor());
59 g->setScaleFactor(ev->value());
60 g->setTotalScaleFactor(g->totalScaleFactor() * g->scaleFactor());
61 g->setChangeFlags(g->changeFlags() | QPinchGesture::ScaleFactorChanged);
62 }
63
64 if (g->changeFlags() != 0)
65 result = QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
66 break;
67 case Qt::RotateNativeGesture:
68 g->setChangeFlags({});
69 g->setHotSpot(ev->globalPosition());
70
71 if (g->centerPoint() != ev->globalPosition().toPoint()) {
72 g->setLastCenterPoint(g->centerPoint());
73 g->setCenterPoint(ev->globalPosition().toPoint());
74 g->setChangeFlags(g->changeFlags() | QPinchGesture::CenterPointChanged);
75 }
76
77 if (g->rotationAngle() != ev->value()) {
78 g->setLastRotationAngle(g->rotationAngle());
79 g->setRotationAngle(ev->value());
80 g->setTotalRotationAngle(g->rotationAngle());
81 g->setChangeFlags(g->changeFlags() | QPinchGesture::RotationAngleChanged);
82 }
83
84 if (g->changeFlags() != 0)
85 result = QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
86 break;
87 default:
88 break;
89 };
90 }
91
92 g->setTotalChangeFlags(g->totalChangeFlags() |= g->changeFlags());
93
94 return result;
95}
96
97void QOhosPinchGestureRecognizer::reset(QGesture *gesture)
98{
99 auto *g = static_cast<QPinchGesture *>(gesture);
100 g->setChangeFlags({});
101 g->setTotalChangeFlags({});
102 g->setScaleFactor(1.0f);
103 g->setTotalScaleFactor(1.0f);
104 g->setLastScaleFactor(1.0f);
105 g->setRotationAngle(0.0f);
106 g->setTotalRotationAngle(0.0f);
107 g->setLastRotationAngle(0.0f);
108 g->setCenterPoint(QPointF());
109 g->setStartCenterPoint(QPointF());
110 g->setLastCenterPoint(QPointF());
111 QGestureRecognizer::reset(gesture);
112}
113
118
119QT_END_NAMESPACE
120
121#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()