1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the tools applications 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 qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVETESTER_H
|
---|
43 | #define QDECLARATIVETESTER_H
|
---|
44 |
|
---|
45 | #include <QEvent>
|
---|
46 | #include <QMouseEvent>
|
---|
47 | #include <QKeyEvent>
|
---|
48 | #include <QImage>
|
---|
49 | #include <QUrl>
|
---|
50 | #include <qmlruntime.h>
|
---|
51 | #include <qdeclarativelist.h>
|
---|
52 | #include <qdeclarative.h>
|
---|
53 | #include <QAbstractAnimation>
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | class QDeclarativeVisualTest : public QObject
|
---|
58 | {
|
---|
59 | Q_OBJECT
|
---|
60 | Q_PROPERTY(QDeclarativeListProperty<QObject> events READ events CONSTANT)
|
---|
61 | Q_CLASSINFO("DefaultProperty", "events")
|
---|
62 | public:
|
---|
63 | QDeclarativeVisualTest() {}
|
---|
64 |
|
---|
65 | QDeclarativeListProperty<QObject> events() { return QDeclarativeListProperty<QObject>(this, m_events); }
|
---|
66 |
|
---|
67 | int count() const { return m_events.count(); }
|
---|
68 | QObject *event(int idx) { return m_events.at(idx); }
|
---|
69 |
|
---|
70 | private:
|
---|
71 | QList<QObject *> m_events;
|
---|
72 | };
|
---|
73 |
|
---|
74 | QT_END_NAMESPACE
|
---|
75 |
|
---|
76 | QML_DECLARE_TYPE(QDeclarativeVisualTest)
|
---|
77 |
|
---|
78 | QT_BEGIN_NAMESPACE
|
---|
79 |
|
---|
80 | class QDeclarativeVisualTestFrame : public QObject
|
---|
81 | {
|
---|
82 | Q_OBJECT
|
---|
83 | Q_PROPERTY(int msec READ msec WRITE setMsec)
|
---|
84 | Q_PROPERTY(QString hash READ hash WRITE setHash)
|
---|
85 | Q_PROPERTY(QUrl image READ image WRITE setImage)
|
---|
86 | public:
|
---|
87 | QDeclarativeVisualTestFrame() : m_msec(-1) {}
|
---|
88 |
|
---|
89 | int msec() const { return m_msec; }
|
---|
90 | void setMsec(int m) { m_msec = m; }
|
---|
91 |
|
---|
92 | QString hash() const { return m_hash; }
|
---|
93 | void setHash(const QString &hash) { m_hash = hash; }
|
---|
94 |
|
---|
95 | QUrl image() const { return m_image; }
|
---|
96 | void setImage(const QUrl &image) { m_image = image; }
|
---|
97 |
|
---|
98 | private:
|
---|
99 | int m_msec;
|
---|
100 | QString m_hash;
|
---|
101 | QUrl m_image;
|
---|
102 | };
|
---|
103 |
|
---|
104 | QT_END_NAMESPACE
|
---|
105 |
|
---|
106 | QML_DECLARE_TYPE(QDeclarativeVisualTestFrame)
|
---|
107 |
|
---|
108 | QT_BEGIN_NAMESPACE
|
---|
109 |
|
---|
110 | class QDeclarativeVisualTestMouse : public QObject
|
---|
111 | {
|
---|
112 | Q_OBJECT
|
---|
113 | Q_PROPERTY(int type READ type WRITE setType)
|
---|
114 | Q_PROPERTY(int button READ button WRITE setButton)
|
---|
115 | Q_PROPERTY(int buttons READ buttons WRITE setButtons)
|
---|
116 | Q_PROPERTY(int x READ x WRITE setX)
|
---|
117 | Q_PROPERTY(int y READ y WRITE setY)
|
---|
118 | Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers)
|
---|
119 | Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport)
|
---|
120 | public:
|
---|
121 | QDeclarativeVisualTestMouse() : m_type(0), m_button(0), m_buttons(0), m_x(0), m_y(0), m_modifiers(0), m_viewport(false) {}
|
---|
122 |
|
---|
123 | int type() const { return m_type; }
|
---|
124 | void setType(int t) { m_type = t; }
|
---|
125 |
|
---|
126 | int button() const { return m_button; }
|
---|
127 | void setButton(int b) { m_button = b; }
|
---|
128 |
|
---|
129 | int buttons() const { return m_buttons; }
|
---|
130 | void setButtons(int b) { m_buttons = b; }
|
---|
131 |
|
---|
132 | int x() const { return m_x; }
|
---|
133 | void setX(int x) { m_x = x; }
|
---|
134 |
|
---|
135 | int y() const { return m_y; }
|
---|
136 | void setY(int y) { m_y = y; }
|
---|
137 |
|
---|
138 | int modifiers() const { return m_modifiers; }
|
---|
139 | void setModifiers(int modifiers) { m_modifiers = modifiers; }
|
---|
140 |
|
---|
141 | bool sendToViewport() const { return m_viewport; }
|
---|
142 | void setSendToViewport(bool v) { m_viewport = v; }
|
---|
143 | private:
|
---|
144 | int m_type;
|
---|
145 | int m_button;
|
---|
146 | int m_buttons;
|
---|
147 | int m_x;
|
---|
148 | int m_y;
|
---|
149 | int m_modifiers;
|
---|
150 | bool m_viewport;
|
---|
151 | };
|
---|
152 |
|
---|
153 | QT_END_NAMESPACE
|
---|
154 |
|
---|
155 | QML_DECLARE_TYPE(QDeclarativeVisualTestMouse)
|
---|
156 |
|
---|
157 | QT_BEGIN_NAMESPACE
|
---|
158 |
|
---|
159 | class QDeclarativeVisualTestKey : public QObject
|
---|
160 | {
|
---|
161 | Q_OBJECT
|
---|
162 | Q_PROPERTY(int type READ type WRITE setType)
|
---|
163 | Q_PROPERTY(int key READ key WRITE setKey)
|
---|
164 | Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers)
|
---|
165 | Q_PROPERTY(QString text READ text WRITE setText)
|
---|
166 | Q_PROPERTY(bool autorep READ autorep WRITE setAutorep)
|
---|
167 | Q_PROPERTY(int count READ count WRITE setCount)
|
---|
168 | Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport)
|
---|
169 | public:
|
---|
170 | QDeclarativeVisualTestKey() : m_type(0), m_key(0), m_modifiers(0), m_autorep(false), m_count(0), m_viewport(false) {}
|
---|
171 |
|
---|
172 | int type() const { return m_type; }
|
---|
173 | void setType(int t) { m_type = t; }
|
---|
174 |
|
---|
175 | int key() const { return m_key; }
|
---|
176 | void setKey(int k) { m_key = k; }
|
---|
177 |
|
---|
178 | int modifiers() const { return m_modifiers; }
|
---|
179 | void setModifiers(int m) { m_modifiers = m; }
|
---|
180 |
|
---|
181 | QString text() const { return m_text; }
|
---|
182 | void setText(const QString &t) { m_text = t; }
|
---|
183 |
|
---|
184 | bool autorep() const { return m_autorep; }
|
---|
185 | void setAutorep(bool a) { m_autorep = a; }
|
---|
186 |
|
---|
187 | int count() const { return m_count; }
|
---|
188 | void setCount(int c) { m_count = c; }
|
---|
189 |
|
---|
190 | bool sendToViewport() const { return m_viewport; }
|
---|
191 | void setSendToViewport(bool v) { m_viewport = v; }
|
---|
192 | private:
|
---|
193 | int m_type;
|
---|
194 | int m_key;
|
---|
195 | int m_modifiers;
|
---|
196 | QString m_text;
|
---|
197 | bool m_autorep;
|
---|
198 | int m_count;
|
---|
199 | bool m_viewport;
|
---|
200 | };
|
---|
201 |
|
---|
202 | QT_END_NAMESPACE
|
---|
203 |
|
---|
204 | QML_DECLARE_TYPE(QDeclarativeVisualTestKey)
|
---|
205 |
|
---|
206 | QT_BEGIN_NAMESPACE
|
---|
207 |
|
---|
208 | class QDeclarativeTester : public QAbstractAnimation
|
---|
209 | {
|
---|
210 | public:
|
---|
211 | QDeclarativeTester(const QString &script, QDeclarativeViewer::ScriptOptions options, QDeclarativeView *parent);
|
---|
212 | ~QDeclarativeTester();
|
---|
213 |
|
---|
214 | static void registerTypes();
|
---|
215 |
|
---|
216 | virtual int duration() const;
|
---|
217 |
|
---|
218 | void run();
|
---|
219 | void save();
|
---|
220 |
|
---|
221 | void executefailure();
|
---|
222 | protected:
|
---|
223 | virtual void updateCurrentTime(int msecs);
|
---|
224 | virtual bool eventFilter(QObject *, QEvent *);
|
---|
225 |
|
---|
226 | private:
|
---|
227 | QString m_script;
|
---|
228 |
|
---|
229 | void imagefailure();
|
---|
230 | void complete();
|
---|
231 | void testSkip();
|
---|
232 |
|
---|
233 | enum Destination { View, ViewPort };
|
---|
234 | void addKeyEvent(Destination, QKeyEvent *);
|
---|
235 | void addMouseEvent(Destination, QMouseEvent *);
|
---|
236 | QDeclarativeView *m_view;
|
---|
237 |
|
---|
238 | struct MouseEvent {
|
---|
239 | MouseEvent(QMouseEvent *e)
|
---|
240 | : type(e->type()), button(e->button()), buttons(e->buttons()),
|
---|
241 | pos(e->pos()), modifiers(e->modifiers()), destination(View) {}
|
---|
242 |
|
---|
243 | QEvent::Type type;
|
---|
244 | Qt::MouseButton button;
|
---|
245 | Qt::MouseButtons buttons;
|
---|
246 | QPoint pos;
|
---|
247 | Qt::KeyboardModifiers modifiers;
|
---|
248 | Destination destination;
|
---|
249 |
|
---|
250 | int msec;
|
---|
251 | };
|
---|
252 | struct KeyEvent {
|
---|
253 | KeyEvent(QKeyEvent *e)
|
---|
254 | : type(e->type()), key(e->key()), modifiers(e->modifiers()), text(e->text()),
|
---|
255 | autorep(e->isAutoRepeat()), count(e->count()), destination(View) {}
|
---|
256 | QEvent::Type type;
|
---|
257 | int key;
|
---|
258 | Qt::KeyboardModifiers modifiers;
|
---|
259 | QString text;
|
---|
260 | bool autorep;
|
---|
261 | ushort count;
|
---|
262 | Destination destination;
|
---|
263 |
|
---|
264 | int msec;
|
---|
265 | };
|
---|
266 | struct FrameEvent {
|
---|
267 | QImage image;
|
---|
268 | QByteArray hash;
|
---|
269 | int msec;
|
---|
270 | };
|
---|
271 | QList<MouseEvent> m_mouseEvents;
|
---|
272 | QList<KeyEvent> m_keyEvents;
|
---|
273 |
|
---|
274 | QList<MouseEvent> m_savedMouseEvents;
|
---|
275 | QList<KeyEvent> m_savedKeyEvents;
|
---|
276 | QList<FrameEvent> m_savedFrameEvents;
|
---|
277 | bool filterEvents;
|
---|
278 |
|
---|
279 | QDeclarativeViewer::ScriptOptions options;
|
---|
280 | int testscriptidx;
|
---|
281 | QDeclarativeVisualTest *testscript;
|
---|
282 |
|
---|
283 | bool hasCompleted;
|
---|
284 | bool hasFailed;
|
---|
285 | };
|
---|
286 |
|
---|
287 |
|
---|
288 | QT_END_NAMESPACE
|
---|
289 |
|
---|
290 | #endif // QDECLARATIVETESTER_H
|
---|