1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qmouseeventtransition.h"
41#include "qbasicmouseeventtransition_p.h"
42#include <QtCore/qstatemachine.h>
43#include <QtGui/qpainterpath.h>
44#include <private/qeventtransition_p.h>
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \class QMouseEventTransition
50
51 \brief The QMouseEventTransition class provides a transition for mouse events.
52
53 \since 4.6
54 \ingroup statemachine
55 \inmodule QtWidgets
56
57 QMouseEventTransition is part of \l{The State Machine Framework}.
58
59 \sa QState::addTransition()
60*/
61
62/*!
63 \property QMouseEventTransition::button
64
65 \brief the button that this mouse event transition is associated with
66*/
67
68/*!
69 \property QMouseEventTransition::modifierMask
70
71 \brief the keyboard modifier mask that this mouse event transition checks for
72*/
73
74class QMouseEventTransitionPrivate : public QEventTransitionPrivate
75{
76 Q_DECLARE_PUBLIC(QMouseEventTransition)
77public:
78 QMouseEventTransitionPrivate();
79
80 QBasicMouseEventTransition *transition;
81};
82
83QMouseEventTransitionPrivate::QMouseEventTransitionPrivate()
84{
85}
86
87/*!
88 Constructs a new mouse event transition with the given \a sourceState.
89*/
90QMouseEventTransition::QMouseEventTransition(QState *sourceState)
91 : QEventTransition(*new QMouseEventTransitionPrivate, sourceState)
92{
93 Q_D(QMouseEventTransition);
94 d->transition = new QBasicMouseEventTransition();
95}
96
97/*!
98 Constructs a new mouse event transition for events of the given \a type for
99 the given \a object, with the given \a button and \a sourceState.
100*/
101QMouseEventTransition::QMouseEventTransition(QObject *object, QEvent::Type type,
102 Qt::MouseButton button,
103 QState *sourceState)
104 : QEventTransition(*new QMouseEventTransitionPrivate, object, type, sourceState)
105{
106 Q_D(QMouseEventTransition);
107 d->transition = new QBasicMouseEventTransition(type, button);
108}
109
110/*!
111 Destroys this mouse event transition.
112*/
113QMouseEventTransition::~QMouseEventTransition()
114{
115 Q_D(QMouseEventTransition);
116 delete d->transition;
117}
118
119/*!
120 Returns the button that this mouse event transition checks for.
121*/
122Qt::MouseButton QMouseEventTransition::button() const
123{
124 Q_D(const QMouseEventTransition);
125 return d->transition->button();
126}
127
128/*!
129 Sets the \a button that this mouse event transition will check for.
130*/
131void QMouseEventTransition::setButton(Qt::MouseButton button)
132{
133 Q_D(QMouseEventTransition);
134 d->transition->setButton(button);
135}
136
137/*!
138 Returns the keyboard modifier mask that this mouse event transition checks
139 for.
140*/
141Qt::KeyboardModifiers QMouseEventTransition::modifierMask() const
142{
143 Q_D(const QMouseEventTransition);
144 return d->transition->modifierMask();
145}
146
147/*!
148 Sets the keyboard modifier mask that this mouse event transition will
149 check for to \a modifierMask.
150*/
151void QMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask)
152{
153 Q_D(QMouseEventTransition);
154 d->transition->setModifierMask(modifierMask);
155}
156
157/*!
158 Returns the hit test path for this mouse event transition.
159*/
160QPainterPath QMouseEventTransition::hitTestPath() const
161{
162 Q_D(const QMouseEventTransition);
163 return d->transition->hitTestPath();
164}
165
166/*!
167 Sets the hit test path for this mouse event transition to \a path.
168 If a valid path has been set, the transition will only trigger if the mouse
169 event position (QMouseEvent::pos()) is inside the path.
170
171 \sa QPainterPath::contains()
172*/
173void QMouseEventTransition::setHitTestPath(const QPainterPath &path)
174{
175 Q_D(QMouseEventTransition);
176 d->transition->setHitTestPath(path);
177}
178
179/*!
180 \reimp
181*/
182bool QMouseEventTransition::eventTest(QEvent *event)
183{
184 Q_D(const QMouseEventTransition);
185 if (!QEventTransition::eventTest(event))
186 return false;
187 QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event);
188 d->transition->setEventType(we->event()->type());
189 return QAbstractTransitionPrivate::get(q: d->transition)->callEventTest(e: we->event());
190}
191
192/*!
193 \reimp
194*/
195void QMouseEventTransition::onTransition(QEvent *event)
196{
197 QEventTransition::onTransition(event);
198}
199
200QT_END_NAMESPACE
201
202#include "moc_qmouseeventtransition.cpp"
203

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