QtBase  v6.3.1
qgesture.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qgesture.h"
41 #include "private/qgesture_p.h"
42 #include "private/qstandardgestures_p.h"
43 #if QT_CONFIG(graphicsview)
44 #include "qgraphicsview.h"
45 #endif
46 
47 #include <private/qdebug_p.h>
48 #ifndef QT_NO_GESTURES
49 
51 
106 {
107  d_func()->gestureType = Qt::CustomGesture;
108 }
109 
114  : QObject(dd, parent)
115 {
116 }
117 
122 {
123 }
124 
154 {
155  return d_func()->gestureType;
156 }
157 
159 {
160  return d_func()->state;
161 }
162 
164 {
165  return d_func()->hotSpot;
166 }
167 
169 {
170  Q_D(QGesture);
171  d->hotSpot = value;
172  d->isHotSpotSet = true;
173 }
174 
176 {
177  return d_func()->isHotSpotSet;
178 }
179 
181 {
182  d_func()->isHotSpotSet = false;
183 }
184 
209 {
210  Q_D(QGesture);
211  d->gestureCancelPolicy = static_cast<uint>(policy);
212 }
213 
215 {
216  Q_D(const QGesture);
217  return static_cast<GestureCancelPolicy>(d->gestureCancelPolicy);
218 }
219 
295 {
296  d_func()->gestureType = Qt::PanGesture;
297 }
298 
303 {
304 }
305 
307 {
308  return d_func()->lastOffset;
309 }
310 
312 {
313  return d_func()->offset;
314 }
315 
317 {
318  Q_D(const QPanGesture);
319  return d->offset - d->lastOffset;
320 }
321 
323 {
324  return d_func()->acceleration;
325 }
326 
328 {
329  d_func()->lastOffset = value;
330 }
331 
333 {
334  d_func()->offset = value;
335 }
336 
338 {
339  d_func()->acceleration = value;
340 }
341 
492 {
493  d_func()->gestureType = Qt::PinchGesture;
494 }
495 
500 {
501 }
502 
503 QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const
504 {
505  return d_func()->totalChangeFlags;
506 }
507 
508 void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value)
509 {
510  d_func()->totalChangeFlags = value;
511 }
512 
513 QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const
514 {
515  return d_func()->changeFlags;
516 }
517 
518 void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value)
519 {
520  d_func()->changeFlags = value;
521 }
522 
524 {
525  return d_func()->startCenterPoint;
526 }
527 
529 {
530  return d_func()->lastCenterPoint;
531 }
532 
534 {
535  return d_func()->centerPoint;
536 }
537 
539 {
540  d_func()->startCenterPoint = value;
541 }
542 
544 {
545  d_func()->lastCenterPoint = value;
546 }
547 
549 {
550  d_func()->centerPoint = value;
551 }
552 
553 
555 {
556  return d_func()->totalScaleFactor;
557 }
558 
560 {
561  return d_func()->lastScaleFactor;
562 }
563 
565 {
566  return d_func()->scaleFactor;
567 }
568 
570 {
571  d_func()->totalScaleFactor = value;
572 }
573 
575 {
576  d_func()->lastScaleFactor = value;
577 }
578 
580 {
581  d_func()->scaleFactor = value;
582 }
583 
584 
586 {
587  return d_func()->totalRotationAngle;
588 }
589 
591 {
592  return d_func()->lastRotationAngle;
593 }
594 
596 {
597  return d_func()->rotationAngle;
598 }
599 
601 {
602  d_func()->totalRotationAngle = value;
603 }
604 
606 {
607  d_func()->lastRotationAngle = value;
608 }
609 
611 {
612  d_func()->rotationAngle = value;
613 }
614 
686 {
687  d_func()->gestureType = Qt::SwipeGesture;
688 }
689 
694 {
695 }
696 
698 {
699  Q_D(const QSwipeGesture);
700  if (d->swipeAngle < 0 || d->swipeAngle == 90 || d->swipeAngle == 270)
702  else if (d->swipeAngle < 90 || d->swipeAngle > 270)
703  return QSwipeGesture::Right;
704  else
705  return QSwipeGesture::Left;
706 }
707 
709 {
710  Q_D(const QSwipeGesture);
711  if (d->swipeAngle <= 0 || d->swipeAngle == 180)
713  else if (d->swipeAngle < 180)
714  return QSwipeGesture::Up;
715  else
716  return QSwipeGesture::Down;
717 }
718 
720 {
721  return d_func()->swipeAngle;
722 }
723 
725 {
726  d_func()->swipeAngle = value;
727 }
728 
752 {
753  d_func()->gestureType = Qt::TapGesture;
754 }
755 
760 {
761 }
762 
764 {
765  return d_func()->position;
766 }
767 
769 {
770  d_func()->position = value;
771 }
796 {
798 }
799 
804 {
805 }
806 
808 {
809  return d_func()->position;
810 }
811 
813 {
814  d_func()->position = value;
815 }
816 
825 {
827 }
828 
837 {
839 }
840 
841 int QTapAndHoldGesturePrivate::Timeout = 700; // in ms
842 
843 
882  : QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(nullptr)
883 
884 {
885 }
886 
891 {
892 }
893 
898 {
899  return m_gestures;
900 }
901 
906 {
907  for (int i = 0; i < m_gestures.size(); ++i)
908  if (m_gestures.at(i)->gestureType() == type)
909  return m_gestures.at(i);
910  return nullptr;
911 }
912 
917 {
919  for (QGesture *gesture : m_gestures) {
922  }
923  return gestures;
924 }
925 
930 {
932  for (QGesture *gesture : m_gestures) {
935  }
936  return gestures;
937 }
938 
953 {
954  if (gesture)
956 }
957 
968 {
969  if (gesture)
970  setAccepted(gesture->gestureType(), true);
971 }
972 
983 {
984  if (gesture)
985  setAccepted(gesture->gestureType(), false);
986 }
987 
992 {
993  return gesture ? isAccepted(gesture->gestureType()) : false;
994 }
995 
1012 {
1013  setAccepted(false);
1014  m_accepted[gestureType] = value;
1015 }
1016 
1027 {
1028  setAccepted(gestureType, true);
1029 }
1030 
1041 {
1042  setAccepted(gestureType, false);
1043 }
1044 
1050 {
1051  return m_accepted.value(gestureType, true);
1052 }
1053 
1060 {
1061  m_widget = widget;
1062 }
1063 
1068 {
1069  return m_widget;
1070 }
1071 
1072 #if QT_CONFIG(graphicsview)
1083 QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
1084 {
1085  QWidget *w = widget();
1086  if (w) // we get the viewport as widget, not the graphics view
1087  w = w->parentWidget();
1088  QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
1089  if (view) {
1090  return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
1091  }
1092  return QPointF();
1093 }
1094 #endif // QT_CONFIG(graphicsview)
1095 
1096 #ifndef QT_NO_DEBUG_STREAM
1097 
1098 static void formatGestureHeader(QDebug d, const char *className, const QGesture *gesture)
1099 {
1100  d << className << "(state=";
1101  QtDebugUtils::formatQEnum(d, gesture->state());
1102  if (gesture->hasHotSpot()) {
1103  d << ",hotSpot=";
1104  QtDebugUtils::formatQPoint(d, gesture->hotSpot());
1105  }
1106 }
1107 
1108 Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGesture *gesture)
1109 {
1110  QDebugStateSaver saver(d);
1111  d.nospace();
1112  switch (gesture->gestureType()) {
1113  case Qt::TapGesture:
1114  formatGestureHeader(d, "QTapGesture", gesture);
1115  d << ",position=";
1116  QtDebugUtils::formatQPoint(d, static_cast<const QTapGesture*>(gesture)->position());
1117  d << ')';
1118  break;
1119  case Qt::TapAndHoldGesture: {
1120  const QTapAndHoldGesture *tap = static_cast<const QTapAndHoldGesture*>(gesture);
1121  formatGestureHeader(d, "QTapAndHoldGesture", tap);
1122  d << ",position=";
1123  QtDebugUtils::formatQPoint(d, tap->position());
1124  d << ",timeout=" << tap->timeout() << ')';
1125  }
1126  break;
1127  case Qt::PanGesture: {
1128  const QPanGesture *pan = static_cast<const QPanGesture*>(gesture);
1129  formatGestureHeader(d, "QPanGesture", pan);
1130  d << ",lastOffset=";
1131  QtDebugUtils::formatQPoint(d, pan->lastOffset());
1132  d << pan->lastOffset();
1133  d << ",offset=";
1134  QtDebugUtils::formatQPoint(d, pan->offset());
1135  d << ",acceleration=" << pan->acceleration() << ",delta=";
1136  QtDebugUtils::formatQPoint(d, pan->delta());
1137  d << ')';
1138  }
1139  break;
1140  case Qt::PinchGesture: {
1141  const QPinchGesture *pinch = static_cast<const QPinchGesture*>(gesture);
1142  formatGestureHeader(d, "QPinchGesture", pinch);
1143  d << ",totalChangeFlags=" << pinch->totalChangeFlags()
1144  << ",changeFlags=" << pinch->changeFlags() << ",startCenterPoint=";
1145  QtDebugUtils::formatQPoint(d, pinch->startCenterPoint());
1146  d << ",lastCenterPoint=";
1147  QtDebugUtils::formatQPoint(d, pinch->lastCenterPoint());
1148  d << ",centerPoint=";
1149  QtDebugUtils::formatQPoint(d, pinch->centerPoint());
1150  d << ",totalScaleFactor=" << pinch->totalScaleFactor()
1151  << ",lastScaleFactor=" << pinch->lastScaleFactor()
1152  << ",scaleFactor=" << pinch->scaleFactor()
1153  << ",totalRotationAngle=" << pinch->totalRotationAngle()
1154  << ",lastRotationAngle=" << pinch->lastRotationAngle()
1155  << ",rotationAngle=" << pinch->rotationAngle() << ')';
1156  }
1157  break;
1158  case Qt::SwipeGesture: {
1159  const QSwipeGesture *swipe = static_cast<const QSwipeGesture*>(gesture);
1160  formatGestureHeader(d, "QSwipeGesture", swipe);
1161  d << ",horizontalDirection=";
1162  QtDebugUtils::formatQEnum(d, swipe->horizontalDirection());
1163  d << ",verticalDirection=";
1164  QtDebugUtils::formatQEnum(d, swipe->verticalDirection());
1165  d << ",swipeAngle=" << swipe->swipeAngle() << ')';
1166  }
1167  break;
1168  default:
1169  formatGestureHeader(d, "Custom gesture", gesture);
1170  d << ",type=" << gesture->gestureType() << ')';
1171  break;
1172  }
1173  return d;
1174 }
1175 
1176 Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QGestureEvent *gestureEvent)
1177 {
1178  QDebugStateSaver saver(d);
1179  d.nospace();
1180  d << "QGestureEvent(" << gestureEvent->gestures() << ')';
1181  return d;
1182 }
1183 
1184 #endif // !QT_NO_DEBUG_STREAM
1186 
1187 #include <moc_qgesture.cpp>
1188 
1189 #endif // QT_NO_GESTURES
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
#define value
[5]
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
Convenience class for custom QDebug operators.
Definition: qdebug.h:176
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QGestureEvent class provides the description of triggered gestures.
Definition: qgesture.h:276
void setWidget(QWidget *widget)
Definition: qgesture.cpp:1059
QGesture * gesture(Qt::GestureType type) const
Definition: qgesture.cpp:905
virtual void setAccepted(bool accepted)
Definition: qcoreevent.h:310
void ignore()
Definition: qcoreevent.h:314
bool isAccepted() const
Definition: qcoreevent.h:311
QList< QGesture * > activeGestures() const
Definition: qgesture.cpp:916
QWidget * widget() const
Definition: qgesture.cpp:1067
QList< QGesture * > canceledGestures() const
Definition: qgesture.cpp:929
QList< QGesture * > gestures() const
Definition: qgesture.cpp:897
QGestureEvent(const QList< QGesture * > &gestures)
Definition: qgesture.cpp:881
void accept()
Definition: qcoreevent.h:313
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:62
Qt::GestureState state
the current state of the gesture
Definition: qgesture.h:66
GestureCancelPolicy
Definition: qgesture.h:86
void setGestureCancelPolicy(GestureCancelPolicy policy)
Definition: qgesture.cpp:208
QGesture::GestureCancelPolicy gestureCancelPolicy
the policy for deciding what happens on accepting a gesture
Definition: qgesture.h:69
Qt::GestureType gestureType
the type of the gesture
Definition: qgesture.h:67
QGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:104
void unsetHotSpot()
Definition: qgesture.cpp:180
void setHotSpot(const QPointF &value)
Definition: qgesture.cpp:168
QPointF hotSpot
The point that is used to find the receiver for the gesture event.
Definition: qgesture.h:70
bool hasHotSpot
whether the gesture has a hot-spot
Definition: qgesture.h:71
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
qsizetype size() const noexcept
Definition: qlist.h:414
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
void append(parameter_type t)
Definition: qlist.h:469
T value(const Key &key, const T &defaultValue=T()) const
Definition: qmap.h:392
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:106
QPointF delta
the offset from the previous input position to the current input
Definition: qgesture.h:112
QPanGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:293
void setAcceleration(qreal value)
Definition: qgesture.cpp:337
qreal acceleration
the acceleration in the motion of the touch point for this gesture
Definition: qgesture.h:113
void setLastOffset(const QPointF &value)
Definition: qgesture.cpp:327
QPointF lastOffset
the last offset recorded for this gesture
Definition: qgesture.h:110
QPointF offset
the total offset from the first input position to the current input position
Definition: qgesture.h:111
void setOffset(const QPointF &value)
Definition: qgesture.cpp:332
The QPinchGesture class describes a pinch gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:136
void setTotalRotationAngle(qreal value)
Definition: qgesture.cpp:600
qreal totalRotationAngle
the total angle covered by the gesture
Definition: qgesture.h:157
qreal totalScaleFactor
the total scale factor
Definition: qgesture.h:153
ChangeFlags changeFlags
the property of the gesture that has changed in the current step
Definition: qgesture.h:151
void setScaleFactor(qreal value)
Definition: qgesture.cpp:579
QPointF centerPoint
the current center point
Definition: qgesture.h:163
void setCenterPoint(const QPointF &value)
Definition: qgesture.cpp:548
qreal lastRotationAngle
the last reported angle covered by the gesture motion
Definition: qgesture.h:158
void setRotationAngle(qreal value)
Definition: qgesture.cpp:610
void setLastScaleFactor(qreal value)
Definition: qgesture.cpp:574
QPinchGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:490
qreal scaleFactor
the current scale factor
Definition: qgesture.h:155
void setLastRotationAngle(qreal value)
Definition: qgesture.cpp:605
QPointF lastCenterPoint
the last position of the center point recorded for this gesture
Definition: qgesture.h:162
void setChangeFlags(ChangeFlags value)
Definition: qgesture.cpp:518
void setStartCenterPoint(const QPointF &value)
Definition: qgesture.cpp:538
void setTotalScaleFactor(qreal value)
Definition: qgesture.cpp:569
void setTotalChangeFlags(ChangeFlags value)
Definition: qgesture.cpp:508
qreal lastScaleFactor
the last scale factor recorded for this gesture
Definition: qgesture.h:154
qreal rotationAngle
the angle covered by the gesture motion
Definition: qgesture.h:159
void setLastCenterPoint(const QPointF &value)
Definition: qgesture.cpp:543
ChangeFlags totalChangeFlags
the property of the gesture that has change
Definition: qgesture.h:150
QPointF startCenterPoint
the starting position of the center point
Definition: qgesture.h:161
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
constexpr QPoint toPoint() const
Definition: qpoint.h:420
The QSwipeGesture class describes a swipe gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:209
SwipeDirection verticalDirection
the vertical direction of the gesture
Definition: qgesture.h:214
QSwipeGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:684
qreal swipeAngle
the angle of the motion associated with the gesture
Definition: qgesture.h:215
void setSwipeAngle(qreal value)
Definition: qgesture.cpp:724
SwipeDirection horizontalDirection
the horizontal direction of the gesture
Definition: qgesture.h:213
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user....
Definition: qgesture.h:254
QTapAndHoldGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:794
static void setTimeout(int msecs)
Definition: qgesture.cpp:824
static int timeout()
Definition: qgesture.cpp:836
void setPosition(const QPointF &pos)
Definition: qgesture.cpp:812
QPointF position
the position of the tap
Definition: qgesture.h:258
The QTapGesture class describes a tap gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:236
void setPosition(const QPointF &pos)
Definition: qgesture.cpp:768
QTapGesture(QObject *parent=nullptr)
Definition: qgesture.cpp:750
QPointF position
the position of the tap
Definition: qgesture.h:240
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QOpenGLWidget * widget
[1]
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
GestureState
Definition: qnamespace.h:1632
@ GestureCanceled
Definition: qnamespace.h:1637
GestureType
Definition: qnamespace.h:1641
@ TapAndHoldGesture
Definition: qnamespace.h:1643
@ SwipeGesture
Definition: qnamespace.h:1646
@ PinchGesture
Definition: qnamespace.h:1645
@ CustomGesture
Definition: qnamespace.h:1648
@ PanGesture
Definition: qnamespace.h:1644
@ TapGesture
Definition: qnamespace.h:1642
EGLOutputLayerEXT EGLint EGLAttrib value
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
GLenum type
Definition: qopengl.h:270
GLfloat GLfloat GLfloat w
[0]
const char className[16]
[1]
Definition: qwizard.cpp:135
QObject::connect nullptr
QSizePolicy policy
QQuickView * view
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent