1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the tools applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETESTER_H
43 #define QDECLARATIVETESTER_H
46 #include <QMouseEvent>
50 #include <qmlruntime.h>
51 #include <qdeclarativelist.h>
52 #include <qdeclarative.h>
53 #include <QAbstractAnimation>
57 class QDeclarativeVisualTest : public QObject
60 Q_PROPERTY(QDeclarativeListProperty<QObject> events READ events CONSTANT)
61 Q_CLASSINFO("DefaultProperty", "events")
63 QDeclarativeVisualTest() {}
65 QDeclarativeListProperty<QObject> events() { return QDeclarativeListProperty<QObject>(this, m_events); }
67 int count() const { return m_events.count(); }
68 QObject *event(int idx) { return m_events.at(idx); }
71 QList<QObject *> m_events;
76 QML_DECLARE_TYPE(QDeclarativeVisualTest)
80 class QDeclarativeVisualTestFrame : public QObject
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)
87 QDeclarativeVisualTestFrame() : m_msec(-1) {}
89 int msec() const { return m_msec; }
90 void setMsec(int m) { m_msec = m; }
92 QString hash() const { return m_hash; }
93 void setHash(const QString &hash) { m_hash = hash; }
95 QUrl image() const { return m_image; }
96 void setImage(const QUrl &image) { m_image = image; }
106 QML_DECLARE_TYPE(QDeclarativeVisualTestFrame)
110 class QDeclarativeVisualTestMouse : public QObject
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)
121 QDeclarativeVisualTestMouse() : m_type(0), m_button(0), m_buttons(0), m_x(0), m_y(0), m_modifiers(0), m_viewport(false) {}
123 int type() const { return m_type; }
124 void setType(int t) { m_type = t; }
126 int button() const { return m_button; }
127 void setButton(int b) { m_button = b; }
129 int buttons() const { return m_buttons; }
130 void setButtons(int b) { m_buttons = b; }
132 int x() const { return m_x; }
133 void setX(int x) { m_x = x; }
135 int y() const { return m_y; }
136 void setY(int y) { m_y = y; }
138 int modifiers() const { return m_modifiers; }
139 void setModifiers(int modifiers) { m_modifiers = modifiers; }
141 bool sendToViewport() const { return m_viewport; }
142 void setSendToViewport(bool v) { m_viewport = v; }
155 QML_DECLARE_TYPE(QDeclarativeVisualTestMouse)
159 class QDeclarativeVisualTestKey : public QObject
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)
170 QDeclarativeVisualTestKey() : m_type(0), m_key(0), m_modifiers(0), m_autorep(false), m_count(0), m_viewport(false) {}
172 int type() const { return m_type; }
173 void setType(int t) { m_type = t; }
175 int key() const { return m_key; }
176 void setKey(int k) { m_key = k; }
178 int modifiers() const { return m_modifiers; }
179 void setModifiers(int m) { m_modifiers = m; }
181 QString text() const { return m_text; }
182 void setText(const QString &t) { m_text = t; }
184 bool autorep() const { return m_autorep; }
185 void setAutorep(bool a) { m_autorep = a; }
187 int count() const { return m_count; }
188 void setCount(int c) { m_count = c; }
190 bool sendToViewport() const { return m_viewport; }
191 void setSendToViewport(bool v) { m_viewport = v; }
204 QML_DECLARE_TYPE(QDeclarativeVisualTestKey)
208 class QDeclarativeTester : public QAbstractAnimation
211 QDeclarativeTester(const QString &script, QDeclarativeViewer::ScriptOptions options, QDeclarativeView *parent);
212 ~QDeclarativeTester();
214 static void registerTypes();
216 virtual int duration() const;
221 void executefailure();
223 virtual void updateCurrentTime(int msecs);
224 virtual bool eventFilter(QObject *, QEvent *);
233 enum Destination { View, ViewPort };
234 void addKeyEvent(Destination, QKeyEvent *);
235 void addMouseEvent(Destination, QMouseEvent *);
236 QDeclarativeView *m_view;
239 MouseEvent(QMouseEvent *e)
240 : type(e->type()), button(e->button()), buttons(e->buttons()),
241 pos(e->pos()), modifiers(e->modifiers()), destination(View) {}
244 Qt::MouseButton button;
245 Qt::MouseButtons buttons;
247 Qt::KeyboardModifiers modifiers;
248 Destination destination;
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) {}
258 Qt::KeyboardModifiers modifiers;
262 Destination destination;
271 QList<MouseEvent> m_mouseEvents;
272 QList<KeyEvent> m_keyEvents;
274 QList<MouseEvent> m_savedMouseEvents;
275 QList<KeyEvent> m_savedKeyEvents;
276 QList<FrameEvent> m_savedFrameEvents;
279 QDeclarativeViewer::ScriptOptions options;
281 QDeclarativeVisualTest *testscript;
290 #endif // QDECLARATIVETESTER_H