Debian Codegraph @

src/Gui/SoTouchEvents.h

raw
1 /***************************************************************************
2 * Copyright (c) 2015 Victor Titov (DeepSOIC) <[email protected])> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef SOTOUCHEVENTS_H
24 #define SOTOUCHEVENTS_H
25
26 #include <QGesture>
27 #include <Quarter/devices/InputDevice.h>
28 #include <Inventor/SbLinear.h>
29 #include <Inventor/events/SoEvent.h>
30 #include <Inventor/events/SoSubEvent.h>
31
32 class QWidget;
33
34 namespace Quarter = SIM::Coin3D::Quarter;
35
36 class SoGestureEvent: public SoEvent
37 {
38 SO_EVENT_HEADER();
39
40 public:
41 static void initClass()
42 {
43 SO_EVENT_INIT_CLASS(SoGestureEvent, SoEvent);
44 }
45 SoGestureEvent() = default;
46 ~SoGestureEvent() override = default;
47 SbBool isSoGestureEvent(const SoEvent* ev) const;
48
49 enum SbGestureState
50 {
51 SbGSNoGesture = Qt::NoGesture,
52 SbGSStart = Qt::GestureStarted,
53 SbGSUpdate = Qt::GestureUpdated,
54 SbGSEnd = Qt::GestureFinished,
55 SbGsCanceled = Qt::GestureCanceled
56 };
57 SbGestureState state {SbGSNoGesture};
58 };
59
60 class SoGesturePanEvent: public SoGestureEvent
61 {
62 SO_EVENT_HEADER();
63
64 public:
65 static void initClass()
66 { // needs to be called before the class can be used. Initializes type IDs of the class.
67 SO_EVENT_INIT_CLASS(SoGesturePanEvent, SoGestureEvent);
68 }
69 SoGesturePanEvent() = default;
70 SoGesturePanEvent(QPanGesture* qpan, QWidget* widget);
71 ~SoGesturePanEvent() override = default;
72 SbBool isSoGesturePanEvent(const SoEvent* ev) const;
73
74 SbVec2f deltaOffset;
75 SbVec2f totalOffset;
76 };
77
78 class SoGesturePinchEvent: public SoGestureEvent
79 {
80 SO_EVENT_HEADER();
81
82 public:
83 static void initClass()
84 {
85 SO_EVENT_INIT_CLASS(SoGesturePinchEvent, SoGestureEvent);
86 }
87 SoGesturePinchEvent()
88 : deltaZoom(0)
89 , totalZoom(0)
90 , deltaAngle(0)
91 , totalAngle(0)
92 {}
93 SoGesturePinchEvent(QPinchGesture* qpinch, QWidget* widget);
94 ~SoGesturePinchEvent() override = default;
95 SbBool isSoGesturePinchEvent(const SoEvent* ev) const;
96
97 SbVec2f startCenter; // in GL pixel coordinates (from bottom left corner of view area)
98 SbVec2f curCenter;
99 SbVec2f deltaCenter;
100 double deltaZoom; // change of zoom factor (1.0 = no change, >1 - zoom in, 0..1 - zoom out)
101 double totalZoom; // zoom factor accumulated since start of gesture.
102 double deltaAngle;
103 double totalAngle;
104
105 static double unbranchAngle(double ang);
106 };
107
108 class SoGestureSwipeEvent: public SoGestureEvent
109 {
110 SO_EVENT_HEADER();
111
112 public:
113 static void initClass()
114 {
115 SO_EVENT_INIT_CLASS(SoGestureSwipeEvent, SoGestureEvent);
116 }
117 SoGestureSwipeEvent()
118 : angle(0)
119 , vertDir(0)
120 , horzDir(0)
121 {}
122 SoGestureSwipeEvent(QSwipeGesture* qwsipe, QWidget* widget);
123 ~SoGestureSwipeEvent() override = default;
124 SbBool isSoGestureSwipeEvent(const SoEvent* ev) const;
125
126 double angle;
127 int vertDir; //+1,0,-1 up/none/down
128 int horzDir; //+1,0,-1 right/none/left
129 };
130
131
132 class GesturesDevice: public Quarter::InputDevice
133 {
134 public:
135 explicit GesturesDevice(QWidget* widget); // it needs to know the widget to do coordinate
136 // translation
137
138 ~GesturesDevice() override = default;
139 const SoEvent* translateEvent(QEvent* event) override;
140
141 protected:
142 QWidget* widget;
143 };
144
145 #endif // SOTOUCHEVENTS_H