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 QtGui 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 "qevent.h"
41#include "qcursor.h"
42#include "private/qguiapplication_p.h"
43#include "private/qtouchdevice_p.h"
44#include "qpa/qplatformintegration.h"
45#include "private/qevent_p.h"
46#include "qfile.h"
47#include "qhashfunctions.h"
48#include "qmetaobject.h"
49#include "qmimedata.h"
50#include "qevent_p.h"
51#include "qmath.h"
52
53#if QT_CONFIG(draganddrop)
54#include <qpa/qplatformdrag.h>
55#include <private/qdnd_p.h>
56#endif
57
58#include <private/qdebug_p.h>
59
60QT_BEGIN_NAMESPACE
61
62/*!
63 \class QEnterEvent
64 \ingroup events
65 \inmodule QtGui
66
67 \brief The QEnterEvent class contains parameters that describe an enter event.
68
69 Enter events occur when the mouse cursor enters a window or a widget.
70
71 \since 5.0
72*/
73
74/*!
75 Constructs an enter event object.
76
77 The points \a localPos, \a windowPos and \a screenPos specify the
78 mouse cursor's position relative to the receiving widget or item,
79 window, and screen, respectively.
80*/
81
82QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos)
83 : QEvent(QEvent::Enter)
84 , l(localPos)
85 , w(windowPos)
86 , s(screenPos)
87{
88}
89
90/*!
91 \internal
92*/
93QEnterEvent::~QEnterEvent()
94{
95}
96
97/*!
98 \fn QPoint QEnterEvent::globalPos() const
99
100 Returns the global position of the mouse cursor \e{at the time of the event}.
101*/
102/*!
103 \fn int QEnterEvent::globalX() const
104
105 Returns the global position on the X-axis of the mouse cursor \e{at the time of the event}.
106*/
107/*!
108 \fn int QEnterEvent::globalY() const
109
110 Returns the global position on the Y-axis of the mouse cursor \e{at the time of the event}.
111*/
112/*!
113 \fn QPointF QEnterEvent::localPos() const
114
115 Returns the mouse cursor's position relative to the receiving widget.
116*/
117/*!
118 \fn QPoint QEnterEvent::pos() const
119
120 Returns the position of the mouse cursor relative to the receiving widget.
121*/
122/*!
123 \fn QPointF QEnterEvent::screenPos() const
124
125 Returns the position of the mouse cursor relative to the receiving screen.
126*/
127/*!
128 \fn QPointF QEnterEvent::windowPos() const
129
130 Returns the position of the mouse cursor relative to the receiving window.
131*/
132/*!
133 \fn int QEnterEvent::x() const
134
135 Returns the x position of the mouse cursor relative to the receiving widget.
136*/
137/*!
138 \fn int QEnterEvent::y() const
139
140 Returns the y position of the mouse cursor relative to the receiving widget.
141*/
142
143/*!
144 \class QInputEvent
145 \ingroup events
146 \inmodule QtGui
147
148 \brief The QInputEvent class is the base class for events that
149 describe user input.
150*/
151
152/*!
153 \internal
154*/
155QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
156 : QEvent(type), modState(modifiers), ts(0)
157{}
158
159/*!
160 \internal
161*/
162QInputEvent::~QInputEvent()
163{
164}
165
166/*!
167 \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
168
169 Returns the keyboard modifier flags that existed immediately
170 before the event occurred.
171
172 \sa QGuiApplication::keyboardModifiers()
173*/
174
175/*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
176
177 \internal
178
179 Sets the keyboard modifiers flags for this event.
180*/
181
182/*!
183 \fn ulong QInputEvent::timestamp() const
184
185 Returns the window system's timestamp for this event.
186 It will normally be in milliseconds since some arbitrary point
187 in time, such as the time when the system was started.
188*/
189
190/*! \fn void QInputEvent::setTimestamp(ulong atimestamp)
191
192 \internal
193
194 Sets the timestamp for this event.
195*/
196
197/*!
198 \class QMouseEvent
199 \ingroup events
200 \inmodule QtGui
201
202 \brief The QMouseEvent class contains parameters that describe a mouse event.
203
204 Mouse events occur when a mouse button is pressed or released
205 inside a widget, or when the mouse cursor is moved.
206
207 Mouse move events will occur only when a mouse button is pressed
208 down, unless mouse tracking has been enabled with
209 QWidget::setMouseTracking().
210
211 Qt automatically grabs the mouse when a mouse button is pressed
212 inside a widget; the widget will continue to receive mouse events
213 until the last mouse button is released.
214
215 A mouse event contains a special accept flag that indicates
216 whether the receiver wants the event. You should call ignore() if
217 the mouse event is not handled by your widget. A mouse event is
218 propagated up the parent widget chain until a widget accepts it
219 with accept(), or an event filter consumes it.
220
221 \note If a mouse event is propagated to a \l{QWidget}{widget} for
222 which Qt::WA_NoMousePropagation has been set, that mouse event
223 will not be propagated further up the parent widget chain.
224
225 The state of the keyboard modifier keys can be found by calling the
226 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
227 QInputEvent.
228
229 The functions pos(), x(), and y() give the cursor position
230 relative to the widget that receives the mouse event. If you
231 move the widget as a result of the mouse event, use the global
232 position returned by globalPos() to avoid a shaking motion.
233
234 The QWidget::setEnabled() function can be used to enable or
235 disable mouse and keyboard events for a widget.
236
237 Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
238 QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
239 and QWidget::mouseMoveEvent() to receive mouse events in your own
240 widgets.
241
242 \sa QWidget::setMouseTracking(), QWidget::grabMouse(),
243 QCursor::pos()
244*/
245
246/*!
247 Constructs a mouse event object.
248
249 The \a type parameter must be one of QEvent::MouseButtonPress,
250 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
251 or QEvent::MouseMove.
252
253 The \a localPos is the mouse cursor's position relative to the
254 receiving widget or item. The window position is set to the same value
255 as \a localPos.
256 The \a button that caused the event is given as a value from
257 the Qt::MouseButton enum. If the event \a type is
258 \l MouseMove, the appropriate button for this event is Qt::NoButton.
259 The mouse and keyboard states at the time of the event are specified by
260 \a buttons and \a modifiers.
261
262 The screenPos() is initialized to QCursor::pos(), which may not
263 be appropriate. Use the other constructor to specify the global
264 position explicitly.
265*/
266QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
267 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
268 : QInputEvent(type, modifiers), l(localPos), w(localPos), b(button), mouseState(buttons), caps(0)
269{
270#ifndef QT_NO_CURSOR
271 s = QCursor::pos();
272#endif
273}
274
275
276/*!
277 Constructs a mouse event object.
278
279 The \a type parameter must be QEvent::MouseButtonPress,
280 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
281 or QEvent::MouseMove.
282
283 The \a localPos is the mouse cursor's position relative to the
284 receiving widget or item. The cursor's position in screen coordinates is
285 specified by \a screenPos. The window position is set to the same value
286 as \a localPos. The \a button that caused the event is
287 given as a value from the \l Qt::MouseButton enum. If the event \a
288 type is \l MouseMove, the appropriate button for this event is
289 Qt::NoButton. \a buttons is the state of all buttons at the
290 time of the event, \a modifiers the state of all keyboard
291 modifiers.
292
293*/
294QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
295 Qt::MouseButton button, Qt::MouseButtons buttons,
296 Qt::KeyboardModifiers modifiers)
297 : QMouseEvent(type, localPos, localPos, screenPos, button, buttons, modifiers)
298{}
299
300/*!
301 Constructs a mouse event object.
302
303 The \a type parameter must be QEvent::MouseButtonPress,
304 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
305 or QEvent::MouseMove.
306
307 The points \a localPos, \a windowPos and \a screenPos specify the
308 mouse cursor's position relative to the receiving widget or item,
309 window, and screen, respectively.
310
311 The \a button that caused the event is
312 given as a value from the \l Qt::MouseButton enum. If the event \a
313 type is \l MouseMove, the appropriate button for this event is
314 Qt::NoButton. \a buttons is the state of all buttons at the
315 time of the event, \a modifiers the state of all keyboard
316 modifiers.
317
318*/
319QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
320 Qt::MouseButton button, Qt::MouseButtons buttons,
321 Qt::KeyboardModifiers modifiers)
322 : QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons), caps(0)
323{}
324
325/*!
326 \since 5.6
327
328 Constructs a mouse event object.
329
330 The \a type parameter must be QEvent::MouseButtonPress,
331 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
332 or QEvent::MouseMove.
333
334 The points \a localPos, \a windowPos and \a screenPos specify the
335 mouse cursor's position relative to the receiving widget or item,
336 window, and screen, respectively.
337
338 The \a button that caused the event is given as a value from the
339 \l Qt::MouseButton enum. If the event \a type is \l MouseMove,
340 the appropriate button for this event is Qt::NoButton. \a buttons
341 is the state of all buttons at the time of the event, \a modifiers
342 is the state of all keyboard modifiers.
343
344 The source of the event is specified by \a source.
345
346*/
347QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
348 Qt::MouseButton button, Qt::MouseButtons buttons,
349 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
350 : QMouseEvent(type, localPos, windowPos, screenPos, button, buttons, modifiers)
351{
352 QGuiApplicationPrivate::setMouseEventSource(this, source);
353}
354
355/*!
356 \internal
357*/
358QMouseEvent::~QMouseEvent()
359{
360}
361
362/*!
363 \since 5.3
364
365 Returns information about the mouse event source.
366
367 The mouse event source can be used to distinguish between genuine
368 and artificial mouse events. The latter are events that are
369 synthesized from touch events by the operating system or Qt itself.
370
371 \note Many platforms provide no such information. On such platforms
372 \l Qt::MouseEventNotSynthesized is returned always.
373
374 \sa Qt::MouseEventSource
375 \sa QGraphicsSceneMouseEvent::source()
376 */
377Qt::MouseEventSource QMouseEvent::source() const
378{
379 return QGuiApplicationPrivate::mouseEventSource(this);
380}
381
382/*!
383 \since 5.3
384
385 Returns the mouse event flags.
386
387 The mouse event flags provide additional information about a mouse event.
388
389 \sa Qt::MouseEventFlag
390 \sa QGraphicsSceneMouseEvent::flags()
391 */
392Qt::MouseEventFlags QMouseEvent::flags() const
393{
394 return QGuiApplicationPrivate::mouseEventFlags(this);
395}
396
397/*!
398 \fn QPointF QMouseEvent::localPos() const
399
400 \since 5.0
401
402 Returns the position of the mouse cursor as a QPointF, relative to the
403 widget or item that received the event.
404
405 If you move the widget as a result of the mouse event, use the
406 screen position returned by screenPos() to avoid a shaking
407 motion.
408
409 \sa x(), y(), windowPos(), screenPos()
410*/
411
412/*!
413 \fn void QMouseEvent::setLocalPos(const QPointF &localPosition)
414
415 \since 5.8
416
417 \internal
418
419 Sets the local position in the mouse event to \a localPosition. This allows to re-use one event
420 when sending it to a series of receivers that expect the local pos in their
421 respective local coordinates.
422*/
423
424/*!
425 \fn QPointF QMouseEvent::windowPos() const
426
427 \since 5.0
428
429 Returns the position of the mouse cursor as a QPointF, relative to the
430 window that received the event.
431
432 If you move the widget as a result of the mouse event, use the
433 global position returned by globalPos() to avoid a shaking
434 motion.
435
436 \sa x(), y(), pos(), localPos(), screenPos()
437*/
438
439/*!
440 \fn QPointF QMouseEvent::screenPos() const
441
442 \since 5.0
443
444 Returns the position of the mouse cursor as a QPointF, relative to the
445 screen that received the event.
446
447 \sa x(), y(), pos(), localPos(), windowPos()
448*/
449
450/*!
451 \fn QPoint QMouseEvent::pos() const
452
453 Returns the position of the mouse cursor, relative to the widget
454 that received the event.
455
456 If you move the widget as a result of the mouse event, use the
457 global position returned by globalPos() to avoid a shaking
458 motion.
459
460 \sa x(), y(), globalPos()
461*/
462
463/*!
464 \fn QPoint QMouseEvent::globalPos() const
465
466 Returns the global position of the mouse cursor \e{at the time
467 of the event}. This is important on asynchronous window systems
468 like X11. Whenever you move your widgets around in response to
469 mouse events, globalPos() may differ a lot from the current
470 pointer position QCursor::pos(), and from
471 QWidget::mapToGlobal(pos()).
472
473 \sa globalX(), globalY()
474*/
475
476/*!
477 \fn int QMouseEvent::x() const
478
479 Returns the x position of the mouse cursor, relative to the
480 widget that received the event.
481
482 \sa y(), pos()
483*/
484
485/*!
486 \fn int QMouseEvent::y() const
487
488 Returns the y position of the mouse cursor, relative to the
489 widget that received the event.
490
491 \sa x(), pos()
492*/
493
494/*!
495 \fn int QMouseEvent::globalX() const
496
497 Returns the global x position of the mouse cursor at the time of
498 the event.
499
500 \sa globalY(), globalPos()
501*/
502
503/*!
504 \fn int QMouseEvent::globalY() const
505
506 Returns the global y position of the mouse cursor at the time of
507 the event.
508
509 \sa globalX(), globalPos()
510*/
511
512/*!
513 \fn Qt::MouseButton QMouseEvent::button() const
514
515 Returns the button that caused the event.
516
517 Note that the returned value is always Qt::NoButton for mouse
518 move events.
519
520 \sa buttons(), Qt::MouseButton
521*/
522
523/*!
524 \fn Qt::MouseButton QMouseEvent::buttons() const
525
526 Returns the button state when the event was generated. The button
527 state is a combination of Qt::LeftButton, Qt::RightButton,
528 Qt::MidButton using the OR operator. For mouse move events,
529 this is all buttons that are pressed down. For mouse press and
530 double click events this includes the button that caused the
531 event. For mouse release events this excludes the button that
532 caused the event.
533
534 \sa button(), Qt::MouseButton
535*/
536
537/*!
538 \fn QPointF QMouseEvent::posF() const
539 \obsolete
540
541 Use localPos() instead.
542*/
543
544/*!
545 \class QHoverEvent
546 \ingroup events
547 \inmodule QtGui
548
549 \brief The QHoverEvent class contains parameters that describe a mouse event.
550
551 Mouse events occur when a mouse cursor is moved into, out of, or within a
552 widget, and if the widget has the Qt::WA_Hover attribute.
553
554 The function pos() gives the current cursor position, while oldPos() gives
555 the old mouse position.
556
557 There are a few similarities between the events QEvent::HoverEnter
558 and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
559 However, they are slightly different because we do an update() in the event
560 handler of HoverEnter and HoverLeave.
561
562 QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
563 consider a top-level window A containing a child B which in turn contains a
564 child C (all with mouse tracking enabled):
565
566 \image hoverevents.png
567
568 Now, if you move the cursor from the top to the bottom in the middle of A,
569 you will get the following QEvent::MouseMove events:
570
571 \list 1
572 \li A::MouseMove
573 \li B::MouseMove
574 \li C::MouseMove
575 \endlist
576
577 You will get the same events for QEvent::HoverMove, except that the event
578 always propagates to the top-level regardless whether the event is accepted
579 or not. It will only stop propagating with the Qt::WA_NoMousePropagation
580 attribute.
581
582 In this case the events will occur in the following way:
583
584 \list 1
585 \li A::HoverMove
586 \li A::HoverMove, B::HoverMove
587 \li A::HoverMove, B::HoverMove, C::HoverMove
588 \endlist
589
590*/
591
592/*!
593 \fn QPoint QHoverEvent::pos() const
594
595 Returns the position of the mouse cursor, relative to the widget
596 that received the event.
597
598 On QEvent::HoverLeave events, this position will always be
599 QPoint(-1, -1).
600
601 \sa oldPos()
602*/
603
604/*!
605 \fn QPoint QHoverEvent::oldPos() const
606
607 Returns the previous position of the mouse cursor, relative to the widget
608 that received the event. If there is no previous position, oldPos() will
609 return the same position as pos().
610
611 On QEvent::HoverEnter events, this position will always be
612 QPoint(-1, -1).
613
614 \sa pos()
615*/
616
617/*!
618 \fn const QPointF &QHoverEvent::posF() const
619
620 Returns the position of the mouse cursor, relative to the widget
621 that received the event.
622
623 On QEvent::HoverLeave events, this position will always be
624 QPointF(-1, -1).
625
626 \sa oldPosF()
627*/
628
629/*!
630 \fn const QPointF &QHoverEvent::oldPosF() const
631
632 Returns the previous position of the mouse cursor, relative to the widget
633 that received the event. If there is no previous position, oldPosF() will
634 return the same position as posF().
635
636 On QEvent::HoverEnter events, this position will always be
637 QPointF(-1, -1).
638
639 \sa posF()
640*/
641
642/*!
643 Constructs a hover event object.
644
645 The \a type parameter must be QEvent::HoverEnter,
646 QEvent::HoverLeave, or QEvent::HoverMove.
647
648 The \a pos is the current mouse cursor's position relative to the
649 receiving widget, while \a oldPos is its previous such position.
650 \a modifiers hold the state of all keyboard modifiers at the time
651 of the event.
652*/
653QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers)
654 : QInputEvent(type, modifiers), p(pos), op(oldPos)
655{
656}
657
658/*!
659 \internal
660*/
661QHoverEvent::~QHoverEvent()
662{
663}
664
665
666/*!
667 \class QWheelEvent
668 \brief The QWheelEvent class contains parameters that describe a wheel event.
669 \inmodule QtGui
670
671 \ingroup events
672
673 Wheel events are sent to the widget under the mouse cursor, but
674 if that widget does not handle the event they are sent to the
675 focus widget. Wheel events are generated for both mouse wheels
676 and trackpad scroll gestures. There are two ways to read the
677 wheel event delta: angleDelta() returns the delta in wheel
678 degrees. This value is always provided. pixelDelta() returns
679 the delta in screen pixels and is available on platforms that
680 have high-resolution trackpads, such as \macos. If that is the
681 case, source() will return Qt::MouseEventSynthesizedBySystem.
682
683 The functions pos() and globalPos() return the mouse cursor's
684 location at the time of the event.
685
686 A wheel event contains a special accept flag that indicates
687 whether the receiver wants the event. You should call ignore() if
688 you do not handle the wheel event; this ensures that it will be
689 sent to the parent widget.
690
691 The QWidget::setEnabled() function can be used to enable or
692 disable mouse and keyboard events for a widget.
693
694 The event handler QWidget::wheelEvent() receives wheel events.
695
696 \sa QMouseEvent, QWidget::grabMouse()
697*/
698
699/*!
700 \enum QWheelEvent::anonymous
701 \internal
702
703 \value DefaultDeltasPerStep Defaqult deltas per step
704*/
705
706/*!
707 \fn Qt::MouseButtons QWheelEvent::buttons() const
708
709 Returns the mouse state when the event occurred.
710*/
711
712/*!
713 \fn Qt::MouseEventSource QWheelEvent::source() const
714 \since 5.5
715
716 Returns information about the wheel event source.
717
718 The source can be used to distinguish between events that come from a mouse
719 with a physical wheel and events that are generated by some other means,
720 such as a flick gesture on a touchpad.
721
722 \note Many platforms provide no such information. On such platforms
723 \l Qt::MouseEventNotSynthesized is returned always.
724
725 \sa Qt::MouseEventSource
726*/
727
728/*!
729 \fn bool QWheelEvent::inverted() const
730 \since 5.7
731
732 Returns whether the delta values delivered with the event are inverted.
733
734 Normally, a vertical wheel will produce a QWheelEvent with positive delta
735 values if the top of the wheel is rotating away from the hand operating it.
736 Similarly, a horizontal wheel movement will produce a QWheelEvent with
737 positive delta values if the top of the wheel is moved to the left.
738
739 However, on some platforms this is configurable, so that the same
740 operations described above will produce negative delta values (but with the
741 same magnitude). With the inverted property a wheel event consumer can
742 choose to always follow the direction of the wheel, regardless of the
743 system settings, but only for specific widgets. (One such use case could be
744 that the user is rotating the wheel in the same direction as a visual
745 Tumbler rotates. Another usecase is to make a slider handle follow the
746 direction of movement of fingers on a touchpad regardless of system
747 configuration.)
748
749 \note Many platforms provide no such information. On such platforms
750 \l inverted always returns false.
751*/
752
753/*!
754 \fn Qt::Orientation QWheelEvent::orientation() const
755 \obsolete
756
757 Use angleDelta() instead.
758*/
759
760#if QT_CONFIG(wheelevent)
761#if QT_DEPRECATED_SINCE(5, 15)
762/*!
763 \obsolete
764 This constructor has been deprecated.
765*/
766QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
767 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
768 Qt::Orientation orient)
769 : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons),
770 src(Qt::MouseEventNotSynthesized), invertedScrolling(false), ph(Qt::NoScrollPhase)
771{
772 g = QCursor::pos();
773 if (orient == Qt::Vertical)
774 angleD = QPoint(0, delta);
775 else
776 angleD = QPoint(delta, 0);
777}
778
779/*!
780 \obsolete
781 This constructor has been deprecated.
782*/
783QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
784 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
785 Qt::Orientation orient)
786 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons),
787 src(Qt::MouseEventNotSynthesized), invertedScrolling(false), ph(Qt::NoScrollPhase)
788{
789 if (orient == Qt::Vertical)
790 angleD = QPoint(0, delta);
791 else
792 angleD = QPoint(delta, 0);
793}
794
795/*!
796 \obsolete
797 This constructor has been deprecated.
798*/
799
800QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
801 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
802 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
803 : QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
804 buttons, modifiers, Qt::NoScrollPhase)
805{}
806
807/*!
808 \obsolete
809 This constructor has been deprecated.
810*/
811
812QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
813 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
814 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase)
815 : QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
816 buttons, modifiers, phase, Qt::MouseEventNotSynthesized)
817{}
818
819/*!
820 \obsolete
821 This constructor has been deprecated.
822*/
823
824QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
825 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
826 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source)
827 : QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
828 buttons, modifiers, phase, source, false)
829{}
830
831/*!
832 \obsolete
833 This constructor has been deprecated.
834*/
835QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
836 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
837 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted)
838 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
839 angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), src(source),
840 invertedScrolling(inverted), ph(phase)
841{}
842#endif // QT_DEPRECATED_SINCE(5, 15)
843
844/*!
845 Constructs a wheel event object.
846
847 The \a pos provides the location of the mouse cursor
848 within the window. The position in global coordinates is specified
849 by \a globalPos.
850
851 \a pixelDelta contains the scrolling distance in pixels on screen, while
852 \a angleDelta contains the wheel rotation distance. \a pixelDelta is
853 optional and can be null.
854
855 The mouse and keyboard states at the time of the event are specified by
856 \a buttons and \a modifiers.
857
858 The scrolling phase of the event is specified by \a phase.
859
860 If the wheel event comes from a physical mouse wheel, \a source is set to
861 Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
862 operating system, or from a non-mouse hardware device, such that \a
863 pixelDelta is directly related to finger movement, \a source is set to
864 Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set
865 to Qt::MouseEventSynthesizedByQt.
866
867 If the system is configured to invert the delta values delivered with the
868 event (such as natural scrolling of the touchpad on macOS), \a inverted
869 should be \c true. Otherwise, \a inverted is \c false
870
871 \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), source()
872*/
873QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
874 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
875 bool inverted, Qt::MouseEventSource source)
876 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta),
877 qt4O(qAbs(angleDelta.x()) > qAbs(angleDelta.y()) ? Qt::Horizontal : Qt::Vertical),
878 mouseState(buttons), src(source), invertedScrolling(inverted), ph(phase)
879{
880 qt4D = (qt4O == Qt::Horizontal ? angleDelta.x() : angleDelta.y());
881}
882
883/*!
884 \internal
885*/
886QWheelEvent::~QWheelEvent()
887{
888}
889#endif // QT_CONFIG(wheelevent)
890
891/*!
892 \fn QPoint QWheelEvent::pixelDelta() const
893
894 Returns the scrolling distance in pixels on screen. This value is
895 provided on platforms that support high-resolution pixel-based
896 delta values, such as \macos. The value should be used directly
897 to scroll content on screen.
898
899 Example:
900
901 \snippet code/src_gui_kernel_qevent.cpp 0
902
903 \note On platforms that support scrolling \l{phase()}{phases}, the delta may be null when:
904 \list
905 \li scrolling is about to begin, but the distance did not yet change (Qt::ScrollBegin),
906 \li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd).
907 \endlist
908 \note On X11 this value is driver specific and unreliable, use angleDelta() instead
909*/
910
911/*!
912 \fn QPoint QWheelEvent::angleDelta() const
913
914 Returns the distance that the wheel is rotated, in eighths of a
915 degree. A positive value indicates that the wheel was rotated
916 forwards away from the user; a negative value indicates that the
917 wheel was rotated backwards toward the user.
918
919 Most mouse types work in steps of 15 degrees, in which case the
920 delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
921
922 However, some mice have finer-resolution wheels and send delta values
923 that are less than 120 units (less than 15 degrees). To support this
924 possibility, you can either cumulatively add the delta values from events
925 until the value of 120 is reached, then scroll the widget, or you can
926 partially scroll the widget in response to each wheel event.
927
928 Example:
929
930 \snippet code/src_gui_kernel_qevent.cpp 0
931
932 \note On platforms that support scrolling \l{phase()}{phases}, the delta may be null when:
933 \list
934 \li scrolling is about to begin, but the distance did not yet change (Qt::ScrollBegin),
935 \li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd).
936 \endlist
937*/
938
939/*!
940 \fn int QWheelEvent::delta() const
941 \obsolete
942
943 This function has been deprecated, use pixelDelta() or angleDelta() instead.
944*/
945
946/*!
947 \fn QPoint QWheelEvent::pos() const
948 \obsolete
949
950 This function has been deprecated, use position() instead.
951*/
952
953/*!
954 \fn int QWheelEvent::x() const
955 \obsolete
956
957 This function has been deprecated, use position() instead.
958*/
959
960/*!
961 \fn int QWheelEvent::y() const
962 \obsolete
963
964 This function has been deprecated, use position() instead.
965*/
966
967
968/*!
969 \fn QPoint QWheelEvent::globalPos() const
970 \obsolete
971
972 This function has been deprecated, use globalPosition() instead.
973*/
974
975/*!
976 \fn int QWheelEvent::globalX() const
977 \obsolete
978
979 This function has been deprecated, use globalPosition() instead.
980*/
981
982/*!
983 \fn int QWheelEvent::globalY() const
984 \obsolete
985
986 This function has been deprecated, use globalPosition() instead.
987*/
988
989/*!
990 \fn const QPointF &QWheelEvent::posF() const
991 \obsolete
992
993 This function has been deprecated, use position() instead.
994*/
995
996/*!
997 \fn const QPointF &QWheelEvent::globalPosF() const
998 \obsolete
999
1000 This function has been deprecated, use globalPosition() instead.
1001*/
1002
1003/*!
1004 \fn Qt::ScrollPhase QWheelEvent::phase() const
1005 \since 5.2
1006
1007 Returns the scrolling phase of this wheel event.
1008
1009 \note The Qt::ScrollBegin and Qt::ScrollEnd phases are currently
1010 supported only on \macos.
1011*/
1012
1013
1014/*!
1015 \class QKeyEvent
1016 \brief The QKeyEvent class describes a key event.
1017
1018 \ingroup events
1019 \inmodule QtGui
1020
1021 Key events are sent to the widget with keyboard input focus
1022 when keys are pressed or released.
1023
1024 A key event contains a special accept flag that indicates whether
1025 the receiver will handle the key event. This flag is set by default
1026 for QEvent::KeyPress and QEvent::KeyRelease, so there is no need to
1027 call accept() when acting on a key event. For QEvent::ShortcutOverride
1028 the receiver needs to explicitly accept the event to trigger the override.
1029 Calling ignore() on a key event will propagate it to the parent widget.
1030 The event is propagated up the parent widget chain until a widget
1031 accepts it or an event filter consumes it.
1032
1033 The QWidget::setEnabled() function can be used to enable or disable
1034 mouse and keyboard events for a widget.
1035
1036 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
1037 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
1038 receive key events.
1039
1040 \sa QFocusEvent, QWidget::grabKeyboard()
1041*/
1042
1043/*!
1044 Constructs a key event object.
1045
1046 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
1047 or QEvent::ShortcutOverride.
1048
1049 Int \a key is the code for the Qt::Key that the event loop should listen
1050 for. If \a key is 0, the event is not a result of a known key; for
1051 example, it may be the result of a compose sequence or keyboard macro.
1052 The \a modifiers holds the keyboard modifiers, and the given \a text
1053 is the Unicode text that the key generated. If \a autorep is true,
1054 isAutoRepeat() will be true. \a count is the number of keys involved
1055 in the event.
1056*/
1057QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
1058 bool autorep, ushort count)
1059 : QInputEvent(type, modifiers), txt(text), k(key),
1060 nScanCode(0), nVirtualKey(0), nModifiers(0),
1061 c(count), autor(autorep)
1062{
1063 if (type == QEvent::ShortcutOverride)
1064 ignore();
1065}
1066
1067/*!
1068 Constructs a key event object.
1069
1070 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
1071 or QEvent::ShortcutOverride.
1072
1073 Int \a key is the code for the Qt::Key that the event loop should listen
1074 for. If \a key is 0, the event is not a result of a known key; for
1075 example, it may be the result of a compose sequence or keyboard macro.
1076 The \a modifiers holds the keyboard modifiers, and the given \a text
1077 is the Unicode text that the key generated. If \a autorep is true,
1078 isAutoRepeat() will be true. \a count is the number of keys involved
1079 in the event.
1080
1081 In addition to the normal key event data, also contains \a nativeScanCode,
1082 \a nativeVirtualKey and \a nativeModifiers. This extra data is used by the
1083 shortcut system, to determine which shortcuts to trigger.
1084*/
1085QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
1086 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
1087 const QString &text, bool autorep, ushort count)
1088 : QInputEvent(type, modifiers), txt(text), k(key),
1089 nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers),
1090 c(count), autor(autorep)
1091{
1092 if (type == QEvent::ShortcutOverride)
1093 ignore();
1094}
1095
1096
1097/*!
1098 \internal
1099*/
1100QKeyEvent::~QKeyEvent()
1101{
1102}
1103
1104/*!
1105 \fn QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text, bool autorep, ushort count)
1106 \internal
1107*/
1108
1109/*!
1110 \fn bool QKeyEvent::hasExtendedInfo() const
1111 \internal
1112*/
1113
1114/*!
1115 \fn quint32 QKeyEvent::nativeScanCode() const
1116 \since 4.2
1117
1118 Returns the native scan code of the key event. If the key event
1119 does not contain this data 0 is returned.
1120
1121 Note: The native scan code may be 0, even if the key event contains
1122 extended information.
1123
1124 Note: On Mac OS/X, this function is not useful, because there is no
1125 way to get the scan code from Carbon or Cocoa. The function always
1126 returns 1 (or 0 in the case explained above).
1127*/
1128
1129/*!
1130 \fn quint32 QKeyEvent::nativeVirtualKey() const
1131 \since 4.2
1132
1133 Returns the native virtual key, or key sym of the key event.
1134 If the key event does not contain this data 0 is returned.
1135
1136 Note: The native virtual key may be 0, even if the key event contains extended information.
1137*/
1138
1139/*!
1140 \fn quint32 QKeyEvent::nativeModifiers() const
1141 \since 4.2
1142
1143 Returns the native modifiers of a key event.
1144 If the key event does not contain this data 0 is returned.
1145
1146 Note: The native modifiers may be 0, even if the key event contains extended information.
1147*/
1148
1149/*!
1150 \fn int QKeyEvent::key() const
1151
1152 Returns the code of the key that was pressed or released.
1153
1154 See \l Qt::Key for the list of keyboard codes. These codes are
1155 independent of the underlying window system. Note that this
1156 function does not distinguish between capital and non-capital
1157 letters, use the text() function (returning the Unicode text the
1158 key generated) for this purpose.
1159
1160 A value of either 0 or Qt::Key_unknown means that the event is not
1161 the result of a known key; for example, it may be the result of
1162 a compose sequence, a keyboard macro, or due to key event
1163 compression.
1164
1165 \sa Qt::WA_KeyCompression
1166*/
1167
1168/*!
1169 \fn QString QKeyEvent::text() const
1170
1171 Returns the Unicode text that this key generated.
1172
1173 Return values when modifier keys such as
1174 Shift, Control, Alt, and Meta are pressed
1175 differ among platforms and could return an empty string.
1176
1177 \note \l key() will always return a valid value,
1178 independent of modifier keys.
1179
1180 \sa Qt::WA_KeyCompression
1181*/
1182
1183/*!
1184 Returns the keyboard modifier flags that existed immediately
1185 after the event occurred.
1186
1187 \warning This function cannot always be trusted. The user can
1188 confuse it by pressing both \uicontrol{Shift} keys simultaneously and
1189 releasing one of them, for example.
1190
1191 \sa QGuiApplication::keyboardModifiers()
1192*/
1193
1194Qt::KeyboardModifiers QKeyEvent::modifiers() const
1195{
1196 if (key() == Qt::Key_Shift)
1197 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
1198 if (key() == Qt::Key_Control)
1199 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
1200 if (key() == Qt::Key_Alt)
1201 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
1202 if (key() == Qt::Key_Meta)
1203 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
1204 if (key() == Qt::Key_AltGr)
1205 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::GroupSwitchModifier);
1206 return QInputEvent::modifiers();
1207}
1208
1209#ifndef QT_NO_SHORTCUT
1210/*!
1211 \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
1212 \since 4.2
1213
1214 Returns \c true if the key event matches the given standard \a key;
1215 otherwise returns \c false.
1216*/
1217bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
1218{
1219 //The keypad and group switch modifier should not make a difference
1220 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier | Qt::GroupSwitchModifier);
1221
1222 const QList<QKeySequence> bindings = QKeySequence::keyBindings(matchKey);
1223 return bindings.contains(QKeySequence(searchkey));
1224}
1225#endif // QT_NO_SHORTCUT
1226
1227
1228/*!
1229 \fn bool QKeyEvent::isAutoRepeat() const
1230
1231 Returns \c true if this event comes from an auto-repeating key;
1232 returns \c false if it comes from an initial key press.
1233
1234 Note that if the event is a multiple-key compressed event that is
1235 partly due to auto-repeat, this function could return either true
1236 or false indeterminately.
1237*/
1238
1239/*!
1240 \fn int QKeyEvent::count() const
1241
1242 Returns the number of keys involved in this event. If text()
1243 is not empty, this is simply the length of the string.
1244
1245 \sa Qt::WA_KeyCompression
1246*/
1247
1248/*!
1249 \class QFocusEvent
1250 \brief The QFocusEvent class contains event parameters for widget focus
1251 events.
1252 \inmodule QtGui
1253
1254 \ingroup events
1255
1256 Focus events are sent to widgets when the keyboard input focus
1257 changes. Focus events occur due to mouse actions, key presses
1258 (such as \uicontrol{Tab} or \uicontrol{Backtab}), the window system, popup
1259 menus, keyboard shortcuts, or other application-specific reasons.
1260 The reason for a particular focus event is returned by reason()
1261 in the appropriate event handler.
1262
1263 The event handlers QWidget::focusInEvent(),
1264 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
1265 QGraphicsItem::focusOutEvent() receive focus events.
1266
1267 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus in Widgets}
1268*/
1269
1270/*!
1271 Constructs a focus event object.
1272
1273 The \a type parameter must be either QEvent::FocusIn or
1274 QEvent::FocusOut. The \a reason describes the cause of the change
1275 in focus.
1276*/
1277QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
1278 : QEvent(type), m_reason(reason)
1279{}
1280
1281/*!
1282 \internal
1283*/
1284QFocusEvent::~QFocusEvent()
1285{
1286}
1287
1288/*!
1289 Returns the reason for this focus event.
1290 */
1291Qt::FocusReason QFocusEvent::reason() const
1292{
1293 return m_reason;
1294}
1295
1296/*!
1297 \fn bool QFocusEvent::gotFocus() const
1298
1299 Returns \c true if type() is QEvent::FocusIn; otherwise returns
1300 false.
1301*/
1302
1303/*!
1304 \fn bool QFocusEvent::lostFocus() const
1305
1306 Returns \c true if type() is QEvent::FocusOut; otherwise returns
1307 false.
1308*/
1309
1310
1311/*!
1312 \class QPaintEvent
1313 \brief The QPaintEvent class contains event parameters for paint events.
1314 \inmodule QtGui
1315
1316 \ingroup events
1317
1318 Paint events are sent to widgets that need to update themselves,
1319 for instance when part of a widget is exposed because a covering
1320 widget was moved.
1321
1322 The event contains a region() that needs to be updated, and a
1323 rect() that is the bounding rectangle of that region. Both are
1324 provided because many widgets cannot make much use of region(),
1325 and rect() can be much faster than region().boundingRect().
1326
1327 \section1 Automatic Clipping
1328
1329 Painting is clipped to region() during the processing of a paint
1330 event. This clipping is performed by Qt's paint system and is
1331 independent of any clipping that may be applied to a QPainter used to
1332 draw on the paint device.
1333
1334 As a result, the value returned by QPainter::clipRegion() on
1335 a newly-constructed QPainter will not reflect the clip region that is
1336 used by the paint system.
1337
1338 \sa QPainter, QWidget::update(), QWidget::repaint(),
1339 QWidget::paintEvent()
1340*/
1341
1342/*!
1343 Constructs a paint event object with the region that needs to
1344 be updated. The region is specified by \a paintRegion.
1345*/
1346QPaintEvent::QPaintEvent(const QRegion& paintRegion)
1347 : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
1348{}
1349
1350/*!
1351 Constructs a paint event object with the rectangle that needs
1352 to be updated. The region is specified by \a paintRect.
1353*/
1354QPaintEvent::QPaintEvent(const QRect &paintRect)
1355 : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
1356{}
1357
1358
1359/*!
1360 \internal
1361*/
1362QPaintEvent::~QPaintEvent()
1363{
1364}
1365
1366/*!
1367 \fn const QRect &QPaintEvent::rect() const
1368
1369 Returns the rectangle that needs to be updated.
1370
1371 \sa region(), QPainter::setClipRect()
1372*/
1373
1374/*!
1375 \fn const QRegion &QPaintEvent::region() const
1376
1377 Returns the region that needs to be updated.
1378
1379 \sa rect(), QPainter::setClipRegion()
1380*/
1381
1382
1383/*!
1384 \class QMoveEvent
1385 \brief The QMoveEvent class contains event parameters for move events.
1386 \inmodule QtGui
1387
1388 \ingroup events
1389
1390 Move events are sent to widgets that have been moved to a new
1391 position relative to their parent.
1392
1393 The event handler QWidget::moveEvent() receives move events.
1394
1395 \sa QWidget::move(), QWidget::setGeometry()
1396*/
1397
1398/*!
1399 Constructs a move event with the new and old widget positions,
1400 \a pos and \a oldPos respectively.
1401*/
1402QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
1403 : QEvent(Move), p(pos), oldp(oldPos)
1404{}
1405
1406/*!
1407 \internal
1408*/
1409QMoveEvent::~QMoveEvent()
1410{
1411}
1412
1413/*!
1414 \fn const QPoint &QMoveEvent::pos() const
1415
1416 Returns the new position of the widget. This excludes the window
1417 frame for top level widgets.
1418*/
1419
1420/*!
1421 \fn const QPoint &QMoveEvent::oldPos() const
1422
1423 Returns the old position of the widget.
1424*/
1425
1426/*!
1427 \class QExposeEvent
1428 \since 5.0
1429 \brief The QExposeEvent class contains event parameters for expose events.
1430 \inmodule QtGui
1431
1432 \ingroup events
1433
1434 Expose events are sent to windows when an area of the window is invalidated,
1435 for example when window exposure in the windowing system changes.
1436
1437 A Window with a client area that is completely covered by another window, or
1438 is otherwise not visible may be considered obscured by Qt and may in such
1439 cases not receive expose events.
1440
1441 The event handler QWindow::exposeEvent() receives expose events.
1442*/
1443
1444/*!
1445 Constructs an expose event for the given \a exposeRegion which must be
1446 in local coordinates.
1447*/
1448QExposeEvent::QExposeEvent(const QRegion &exposeRegion)
1449 : QEvent(Expose)
1450 , rgn(exposeRegion)
1451{
1452}
1453
1454/*!
1455 \internal
1456*/
1457QExposeEvent::~QExposeEvent()
1458{
1459}
1460
1461/*!
1462 \class QPlatformSurfaceEvent
1463 \since 5.5
1464 \brief The QPlatformSurfaceEvent class is used to notify about native platform surface events.
1465 \inmodule QtGui
1466
1467 \ingroup events
1468
1469 Platform window events are synchronously sent to windows and offscreen surfaces when their
1470 underlying native surfaces are created or are about to be destroyed.
1471
1472 Applications can respond to these events to know when the underlying platform
1473 surface exists.
1474*/
1475
1476/*!
1477 \enum QPlatformSurfaceEvent::SurfaceEventType
1478
1479 This enum describes the type of platform surface event. The possible types are:
1480
1481 \value SurfaceCreated The underlying native surface has been created
1482 \value SurfaceAboutToBeDestroyed The underlying native surface will be destroyed immediately after this event
1483
1484 The \c SurfaceAboutToBeDestroyed event type is useful as a means of stopping rendering to
1485 a platform window before it is destroyed.
1486*/
1487
1488/*!
1489 \fn QPlatformSurfaceEvent::SurfaceEventType QPlatformSurfaceEvent::surfaceEventType() const
1490
1491 Returns the specific type of platform surface event.
1492*/
1493
1494/*!
1495 Constructs a platform surface event for the given \a surfaceEventType.
1496*/
1497QPlatformSurfaceEvent::QPlatformSurfaceEvent(SurfaceEventType surfaceEventType)
1498 : QEvent(PlatformSurface)
1499 , m_surfaceEventType(surfaceEventType)
1500{
1501}
1502
1503/*!
1504 \internal
1505*/
1506QPlatformSurfaceEvent::~QPlatformSurfaceEvent()
1507{
1508}
1509
1510/*!
1511 \fn const QRegion &QExposeEvent::region() const
1512
1513 Returns the window area that has been exposed. The region is given in local coordinates.
1514*/
1515
1516/*!
1517 \class QResizeEvent
1518 \brief The QResizeEvent class contains event parameters for resize events.
1519 \inmodule QtGui
1520
1521 \ingroup events
1522
1523 Resize events are sent to widgets that have been resized.
1524
1525 The event handler QWidget::resizeEvent() receives resize events.
1526
1527 \sa QWidget::resize(), QWidget::setGeometry()
1528*/
1529
1530/*!
1531 Constructs a resize event with the new and old widget sizes, \a
1532 size and \a oldSize respectively.
1533*/
1534QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
1535 : QEvent(Resize), s(size), olds(oldSize)
1536{}
1537
1538/*!
1539 \internal
1540*/
1541QResizeEvent::~QResizeEvent()
1542{
1543}
1544
1545/*!
1546 \fn const QSize &QResizeEvent::size() const
1547
1548 Returns the new size of the widget. This is the same as
1549 QWidget::size().
1550*/
1551
1552/*!
1553 \fn const QSize &QResizeEvent::oldSize() const
1554
1555 Returns the old size of the widget.
1556*/
1557
1558
1559/*!
1560 \class QCloseEvent
1561 \brief The QCloseEvent class contains parameters that describe a close event.
1562
1563 \ingroup events
1564 \inmodule QtGui
1565
1566 Close events are sent to widgets that the user wants to close,
1567 usually by choosing "Close" from the window menu, or by clicking
1568 the \uicontrol{X} title bar button. They are also sent when you call
1569 QWidget::close() to close a widget programmatically.
1570
1571 Close events contain a flag that indicates whether the receiver
1572 wants the widget to be closed or not. When a widget accepts the
1573 close event, it is hidden (and destroyed if it was created with
1574 the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
1575 event nothing happens. (Under X11 it is possible that the window
1576 manager will forcibly close the window; but at the time of writing
1577 we are not aware of any window manager that does this.)
1578
1579 The event handler QWidget::closeEvent() receives close events. The
1580 default implementation of this event handler accepts the close
1581 event. If you do not want your widget to be hidden, or want some
1582 special handling, you should reimplement the event handler and
1583 ignore() the event.
1584
1585 The \l{mainwindows/application#close event handler}{closeEvent() in the
1586 Application example} shows a close event handler that
1587 asks whether to save a document before closing.
1588
1589 If you want the widget to be deleted when it is closed, create it
1590 with the Qt::WA_DeleteOnClose flag. This is very useful for
1591 independent top-level windows in a multi-window application.
1592
1593 \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
1594 signal when they are deleted.
1595
1596 If the last top-level window is closed, the
1597 QGuiApplication::lastWindowClosed() signal is emitted.
1598
1599 The isAccepted() function returns \c true if the event's receiver has
1600 agreed to close the widget; call accept() to agree to close the
1601 widget and call ignore() if the receiver of this event does not
1602 want the widget to be closed.
1603
1604 \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
1605 QCoreApplication::exec(), QCoreApplication::quit(),
1606 QGuiApplication::lastWindowClosed()
1607*/
1608
1609/*!
1610 Constructs a close event object.
1611
1612 \sa accept()
1613*/
1614QCloseEvent::QCloseEvent()
1615 : QEvent(Close)
1616{}
1617
1618/*! \internal
1619*/
1620QCloseEvent::~QCloseEvent()
1621{
1622}
1623
1624/*!
1625 \class QIconDragEvent
1626 \brief The QIconDragEvent class indicates that a main icon drag has begun.
1627 \inmodule QtGui
1628
1629 \ingroup events
1630
1631 Icon drag events are sent to widgets when the main icon of a window
1632 has been dragged away. On \macos, this happens when the proxy
1633 icon of a window is dragged off the title bar.
1634
1635 It is normal to begin using drag and drop in response to this
1636 event.
1637
1638 \sa {Drag and Drop}, QMimeData, QDrag
1639*/
1640
1641/*!
1642 Constructs an icon drag event object with the accept flag set to
1643 false.
1644
1645 \sa accept()
1646*/
1647QIconDragEvent::QIconDragEvent()
1648 : QEvent(IconDrag)
1649{ ignore(); }
1650
1651/*! \internal */
1652QIconDragEvent::~QIconDragEvent()
1653{
1654}
1655
1656/*!
1657 \class QContextMenuEvent
1658 \brief The QContextMenuEvent class contains parameters that describe a context menu event.
1659 \inmodule QtGui
1660
1661 \ingroup events
1662
1663 Context menu events are sent to widgets when a user performs
1664 an action associated with opening a context menu.
1665 The actions required to open context menus vary between platforms;
1666 for example, on Windows, pressing the menu button or clicking the
1667 right mouse button will cause this event to be sent.
1668
1669 When this event occurs it is customary to show a QMenu with a
1670 context menu, if this is relevant to the context.
1671
1672 Context menu events contain a special accept flag that indicates
1673 whether the receiver accepted the event. If the event handler does
1674 not accept the event then, if possible, whatever triggered the event will be
1675 handled as a regular input event.
1676*/
1677
1678#ifndef QT_NO_CONTEXTMENU
1679/*!
1680 Constructs a context menu event object with the accept parameter
1681 flag set to false.
1682
1683 The \a reason parameter must be QContextMenuEvent::Mouse or
1684 QContextMenuEvent::Keyboard.
1685
1686 The \a pos parameter specifies the mouse position relative to the
1687 receiving widget. \a globalPos is the mouse position in absolute
1688 coordinates.
1689*/
1690QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
1691 : QContextMenuEvent(reason, pos, globalPos, Qt::NoModifier)
1692{}
1693
1694/*!
1695 Constructs a context menu event object with the accept parameter
1696 flag set to false.
1697
1698 The \a reason parameter must be QContextMenuEvent::Mouse or
1699 QContextMenuEvent::Keyboard.
1700
1701 The \a pos parameter specifies the mouse position relative to the
1702 receiving widget. \a globalPos is the mouse position in absolute
1703 coordinates. The \a modifiers holds the keyboard modifiers.
1704*/
1705QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1706 Qt::KeyboardModifiers modifiers)
1707 : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
1708{}
1709
1710
1711/*! \internal */
1712QContextMenuEvent::~QContextMenuEvent()
1713{
1714}
1715/*!
1716 Constructs a context menu event object with the accept parameter
1717 flag set to false.
1718
1719 The \a reason parameter must be QContextMenuEvent::Mouse or
1720 QContextMenuEvent::Keyboard.
1721
1722 The \a pos parameter specifies the mouse position relative to the
1723 receiving widget.
1724
1725 The globalPos() is initialized to QCursor::pos(), which may not be
1726 appropriate. Use the other constructor to specify the global
1727 position explicitly.
1728*/
1729QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
1730 : QInputEvent(ContextMenu), p(pos), reas(reason)
1731{
1732#ifndef QT_NO_CURSOR
1733 gp = QCursor::pos();
1734#endif
1735}
1736
1737/*!
1738 \fn const QPoint &QContextMenuEvent::pos() const
1739
1740 Returns the position of the mouse pointer relative to the widget
1741 that received the event.
1742
1743 \sa x(), y(), globalPos()
1744*/
1745
1746/*!
1747 \fn int QContextMenuEvent::x() const
1748
1749 Returns the x position of the mouse pointer, relative to the
1750 widget that received the event.
1751
1752 \sa y(), pos()
1753*/
1754
1755/*!
1756 \fn int QContextMenuEvent::y() const
1757
1758 Returns the y position of the mouse pointer, relative to the
1759 widget that received the event.
1760
1761 \sa x(), pos()
1762*/
1763
1764/*!
1765 \fn const QPoint &QContextMenuEvent::globalPos() const
1766
1767 Returns the global position of the mouse pointer at the time of
1768 the event.
1769
1770 \sa x(), y(), pos()
1771*/
1772
1773/*!
1774 \fn int QContextMenuEvent::globalX() const
1775
1776 Returns the global x position of the mouse pointer at the time of
1777 the event.
1778
1779 \sa globalY(), globalPos()
1780*/
1781
1782/*!
1783 \fn int QContextMenuEvent::globalY() const
1784
1785 Returns the global y position of the mouse pointer at the time of
1786 the event.
1787
1788 \sa globalX(), globalPos()
1789*/
1790#endif // QT_NO_CONTEXTMENU
1791
1792/*!
1793 \enum QContextMenuEvent::Reason
1794
1795 This enum describes the reason why the event was sent.
1796
1797 \value Mouse The mouse caused the event to be sent. Normally this
1798 means the right mouse button was clicked, but this is platform
1799 dependent.
1800
1801 \value Keyboard The keyboard caused this event to be sent. On
1802 Windows, this means the menu button was pressed.
1803
1804 \value Other The event was sent by some other means (i.e. not by
1805 the mouse or keyboard).
1806*/
1807
1808
1809/*!
1810 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
1811
1812 Returns the reason for this context event.
1813*/
1814
1815
1816/*!
1817 \class QInputMethodEvent
1818 \brief The QInputMethodEvent class provides parameters for input method events.
1819 \inmodule QtGui
1820
1821 \ingroup events
1822
1823 Input method events are sent to widgets when an input method is
1824 used to enter text into a widget. Input methods are widely used
1825 to enter text for languages with non-Latin alphabets.
1826
1827 Note that when creating custom text editing widgets, the
1828 Qt::WA_InputMethodEnabled window attribute must be set explicitly
1829 (using the QWidget::setAttribute() function) in order to receive
1830 input method events.
1831
1832 The events are of interest to authors of keyboard entry widgets
1833 who want to be able to correctly handle languages with complex
1834 character input. Text input in such languages is usually a three
1835 step process:
1836
1837 \list 1
1838 \li \b{Starting to Compose}
1839
1840 When the user presses the first key on a keyboard, an input
1841 context is created. This input context will contain a string
1842 of the typed characters.
1843
1844 \li \b{Composing}
1845
1846 With every new key pressed, the input method will try to create a
1847 matching string for the text typed so far called preedit
1848 string. While the input context is active, the user can only move
1849 the cursor inside the string belonging to this input context.
1850
1851 \li \b{Completing}
1852
1853 At some point, the user will activate a user interface component
1854 (perhaps using a particular key) where they can choose from a
1855 number of strings matching the text they have typed so far. The
1856 user can either confirm their choice cancel the input; in either
1857 case the input context will be closed.
1858 \endlist
1859
1860 QInputMethodEvent models these three stages, and transfers the
1861 information needed to correctly render the intermediate result. A
1862 QInputMethodEvent has two main parameters: preeditString() and
1863 commitString(). The preeditString() parameter gives the currently
1864 active preedit string. The commitString() parameter gives a text
1865 that should get added to (or replace parts of) the text of the
1866 editor widget. It usually is a result of the input operations and
1867 has to be inserted to the widgets text directly before the preedit
1868 string.
1869
1870 If the commitString() should replace parts of the of the text in
1871 the editor, replacementLength() will contain the number of
1872 characters to be replaced. replacementStart() contains the position
1873 at which characters are to be replaced relative from the start of
1874 the preedit string.
1875
1876 A number of attributes control the visual appearance of the
1877 preedit string (the visual appearance of text outside the preedit
1878 string is controlled by the widget only). The AttributeType enum
1879 describes the different attributes that can be set.
1880
1881 A class implementing QWidget::inputMethodEvent() or
1882 QGraphicsItem::inputMethodEvent() should at least understand and
1883 honor the \l TextFormat and \l Cursor attributes.
1884
1885 Since input methods need to be able to query certain properties
1886 from the widget or graphics item, subclasses must also implement
1887 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
1888 respectively.
1889
1890 When receiving an input method event, the text widget has to performs the
1891 following steps:
1892
1893 \list 1
1894 \li If the widget has selected text, the selected text should get
1895 removed.
1896
1897 \li Remove the text starting at replacementStart() with length
1898 replacementLength() and replace it by the commitString(). If
1899 replacementLength() is 0, replacementStart() gives the insertion
1900 position for the commitString().
1901
1902 When doing replacement the area of the preedit
1903 string is ignored, thus a replacement starting at -1 with a length
1904 of 2 will remove the last character before the preedit string and
1905 the first character afterwards, and insert the commit string
1906 directly before the preedit string.
1907
1908 If the widget implements undo/redo, this operation gets added to
1909 the undo stack.
1910
1911 \li If there is no current preedit string, insert the
1912 preeditString() at the current cursor position; otherwise replace
1913 the previous preeditString with the one received from this event.
1914
1915 If the widget implements undo/redo, the preeditString() should not
1916 influence the undo/redo stack in any way.
1917
1918 The widget should examine the list of attributes to apply to the
1919 preedit string. It has to understand at least the TextFormat and
1920 Cursor attributes and render them as specified.
1921 \endlist
1922
1923 \sa QInputMethod
1924*/
1925
1926/*!
1927 \enum QInputMethodEvent::AttributeType
1928
1929 \value TextFormat
1930 A QTextCharFormat for the part of the preedit string specified by
1931 start and length. value contains a QVariant of type QTextFormat
1932 specifying rendering of this part of the preedit string. There
1933 should be at most one format for every part of the preedit
1934 string. If several are specified for any character in the string the
1935 behaviour is undefined. A conforming implementation has to at least
1936 honor the backgroundColor, textColor and fontUnderline properties
1937 of the format.
1938
1939 \value Cursor If set, a cursor should be shown inside the preedit
1940 string at position start. The length variable determines whether
1941 the cursor is visible or not. If the length is 0 the cursor is
1942 invisible. If value is a QVariant of type QColor this color will
1943 be used for rendering the cursor, otherwise the color of the
1944 surrounding text will be used. There should be at most one Cursor
1945 attribute per event. If several are specified the behaviour is
1946 undefined.
1947
1948 \value Language
1949 The variant contains a QLocale object specifying the language of a
1950 certain part of the preedit string. There should be at most one
1951 language set for every part of the preedit string. If several are
1952 specified for any character in the string the behavior is undefined.
1953
1954 \value Ruby
1955 The ruby text for a part of the preedit string. There should be at
1956 most one ruby text set for every part of the preedit string. If
1957 several are specified for any character in the string the behaviour
1958 is undefined.
1959
1960 \value Selection
1961 If set, the edit cursor should be moved to the specified position
1962 in the editor text contents. In contrast with \c Cursor, this
1963 attribute does not work on the preedit text, but on the surrounding
1964 text. The cursor will be moved after the commit string has been
1965 committed, and the preedit string will be located at the new edit
1966 position.
1967 The start position specifies the new position and the length
1968 variable can be used to set a selection starting from that point.
1969 The value is unused.
1970
1971 \sa Attribute
1972*/
1973
1974/*!
1975 \class QInputMethodEvent::Attribute
1976 \inmodule QtGui
1977 \brief The QInputMethodEvent::Attribute class stores an input method attribute.
1978*/
1979
1980/*!
1981 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
1982
1983 Constructs an input method attribute. \a type specifies the type
1984 of attribute, \a start and \a length the position of the
1985 attribute, and \a value the value of the attribute.
1986*/
1987
1988/*!
1989 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length)
1990 \overload
1991 \since 5.7
1992
1993 Constructs an input method attribute with no value. \a type
1994 specifies the type of attribute, and \a start and \a length
1995 the position of the attribute.
1996*/
1997
1998/*!
1999 Constructs an event of type QEvent::InputMethod. The
2000 attributes(), preeditString(), commitString(), replacementStart(),
2001 and replacementLength() are initialized to default values.
2002
2003 \sa setCommitString()
2004*/
2005QInputMethodEvent::QInputMethodEvent()
2006 : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
2007{
2008}
2009
2010/*!
2011 Constructs an event of type QEvent::InputMethod. The
2012 preedit text is set to \a preeditText, the attributes to
2013 \a attributes.
2014
2015 The commitString(), replacementStart(), and replacementLength()
2016 values can be set using setCommitString().
2017
2018 \sa preeditString(), attributes()
2019*/
2020QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
2021 : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
2022 replace_from(0), replace_length(0)
2023{
2024}
2025
2026/*!
2027 Constructs a copy of \a other.
2028*/
2029QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
2030 : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
2031 commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
2032{
2033}
2034
2035QInputMethodEvent::~QInputMethodEvent()
2036{
2037 // must be empty until ### Qt 6
2038}
2039
2040/*!
2041 Sets the commit string to \a commitString.
2042
2043 The commit string is the text that should get added to (or
2044 replace parts of) the text of the editor widget. It usually is a
2045 result of the input operations and has to be inserted to the
2046 widgets text directly before the preedit string.
2047
2048 If the commit string should replace parts of the of the text in
2049 the editor, \a replaceLength specifies the number of
2050 characters to be replaced. \a replaceFrom specifies the position
2051 at which characters are to be replaced relative from the start of
2052 the preedit string.
2053
2054 \sa commitString(), replacementStart(), replacementLength()
2055*/
2056void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
2057{
2058 commit = commitString;
2059 replace_from = replaceFrom;
2060 replace_length = replaceLength;
2061}
2062
2063/*!
2064 \fn const QList<Attribute> &QInputMethodEvent::attributes() const
2065
2066 Returns the list of attributes passed to the QInputMethodEvent
2067 constructor. The attributes control the visual appearance of the
2068 preedit string (the visual appearance of text outside the preedit
2069 string is controlled by the widget only).
2070
2071 \sa preeditString(), Attribute
2072*/
2073
2074/*!
2075 \fn const QString &QInputMethodEvent::preeditString() const
2076
2077 Returns the preedit text, i.e. the text before the user started
2078 editing it.
2079
2080 \sa commitString(), attributes()
2081*/
2082
2083/*!
2084 \fn const QString &QInputMethodEvent::commitString() const
2085
2086 Returns the text that should get added to (or replace parts of)
2087 the text of the editor widget. It usually is a result of the
2088 input operations and has to be inserted to the widgets text
2089 directly before the preedit string.
2090
2091 \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
2092*/
2093
2094/*!
2095 \fn int QInputMethodEvent::replacementStart() const
2096
2097 Returns the position at which characters are to be replaced relative
2098 from the start of the preedit string.
2099
2100 \sa replacementLength(), setCommitString()
2101*/
2102
2103/*!
2104 \fn int QInputMethodEvent::replacementLength() const
2105
2106 Returns the number of characters to be replaced in the preedit
2107 string.
2108
2109 \sa replacementStart(), setCommitString()
2110*/
2111
2112/*!
2113 \class QInputMethodQueryEvent
2114 \since 5.0
2115 \inmodule QtGui
2116
2117 \brief The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
2118
2119 It is used by the
2120 input method to query a set of properties of the object to be
2121 able to support complex input method operations as support for
2122 surrounding text and reconversions.
2123
2124 queries() specifies which properties are queried.
2125
2126 The object should call setValue() on the event to fill in the requested
2127 data before calling accept().
2128*/
2129
2130/*!
2131 \fn Qt::InputMethodQueries QInputMethodQueryEvent::queries() const
2132
2133 Returns the properties queried by the event.
2134 */
2135
2136/*!
2137 Constructs a query event for properties given by \a queries.
2138 */
2139QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
2140 : QEvent(InputMethodQuery),
2141 m_queries(queries)
2142{
2143}
2144
2145/*!
2146 \internal
2147 */
2148QInputMethodQueryEvent::~QInputMethodQueryEvent()
2149{
2150}
2151
2152/*!
2153 Sets property \a query to \a value.
2154 */
2155void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery query, const QVariant &value)
2156{
2157 for (int i = 0; i < m_values.size(); ++i) {
2158 if (m_values.at(i).query == query) {
2159 m_values[i].value = value;
2160 return;
2161 }
2162 }
2163 QueryPair pair = { query, value };
2164 m_values.append(pair);
2165}
2166
2167/*!
2168 Returns value of the property \a query.
2169 */
2170QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
2171{
2172 for (int i = 0; i < m_values.size(); ++i)
2173 if (m_values.at(i).query == query)
2174 return m_values.at(i).value;
2175 return QVariant();
2176}
2177
2178#if QT_CONFIG(tabletevent)
2179
2180/*!
2181 \class QTabletEvent
2182 \brief The QTabletEvent class contains parameters that describe a Tablet event.
2183 \inmodule QtGui
2184
2185 \ingroup events
2186
2187 \e{Tablet events} are generated from tablet peripherals such as Wacom
2188 tablets and various other brands, and electromagnetic stylus devices
2189 included with some types of tablet computers. (It is not the same as
2190 \l QTouchEvent which a touchscreen generates, even when a passive stylus is
2191 used on a touchscreen.)
2192
2193 Tablet events are similar to mouse events; for example, the \l x(), \l y(),
2194 \l pos(), \l globalX(), \l globalY(), and \l globalPos() accessors provide
2195 the cursor position, and you can see which \l buttons() are pressed
2196 (pressing the stylus tip against the tablet surface is equivalent to a left
2197 mouse button). But tablet events also pass through some extra information
2198 that the tablet device driver provides; for example, you might want to do
2199 subpixel rendering with higher resolution coordinates (\l hiResGlobalX()
2200 and \l hiResGlobalY()), adjust color brightness based on the \l pressure()
2201 of the tool against the tablet surface, use different brushes depending on
2202 the type of tool in use (\l device()), modulate the brush shape in some way
2203 according to the X-axis and Y-axis tilt of the tool with respect to the
2204 tablet surface (\l xTilt() and \l yTilt()), and use a virtual eraser
2205 instead of a brush if the user switches to the other end of a double-ended
2206 stylus (\l pointerType()).
2207
2208 Every event contains an accept flag that indicates whether the receiver
2209 wants the event. You should call QTabletEvent::accept() if you handle the
2210 tablet event; otherwise it will be sent to the parent widget. The exception
2211 are TabletEnterProximity and TabletLeaveProximity events: these are only
2212 sent to QApplication and do not check whether or not they are accepted.
2213
2214 The QWidget::setEnabled() function can be used to enable or disable
2215 mouse, tablet and keyboard events for a widget.
2216
2217 The event handler QWidget::tabletEvent() receives TabletPress,
2218 TabletRelease and TabletMove events. Qt will first send a
2219 tablet event, then if it is not accepted by any widget, it will send a
2220 mouse event. This allows users of applications that are not designed for
2221 tablets to use a tablet like a mouse. However high-resolution drawing
2222 applications should handle the tablet events, because they can occur at a
2223 higher frequency, which is a benefit for smooth and accurate drawing.
2224 If the tablet events are rejected, the synthetic mouse events may be
2225 compressed for efficiency.
2226
2227 New in Qt 5.4: QTabletEvent includes all information available from the
2228 device, including \l QTabletEvent::buttons(). Previously it was not
2229 possible to accept all tablet events and also know which stylus buttons
2230 were pressed.
2231
2232 Note that pressing the stylus button while the stylus hovers over the
2233 tablet will generate a button press on some types of tablets, while on
2234 other types it will be necessary to press the stylus against the tablet
2235 surface in order to register the simultaneous stylus button press.
2236
2237 \section1 Notes for X11 Users
2238
2239 If the tablet is configured in xorg.conf to use the Wacom driver, there
2240 will be separate XInput "devices" for the stylus, eraser, and (optionally)
2241 cursor and touchpad. Qt recognizes these by their names. Otherwise, if the
2242 tablet is configured to use the evdev driver, there will be only one device
2243 and applications may not be able to distinguish the stylus from the eraser.
2244
2245 \section1 Notes for Windows Users
2246
2247 Tablet support currently requires the WACOM windows driver providing the DLL
2248 \c{wintab32.dll} to be installed. It is contained in older packages,
2249 for example \c{pentablet_5.3.5-3.exe}.
2250
2251*/
2252
2253/*!
2254 \enum QTabletEvent::TabletDevice
2255
2256 This enum defines what type of device is generating the event.
2257
2258 \value NoDevice No device, or an unknown device.
2259 \value Puck A Puck (a device that is similar to a flat mouse with
2260 a transparent circle with cross-hairs).
2261 \value Stylus A Stylus.
2262 \value Airbrush An airbrush
2263 \value FourDMouse A 4D Mouse.
2264 \value RotationStylus A special stylus that also knows about rotation
2265 (a 6D stylus). \since 4.1
2266 \omitvalue XFreeEraser
2267*/
2268
2269/*!
2270 \enum QTabletEvent::PointerType
2271
2272 This enum defines what type of point is generating the event.
2273
2274 \value UnknownPointer An unknown device.
2275 \value Pen Tip end of a stylus-like device (the narrow end of the pen).
2276 \value Cursor Any puck-like device.
2277 \value Eraser Eraser end of a stylus-like device (the broad end of the pen).
2278
2279 \sa pointerType()
2280*/
2281
2282/*!
2283 Construct a tablet event of the given \a type.
2284
2285 The \a pos parameter indicates where the event occurred in the
2286 widget; \a globalPos is the corresponding position in absolute
2287 coordinates.
2288
2289 \a pressure contains the pressure exerted on the \a device.
2290
2291 \a pointerType describes the type of pen that is being used.
2292
2293 \a xTilt and \a yTilt contain the device's degree of tilt from the
2294 x and y axes respectively.
2295
2296 \a keyState specifies which keyboard modifiers are pressed (e.g.,
2297 \uicontrol{Ctrl}).
2298
2299 The \a uniqueID parameter contains the unique ID for the current device.
2300
2301 The \a z parameter contains the coordinate of the device on the tablet, this
2302 is usually given by a wheel on 4D mouse. If the device does not support a
2303 Z-axis, pass zero here.
2304
2305 The \a tangentialPressure parameter contins the tangential pressure of an air
2306 brush. If the device does not support tangential pressure, pass 0 here.
2307
2308 \a rotation contains the device's rotation in degrees.
2309 4D mice, the Wacom Art Pen, and the Apple Pencil support rotation.
2310 If the device does not support rotation, pass 0 here.
2311
2312 The \a button that caused the event is given as a value from the
2313 \l Qt::MouseButton enum. If the event \a type is not \l TabletPress or
2314 \l TabletRelease, the appropriate button for this event is \l Qt::NoButton.
2315
2316 \a buttons is the state of all buttons at the time of the event.
2317
2318 \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
2319 tangentialPressure(), z()
2320*/
2321
2322QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
2323 int device, int pointerType,
2324 qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
2325 qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID,
2326 Qt::MouseButton button, Qt::MouseButtons buttons)
2327 : QInputEvent(type, keyState),
2328 mPos(pos),
2329 mGPos(globalPos),
2330 mDev(device),
2331 mPointerType(pointerType),
2332 mXT(xTilt),
2333 mYT(yTilt),
2334 mZ(z),
2335 mPress(pressure),
2336 mTangential(tangentialPressure),
2337 mRot(rotation),
2338 mUnique(uniqueID),
2339 mExtra(new QTabletEventPrivate(button, buttons))
2340{
2341}
2342
2343/*!
2344 Construct a tablet event of the given \a type.
2345
2346 The \a pos parameter indicates where the event occurred in the
2347 widget; \a globalPos is the corresponding position in absolute
2348 coordinates.
2349
2350 \a pressure contains the pressure exerted on the \a device.
2351
2352 \a pointerType describes the type of pen that is being used.
2353
2354 \a xTilt and \a yTilt contain the device's degree of tilt from the
2355 x and y axes respectively.
2356
2357 \a keyState specifies which keyboard modifiers are pressed (e.g.,
2358 \uicontrol{Ctrl}).
2359
2360 The \a uniqueID parameter contains the unique ID for the current device.
2361
2362 The \a z parameter contains the coordinate of the device on the tablet, this
2363 is usually given by a wheel on 4D mouse. If the device does not support a
2364 Z-axis, pass zero here.
2365
2366 The \a tangentialPressure parameter contins the tangential pressure of an air
2367 brush. If the device does not support tangential pressure, pass 0 here.
2368
2369 \a rotation contains the device's rotation in degrees. 4D mice support
2370 rotation. If the device does not support rotation, pass 0 here.
2371
2372 \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
2373 tangentialPressure(), z()
2374
2375 \deprecated in 5.4: use the constructor with MouseButton status
2376*/
2377
2378QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
2379 int device, int pointerType,
2380 qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
2381 qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
2382 : QTabletEvent(type, pos, globalPos, device, pointerType, pressure, xTilt, yTilt,
2383 tangentialPressure, rotation, z, keyState, uniqueID, Qt::NoButton, Qt::NoButton)
2384{
2385}
2386
2387/*!
2388 \internal
2389*/
2390QTabletEvent::~QTabletEvent()
2391{
2392 delete static_cast<QTabletEventPrivate *>(mExtra);
2393}
2394
2395/*!
2396 Returns the button that caused the event.
2397
2398 Note that the returned value is always Qt::NoButton for \l TabletMove,
2399 \l TabletEnterProximity and \l TabletLeaveProximity events.
2400
2401 \sa buttons(), Qt::MouseButton
2402*/
2403Qt::MouseButton QTabletEvent::button() const
2404{
2405 return static_cast<QTabletEventPrivate *>(mExtra)->b;
2406}
2407
2408/*!
2409 Returns the button state when the event was generated. The button state is
2410 a combination of buttons from the \l Qt::MouseButton enum using the OR
2411 operator. For \l TabletMove events, this is all buttons that are pressed
2412 down. For \l TabletPress events this includes the button that caused the
2413 event. For \l TabletRelease events this excludes the button that caused the
2414 event.
2415
2416 \sa button(), Qt::MouseButton
2417*/
2418Qt::MouseButtons QTabletEvent::buttons() const
2419{
2420 return static_cast<QTabletEventPrivate *>(mExtra)->buttonState;
2421}
2422
2423/*!
2424 \fn TabletDevices QTabletEvent::device() const
2425
2426 Returns the type of device that generated the event.
2427
2428 \sa TabletDevice
2429*/
2430
2431/*!
2432 \fn PointerType QTabletEvent::pointerType() const
2433
2434 Returns the type of point that generated the event.
2435*/
2436
2437/*!
2438 \fn qreal QTabletEvent::tangentialPressure() const
2439
2440 Returns the tangential pressure for the device. This is typically given by a finger
2441 wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
2442 neutral position. Current airbrushes can only move in the positive
2443 direction from the neutrual position. If the device does not support
2444 tangential pressure, this value is always 0.0.
2445
2446 \sa pressure()
2447*/
2448
2449/*!
2450 \fn qreal QTabletEvent::rotation() const
2451
2452 Returns the rotation of the current tool in degrees, where zero means the
2453 tip of the stylus is pointing towards the top of the tablet, a positive
2454 value means it's turned to the right, and a negative value means it's
2455 turned to the left. This can be given by a 4D Mouse or a rotation-capable
2456 stylus (such as the Wacom Art Pen or the Apple Pencil). If the device does
2457 not support rotation, this value is always 0.0.
2458*/
2459
2460/*!
2461 \fn qreal QTabletEvent::pressure() const
2462
2463 Returns the pressure for the device. 0.0 indicates that the stylus is not
2464 on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
2465
2466 \sa tangentialPressure()
2467*/
2468
2469/*!
2470 \fn int QTabletEvent::xTilt() const
2471
2472 Returns the angle between the device (a pen, for example) and the
2473 perpendicular in the direction of the x axis.
2474 Positive values are towards the tablet's physical right. The angle
2475 is in the range -60 to +60 degrees.
2476
2477 \image qtabletevent-tilt.png
2478
2479 \sa yTilt()
2480*/
2481
2482/*!
2483 \fn int QTabletEvent::yTilt() const
2484
2485 Returns the angle between the device (a pen, for example) and the
2486 perpendicular in the direction of the y axis.
2487 Positive values are towards the bottom of the tablet. The angle is
2488 within the range -60 to +60 degrees.
2489
2490 \sa xTilt()
2491*/
2492
2493/*!
2494 \fn QPoint QTabletEvent::pos() const
2495
2496 Returns the position of the device, relative to the widget that
2497 received the event.
2498
2499 If you move widgets around in response to mouse events, use
2500 globalPos() instead of this function.
2501
2502 \sa x(), y(), globalPos()
2503*/
2504
2505/*!
2506 \fn int QTabletEvent::x() const
2507
2508 Returns the x position of the device, relative to the widget that
2509 received the event.
2510
2511 \sa y(), pos()
2512*/
2513
2514/*!
2515 \fn int QTabletEvent::y() const
2516
2517 Returns the y position of the device, relative to the widget that
2518 received the event.
2519
2520 \sa x(), pos()
2521*/
2522
2523/*!
2524 \fn int QTabletEvent::z() const
2525
2526 Returns the z position of the device. Typically this is represented by a
2527 wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
2528 always zero. This is \b not the same as pressure.
2529
2530 \sa pressure()
2531*/
2532
2533/*!
2534 \fn QPoint QTabletEvent::globalPos() const
2535
2536 Returns the global position of the device \e{at the time of the
2537 event}. This is important on asynchronous windows systems like X11;
2538 whenever you move your widgets around in response to mouse events,
2539 globalPos() can differ significantly from the current position
2540 QCursor::pos().
2541
2542 \sa globalX(), globalY(), hiResGlobalPos()
2543*/
2544
2545/*!
2546 \fn int QTabletEvent::globalX() const
2547
2548 Returns the global x position of the mouse pointer at the time of
2549 the event.
2550
2551 \sa globalY(), globalPos(), hiResGlobalX()
2552*/
2553
2554/*!
2555 \fn int QTabletEvent::globalY() const
2556
2557 Returns the global y position of the tablet device at the time of
2558 the event.
2559
2560 \sa globalX(), globalPos(), hiResGlobalY()
2561*/
2562
2563/*!
2564 \fn qint64 QTabletEvent::uniqueId() const
2565
2566 Returns a unique ID for the current device, making it possible
2567 to differentiate between multiple devices being used at the same
2568 time on the tablet.
2569
2570 Support of this feature is dependent on the tablet.
2571
2572 Values for the same device may vary from OS to OS.
2573
2574 Later versions of the Wacom driver for Linux will now report
2575 the ID information. If you have a tablet that supports unique ID
2576 and are not getting the information on Linux, consider upgrading
2577 your driver.
2578
2579 As of Qt 4.2, the unique ID is the same regardless of the orientation
2580 of the pen. Earlier versions would report a different value when using
2581 the eraser-end versus the pen-end of the stylus on some OS's.
2582
2583 \sa pointerType()
2584*/
2585
2586/*!
2587 \fn const QPointF &QTabletEvent::hiResGlobalPos() const
2588
2589 The high precision coordinates delivered from the tablet expressed.
2590 Sub pixeling information is in the fractional part of the QPointF.
2591
2592 \sa globalPos(), hiResGlobalX(), hiResGlobalY()
2593*/
2594
2595/*!
2596 \fn qreal &QTabletEvent::hiResGlobalX() const
2597
2598 The high precision x position of the tablet device.
2599*/
2600
2601/*!
2602 \fn qreal &QTabletEvent::hiResGlobalY() const
2603
2604 The high precision y position of the tablet device.
2605*/
2606
2607/*!
2608 \fn const QPointF &QTabletEvent::posF() const
2609
2610 Returns the position of the device, relative to the widget that
2611 received the event.
2612
2613 If you move widgets around in response to mouse events, use
2614 globalPosF() instead of this function.
2615
2616 \sa globalPosF()
2617*/
2618
2619/*!
2620 \fn const QPointF &QTabletEvent::globalPosF() const
2621
2622 Returns the global position of the device \e{at the time of the
2623 event}. This is important on asynchronous windows systems like X11;
2624 whenever you move your widgets around in response to mouse events,
2625 globalPosF() can differ significantly from the current position
2626 QCursor::pos().
2627
2628 \sa posF()
2629*/
2630
2631#endif // QT_CONFIG(tabletevent)
2632
2633#ifndef QT_NO_GESTURES
2634/*!
2635 \class QNativeGestureEvent
2636 \since 5.2
2637 \brief The QNativeGestureEvent class contains parameters that describe a gesture event.
2638 \inmodule QtGui
2639 \ingroup events
2640
2641 Native gesture events are generated by the operating system, typically by
2642 interpreting touch events. Gesture events are high-level events such
2643 as zoom or rotate.
2644
2645 \table
2646 \header
2647 \li Event Type
2648 \li Description
2649 \li Touch sequence
2650 \row
2651 \li Qt::ZoomNativeGesture
2652 \li Magnification delta in percent.
2653 \li \macos: Two-finger pinch.
2654 \row
2655 \li Qt::SmartZoomNativeGesture
2656 \li Boolean magnification state.
2657 \li \macos: Two-finger douple tap (trackpad) / One-finger douple tap (magic mouse).
2658 \row
2659 \li Qt::RotateNativeGesture
2660 \li Rotation delta in degrees.
2661 \li \macos: Two-finger rotate.
2662 \endtable
2663
2664
2665 In addition, BeginNativeGesture and EndNativeGesture are sent before and after
2666 gesture event streams:
2667
2668 BeginNativeGesture
2669 ZoomNativeGesture
2670 ZoomNativeGesture
2671 ZoomNativeGesture
2672 EndNativeGesture
2673
2674 \sa Qt::NativeGestureType, QGestureEvent
2675*/
2676
2677/*!
2678 \deprecated The QTouchDevice parameter is now required
2679*/
2680#if QT_DEPRECATED_SINCE(5, 10)
2681QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointF &localPos, const QPointF &windowPos,
2682 const QPointF &screenPos, qreal realValue, ulong sequenceId, quint64 intValue)
2683 : QInputEvent(QEvent::NativeGesture), mGestureType(type),
2684 mLocalPos(localPos), mWindowPos(windowPos), mScreenPos(screenPos), mRealValue(realValue),
2685 mSequenceId(sequenceId), mIntValue(intValue)
2686{ }
2687#endif
2688
2689typedef QHash<const QNativeGestureEvent*, const QTouchDevice*> NativeGestureEventDataHash;
2690// ### Qt6: move this to a member in QNativeGestureEvent
2691Q_GLOBAL_STATIC(NativeGestureEventDataHash, g_nativeGestureEventDataHash)
2692
2693/*!
2694 Constructs a native gesture event of type \a type originating from \a device.
2695
2696 The points \a localPos, \a windowPos and \a screenPos specify the
2697 gesture position relative to the receiving widget or item,
2698 window, and screen, respectively.
2699
2700 \a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters.
2701 \since 5.10
2702*/
2703QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QTouchDevice *device, const QPointF &localPos, const QPointF &windowPos,
2704 const QPointF &screenPos, qreal realValue, ulong sequenceId, quint64 intValue)
2705 : QInputEvent(QEvent::NativeGesture), mGestureType(type),
2706 mLocalPos(localPos), mWindowPos(windowPos), mScreenPos(screenPos), mRealValue(realValue),
2707 mSequenceId(sequenceId), mIntValue(intValue)
2708{
2709 g_nativeGestureEventDataHash->insert(this, device);
2710}
2711
2712QNativeGestureEvent::~QNativeGestureEvent()
2713{
2714 g_nativeGestureEventDataHash->remove(this);
2715}
2716
2717/*!
2718 \since 5.10
2719
2720 Returns the device.
2721*/
2722
2723const QTouchDevice *QNativeGestureEvent::device() const
2724{
2725 return g_nativeGestureEventDataHash->value(this);
2726}
2727
2728/*!
2729 \fn QNativeGestureEvent::gestureType() const
2730 \since 5.2
2731
2732 Returns the gesture type.
2733*/
2734
2735/*!
2736 \fn QNativeGestureEvent::value() const
2737 \since 5.2
2738
2739 Returns the gesture value. The value should be interpreted based on the
2740 gesture type. For example, a Zoom gesture provides a scale factor while a Rotate
2741 gesture provides a rotation delta.
2742
2743 \sa QNativeGestureEvent, gestureType()
2744*/
2745
2746/*!
2747 \fn QPoint QNativeGestureEvent::globalPos() const
2748 \since 5.2
2749
2750 Returns the position of the gesture as a QPointF in screen coordinates
2751*/
2752
2753/*!
2754 \fn QPoint QNativeGestureEvent::pos() const
2755 \since 5.2
2756
2757 Returns the position of the mouse cursor, relative to the widget
2758 or item that received the event.
2759*/
2760
2761/*!
2762 \fn QPointF QNativeGestureEvent::localPos() const
2763 \since 5.2
2764
2765 Returns the position of the gesture as a QPointF, relative to the
2766 widget or item that received the event.
2767*/
2768
2769/*!
2770 \fn QPointF QNativeGestureEvent::screenPos() const
2771 \since 5.2
2772
2773 Returns the position of the gesture as a QPointF in screen coordinates.
2774*/
2775
2776/*!
2777 \fn QPointF QNativeGestureEvent::windowPos() const
2778 \since 5.2
2779
2780 Returns the position of the gesture as a QPointF, relative to the
2781 window that received the event.
2782*/
2783#endif // QT_NO_GESTURES
2784
2785#if QT_CONFIG(draganddrop)
2786/*!
2787 Creates a QDragMoveEvent of the required \a type indicating
2788 that the mouse is at position \a pos given within a widget.
2789
2790 The mouse and keyboard states are specified by \a buttons and
2791 \a modifiers, and the \a actions describe the types of drag
2792 and drop operation that are possible.
2793 The drag data is passed as MIME-encoded information in \a data.
2794
2795 \warning Do not attempt to create a QDragMoveEvent yourself.
2796 These objects rely on Qt's internal state.
2797*/
2798QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
2799 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2800 : QDropEvent(pos, actions, data, buttons, modifiers, type)
2801 , rect(pos, QSize(1, 1))
2802{}
2803
2804/*!
2805 Destroys the event.
2806*/
2807QDragMoveEvent::~QDragMoveEvent()
2808{
2809}
2810
2811/*!
2812 \fn void QDragMoveEvent::accept(const QRect &rectangle)
2813
2814 The same as accept(), but also notifies that future moves will
2815 also be acceptable if they remain within the \a rectangle
2816 given on the widget. This can improve performance, but may
2817 also be ignored by the underlying system.
2818
2819 If the rectangle is empty, drag move events will be sent
2820 continuously. This is useful if the source is scrolling in a
2821 timer event.
2822*/
2823
2824/*!
2825 \fn void QDragMoveEvent::accept()
2826
2827 \overload
2828
2829 Calls QDropEvent::accept().
2830*/
2831
2832/*!
2833 \fn void QDragMoveEvent::ignore()
2834
2835 \overload
2836
2837 Calls QDropEvent::ignore().
2838*/
2839
2840/*!
2841 \fn void QDragMoveEvent::ignore(const QRect &rectangle)
2842
2843 The opposite of the accept(const QRect&) function.
2844 Moves within the \a rectangle are not acceptable, and will be
2845 ignored.
2846*/
2847
2848/*!
2849 \fn QRect QDragMoveEvent::answerRect() const
2850
2851 Returns the rectangle in the widget where the drop will occur if accepted.
2852 You can use this information to restrict drops to certain places on the
2853 widget.
2854*/
2855
2856
2857/*!
2858 \class QDropEvent
2859 \ingroup events
2860 \ingroup draganddrop
2861 \inmodule QtGui
2862
2863 \brief The QDropEvent class provides an event which is sent when a
2864 drag and drop action is completed.
2865
2866 When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
2867 receive this event if it has accepted the most recent QDragEnterEvent or
2868 QDragMoveEvent sent to it.
2869
2870 The drop event contains a proposed action, available from proposedAction(), for
2871 the widget to either accept or ignore. If the action can be handled by the
2872 widget, you should call the acceptProposedAction() function. Since the
2873 proposed action can be a combination of \l Qt::DropAction values, it may be
2874 useful to either select one of these values as a default action or ask
2875 the user to select their preferred action.
2876
2877 If the proposed drop action is not suitable, perhaps because your custom
2878 widget does not support that action, you can replace it with any of the
2879 \l{possibleActions()}{possible drop actions} by calling setDropAction()
2880 with your preferred action. If you set a value that is not present in the
2881 bitwise OR combination of values returned by possibleActions(), the default
2882 copy action will be used. Once a replacement drop action has been set, call
2883 accept() instead of acceptProposedAction() to complete the drop operation.
2884
2885 The mimeData() function provides the data dropped on the widget in a QMimeData
2886 object. This contains information about the MIME type of the data in addition to
2887 the data itself.
2888
2889 \sa QMimeData, QDrag, {Drag and Drop}
2890*/
2891
2892/*!
2893 \fn const QMimeData *QDropEvent::mimeData() const
2894
2895 Returns the data that was dropped on the widget and its associated MIME
2896 type information.
2897*/
2898
2899// ### pos is in which coordinate system?
2900/*!
2901 Constructs a drop event of a certain \a type corresponding to a
2902 drop at the point specified by \a pos in the destination widget's
2903 coordinate system.
2904
2905 The \a actions indicate which types of drag and drop operation can
2906 be performed, and the drag data is stored as MIME-encoded data in \a data.
2907
2908 The states of the mouse buttons and keyboard modifiers at the time of
2909 the drop are specified by \a buttons and \a modifiers.
2910*/
2911QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
2912 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2913 : QEvent(type), p(pos), mouseState(buttons),
2914 modState(modifiers), act(actions),
2915 mdata(data)
2916{
2917 default_action = QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(act, modifiers);
2918 drop_action = default_action;
2919 ignore();
2920}
2921
2922/*! \internal */
2923QDropEvent::~QDropEvent()
2924{
2925}
2926
2927
2928/*!
2929 If the source of the drag operation is a widget in this
2930 application, this function returns that source; otherwise it
2931 returns \nullptr. The source of the operation is the first parameter to
2932 the QDrag object used instantiate the drag.
2933
2934 This is useful if your widget needs special behavior when dragging
2935 to itself.
2936
2937 \sa QDrag::QDrag()
2938*/
2939QObject* QDropEvent::source() const
2940{
2941 if (const QDragManager *manager = QDragManager::self())
2942 return manager->source();
2943 return 0;
2944}
2945
2946
2947void QDropEvent::setDropAction(Qt::DropAction action)
2948{
2949 if (!(action & act) && action != Qt::IgnoreAction)
2950 action = default_action;
2951 drop_action = action;
2952}
2953
2954/*!
2955 \fn QPoint QDropEvent::pos() const
2956
2957 Returns the position where the drop was made.
2958*/
2959
2960/*!
2961 \fn const QPointF& QDropEvent::posF() const
2962
2963 Returns the position where the drop was made.
2964*/
2965
2966/*!
2967 \fn Qt::MouseButtons QDropEvent::mouseButtons() const
2968
2969 Returns the mouse buttons that are pressed..
2970*/
2971
2972/*!
2973 \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
2974
2975 Returns the modifier keys that are pressed.
2976*/
2977
2978/*!
2979 \fn void QDropEvent::setDropAction(Qt::DropAction action)
2980
2981 Sets the \a action to be performed on the data by the target.
2982 Use this to override the \l{proposedAction()}{proposed action}
2983 with one of the \l{possibleActions()}{possible actions}.
2984
2985 If you set a drop action that is not one of the possible actions, the
2986 drag and drop operation will default to a copy operation.
2987
2988 Once you have supplied a replacement drop action, call accept()
2989 instead of acceptProposedAction().
2990
2991 \sa dropAction()
2992*/
2993
2994/*!
2995 \fn Qt::DropAction QDropEvent::dropAction() const
2996
2997 Returns the action to be performed on the data by the target. This may be
2998 different from the action supplied in proposedAction() if you have called
2999 setDropAction() to explicitly choose a drop action.
3000
3001 \sa setDropAction()
3002*/
3003
3004/*!
3005 \fn Qt::DropActions QDropEvent::possibleActions() const
3006
3007 Returns an OR-combination of possible drop actions.
3008
3009 \sa dropAction()
3010*/
3011
3012/*!
3013 \fn Qt::DropAction QDropEvent::proposedAction() const
3014
3015 Returns the proposed drop action.
3016
3017 \sa dropAction()
3018*/
3019
3020/*!
3021 \fn void QDropEvent::acceptProposedAction()
3022
3023 Sets the drop action to be the proposed action.
3024
3025 \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
3026*/
3027
3028/*!
3029 \class QDragEnterEvent
3030 \brief The QDragEnterEvent class provides an event which is sent
3031 to a widget when a drag and drop action enters it.
3032
3033 \ingroup events
3034 \ingroup draganddrop
3035 \inmodule QtGui
3036
3037 A widget must accept this event in order to receive the \l
3038 {QDragMoveEvent}{drag move events} that are sent while the drag
3039 and drop action is in progress. The drag enter event is always
3040 immediately followed by a drag move event.
3041
3042 QDragEnterEvent inherits most of its functionality from
3043 QDragMoveEvent, which in turn inherits most of its functionality
3044 from QDropEvent.
3045
3046 \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
3047*/
3048
3049/*!
3050 Constructs a QDragEnterEvent that represents a drag entering a
3051 widget at the given \a point with mouse and keyboard states specified by
3052 \a buttons and \a modifiers.
3053
3054 The drag data is passed as MIME-encoded information in \a data, and the
3055 specified \a actions describe the possible types of drag and drop
3056 operation that can be performed.
3057
3058 \warning Do not create a QDragEnterEvent yourself since these
3059 objects rely on Qt's internal state.
3060*/
3061QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
3062 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3063 : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
3064{}
3065
3066/*! \internal
3067*/
3068QDragEnterEvent::~QDragEnterEvent()
3069{
3070}
3071
3072/*!
3073 \class QDragMoveEvent
3074 \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
3075
3076 \ingroup events
3077 \ingroup draganddrop
3078 \inmodule QtGui
3079
3080 A widget will receive drag move events repeatedly while the drag
3081 is within its boundaries, if it accepts
3082 \l{QWidget::setAcceptDrops()}{drop events} and \l
3083 {QWidget::dragEnterEvent()}{enter events}. The widget should
3084 examine the event to see what kind of \l{mimeData()}{data} it
3085 provides, and call the accept() function to accept the drop if appropriate.
3086
3087 The rectangle supplied by the answerRect() function can be used to restrict
3088 drops to certain parts of the widget. For example, we can check whether the
3089 rectangle intersects with the geometry of a certain child widget and only
3090 call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
3091 is the case.
3092
3093 Note that this class inherits most of its functionality from
3094 QDropEvent.
3095
3096 \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
3097*/
3098
3099/*!
3100 \class QDragLeaveEvent
3101 \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
3102
3103 \ingroup events
3104 \ingroup draganddrop
3105 \inmodule QtGui
3106
3107 This event is always preceded by a QDragEnterEvent and a series
3108 of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
3109 instead.
3110
3111 \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
3112*/
3113
3114/*!
3115 Constructs a QDragLeaveEvent.
3116
3117 \warning Do not create a QDragLeaveEvent yourself since these
3118 objects rely on Qt's internal state.
3119*/
3120QDragLeaveEvent::QDragLeaveEvent()
3121 : QEvent(DragLeave)
3122{}
3123
3124/*! \internal
3125*/
3126QDragLeaveEvent::~QDragLeaveEvent()
3127{
3128}
3129#endif // QT_CONFIG(draganddrop)
3130
3131/*!
3132 \class QHelpEvent
3133 \brief The QHelpEvent class provides an event that is used to request helpful information
3134 about a particular point in a widget.
3135
3136 \ingroup events
3137 \ingroup helpsystem
3138 \inmodule QtGui
3139
3140 This event can be intercepted in applications to provide tooltips
3141 or "What's This?" help for custom widgets. The type() can be
3142 either QEvent::ToolTip or QEvent::WhatsThis.
3143
3144 \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
3145*/
3146
3147/*!
3148 Constructs a help event with the given \a type corresponding to the
3149 widget-relative position specified by \a pos and the global position
3150 specified by \a globalPos.
3151
3152 \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
3153
3154 \sa pos(), globalPos()
3155*/
3156QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
3157 : QEvent(type), p(pos), gp(globalPos)
3158{}
3159
3160/*!
3161 \fn int QHelpEvent::x() const
3162
3163 Same as pos().x().
3164
3165 \sa y(), pos(), globalPos()
3166*/
3167
3168/*!
3169 \fn int QHelpEvent::y() const
3170
3171 Same as pos().y().
3172
3173 \sa x(), pos(), globalPos()
3174*/
3175
3176/*!
3177 \fn int QHelpEvent::globalX() const
3178
3179 Same as globalPos().x().
3180
3181 \sa x(), globalY(), globalPos()
3182*/
3183
3184/*!
3185 \fn int QHelpEvent::globalY() const
3186
3187 Same as globalPos().y().
3188
3189 \sa y(), globalX(), globalPos()
3190*/
3191
3192/*!
3193 \fn const QPoint &QHelpEvent::pos() const
3194
3195 Returns the mouse cursor position when the event was generated,
3196 relative to the widget to which the event is dispatched.
3197
3198 \sa globalPos(), x(), y()
3199*/
3200
3201/*!
3202 \fn const QPoint &QHelpEvent::globalPos() const
3203
3204 Returns the mouse cursor position when the event was generated
3205 in global coordinates.
3206
3207 \sa pos(), globalX(), globalY()
3208*/
3209
3210/*! \internal
3211*/
3212QHelpEvent::~QHelpEvent()
3213{
3214}
3215
3216#ifndef QT_NO_STATUSTIP
3217
3218/*!
3219 \class QStatusTipEvent
3220 \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
3221
3222 \ingroup events
3223 \ingroup helpsystem
3224 \inmodule QtGui
3225
3226 Status tips can be set on a widget using the
3227 QWidget::setStatusTip() function. They are shown in the status
3228 bar when the mouse cursor enters the widget. For example:
3229
3230 \table 100%
3231 \row
3232 \li
3233 \snippet qstatustipevent/main.cpp 1
3234 \dots
3235 \snippet qstatustipevent/main.cpp 3
3236 \li
3237 \image qstatustipevent-widget.png Widget with status tip.
3238 \endtable
3239
3240 Status tips can also be set on actions using the
3241 QAction::setStatusTip() function:
3242
3243 \table 100%
3244 \row
3245 \li
3246 \snippet qstatustipevent/main.cpp 0
3247 \snippet qstatustipevent/main.cpp 2
3248 \dots
3249 \snippet qstatustipevent/main.cpp 3
3250 \li
3251 \image qstatustipevent-action.png Action with status tip.
3252 \endtable
3253
3254 Finally, status tips are supported for the item view classes
3255 through the Qt::StatusTipRole enum value.
3256
3257 \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
3258*/
3259
3260/*!
3261 Constructs a status tip event with the text specified by \a tip.
3262
3263 \sa tip()
3264*/
3265QStatusTipEvent::QStatusTipEvent(const QString &tip)
3266 : QEvent(StatusTip), s(tip)
3267{}
3268
3269/*! \internal
3270*/
3271QStatusTipEvent::~QStatusTipEvent()
3272{
3273}
3274
3275/*!
3276 \fn QString QStatusTipEvent::tip() const
3277
3278 Returns the message to show in the status bar.
3279
3280 \sa QStatusBar::showMessage()
3281*/
3282
3283#endif // QT_NO_STATUSTIP
3284
3285#if QT_CONFIG(whatsthis)
3286
3287/*!
3288 \class QWhatsThisClickedEvent
3289 \brief The QWhatsThisClickedEvent class provides an event that
3290 can be used to handle hyperlinks in a "What's This?" text.
3291
3292 \ingroup events
3293 \ingroup helpsystem
3294 \inmodule QtGui
3295
3296 \sa QWhatsThis, QHelpEvent, QStatusTipEvent
3297*/
3298
3299/*!
3300 Constructs an event containing a URL specified by \a href when a link
3301 is clicked in a "What's This?" message.
3302
3303 \sa href()
3304*/
3305QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
3306 : QEvent(WhatsThisClicked), s(href)
3307{}
3308
3309/*! \internal
3310*/
3311QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
3312{
3313}
3314
3315/*!
3316 \fn QString QWhatsThisClickedEvent::href() const
3317
3318 Returns the URL that was clicked by the user in the "What's
3319 This?" text.
3320*/
3321
3322#endif // QT_CONFIG(whatsthis)
3323
3324#ifndef QT_NO_ACTION
3325
3326/*!
3327 \class QActionEvent
3328 \brief The QActionEvent class provides an event that is generated
3329 when a QAction is added, removed, or changed.
3330
3331 \ingroup events
3332 \inmodule QtGui
3333
3334 Actions can be added to widgets using QWidget::addAction(). This
3335 generates an \l ActionAdded event, which you can handle to provide
3336 custom behavior. For example, QToolBar reimplements
3337 QWidget::actionEvent() to create \l{QToolButton}s for the
3338 actions.
3339
3340 \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
3341*/
3342
3343/*!
3344 Constructs an action event. The \a type can be \l ActionChanged,
3345 \l ActionAdded, or \l ActionRemoved.
3346
3347 \a action is the action that is changed, added, or removed. If \a
3348 type is ActionAdded, the action is to be inserted before the
3349 action \a before. If \a before is 0, the action is appended.
3350*/
3351QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
3352 : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
3353{}
3354
3355/*! \internal
3356*/
3357QActionEvent::~QActionEvent()
3358{
3359}
3360
3361/*!
3362 \fn QAction *QActionEvent::action() const
3363
3364 Returns the action that is changed, added, or removed.
3365
3366 \sa before()
3367*/
3368
3369/*!
3370 \fn QAction *QActionEvent::before() const
3371
3372 If type() is \l ActionAdded, returns the action that should
3373 appear before action(). If this function returns \nullptr, the action
3374 should be appended to already existing actions on the same
3375 widget.
3376
3377 \sa action(), QWidget::actions()
3378*/
3379
3380#endif // QT_NO_ACTION
3381
3382/*!
3383 \class QHideEvent
3384 \brief The QHideEvent class provides an event which is sent after a widget is hidden.
3385
3386 \ingroup events
3387 \inmodule QtGui
3388
3389 This event is sent just before QWidget::hide() returns, and also
3390 when a top-level window has been hidden (iconified) by the user.
3391
3392 If spontaneous() is true, the event originated outside the
3393 application. In this case, the user hid the window using the
3394 window manager controls, either by iconifying the window or by
3395 switching to another virtual desktop where the window is not
3396 visible. The window will become hidden but not withdrawn. If the
3397 window was iconified, QWidget::isMinimized() returns \c true.
3398
3399 \sa QShowEvent
3400*/
3401
3402/*!
3403 Constructs a QHideEvent.
3404*/
3405QHideEvent::QHideEvent()
3406 : QEvent(Hide)
3407{}
3408
3409/*! \internal
3410*/
3411QHideEvent::~QHideEvent()
3412{
3413}
3414
3415/*!
3416 \class QShowEvent
3417 \brief The QShowEvent class provides an event that is sent when a widget is shown.
3418
3419 \ingroup events
3420 \inmodule QtGui
3421
3422 There are two kinds of show events: show events caused by the
3423 window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
3424 show events are sent just after the window system shows the
3425 window; they are also sent when a top-level window is redisplayed
3426 after being iconified. Internal show events are delivered just
3427 before the widget becomes visible.
3428
3429 \sa QHideEvent
3430*/
3431
3432/*!
3433 Constructs a QShowEvent.
3434*/
3435QShowEvent::QShowEvent()
3436 : QEvent(Show)
3437{}
3438
3439/*! \internal
3440*/
3441QShowEvent::~QShowEvent()
3442{
3443}
3444
3445/*!
3446 \class QFileOpenEvent
3447 \brief The QFileOpenEvent class provides an event that will be
3448 sent when there is a request to open a file or a URL.
3449
3450 \ingroup events
3451 \inmodule QtGui
3452
3453 File open events will be sent to the QApplication::instance()
3454 when the operating system requests that a file or URL should be opened.
3455 This is a high-level event that can be caused by different user actions
3456 depending on the user's desktop environment; for example, double
3457 clicking on an file icon in the Finder on \macos.
3458
3459 This event is only used to notify the application of a request.
3460 It may be safely ignored.
3461
3462 \note This class is currently supported for \macos only.
3463
3464 \section1 \macos Example
3465
3466 In order to trigger the event on \macos, the application must be configured
3467 to let the OS know what kind of file(s) it should react on.
3468
3469 For example, the following \c Info.plist file declares that the application
3470 can act as a viewer for files with a PNG extension:
3471
3472 \snippet qfileopenevent/Info.plist Custom Info.plist
3473
3474 The following implementation of a QApplication subclass prints the path to
3475 the file that was, for example, dropped on the Dock icon of the application.
3476
3477 \snippet qfileopenevent/main.cpp QApplication subclass
3478*/
3479
3480/*!
3481 \internal
3482
3483 Constructs a file open event for the given \a file.
3484*/
3485QFileOpenEvent::QFileOpenEvent(const QString &file)
3486 : QEvent(FileOpen), f(file), m_url(QUrl::fromLocalFile(file))
3487{
3488}
3489
3490/*!
3491 \internal
3492
3493 Constructs a file open event for the given \a url.
3494*/
3495QFileOpenEvent::QFileOpenEvent(const QUrl &url)
3496 : QEvent(FileOpen), f(url.toLocalFile()), m_url(url)
3497{
3498}
3499
3500
3501/*! \internal
3502*/
3503QFileOpenEvent::~QFileOpenEvent()
3504{
3505}
3506
3507/*!
3508 \fn QString QFileOpenEvent::file() const
3509
3510 Returns the file that is being opened.
3511*/
3512
3513/*!
3514 \fn QUrl QFileOpenEvent::url() const
3515
3516 Returns the url that is being opened.
3517
3518 \since 4.6
3519*/
3520
3521/*!
3522 \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3523
3524 Opens a QFile on the \a file referenced by this event in the mode specified
3525 by \a flags. Returns \c true if successful; otherwise returns \c false.
3526
3527 This is necessary as some files cannot be opened by name, but require specific
3528 information stored in this event.
3529
3530 \since 4.8
3531*/
3532bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3533{
3534 file.setFileName(f);
3535 return file.open(flags);
3536}
3537
3538#ifndef QT_NO_TOOLBAR
3539/*!
3540 \internal
3541 \class QToolBarChangeEvent
3542 \brief The QToolBarChangeEvent class provides an event that is
3543 sent whenever a the toolbar button is clicked on \macos.
3544
3545 \ingroup events
3546 \inmodule QtGui
3547
3548 The QToolBarChangeEvent is sent when the toolbar button is clicked. On
3549 \macos, this is the long oblong button on the right side of the window
3550 title bar. The default implementation is to toggle the appearance (hidden or
3551 shown) of the associated toolbars for the window.
3552*/
3553
3554/*!
3555 \internal
3556
3557 Construct a QToolBarChangeEvent given the current button state in \a state.
3558*/
3559QToolBarChangeEvent::QToolBarChangeEvent(bool t)
3560 : QEvent(ToolBarChange), tog(t)
3561{}
3562
3563/*! \internal
3564*/
3565QToolBarChangeEvent::~QToolBarChangeEvent()
3566{
3567}
3568
3569/*!
3570 \fn bool QToolBarChangeEvent::toggle() const
3571 \internal
3572*/
3573
3574/*
3575 \fn Qt::ButtonState QToolBarChangeEvent::state() const
3576
3577 Returns the keyboard modifier flags at the time of the event.
3578
3579 The returned value is a selection of the following values,
3580 combined using the OR operator:
3581 Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
3582*/
3583
3584#endif // QT_NO_TOOLBAR
3585
3586#ifndef QT_NO_SHORTCUT
3587
3588/*!
3589 Constructs a shortcut event for the given \a key press,
3590 associated with the QShortcut ID \a id.
3591
3592 \a ambiguous specifies whether there is more than one QShortcut
3593 for the same key sequence.
3594*/
3595QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
3596 : QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
3597{
3598}
3599
3600/*!
3601 Destroys the event object.
3602*/
3603QShortcutEvent::~QShortcutEvent()
3604{
3605}
3606
3607#endif // QT_NO_SHORTCUT
3608
3609#ifndef QT_NO_DEBUG_STREAM
3610
3611static inline void formatTouchEvent(QDebug d, const QTouchEvent &t)
3612{
3613 d << "QTouchEvent(";
3614 QtDebugUtils::formatQEnum(d, t.type());
3615 d << " device: " << t.device()->name();
3616 d << " states: ";
3617 QtDebugUtils::formatQFlags(d, t.touchPointStates());
3618 d << ", " << t.touchPoints().size() << " points: " << t.touchPoints() << ')';
3619}
3620
3621static void formatUnicodeString(QDebug d, const QString &s)
3622{
3623 d << '"' << Qt::hex;
3624 for (int i = 0; i < s.size(); ++i) {
3625 if (i)
3626 d << ',';
3627 d << "U+" << s.at(i).unicode();
3628 }
3629 d << Qt::dec << '"';
3630}
3631
3632static inline void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
3633{
3634 d << "QInputMethodEvent(";
3635 if (!e->preeditString().isEmpty()) {
3636 d << "preedit=";
3637 formatUnicodeString(d, e->preeditString());
3638 }
3639 if (!e->commitString().isEmpty()) {
3640 d << ", commit=";
3641 formatUnicodeString(d, e->commitString());
3642 }
3643 if (e->replacementLength()) {
3644 d << ", replacementStart=" << e->replacementStart() << ", replacementLength="
3645 << e->replacementLength();
3646 }
3647 if (const int attributeCount = e->attributes().size()) {
3648 d << ", attributes= {";
3649 for (int a = 0; a < attributeCount; ++a) {
3650 const QInputMethodEvent::Attribute &at = e->attributes().at(a);
3651 if (a)
3652 d << ',';
3653 d << "[type= " << at.type << ", start=" << at.start << ", length=" << at.length
3654 << ", value=" << at.value << ']';
3655 }
3656 d << '}';
3657 }
3658 d << ')';
3659}
3660
3661static inline void formatInputMethodQueryEvent(QDebug d, const QInputMethodQueryEvent *e)
3662{
3663 QDebugStateSaver saver(d);
3664 d.noquote();
3665 const Qt::InputMethodQueries queries = e->queries();
3666 d << "QInputMethodQueryEvent(queries=" << Qt::showbase << Qt::hex << int(queries)
3667 << Qt::noshowbase << Qt::dec << ", {";
3668 for (unsigned mask = 1; mask <= Qt::ImInputItemClipRectangle; mask<<=1) {
3669 if (queries & mask) {
3670 const Qt::InputMethodQuery query = static_cast<Qt::InputMethodQuery>(mask);
3671 const QVariant value = e->value(query);
3672 if (value.isValid()) {
3673 d << '[';
3674 QtDebugUtils::formatQEnum(d, query);
3675 d << '=';
3676 if (query == Qt::ImHints)
3677 QtDebugUtils::formatQFlags(d, Qt::InputMethodHints(value.toInt()));
3678 else
3679 d << value.toString();
3680 d << "],";
3681 }
3682 }
3683 }
3684 d << "})";
3685}
3686
3687static const char *eventClassName(QEvent::Type t)
3688{
3689 switch (t) {
3690 case QEvent::ActionAdded:
3691 case QEvent::ActionRemoved:
3692 case QEvent::ActionChanged:
3693 return "QActionEvent";
3694 case QEvent::MouseButtonPress:
3695 case QEvent::MouseButtonRelease:
3696 case QEvent::MouseButtonDblClick:
3697 case QEvent::MouseMove:
3698 case QEvent::NonClientAreaMouseMove:
3699 case QEvent::NonClientAreaMouseButtonPress:
3700 case QEvent::NonClientAreaMouseButtonRelease:
3701 case QEvent::NonClientAreaMouseButtonDblClick:
3702 return "QMouseEvent";
3703 case QEvent::DragEnter:
3704 return "QDragEnterEvent";
3705 case QEvent::DragMove:
3706 return "QDragMoveEvent";
3707 case QEvent::Drop:
3708 return "QDropEvent";
3709 case QEvent::KeyPress:
3710 case QEvent::KeyRelease:
3711 case QEvent::ShortcutOverride:
3712 return "QKeyEvent";
3713 case QEvent::FocusIn:
3714 case QEvent::FocusOut:
3715 case QEvent::FocusAboutToChange:
3716 return "QFocusEvent";
3717 case QEvent::ChildAdded:
3718 case QEvent::ChildPolished:
3719 case QEvent::ChildRemoved:
3720 return "QChildEvent";
3721 case QEvent::Paint:
3722 return "QPaintEvent";
3723 case QEvent::Move:
3724 return "QMoveEvent";
3725 case QEvent::Resize:
3726 return "QResizeEvent";
3727 case QEvent::Show:
3728 return "QShowEvent";
3729 case QEvent::Hide:
3730 return "QHideEvent";
3731 case QEvent::Enter:
3732 return "QEnterEvent";
3733 case QEvent::Close:
3734 return "QCloseEvent";
3735 case QEvent::FileOpen:
3736 return "QFileOpenEvent";
3737#ifndef QT_NO_GESTURES
3738 case QEvent::NativeGesture:
3739 return "QNativeGestureEvent";
3740 case QEvent::Gesture:
3741 case QEvent::GestureOverride:
3742 return "QGestureEvent";
3743#endif
3744 case QEvent::HoverEnter:
3745 case QEvent::HoverLeave:
3746 case QEvent::HoverMove:
3747 return "QHoverEvent";
3748 case QEvent::TabletEnterProximity:
3749 case QEvent::TabletLeaveProximity:
3750 case QEvent::TabletPress:
3751 case QEvent::TabletMove:
3752 case QEvent::TabletRelease:
3753 return "QTabletEvent";
3754 case QEvent::StatusTip:
3755 return "QStatusTipEvent";
3756 case QEvent::ToolTip:
3757 return "QHelpEvent";
3758 case QEvent::WindowStateChange:
3759 return "QWindowStateChangeEvent";
3760 case QEvent::Wheel:
3761 return "QWheelEvent";
3762 case QEvent::TouchBegin:
3763 case QEvent::TouchUpdate:
3764 case QEvent::TouchEnd:
3765 return "QTouchEvent";
3766 case QEvent::Shortcut:
3767 return "QShortcutEvent";
3768 case QEvent::InputMethod:
3769 return "QInputMethodEvent";
3770 case QEvent::InputMethodQuery:
3771 return "QInputMethodQueryEvent";
3772 case QEvent::OrientationChange:
3773 return "QScreenOrientationChangeEvent";
3774 case QEvent::ScrollPrepare:
3775 return "QScrollPrepareEvent";
3776 case QEvent::Scroll:
3777 return "QScrollEvent";
3778 case QEvent::GraphicsSceneMouseMove:
3779 case QEvent::GraphicsSceneMousePress:
3780 case QEvent::GraphicsSceneMouseRelease:
3781 case QEvent::GraphicsSceneMouseDoubleClick:
3782 return "QGraphicsSceneMouseEvent";
3783 case QEvent::GraphicsSceneContextMenu:
3784 case QEvent::GraphicsSceneHoverEnter:
3785 case QEvent::GraphicsSceneHoverMove:
3786 case QEvent::GraphicsSceneHoverLeave:
3787 case QEvent::GraphicsSceneHelp:
3788 case QEvent::GraphicsSceneDragEnter:
3789 case QEvent::GraphicsSceneDragMove:
3790 case QEvent::GraphicsSceneDragLeave:
3791 case QEvent::GraphicsSceneDrop:
3792 case QEvent::GraphicsSceneWheel:
3793 return "QGraphicsSceneEvent";
3794 case QEvent::Timer:
3795 return "QTimerEvent";
3796 case QEvent::PlatformSurface:
3797 return "QPlatformSurfaceEvent";
3798 default:
3799 break;
3800 }
3801 return "QEvent";
3802}
3803
3804# if QT_CONFIG(draganddrop)
3805
3806static void formatDropEvent(QDebug d, const QDropEvent *e)
3807{
3808 const QEvent::Type type = e->type();
3809 d << eventClassName(type) << "(dropAction=";
3810 QtDebugUtils::formatQEnum(d, e->dropAction());
3811 d << ", proposedAction=";
3812 QtDebugUtils::formatQEnum(d, e->proposedAction());
3813 d << ", possibleActions=";
3814 QtDebugUtils::formatQFlags(d, e->possibleActions());
3815 d << ", posF=";
3816 QtDebugUtils::formatQPoint(d, e->posF());
3817 if (type == QEvent::DragMove || type == QEvent::DragEnter)
3818 d << ", answerRect=" << static_cast<const QDragMoveEvent *>(e)->answerRect();
3819 d << ", formats=" << e->mimeData()->formats();
3820 QtDebugUtils::formatNonNullQFlags(d, ", keyboardModifiers=", e->keyboardModifiers());
3821 d << ", ";
3822 QtDebugUtils::formatQFlags(d, e->mouseButtons());
3823}
3824
3825# endif // QT_CONFIG(draganddrop)
3826
3827# if QT_CONFIG(tabletevent)
3828
3829static void formatTabletEvent(QDebug d, const QTabletEvent *e)
3830{
3831 const QEvent::Type type = e->type();
3832
3833 d << eventClassName(type) << '(';
3834 QtDebugUtils::formatQEnum(d, type);
3835 d << ", device=";
3836 QtDebugUtils::formatQEnum(d, e->device());
3837 d << ", pointerType=";
3838 QtDebugUtils::formatQEnum(d, e->pointerType());
3839 d << ", uniqueId=" << e->uniqueId()
3840 << ", pos=" << e->posF()
3841 << ", z=" << e->z()
3842 << ", xTilt=" << e->xTilt()
3843 << ", yTilt=" << e->yTilt()
3844 << ", ";
3845 QtDebugUtils::formatQFlags(d, e->buttons());
3846 if (type == QEvent::TabletPress || type == QEvent::TabletMove)
3847 d << ", pressure=" << e->pressure();
3848 if (e->device() == QTabletEvent::RotationStylus || e->device() == QTabletEvent::FourDMouse)
3849 d << ", rotation=" << e->rotation();
3850 if (e->device() == QTabletEvent::Airbrush)
3851 d << ", tangentialPressure=" << e->tangentialPressure();
3852}
3853
3854# endif // QT_CONFIG(tabletevent)
3855
3856QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp)
3857{
3858 QDebugStateSaver saver(dbg);
3859 dbg.nospace();
3860 dbg << "TouchPoint(" << Qt::hex << tp.id() << Qt::dec << " (";
3861 QtDebugUtils::formatQPoint(dbg, tp.pos());
3862 dbg << ") ";
3863 QtDebugUtils::formatQEnum(dbg, tp.state());
3864 dbg << " pressure " << tp.pressure() << " ellipse ("
3865 << tp.ellipseDiameters().width() << " x " << tp.ellipseDiameters().height()
3866 << " angle " << tp.rotation() << ") vel (";
3867 QtDebugUtils::formatQPoint(dbg, tp.velocity().toPointF());
3868 dbg << ") start (";
3869 QtDebugUtils::formatQPoint(dbg, tp.startPos());
3870 dbg << ") last (";
3871 QtDebugUtils::formatQPoint(dbg, tp.lastPos());
3872 dbg << ") delta (";
3873 QtDebugUtils::formatQPoint(dbg, tp.pos() - tp.lastPos());
3874 dbg << ')';
3875 return dbg;
3876}
3877
3878QDebug operator<<(QDebug dbg, const QEvent *e)
3879{
3880 QDebugStateSaver saver(dbg);
3881 dbg.nospace();
3882 if (!e) {
3883 dbg << "QEvent(this = 0x0)";
3884 return dbg;
3885 }
3886 // More useful event output could be added here
3887 const QEvent::Type type = e->type();
3888 switch (type) {
3889 case QEvent::Expose:
3890 dbg << "QExposeEvent(" << static_cast<const QExposeEvent *>(e)->region() << ')';
3891 break;
3892 case QEvent::Paint:
3893 dbg << "QPaintEvent(" << static_cast<const QPaintEvent *>(e)->region() << ')';
3894 break;
3895 case QEvent::MouseButtonPress:
3896 case QEvent::MouseMove:
3897 case QEvent::MouseButtonRelease:
3898 case QEvent::MouseButtonDblClick:
3899 case QEvent::NonClientAreaMouseButtonPress:
3900 case QEvent::NonClientAreaMouseMove:
3901 case QEvent::NonClientAreaMouseButtonRelease:
3902 case QEvent::NonClientAreaMouseButtonDblClick:
3903 {
3904 const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
3905 const Qt::MouseButton button = me->button();
3906 const Qt::MouseButtons buttons = me->buttons();
3907 dbg << "QMouseEvent(";
3908 QtDebugUtils::formatQEnum(dbg, type);
3909 if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) {
3910 dbg << ", ";
3911 QtDebugUtils::formatQEnum(dbg, button);
3912 }
3913 if (buttons && button != buttons) {
3914 dbg << ", buttons=";
3915 QtDebugUtils::formatQFlags(dbg, buttons);
3916 }
3917 QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers());
3918 dbg << ", localPos=";
3919 QtDebugUtils::formatQPoint(dbg, me->localPos());
3920 dbg << ", screenPos=";
3921 QtDebugUtils::formatQPoint(dbg, me->screenPos());
3922 QtDebugUtils::formatNonNullQEnum(dbg, ", ", me->source());
3923 QtDebugUtils::formatNonNullQFlags(dbg, ", flags=", me->flags());
3924 dbg << ')';
3925 }
3926 break;
3927# if QT_CONFIG(wheelevent)
3928 case QEvent::Wheel: {
3929 const QWheelEvent *we = static_cast<const QWheelEvent *>(e);
3930 dbg << "QWheelEvent(" << we->phase();
3931 if (!we->pixelDelta().isNull() || !we->angleDelta().isNull())
3932 dbg << ", pixelDelta=" << we->pixelDelta() << ", angleDelta=" << we->angleDelta();
3933#if QT_DEPRECATED_SINCE(5, 14)
3934 else if (int qt4Delta = we->delta())
3935 dbg << ", delta=" << qt4Delta << ", orientation=" << we->orientation();
3936#endif
3937 dbg << ')';
3938 }
3939 break;
3940# endif // QT_CONFIG(wheelevent)
3941 case QEvent::KeyPress:
3942 case QEvent::KeyRelease:
3943 case QEvent::ShortcutOverride:
3944 {
3945 const QKeyEvent *ke = static_cast<const QKeyEvent *>(e);
3946 dbg << "QKeyEvent(";
3947 QtDebugUtils::formatQEnum(dbg, type);
3948 dbg << ", ";
3949 QtDebugUtils::formatQEnum(dbg, static_cast<Qt::Key>(ke->key()));
3950 QtDebugUtils::formatNonNullQFlags(dbg, ", ", ke->modifiers());
3951 if (!ke->text().isEmpty())
3952 dbg << ", text=" << ke->text();
3953 if (ke->isAutoRepeat())
3954 dbg << ", autorepeat, count=" << ke->count();
3955 dbg << ')';
3956 }
3957 break;
3958#ifndef QT_NO_SHORTCUT
3959 case QEvent::Shortcut: {
3960 const QShortcutEvent *se = static_cast<const QShortcutEvent *>(e);
3961 dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId();
3962 if (se->isAmbiguous())
3963 dbg << ", ambiguous";
3964 dbg << ')';
3965 }
3966 break;
3967#endif
3968 case QEvent::FocusAboutToChange:
3969 case QEvent::FocusIn:
3970 case QEvent::FocusOut:
3971 dbg << "QFocusEvent(";
3972 QtDebugUtils::formatQEnum(dbg, type);
3973 dbg << ", ";
3974 QtDebugUtils::formatQEnum(dbg, static_cast<const QFocusEvent *>(e)->reason());
3975 dbg << ')';
3976 break;
3977 case QEvent::Move: {
3978 const QMoveEvent *me = static_cast<const QMoveEvent *>(e);
3979 dbg << "QMoveEvent(";
3980 QtDebugUtils::formatQPoint(dbg, me->pos());
3981 if (!me->spontaneous())
3982 dbg << ", non-spontaneous";
3983 dbg << ')';
3984 }
3985 break;
3986 case QEvent::Resize: {
3987 const QResizeEvent *re = static_cast<const QResizeEvent *>(e);
3988 dbg << "QResizeEvent(";
3989 QtDebugUtils::formatQSize(dbg, re->size());
3990 if (!re->spontaneous())
3991 dbg << ", non-spontaneous";
3992 dbg << ')';
3993 }
3994 break;
3995# if QT_CONFIG(draganddrop)
3996 case QEvent::DragEnter:
3997 case QEvent::DragMove:
3998 case QEvent::Drop:
3999 formatDropEvent(dbg, static_cast<const QDropEvent *>(e));
4000 break;
4001# endif // QT_CONFIG(draganddrop)
4002 case QEvent::InputMethod:
4003 formatInputMethodEvent(dbg, static_cast<const QInputMethodEvent *>(e));
4004 break;
4005 case QEvent::InputMethodQuery:
4006 formatInputMethodQueryEvent(dbg, static_cast<const QInputMethodQueryEvent *>(e));
4007 break;
4008 case QEvent::TouchBegin:
4009 case QEvent::TouchUpdate:
4010 case QEvent::TouchEnd:
4011 formatTouchEvent(dbg, *static_cast<const QTouchEvent*>(e));
4012 break;
4013 case QEvent::ChildAdded:
4014 case QEvent::ChildPolished:
4015 case QEvent::ChildRemoved:
4016 dbg << "QChildEvent(";
4017 QtDebugUtils::formatQEnum(dbg, type);
4018 dbg << ", " << (static_cast<const QChildEvent*>(e))->child() << ')';
4019 break;
4020# ifndef QT_NO_GESTURES
4021 case QEvent::NativeGesture: {
4022 const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(e);
4023 dbg << "QNativeGestureEvent(";
4024 QtDebugUtils::formatQEnum(dbg, ne->gestureType());
4025 dbg << ", localPos=";
4026 QtDebugUtils::formatQPoint(dbg, ne->localPos());
4027 dbg << ", value=" << ne->value() << ')';
4028 }
4029 break;
4030# endif // !QT_NO_GESTURES
4031 case QEvent::ApplicationStateChange:
4032 dbg << "QApplicationStateChangeEvent(";
4033 QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState());
4034 dbg << ')';
4035 break;
4036# ifndef QT_NO_CONTEXTMENU
4037 case QEvent::ContextMenu:
4038 dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')';
4039 break;
4040# endif // !QT_NO_CONTEXTMENU
4041# if QT_CONFIG(tabletevent)
4042 case QEvent::TabletEnterProximity:
4043 case QEvent::TabletLeaveProximity:
4044 case QEvent::TabletPress:
4045 case QEvent::TabletMove:
4046 case QEvent::TabletRelease:
4047 formatTabletEvent(dbg, static_cast<const QTabletEvent *>(e));
4048 break;
4049# endif // QT_CONFIG(tabletevent)
4050 case QEvent::Enter:
4051 dbg << "QEnterEvent(" << static_cast<const QEnterEvent *>(e)->pos() << ')';
4052 break;
4053 case QEvent::Timer:
4054 dbg << "QTimerEvent(id=" << static_cast<const QTimerEvent *>(e)->timerId() << ')';
4055 break;
4056 case QEvent::PlatformSurface:
4057 dbg << "QPlatformSurfaceEvent(surfaceEventType=";
4058 switch (static_cast<const QPlatformSurfaceEvent *>(e)->surfaceEventType()) {
4059 case QPlatformSurfaceEvent::SurfaceCreated:
4060 dbg << "SurfaceCreated";
4061 break;
4062 case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed:
4063 dbg << "SurfaceAboutToBeDestroyed";
4064 break;
4065 }
4066 dbg << ')';
4067 break;
4068 case QEvent::ScrollPrepare: {
4069 const QScrollPrepareEvent *se = static_cast<const QScrollPrepareEvent *>(e);
4070 dbg << "QScrollPrepareEvent(viewportSize=" << se->viewportSize()
4071 << ", contentPosRange=" << se->contentPosRange()
4072 << ", contentPos=" << se->contentPos() << ')';
4073 }
4074 break;
4075 case QEvent::Scroll: {
4076 const QScrollEvent *se = static_cast<const QScrollEvent *>(e);
4077 dbg << "QScrollEvent(contentPos=" << se->contentPos()
4078 << ", overshootDistance=" << se->overshootDistance()
4079 << ", scrollState=" << se->scrollState() << ')';
4080 }
4081 break;
4082 default:
4083 dbg << eventClassName(type) << '(';
4084 QtDebugUtils::formatQEnum(dbg, type);
4085 dbg << ", " << (const void *)e << ')';
4086 break;
4087 }
4088 return dbg;
4089}
4090#endif // !QT_NO_DEBUG_STREAM
4091
4092/*!
4093 \class QShortcutEvent
4094 \brief The QShortcutEvent class provides an event which is generated when
4095 the user presses a key combination.
4096
4097 \ingroup events
4098 \inmodule QtGui
4099
4100 Normally you do not need to use this class directly; QShortcut
4101 provides a higher-level interface to handle shortcut keys.
4102
4103 \sa QShortcut
4104*/
4105
4106/*!
4107 \fn const QKeySequence &QShortcutEvent::key() const
4108
4109 Returns the key sequence that triggered the event.
4110*/
4111
4112/*!
4113 \fn int QShortcutEvent::shortcutId() const
4114
4115 Returns the ID of the QShortcut object for which this event was
4116 generated.
4117
4118 \sa QShortcut::id()
4119*/
4120
4121/*!
4122 \fn bool QShortcutEvent::isAmbiguous() const
4123
4124 Returns \c true if the key sequence that triggered the event is
4125 ambiguous.
4126
4127 \sa QShortcut::activatedAmbiguously()
4128*/
4129
4130/*!
4131 \class QWindowStateChangeEvent
4132 \ingroup events
4133 \inmodule QtGui
4134
4135 \brief The QWindowStateChangeEvent class provides the window state before a
4136 window state change.
4137*/
4138
4139/*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
4140
4141 Returns the state of the window before the change.
4142*/
4143
4144/*! \internal
4145 */
4146QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride)
4147 : QEvent(WindowStateChange), ostate(s), m_override(isOverride)
4148{
4149}
4150
4151/*! \internal
4152 */
4153bool QWindowStateChangeEvent::isOverride() const
4154{
4155 return m_override;
4156}
4157
4158/*! \internal
4159*/
4160QWindowStateChangeEvent::~QWindowStateChangeEvent()
4161{
4162}
4163
4164
4165/*!
4166 \class QTouchEvent
4167 \brief The QTouchEvent class contains parameters that describe a touch event.
4168 \since 4.6
4169 \ingroup events
4170 \ingroup touch
4171 \inmodule QtGui
4172
4173 \section1 Enabling Touch Events
4174
4175 Touch events occur when pressing, releasing, or moving one or more touch points on a touch
4176 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
4177 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
4178 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
4179
4180 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
4181 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
4182
4183 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
4184 widget, and the widget will receive all updates for the touch point until it is released.
4185 Note that it is possible for a widget to receive events for numerous touch points, and that
4186 multiple widgets may be receiving touch events at the same time.
4187
4188 \section1 Event Handling
4189
4190 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or
4191 QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for
4192 widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
4193
4194 Unlike widgets, QWindows receive touch events always, there is no need to opt in. When working
4195 directly with a QWindow, it is enough to reimplement QWindow::touchEvent().
4196
4197 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
4198 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
4199 filtered by an event filter, then no further touch events are sent until the next
4200 QEvent::TouchBegin.
4201
4202 Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event
4203 applications are requested to ignore the entire active touch sequence. For example in a
4204 composited system the compositor may decide to treat certain gestures as system-wide
4205 gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
4206 notified with a QEvent::TouchCancel event so they can update their state accordingly.
4207
4208 The touchPoints() function returns a list of all touch points contained in the event. Note that
4209 this list may be empty, for example in case of a QEvent::TouchCancel event. Information about
4210 each touch point can be retrieved using the QTouchEvent::TouchPoint class. The
4211 Qt::TouchPointState enum describes the different states that a touch point may have.
4212
4213 \note The list of touchPoints() will never be partial: A touch event will always contain a touch
4214 point for each existing physical touch contacts targetting the window or widget to which the
4215 event is sent. For instance, assuming that all touches target the same window or widget, an
4216 event with a condition of touchPoints().count()==2 is guaranteed to imply that the number of
4217 fingers touching the touchscreen or touchpad is exactly two.
4218
4219 \section1 Event Delivery and Propagation
4220
4221 By default, QGuiApplication translates the first touch point in a QTouchEvent into
4222 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
4223 normally handle QTouchEvent. See below for information on some special considerations needed
4224 when doing this.
4225
4226 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
4227 contains a special accept flag that indicates whether the receiver wants the event. By default,
4228 the event is accepted. You should call ignore() if the touch event is not handled by your
4229 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
4230 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
4231 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
4232 propagation for QGraphicsItems).
4233
4234 \section1 Touch Point Grouping
4235
4236 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
4237 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
4238 widget, which could theoretically happen during propagation if, for example, the user touched 2
4239 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
4240
4241 To avoid this, Qt will group new touch points together using the following rules:
4242
4243 \list
4244
4245 \li When the first touch point is detected, the destination widget is determined firstly by the
4246 location on screen and secondly by the propagation rules.
4247
4248 \li When additional touch points are detected, Qt first looks to see if there are any active
4249 touch points on any ancestor or descendent of the widget under the new touch point. If there
4250 are, the new touch point is grouped with the first, and the new touch point will be sent in a
4251 single QTouchEvent to the widget that handled the first touch point. (The widget under the new
4252 touch point will not receive an event).
4253
4254 \endlist
4255
4256 This makes it possible for sibling widgets to handle touch events independently while making
4257 sure that the sequence of QTouchEvents is always correct.
4258
4259 \section1 Mouse Events and Touch Event Synthesizing
4260
4261 QTouchEvent delivery is independent from that of QMouseEvent. The application flags
4262 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents
4263 can be used to enable or disable automatic synthesizing of touch events to mouse events and
4264 mouse events to touch events.
4265
4266 \section1 Caveats
4267
4268 \list
4269
4270 \li As mentioned above, enabling touch events means multiple widgets can be receiving touch
4271 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
4272 this gives you great flexibility in designing touch user interfaces. Be aware of the
4273 implications. For example, it is possible that the user is moving a QSlider with one finger and
4274 pressing a QPushButton with another. The signals emitted by these widgets will be
4275 interleaved.
4276
4277 \li Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
4278 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
4279 recipients, recursion may cause problems, including but not limited to lost events
4280 and unexpected infinite recursion.
4281
4282 \li QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
4283 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
4284 undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
4285 points.
4286
4287 \endlist
4288
4289 \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
4290 QGraphicsItem::acceptTouchEvents()
4291*/
4292
4293/*! \enum QTouchEvent::DeviceType
4294 \obsolete
4295
4296 This enum represents the type of device that generated a QTouchEvent.
4297
4298 This enum has been deprecated. Use QTouchDevice::DeviceType instead.
4299 \omitvalue TouchPad
4300 \omitvalue TouchScreen
4301
4302 \sa QTouchDevice::DeviceType, QTouchDevice::type(), QTouchEvent::device()
4303*/
4304
4305/*!
4306 Constructs a QTouchEvent with the given \a eventType, \a device, and
4307 \a touchPoints. The \a touchPointStates and \a modifiers
4308 are the current touch point states and keyboard modifiers at the time of
4309 the event.
4310*/
4311QTouchEvent::QTouchEvent(QEvent::Type eventType,
4312 QTouchDevice *device,
4313 Qt::KeyboardModifiers modifiers,
4314 Qt::TouchPointStates touchPointStates,
4315 const QList<QTouchEvent::TouchPoint> &touchPoints)
4316 : QInputEvent(eventType, modifiers),
4317 _window(0),
4318 _target(0),
4319 _device(device),
4320 _touchPointStates(touchPointStates),
4321 _touchPoints(touchPoints)
4322{ }
4323
4324/*!
4325 Destroys the QTouchEvent.
4326*/
4327QTouchEvent::~QTouchEvent()
4328{ }
4329
4330/*! \fn QWindow *QTouchEvent::window() const
4331
4332 Returns the window on which the event occurred. Useful for doing
4333 global-local mapping on data like rawScreenPositions() which,
4334 for performance reasons, only stores the global positions in the
4335 touch event.
4336*/
4337
4338/*! \fn QObject *QTouchEvent::target() const
4339
4340 Returns the target object within the window on which the event occurred.
4341 This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
4342*/
4343
4344/*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
4345 \obsolete
4346
4347 Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
4348
4349 This function has been deprecated. Use QTouchDevice::type() instead.
4350
4351 \sa QTouchDevice::type(), QTouchEvent::device()
4352*/
4353
4354/*! \fn QTouchEvent::TouchPoint::TouchPoint(TouchPoint &&other)
4355
4356 Move-constructs a TouchPoint instance, making it point to the same
4357 object that \a other was pointing to.
4358*/
4359
4360/*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
4361
4362 Returns a bitwise OR of all the touch point states for this event.
4363*/
4364
4365/*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
4366
4367 Returns the list of touch points contained in the touch event.
4368*/
4369
4370/*! \fn QTouchDevice* QTouchEvent::device() const
4371
4372 Returns the touch device from which this touch event originates.
4373*/
4374
4375/*! \fn void QTouchEvent::setWindow(QWindow *window)
4376
4377 \internal
4378
4379 Sets the window for this event.
4380*/
4381
4382/*! \fn void QTouchEvent::setTarget(QObject *target)
4383
4384 \internal
4385
4386 Sets the target within the window (typically a widget) for this event.
4387*/
4388
4389/*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
4390
4391 \internal
4392
4393 Sets a bitwise OR of all the touch point states for this event.
4394*/
4395
4396/*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
4397
4398 \internal
4399
4400 Sets the list of touch points for this event.
4401*/
4402
4403/*! \fn void QTouchEvent::setDevice(QTouchDevice *adevice)
4404
4405 \internal
4406
4407 Sets the device to \a adevice.
4408*/
4409
4410/*! \class QTouchEvent::TouchPoint
4411 \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
4412 \since 4.6
4413 \inmodule QtGui
4414
4415 \image touchpoint-metrics.png
4416*/
4417
4418/*! \enum TouchPoint::InfoFlag
4419
4420 The values of this enum describe additional information about a touch point.
4421
4422 \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger.
4423 \value Token Indicates that the contact has been made by a fiducial object (e.g. a knob or other token) instead of a finger.
4424*/
4425
4426/*!
4427 \internal
4428
4429 Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
4430*/
4431QTouchEvent::TouchPoint::TouchPoint(int id)
4432 : d(new QTouchEventTouchPointPrivate(id))
4433{ }
4434
4435/*!
4436 \fn QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
4437 \internal
4438
4439 Constructs a copy of \a other.
4440*/
4441QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
4442 : d(other.d)
4443{
4444 d->ref.ref();
4445}
4446
4447/*!
4448 \internal
4449
4450 Destroys the QTouchEvent::TouchPoint.
4451*/
4452QTouchEvent::TouchPoint::~TouchPoint()
4453{
4454 if (d && !d->ref.deref())
4455 delete d;
4456}
4457
4458/*!
4459 Returns the id number of this touch point.
4460
4461 Do not assume that id numbers start at zero or that they are sequential.
4462 Such an assumption is often false due to the way the underlying drivers work.
4463*/
4464int QTouchEvent::TouchPoint::id() const
4465{
4466 return d->id;
4467}
4468
4469/*!
4470 \since 5.8
4471 Returns the unique ID of this touch point or token, if any.
4472
4473 It is normally invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
4474 because touchscreens cannot uniquely identify fingers. But when the
4475 \l {TouchPoint::InfoFlag} {Token} flag is set, it is expected to uniquely
4476 identify a specific token (fiducial object).
4477
4478 \sa flags
4479*/
4480QPointingDeviceUniqueId QTouchEvent::TouchPoint::uniqueId() const
4481{
4482 return d->uniqueId;
4483}
4484
4485/*!
4486 Returns the current state of this touch point.
4487*/
4488Qt::TouchPointState QTouchEvent::TouchPoint::state() const
4489{
4490 return Qt::TouchPointState(int(d->state));
4491}
4492
4493/*!
4494 Returns the position of this touch point, relative to the widget
4495 or QGraphicsItem that received the event.
4496
4497 \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
4498*/
4499QPointF QTouchEvent::TouchPoint::pos() const
4500{
4501 return d->pos;
4502}
4503
4504/*!
4505 Returns the scene position of this touch point.
4506
4507 The scene position is the position in QGraphicsScene coordinates
4508 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
4509 reimplementation, and identical to the screen position for
4510 widgets.
4511
4512 \sa startScenePos(), lastScenePos(), pos()
4513*/
4514QPointF QTouchEvent::TouchPoint::scenePos() const
4515{
4516 return d->scenePos;
4517}
4518
4519/*!
4520 Returns the screen position of this touch point.
4521
4522 \sa startScreenPos(), lastScreenPos(), pos()
4523*/
4524QPointF QTouchEvent::TouchPoint::screenPos() const
4525{
4526 return d->screenPos;
4527}
4528
4529/*!
4530 Returns the normalized position of this touch point.
4531
4532 The coordinates are normalized to the size of the touch device,
4533 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
4534
4535 \sa startNormalizedPos(), lastNormalizedPos(), pos()
4536*/
4537QPointF QTouchEvent::TouchPoint::normalizedPos() const
4538{
4539 return d->normalizedPos;
4540}
4541
4542/*!
4543 Returns the starting position of this touch point, relative to the
4544 widget or QGraphicsItem that received the event.
4545
4546 \sa pos(), lastPos()
4547*/
4548QPointF QTouchEvent::TouchPoint::startPos() const
4549{
4550 return d->startPos;
4551}
4552
4553/*!
4554 Returns the starting scene position of this touch point.
4555
4556 The scene position is the position in QGraphicsScene coordinates
4557 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
4558 reimplementation, and identical to the screen position for
4559 widgets.
4560
4561 \sa scenePos(), lastScenePos()
4562*/
4563QPointF QTouchEvent::TouchPoint::startScenePos() const
4564{
4565 return d->startScenePos;
4566}
4567
4568/*!
4569 Returns the starting screen position of this touch point.
4570
4571 \sa screenPos(), lastScreenPos()
4572*/
4573QPointF QTouchEvent::TouchPoint::startScreenPos() const
4574{
4575 return d->startScreenPos;
4576}
4577
4578/*!
4579 Returns the normalized starting position of this touch point.
4580
4581 The coordinates are normalized to the size of the touch device,
4582 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
4583
4584 \sa normalizedPos(), lastNormalizedPos()
4585*/
4586QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
4587{
4588 return d->startNormalizedPos;
4589}
4590
4591/*!
4592 Returns the position of this touch point from the previous touch
4593 event, relative to the widget or QGraphicsItem that received the event.
4594
4595 \sa pos(), startPos()
4596*/
4597QPointF QTouchEvent::TouchPoint::lastPos() const
4598{
4599 return d->lastPos;
4600}
4601
4602/*!
4603 Returns the scene position of this touch point from the previous
4604 touch event.
4605
4606 The scene position is the position in QGraphicsScene coordinates
4607 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
4608 reimplementation, and identical to the screen position for
4609 widgets.
4610
4611 \sa scenePos(), startScenePos()
4612*/
4613QPointF QTouchEvent::TouchPoint::lastScenePos() const
4614{
4615 return d->lastScenePos;
4616}
4617
4618/*!
4619 Returns the screen position of this touch point from the previous
4620 touch event.
4621
4622 \sa screenPos(), startScreenPos()
4623*/
4624QPointF QTouchEvent::TouchPoint::lastScreenPos() const
4625{
4626 return d->lastScreenPos;
4627}
4628
4629/*!
4630 Returns the normalized position of this touch point from the
4631 previous touch event.
4632
4633 The coordinates are normalized to the size of the touch device,
4634 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
4635
4636 \sa normalizedPos(), startNormalizedPos()
4637*/
4638QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
4639{
4640 return d->lastNormalizedPos;
4641}
4642
4643/*!
4644 Returns the rect for this touch point, relative to the widget
4645 or QGraphicsItem that received the event. The rect is centered
4646 around the point returned by pos().
4647
4648 \note This function returns an empty rect if the device does not report touch point sizes.
4649
4650 \obsolete This function is deprecated in 5.9 because it returns the outer bounds
4651 of the touchpoint regardless of rotation, whereas a touchpoint is more correctly
4652 modeled as an ellipse at position pos() with ellipseDiameters()
4653 which are independent of rotation().
4654
4655 \sa scenePos(), ellipseDiameters()
4656*/
4657QRectF QTouchEvent::TouchPoint::rect() const
4658{
4659 QRectF ret(QPointF(), d->ellipseDiameters);
4660 ret.moveCenter(d->pos);
4661 return ret;
4662}
4663
4664/*!
4665 Returns the rect for this touch point in scene coordinates.
4666
4667 \note This function returns an empty rect if the device does not report touch point sizes.
4668
4669 \obsolete This function is deprecated in 5.9 because it returns the outer bounds
4670 of the touchpoint regardless of rotation, whereas a touchpoint is more correctly
4671 modeled as an ellipse at position scenePos() with ellipseDiameters()
4672 which are independent of rotation().
4673
4674 \sa scenePos(), ellipseDiameters()
4675*/
4676QRectF QTouchEvent::TouchPoint::sceneRect() const
4677{
4678 QRectF ret(QPointF(), d->ellipseDiameters);
4679 ret.moveCenter(d->scenePos);
4680 return ret;
4681}
4682
4683/*!
4684 Returns the rect for this touch point in screen coordinates.
4685
4686 \note This function returns an empty rect if the device does not report touch point sizes.
4687
4688 \obsolete This function is deprecated because it returns the outer bounds of the
4689 touchpoint regardless of rotation, whereas a touchpoint is more correctly
4690 modeled as an ellipse at position screenPos() with ellipseDiameters()
4691 which are independent of rotation().
4692
4693 \sa screenPos(), ellipseDiameters()
4694*/
4695QRectF QTouchEvent::TouchPoint::screenRect() const
4696{
4697 QRectF ret(QPointF(), d->ellipseDiameters);
4698 ret.moveCenter(d->screenPos);
4699 return ret;
4700}
4701
4702/*!
4703 Returns the pressure of this touch point. The return value is in
4704 the range 0.0 to 1.0.
4705*/
4706qreal QTouchEvent::TouchPoint::pressure() const
4707{
4708 return d->pressure;
4709}
4710
4711/*!
4712 \since 5.8
4713 Returns the angular orientation of this touch point. The return value is in degrees,
4714 where zero (the default) indicates the finger or token is pointing upwards,
4715 a negative angle means it's rotated to the left, and a positive angle means
4716 it's rotated to the right. Most touchscreens do not detect rotation, so
4717 zero is the most common value.
4718*/
4719qreal QTouchEvent::TouchPoint::rotation() const
4720{
4721 return d->rotation;
4722}
4723
4724/*!
4725 \since 5.9
4726 Returns the width and height of the bounding ellipse of this touch point.
4727 The return value is in logical pixels. Most touchscreens do not detect the
4728 shape of the contact point, so a null size is the most common value.
4729 In other cases the diameters may be nonzero and equal (the ellipse is
4730 approximated as a circle).
4731*/
4732QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const
4733{
4734 return d->ellipseDiameters;
4735}
4736
4737/*!
4738 Returns a velocity vector for this touch point.
4739 The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
4740
4741 \note The returned vector is only valid if the touch device's capabilities include QTouchDevice::Velocity.
4742
4743 \sa QTouchDevice::capabilities(), device()
4744*/
4745QVector2D QTouchEvent::TouchPoint::velocity() const
4746{
4747 return d->velocity;
4748}
4749
4750/*!
4751 Returns additional information about the touch point.
4752
4753 \sa QTouchEvent::TouchPoint::InfoFlags
4754 */
4755QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const
4756{
4757 return d->flags;
4758}
4759
4760/*!
4761 \since 5.0
4762 Returns the raw, unfiltered positions for the touch point. The positions are in native screen coordinates.
4763 To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window().
4764
4765 \note Returns an empty vector if the touch device's capabilities do not include QTouchDevice::RawPositions.
4766
4767 \note Native screen coordinates refer to the native orientation of the screen which, in case of
4768 mobile devices, is typically portrait. This means that on systems capable of screen orientation
4769 changes the positions in this list will not reflect the current orientation (unlike pos(),
4770 screenPos(), etc.) and will always be reported in the native orientation.
4771
4772 \sa QTouchDevice::capabilities(), device(), window()
4773 */
4774QVector<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
4775{
4776 return d->rawScreenPositions;
4777}
4778
4779/*! \internal */
4780void QTouchEvent::TouchPoint::setId(int id)
4781{
4782 if (d->ref.loadRelaxed() != 1)
4783 d = d->detach();
4784 d->id = id;
4785}
4786
4787/*! \internal */
4788void QTouchEvent::TouchPoint::setUniqueId(qint64 uid)
4789{
4790 if (d->ref.loadRelaxed() != 1)
4791 d = d->detach();
4792 d->uniqueId = QPointingDeviceUniqueId::fromNumericId(uid);
4793}
4794
4795/*! \internal */
4796void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
4797{
4798 if (d->ref.loadRelaxed() != 1)
4799 d = d->detach();
4800 d->state = state;
4801}
4802
4803/*! \internal */
4804void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
4805{
4806 if (d->ref.loadRelaxed() != 1)
4807 d = d->detach();
4808 d->pos = pos;
4809}
4810
4811/*! \internal */
4812void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
4813{
4814 if (d->ref.loadRelaxed() != 1)
4815 d = d->detach();
4816 d->scenePos = scenePos;
4817}
4818
4819/*! \internal */
4820void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
4821{
4822 if (d->ref.loadRelaxed() != 1)
4823 d = d->detach();
4824 d->screenPos = screenPos;
4825}
4826
4827/*! \internal */
4828void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
4829{
4830 if (d->ref.loadRelaxed() != 1)
4831 d = d->detach();
4832 d->normalizedPos = normalizedPos;
4833}
4834
4835/*! \internal */
4836void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
4837{
4838 if (d->ref.loadRelaxed() != 1)
4839 d = d->detach();
4840 d->startPos = startPos;
4841}
4842
4843/*! \internal */
4844void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
4845{
4846 if (d->ref.loadRelaxed() != 1)
4847 d = d->detach();
4848 d->startScenePos = startScenePos;
4849}
4850
4851/*! \internal */
4852void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
4853{
4854 if (d->ref.loadRelaxed() != 1)
4855 d = d->detach();
4856 d->startScreenPos = startScreenPos;
4857}
4858
4859/*! \internal */
4860void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
4861{
4862 if (d->ref.loadRelaxed() != 1)
4863 d = d->detach();
4864 d->startNormalizedPos = startNormalizedPos;
4865}
4866
4867/*! \internal */
4868void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
4869{
4870 if (d->ref.loadRelaxed() != 1)
4871 d = d->detach();
4872 d->lastPos = lastPos;
4873}
4874
4875/*! \internal */
4876void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
4877{
4878 if (d->ref.loadRelaxed() != 1)
4879 d = d->detach();
4880 d->lastScenePos = lastScenePos;
4881}
4882
4883/*! \internal */
4884void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
4885{
4886 if (d->ref.loadRelaxed() != 1)
4887 d = d->detach();
4888 d->lastScreenPos = lastScreenPos;
4889}
4890
4891/*! \internal */
4892void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
4893{
4894 if (d->ref.loadRelaxed() != 1)
4895 d = d->detach();
4896 d->lastNormalizedPos = lastNormalizedPos;
4897}
4898
4899// ### remove the following 3 setRect functions and their usages soon
4900/*! \internal
4901 \obsolete
4902*/
4903void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
4904{
4905 if (d->ref.loadRelaxed() != 1)
4906 d = d->detach();
4907 d->pos = rect.center();
4908 d->ellipseDiameters = rect.size();
4909}
4910
4911/*! \internal
4912 \obsolete
4913*/
4914void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
4915{
4916 if (d->ref.loadRelaxed() != 1)
4917 d = d->detach();
4918 d->scenePos = sceneRect.center();
4919 d->ellipseDiameters = sceneRect.size();
4920}
4921
4922/*! \internal
4923 \obsolete
4924*/
4925void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
4926{
4927 if (d->ref.loadRelaxed() != 1)
4928 d = d->detach();
4929 d->screenPos = screenRect.center();
4930 d->ellipseDiameters = screenRect.size();
4931}
4932
4933/*! \internal */
4934void QTouchEvent::TouchPoint::setPressure(qreal pressure)
4935{
4936 if (d->ref.loadRelaxed() != 1)
4937 d = d->detach();
4938 d->pressure = pressure;
4939}
4940
4941/*! \internal */
4942void QTouchEvent::TouchPoint::setRotation(qreal angle)
4943{
4944 if (d->ref.loadRelaxed() != 1)
4945 d = d->detach();
4946 d->rotation = angle;
4947}
4948
4949/*! \internal */
4950void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
4951{
4952 if (d->ref.loadRelaxed() != 1)
4953 d = d->detach();
4954 d->ellipseDiameters = dia;
4955}
4956
4957/*! \internal */
4958void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
4959{
4960 if (d->ref.loadRelaxed() != 1)
4961 d = d->detach();
4962 d->velocity = v;
4963}
4964
4965/*! \internal */
4966void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &positions)
4967{
4968 if (d->ref.loadRelaxed() != 1)
4969 d = d->detach();
4970 d->rawScreenPositions = positions;
4971}
4972
4973/*!
4974 \internal
4975*/
4976void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
4977{
4978 if (d->ref.loadRelaxed() != 1)
4979 d = d->detach();
4980 d->flags = flags;
4981}
4982
4983/*!
4984 \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
4985 \internal
4986 */
4987
4988/*!
4989 \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(QTouchEvent::TouchPoint &&other)
4990 \internal
4991 */
4992/*!
4993 \fn void QTouchEvent::TouchPoint::swap(TouchPoint &other);
4994 \internal
4995*/
4996
4997/*!
4998 \class QScrollPrepareEvent
4999 \since 4.8
5000 \ingroup events
5001 \inmodule QtGui
5002
5003 \brief The QScrollPrepareEvent class is sent in preparation of scrolling.
5004
5005 The scroll prepare event is sent before scrolling (usually by QScroller) is started.
5006 The object receiving this event should set viewportSize, maxContentPos and contentPos.
5007 It also should accept this event to indicate that scrolling should be started.
5008
5009 It is not guaranteed that a QScrollEvent will be sent after an acceepted
5010 QScrollPrepareEvent, e.g. in a case where the maximum content position is (0,0).
5011
5012 \sa QScrollEvent, QScroller
5013*/
5014
5015/*!
5016 Creates new QScrollPrepareEvent
5017 The \a startPos is the position of a touch or mouse event that started the scrolling.
5018*/
5019QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
5020 : QEvent(QEvent::ScrollPrepare), m_target(0), m_startPos(startPos)
5021{
5022 Q_UNUSED(m_target);
5023}
5024
5025/*!
5026 Destroys QScrollEvent.
5027*/
5028QScrollPrepareEvent::~QScrollPrepareEvent()
5029{
5030}
5031
5032/*!
5033 Returns the position of the touch or mouse event that started the scrolling.
5034*/
5035QPointF QScrollPrepareEvent::startPos() const
5036{
5037 return m_startPos;
5038}
5039
5040/*!
5041 Returns size of the area that is to be scrolled as set by setViewportSize
5042
5043 \sa setViewportSize()
5044*/
5045QSizeF QScrollPrepareEvent::viewportSize() const
5046{
5047 return m_viewportSize;
5048}
5049
5050/*!
5051 Returns the range of coordinates for the content as set by setContentPosRange().
5052*/
5053QRectF QScrollPrepareEvent::contentPosRange() const
5054{
5055 return m_contentPosRange;
5056}
5057
5058/*!
5059 Returns the current position of the content as set by setContentPos.
5060*/
5061QPointF QScrollPrepareEvent::contentPos() const
5062