Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qevent_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QEVENT_P_H
6#define QEVENT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <QtCore/qurl.h>
21#include <QtGui/qevent.h>
22#include <QtGui/qwindow.h>
23
25
26class QPointingDevice;
27
28/*!
29 \internal
30 \since 6.9
31
32 This class provides a way to store copies of QEvents. QEvents can otherwise
33 only be copied by \l{QEvent::clone()}{cloning}, which allocates the copy on
34 the heap. By befriending concrete QEvent subclasses, QEventStorage gains
35 access to their protected copy constructors.
36
37 It is similar to std::optional, but with a more targeted API.
38
39 Note that by storing an event in QEventStorage, it may be sliced.
40*/
41template <typename Event>
42class QEventStorage
43{
44 Q_DISABLE_COPY_MOVE(QEventStorage)
45 static_assert(std::is_base_of_v<QEvent, Event>);
46 union {
47 char m_eventNotSet; // could be std::monostate, but don't want to pay for <variant> include
48 Event m_event;
49 };
50 bool m_engaged = false;
51
52 void engage(const Event &e)
53 {
54 Q_ASSERT(!m_engaged);
55 new (&m_event) Event(e);
56 m_engaged = true;
57 }
58
59 void disengage()
60 {
61 Q_ASSERT(m_engaged);
62 m_event.~Event();
63 m_engaged = false;
64 }
65
66public:
67 QEventStorage() noexcept : m_eventNotSet{} {}
68 explicit QEventStorage(const Event &e)
69 {
70 engage(e);
71 }
72
74 {
75 if (m_engaged)
76 disengage();
77 }
78
79 explicit operator bool() const noexcept { return m_engaged; }
80 bool operator!() const noexcept { return !m_engaged; }
81
82 Event &store(const Event &e)
83 {
84 if (m_engaged)
85 disengage();
86 engage(e);
87 return m_event;
88 }
89
90 Event &storeUnlessAlias(const Event &e)
91 {
92 if (m_engaged && &e == &m_event)
93 return m_event;
94 return store(e);
95 }
96
97 const Event &operator*() const
98 {
99 Q_PRE(m_engaged);
100 return m_event;
101 }
102
103 Event &operator*()
104 {
105 Q_PRE(m_engaged);
106 return m_event;
107 }
108
109 const Event *operator->() const
110 {
111 Q_PRE(m_engaged);
112 return &m_event;
113 }
114
115 Event *operator->()
116 {
117 Q_PRE(m_engaged);
118 return &m_event;
119 }
120};
121
122class Q_GUI_EXPORT QMutableTouchEvent : public QTouchEvent
123{
124public:
125 QMutableTouchEvent(QEvent::Type eventType = QEvent::TouchBegin,
126 const QPointingDevice *device = nullptr,
127 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
128 const QList<QEventPoint> &touchPoints = QList<QEventPoint>()) :
129 QTouchEvent(eventType, device, modifiers, touchPoints) { }
130 ~QMutableTouchEvent() override;
131
132 void setTarget(QObject *target) { m_target = target; }
133 void addPoint(const QEventPoint &point);
134
135 static void setTarget(QTouchEvent *e, QObject *target) { e->m_target = target; }
136 static void addPoint(QTouchEvent *e, const QEventPoint &point);
137};
138
139class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent
140{
141public:
142 QMutableSinglePointEvent(const QSinglePointEvent &other) : QSinglePointEvent(other) {}
143 QMutableSinglePointEvent(Type type = QEvent::None, const QPointingDevice *device = nullptr, const QEventPoint &point = QEventPoint(),
144 Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton,
145 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
146 Qt::MouseEventSource source = Qt::MouseEventSynthesizedByQt) :
147 QSinglePointEvent(type, device, point, button, buttons, modifiers, source) { }
148 ~QMutableSinglePointEvent() override;
149
150 void setSource(Qt::MouseEventSource s) { m_source = s; }
151
152 bool isDoubleClick() { return m_doubleClick; }
153
154 void setDoubleClick(bool d = true) { m_doubleClick = d; }
155
156 static bool isDoubleClick(const QSinglePointEvent *ev)
157 {
158 return ev->m_doubleClick;
159 }
160
161 static void setDoubleClick(QSinglePointEvent *ev, bool d)
162 {
163 ev->m_doubleClick = d;
164 }
165};
166
167QT_END_NAMESPACE
168
169#endif // QEVENT_P_H
\inmodule QtGui
Definition qevent.h:1042
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:566
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:598
QEventStorage() noexcept
Definition qevent_p.h:67
bool operator!() const noexcept
Definition qevent_p.h:80
Event & operator*()
Definition qevent_p.h:103
Event & storeUnlessAlias(const Event &e)
Definition qevent_p.h:90
char m_eventNotSet
Definition qevent_p.h:47
const Event * operator->() const
Definition qevent_p.h:109
Event & store(const Event &e)
Definition qevent_p.h:82
operator bool() const noexcept
Definition qevent_p.h:79
QEventStorage(const Event &e)
Definition qevent_p.h:68
Event m_event
Definition qevent_p.h:48
Event * operator->()
Definition qevent_p.h:115
const Event & operator*() const
Definition qevent_p.h:97
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:518
The QFileOpenEvent class provides an event that will be sent when there is a request to open a file o...
Definition qevent.h:863
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:472
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:803
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:590
The QIconDragEvent class indicates that a main icon drag has begun.
Definition qevent.h:574
\inmodule QtGui
Definition qevent.h:50
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:629
The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
Definition qevent.h:684
The QKeyEvent class describes a key event.
Definition qevent.h:426
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:504
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:488
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition qevent.h:534
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:551
The QScrollEvent class is sent when scrolling.
Definition qevent.h:993
The QScrollPrepareEvent class is sent in preparation of scrolling.
Definition qevent.h:969
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:582
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:110
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
Definition qevent.h:823
The QToolBarChangeEvent class provides an event that is sent whenever a the toolbar button is clicked...
Definition qevent.h:882
\inmodule QtGui
Definition qevent.h:914
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const NSObject *nsObject)
Definition qcore_mac.mm:207
static void formatInputMethodQueryEvent(QDebug d, const QInputMethodQueryEvent *e)
Definition qevent.cpp:3990
static void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
Definition qevent.cpp:3961
#define Q_IMPL_POINTER_EVENT(Class)
Definition qevent.cpp:35
static void formatUnicodeString(QDebug d, const QString &s)
Definition qevent.cpp:3943
static const char * eventClassName(QEvent::Type t)
Definition qevent.cpp:4016
static QDebug operator<<(QDebug dbg, const QInputMethodEvent::Attribute &attr)
Definition qevent.cpp:3954
static void formatTouchEvent(QDebug d, const QTouchEvent &t)
Definition qevent.cpp:3933
QDebug operator<<(QDebug dbg, const QFileInfo &fi)