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

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