1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia 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 | #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)
|
---|
|
---|