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