Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgesture.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qgesture.h"
5#include "private/qgesture_p.h"
6#include "private/qstandardgestures_p.h"
7#if QT_CONFIG(graphicsview)
8#include "qgraphicsview.h"
9#endif
10
11#include <private/qdebug_p.h>
12#ifndef QT_NO_GESTURES
13
15
18QT_IMPL_METATYPE_EXTERN_TAGGED(QPinchGesture::ChangeFlags,
19 QPinchGesture__ChangeFlags)
21 QGesture__GestureCancelPolicy)
22
23
76 : QObject(*new QGesturePrivate, parent)
77{
78 d_func()->gestureType = Qt::CustomGesture;
79}
80
85 : QObject(dd, parent)
86{
87}
88
95
125{
126 return d_func()->gestureType;
127}
128
130{
131 return d_func()->state;
132}
133
135{
136 return d_func()->hotSpot;
137}
138
140{
141 Q_D(QGesture);
142 d->hotSpot = value;
143 d->isHotSpotSet = true;
144}
145
147{
148 return d_func()->isHotSpotSet;
149}
150
152{
153 d_func()->isHotSpotSet = false;
154}
155
180{
181 Q_D(QGesture);
182 d->gestureCancelPolicy = static_cast<uint>(policy);
183}
184
186{
187 Q_D(const QGesture);
188 return static_cast<GestureCancelPolicy>(d->gestureCancelPolicy);
189}
190
265 : QGesture(*new QPanGesturePrivate, parent)
266{
267 d_func()->gestureType = Qt::PanGesture;
268}
269
276
278{
279 return d_func()->lastOffset;
280}
281
283{
284 return d_func()->offset;
285}
286
288{
289 Q_D(const QPanGesture);
290 return d->offset - d->lastOffset;
291}
292
294{
295 return d_func()->acceleration;
296}
297
299{
300 d_func()->lastOffset = value;
301}
302
304{
305 d_func()->offset = value;
306}
307
309{
310 d_func()->acceleration = value;
311}
312
466
473
474QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const
475{
476 return d_func()->totalChangeFlags;
477}
478
479void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value)
480{
481 d_func()->totalChangeFlags = value;
482}
483
484QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const
485{
486 return d_func()->changeFlags;
487}
488
489void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value)
490{
491 d_func()->changeFlags = value;
492}
493
495{
496 return d_func()->startCenterPoint;
497}
498
500{
501 return d_func()->lastCenterPoint;
502}
503
505{
506 return d_func()->centerPoint;
507}
508
510{
511 d_func()->startCenterPoint = value;
512}
513
515{
516 d_func()->lastCenterPoint = value;
517}
518
520{
521 d_func()->centerPoint = value;
522}
523
524
526{
527 return d_func()->totalScaleFactor;
528}
529
531{
532 return d_func()->lastScaleFactor;
533}
534
536{
537 return d_func()->scaleFactor;
538}
539
541{
542 d_func()->totalScaleFactor = value;
543}
544
546{
547 d_func()->lastScaleFactor = value;
548}
549
551{
552 d_func()->scaleFactor = value;
553}
554
555
557{
558 return d_func()->totalRotationAngle;
559}
560
562{
563 return d_func()->lastRotationAngle;
564}
565
567{
568 return d_func()->rotationAngle;
569}
570
572{
573 d_func()->totalRotationAngle = value;
574}
575
577{
578 d_func()->lastRotationAngle = value;
579}
580
582{
583 d_func()->rotationAngle = value;
584}
585
660
667
669{
670 Q_D(const QSwipeGesture);
671 if (d->swipeAngle < 0 || d->swipeAngle == 90 || d->swipeAngle == 270)
673 else if (d->swipeAngle < 90 || d->swipeAngle > 270)
675 else
676 return QSwipeGesture::Left;
677}
678
680{
681 Q_D(const QSwipeGesture);
682 if (d->swipeAngle <= 0 || d->swipeAngle == 180)
684 else if (d->swipeAngle < 180)
685 return QSwipeGesture::Up;
686 else
687 return QSwipeGesture::Down;
688}
689
691{
692 return d_func()->swipeAngle;
693}
694
696{
697 d_func()->swipeAngle = value;
698}
699
722 : QGesture(*new QTapGesturePrivate, parent)
723{
724 d_func()->gestureType = Qt::TapGesture;
725}
726
733
735{
736 return d_func()->position;
737}
738
740{
741 d_func()->position = value;
742}
770
777
779{
780 return d_func()->position;
781}
782
784{
785 d_func()->position = value;
786}
787
799
811
812int QTapAndHoldGesturePrivate::Timeout = 700; // in ms
813
814
852QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures)
853 : QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(nullptr)
854
855{
856}
857
864
868QList<QGesture *> QGestureEvent::gestures() const
869{
870 return m_gestures;
871}
872
877{
878 for (int i = 0; i < m_gestures.size(); ++i)
879 if (m_gestures.at(i)->gestureType() == type)
880 return m_gestures.at(i);
881 return nullptr;
882}
883
887QList<QGesture *> QGestureEvent::activeGestures() const
888{
889 QList<QGesture *> gestures;
890 for (QGesture *gesture : m_gestures) {
893 }
894 return gestures;
895}
896
900QList<QGesture *> QGestureEvent::canceledGestures() const
901{
902 QList<QGesture *> gestures;
903 for (QGesture *gesture : m_gestures) {
906 }
907 return gestures;
908}
909
924{
925 if (gesture)
927}
928
939{
940 if (gesture)
942}
943
954{
955 if (gesture)
957}
958
963{
964 return gesture ? isAccepted(gesture->gestureType()) : false;
965}
966
983{
984 setAccepted(false);
985 m_accepted[gestureType] = value;
986}
987
998{
999 setAccepted(gestureType, true);
1000}
1001
1012{
1013 setAccepted(gestureType, false);
1014}
1015
1021{
1022 return m_accepted.value(gestureType, true);
1023}
1024
1031{
1032 m_widget = widget;
1033}
1034
1039{
1040 return m_widget;
1041}
1042
1043#if QT_CONFIG(graphicsview)
1054QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
1055{
1056 QWidget *w = widget();
1057 if (w) // we get the viewport as widget, not the graphics view
1058 w = w->parentWidget();
1059 QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
1060 if (view) {
1061 return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
1062 }
1063 return QPointF();
1064}
1065#endif // QT_CONFIG(graphicsview)
1066
1067#ifndef QT_NO_DEBUG_STREAM
1068
1069static void formatGestureHeader(QDebug d, const char *className, const QGesture *gesture)
1070{
1071 d << className << "(state=";
1072 QtDebugUtils::formatQEnum(d, gesture->state());
1073 if (gesture->hasHotSpot()) {
1074 d << ",hotSpot=";
1076 }
1077}
1078
1079Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGesture *gesture)
1080{
1081 QDebugStateSaver saver(d);
1082 d.nospace();
1083 switch (gesture->gestureType()) {
1084 case Qt::TapGesture:
1085 formatGestureHeader(d, "QTapGesture", gesture);
1086 d << ",position=";
1087 QtDebugUtils::formatQPoint(d, static_cast<const QTapGesture*>(gesture)->position());
1088 d << ')';
1089 break;
1090 case Qt::TapAndHoldGesture: {
1091 const QTapAndHoldGesture *tap = static_cast<const QTapAndHoldGesture*>(gesture);
1092 formatGestureHeader(d, "QTapAndHoldGesture", tap);
1093 d << ",position=";
1094 QtDebugUtils::formatQPoint(d, tap->position());
1095 d << ",timeout=" << tap->timeout() << ')';
1096 }
1097 break;
1098 case Qt::PanGesture: {
1099 const QPanGesture *pan = static_cast<const QPanGesture*>(gesture);
1100 formatGestureHeader(d, "QPanGesture", pan);
1101 d << ",lastOffset=";
1103 d << pan->lastOffset();
1104 d << ",offset=";
1106 d << ",acceleration=" << pan->acceleration() << ",delta=";
1108 d << ')';
1109 }
1110 break;
1111 case Qt::PinchGesture: {
1112 const QPinchGesture *pinch = static_cast<const QPinchGesture*>(gesture);
1113 formatGestureHeader(d, "QPinchGesture", pinch);
1114 d << ",totalChangeFlags=" << pinch->totalChangeFlags()
1115 << ",changeFlags=" << pinch->changeFlags() << ",startCenterPoint=";
1117 d << ",lastCenterPoint=";
1119 d << ",centerPoint=";
1121 d << ",totalScaleFactor=" << pinch->totalScaleFactor()
1122 << ",lastScaleFactor=" << pinch->lastScaleFactor()
1123 << ",scaleFactor=" << pinch->scaleFactor()
1124 << ",totalRotationAngle=" << pinch->totalRotationAngle()
1125 << ",lastRotationAngle=" << pinch->lastRotationAngle()
1126 << ",rotationAngle=" << pinch->rotationAngle() << ')';
1127 }
1128 break;
1129 case Qt::SwipeGesture: {
1130 const QSwipeGesture *swipe = static_cast<const QSwipeGesture*>(gesture);
1131 formatGestureHeader(d, "QSwipeGesture", swipe);
1132 d << ",horizontalDirection=";
1134 d << ",verticalDirection=";
1136 d << ",swipeAngle=" << swipe->swipeAngle() << ')';
1137 }
1138 break;
1139 default:
1140 formatGestureHeader(d, "Custom gesture", gesture);
1141 d << ",type=" << gesture->gestureType() << ')';
1142 break;
1143 }
1144 return d;
1145}
1146
1147Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGestureEvent *gestureEvent)
1148{
1149 QDebugStateSaver saver(d);
1150 d.nospace();
1151 d << "QGestureEvent(" << gestureEvent->gestures() << ')';
1152 return d;
1153}
1154
1155#endif // !QT_NO_DEBUG_STREAM
1157
1158#include <moc_qgesture.cpp>
1159
1160#endif // QT_NO_GESTURES
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:244
void setWidget(QWidget *widget)
QGesture * gesture(Qt::GestureType type) const
Returns a gesture object by type.
Definition qgesture.cpp:876
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
bool isAccepted() const
Definition qcoreevent.h:308
QList< QGesture * > activeGestures() const
Returns a list of active (not canceled) gestures.
Definition qgesture.cpp:887
~QGestureEvent()
Destroys QGestureEvent.
Definition qgesture.cpp:861
QWidget * widget() const
Returns the widget on which the event occurred.
QList< QGesture * > canceledGestures() const
Returns a list of canceled gestures.
Definition qgesture.cpp:900
QList< QGesture * > gestures() const
Returns all gestures that are delivered in the event.
Definition qgesture.cpp:868
QGestureEvent(const QList< QGesture * > &gestures)
Creates new QGestureEvent containing a list of gestures.
Definition qgesture.cpp:852
void setAccepted(QGesture *, bool)
Sets the accept flag of the given gesture object to the specified value.
Definition qgesture.cpp:923
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition qgesture.h:29
Qt::GestureState state
the current state of the gesture
Definition qgesture.h:33
GestureCancelPolicy
This enum describes how accepting a gesture can cancel other gestures automatically.
Definition qgesture.h:53
void setGestureCancelPolicy(GestureCancelPolicy policy)
Definition qgesture.cpp:179
QGesture::GestureCancelPolicy gestureCancelPolicy
the policy for deciding what happens on accepting a gesture
Definition qgesture.h:36
Qt::GestureType gestureType
the type of the gesture
Definition qgesture.h:34
~QGesture()
Destroys the gesture object.
Definition qgesture.cpp:92
QGesture(QObject *parent=nullptr)
void unsetHotSpot()
Definition qgesture.cpp:151
void setHotSpot(const QPointF &value)
Definition qgesture.cpp:139
QPointF hotSpot
The point that is used to find the receiver for the gesture event.
Definition qgesture.h:37
bool hasHotSpot
whether the gesture has a hot-spot
Definition qgesture.h:38
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void append(parameter_type t)
Definition qlist.h:458
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
\inmodule QtCore
Definition qobject.h:103
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:73
QPointF delta
the offset from the previous input position to the current input
Definition qgesture.h:79
QPanGesture(QObject *parent=nullptr)
Definition qgesture.cpp:264
void setAcceleration(qreal value)
Definition qgesture.cpp:308
qreal acceleration
the acceleration in the motion of the touch point for this gesture
Definition qgesture.h:80
void setLastOffset(const QPointF &value)
Definition qgesture.cpp:298
~QPanGesture()
Destructor.
Definition qgesture.cpp:273
QPointF lastOffset
the last offset recorded for this gesture
Definition qgesture.h:77
QPointF offset
the total offset from the first input position to the current input position
Definition qgesture.h:78
void setOffset(const QPointF &value)
Definition qgesture.cpp:303
The QPinchGesture class describes a pinch gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:103
void setTotalRotationAngle(qreal value)
Definition qgesture.cpp:571
qreal totalRotationAngle
the total angle covered by the gesture
Definition qgesture.h:124
qreal totalScaleFactor
the total scale factor
Definition qgesture.h:120
ChangeFlags changeFlags
the property of the gesture that has changed in the current step
Definition qgesture.h:118
void setScaleFactor(qreal value)
Definition qgesture.cpp:550
QPointF centerPoint
the current center point
Definition qgesture.h:130
void setCenterPoint(const QPointF &value)
Definition qgesture.cpp:519
qreal lastRotationAngle
the last reported angle covered by the gesture motion
Definition qgesture.h:125
void setRotationAngle(qreal value)
Definition qgesture.cpp:581
void setLastScaleFactor(qreal value)
Definition qgesture.cpp:545
QPinchGesture(QObject *parent=nullptr)
Definition qgesture.cpp:461
qreal scaleFactor
the current scale factor
Definition qgesture.h:122
void setLastRotationAngle(qreal value)
Definition qgesture.cpp:576
~QPinchGesture()
Destructor.
Definition qgesture.cpp:470
QPointF lastCenterPoint
the last position of the center point recorded for this gesture
Definition qgesture.h:129
void setChangeFlags(ChangeFlags value)
Definition qgesture.cpp:489
void setStartCenterPoint(const QPointF &value)
Definition qgesture.cpp:509
void setTotalScaleFactor(qreal value)
Definition qgesture.cpp:540
void setTotalChangeFlags(ChangeFlags value)
Definition qgesture.cpp:479
qreal lastScaleFactor
the last scale factor recorded for this gesture
Definition qgesture.h:121
qreal rotationAngle
the angle covered by the gesture motion
Definition qgesture.h:126
void setLastCenterPoint(const QPointF &value)
Definition qgesture.cpp:514
ChangeFlags totalChangeFlags
the property of the gesture that has change
Definition qgesture.h:117
QPointF startCenterPoint
the starting position of the center point
Definition qgesture.h:128
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QSwipeGesture class describes a swipe gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:177
~QSwipeGesture()
Destructor.
Definition qgesture.cpp:664
SwipeDirection verticalDirection
the vertical direction of the gesture
Definition qgesture.h:182
QSwipeGesture(QObject *parent=nullptr)
Definition qgesture.cpp:655
qreal swipeAngle
the angle of the motion associated with the gesture
Definition qgesture.h:183
SwipeDirection
This enum describes the possible directions for the gesture's motion along the horizontal and vertica...
Definition qgesture.h:187
void setSwipeAngle(qreal value)
Definition qgesture.cpp:695
SwipeDirection horizontalDirection
the horizontal direction of the gesture
Definition qgesture.h:181
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user....
Definition qgesture.h:222
QTapAndHoldGesture(QObject *parent=nullptr)
Definition qgesture.cpp:765
static void setTimeout(int msecs)
Set the timeout, in milliseconds, before the gesture triggers.
Definition qgesture.cpp:795
~QTapAndHoldGesture()
Destructor.
Definition qgesture.cpp:774
static int timeout()
Gets the timeout, in milliseconds, before the gesture triggers.
Definition qgesture.cpp:807
void setPosition(const QPointF &pos)
Definition qgesture.cpp:783
QPointF position
the position of the tap
Definition qgesture.h:226
The QTapGesture class describes a tap gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:204
void setPosition(const QPointF &pos)
Definition qgesture.cpp:739
QTapGesture(QObject *parent=nullptr)
Definition qgesture.cpp:721
~QTapGesture()
Destructor.
Definition qgesture.cpp:730
QPointF position
the position of the tap
Definition qgesture.h:208
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
Combined button and popup list for selecting options.
static void formatQEnum(QDebug &debug, QEnum value)
Definition qdebug_p.h:59
static void formatQPoint(QDebug &debug, const Point &point)
Definition qdebug_p.h:33
GestureState
@ GestureCanceled
GestureType
@ TapAndHoldGesture
@ SwipeGesture
@ PinchGesture
@ CustomGesture
@ PanGesture
@ TapGesture
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGesture *gesture)
static void formatGestureHeader(QDebug d, const char *className, const QGesture *gesture)
#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
Definition qmetatype.h:1384
GLfloat GLfloat GLfloat w
[0]
GLenum type
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
const char className[16]
[1]
Definition qwizard.cpp:100
QObject::connect nullptr
QSizePolicy policy
QQuickView * view
[0]