diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-21 07:09:33 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-21 07:09:33 (GMT) |
commit | a14765de5b1bb26b4cbc6ebbdee71145e54650a8 (patch) | |
tree | 5ce3cd3acb9448a3d86eef96ac1f4129ce3b8936 /src | |
parent | 26bd84ec3625c825c04228b76dd37cd5e75fb36b (diff) | |
download | Qt-a14765de5b1bb26b4cbc6ebbdee71145e54650a8.zip Qt-a14765de5b1bb26b4cbc6ebbdee71145e54650a8.tar.gz Qt-a14765de5b1bb26b4cbc6ebbdee71145e54650a8.tar.bz2 |
Basic implementation of visual "test scripts"
Test scripts allow the qmlviewer to record a set of input actions, and the resulting visual frames.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 18 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.cpp | 37 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem_p.h | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxpathview.cpp | 6 | ||||
-rw-r--r-- | src/declarative/util/qfxview.cpp | 8 |
5 files changed, 60 insertions, 16 deletions
diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 5297516..5c1cccf 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -590,13 +590,13 @@ void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) velocityX = 0; velocityY = 0; lastPos = QPoint(); - lastPosTime.start(); + QFxItemPrivate::start(lastPosTime); pressPos = event->pos(); pressX = _moveX.value(); pressY = _moveY.value(); flicked = false; - pressTime.start(); - velocityTime.start(); + QFxItemPrivate::start(pressTime); + QFxItemPrivate::start(velocityTime); } void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -610,7 +610,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); - if (qAbs(dy) > DragThreshold || pressTime.elapsed() > 200) { + if (qAbs(dy) > DragThreshold || QFxItemPrivate::elapsed(pressTime) > 200) { qreal newY = dy + pressY; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); @@ -630,7 +630,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); - if (qAbs(dx) > DragThreshold || pressTime.elapsed() > 200) { + if (qAbs(dx) > DragThreshold || QFxItemPrivate::elapsed(pressTime) > 200) { qreal newX = dx + pressX; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); @@ -649,7 +649,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) } if (!lastPos.isNull()) { - qreal elapsed = qreal(lastPosTime.restart()) / 1000.; + qreal elapsed = qreal(QFxItemPrivate::restart(lastPosTime)) / 1000.; if (elapsed <= 0) elapsed = 1; if (q->yflick()) { @@ -685,7 +685,7 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *even if (lastPosTime.isNull()) return; - if (lastPosTime.elapsed() > 100) { + if (QFxItemPrivate::elapsed(lastPosTime) > 100) { // if we drag then pause before release we should not cause a flick. velocityX = 0.0; velocityY = 0.0; @@ -802,7 +802,7 @@ void QFxFlickable::viewportMoved() { Q_D(QFxFlickable); - int elapsed = d->velocityTime.elapsed(); + int elapsed = QFxItemPrivate::elapsed(d->velocityTime); if (elapsed) { qreal prevY = d->lastFlickablePosition.x(); @@ -827,7 +827,7 @@ void QFxFlickable::viewportMoved() } d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); - d->velocityTime.restart(); + QFxItemPrivate::restart(d->velocityTime); d->updateBeginningEnd(); if (d->flicked) { diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 5fbd816..1ca5254 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -2846,6 +2846,43 @@ QDebug operator<<(QDebug debug, QFxItem *item) return debug; } +int QFxItemPrivate::consistentTime = -1; +void QFxItemPrivate::setConsistentTime(int t) +{ + consistentTime = t; +} + +QTime QFxItemPrivate::currentTime() +{ + if (consistentTime == -1) + return QTime::currentTime(); + else + return QTime(0, 0).addMSecs(consistentTime); +} + +void QFxItemPrivate::start(QTime &t) +{ + t = currentTime(); +} + +int QFxItemPrivate::elapsed(QTime &t) +{ + int n = t.msecsTo(currentTime()); + if (n < 0) // passed midnight + n += 86400 * 1000; + return n; +} + +int QFxItemPrivate::restart(QTime &t) +{ + QTime time = currentTime(); + int n = t.msecsTo(time); + if (n < 0) // passed midnight + n += 86400*1000; + t = time; + return n; +} + QT_END_NAMESPACE QML_DECLARE_TYPE(QFxKeysAttached) diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index df75148..2c7440f 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -231,6 +231,13 @@ public: { emit q_func()->wantsFocusChanged(); } + + static int consistentTime; + static QTime currentTime(); + static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); + static void start(QTime &); + static int elapsed(QTime &); + static int restart(QTime &); }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 62f9db0..86bc9a2 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -414,7 +414,7 @@ void QFxPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) d->stealMouse = false; d->lastElapsed = 0; d->lastDist = 0; - d->lastPosTime.start(); + QFxItemPrivate::start(d->lastPosTime); d->tl.clear(); } @@ -443,7 +443,7 @@ void QFxPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) else if (diff < -50) diff += 100; - d->lastElapsed = d->lastPosTime.restart(); + d->lastElapsed = QFxItemPrivate::restart(d->lastPosTime); d->lastDist = diff; d->startPc = newPc; } @@ -456,7 +456,7 @@ void QFxPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) if (d->lastPosTime.isNull()) return; - qreal elapsed = qreal(d->lastElapsed + d->lastPosTime.elapsed()) / 1000.; + qreal elapsed = qreal(d->lastElapsed + QFxItemPrivate::elapsed(d->lastPosTime)) / 1000.; qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; if (d->model && d->model->count() && qAbs(velocity) > 5) { if (velocity > 100) diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 19dfe2c..9a2845c 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -247,10 +247,10 @@ void QFxView::continueExecute() if(d->component->isError()) { QList<QmlError> errorList = d->component->errors(); - emit errors(errorList); foreach (const QmlError &error, errorList) { qWarning() << error; } + emit errors(errorList); return; } @@ -259,10 +259,10 @@ void QFxView::continueExecute() if(d->component->isError()) { QList<QmlError> errorList = d->component->errors(); - emit errors(errorList); foreach (const QmlError &error, errorList) { qWarning() << error; } + emit errors(errorList); return; } @@ -407,10 +407,10 @@ QFxItem* QFxView::addItem(const QString &qml, QFxItem* parent) QmlComponent component(&d->engine, qml.toUtf8(), QUrl()); if(d->component->isError()) { QList<QmlError> errorList = d->component->errors(); - emit errors(errorList); foreach (const QmlError &error, errorList) { qWarning() << error; } + emit errors(errorList); return 0; } @@ -418,10 +418,10 @@ QFxItem* QFxView::addItem(const QString &qml, QFxItem* parent) QObject *obj = component.create(); if(d->component->isError()) { QList<QmlError> errorList = d->component->errors(); - emit errors(errorList); foreach (const QmlError &error, errorList) { qWarning() << error; } + emit errors(errorList); return 0; } |