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

source code of qtscxml/src/statemachine/gui/qbasickeyeventtransition.cpp