1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QTESTEVENT_H
|
---|
43 | #define QTESTEVENT_H
|
---|
44 |
|
---|
45 | #if 0
|
---|
46 | // inform syncqt
|
---|
47 | #pragma qt_no_master_include
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #include <QtTest/qtest_global.h>
|
---|
51 | #include <QtTest/qtestkeyboard.h>
|
---|
52 | #include <QtTest/qtestmouse.h>
|
---|
53 | #include <QtTest/qtestsystem.h>
|
---|
54 |
|
---|
55 | #include <QtCore/qlist.h>
|
---|
56 |
|
---|
57 | #include <stdlib.h>
|
---|
58 |
|
---|
59 | QT_BEGIN_HEADER
|
---|
60 |
|
---|
61 | QT_BEGIN_NAMESPACE
|
---|
62 |
|
---|
63 | QT_MODULE(Test)
|
---|
64 |
|
---|
65 | class QTestEvent
|
---|
66 | {
|
---|
67 | public:
|
---|
68 | virtual void simulate(QWidget *w) = 0;
|
---|
69 | virtual QTestEvent *clone() const = 0;
|
---|
70 |
|
---|
71 | virtual ~QTestEvent() {}
|
---|
72 | };
|
---|
73 |
|
---|
74 | class QTestKeyEvent: public QTestEvent
|
---|
75 | {
|
---|
76 | public:
|
---|
77 | inline QTestKeyEvent(QTest::KeyAction action, Qt::Key key, Qt::KeyboardModifiers modifiers, int delay)
|
---|
78 | : _action(action), _delay(delay), _modifiers(modifiers), _ascii(0), _key(key) {}
|
---|
79 | inline QTestKeyEvent(QTest::KeyAction action, char ascii, Qt::KeyboardModifiers modifiers, int delay)
|
---|
80 | : _action(action), _delay(delay), _modifiers(modifiers),
|
---|
81 | _ascii(ascii), _key(Qt::Key_unknown) {}
|
---|
82 | inline QTestEvent *clone() const { return new QTestKeyEvent(*this); }
|
---|
83 |
|
---|
84 | inline void simulate(QWidget *w)
|
---|
85 | {
|
---|
86 | if (_ascii == 0)
|
---|
87 | QTest::keyEvent(_action, w, _key, _modifiers, _delay);
|
---|
88 | else
|
---|
89 | QTest::keyEvent(_action, w, _ascii, _modifiers, _delay);
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected:
|
---|
93 | QTest::KeyAction _action;
|
---|
94 | int _delay;
|
---|
95 | Qt::KeyboardModifiers _modifiers;
|
---|
96 | char _ascii;
|
---|
97 | Qt::Key _key;
|
---|
98 | };
|
---|
99 |
|
---|
100 | class QTestKeyClicksEvent: public QTestEvent
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | inline QTestKeyClicksEvent(const QString &keys, Qt::KeyboardModifiers modifiers, int delay)
|
---|
104 | : _keys(keys), _modifiers(modifiers), _delay(delay) {}
|
---|
105 | inline QTestEvent *clone() const { return new QTestKeyClicksEvent(*this); }
|
---|
106 |
|
---|
107 | inline void simulate(QWidget *w)
|
---|
108 | {
|
---|
109 | QTest::keyClicks(w, _keys, _modifiers, _delay);
|
---|
110 | }
|
---|
111 |
|
---|
112 | private:
|
---|
113 | QString _keys;
|
---|
114 | Qt::KeyboardModifiers _modifiers;
|
---|
115 | int _delay;
|
---|
116 | };
|
---|
117 |
|
---|
118 | class QTestMouseEvent: public QTestEvent
|
---|
119 | {
|
---|
120 | public:
|
---|
121 | inline QTestMouseEvent(QTest::MouseAction action, Qt::MouseButton button,
|
---|
122 | Qt::KeyboardModifiers modifiers, QPoint position, int delay)
|
---|
123 | : _action(action), _button(button), _modifiers(modifiers), _pos(position), _delay(delay) {}
|
---|
124 | inline QTestEvent *clone() const { return new QTestMouseEvent(*this); }
|
---|
125 |
|
---|
126 | inline void simulate(QWidget *w)
|
---|
127 | {
|
---|
128 | QTest::mouseEvent(_action, w, _button, _modifiers, _pos, _delay);
|
---|
129 | }
|
---|
130 |
|
---|
131 | private:
|
---|
132 | QTest::MouseAction _action;
|
---|
133 | Qt::MouseButton _button;
|
---|
134 | Qt::KeyboardModifiers _modifiers;
|
---|
135 | QPoint _pos;
|
---|
136 | int _delay;
|
---|
137 | };
|
---|
138 |
|
---|
139 | class QTestDelayEvent: public QTestEvent
|
---|
140 | {
|
---|
141 | public:
|
---|
142 | inline QTestDelayEvent(int msecs): _delay(msecs) {}
|
---|
143 | inline QTestEvent *clone() const { return new QTestDelayEvent(*this); }
|
---|
144 |
|
---|
145 | inline void simulate(QWidget * /*w*/) { QTest::qWait(_delay); }
|
---|
146 |
|
---|
147 | private:
|
---|
148 | int _delay;
|
---|
149 | };
|
---|
150 |
|
---|
151 | class QTestEventList: public QList<QTestEvent *>
|
---|
152 | {
|
---|
153 | public:
|
---|
154 | inline QTestEventList() {}
|
---|
155 | inline QTestEventList(const QTestEventList &other): QList<QTestEvent *>()
|
---|
156 | { for (int i = 0; i < other.count(); ++i) append(other.at(i)->clone()); }
|
---|
157 | inline ~QTestEventList()
|
---|
158 | { clear(); }
|
---|
159 | inline void clear()
|
---|
160 | { qDeleteAll(*this); QList<QTestEvent *>::clear(); }
|
---|
161 |
|
---|
162 | inline void addKeyClick(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
163 | { addKeyEvent(QTest::Click, qtKey, modifiers, msecs); }
|
---|
164 | inline void addKeyPress(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
165 | { addKeyEvent(QTest::Press, qtKey, modifiers, msecs); }
|
---|
166 | inline void addKeyRelease(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
167 | { addKeyEvent(QTest::Release, qtKey, modifiers, msecs); }
|
---|
168 | inline void addKeyEvent(QTest::KeyAction action, Qt::Key qtKey,
|
---|
169 | Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
170 | { append(new QTestKeyEvent(action, qtKey, modifiers, msecs)); }
|
---|
171 |
|
---|
172 | inline void addKeyClick(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
173 | { addKeyEvent(QTest::Click, ascii, modifiers, msecs); }
|
---|
174 | inline void addKeyPress(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
175 | { addKeyEvent(QTest::Press, ascii, modifiers, msecs); }
|
---|
176 | inline void addKeyRelease(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
177 | { addKeyEvent(QTest::Release, ascii, modifiers, msecs); }
|
---|
178 | inline void addKeyClicks(const QString &keys, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
179 | { append(new QTestKeyClicksEvent(keys, modifiers, msecs)); }
|
---|
180 | inline void addKeyEvent(QTest::KeyAction action, char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
|
---|
181 | { append(new QTestKeyEvent(action, ascii, modifiers, msecs)); }
|
---|
182 |
|
---|
183 | inline void addMousePress(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
---|
184 | QPoint pos = QPoint(), int delay=-1)
|
---|
185 | { append(new QTestMouseEvent(QTest::MousePress, button, stateKey, pos, delay)); }
|
---|
186 | inline void addMouseRelease(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
---|
187 | QPoint pos = QPoint(), int delay=-1)
|
---|
188 | { append(new QTestMouseEvent(QTest::MouseRelease, button, stateKey, pos, delay)); }
|
---|
189 | inline void addMouseClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
---|
190 | QPoint pos = QPoint(), int delay=-1)
|
---|
191 | { append(new QTestMouseEvent(QTest::MouseClick, button, stateKey, pos, delay)); }
|
---|
192 | inline void addMouseDClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
---|
193 | QPoint pos = QPoint(), int delay=-1)
|
---|
194 | { append(new QTestMouseEvent(QTest::MouseDClick, button, stateKey, pos, delay)); }
|
---|
195 | inline void addMouseMove(QPoint pos = QPoint(), int delay=-1)
|
---|
196 | { append(new QTestMouseEvent(QTest::MouseMove, Qt::NoButton, 0, pos, delay)); }
|
---|
197 |
|
---|
198 | inline void addDelay(int msecs)
|
---|
199 | { append(new QTestDelayEvent(msecs)); }
|
---|
200 |
|
---|
201 | inline void simulate(QWidget *w)
|
---|
202 | {
|
---|
203 | for (int i = 0; i < count(); ++i)
|
---|
204 | at(i)->simulate(w);
|
---|
205 | }
|
---|
206 | };
|
---|
207 |
|
---|
208 | QT_END_NAMESPACE
|
---|
209 |
|
---|
210 | Q_DECLARE_METATYPE(QTestEventList)
|
---|
211 |
|
---|
212 | QT_END_HEADER
|
---|
213 |
|
---|
214 | #endif
|
---|