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 "qkeyeventtransition.h"
5#include "qbasickeyeventtransition_p.h"
6#include "qstatemachine.h"
7
8#include <private/qeventtransition_p.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \class QKeyEventTransition
14
15 \brief The QKeyEventTransition class provides a transition for key events.
16
17 \since 4.6
18 \ingroup statemachine
19 \inmodule QtStateMachine
20
21 QKeyEventTransition is part of \l{Qt State Machine Overview}{Qt State Machine Framework}.
22
23 \sa QState::addTransition()
24*/
25
26/*!
27 \property QKeyEventTransition::key
28
29 \brief the key that this key event transition is associated with
30*/
31
32/*!
33 \property QKeyEventTransition::modifierMask
34
35 \brief the keyboard modifier mask that this key event transition checks for
36*/
37
38class QKeyEventTransitionPrivate : public QEventTransitionPrivate
39{
40 Q_DECLARE_PUBLIC(QKeyEventTransition)
41public:
42 QKeyEventTransitionPrivate() {}
43
44 QBasicKeyEventTransition *transition;
45};
46
47/*!
48 Constructs a new key event transition with the given \a sourceState.
49*/
50QKeyEventTransition::QKeyEventTransition(QState *sourceState)
51 : QEventTransition(*new QKeyEventTransitionPrivate, sourceState)
52{
53 Q_D(QKeyEventTransition);
54 d->transition = new QBasicKeyEventTransition();
55}
56
57/*!
58 Constructs a new key event transition for events of the given \a type for
59 the given \a object, with the given \a key and \a sourceState.
60*/
61QKeyEventTransition::QKeyEventTransition(QObject *object, QEvent::Type type,
62 int key, QState *sourceState)
63 : QEventTransition(*new QKeyEventTransitionPrivate, object, type, sourceState)
64{
65 Q_D(QKeyEventTransition);
66 d->transition = new QBasicKeyEventTransition(type, key);
67}
68
69/*!
70 Destroys this key event transition.
71*/
72QKeyEventTransition::~QKeyEventTransition()
73{
74 Q_D(QKeyEventTransition);
75 delete d->transition;
76}
77
78/*!
79 Returns the key that this key event transition checks for.
80*/
81int QKeyEventTransition::key() const
82{
83 Q_D(const QKeyEventTransition);
84 return d->transition->key();
85}
86
87/*!
88 Sets the \a key that this key event transition will check for.
89*/
90void QKeyEventTransition::setKey(int key)
91{
92 Q_D(QKeyEventTransition);
93 d->transition->setKey(key);
94}
95
96QBindable<int> QKeyEventTransition::bindableKey()
97{
98 Q_D(QKeyEventTransition);
99 return d->transition->bindableKey();
100}
101
102/*!
103 Returns the keyboard modifier mask that this key event transition checks
104 for.
105*/
106Qt::KeyboardModifiers QKeyEventTransition::modifierMask() const
107{
108 Q_D(const QKeyEventTransition);
109 return d->transition->modifierMask();
110}
111
112/*!
113 Sets the keyboard modifier mask that this key event transition will
114 check for to \a modifierMask.
115*/
116void QKeyEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask)
117{
118 Q_D(QKeyEventTransition);
119 d->transition->setModifierMask(modifierMask);
120}
121
122QBindable<Qt::KeyboardModifiers> QKeyEventTransition::bindableModifierMask()
123{
124 Q_D(QKeyEventTransition);
125 return d->transition->bindableModifierMask();
126}
127
128/*!
129 \reimp
130*/
131bool QKeyEventTransition::eventTest(QEvent *event)
132{
133 Q_D(const QKeyEventTransition);
134 if (!QEventTransition::eventTest(event))
135 return false;
136 QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event);
137 d->transition->setEventType(we->event()->type());
138 return QAbstractTransitionPrivate::get(q: d->transition)->callEventTest(e: we->event());
139}
140
141/*!
142 \reimp
143*/
144void QKeyEventTransition::onTransition(QEvent *event)
145{
146 QEventTransition::onTransition(event);
147}
148
149QT_END_NAMESPACE
150
151#include "moc_qkeyeventtransition.cpp"
152

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