diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-04-14 02:00:02 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-04-14 02:00:02 (GMT) |
commit | 071f008b7f41575de364baa606652ef54502d636 (patch) | |
tree | b3a6880e7f7351c60815219bc8c6dd79729b5b46 | |
parent | 428317f83fd8b7a62244a446b76299de050d1325 (diff) | |
parent | a5ed6df017603118372f338d336c5e79f56886cd (diff) | |
download | Qt-071f008b7f41575de364baa606652ef54502d636.zip Qt-071f008b7f41575de364baa606652ef54502d636.tar.gz Qt-071f008b7f41575de364baa606652ef54502d636.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
19 files changed, 241 insertions, 414 deletions
diff --git a/demos/declarative/minehunt/MinehuntCore/Explosion.qml b/demos/declarative/minehunt/MinehuntCore/Explosion.qml index 526cd34..73ada60 100644 --- a/demos/declarative/minehunt/MinehuntCore/Explosion.qml +++ b/demos/declarative/minehunt/MinehuntCore/Explosion.qml @@ -17,11 +17,9 @@ Item { velocity: 100 velocityDeviation: 20 z: 100 - opacity: 1 } - states: [ State { name: "exploding"; when: explode == true - StateChangeScript {script: particles.burst(200); } - } - ] + states: State { name: "exploding"; when: explode + StateChangeScript {script: particles.burst(200); } + } } diff --git a/demos/declarative/minehunt/MinehuntCore/Tile.qml b/demos/declarative/minehunt/MinehuntCore/Tile.qml new file mode 100644 index 0000000..f3620f4 --- /dev/null +++ b/demos/declarative/minehunt/MinehuntCore/Tile.qml @@ -0,0 +1,87 @@ +import Qt 4.7 + +Flipable { + id: flipable + property int angle: 0 + + width: 40; height: 40 + transform: Rotation { origin.x: 20; origin.y: 20; axis.x: 1; axis.z: 0; angle: flipable.angle } + + front: Image { + source: "pics/front.png"; width: 40; height: 40 + + Image { + anchors.centerIn: parent + source: "pics/flag.png"; opacity: modelData.hasFlag + + Behavior on opacity { NumberAnimation {} } + } + } + + back: Image { + source: "pics/back.png" + width: 40; height: 40 + + Text { + anchors.centerIn: parent + text: modelData.hint; color: "white"; font.bold: true + opacity: !modelData.hasMine && modelData.hint > 0 + } + + Image { + anchors.centerIn: parent + source: "pics/bomb.png"; opacity: modelData.hasMine + } + + Explosion { id: expl } + } + + states: State { + name: "back"; when: modelData.flipped + PropertyChanges { target: flipable; angle: 180 } + } + + property real pauseDur: 250 + transitions: Transition { + SequentialAnimation { + ScriptAction { + script: { + var ret = Math.abs(flipable.x - field.clickx) + + Math.abs(flipable.y - field.clicky); + if (modelData.hasMine && modelData.flipped) + pauseDur = ret * 3 + else + pauseDur = ret + } + } + PauseAnimation { + duration: pauseDur + } + RotationAnimation { easing.type: "InOutQuad" } + ScriptAction { script: if (modelData.hasMine && modelData.flipped) { expl.explode = true } } + } + } + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + field.clickx = flipable.x + field.clicky = flipable.y + var row = Math.floor(index / 9) + var col = index - (Math.floor(index / 9) * 9) + if (mouse.button == undefined || mouse.button == Qt.RightButton) { + flag(row, col) + } else { + flip(row, col) + } + } + onPressAndHold: { + field.clickx = flipable.x + field.clicky = flipable.y + var row = Math.floor(index / 9) + var col = index - (Math.floor(index / 9) * 9) + flag(row, col) + } + } +} diff --git a/demos/declarative/minehunt/MinehuntCore/qmldir b/demos/declarative/minehunt/MinehuntCore/qmldir index 862c396..95bccc8 100644 --- a/demos/declarative/minehunt/MinehuntCore/qmldir +++ b/demos/declarative/minehunt/MinehuntCore/qmldir @@ -1,2 +1,3 @@ plugin minehunt Explosion 1.0 Explosion.qml +Tile 1.0 Tile.qml diff --git a/demos/declarative/minehunt/README b/demos/declarative/minehunt/README index 1b6cf81..b9f1d2a 100644 --- a/demos/declarative/minehunt/README +++ b/demos/declarative/minehunt/README @@ -1,5 +1,3 @@ To compile the C++ part, do 'qmake && make'. Minehunt will not run properly if the C++ plugin is not compiled. To run, simply load the minehunt.qml file with the qml runtime. - -Note that on X11, this demo has problems with the native graphicssystem. If you are using the X11 window system, please pass -graphicssystem raster to the qml binary. diff --git a/demos/declarative/minehunt/minehunt.cpp b/demos/declarative/minehunt/minehunt.cpp index a953c5a..d4b0039 100644 --- a/demos/declarative/minehunt/minehunt.cpp +++ b/demos/declarative/minehunt/minehunt.cpp @@ -48,11 +48,11 @@ #include <QTime> #include <QTimer> -class Tile : public QObject +class TileData : public QObject { Q_OBJECT public: - Tile() : _hasFlag(false), _hasMine(false), _hint(-1), _flipped(false) {} + TileData() : _hasFlag(false), _hasMine(false), _hint(-1), _flipped(false) {} Q_PROPERTY(bool hasFlag READ hasFlag WRITE setHasFlag NOTIFY hasFlagChanged) bool hasFlag() const { return _hasFlag; } @@ -91,8 +91,8 @@ class MinehuntGame : public QObject public: MinehuntGame(); - Q_PROPERTY(QDeclarativeListProperty<Tile> tiles READ tiles CONSTANT) - QDeclarativeListProperty<Tile> tiles(); + Q_PROPERTY(QDeclarativeListProperty<TileData> tiles READ tiles CONSTANT) + QDeclarativeListProperty<TileData> tiles(); Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged) bool isPlaying() {return playing;} @@ -120,11 +120,11 @@ signals: private: bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; } - Tile *tile( int row, int col ) { return onBoard(row, col) ? _tiles[col+numRows*row] : 0; } + TileData *tile( int row, int col ) { return onBoard(row, col) ? _tiles[col+numRows*row] : 0; } int getHint(int row, int col); void setPlaying(bool b){if(b==playing) return; playing=b; emit isPlayingChanged();} - QList<Tile *> _tiles; + QList<TileData *> _tiles; int numCols; int numRows; bool playing; @@ -134,25 +134,25 @@ private: int nFlags; }; -void tilesPropAppend(QDeclarativeListProperty<Tile>* prop, Tile* value) +void tilesPropAppend(QDeclarativeListProperty<TileData>* prop, TileData* value) { Q_UNUSED(prop); Q_UNUSED(value); return; //Append not supported } -int tilesPropCount(QDeclarativeListProperty<Tile>* prop) +int tilesPropCount(QDeclarativeListProperty<TileData>* prop) { - return static_cast<QList<Tile*>*>(prop->data)->count(); + return static_cast<QList<TileData*>*>(prop->data)->count(); } -Tile* tilesPropAt(QDeclarativeListProperty<Tile>* prop, int index) +TileData* tilesPropAt(QDeclarativeListProperty<TileData>* prop, int index) { - return static_cast<QList<Tile*>*>(prop->data)->at(index); + return static_cast<QList<TileData*>*>(prop->data)->at(index); } -QDeclarativeListProperty<Tile> MinehuntGame::tiles(){ - return QDeclarativeListProperty<Tile>(this, &_tiles, &tilesPropAppend, +QDeclarativeListProperty<TileData> MinehuntGame::tiles(){ + return QDeclarativeListProperty<TileData>(this, &_tiles, &tilesPropAppend, &tilesPropCount, &tilesPropAt, 0); } @@ -164,7 +164,7 @@ MinehuntGame::MinehuntGame() //initialize array for(int ii = 0; ii < numRows * numCols; ++ii) { - _tiles << new Tile; + _tiles << new TileData; } reset(); @@ -172,7 +172,7 @@ MinehuntGame::MinehuntGame() void MinehuntGame::setBoard() { - foreach(Tile* t, _tiles){ + foreach(TileData* t, _tiles){ t->setHasMine(false); t->setHint(-1); } @@ -183,7 +183,7 @@ void MinehuntGame::setBoard() int col = int((double(rand()) / double(RAND_MAX)) * numCols); int row = int((double(rand()) / double(RAND_MAX)) * numRows); - Tile* t = tile( row, col ); + TileData* t = tile( row, col ); if (t && !t->hasMine()) { t->setHasMine( true ); @@ -194,7 +194,7 @@ void MinehuntGame::setBoard() //set hints for (int r = 0; r < numRows; r++) for (int c = 0; c < numCols; c++) { - Tile* t = tile(r, c); + TileData* t = tile(r, c); if (t && !t->hasMine()) { int hint = getHint(r,c); t->setHint(hint); @@ -206,7 +206,7 @@ void MinehuntGame::setBoard() void MinehuntGame::reset() { - foreach(Tile* t, _tiles){ + foreach(TileData* t, _tiles){ t->unflip(); t->setHasFlag(false); } @@ -221,7 +221,7 @@ int MinehuntGame::getHint(int row, int col) int hint = 0; for (int c = col-1; c <= col+1; c++) for (int r = row-1; r <= row+1; r++) { - Tile* t = tile(r, c); + TileData* t = tile(r, c); if (t && t->hasMine()) hint++; } @@ -233,7 +233,7 @@ bool MinehuntGame::flip(int row, int col) if(!playing) return false; - Tile *t = tile(row, col); + TileData *t = tile(row, col); if (!t || t->hasFlag()) return false; @@ -241,7 +241,7 @@ bool MinehuntGame::flip(int row, int col) int flags = 0; for (int c = col-1; c <= col+1; c++) for (int r = row-1; r <= row+1; r++) { - Tile *nearT = tile(r, c); + TileData *nearT = tile(r, c); if(!nearT || nearT == t) continue; if(nearT->hasFlag()) @@ -251,7 +251,7 @@ bool MinehuntGame::flip(int row, int col) return false; for (int c = col-1; c <= col+1; c++) for (int r = row-1; r <= row+1; r++) { - Tile *nearT = tile(r, c); + TileData *nearT = tile(r, c); if (nearT && !nearT->flipped() && !nearT->hasFlag()) { flip( r, c ); } @@ -264,7 +264,7 @@ bool MinehuntGame::flip(int row, int col) if (t->hint() == 0) { for (int c = col-1; c <= col+1; c++) for (int r = row-1; r <= row+1; r++) { - Tile* t = tile(r, c); + TileData* t = tile(r, c); if (t && !t->flipped()) { flip( r, c ); } @@ -274,7 +274,7 @@ bool MinehuntGame::flip(int row, int col) if(t->hasMine()){ for (int r = 0; r < numRows; r++)//Flip all other mines for (int c = 0; c < numCols; c++) { - Tile* t = tile(r, c); + TileData* t = tile(r, c); if (t && t->hasMine()) { flip(r, c); } @@ -295,7 +295,7 @@ bool MinehuntGame::flip(int row, int col) bool MinehuntGame::flag(int row, int col) { - Tile *t = tile(row, col); + TileData *t = tile(row, col); if(!t) return false; @@ -305,8 +305,7 @@ bool MinehuntGame::flag(int row, int col) return true; } -QML_DECLARE_TYPE(Tile); -QML_DECLARE_TYPE(MinehuntGame); +QML_DECLARE_TYPE(TileData); class MinehuntExtensionPlugin : public QDeclarativeExtensionPlugin { @@ -314,8 +313,8 @@ class MinehuntExtensionPlugin : public QDeclarativeExtensionPlugin public: void registerTypes(const char *uri) { - qmlRegisterType<Tile>(uri, 0, 1, "Tile"); - qmlRegisterType<MinehuntGame>(uri, 0, 1, "Game"); + Q_UNUSED(uri); + qmlRegisterType<TileData>(); } void initializeEngine(QDeclarativeEngine *engine, const char *uri) { diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index 8a5667d..43f68c3 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -16,6 +16,7 @@ target.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt/MinehuntCore MinehuntCore_sources.files = \ MinehuntCore/Explosion.qml \ + MinehuntCore/Tile.qml \ MinehuntCore/pics \ MinehuntCore/qmldir MinehuntCore_sources.path = $$[QT_INSTALL_DEMOS]/declarative/minehunt/MinehuntCore diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 98955e2..5ed78fb 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -8,101 +8,6 @@ Item { width: 450; height: 450 - Component { - id: tile - - Flipable { - id: flipable - property int angle: 0 - - width: 40; height: 40 - transform: Rotation { origin.x: 20; origin.y: 20; axis.x: 1; axis.z: 0; angle: flipable.angle } - - front: Image { - source: "MinehuntCore/pics/front.png"; width: 40; height: 40 - - Image { - anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter - source: "MinehuntCore/pics/flag.png"; opacity: modelData.hasFlag - - Behavior on opacity { NumberAnimation { property: "opacity"; duration: 250 } } - } - } - - back: Image { - source: "MinehuntCore/pics/back.png" - width: 40; height: 40 - - Text { - anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter - text: modelData.hint; color: "white"; font.bold: true - opacity: !modelData.hasMine && modelData.hint > 0 - } - - Image { - anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter - source: "MinehuntCore/pics/bomb.png"; opacity: modelData.hasMine - } - - Explosion { id: expl } - } - - states: State { - name: "back"; when: modelData.flipped - PropertyChanges { target: flipable; angle: 180 } - } - - transitions: Transition { - SequentialAnimation { - PauseAnimation { - duration: { - var ret - if (flipable.parent != null) - ret = Math.abs(flipable.parent.x - field.clickx) - + Math.abs(flipable.parent.y - field.clicky) - else - ret = 0 - if (ret > 0) { - if (modelData.hasMine && modelData.flipped) { - ret * 3 - } else { - ret - } - } else { - 0 - } - } - } - NumberAnimation { easing.type: "InOutQuad"; properties: "angle" } - ScriptAction { script: if (modelData.hasMine && modelData.flipped) { expl.explode = true } } - } - } - - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton - onClicked: { - field.clickx = flipable.parent.x - field.clicky = flipable.parent.y - var row = Math.floor(index / 9) - var col = index - (Math.floor(index / 9) * 9) - if (mouse.button == undefined || mouse.button == Qt.RightButton) { - flag(row, col) - } else { - flip(row, col) - } - } - onPressAndHold: { - field.clickx = flipable.parent.x - field.clicky = flipable.parent.y - var row = Math.floor(index / 9) - var col = index - (Math.floor(index / 9) * 9) - flag(row, col) - } - } - } - } - Image { source: "MinehuntCore/pics/No-Ones-Laughing-3.jpg"; anchors.fill: parent; fillMode: Image.Tile } Grid { @@ -112,7 +17,7 @@ Item { Repeater { id: repeater model: tiles - Component { Loader { sourceComponent: tile } } + delegate: Tile {} } } @@ -143,8 +48,10 @@ Item { MouseArea { anchors.fill: parent; onPressed: reset() } } Text { - anchors.fill: parent; wrapMode: Text.WordWrap - text: "Minehunt will not run properly if the C++ plugin is not compiled.\nPlease see README." + anchors.centerIn: parent; width: parent.width - 20 + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + text: "Minehunt will not run properly if the C++ plugin is not compiled.\n\nPlease see README." color: "white"; font.bold: true; font.pixelSize: 14 visible: tiles == undefined } diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index fc7a87b..951b171 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -816,6 +816,8 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event) d->vData.velocity = qMin(event->delta() - d->vData.smoothVelocity.value(), qreal(-250.0)); d->flicked = false; d->flickY(d->vData.velocity); + if (d->flicked) + movementStarting(); event->accept(); } else if (xflick()) { if (event->delta() > 0) @@ -824,6 +826,8 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event) d->hData.velocity = qMin(event->delta() - d->hData.smoothVelocity.value(), qreal(-250.0)); d->flicked = false; d->flickX(d->hData.velocity); + if (d->flicked) + movementStarting(); event->accept(); } else { QDeclarativeItem::wheelEvent(event); diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 06e3540..4aaa28d 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -1102,7 +1102,6 @@ void QDeclarativePathView::refill() // qDebug() << "append" << idx; QDeclarativeItem *item = d->getItem(idx); item->setZValue(idx+1); - d->model->completeItem(); if (d->currentIndex == idx) { item->setFocus(true); if (QDeclarativePathViewAttached *att = d->attached(item)) @@ -1115,6 +1114,7 @@ void QDeclarativePathView::refill() d->firstIndex = idx; d->items.append(item); d->updateItem(item, pos); + d->model->completeItem(); ++idx; if (idx >= d->model->count()) idx = 0; @@ -1129,7 +1129,6 @@ void QDeclarativePathView::refill() // qDebug() << "prepend" << idx; QDeclarativeItem *item = d->getItem(idx); item->setZValue(idx+1); - d->model->completeItem(); if (d->currentIndex == idx) { item->setFocus(true); if (QDeclarativePathViewAttached *att = d->attached(item)) @@ -1140,6 +1139,7 @@ void QDeclarativePathView::refill() } d->items.prepend(item); d->updateItem(item, pos); + d->model->completeItem(); d->firstIndex = idx; idx = d->firstIndex - 1; if (idx < 0) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index d33a8be..f436471 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -700,14 +700,15 @@ void QDeclarativeGrid::setRows(const int rows) void QDeclarativeGrid::doPositioning(QSizeF *contentSize) { - int c=_columns,r=_rows;//Actual number of rows/columns + int c = _columns; + int r = _rows; int numVisible = positionedItems.count(); - if (_columns==-1 && _rows==-1){ + if (_columns <= 0 && _rows <= 0){ c = 4; r = (numVisible+3)/4; - }else if (_rows==-1){ + } else if (_rows <= 0){ r = (numVisible+(_columns-1))/_columns; - }else if (_columns==-1){ + } else if (_columns <= 0){ c = (numVisible+(_rows-1))/_rows; } diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index b8c8f57..615c674 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -82,6 +82,9 @@ public: A GestureArea is like a MouseArea, but it has signals for gesture events. + \e {Elements in the Qt.labs module are not guaranteed to remain compatible + in future versions.} + \e {This element is only functional on devices with touch input.} \qml diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp index e98a801..ad6a512 100644 --- a/src/imports/particles/qdeclarativeparticles.cpp +++ b/src/imports/particles/qdeclarativeparticles.cpp @@ -624,6 +624,8 @@ void QDeclarativeParticlesPrivate::updateOpacity(QDeclarativeParticle &p, int ag \inherits Item Particles are available in the \bold{Qt.labs.particles 1.0} module. + \e {Elements in the Qt.labs module are not guaranteed to remain compatible + in future versions.} This element provides preliminary support for particles in QML, and may be heavily changed or removed in later versions. diff --git a/tests/auto/declarative/qdeclarativepositioners/data/gridzerocolumns.qml b/tests/auto/declarative/qdeclarativepositioners/data/gridzerocolumns.qml new file mode 100644 index 0000000..052d96b --- /dev/null +++ b/tests/auto/declarative/qdeclarativepositioners/data/gridzerocolumns.qml @@ -0,0 +1,40 @@ +import Qt 4.6 + +Item { + width: 640 + height: 480 + Grid { + objectName: "grid" + columns: 0 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 50 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 08eac0a..8692596 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -63,6 +63,7 @@ private slots: void test_grid(); void test_grid_spacing(); void test_grid_animated(); + void test_grid_zero_columns(); void test_propertychanges(); void test_repeater(); void test_flow(); @@ -414,6 +415,38 @@ void tst_QDeclarativePositioners::test_grid_animated() QTRY_COMPARE(five->y(), 50.0); } + +void tst_QDeclarativePositioners::test_grid_zero_columns() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml"); + + QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one"); + QVERIFY(one != 0); + QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two"); + QVERIFY(two != 0); + QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three"); + QVERIFY(three != 0); + QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four"); + QVERIFY(four != 0); + QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 120.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 0.0); + QCOMPARE(five->y(), 50.0); + + QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid"); + QCOMPARE(grid->width(), 170.0); + QCOMPARE(grid->height(), 60.0); +} + void tst_QDeclarativePositioners::test_propertychanges() { QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml"); diff --git a/tests/auto/declarative/qmlvisual/fillmode/data/fillmode.qml b/tests/auto/declarative/qmlvisual/fillmode/data/fillmode.qml index 7ac6f51..08ed609 100644 --- a/tests/auto/declarative/qmlvisual/fillmode/data/fillmode.qml +++ b/tests/auto/declarative/qmlvisual/fillmode/data/fillmode.qml @@ -6,274 +6,6 @@ VisualTest { } Frame { msec: 16 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 32 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 48 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 64 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 80 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 96 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 112 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 128 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 144 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 160 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 176 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 192 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 208 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 224 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 240 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 256 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 272 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 288 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 304 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 320 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 336 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 352 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 368 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 384 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 400 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 416 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 432 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 448 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 464 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 480 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 496 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 512 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 528 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 544 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 560 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 576 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 592 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 608 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 624 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 640 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 656 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 672 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 688 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 704 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Key { - type: 6 - key: 16777249 - modifiers: 0 - text: "" - autorep: false - count: 1 - } - Frame { - msec: 720 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 736 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 752 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 768 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 784 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 800 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 816 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 832 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 848 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 864 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 880 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 896 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 912 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 928 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 944 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 960 image: "fillmode.0.png" - } - Frame { - msec: 976 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 992 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 1008 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 1024 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 1040 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } - Frame { - msec: 1056 - hash: "c8cb8d51ca04231dc272133faaf2fb6d" - } + } } diff --git a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp index 05c2ebd..718e3a6 100644 --- a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp +++ b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp @@ -47,7 +47,7 @@ #include <QProcess> #include <QFile> -enum Mode { Record, RecordNoVisuals, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; +enum Mode { Record, RecordNoVisuals, RecordSnapshot, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; static QString testdir; class tst_qmlvisual : public QObject @@ -133,7 +133,7 @@ void tst_qmlvisual::visual() QStringList arguments; arguments << "-script" << testdata << "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure" - << file << "-graphicssystem" << "raster"; + << file; #ifdef Q_WS_QWS arguments << "-qws"; #endif @@ -246,6 +246,11 @@ void action(Mode mode, const QString &file) << "-scriptopts" << "record,saveonexit" << file; break; + case RecordSnapshot: + arguments << "-script" << testdata + << "-scriptopts" << "record,testimages,snapshot,saveonexit" + << file; + break; case Play: arguments << "-script" << testdata << "-scriptopts" << "play,testimages,testerror,exitoncomplete" @@ -283,6 +288,7 @@ void usage() fprintf(stderr, " -listtests : list all the tests seen by tst_qmlvisual, and then exit immediately\n"); fprintf(stderr, " -record file : record new test data for file\n"); fprintf(stderr, " -recordnovisuals file : record new test data for file, but ignore visuals\n"); + fprintf(stderr, " -recordsnapshot file : record new snapshot for file (like record but only records a single frame and then exits)\n"); fprintf(stderr, " -play file : playback test data for file, printing errors\n"); fprintf(stderr, " -testvisuals file : playback test data for file, without errors\n"); fprintf(stderr, " -updatevisuals file : playback test data for file, accept new visuals for file\n"); @@ -340,6 +346,9 @@ int main(int argc, char **argv) } else if (arg == "-recordnovisuals" && (ii + 1) < argc) { mode = RecordNoVisuals; file = argv[++ii]; + } else if (arg == "-recordsnapshot" && (ii + 1) < argc) { + mode = RecordSnapshot; + file = argv[++ii]; } else if (arg == "-testvisuals" && (ii + 1) < argc) { mode = TestVisuals; file = argv[++ii]; diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 01b3912..341908e 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -121,6 +121,8 @@ void scriptOptsUsage() qWarning(" play ..................................... playback an existing script"); qWarning(" testimages ............................... record images or compare images on playback"); qWarning(" testerror ................................ test 'error' property of root item on playback"); + qWarning(" snapshot ................................. file being recorded is static,"); + qWarning(" only one frame will be recorded or tested"); 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"); @@ -309,6 +311,8 @@ int main(int argc, char ** argv) scriptOptions |= QDeclarativeViewer::ExitOnFailure; } else if (option == QLatin1String("saveonexit")) { scriptOptions |= QDeclarativeViewer::SaveOnExit; + } else if (option == QLatin1String("snapshot")) { + scriptOptions |= QDeclarativeViewer::Snapshot; } else { scriptOptsUsage(); } diff --git a/tools/qml/qdeclarativetester.cpp b/tools/qml/qdeclarativetester.cpp index 6245124..cf537ee 100644 --- a/tools/qml/qdeclarativetester.cpp +++ b/tools/qml/qdeclarativetester.cpp @@ -240,6 +240,8 @@ void QDeclarativeTester::save() void QDeclarativeTester::updateCurrentTime(int msec) { QDeclarativeItemPrivate::setConsistentTime(msec); + if (!testscript && msec > 16 && options & QDeclarativeViewer::Snapshot) + return; QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32); @@ -249,11 +251,13 @@ void QDeclarativeTester::updateCurrentTime(int msec) m_view->render(&p); } + bool snapshot = msec == 16 && options & QDeclarativeViewer::Snapshot; + FrameEvent fe; fe.msec = msec; if (msec == 0 || !(options & QDeclarativeViewer::TestImages)) { // Skip first frame, skip if not doing images - } else if (0 == (m_savedFrameEvents.count() % 60)) { + } else if (0 == (m_savedFrameEvents.count() % 60) || snapshot) { fe.image = img; } else { QCryptographicHash hash(QCryptographicHash::Md5); @@ -366,8 +370,11 @@ void QDeclarativeTester::updateCurrentTime(int msec) filterEvents = true; - if (testscript && testscript->count() <= testscriptidx) + if (testscript && testscript->count() <= testscriptidx) { + //if (msec == 16) //for a snapshot, leave it up long enough to see + // (void)::sleep(1); complete(); + } } void QDeclarativeTester::registerTypes() diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 6f1e425..b934a70 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -81,7 +81,8 @@ public: TestErrorProperty = 0x00000008, SaveOnExit = 0x00000010, ExitOnComplete = 0x00000020, - ExitOnFailure = 0x00000040 + ExitOnFailure = 0x00000040, + Snapshot = 0x00000080 }; Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) void setScript(const QString &s) { m_script = s; } |