Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtTest 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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
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 | #ifdef QT_GUI_LIB |
52 | #include <QtTest/qtestkeyboard.h> |
53 | #include <QtTest/qtestmouse.h> |
54 | #endif |
55 | #include <QtTest/qtestsystem.h> |
56 | |
57 | #include <QtCore/qlist.h> |
58 | |
59 | #include <stdlib.h> |
60 | |
61 | QT_BEGIN_HEADER |
62 | |
63 | QT_BEGIN_NAMESPACE |
64 | |
65 | QT_MODULE(Test) |
66 | |
67 | class QTestEvent |
68 | { |
69 | public: |
70 | virtual void simulate(QWidget *w) = 0; |
71 | virtual QTestEvent *clone() const = 0; |
72 | |
73 | virtual ~QTestEvent() {} |
74 | }; |
75 | |
76 | #ifdef QT_GUI_LIB |
77 | class QTestKeyEvent: public QTestEvent |
78 | { |
79 | public: |
80 | inline QTestKeyEvent(QTest::KeyAction action, Qt::Key key, Qt::KeyboardModifiers modifiers, int delay) |
81 | : _action(action), _delay(delay), _modifiers(modifiers), _ascii(0), _key(key) {} |
82 | inline QTestKeyEvent(QTest::KeyAction action, char ascii, Qt::KeyboardModifiers modifiers, int delay) |
83 | : _action(action), _delay(delay), _modifiers(modifiers), |
84 | _ascii(ascii), _key(Qt::Key_unknown) {} |
85 | inline QTestEvent *clone() const { return new QTestKeyEvent(*this); } |
86 | |
87 | inline void simulate(QWidget *w) |
88 | { |
89 | if (_ascii == 0) |
90 | QTest::keyEvent(_action, w, _key, _modifiers, _delay); |
91 | else |
92 | QTest::keyEvent(_action, w, _ascii, _modifiers, _delay); |
93 | } |
94 | |
95 | protected: |
96 | QTest::KeyAction _action; |
97 | int _delay; |
98 | Qt::KeyboardModifiers _modifiers; |
99 | char _ascii; |
100 | Qt::Key _key; |
101 | }; |
102 | |
103 | class QTestKeyClicksEvent: public QTestEvent |
104 | { |
105 | public: |
106 | inline QTestKeyClicksEvent(const QString &keys, Qt::KeyboardModifiers modifiers, int delay) |
107 | : _keys(keys), _modifiers(modifiers), _delay(delay) {} |
108 | inline QTestEvent *clone() const { return new QTestKeyClicksEvent(*this); } |
109 | |
110 | inline void simulate(QWidget *w) |
111 | { |
112 | QTest::keyClicks(w, _keys, _modifiers, _delay); |
113 | } |
114 | |
115 | private: |
116 | QString _keys; |
117 | Qt::KeyboardModifiers _modifiers; |
118 | int _delay; |
119 | }; |
120 | |
121 | class QTestMouseEvent: public QTestEvent |
122 | { |
123 | public: |
124 | inline QTestMouseEvent(QTest::MouseAction action, Qt::MouseButton button, |
125 | Qt::KeyboardModifiers modifiers, QPoint position, int delay) |
126 | : _action(action), _button(button), _modifiers(modifiers), _pos(position), _delay(delay) {} |
127 | inline QTestEvent *clone() const { return new QTestMouseEvent(*this); } |
128 | |
129 | inline void simulate(QWidget *w) |
130 | { |
131 | QTest::mouseEvent(_action, w, _button, _modifiers, _pos, _delay); |
132 | } |
133 | |
134 | private: |
135 | QTest::MouseAction _action; |
136 | Qt::MouseButton _button; |
137 | Qt::KeyboardModifiers _modifiers; |
138 | QPoint _pos; |
139 | int _delay; |
140 | }; |
141 | #endif //QT_GUI_LIB |
142 | |
143 | |
144 | class QTestDelayEvent: public QTestEvent |
145 | { |
146 | public: |
147 | inline QTestDelayEvent(int msecs): _delay(msecs) {} |
148 | inline QTestEvent *clone() const { return new QTestDelayEvent(*this); } |
149 | |
150 | inline void simulate(QWidget * /*w*/) { QTest::qWait(_delay); } |
151 | |
152 | private: |
153 | int _delay; |
154 | }; |
155 | |
156 | class QTestEventList: public QList<QTestEvent *> |
157 | { |
158 | public: |
159 | inline QTestEventList() {} |
160 | inline QTestEventList(const QTestEventList &other): QList<QTestEvent *>() |
161 | { for (int i = 0; i < other.count(); ++i) append(other.at(i)->clone()); } |
162 | inline ~QTestEventList() |
163 | { clear(); } |
164 | inline void clear() |
165 | { qDeleteAll(*this); QList<QTestEvent *>::clear(); } |
166 | |
167 | #ifdef QT_GUI_LIB |
168 | inline void addKeyClick(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
169 | { addKeyEvent(QTest::Click, qtKey, modifiers, msecs); } |
170 | inline void addKeyPress(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
171 | { addKeyEvent(QTest::Press, qtKey, modifiers, msecs); } |
172 | inline void addKeyRelease(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
173 | { addKeyEvent(QTest::Release, qtKey, modifiers, msecs); } |
174 | inline void addKeyEvent(QTest::KeyAction action, Qt::Key qtKey, |
175 | Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
176 | { append(new QTestKeyEvent(action, qtKey, modifiers, msecs)); } |
177 | |
178 | inline void addKeyClick(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
179 | { addKeyEvent(QTest::Click, ascii, modifiers, msecs); } |
180 | inline void addKeyPress(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
181 | { addKeyEvent(QTest::Press, ascii, modifiers, msecs); } |
182 | inline void addKeyRelease(char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
183 | { addKeyEvent(QTest::Release, ascii, modifiers, msecs); } |
184 | inline void addKeyClicks(const QString &keys, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
185 | { append(new QTestKeyClicksEvent(keys, modifiers, msecs)); } |
186 | inline void addKeyEvent(QTest::KeyAction action, char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1) |
187 | { append(new QTestKeyEvent(action, ascii, modifiers, msecs)); } |
188 | |
189 | inline void addMousePress(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, |
190 | QPoint pos = QPoint(), int delay=-1) |
191 | { append(new QTestMouseEvent(QTest::MousePress, button, stateKey, pos, delay)); } |
192 | inline void addMouseRelease(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, |
193 | QPoint pos = QPoint(), int delay=-1) |
194 | { append(new QTestMouseEvent(QTest::MouseRelease, button, stateKey, pos, delay)); } |
195 | inline void addMouseClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, |
196 | QPoint pos = QPoint(), int delay=-1) |
197 | { append(new QTestMouseEvent(QTest::MouseClick, button, stateKey, pos, delay)); } |
198 | inline void addMouseDClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, |
199 | QPoint pos = QPoint(), int delay=-1) |
200 | { append(new QTestMouseEvent(QTest::MouseDClick, button, stateKey, pos, delay)); } |
201 | inline void addMouseMove(QPoint pos = QPoint(), int delay=-1) |
202 | { append(new QTestMouseEvent(QTest::MouseMove, Qt::NoButton, 0, pos, delay)); } |
203 | #endif //QT_GUI_LIB |
204 | |
205 | inline void addDelay(int msecs) |
206 | { append(new QTestDelayEvent(msecs)); } |
207 | |
208 | inline void simulate(QWidget *w) |
209 | { |
210 | for (int i = 0; i < count(); ++i) |
211 | at(i)->simulate(w); |
212 | } |
213 | }; |
214 | |
215 | QT_END_NAMESPACE |
216 | |
217 | Q_DECLARE_METATYPE(QTestEventList) |
218 | |
219 | QT_END_HEADER |
220 | |
221 | #endif |
222 |
Warning: That file was not part of the compilation database. It may have many parsing errors.