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 <QtCore/qstatemachine.h>
41#include <private/qstatemachine_p.h>
42#include <QtGui/qevent.h>
43#include <QtWidgets/qtwidgetsglobal.h>
44#if QT_CONFIG(graphicsview)
45#include <QtWidgets/qgraphicssceneevent.h>
46#endif
47
48QT_BEGIN_NAMESPACE
49
50Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler();
51
52static QEvent *cloneEvent(QEvent *e)
53{
54 switch (e->type()) {
55 case QEvent::MouseButtonPress:
56 case QEvent::MouseButtonRelease:
57 case QEvent::MouseButtonDblClick:
58 case QEvent::MouseMove:
59 return new QMouseEvent(*static_cast<QMouseEvent*>(e));
60 case QEvent::KeyPress:
61 case QEvent::KeyRelease:
62 return new QKeyEvent(*static_cast<QKeyEvent*>(e));
63 case QEvent::FocusIn:
64 case QEvent::FocusOut:
65 return new QFocusEvent(*static_cast<QFocusEvent*>(e));
66 case QEvent::Enter:
67 return new QEvent(*e);
68 case QEvent::Leave:
69 return new QEvent(*e);
70 case QEvent::Paint:
71 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
72 break;
73 case QEvent::Move:
74 return new QMoveEvent(*static_cast<QMoveEvent*>(e));
75 case QEvent::Resize:
76 return new QResizeEvent(*static_cast<QResizeEvent*>(e));
77 case QEvent::Create:
78 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
79 break;
80 case QEvent::Destroy:
81 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
82 break;
83 case QEvent::Show:
84 return new QShowEvent(*static_cast<QShowEvent*>(e));
85 case QEvent::Hide:
86 return new QHideEvent(*static_cast<QHideEvent*>(e));
87 case QEvent::Close:
88 return new QCloseEvent(*static_cast<QCloseEvent*>(e));
89 case QEvent::Quit:
90 return new QEvent(*e);
91 case QEvent::ParentChange:
92 return new QEvent(*e);
93 case QEvent::ParentAboutToChange:
94 return new QEvent(*e);
95 case QEvent::ThreadChange:
96 return new QEvent(*e);
97
98 case QEvent::WindowActivate:
99 case QEvent::WindowDeactivate:
100 return new QEvent(*e);
101
102 case QEvent::ShowToParent:
103 return new QEvent(*e);
104 case QEvent::HideToParent:
105 return new QEvent(*e);
106#if QT_CONFIG(wheelevent)
107 case QEvent::Wheel:
108 return new QWheelEvent(*static_cast<QWheelEvent*>(e));
109#endif // QT_CONFIG(wheelevent)
110 case QEvent::WindowTitleChange:
111 return new QEvent(*e);
112 case QEvent::WindowIconChange:
113 return new QEvent(*e);
114 case QEvent::ApplicationWindowIconChange:
115 return new QEvent(*e);
116 case QEvent::ApplicationFontChange:
117 return new QEvent(*e);
118 case QEvent::ApplicationLayoutDirectionChange:
119 return new QEvent(*e);
120 case QEvent::ApplicationPaletteChange:
121 return new QEvent(*e);
122 case QEvent::PaletteChange:
123 return new QEvent(*e);
124 case QEvent::Clipboard:
125 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
126 break;
127 case QEvent::Speech:
128 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
129 break;
130 case QEvent::MetaCall:
131 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
132 break;
133 case QEvent::SockAct:
134 return new QEvent(*e);
135 case QEvent::WinEventAct:
136 return new QEvent(*e);
137 case QEvent::DeferredDelete:
138 return new QEvent(*e);
139#if QT_CONFIG(draganddrop)
140 case QEvent::DragEnter:
141 return new QDragEnterEvent(*static_cast<QDragEnterEvent*>(e));
142 case QEvent::DragMove:
143 return new QDragMoveEvent(*static_cast<QDragMoveEvent*>(e));
144 case QEvent::DragLeave:
145 return new QDragLeaveEvent(*static_cast<QDragLeaveEvent*>(e));
146 case QEvent::Drop:
147 return new QDropEvent(*static_cast<QDragMoveEvent*>(e));
148#endif
149 case QEvent::ChildAdded:
150 return new QChildEvent(*static_cast<QChildEvent*>(e));
151 case QEvent::ChildPolished:
152 return new QChildEvent(*static_cast<QChildEvent*>(e));
153 case QEvent::ChildRemoved:
154 return new QChildEvent(*static_cast<QChildEvent*>(e));
155 case QEvent::ShowWindowRequest:
156 return new QEvent(*e);
157 case QEvent::PolishRequest:
158 return new QEvent(*e);
159 case QEvent::Polish:
160 return new QEvent(*e);
161 case QEvent::LayoutRequest:
162 return new QEvent(*e);
163 case QEvent::UpdateRequest:
164 return new QEvent(*e);
165 case QEvent::UpdateLater:
166 return new QEvent(*e);
167
168 case QEvent::EmbeddingControl:
169 return new QEvent(*e);
170 case QEvent::ActivateControl:
171 return new QEvent(*e);
172 case QEvent::DeactivateControl:
173 return new QEvent(*e);
174
175#ifndef QT_NO_CONTEXTMENU
176 case QEvent::ContextMenu:
177 return new QContextMenuEvent(*static_cast<QContextMenuEvent*>(e));
178#endif
179 case QEvent::InputMethod:
180 return new QInputMethodEvent(*static_cast<QInputMethodEvent*>(e));
181 case QEvent::LocaleChange:
182 return new QEvent(*e);
183 case QEvent::LanguageChange:
184 return new QEvent(*e);
185 case QEvent::LayoutDirectionChange:
186 return new QEvent(*e);
187 case QEvent::Style:
188 return new QEvent(*e);
189#if QT_CONFIG(tabletevent)
190 case QEvent::TabletMove:
191 case QEvent::TabletPress:
192 case QEvent::TabletRelease:
193 return new QTabletEvent(*static_cast<QTabletEvent*>(e));
194#endif // QT_CONFIG(tabletevent)
195 case QEvent::OkRequest:
196 return new QEvent(*e);
197 case QEvent::HelpRequest:
198 return new QEvent(*e);
199
200 case QEvent::IconDrag:
201 return new QIconDragEvent(*static_cast<QIconDragEvent*>(e));
202
203 case QEvent::FontChange:
204 return new QEvent(*e);
205 case QEvent::EnabledChange:
206 return new QEvent(*e);
207 case QEvent::ActivationChange:
208 return new QEvent(*e);
209 case QEvent::StyleChange:
210 return new QEvent(*e);
211 case QEvent::IconTextChange:
212 return new QEvent(*e);
213 case QEvent::ModifiedChange:
214 return new QEvent(*e);
215 case QEvent::MouseTrackingChange:
216 return new QEvent(*e);
217
218 case QEvent::WindowBlocked:
219 return new QEvent(*e);
220 case QEvent::WindowUnblocked:
221 return new QEvent(*e);
222 case QEvent::WindowStateChange:
223 return new QWindowStateChangeEvent(*static_cast<QWindowStateChangeEvent*>(e));
224
225 case QEvent::ToolTip:
226 return new QHelpEvent(*static_cast<QHelpEvent*>(e));
227 case QEvent::WhatsThis:
228 return new QHelpEvent(*static_cast<QHelpEvent*>(e));
229#if QT_CONFIG(statustip)
230 case QEvent::StatusTip:
231 return new QStatusTipEvent(*static_cast<QStatusTipEvent*>(e));
232#endif // QT_CONFIG(statustip)
233#ifndef QT_NO_ACTION
234 case QEvent::ActionChanged:
235 case QEvent::ActionAdded:
236 case QEvent::ActionRemoved:
237 return new QActionEvent(*static_cast<QActionEvent*>(e));
238#endif
239 case QEvent::FileOpen:
240 return new QFileOpenEvent(*static_cast<QFileOpenEvent*>(e));
241
242#ifndef QT_NO_SHORTCUT
243 case QEvent::Shortcut:
244 return new QShortcutEvent(*static_cast<QShortcutEvent*>(e));
245#endif //QT_NO_SHORTCUT
246 case QEvent::ShortcutOverride:
247 return new QKeyEvent(*static_cast<QKeyEvent*>(e));
248
249#if QT_CONFIG(whatsthis)
250 case QEvent::WhatsThisClicked:
251 return new QWhatsThisClickedEvent(*static_cast<QWhatsThisClickedEvent*>(e));
252#endif // QT_CONFIG(whatsthis)
253
254#if QT_CONFIG(toolbar)
255 case QEvent::ToolBarChange:
256 return new QToolBarChangeEvent(*static_cast<QToolBarChangeEvent*>(e));
257#endif // QT_CONFIG(toolbar)
258
259 case QEvent::ApplicationActivate:
260 return new QEvent(*e);
261 case QEvent::ApplicationDeactivate:
262 return new QEvent(*e);
263
264 case QEvent::QueryWhatsThis:
265 return new QHelpEvent(*static_cast<QHelpEvent*>(e));
266 case QEvent::EnterWhatsThisMode:
267 return new QEvent(*e);
268 case QEvent::LeaveWhatsThisMode:
269 return new QEvent(*e);
270
271 case QEvent::ZOrderChange:
272 return new QEvent(*e);
273
274 case QEvent::HoverEnter:
275 case QEvent::HoverLeave:
276 case QEvent::HoverMove:
277 return new QHoverEvent(*static_cast<QHoverEvent*>(e));
278
279#ifdef QT_KEYPAD_NAVIGATION
280 case QEvent::EnterEditFocus:
281 return new QEvent(*e);
282 case QEvent::LeaveEditFocus:
283 return new QEvent(*e);
284#endif
285 case QEvent::AcceptDropsChange:
286 return new QEvent(*e);
287
288 case QEvent::ZeroTimerEvent:
289 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
290 break;
291#if QT_CONFIG(graphicsview)
292 case QEvent::GraphicsSceneMouseMove:
293 case QEvent::GraphicsSceneMousePress:
294 case QEvent::GraphicsSceneMouseRelease:
295 case QEvent::GraphicsSceneMouseDoubleClick: {
296 QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent*>(e);
297 QGraphicsSceneMouseEvent *me2 = new QGraphicsSceneMouseEvent(me->type());
298 me2->setWidget(me->widget());
299 me2->setPos(me->pos());
300 me2->setScenePos(me->scenePos());
301 me2->setScreenPos(me->screenPos());
302// ### for all buttons
303 me2->setButtonDownPos(button: Qt::LeftButton, pos: me->buttonDownPos(button: Qt::LeftButton));
304 me2->setButtonDownPos(button: Qt::RightButton, pos: me->buttonDownPos(button: Qt::RightButton));
305 me2->setButtonDownScreenPos(button: Qt::LeftButton, pos: me->buttonDownScreenPos(button: Qt::LeftButton));
306 me2->setButtonDownScreenPos(button: Qt::RightButton, pos: me->buttonDownScreenPos(button: Qt::RightButton));
307 me2->setLastPos(me->lastPos());
308 me2->setLastScenePos(me->lastScenePos());
309 me2->setLastScreenPos(me->lastScreenPos());
310 me2->setButtons(me->buttons());
311 me2->setButton(me->button());
312 me2->setModifiers(me->modifiers());
313 me2->setSource(me->source());
314 me2->setFlags(me->flags());
315 return me2;
316 }
317
318 case QEvent::GraphicsSceneContextMenu: {
319 QGraphicsSceneContextMenuEvent *me = static_cast<QGraphicsSceneContextMenuEvent*>(e);
320 QGraphicsSceneContextMenuEvent *me2 = new QGraphicsSceneContextMenuEvent(me->type());
321 me2->setWidget(me->widget());
322 me2->setPos(me->pos());
323 me2->setScenePos(me->scenePos());
324 me2->setScreenPos(me->screenPos());
325 me2->setModifiers(me->modifiers());
326 me2->setReason(me->reason());
327 return me2;
328 }
329
330 case QEvent::GraphicsSceneHoverEnter:
331 case QEvent::GraphicsSceneHoverMove:
332 case QEvent::GraphicsSceneHoverLeave: {
333 QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(e);
334 QGraphicsSceneHoverEvent *he2 = new QGraphicsSceneHoverEvent(he->type());
335 he2->setPos(he->pos());
336 he2->setScenePos(he->scenePos());
337 he2->setScreenPos(he->screenPos());
338 he2->setLastPos(he->lastPos());
339 he2->setLastScenePos(he->lastScenePos());
340 he2->setLastScreenPos(he->lastScreenPos());
341 he2->setModifiers(he->modifiers());
342 return he2;
343 }
344 case QEvent::GraphicsSceneHelp:
345 return new QHelpEvent(*static_cast<QHelpEvent*>(e));
346 case QEvent::GraphicsSceneDragEnter:
347 case QEvent::GraphicsSceneDragMove:
348 case QEvent::GraphicsSceneDragLeave:
349 case QEvent::GraphicsSceneDrop: {
350 QGraphicsSceneDragDropEvent *dde = static_cast<QGraphicsSceneDragDropEvent*>(e);
351 QGraphicsSceneDragDropEvent *dde2 = new QGraphicsSceneDragDropEvent(dde->type());
352 dde2->setPos(dde->pos());
353 dde2->setScenePos(dde->scenePos());
354 dde2->setScreenPos(dde->screenPos());
355 dde2->setButtons(dde->buttons());
356 dde2->setModifiers(dde->modifiers());
357 return dde2;
358 }
359 case QEvent::GraphicsSceneWheel: {
360 QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent*>(e);
361 QGraphicsSceneWheelEvent *we2 = new QGraphicsSceneWheelEvent(we->type());
362 we2->setPos(we->pos());
363 we2->setScenePos(we->scenePos());
364 we2->setScreenPos(we->screenPos());
365 we2->setButtons(we->buttons());
366 we2->setModifiers(we->modifiers());
367 we2->setOrientation(we->orientation());
368 we2->setDelta(we->delta());
369 return we2;
370 }
371#endif
372 case QEvent::KeyboardLayoutChange:
373 return new QEvent(*e);
374
375 case QEvent::DynamicPropertyChange:
376 return new QDynamicPropertyChangeEvent(*static_cast<QDynamicPropertyChangeEvent*>(e));
377
378#if QT_CONFIG(tabletevent)
379 case QEvent::TabletEnterProximity:
380 case QEvent::TabletLeaveProximity:
381 return new QTabletEvent(*static_cast<QTabletEvent*>(e));
382#endif // QT_CONFIG(tabletevent)
383
384 case QEvent::NonClientAreaMouseMove:
385 case QEvent::NonClientAreaMouseButtonPress:
386 case QEvent::NonClientAreaMouseButtonRelease:
387 case QEvent::NonClientAreaMouseButtonDblClick:
388 return new QMouseEvent(*static_cast<QMouseEvent*>(e));
389
390 case QEvent::MacSizeChange:
391 return new QEvent(*e);
392
393 case QEvent::ContentsRectChange:
394 return new QEvent(*e);
395
396 case QEvent::MacGLWindowChange:
397 return new QEvent(*e);
398
399 case QEvent::FutureCallOut:
400 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
401 break;
402#if QT_CONFIG(graphicsview)
403 case QEvent::GraphicsSceneResize: {
404 QGraphicsSceneResizeEvent *re = static_cast<QGraphicsSceneResizeEvent*>(e);
405 QGraphicsSceneResizeEvent *re2 = new QGraphicsSceneResizeEvent();
406 re2->setOldSize(re->oldSize());
407 re2->setNewSize(re->newSize());
408 return re2;
409 }
410 case QEvent::GraphicsSceneMove: {
411 QGraphicsSceneMoveEvent *me = static_cast<QGraphicsSceneMoveEvent*>(e);
412 QGraphicsSceneMoveEvent *me2 = new QGraphicsSceneMoveEvent();
413 me2->setWidget(me->widget());
414 me2->setNewPos(me->newPos());
415 me2->setOldPos(me->oldPos());
416 return me2;
417 }
418#endif
419 case QEvent::CursorChange:
420 return new QEvent(*e);
421 case QEvent::ToolTipChange:
422 return new QEvent(*e);
423
424 case QEvent::NetworkReplyUpdated:
425 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
426 break;
427
428 case QEvent::GrabMouse:
429 case QEvent::UngrabMouse:
430 case QEvent::GrabKeyboard:
431 case QEvent::UngrabKeyboard:
432 return new QEvent(*e);
433
434 case QEvent::TouchBegin:
435 case QEvent::TouchUpdate:
436 case QEvent::TouchEnd:
437 return new QTouchEvent(*static_cast<QTouchEvent*>(e));
438
439#ifndef QT_NO_GESTURES
440 case QEvent::NativeGesture:
441 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
442 break;
443#endif
444
445 case QEvent::User:
446 case QEvent::MaxUser:
447 Q_ASSERT_X(false, "cloneEvent()", "not implemented");
448 break;
449 default:
450 ;
451 }
452 return qcoreStateMachineHandler()->cloneEvent(e);
453}
454
455const QStateMachinePrivate::Handler qt_gui_statemachine_handler = {
456 .cloneEvent: cloneEvent
457};
458
459static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = nullptr;
460void qRegisterGuiStateMachine()
461{
462 qt_guistatemachine_last_handler = QStateMachinePrivate::handler;
463 QStateMachinePrivate::handler = &qt_gui_statemachine_handler;
464}
465Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine)
466
467void qUnregisterGuiStateMachine()
468{
469 QStateMachinePrivate::handler = qt_guistatemachine_last_handler;
470}
471Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine)
472
473QT_END_NAMESPACE
474

source code of qtbase/src/widgets/statemachine/qguistatemachine.cpp