diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-09-28 00:15:02 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-09-28 00:15:02 (GMT) |
commit | 46c3f05e1edbc112df1ddb96a161d53d22340b19 (patch) | |
tree | fd917138ad3c159a1f916351cc221a225b155d48 /tools | |
parent | f1e06cdd804934ff8c0b350b41d3d7187a21560c (diff) | |
parent | c6090b6749c9f9bf002f999f808e456b74fea1bf (diff) | |
download | Qt-46c3f05e1edbc112df1ddb96a161d53d22340b19.zip Qt-46c3f05e1edbc112df1ddb96a161d53d22340b19.tar.gz Qt-46c3f05e1edbc112df1ddb96a161d53d22340b19.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlviewer/main.cpp | 7 | ||||
-rw-r--r-- | tools/qmlviewer/qfxtester.cpp | 60 | ||||
-rw-r--r-- | tools/qmlviewer/qfxtester.h | 8 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 4 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 5 |
5 files changed, 60 insertions, 24 deletions
diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 7df1179..98a5d3a 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -60,8 +60,9 @@ void scriptOptsUsage() qWarning(" testimages ............................... compare images on playback"); qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); + qWarning(" saveonexit ............................... save recording on viewer exit"); qWarning(" "); - qWarning(" One of record or play must be specified."); + qWarning(" One of record, play or both must be specified."); exit(1); } @@ -190,10 +191,8 @@ int main(int argc, char ** argv) if (option == QLatin1String("help")) { scriptOptsUsage(); } else if (option == QLatin1String("play")) { - if (scriptOptions & QmlViewer::Record) scriptOptsUsage(); scriptOptions |= QmlViewer::Play; } else if (option == QLatin1String("record")) { - if (scriptOptions & QmlViewer::Play) scriptOptsUsage(); scriptOptions |= QmlViewer::Record; } else if (option == QLatin1String("testimages")) { scriptOptions |= QmlViewer::TestImages; @@ -201,6 +200,8 @@ int main(int argc, char ** argv) scriptOptions |= QmlViewer::ExitOnComplete; } else if (option == QLatin1String("exitonfailure")) { scriptOptions |= QmlViewer::ExitOnFailure; + } else if (option == QLatin1String("saveonexit")) { + scriptOptions |= QmlViewer::SaveOnExit; } else { scriptOptsUsage(); } diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index d4802f6..7903fa9 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -17,6 +17,7 @@ #include <qmlview.h> #include <QFile> #include <QmlComponent> +#include <QDir> #include <QCryptographicHash> #include <private/qabstractanimation_p.h> #include <private/qfxitem_p.h> @@ -30,17 +31,25 @@ QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Key, QFxVisualTes QFxTester::QFxTester(const QString &script, QmlViewer::ScriptOptions opts, QmlView *parent) -: QAbstractAnimation(parent), m_view(parent), filterEvents(true), options(opts), - testscript(0), hasFailed(false) +: QAbstractAnimation(parent), m_script(script), m_view(parent), filterEvents(true), options(opts), + testscript(0), hasCompleted(false), hasFailed(false) { parent->viewport()->installEventFilter(this); parent->installEventFilter(this); QUnifiedTimer::instance()->setConsistentTiming(true); if (options & QmlViewer::Play) - this->run(script); + this->run(); start(); } +QFxTester::~QFxTester() +{ + if (!hasFailed && + options & QmlViewer::Record && + options & QmlViewer::SaveOnExit) + save(); +} + int QFxTester::duration() const { return -1; @@ -109,22 +118,32 @@ void QFxTester::imagefailure() void QFxTester::complete() { + if (hasCompleted) + return; + hasCompleted = true; if (options & QmlViewer::ExitOnComplete) QApplication::exit(hasFailed?-1:0); + else if (options & QmlViewer::Play) + qWarning("Script playback complete"); } -void QFxTester::run(const QString &name) +void QFxTester::run() { - QmlComponent c(m_view->engine(), name + QLatin1String(".qml")); + QmlComponent c(m_view->engine(), m_script + QLatin1String(".qml")); testscript = qobject_cast<QFxVisualTest *>(c.create()); if (testscript) testscript->setParent(this); + else executefailure(); testscriptidx = 0; } -void QFxTester::save(const QString &name) +void QFxTester::save() { - QFile file(name + QLatin1String(".qml")); + QString filename = m_script + QLatin1String(".qml"); + QDir saveDir = QFileInfo(filename).absoluteDir(); + saveDir.mkpath("."); + + QFile file(filename); file.open(QIODevice::WriteOnly); QTextStream ts(&file); @@ -132,6 +151,8 @@ void QFxTester::save(const QString &name) ts << "VisualTest {\n"; int imgCount = 0; + QList<KeyEvent> keyevents = m_savedKeyEvents; + QList<MouseEvent> mouseevents = m_savedMouseEvents; for (int ii = 0; ii < m_savedFrameEvents.count(); ++ii) { const FrameEvent &fe = m_savedFrameEvents.at(ii); ts << " Frame {\n"; @@ -139,15 +160,15 @@ void QFxTester::save(const QString &name) if (!fe.hash.isEmpty()) { ts << " hash: \"" << fe.hash.toHex() << "\"\n"; } else if (!fe.image.isNull()) { - QString filename = name + "." + QString::number(imgCount++) + ".png"; + QString filename = m_script + "." + QString::number(imgCount++) + ".png"; fe.image.save(filename); ts << " image: \"" << filename << "\"\n"; } ts << " }\n"; - while (!m_savedMouseEvents.isEmpty() && - m_savedMouseEvents.first().msec == fe.msec) { - MouseEvent me = m_savedMouseEvents.takeFirst(); + while (!mouseevents.isEmpty() && + mouseevents.first().msec == fe.msec) { + MouseEvent me = mouseevents.takeFirst(); ts << " Mouse {\n"; ts << " type: " << me.type << "\n"; @@ -160,9 +181,9 @@ void QFxTester::save(const QString &name) ts << " }\n"; } - while (!m_savedKeyEvents.isEmpty() && - m_savedKeyEvents.first().msec == fe.msec) { - KeyEvent ke = m_savedKeyEvents.takeFirst(); + while (!keyevents.isEmpty() && + keyevents.first().msec == fe.msec) { + KeyEvent ke = keyevents.takeFirst(); ts << " Key {\n"; ts << " type: " << ke.type << "\n"; @@ -176,7 +197,6 @@ void QFxTester::save(const QString &name) ts << " }\n"; } } - m_savedFrameEvents.clear(); ts << "}\n"; file.close(); @@ -279,20 +299,30 @@ void QFxTester::updateCurrentTime(int msec) QPoint globalPos = m_view->mapToGlobal(QPoint(0, 0)) + pos; QMouseEvent event((QEvent::Type)mouse->type(), pos, globalPos, (Qt::MouseButton)mouse->button(), (Qt::MouseButtons)mouse->buttons(), (Qt::KeyboardModifiers)mouse->modifiers()); + MouseEvent me(&event); + me.msec = msec; if (!mouse->sendToViewport()) { QCoreApplication::sendEvent(m_view, &event); + me.destination = View; } else { QCoreApplication::sendEvent(m_view->viewport(), &event); + me.destination = ViewPort; } + m_savedMouseEvents.append(me); } else if (QFxVisualTestKey *key = qobject_cast<QFxVisualTestKey *>(event)) { QKeyEvent event((QEvent::Type)key->type(), key->key(), (Qt::KeyboardModifiers)key->modifiers(), QString::fromUtf8(QByteArray::fromHex(key->text().toUtf8())), key->autorep(), key->count()); + KeyEvent ke(&event); + ke.msec = msec; if (!key->sendToViewport()) { QCoreApplication::sendEvent(m_view, &event); + ke.destination = View; } else { QCoreApplication::sendEvent(m_view->viewport(), &event); + ke.destination = ViewPort; } + m_savedKeyEvents.append(ke); } testscriptidx++; } diff --git a/tools/qmlviewer/qfxtester.h b/tools/qmlviewer/qfxtester.h index 4ace2d1..bb027f6 100644 --- a/tools/qmlviewer/qfxtester.h +++ b/tools/qmlviewer/qfxtester.h @@ -156,11 +156,12 @@ class QFxTester : public QAbstractAnimation { public: QFxTester(const QString &script, QmlViewer::ScriptOptions options, QmlView *parent); + ~QFxTester(); virtual int duration() const; - void run(const QString &); - void save(const QString &); + void run(); + void save(); void executefailure(); protected: @@ -168,6 +169,8 @@ protected: virtual bool eventFilter(QObject *, QEvent *); private: + QString m_script; + void imagefailure(); void complete(); @@ -221,6 +224,7 @@ private: int testscriptidx; QFxVisualTest *testscript; + bool hasCompleted; bool hasFailed; }; diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 11d0ef0..49b91af 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -785,9 +785,9 @@ void QmlViewer::keyPressEvent(QKeyEvent *event) << "F9 - toggle video recording\n" << "device keys: 0=quit, 1..8=F1..F8" ; - } else if (event->key() == Qt::Key_F2 || (event->key() == Qt::Key_3 && devicemode)) { + } else if (event->key() == Qt::Key_F2 || (event->key() == Qt::Key_2 && devicemode)) { if (tester && m_scriptOptions & Record) - tester->save(m_script); + tester->save(); } else if (event->key() == Qt::Key_F3 || (event->key() == Qt::Key_3 && devicemode)) { takeSnapShot(); } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) { diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index c785e89..7f9dca0 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -38,8 +38,9 @@ public: Play = 0x00000001, Record = 0x00000002, TestImages = 0x00000004, - ExitOnComplete = 0x00000008, - ExitOnFailure = 0x00000010 + SaveOnExit = 0x00000008, + ExitOnComplete = 0x00000010, + ExitOnFailure = 0x00000020 }; Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) void setScript(const QString &s) { m_script = s; } |