|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qmouseeventtransition.h" |
|
43 |
|
44 #ifndef QT_NO_STATEMACHINE |
|
45 |
|
46 #include "qbasicmouseeventtransition_p.h" |
|
47 #include <QtCore/qstatemachine.h> |
|
48 #include <QtGui/qpainterpath.h> |
|
49 #include <private/qeventtransition_p.h> |
|
50 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 /*! |
|
54 \class QMouseEventTransition |
|
55 |
|
56 \brief The QMouseEventTransition class provides a transition for mouse events. |
|
57 |
|
58 \since 4.6 |
|
59 \ingroup statemachine |
|
60 |
|
61 QMouseEventTransition is part of \l{The State Machine Framework}. |
|
62 |
|
63 \sa QState::addTransition() |
|
64 */ |
|
65 |
|
66 /*! |
|
67 \property QMouseEventTransition::button |
|
68 |
|
69 \brief the button that this mouse event transition is associated with |
|
70 */ |
|
71 |
|
72 /*! |
|
73 \property QMouseEventTransition::modifiersMask |
|
74 |
|
75 \brief the keyboard modifiers mask that this mouse event transition checks for |
|
76 */ |
|
77 |
|
78 class QMouseEventTransitionPrivate : public QEventTransitionPrivate |
|
79 { |
|
80 Q_DECLARE_PUBLIC(QMouseEventTransition) |
|
81 public: |
|
82 QMouseEventTransitionPrivate(); |
|
83 |
|
84 QBasicMouseEventTransition *transition; |
|
85 }; |
|
86 |
|
87 QMouseEventTransitionPrivate::QMouseEventTransitionPrivate() |
|
88 { |
|
89 } |
|
90 |
|
91 /*! |
|
92 Constructs a new mouse event transition with the given \a sourceState. |
|
93 */ |
|
94 QMouseEventTransition::QMouseEventTransition(QState *sourceState) |
|
95 : QEventTransition(*new QMouseEventTransitionPrivate, sourceState) |
|
96 { |
|
97 Q_D(QMouseEventTransition); |
|
98 d->transition = new QBasicMouseEventTransition(); |
|
99 } |
|
100 |
|
101 /*! |
|
102 Constructs a new mouse event transition for events of the given \a type for |
|
103 the given \a object, with the given \a button and \a sourceState. |
|
104 */ |
|
105 QMouseEventTransition::QMouseEventTransition(QObject *object, QEvent::Type type, |
|
106 Qt::MouseButton button, |
|
107 QState *sourceState) |
|
108 : QEventTransition(*new QMouseEventTransitionPrivate, object, type, sourceState) |
|
109 { |
|
110 Q_D(QMouseEventTransition); |
|
111 d->transition = new QBasicMouseEventTransition(type, button); |
|
112 } |
|
113 |
|
114 /*! |
|
115 Destroys this mouse event transition. |
|
116 */ |
|
117 QMouseEventTransition::~QMouseEventTransition() |
|
118 { |
|
119 Q_D(QMouseEventTransition); |
|
120 delete d->transition; |
|
121 } |
|
122 |
|
123 /*! |
|
124 Returns the button that this mouse event transition checks for. |
|
125 */ |
|
126 Qt::MouseButton QMouseEventTransition::button() const |
|
127 { |
|
128 Q_D(const QMouseEventTransition); |
|
129 return d->transition->button(); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Sets the \a button that this mouse event transition will check for. |
|
134 */ |
|
135 void QMouseEventTransition::setButton(Qt::MouseButton button) |
|
136 { |
|
137 Q_D(QMouseEventTransition); |
|
138 d->transition->setButton(button); |
|
139 } |
|
140 |
|
141 /*! |
|
142 Returns the keyboard modifiers mask that this mouse event transition checks |
|
143 for. |
|
144 */ |
|
145 Qt::KeyboardModifiers QMouseEventTransition::modifiersMask() const |
|
146 { |
|
147 Q_D(const QMouseEventTransition); |
|
148 return d->transition->modifiersMask(); |
|
149 } |
|
150 |
|
151 /*! |
|
152 Sets the keyboard \a modifiers mask that this mouse event transition will |
|
153 check for. |
|
154 */ |
|
155 void QMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) |
|
156 { |
|
157 Q_D(QMouseEventTransition); |
|
158 d->transition->setModifiersMask(modifiersMask); |
|
159 } |
|
160 |
|
161 /*! |
|
162 Returns the path for this mouse event transition. |
|
163 */ |
|
164 QPainterPath QMouseEventTransition::path() const |
|
165 { |
|
166 Q_D(const QMouseEventTransition); |
|
167 return d->transition->path(); |
|
168 } |
|
169 |
|
170 /*! |
|
171 Sets the \a path for this mouse event transition. |
|
172 If a valid path has been set, the transition will only trigger if the mouse |
|
173 event position (QMouseEvent::pos()) is inside the path. |
|
174 |
|
175 \sa QPainterPath::contains() |
|
176 */ |
|
177 void QMouseEventTransition::setPath(const QPainterPath &path) |
|
178 { |
|
179 Q_D(QMouseEventTransition); |
|
180 d->transition->setPath(path); |
|
181 } |
|
182 |
|
183 /*! |
|
184 \reimp |
|
185 */ |
|
186 bool QMouseEventTransition::eventTest(QEvent *event) |
|
187 { |
|
188 Q_D(const QMouseEventTransition); |
|
189 if (!QEventTransition::eventTest(event)) |
|
190 return false; |
|
191 QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event); |
|
192 d->transition->setEventType(we->event()->type()); |
|
193 return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event()); |
|
194 } |
|
195 |
|
196 /*! |
|
197 \reimp |
|
198 */ |
|
199 void QMouseEventTransition::onTransition(QEvent *event) |
|
200 { |
|
201 QEventTransition::onTransition(event); |
|
202 } |
|
203 |
|
204 QT_END_NAMESPACE |
|
205 |
|
206 #endif //QT_NO_STATEMACHINE |