1 | // Copyright (C) 2016 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 | |
4 | #include "qmouseeventtransition.h" |
5 | #include "qbasicmouseeventtransition_p.h" |
6 | #include "qstatemachine.h" |
7 | |
8 | #include <QtGui/qpainterpath.h> |
9 | #include <private/qeventtransition_p.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | /*! |
14 | \class QMouseEventTransition |
15 | |
16 | \brief The QMouseEventTransition class provides a transition for mouse events. |
17 | |
18 | \since 4.6 |
19 | \ingroup statemachine |
20 | \inmodule QtStateMachine |
21 | |
22 | QMouseEventTransition is part of \l{Qt State Machine Overview}{Qt State Machine Framework}. |
23 | |
24 | \sa QState::addTransition() |
25 | */ |
26 | |
27 | /*! |
28 | \property QMouseEventTransition::button |
29 | |
30 | \brief the button that this mouse event transition is associated with |
31 | */ |
32 | |
33 | /*! |
34 | \property QMouseEventTransition::modifierMask |
35 | |
36 | \brief the keyboard modifier mask that this mouse event transition checks for |
37 | */ |
38 | |
39 | class QMouseEventTransitionPrivate : public QEventTransitionPrivate |
40 | { |
41 | Q_DECLARE_PUBLIC(QMouseEventTransition) |
42 | public: |
43 | QMouseEventTransitionPrivate(); |
44 | |
45 | QBasicMouseEventTransition *transition; |
46 | }; |
47 | |
48 | QMouseEventTransitionPrivate::QMouseEventTransitionPrivate() |
49 | { |
50 | } |
51 | |
52 | /*! |
53 | Constructs a new mouse event transition with the given \a sourceState. |
54 | */ |
55 | QMouseEventTransition::QMouseEventTransition(QState *sourceState) |
56 | : QEventTransition(*new QMouseEventTransitionPrivate, sourceState) |
57 | { |
58 | Q_D(QMouseEventTransition); |
59 | d->transition = new QBasicMouseEventTransition(); |
60 | } |
61 | |
62 | /*! |
63 | Constructs a new mouse event transition for events of the given \a type for |
64 | the given \a object, with the given \a button and \a sourceState. |
65 | */ |
66 | QMouseEventTransition::QMouseEventTransition(QObject *object, QEvent::Type type, |
67 | Qt::MouseButton button, |
68 | QState *sourceState) |
69 | : QEventTransition(*new QMouseEventTransitionPrivate, object, type, sourceState) |
70 | { |
71 | Q_D(QMouseEventTransition); |
72 | d->transition = new QBasicMouseEventTransition(type, button); |
73 | } |
74 | |
75 | /*! |
76 | Destroys this mouse event transition. |
77 | */ |
78 | QMouseEventTransition::~QMouseEventTransition() |
79 | { |
80 | Q_D(QMouseEventTransition); |
81 | delete d->transition; |
82 | } |
83 | |
84 | /*! |
85 | Returns the button that this mouse event transition checks for. |
86 | */ |
87 | Qt::MouseButton QMouseEventTransition::button() const |
88 | { |
89 | Q_D(const QMouseEventTransition); |
90 | return d->transition->button(); |
91 | } |
92 | |
93 | /*! |
94 | Sets the \a button that this mouse event transition will check for. |
95 | */ |
96 | void QMouseEventTransition::setButton(Qt::MouseButton button) |
97 | { |
98 | Q_D(QMouseEventTransition); |
99 | d->transition->setButton(button); |
100 | } |
101 | |
102 | QBindable<Qt::MouseButton> QMouseEventTransition::bindableButton() |
103 | { |
104 | Q_D(QMouseEventTransition); |
105 | return d->transition->bindableButton(); |
106 | } |
107 | |
108 | /*! |
109 | Returns the keyboard modifier mask that this mouse event transition checks |
110 | for. |
111 | */ |
112 | Qt::KeyboardModifiers QMouseEventTransition::modifierMask() const |
113 | { |
114 | Q_D(const QMouseEventTransition); |
115 | return d->transition->modifierMask(); |
116 | } |
117 | |
118 | /*! |
119 | Sets the keyboard modifier mask that this mouse event transition will |
120 | check for to \a modifierMask. |
121 | */ |
122 | void QMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) |
123 | { |
124 | Q_D(QMouseEventTransition); |
125 | d->transition->setModifierMask(modifierMask); |
126 | } |
127 | |
128 | QBindable<Qt::KeyboardModifiers> QMouseEventTransition::bindableModifierMask() |
129 | { |
130 | Q_D(QMouseEventTransition); |
131 | return d->transition->bindableModifierMask(); |
132 | } |
133 | |
134 | |
135 | /*! |
136 | Returns the hit test path for this mouse event transition. |
137 | */ |
138 | QPainterPath QMouseEventTransition::hitTestPath() const |
139 | { |
140 | Q_D(const QMouseEventTransition); |
141 | return d->transition->hitTestPath(); |
142 | } |
143 | |
144 | /*! |
145 | Sets the hit test path for this mouse event transition to \a path. |
146 | If a valid path has been set, the transition will only trigger if the mouse |
147 | event position (QMouseEvent::pos()) is inside the path. |
148 | |
149 | \sa QPainterPath::contains() |
150 | */ |
151 | void QMouseEventTransition::setHitTestPath(const QPainterPath &path) |
152 | { |
153 | Q_D(QMouseEventTransition); |
154 | d->transition->setHitTestPath(path); |
155 | } |
156 | |
157 | /*! |
158 | \reimp |
159 | */ |
160 | bool QMouseEventTransition::eventTest(QEvent *event) |
161 | { |
162 | Q_D(const QMouseEventTransition); |
163 | if (!QEventTransition::eventTest(event)) |
164 | return false; |
165 | QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event); |
166 | d->transition->setEventType(we->event()->type()); |
167 | return QAbstractTransitionPrivate::get(q: d->transition)->callEventTest(e: we->event()); |
168 | } |
169 | |
170 | /*! |
171 | \reimp |
172 | */ |
173 | void QMouseEventTransition::onTransition(QEvent *event) |
174 | { |
175 | QEventTransition::onTransition(event); |
176 | } |
177 | |
178 | QT_END_NAMESPACE |
179 | |
180 | #include "moc_qmouseeventtransition.cpp" |
181 | |