| 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 "qbasicmouseeventtransition_p.h" |
| 41 | #include <QtGui/qevent.h> |
| 42 | #include <QtGui/qpainterpath.h> |
| 43 | #include <qdebug.h> |
| 44 | #include <private/qabstracttransition_p.h> |
| 45 | |
| 46 | QT_BEGIN_NAMESPACE |
| 47 | |
| 48 | /*! |
| 49 | \internal |
| 50 | \class QBasicMouseEventTransition |
| 51 | \since 4.6 |
| 52 | \ingroup statemachine |
| 53 | |
| 54 | \brief The QBasicMouseEventTransition class provides a transition for Qt mouse events. |
| 55 | */ |
| 56 | |
| 57 | class QBasicMouseEventTransitionPrivate : public QAbstractTransitionPrivate |
| 58 | { |
| 59 | Q_DECLARE_PUBLIC(QBasicMouseEventTransition) |
| 60 | public: |
| 61 | QBasicMouseEventTransitionPrivate(); |
| 62 | |
| 63 | static QBasicMouseEventTransitionPrivate *get(QBasicMouseEventTransition *q); |
| 64 | |
| 65 | QEvent::Type eventType; |
| 66 | Qt::MouseButton button; |
| 67 | Qt::KeyboardModifiers modifierMask; |
| 68 | QPainterPath path; |
| 69 | }; |
| 70 | |
| 71 | QBasicMouseEventTransitionPrivate::QBasicMouseEventTransitionPrivate() |
| 72 | { |
| 73 | eventType = QEvent::None; |
| 74 | button = Qt::NoButton; |
| 75 | } |
| 76 | |
| 77 | QBasicMouseEventTransitionPrivate *QBasicMouseEventTransitionPrivate::get(QBasicMouseEventTransition *q) |
| 78 | { |
| 79 | return q->d_func(); |
| 80 | } |
| 81 | |
| 82 | /*! |
| 83 | Constructs a new mouse event transition with the given \a sourceState. |
| 84 | */ |
| 85 | QBasicMouseEventTransition::QBasicMouseEventTransition(QState *sourceState) |
| 86 | : QAbstractTransition(*new QBasicMouseEventTransitionPrivate, sourceState) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | /*! |
| 91 | Constructs a new mouse event transition for events of the given \a type. |
| 92 | */ |
| 93 | QBasicMouseEventTransition::QBasicMouseEventTransition(QEvent::Type type, |
| 94 | Qt::MouseButton button, |
| 95 | QState *sourceState) |
| 96 | : QAbstractTransition(*new QBasicMouseEventTransitionPrivate, sourceState) |
| 97 | { |
| 98 | Q_D(QBasicMouseEventTransition); |
| 99 | d->eventType = type; |
| 100 | d->button = button; |
| 101 | } |
| 102 | |
| 103 | /*! |
| 104 | Destroys this mouse event transition. |
| 105 | */ |
| 106 | QBasicMouseEventTransition::~QBasicMouseEventTransition() |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | Returns the event type that this mouse event transition is associated with. |
| 112 | */ |
| 113 | QEvent::Type QBasicMouseEventTransition::eventType() const |
| 114 | { |
| 115 | Q_D(const QBasicMouseEventTransition); |
| 116 | return d->eventType; |
| 117 | } |
| 118 | |
| 119 | /*! |
| 120 | Sets the event \a type that this mouse event transition is associated with. |
| 121 | */ |
| 122 | void QBasicMouseEventTransition::setEventType(QEvent::Type type) |
| 123 | { |
| 124 | Q_D(QBasicMouseEventTransition); |
| 125 | d->eventType = type; |
| 126 | } |
| 127 | |
| 128 | /*! |
| 129 | Returns the button that this mouse event transition checks for. |
| 130 | */ |
| 131 | Qt::MouseButton QBasicMouseEventTransition::button() const |
| 132 | { |
| 133 | Q_D(const QBasicMouseEventTransition); |
| 134 | return d->button; |
| 135 | } |
| 136 | |
| 137 | /*! |
| 138 | Sets the button that this mouse event transition will check for. |
| 139 | */ |
| 140 | void QBasicMouseEventTransition::setButton(Qt::MouseButton button) |
| 141 | { |
| 142 | Q_D(QBasicMouseEventTransition); |
| 143 | d->button = button; |
| 144 | } |
| 145 | |
| 146 | /*! |
| 147 | Returns the keyboard modifier mask that this mouse event transition checks |
| 148 | for. |
| 149 | */ |
| 150 | Qt::KeyboardModifiers QBasicMouseEventTransition::modifierMask() const |
| 151 | { |
| 152 | Q_D(const QBasicMouseEventTransition); |
| 153 | return d->modifierMask; |
| 154 | } |
| 155 | |
| 156 | /*! |
| 157 | Sets the keyboard modifier mask that this mouse event transition will check |
| 158 | for. |
| 159 | */ |
| 160 | void QBasicMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) |
| 161 | { |
| 162 | Q_D(QBasicMouseEventTransition); |
| 163 | d->modifierMask = modifierMask; |
| 164 | } |
| 165 | |
| 166 | /*! |
| 167 | Returns the hit test path for this mouse event transition. |
| 168 | */ |
| 169 | QPainterPath QBasicMouseEventTransition::hitTestPath() const |
| 170 | { |
| 171 | Q_D(const QBasicMouseEventTransition); |
| 172 | return d->path; |
| 173 | } |
| 174 | |
| 175 | /*! |
| 176 | Sets the hit test path for this mouse event transition. |
| 177 | */ |
| 178 | void QBasicMouseEventTransition::setHitTestPath(const QPainterPath &path) |
| 179 | { |
| 180 | Q_D(QBasicMouseEventTransition); |
| 181 | d->path = path; |
| 182 | } |
| 183 | |
| 184 | /*! |
| 185 | \reimp |
| 186 | */ |
| 187 | bool QBasicMouseEventTransition::eventTest(QEvent *event) |
| 188 | { |
| 189 | Q_D(const QBasicMouseEventTransition); |
| 190 | if (event->type() == d->eventType) { |
| 191 | QMouseEvent *me = static_cast<QMouseEvent*>(event); |
| 192 | return (me->button() == d->button) |
| 193 | && ((me->modifiers() & d->modifierMask) == d->modifierMask) |
| 194 | && (d->path.isEmpty() || d->path.contains(pt: me->pos())); |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | /*! |
| 200 | \reimp |
| 201 | */ |
| 202 | void QBasicMouseEventTransition::onTransition(QEvent *) |
| 203 | { |
| 204 | } |
| 205 | |
| 206 | QT_END_NAMESPACE |
| 207 | |
| 208 | #include "moc_qbasicmouseeventtransition_p.cpp" |
| 209 |
