From ca17b86f02524338d1501652c22eb9fd2501317b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 22 Jun 2010 09:11:10 +0200 Subject: Check for main.qml first On case insensitive platforms, it would accidently pick up internal components sometimes if you check the other way around. Task-number: QTBUG-11566 --- demos/qtdemo/menumanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/qtdemo/menumanager.cpp b/demos/qtdemo/menumanager.cpp index a2ceb0e..15561ab 100644 --- a/demos/qtdemo/menumanager.cpp +++ b/demos/qtdemo/menumanager.cpp @@ -369,10 +369,10 @@ void MenuManager::launchQmlExample(const QString &name) dir = QDir(QLibraryInfo::location(QLibraryInfo::DemosPath)); else dir = QDir(QLibraryInfo::location(QLibraryInfo::ExamplesPath)); - QFile file(dir.path() + "/" + dirName + "/" + fileName + "/" + fileName.split('/').last() + ".qml"); + QFile file(dir.path() + "/" + dirName + "/" + fileName + "/" + "main.qml"); if(!file.exists()){ - //try main.qml as well - file.setFileName(dir.path() + "/" + dirName + "/" + fileName + "/" + "main.qml"); + //try dirname.qml as well + file.setFileName(dir.path() + "/" + dirName + "/" + fileName + "/" + fileName.split('/').last() + ".qml"); if(!file.exists()){ exampleError(QProcess::UnknownError); return; -- cgit v0.12 From 3e209785c3f027973089ccbebc6528501f416f2b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 23 Jun 2010 12:45:34 +1000 Subject: References to undefined variables throws a ReferenceError This is consistent with normal JavaScript --- .../qml/qdeclarativeglobalscriptclass.cpp | 24 +++++++++------------- .../qml/qdeclarativeglobalscriptclass_p.h | 5 +---- .../qdeclarativeecmascript/data/eval.qml | 6 +++++- .../qdeclarativeecmascript/data/function.qml | 6 +++++- .../qdeclarativeecmascript/data/scriptErrors.qml | 2 +- .../tst_qdeclarativeecmascript.cpp | 13 ++++++++---- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 6e107fb..f29b3f4 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -41,6 +41,7 @@ #include "private/qdeclarativeglobalscriptclass_p.h" +#include #include #include #include @@ -87,18 +88,7 @@ QDeclarativeGlobalScriptClass::queryProperty(const QScriptValue &object, Q_UNUSED(name); Q_UNUSED(flags); Q_UNUSED(id); - return HandlesReadAccess | HandlesWriteAccess; -} - -QScriptValue -QDeclarativeGlobalScriptClass::property(const QScriptValue &object, - const QScriptString &name, - uint id) -{ - Q_UNUSED(object); - Q_UNUSED(name); - Q_UNUSED(id); - return engine()->undefinedValue(); + return HandlesWriteAccess; } void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, @@ -114,8 +104,9 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, } /* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */ -void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value) +void QDeclarativeGlobalScriptClass::explicitSetProperty(const QStringList &names, const QList &values) { + Q_ASSERT(names.count() == values.count()); QScriptValue globalObject = engine()->globalObject(); QScriptValue v = engine()->newObject(); @@ -126,7 +117,12 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con v.setProperty(iter.scriptName(), iter.value()); } - v.setProperty(name, value); + for (int ii = 0; ii < names.count(); ++ii) { + const QString &name = names.at(ii); + const QScriptValue &value = values.at(ii); + v.setProperty(name, value); + } + v.setScriptClass(this); engine()->setGlobalObject(v); diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h index 7690edd..fb44e5d 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h @@ -67,13 +67,10 @@ public: const QScriptString &name, QueryFlags flags, uint *id); - virtual QScriptValue property(const QScriptValue &object, - const QScriptString &name, uint id); - virtual void setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value); - void explicitSetProperty(const QString &, const QScriptValue &); + void explicitSetProperty(const QStringList &, const QList &); const QScriptValue &globalObject() const { return m_globalObject; } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml index bc2df98..aab39be 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml @@ -16,7 +16,11 @@ QtObject { test1 = (eval("a") == 7); test2 = (eval("b") == 9); - test3 = (eval("c") == undefined); + try { + eval("c"); + } catch(e) { + test3 = true; + } test4 = (eval("console") == console); test5 = (eval("Qt") == Qt); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml index b435f58..80d6ef4 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml @@ -14,6 +14,10 @@ QtObject { test1 = (func1(4) == 11); test2 = (func2("Hello World!") == Qt.atob("Hello World!")); - test3 = (func3() == undefined); + try { + func3(); + } catch(e) { + test3 = true; + } } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml index e8f7b62..f601f49 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml @@ -4,7 +4,7 @@ import "scriptErrors.js" as Script MyQmlObject { property int t: a.value property int w: Script.getValue(); - property int x: undefinedObject + property int x: undefined property int y: (a.value, undefinedObject) onBasicSignal: { console.log(a.value); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 16e7ec5..50da55d 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1002,10 +1002,10 @@ void tst_qdeclarativeecmascript::scriptErrors() QString url = component.url().toString(); QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; - QString warning2 = url + ":5: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning2 = url + ":5: ReferenceError: Can't find variable: a"; QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\""; - QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning5 = url + ":8: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning4 = url + ":10: ReferenceError: Can't find variable: a"; + QString warning5 = url + ":8: ReferenceError: Can't find variable: a"; QString warning6 = url + ":7: Unable to assign [undefined] to int x"; QString warning7 = url + ":12: Error: Cannot assign to read-only property \"trueProperty\""; QString warning8 = url + ":13: Error: Cannot assign to non-existent property \"fakeProperty\""; @@ -1322,7 +1322,12 @@ void tst_qdeclarativeecmascript::callQtInvokables() QDeclarativeEngine qmlengine; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine); QScriptEngine *engine = &ep->scriptEngine; - ep->globalClass->explicitSetProperty("object", ep->objectClass->newQObject(&o)); + + QStringList names; QList values; + names << QLatin1String("object"); values << ep->objectClass->newQObject(&o); + names << QLatin1String("undefined"); values << engine->undefinedValue(); + + ep->globalClass->explicitSetProperty(names, values); // Non-existent methods o.reset(); -- cgit v0.12 From e53cd1a6c32e2de719e82a1e0f25b104a0fee995 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 23 Jun 2010 15:31:21 +1000 Subject: Support for non-literal plural arguments to qsTr() in lupdate (QML). Task-number: QTBUG-11579 --- tools/linguist/lupdate/qdeclarative.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp index a734e99..1b35c14 100644 --- a/tools/linguist/lupdate/qdeclarative.cpp +++ b/tools/linguist/lupdate/qdeclarative.cpp @@ -102,12 +102,8 @@ protected: comment = literal->value->asString(); AST::ArgumentList *nNode = commentNode->next; - if (nNode) { - AST::NumericLiteral *numLiteral = AST::cast(nNode->expression); - if (numLiteral) { - plural = true; - } - } + if (nNode) + plural = true; } TranslatorMessage msg(m_component, source, @@ -135,12 +131,8 @@ protected: comment = literal->value->asString(); AST::ArgumentList *nNode = commentNode->next; - if (nNode) { - AST::NumericLiteral *numLiteral = AST::cast(nNode->expression); - if (numLiteral) { - plural = true; - } - } + if (nNode) + plural = true; } } -- cgit v0.12 From a60f8832425aafbe6c5e8be3c25fefc9f8f2f87b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 23 Jun 2010 16:13:18 +1000 Subject: Ensure the view is correctly positioned at component complete. If a currentIndex has been specified, ensure the view starts at the correct position immediately, rather than scrolling to it after startup. --- .../graphicsitems/qdeclarativegridview.cpp | 9 ++++ .../graphicsitems/qdeclarativelistview.cpp | 8 +++ .../data/gridview-initCurrent.qml | 2 +- .../tst_qdeclarativegridview.cpp | 57 +++++++++++----------- .../data/listview-initCurrent.qml | 2 +- .../tst_qdeclarativelistview.cpp | 32 ++++++------ 6 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 3792595..8e53237 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2037,6 +2037,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) if (mode < Beginning || mode > Contain) return; + if (d->layoutScheduled) + d->layout(); qreal pos = d->position(); FxGridItem *item = d->visibleItem(index); if (!item) { @@ -2079,6 +2081,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) pos = qMin(pos, maxExtent); qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); + d->moveReason = QDeclarativeGridViewPrivate::Other; + cancelFlick(); d->setPosition(pos); } d->fixupPosition(); @@ -2113,10 +2117,15 @@ void QDeclarativeGridView::componentComplete() d->updateGrid(); if (d->isValid()) { refill(); + d->moveReason = QDeclarativeGridViewPrivate::SetIndex; if (d->currentIndex < 0) d->updateCurrent(0); else d->updateCurrent(d->currentIndex); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + d->updateTrackedItem(); + } d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 06a3239..35e6bab 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2448,6 +2448,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) if (mode < Beginning || mode > Contain) return; + if (d->layoutScheduled) + d->layout(); qreal pos = d->position(); FxListItem *item = d->visibleItem(index); if (!item) { @@ -2491,6 +2493,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) pos = qMin(pos, maxExtent); qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); + d->moveReason = QDeclarativeListViewPrivate::Other; + cancelFlick(); d->setPosition(pos); } d->fixupPosition(); @@ -2529,6 +2533,10 @@ void QDeclarativeListView::componentComplete() d->updateCurrent(0); else d->updateCurrent(d->currentIndex); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->position()); + d->updateTrackedItem(); + } d->fixupPosition(); } } diff --git a/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml b/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml index 9331243..a5d651d 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml @@ -43,7 +43,7 @@ Rectangle { focus: true width: 240 height: 320 - currentIndex: 5 + currentIndex: 35 cellWidth: 80 cellHeight: 60 delegate: myDelegate diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 4e35bc0..deff1f8 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -557,7 +557,7 @@ void tst_QDeclarativeGridView::moved() void tst_QDeclarativeGridView::currentIndex() { TestModel model; - for (int i = 0; i < 30; i++) + for (int i = 0; i < 60; i++) model.addItem("Item" + QString::number(i), QString::number(i)); QDeclarativeView *canvas = new QDeclarativeView(0); @@ -572,57 +572,58 @@ void tst_QDeclarativeGridView::currentIndex() qApp->processEvents(); QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); - QTRY_VERIFY(gridview != 0); + QVERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QVERIFY(viewport != 0); // current item should be third item - QTRY_COMPARE(gridview->currentIndex(), 5); - QTRY_COMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 5)); - QTRY_COMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); + QCOMPARE(gridview->currentIndex(), 35); + QCOMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 35)); + QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); + QCOMPARE(gridview->contentY(), 399.0); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), 6); + QCOMPARE(gridview->currentIndex(), 36); gridview->moveCurrentIndexDown(); - QTRY_COMPARE(gridview->currentIndex(), 9); + QCOMPARE(gridview->currentIndex(), 39); gridview->moveCurrentIndexUp(); - QTRY_COMPARE(gridview->currentIndex(), 6); + QCOMPARE(gridview->currentIndex(), 36); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), 5); + QCOMPARE(gridview->currentIndex(), 35); // no wrap gridview->setCurrentIndex(0); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexUp(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->setCurrentIndex(model.count()-1); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexDown(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); // with wrap gridview->setWrapEnabled(true); gridview->setCurrentIndex(0); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); - QTRY_COMPARE(gridview->contentY(), 279.0); + QTRY_COMPARE(gridview->contentY(), 879.0); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); QTRY_COMPARE(gridview->contentY(), 0.0); @@ -638,30 +639,30 @@ void tst_QDeclarativeGridView::currentIndex() qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(gridview->currentIndex(), 3); + QCOMPARE(gridview->currentIndex(), 3); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->setFlow(QDeclarativeGridView::TopToBottom); QTest::keyClick(canvas, Qt::Key_Right); - QTRY_COMPARE(gridview->currentIndex(), 5); + QCOMPARE(gridview->currentIndex(), 5); QTest::keyClick(canvas, Qt::Key_Left); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(gridview->currentIndex(), 1); + QCOMPARE(gridview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); - QTRY_VERIFY(gridview->highlightFollowsCurrentItem() == false); - QTRY_VERIFY(gridview->highlightItem()); + QVERIFY(gridview->highlightFollowsCurrentItem() == false); + QVERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); diff --git a/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml b/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml index 0599ddd..f3c2910 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml @@ -40,7 +40,7 @@ Rectangle { id: list objectName: "list" focus: true - currentIndex: 3 + currentIndex: 20 width: 240 height: 320 keyNavigationWraps: testWrap diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index cd42b63..8ff6e56 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -973,34 +973,36 @@ void tst_QDeclarativeListView::currentIndex() QDeclarativeItem *viewport = listview->viewport(); QTRY_VERIFY(viewport != 0); - // current item should be third item - QTRY_COMPARE(listview->currentIndex(), 3); - QTRY_COMPARE(listview->currentItem(), findItem(viewport, "wrapper", 3)); - QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + // current item should be 20th item at startup + // and current item should be in view + QCOMPARE(listview->currentIndex(), 20); + QCOMPARE(listview->contentY(), 99.0); + QCOMPARE(listview->currentItem(), findItem(viewport, "wrapper", 20)); + QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // no wrap listview->setCurrentIndex(0); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); listview->incrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 1); + QCOMPARE(listview->currentIndex(), 1); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); // with wrap ctxt->setContextProperty("testWrap", QVariant(true)); - QTRY_VERIFY(listview->isWrapEnabled()); + QVERIFY(listview->isWrapEnabled()); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), model.count()-1); + QCOMPARE(listview->currentIndex(), model.count()-1); QTRY_COMPARE(listview->contentY(), 279.0); listview->incrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); QTRY_COMPARE(listview->contentY(), 0.0); @@ -1016,16 +1018,16 @@ void tst_QDeclarativeListView::currentIndex() qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(listview->currentIndex(), 1); + QCOMPARE(listview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); // turn off auto highlight listview->setHighlightFollowsCurrentItem(false); - QTRY_VERIFY(listview->highlightFollowsCurrentItem() == false); + QVERIFY(listview->highlightFollowsCurrentItem() == false); - QTRY_VERIFY(listview->highlightItem()); + QVERIFY(listview->highlightItem()); qreal hlPos = listview->highlightItem()->y(); listview->setCurrentIndex(4); -- cgit v0.12 From faebec95f12f2db4cc105738c064e12bd0bcf988 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 23 Jun 2010 16:50:48 +1000 Subject: Fix and better test Text / TextEdit alignments. Various clipping and refresh bugs. Task-number: QTBUG-11492 --- .../graphicsitems/qdeclarativepainteditem.cpp | 4 +- src/declarative/graphicsitems/qdeclarativetext.cpp | 142 +++++++++++++-------- src/declarative/graphicsitems/qdeclarativetext_p.h | 2 + .../graphicsitems/qdeclarativetextedit.cpp | 28 +++- .../graphicsitems/qdeclarativetextedit_p.h | 2 + .../qdeclarativetext/data/alignments.qml | 42 ++++++ .../qdeclarativetext/data/alignments_cb.png | Bin 0 -> 1184 bytes .../qdeclarativetext/data/alignments_cc.png | Bin 0 -> 1293 bytes .../qdeclarativetext/data/alignments_ct.png | Bin 0 -> 1237 bytes .../qdeclarativetext/data/alignments_lb.png | Bin 0 -> 1208 bytes .../qdeclarativetext/data/alignments_lc.png | Bin 0 -> 1303 bytes .../qdeclarativetext/data/alignments_lt.png | Bin 0 -> 1241 bytes .../qdeclarativetext/data/alignments_rb.png | Bin 0 -> 1178 bytes .../qdeclarativetext/data/alignments_rc.png | Bin 0 -> 1274 bytes .../qdeclarativetext/data/alignments_rt.png | Bin 0 -> 1221 bytes .../qdeclarativetext/tst_qdeclarativetext.cpp | 66 ++++++++++ .../qdeclarativetextedit/data/alignments.qml | 42 ++++++ .../qdeclarativetextedit/data/alignments_cb.png | Bin 0 -> 1411 bytes .../qdeclarativetextedit/data/alignments_cc.png | Bin 0 -> 1501 bytes .../qdeclarativetextedit/data/alignments_ct.png | Bin 0 -> 1457 bytes .../qdeclarativetextedit/data/alignments_lb.png | Bin 0 -> 1420 bytes .../qdeclarativetextedit/data/alignments_lc.png | Bin 0 -> 1508 bytes .../qdeclarativetextedit/data/alignments_lt.png | Bin 0 -> 1447 bytes .../qdeclarativetextedit/data/alignments_rb.png | Bin 0 -> 1421 bytes .../qdeclarativetextedit/data/alignments_rc.png | Bin 0 -> 1485 bytes .../qdeclarativetextedit/data/alignments_rt.png | Bin 0 -> 1439 bytes .../tst_qdeclarativetextedit.cpp | 54 ++++++++ 27 files changed, 326 insertions(+), 56 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments.qml create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_cb.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_cc.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_ct.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_lb.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_lc.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_lt.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_rb.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_rc.png create mode 100644 tests/auto/declarative/qdeclarativetext/data/alignments_rt.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments.qml create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 13d1b61..3b9b8df 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -151,6 +151,7 @@ void QDeclarativePaintedItem::setContentsSize(const QSize &size) { Q_D(QDeclarativePaintedItem); if (d->contentsSize == size) return; + prepareGeometryChange(); d->contentsSize = size; clearCache(); update(); @@ -247,8 +248,7 @@ QRectF QDeclarativePaintedItem::boundingRect() const void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativePaintedItem); - const QRect content(0,0,qCeil(d->contentsSize.width()*d->contentsScale), - qCeil(d->contentsSize.height()*d->contentsScale)); + const QRect content = boundingRect().toRect(); if (content.width() <= 0 || content.height() <= 0) return; diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index c2e0d67..2ba680d 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -663,6 +663,71 @@ void QDeclarativeText::setElideMode(QDeclarativeText::TextElideMode mode) emit elideModeChanged(d->elideMode); } +QRectF QDeclarativeText::boundingRect() const +{ + Q_D(const QDeclarativeText); + + int w = width(); + int h = height(); + + int x = 0; + int y = 0; + + if (d->cache || d->style != Normal) { + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - d->imgCache.width(); + break; + case AlignHCenter: + x = (w - d->imgCache.width()) / 2; + break; + } + + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - d->imgCache.height(); + break; + case AlignVCenter: + y = (h - d->imgCache.height()) / 2; + break; + } + + return QRectF(x,y,d->imgCache.width(),d->imgCache.height()); + } else { + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - d->cachedLayoutSize.width(); + break; + case AlignHCenter: + x = (w - d->cachedLayoutSize.width()) / 2; + break; + } + + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - d->cachedLayoutSize.height(); + break; + case AlignVCenter: + y = (h - d->cachedLayoutSize.height()) / 2; + break; + } + + return QRectF(x,y,d->cachedLayoutSize.width(),d->cachedLayoutSize.height()); + } +} + void QDeclarativeText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { @@ -713,6 +778,7 @@ void QDeclarativeTextPrivate::updateLayout() } } + void QDeclarativeTextPrivate::updateSize() { Q_Q(QDeclarativeText); @@ -730,7 +796,10 @@ void QDeclarativeTextPrivate::updateSize() //setup instance of QTextLayout for all cases other than richtext if (!richText) { size = setupTextLayout(&layout); - cachedLayoutSize = size; + if (cachedLayoutSize != size) { + q->prepareGeometryChange(); + cachedLayoutSize = size; + } dy -= size.height(); } else { singleline = false; // richtext can't elide or be optimized for single-line case @@ -744,7 +813,13 @@ void QDeclarativeTextPrivate::updateSize() else doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) dy -= (int)doc->size().height(); - cachedLayoutSize = doc->size().toSize(); + q->prepareGeometryChange(); + QSize dsize = doc->size().toSize(); + if (dsize != cachedLayoutSize) { + q->prepareGeometryChange(); + cachedLayoutSize = dsize; + } + size = QSize(int(doc->idealWidth()),dsize.height()); } int yoff = 0; @@ -757,8 +832,8 @@ void QDeclarativeTextPrivate::updateSize() q->setBaselineOffset(fm.ascent() + yoff); //### need to comfirm cost of always setting these for richText - q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width()); - q->setImplicitHeight(richText ? (int)doc->size().height() : size.height()); + q->setImplicitWidth(size.width()); + q->setImplicitHeight(size.height()); emit q->paintedSizeChanged(); } else { dirty = true; @@ -813,6 +888,8 @@ void QDeclarativeTextPrivate::drawOutline() ppm.drawPixmap(pos, imgCache); ppm.end(); + if (imgCache.size() != img.size()) + q_func()->prepareGeometryChange(); imgCache = img; } @@ -831,6 +908,8 @@ void QDeclarativeTextPrivate::drawOutline(int yOffset) ppm.drawPixmap(pos, imgCache); ppm.end(); + if (imgCache.size() != img.size()) + q_func()->prepareGeometryChange(); imgCache = img; } @@ -955,18 +1034,21 @@ void QDeclarativeTextPrivate::checkImgCache() return; bool empty = text.isEmpty(); + QPixmap newImgCache; if (empty) { - imgCache = QPixmap(); imgStyleCache = QPixmap(); } else if (richText) { - imgCache = richTextImage(false); + newImgCache = richTextImage(false); if (style != QDeclarativeText::Normal) imgStyleCache = richTextImage(true); //### should use styleColor } else { - imgCache = wrappedTextImage(false); + newImgCache = wrappedTextImage(false); if (style != QDeclarativeText::Normal) imgStyleCache = wrappedTextImage(true); //### should use styleColor } + if (imgCache.size() != newImgCache.size()) + q_func()->prepareGeometryChange(); + imgCache = newImgCache; if (!empty) switch (style) { case QDeclarativeText::Outline: @@ -1031,35 +1113,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid if (d->smooth) p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - int w = width(); - int h = height(); - - int x = 0; - int y = 0; - - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->imgCache.width(); - break; - case AlignHCenter: - x = (w - d->imgCache.width()) / 2; - break; - } - - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->imgCache.height(); - break; - case AlignVCenter: - y = (h - d->imgCache.height()) / 2; - break; - } + QRect br = boundingRect().toRect(); bool needClip = clip() && (d->imgCache.width() > width() || d->imgCache.height() > height()); @@ -1068,7 +1122,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid p->save(); p->setClipRect(boundingRect(), Qt::IntersectClip); } - p->drawPixmap(x, y, d->imgCache); + p->drawPixmap(br.x(), br.y(), d->imgCache); if (needClip) p->restore(); @@ -1077,20 +1131,8 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } else { - int h = height(); - int y = 0; + qreal y = boundingRect().y(); - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->cachedLayoutSize.height(); - break; - case AlignVCenter: - y = (h - d->cachedLayoutSize.height()) / 2; - break; - } bool needClip = !clip() && (d->cachedLayoutSize.width() > width() || d->cachedLayoutSize.height() > height()); diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index db21140..cd97df3 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -143,6 +143,8 @@ public: qreal paintedWidth() const; qreal paintedHeight() const; + QRectF boundingRect() const; + Q_SIGNALS: void textChanged(const QString &text); void linkActivated(const QString &link); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 3106daf..7db21f2 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -1231,8 +1231,13 @@ void QDeclarativeTextEdit::updateImgCache(const QRectF &rf) r = QRect(0,0,INT_MAX,INT_MAX); } else { r = rf.toRect(); - if (r != QRect(0,0,INT_MAX,INT_MAX)) // Don't translate "everything" + if (r.height() > INT_MAX/2) { + // Take care of overflow when translating "everything" + r.setTop(r.y() + d->yoff); + r.setBottom(INT_MAX/2); + } else { r = r.translated(0,d->yoff); + } } dirtyCache(r); emit update(); @@ -1327,6 +1332,14 @@ void QDeclarativeTextEdit::updateSelectionMarkers() } } +QRectF QDeclarativeTextEdit::boundingRect() const +{ + Q_D(const QDeclarativeTextEdit); + QRectF r = QDeclarativePaintedItem::boundingRect(); + return r.translated(0,d->yoff); +} + + //### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't // need to do all the calculations each time void QDeclarativeTextEdit::updateSize() @@ -1341,13 +1354,20 @@ void QDeclarativeTextEdit::updateSize() d->document->setTextWidth(width()); dy -= (int)d->document->size().height(); + int nyoff; if (heightValid()) { if (d->vAlign == AlignBottom) - d->yoff = dy; + nyoff = dy; else if (d->vAlign == AlignVCenter) - d->yoff = dy/2; + nyoff = dy/2; + else + nyoff = 0; } else { - d->yoff = 0; + nyoff = 0; + } + if (nyoff != d->yoff) { + prepareGeometryChange(); + d->yoff = nyoff; } setBaselineOffset(fm.ascent() + d->yoff + d->textMargin); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index d08f607..a6dd4a4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -195,6 +195,8 @@ public: Q_INVOKABLE int positionAt(int x, int y) const; Q_INVOKABLE void moveCursorSelection(int pos); + QRectF boundingRect() const; + Q_SIGNALS: void textChanged(const QString &); void paintedSizeChanged(); diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments.qml b/tests/auto/declarative/qdeclarativetext/data/alignments.qml new file mode 100644 index 0000000..6a98a4d --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments.qml @@ -0,0 +1,42 @@ +import Qt 4.7 + +Rectangle { + id: top + width: 70; height: 70; + + property alias horizontalAlignment: t.horizontalAlignment + property alias verticalAlignment: t.verticalAlignment + property alias wrapMode: t.wrapMode + property alias running: timer.running + property string txt: "Test" + + Rectangle { + anchors.centerIn: parent + width: 40 + height: 40 + color: "green" + + Text { + id: t + + anchors.fill: parent + font.pixelSize: 8 + horizontalAlignment: TextEdit.AlignRight + verticalAlignment: TextEdit.AlignBottom + wrapMode: TextEdit.WordWrap + text: top.txt + } + Timer { + id: timer + + interval: 1 + running: true + repeat: true + onTriggered: { + top.txt = top.txt + "
more " + top.txt.length; + if (top.txt.length > 50) + running = false + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png new file mode 100644 index 0000000..5cdb1e5 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png new file mode 100644 index 0000000..6b6862c Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png new file mode 100644 index 0000000..7bfd281 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png new file mode 100644 index 0000000..a8c16a0 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png new file mode 100644 index 0000000..1f6e28d Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png new file mode 100644 index 0000000..e529880 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png new file mode 100644 index 0000000..c1ce274 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png new file mode 100644 index 0000000..4f8a4a7 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png new file mode 100644 index 0000000..643bd18 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png differ diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 01120b1..91b3ca0 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include "../../../shared/util.h" #include "testhttpserver.h" @@ -70,6 +71,9 @@ private slots: void elide(); void textFormat(); + void alignments_data(); + void alignments(); + void embeddedImages_data(); void embeddedImages(); @@ -108,6 +112,8 @@ private: QStringList colorStrings; QDeclarativeEngine engine; + + QDeclarativeView *createView(const QString &filename); }; tst_qdeclarativetext::tst_qdeclarativetext() @@ -163,6 +169,14 @@ tst_qdeclarativetext::tst_qdeclarativetext() // } +QDeclarativeView *tst_qdeclarativetext::createView(const QString &filename) +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + + canvas->setSource(QUrl::fromLocalFile(filename)); + return canvas; +} + void tst_qdeclarativetext::text() { { @@ -383,6 +397,58 @@ void tst_qdeclarativetext::textFormat() } } + +void tst_qdeclarativetext::alignments_data() +{ + QTest::addColumn("hAlign"); + QTest::addColumn("vAlign"); + QTest::addColumn("expectfile"); + + QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png"; + QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png"; + QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png"; + + QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png"; + QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png"; + QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png"; + + QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png"; + QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png"; + QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png"; +} + + +void tst_qdeclarativetext::alignments() +{ + QFETCH(int, hAlign); + QFETCH(int, vAlign); + QFETCH(QString, expectfile); + + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + ob->setProperty("horizontalAlignment",hAlign); + ob->setProperty("verticalAlignment",vAlign); + QTRY_COMPARE(ob->property("running").toBool(),false); + QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32); + actual.fill(qRgb(255,255,255)); + QPainter p(&actual); + canvas->render(&p); + + QImage expect(expectfile); + +#ifdef Q_OS_LINUX + // Font-specific, but not likely platform-specific, so only test on one platform + QCOMPARE(actual,expect); +#endif +} + //the alignment tests may be trivial o.oa void tst_qdeclarativetext::horizontalAlignment() { diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml new file mode 100644 index 0000000..6a98a4d --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml @@ -0,0 +1,42 @@ +import Qt 4.7 + +Rectangle { + id: top + width: 70; height: 70; + + property alias horizontalAlignment: t.horizontalAlignment + property alias verticalAlignment: t.verticalAlignment + property alias wrapMode: t.wrapMode + property alias running: timer.running + property string txt: "Test" + + Rectangle { + anchors.centerIn: parent + width: 40 + height: 40 + color: "green" + + Text { + id: t + + anchors.fill: parent + font.pixelSize: 8 + horizontalAlignment: TextEdit.AlignRight + verticalAlignment: TextEdit.AlignBottom + wrapMode: TextEdit.WordWrap + text: top.txt + } + Timer { + id: timer + + interval: 1 + running: true + repeat: true + onTriggered: { + top.txt = top.txt + "
more " + top.txt.length; + if (top.txt.length > 50) + running = false + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png new file mode 100644 index 0000000..0e40444 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png new file mode 100644 index 0000000..a5c83a8 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png new file mode 100644 index 0000000..8177c20 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png new file mode 100644 index 0000000..c0e1774 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png new file mode 100644 index 0000000..d61aaf2 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png new file mode 100644 index 0000000..599f4c6 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png new file mode 100644 index 0000000..83ec990 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png new file mode 100644 index 0000000..53e30b7 Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png new file mode 100644 index 0000000..61a112f Binary files /dev/null and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index f7ba7a1..009d354 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -73,6 +73,8 @@ private slots: void width(); void wrap(); void textFormat(); + void alignments(); + void alignments_data(); // ### these tests may be trivial void hAlign(); @@ -297,6 +299,58 @@ void tst_qdeclarativetextedit::textFormat() } } +void tst_qdeclarativetextedit::alignments_data() +{ + QTest::addColumn("hAlign"); + QTest::addColumn("vAlign"); + QTest::addColumn("expectfile"); + + QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png"; + QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png"; + QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png"; + + QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png"; + QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png"; + QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png"; + + QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png"; + QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png"; + QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png"; +} + + +void tst_qdeclarativetextedit::alignments() +{ + QFETCH(int, hAlign); + QFETCH(int, vAlign); + QFETCH(QString, expectfile); + + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + ob->setProperty("horizontalAlignment",hAlign); + ob->setProperty("verticalAlignment",vAlign); + QTRY_COMPARE(ob->property("running").toBool(),false); + QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32); + actual.fill(qRgb(255,255,255)); + QPainter p(&actual); + canvas->render(&p); + + QImage expect(expectfile); + +#ifdef Q_OS_LINUX + // Font-specific, but not likely platform-specific, so only test on one platform + QCOMPARE(actual,expect); +#endif +} + + //the alignment tests may be trivial o.oa void tst_qdeclarativetextedit::hAlign() { -- cgit v0.12 From ae3e6af047e952694637bf41b1afd986d10068c1 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 23 Jun 2010 10:01:37 +1000 Subject: Update screenshot --- doc/src/images/qml-xmlhttprequest-example.png | Bin 21311 -> 20934 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/doc/src/images/qml-xmlhttprequest-example.png b/doc/src/images/qml-xmlhttprequest-example.png index 68e7d27..f585613 100644 Binary files a/doc/src/images/qml-xmlhttprequest-example.png and b/doc/src/images/qml-xmlhttprequest-example.png differ -- cgit v0.12 From b1c128415894686d61b3d568e5117ba96dd4c74e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 23 Jun 2010 16:55:04 +1000 Subject: Use Pen with Qt::MiterJoin when drawing Rectangles with gradients Task-number: QTBUG-11624 --- src/declarative/graphicsitems/qdeclarativerectangle.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 2756877..c49be46 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -446,6 +446,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p) p.setRenderHint(QPainter::Antialiasing); if (d->pen && d->pen->isValid()) { QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); p.setPen(pn); } else { p.setPen(Qt::NoPen); -- cgit v0.12 From 79c2f9d676d782212fb17f9158604e8158c47a22 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 24 Jun 2010 09:04:45 +1000 Subject: Fix unstable qdeclarativeviewer tests --- tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index f30f758..1ea2a95 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -261,7 +261,7 @@ void tst_QDeclarativeViewer::resizing() QCOMPARE(rootItem->width(), 150.0); QCOMPARE(rootItem->height(), 200.0); - QCOMPARE(viewer->view()->size(), QSize(150, 200)); + QTRY_COMPARE(viewer->view()->size(), QSize(150, 200)); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(150, 200)); QCOMPARE(viewer->size(), QSize(150, 200+viewer->menuBar()->height())); @@ -279,7 +279,7 @@ void tst_QDeclarativeViewer::resizing() QTRY_COMPARE(rootItem->width(), 250.0); QTRY_COMPARE(rootItem->height(), 350.0-viewer->menuBar()->height()); - QCOMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); + QTRY_COMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(250, 350-viewer->menuBar()->height())); QCOMPARE(viewer->size(), QSize(250, 350)); -- cgit v0.12 From 168abf1f3165f0a6d83f747c46f3d3241b1a405f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 24 Jun 2010 09:27:08 +1000 Subject: doc: note that calling methods before component completion may have no effect So use Component.onCompleted: --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 18 ++++++++++++++++++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 14 ++++++++++++++ src/declarative/graphicsitems/qdeclarativepathview.cpp | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 8e53237..14980a8 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1919,6 +1919,8 @@ void QDeclarativeGridView::keyPressEvent(QKeyEvent *event) Move the currentIndex up one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexUp() { @@ -1942,6 +1944,8 @@ void QDeclarativeGridView::moveCurrentIndexUp() Move the currentIndex down one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexDown() { @@ -1965,6 +1969,8 @@ void QDeclarativeGridView::moveCurrentIndexDown() Move the currentIndex left one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexLeft() { @@ -1988,6 +1994,8 @@ void QDeclarativeGridView::moveCurrentIndexLeft() Move the currentIndex right one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexRight() { @@ -2028,6 +2036,14 @@ void QDeclarativeGridView::moveCurrentIndexRight() at a particular index. This is unreliable since removing items from the start of the view does not cause all other items to be repositioned. The correct way to bring an item into view is with \c positionViewAtIndex. + + \bold Note: methods should only be called after the Component has completed. To position + the view at startup, this method should be called by Component.onCompleted. For + example, to position the view at the end: + + \code + Component.onCompleted: positionViewAtIndex(count - 1, GridView.Beginning) + \endcode */ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) { @@ -2097,6 +2113,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. */ int QDeclarativeGridView::indexAt(int x, int y) const { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 35e6bab..35794c2 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2386,6 +2386,8 @@ void QDeclarativeListView::keyPressEvent(QKeyEvent *event) Increments the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeListView::incrementCurrentIndex() { @@ -2403,6 +2405,8 @@ void QDeclarativeListView::incrementCurrentIndex() Decrements the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the beginning. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeListView::decrementCurrentIndex() { @@ -2439,6 +2443,14 @@ void QDeclarativeListView::decrementCurrentIndex() of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates. The correct way to bring an item into view is with \c positionViewAtIndex. + + \bold Note: methods should only be called after the Component has completed. To position + the view at startup, this method should be called by Component.onCompleted. For + example, to position the view at the end: + + \code + Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning) + \endcode */ void QDeclarativeListView::positionViewAtIndex(int index, int mode) { @@ -2509,6 +2521,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. */ int QDeclarativeListView::indexAt(int x, int y) const { diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 0c2d249..0e980b3 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -552,6 +552,8 @@ void QDeclarativePathView::setCurrentIndex(int idx) \qmlmethod PathView::incrementCurrentIndex() Increments the current index. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativePathView::incrementCurrentIndex() { @@ -563,6 +565,8 @@ void QDeclarativePathView::incrementCurrentIndex() \qmlmethod PathView::decrementCurrentIndex() Decrements the current index. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativePathView::decrementCurrentIndex() { -- cgit v0.12 From a75d0052ea25968d05298d9b8622cb331c9af5a2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 24 Jun 2010 10:25:40 +1000 Subject: Use ugly but reliable bitmaps fonts in test. --- .../declarative/qdeclarativetext/data/alignments.qml | 1 + .../qdeclarativetext/data/alignments_cb.png | Bin 1184 -> 528 bytes .../qdeclarativetext/data/alignments_cc.png | Bin 1293 -> 549 bytes .../qdeclarativetext/data/alignments_ct.png | Bin 1237 -> 564 bytes .../qdeclarativetext/data/alignments_lb.png | Bin 1208 -> 522 bytes .../qdeclarativetext/data/alignments_lc.png | Bin 1303 -> 541 bytes .../qdeclarativetext/data/alignments_lt.png | Bin 1241 -> 558 bytes .../qdeclarativetext/data/alignments_rb.png | Bin 1178 -> 530 bytes .../qdeclarativetext/data/alignments_rc.png | Bin 1274 -> 550 bytes .../qdeclarativetext/data/alignments_rt.png | Bin 1221 -> 564 bytes .../qdeclarativetextedit/data/alignments.qml | 1 + .../qdeclarativetextedit/data/alignments_cb.png | Bin 1411 -> 528 bytes .../qdeclarativetextedit/data/alignments_cc.png | Bin 1501 -> 549 bytes .../qdeclarativetextedit/data/alignments_ct.png | Bin 1457 -> 564 bytes .../qdeclarativetextedit/data/alignments_lb.png | Bin 1420 -> 522 bytes .../qdeclarativetextedit/data/alignments_lc.png | Bin 1508 -> 541 bytes .../qdeclarativetextedit/data/alignments_lt.png | Bin 1447 -> 558 bytes .../qdeclarativetextedit/data/alignments_rb.png | Bin 1421 -> 530 bytes .../qdeclarativetextedit/data/alignments_rc.png | Bin 1485 -> 550 bytes .../qdeclarativetextedit/data/alignments_rt.png | Bin 1439 -> 564 bytes 20 files changed, 2 insertions(+) diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments.qml b/tests/auto/declarative/qdeclarativetext/data/alignments.qml index 6a98a4d..b10c335 100644 --- a/tests/auto/declarative/qdeclarativetext/data/alignments.qml +++ b/tests/auto/declarative/qdeclarativetext/data/alignments.qml @@ -20,6 +20,7 @@ Rectangle { id: t anchors.fill: parent + font.family: "Misc Fixed" font.pixelSize: 8 horizontalAlignment: TextEdit.AlignRight verticalAlignment: TextEdit.AlignBottom diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png index 5cdb1e5..b0ad381 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png index 6b6862c..98232ce 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png index 7bfd281..b606ba5 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png index a8c16a0..a8f095d 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png index 1f6e28d..c2a0679 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png index e529880..c019551 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png index c1ce274..08d581a 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png index 4f8a4a7..d607955 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png index 643bd18..2acfb9e 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml index 6a98a4d..b10c335 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml @@ -20,6 +20,7 @@ Rectangle { id: t anchors.fill: parent + font.family: "Misc Fixed" font.pixelSize: 8 horizontalAlignment: TextEdit.AlignRight verticalAlignment: TextEdit.AlignBottom diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png index 0e40444..b0ad381 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png index a5c83a8..98232ce 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png index 8177c20..b606ba5 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png index c0e1774..a8f095d 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png index d61aaf2..c2a0679 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png index 599f4c6..c019551 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png index 83ec990..08d581a 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png index 53e30b7..d607955 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png index 61a112f..2acfb9e 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png differ -- cgit v0.12 From bb3ae9779730b6d4a0442ea5553b0dfab1a3da2b Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 24 Jun 2010 10:31:41 +1000 Subject: Ensure sourcesize is in pixmap cache key. Task-number: QTBUG-11645 --- src/declarative/util/qdeclarativepixmapcache.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index a4ddf46..0a14462 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -510,6 +510,12 @@ bool QDeclarativePixmapReply::event(QEvent *event) else d->errorString = de->errorString; QByteArray key = d->url.toEncoded(QUrl::FormattingOption(0x100)); + if (d->forced_width > 0 || d->forced_height > 0) { + key += ':'; + key += QByteArray::number(d->forced_width); + key += 'x'; + key += QByteArray::number(d->forced_height); + } QString strKey = QString::fromLatin1(key.constData(), key.count()); QPixmapCache::insert(strKey, d->pixmap); // note: may fail (returns false) emit finished(); -- cgit v0.12 From 52b3d6263bb58ca82a8f00d42af801f5ed521f6b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 24 Jun 2010 11:45:59 +1000 Subject: Update lupdate to recognize concatenated text in QML files. Also fixes a potential crash with non-string-literal nodes. Task-number: QTBUG-11580 --- tools/linguist/lupdate/qdeclarative.cpp | 72 +++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp index 1b35c14..3eef2d7 100644 --- a/tools/linguist/lupdate/qdeclarative.cpp +++ b/tools/linguist/lupdate/qdeclarative.cpp @@ -87,17 +87,25 @@ protected: virtual void endVisit(AST::CallExpression *node) { + m_bSource.clear(); if (AST::IdentifierExpression *idExpr = AST::cast(node->base)) { if (idExpr->name->asString() == QLatin1String("qsTr") || idExpr->name->asString() == QLatin1String("QT_TR_NOOP")) { - if (node->arguments && AST::cast(node->arguments->expression)) { - AST::StringLiteral *literal = AST::cast(node->arguments->expression); - const QString source = literal->value->asString(); + if (!node->arguments) + return; + AST::BinaryExpression *binary = AST::cast(node->arguments->expression); + if (binary) { + if (!createString(binary)) + m_bSource.clear(); + } + AST::StringLiteral *literal = AST::cast(node->arguments->expression); + if (literal || !m_bSource.isEmpty()) { + const QString source = literal ? literal->value->asString() : m_bSource; QString comment; bool plural = false; AST::ArgumentList *commentNode = node->arguments->next; - if (commentNode) { + if (commentNode && AST::cast(commentNode->expression)) { literal = AST::cast(commentNode->expression); comment = literal->value->asString(); @@ -122,18 +130,25 @@ protected: QString comment; bool plural = false; AST::ArgumentList *sourceNode = node->arguments->next; - if (sourceNode) { - literal = AST::cast(sourceNode->expression); - source = literal->value->asString(); - AST::ArgumentList *commentNode = sourceNode->next; - if (commentNode) { - literal = AST::cast(commentNode->expression); - comment = literal->value->asString(); - - AST::ArgumentList *nNode = commentNode->next; - if (nNode) - plural = true; - } + if (!sourceNode) + return; + literal = AST::cast(sourceNode->expression); + AST::BinaryExpression *binary = AST::cast(sourceNode->expression); + if (binary) { + if (!createString(binary)) + m_bSource.clear(); + } + if (!literal && m_bSource.isEmpty()) + return; + source = literal ? literal->value->asString() : m_bSource; + AST::ArgumentList *commentNode = sourceNode->next; + if (commentNode && AST::cast(commentNode->expression)) { + literal = AST::cast(commentNode->expression); + comment = literal->value->asString(); + + AST::ArgumentList *nNode = commentNode->next; + if (nNode) + plural = true; } TranslatorMessage msg(context, source, @@ -148,9 +163,34 @@ protected: } private: + bool createString(AST::BinaryExpression *b) { + if (!b or b->op != 0) + return false; + AST::BinaryExpression *l = AST::cast(b->left); + AST::BinaryExpression *r = AST::cast(b->right); + AST::StringLiteral *ls = AST::cast(b->left); + AST::StringLiteral *rs = AST::cast(b->right); + if ((!l && !ls) || (!r && !rs)) + return false; + if (l) { + if (!createString(l)) + return false; + } else + m_bSource.prepend(ls->value->asString()); + + if (r) { + if (!createString(r)) + return false; + } else + m_bSource.append(rs->value->asString()); + + return true; + } + Translator *m_translator; QString m_fileName; QString m_component; + QString m_bSource; }; QString createErrorString(const QString &filename, const QString &code, Parser &parser) -- cgit v0.12 From 5d64484bf0b37427133c163ad9b160e767dc1bcd Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 24 Jun 2010 13:43:25 +1000 Subject: Script benchmarking. --- tests/benchmarks/declarative/script/data/block.qml | 6 +-- tests/benchmarks/declarative/script/data/global.js | 45 +++++++++++++++++ .../declarative/script/data/global_prop.qml | 54 +++++++++++++++++++++ tests/benchmarks/declarative/script/tst_script.cpp | 56 +++++++++++++++++++++- 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 tests/benchmarks/declarative/script/data/global.js create mode 100644 tests/benchmarks/declarative/script/data/global_prop.qml diff --git a/tests/benchmarks/declarative/script/data/block.qml b/tests/benchmarks/declarative/script/data/block.qml index 4e5006e..f7b2ab3 100644 --- a/tests/benchmarks/declarative/script/data/block.qml +++ b/tests/benchmarks/declarative/script/data/block.qml @@ -47,7 +47,7 @@ Rectangle { function doSomethingDirect() { theObject.prop1 = 0; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += theObject.prop2; theObject.prop3 = theObject.prop1; @@ -57,7 +57,7 @@ Rectangle { theObject.prop1 = 0; var incrementObj = theObject; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) incrementObj.prop1 += incrementObj.prop2; incrementObj.prop3 = incrementObj.prop1; @@ -67,7 +67,7 @@ Rectangle { theObject.prop1 = 0; var increment = theObject.prop2; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += increment; theObject.prop3 = theObject.prop1; diff --git a/tests/benchmarks/declarative/script/data/global.js b/tests/benchmarks/declarative/script/data/global.js new file mode 100644 index 0000000..02472d2 --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global.js @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +function doSomething() { + for (var i = 0; i < 10000; ++i) + Math.sin(90); +} diff --git a/tests/benchmarks/declarative/script/data/global_prop.qml b/tests/benchmarks/declarative/script/data/global_prop.qml new file mode 100644 index 0000000..908cecf --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global_prop.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import "global.js" as Program + +Rectangle { + width: 200; height: 200 + + signal triggered + onTriggered: Program.doSomething(); + + function doSomething() { + Program.doSomething(); + } +} diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 99f294c..16052fa 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -92,7 +92,10 @@ private slots: void block_data(); void block(); -private: + + void global_property_js(); + void global_property_qml(); + void global_property_qml_js(); }; inline QUrl TEST_FILE(const QString &filename) @@ -625,6 +628,57 @@ void tst_script::block() delete rect; } +#define GLOBALPROPERTY_PROGRAM \ + "(function() { " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " Math.sin(90); " \ + " } " \ + "})" + +void tst_script::global_property_js() +{ + QScriptEngine engine; + + QScriptValue prog = engine.evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml() +{ + QDeclarativeEngine qmlengine; + + QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine); + QScriptValue prog = engine->evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml_js() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("triggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + + QTEST_MAIN(tst_script) #include "tst_script.moc" -- cgit v0.12 From 9d6ccfea89ae99b747f70ece71185868f189d0f9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 24 Jun 2010 14:19:45 +1000 Subject: Expose the Flickable's internal contentItem So that dynamically created items can be parented to the contentItem and be flicked with the rest of the content. Task-number: QTBUG-11674 Reviewed-by: Aaron Kennedy --- .../graphicsitems/qdeclarativeflickable.cpp | 52 +++++++++++++++------- .../graphicsitems/qdeclarativeflickable_p.h | 3 +- .../graphicsitems/qdeclarativeflickable_p_p.h | 2 +- .../graphicsitems/qdeclarativegridview.cpp | 20 ++++----- .../graphicsitems/qdeclarativelistview.cpp | 24 +++++----- .../qdeclarativeflickable/data/flickable04.qml | 6 +++ .../tst_qdeclarativeflickable.cpp | 4 ++ 7 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 3f681b7..65bc233 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -122,7 +122,7 @@ void QDeclarativeFlickableVisibleArea::updateVisible() QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() - : viewport(new QDeclarativeItem) + : contentItem(new QDeclarativeItem) , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) , flickingHorizontally(false), flickingVertically(false) @@ -140,8 +140,8 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() void QDeclarativeFlickablePrivate::init() { Q_Q(QDeclarativeFlickable); - QDeclarative_setParent_noEvent(viewport, q); - viewport->setParentItem(q); + QDeclarative_setParent_noEvent(contentItem, q); + contentItem->setParentItem(q); static int timelineUpdatedIdx = -1; static int timelineCompletedIdx = -1; static int flickableTickedIdx = -1; @@ -158,7 +158,7 @@ void QDeclarativeFlickablePrivate::init() q, flickableMovementEndingIdx, Qt::DirectConnection); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFiltersChildEvents(true); - QDeclarativeItemPrivate *viewportPrivate = static_cast(QGraphicsItemPrivate::get(viewport)); + QDeclarativeItemPrivate *viewportPrivate = static_cast(QGraphicsItemPrivate::get(contentItem)); viewportPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); lastPosTime.invalidate(); } @@ -182,7 +182,7 @@ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size void QDeclarativeFlickablePrivate::itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeom, const QRectF &oldGeom) { Q_Q(QDeclarativeFlickable); - if (item == viewport) { + if (item == contentItem) { if (newGeom.x() != oldGeom.x()) emit q->contentXChanged(); if (newGeom.y() != oldGeom.y()) @@ -579,10 +579,28 @@ void QDeclarativeFlickable::ticked() viewportMoved(); } -QDeclarativeItem *QDeclarativeFlickable::viewport() +/*! + \qmlproperty Item Flickable::contentItem + + The internal item that contains the Items to be moved in the Flickable. + + Items declared as children of a Flickable are automatically parented to the Flickable's contentItem. + + Items created dynamically need to be explicitly parented to the \e contentItem: + \code + Flickable { + id: myFlickable + function addItem(file) { + var component = Qt.createComponent(file) + component.createObject(myFlickable.contentItem); + } + } + \endcode +*/ +QDeclarativeItem *QDeclarativeFlickable::contentItem() { Q_D(QDeclarativeFlickable); - return d->viewport; + return d->contentItem; } QDeclarativeFlickableVisibleArea *QDeclarativeFlickable::visibleArea() @@ -899,12 +917,12 @@ void QDeclarativeFlickablePrivate::clearDelayedPress() void QDeclarativeFlickablePrivate::setRoundedViewportX(qreal x) { - viewport->setX(qRound(x)); + contentItem->setX(qRound(x)); } void QDeclarativeFlickablePrivate::setRoundedViewportY(qreal y) { - viewport->setY(qRound(y)); + contentItem->setY(qRound(y)); } void QDeclarativeFlickable::timerEvent(QTimerEvent *event) @@ -991,13 +1009,13 @@ void QDeclarativeFlickable::geometryChanged(const QRectF &newGeometry, bool changed = false; if (newGeometry.width() != oldGeometry.width()) { if (d->hData.viewSize < 0) { - d->viewport->setWidth(width()); + d->contentItem->setWidth(width()); emit contentWidthChanged(); } } if (newGeometry.height() != oldGeometry.height()) { if (d->vData.viewSize < 0) { - d->viewport->setHeight(height()); + d->contentItem->setHeight(height()); emit contentHeightChanged(); } } @@ -1018,7 +1036,7 @@ void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty { QDeclarativeItem *i = qobject_cast(o); if (i) - i->setParentItem(static_cast(prop->data)->viewport); + i->setParentItem(static_cast(prop->data)->contentItem); else o->setParent(prop->object); } @@ -1032,7 +1050,7 @@ QDeclarativeListProperty QDeclarativeFlickable::flickableData() QDeclarativeListProperty QDeclarativeFlickable::flickableChildren() { Q_D(QDeclarativeFlickable); - return QGraphicsItemPrivate::get(d->viewport)->childrenList(); + return QGraphicsItemPrivate::get(d->contentItem)->childrenList(); } /*! @@ -1102,9 +1120,9 @@ void QDeclarativeFlickable::setContentWidth(qreal w) return; d->hData.viewSize = w; if (w < 0) - d->viewport->setWidth(width()); + d->contentItem->setWidth(width()); else - d->viewport->setWidth(w); + d->contentItem->setWidth(w); // Make sure that we're entirely in view. if (!d->pressed && !d->movingHorizontally && !d->movingVertically) { int oldDuration = d->fixupDuration; @@ -1129,9 +1147,9 @@ void QDeclarativeFlickable::setContentHeight(qreal h) return; d->vData.viewSize = h; if (h < 0) - d->viewport->setHeight(height()); + d->contentItem->setHeight(height()); else - d->viewport->setHeight(h); + d->contentItem->setHeight(h); // Make sure that we're entirely in view. if (!d->pressed && !d->movingHorizontally && !d->movingVertically) { int oldDuration = d->fixupDuration; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index d40a0dc..be4846e 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged) Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged) + Q_PROPERTY(QDeclarativeItem *contentItem READ contentItem CONSTANT) Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) @@ -143,7 +144,7 @@ public: bool isAtYEnd() const; bool isAtYBeginning() const; - QDeclarativeItem *viewport(); + QDeclarativeItem *contentItem(); enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 }; FlickableDirection flickDirection() const; // deprecated diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 66d2678..b919e1b 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -125,7 +125,7 @@ public: void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &); public: - QDeclarativeItem *viewport; + QDeclarativeItem *contentItem; AxisData hData; AxisData vData; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 14980a8..af9b04e 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -421,10 +421,10 @@ FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); model->completeItem(); } else { - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); } unrequestedItems.remove(listItem->item); } @@ -716,12 +716,12 @@ void QDeclarativeGridViewPrivate::createHighlight() } } else { item = new QDeclarativeItem; - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); highlight = new FxGridItem(item, q); highlightXAnimator = new QSmoothedAnimation(q); highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x")); @@ -808,8 +808,8 @@ void QDeclarativeGridViewPrivate::updateFooter() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -854,8 +854,8 @@ void QDeclarativeGridViewPrivate::updateHeader() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 35794c2..59bb178 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -421,7 +421,7 @@ public: void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { Q_Q(QDeclarativeListView); QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (item != viewport && (!highlight || item != highlight->item)) { + if (item != contentItem && (!highlight || item != highlight->item)) { if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) { scheduleLayout(); @@ -580,10 +580,10 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); model->completeItem(); } else { - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); } QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -840,8 +840,8 @@ void QDeclarativeListViewPrivate::createHighlight() item = new QDeclarativeItem; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); highlight = new FxListItem(item, q); if (currentItem && autoHighlight) { if (orient == QDeclarativeListView::Vertical) { @@ -921,8 +921,8 @@ void QDeclarativeListViewPrivate::createSection(FxListItem *listItem) delete nobj; } else { listItem->section->setZValue(1); - QDeclarative_setParent_noEvent(listItem->section, q->viewport()); - listItem->section->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(listItem->section, q->contentItem()); + listItem->section->setParentItem(q->contentItem()); } } else { delete context; @@ -1046,8 +1046,8 @@ void QDeclarativeListViewPrivate::updateFooter() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -1086,8 +1086,8 @@ void QDeclarativeListViewPrivate::updateHeader() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -2983,7 +2983,7 @@ void QDeclarativeListView::createdItem(int index, QDeclarativeItem *item) { Q_D(QDeclarativeListView); if (d->requestedIndex != index) { - item->setParentItem(viewport()); + item->setParentItem(contentItem()); d->unrequestedItems.insert(item, index); if (d->orient == QDeclarativeListView::Vertical) item->setY(d->positionAt(index)); diff --git a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml index aa156ed..a840a01 100644 --- a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml +++ b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml @@ -1,6 +1,12 @@ import Qt 4.7 Flickable { + property bool ok: false + function check() { + if (column.parent == contentItem) + ok = true; + } + width: 100; height: 100 contentWidth: column.width; contentHeight: column.height pressDelay: 200; boundsBehavior: Flickable.StopAtBounds; interactive: false diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index 2ba5574..678996b 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -147,6 +147,10 @@ void tst_qdeclarativeflickable::properties() QCOMPARE(obj->pressDelay(), 200); QCOMPARE(obj->maximumFlickVelocity(), 2000.); + QVERIFY(obj->property("ok").toBool() == false); + QMetaObject::invokeMethod(obj, "check"); + QVERIFY(obj->property("ok").toBool() == true); + delete obj; } -- cgit v0.12 From 2bae9da77fbc6407ddb24d0fe8135698092cbb6a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 24 Jun 2010 14:28:18 +1000 Subject: More script benchmarking. --- tests/benchmarks/declarative/script/data/global.js | 9 +++++++++ .../declarative/script/data/global_prop.qml | 7 +++---- tests/benchmarks/declarative/script/tst_script.cpp | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/benchmarks/declarative/script/data/global.js b/tests/benchmarks/declarative/script/data/global.js index 02472d2..5b86b4d 100644 --- a/tests/benchmarks/declarative/script/data/global.js +++ b/tests/benchmarks/declarative/script/data/global.js @@ -39,7 +39,16 @@ ** ****************************************************************************/ +var incVar = 1; +var total; + function doSomething() { for (var i = 0; i < 10000; ++i) Math.sin(90); } + +function doIncrement() { + total = 0; + for (var i = 0; i < 100000; ++i) + total += incVar; +} diff --git a/tests/benchmarks/declarative/script/data/global_prop.qml b/tests/benchmarks/declarative/script/data/global_prop.qml index 908cecf..4fb7ee7 100644 --- a/tests/benchmarks/declarative/script/data/global_prop.qml +++ b/tests/benchmarks/declarative/script/data/global_prop.qml @@ -46,9 +46,8 @@ Rectangle { width: 200; height: 200 signal triggered - onTriggered: Program.doSomething(); + signal incrementTriggered - function doSomething() { - Program.doSomething(); - } + onTriggered: Program.doSomething(); + onIncrementTriggered: Program.doIncrement(); } diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 16052fa..5a7e151 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -96,6 +96,8 @@ private slots: void global_property_js(); void global_property_qml(); void global_property_qml_js(); + + void scriptfile_property(); }; inline QUrl TEST_FILE(const QString &filename) @@ -678,6 +680,23 @@ void tst_script::global_property_qml_js() delete rect; } +void tst_script::scriptfile_property() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("incrementTriggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} QTEST_MAIN(tst_script) -- cgit v0.12 From ae422458fdbd9a2cdbc48024b31f7e5528baebb4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 24 Jun 2010 14:33:51 +1000 Subject: Make compile. --- tools/linguist/lupdate/qdeclarative.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp index 3eef2d7..2377416 100644 --- a/tools/linguist/lupdate/qdeclarative.cpp +++ b/tools/linguist/lupdate/qdeclarative.cpp @@ -164,7 +164,7 @@ protected: private: bool createString(AST::BinaryExpression *b) { - if (!b or b->op != 0) + if (!b || b->op != 0) return false; AST::BinaryExpression *l = AST::cast(b->left); AST::BinaryExpression *r = AST::cast(b->right); -- cgit v0.12 From f2fc1355306219eaec9042462d3be4aceed1b829 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 24 Jun 2010 14:46:55 +1000 Subject: Prevent value source animations from being registered to start twice. If the animation had an explicit "running: true", the animation would be registered with the engine twice, which prevented a proper start. --- src/declarative/util/qdeclarativeanimation.cpp | 2 ++ .../qdeclarativeanimations/data/runningTrueBug.qml | 30 ++++++++++++++++++++++ .../tst_qdeclarativeanimations.cpp | 15 +++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index f807866..add27f3 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -176,6 +176,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) { Q_D(QDeclarativeAbstractAnimation); if (!d->componentComplete) { + if (d->running && r == d->running) //don't re-register + return; d->running = r; if (r == false) d->avoidPropertyValueSourceStart = true; diff --git a/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml b/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml new file mode 100644 index 0000000..2c5207e --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml @@ -0,0 +1,30 @@ +import Qt 4.7 +Rectangle { + color: "skyblue" + width: 500 + height: 200 + Rectangle { + objectName: "cloud" + color: "white" + y: 50 + width: 100 + height: 100 + + SequentialAnimation on x { + loops: Animation.Infinite + running: true + NumberAnimation { + id: firstAnimation + from: 0 + to: 500 + duration: 5000 + } + NumberAnimation { + id: secondAnimation + from: -100 + to: 0 + duration: 1000 + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 5cf4c23..a965ef3 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -81,6 +81,7 @@ private slots: void dontStart(); void easingProperties(); void rotation(); + void runningTrueBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -733,6 +734,20 @@ void tst_qdeclarativeanimations::rotation() QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4)); } +void tst_qdeclarativeanimations::runningTrueBug() +{ + //ensure we start correctly when "running: true" is explicitly set + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrueBug.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *cloud = rect->findChild("cloud"); + QVERIFY(cloud); + QTest::qWait(1000); + QVERIFY(cloud->x() > qreal(0)); +} + QTEST_MAIN(tst_qdeclarativeanimations) #include "tst_qdeclarativeanimations.moc" -- cgit v0.12 From 29a406e3622ba44ccf35c6913fbb4ad098674092 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 24 Jun 2010 15:14:14 +1000 Subject: Update tests following QDeclarativeFlickable::viewport() -> contentIem() --- .../tst_qdeclarativegridview.cpp | 178 +++++++-------- .../tst_qdeclarativelistview.cpp | 244 ++++++++++----------- .../tst_qdeclarativevisualdatamodel.cpp | 6 +- 3 files changed, 214 insertions(+), 214 deletions(-) diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index deff1f8..a67c56f 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -178,17 +178,17 @@ void tst_QDeclarativeGridView::items() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->count(), model.count()); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { - QDeclarativeText *name = findItem(viewport, "textName", i); + QDeclarativeText *name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem(viewport, "textNumber", i); + QDeclarativeText *number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -197,7 +197,7 @@ void tst_QDeclarativeGridView::items() TestModel model2; ctxt->setContextProperty("testModel", &model2); - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); QTRY_VERIFY(itemCount == 0); delete canvas; @@ -226,14 +226,14 @@ void tst_QDeclarativeGridView::changed() QDeclarativeFlickable *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.modifyItem(1, "Will", "9876"); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -259,17 +259,17 @@ void tst_QDeclarativeGridView::inserted() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.insertItem(1, "Will", "9876"); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -279,19 +279,19 @@ void tst_QDeclarativeGridView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); QTRY_COMPARE(item->x(), (i%3)*80.0); QTRY_COMPARE(item->y(), (i/3)*60.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - name = findItem(viewport, "textName", 0); + name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); @@ -299,7 +299,7 @@ void tst_QDeclarativeGridView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); QTRY_VERIFY(item->x() == (i%3)*80); QTRY_VERIFY(item->y() == (i/3)*60); } @@ -335,15 +335,15 @@ void tst_QDeclarativeGridView::removed() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.removeItem(1); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -352,9 +352,9 @@ void tst_QDeclarativeGridView::removed() QTRY_COMPARE(removed, QString("Item1")); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -364,17 +364,17 @@ void tst_QDeclarativeGridView::removed() // Remove first item (which is the current item); model.removeItem(0); - name = findItem(viewport, "textName", 0); + name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -385,9 +385,9 @@ void tst_QDeclarativeGridView::removed() model.removeItem(25); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -405,7 +405,7 @@ void tst_QDeclarativeGridView::removed() // Confirm items positioned correctly for (int i = 6; i < 18; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -424,9 +424,9 @@ void tst_QDeclarativeGridView::removed() QTest::qWait(100); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -478,29 +478,29 @@ void tst_QDeclarativeGridView::moved() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.moveItem(1, 8); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); - name = findItem(viewport, "textName", 8); + name = findItem(contentItem, "textName", 8); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(8)); - number = findItem(viewport, "textNumber", 8); + number = findItem(contentItem, "textNumber", 8); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(8)); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -513,17 +513,17 @@ void tst_QDeclarativeGridView::moved() model.moveItem(1, 25); // Confirm items positioned correctly and indexes correct - itemCount = findItems(viewport, "wrapper").count()-1; + itemCount = findItems(contentItem, "wrapper").count()-1; for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_COMPARE(item->y(), qreal((i/3)*60)); - name = findItem(viewport, "textName", i); + name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); + number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -533,15 +533,15 @@ void tst_QDeclarativeGridView::moved() // Confirm items positioned correctly and indexes correct for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); QTRY_VERIFY(item->y() == (i/3)*60); - name = findItem(viewport, "textName", i); + name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); + number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -574,12 +574,12 @@ void tst_QDeclarativeGridView::currentIndex() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QVERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QVERIFY(contentItem != 0); // current item should be third item QCOMPARE(gridview->currentIndex(), 35); - QCOMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 35)); + QCOMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 35)); QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); QCOMPARE(gridview->contentY(), 399.0); @@ -696,21 +696,21 @@ void tst_QDeclarativeGridView::changeFlow() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly and indexes correct - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_COMPARE(item->y(), qreal((i/3)*60)); - QDeclarativeText *name = findItem(viewport, "textName", i); + QDeclarativeText *name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem(viewport, "textNumber", i); + QDeclarativeText *number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -718,17 +718,17 @@ void tst_QDeclarativeGridView::changeFlow() ctxt->setContextProperty("testTopToBottom", QVariant(true)); // Confirm items positioned correctly and indexes correct - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i/5)*80)); QTRY_COMPARE(item->y(), qreal((i%5)*60)); - QDeclarativeText *name = findItem(viewport, "textName", i); + QDeclarativeText *name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem(viewport, "textNumber", i); + QDeclarativeText *number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -914,13 +914,13 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -932,9 +932,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 60.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -946,9 +946,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 420.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -960,9 +960,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 520.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -974,9 +974,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 0.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -1044,13 +1044,13 @@ void tst_QDeclarativeGridView::resetModel() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem(viewport, "displayText", i); + QDeclarativeText *display = findItem(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1062,7 +1062,7 @@ void tst_QDeclarativeGridView::resetModel() QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem(viewport, "displayText", i); + QDeclarativeText *display = findItem(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1089,22 +1089,22 @@ void tst_QDeclarativeGridView::enforceRange() QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(gridview->highlightRangeMode(), QDeclarativeGridView::StrictlyEnforceRange); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // view should be positioned at the top of the range. - QDeclarativeItem *item = findItem(viewport, "wrapper", 0); + QDeclarativeItem *item = findItem(contentItem, "wrapper", 0); QTRY_VERIFY(item); QTRY_COMPARE(gridview->contentY(), -100.0); - QDeclarativeText *name = findItem(viewport, "textName", 0); + QDeclarativeText *name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - QDeclarativeText *number = findItem(viewport, "textNumber", 0); + QDeclarativeText *number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); - // Check currentIndex is updated when viewport moves + // Check currentIndex is updated when contentItem moves gridview->setContentY(0); QTRY_COMPARE(gridview->currentIndex(), 2); @@ -1146,18 +1146,18 @@ void tst_QDeclarativeGridView::manualHighlight() QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->currentIndex(), 0); - QTRY_COMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 0)); + QTRY_COMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 0)); QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); gridview->setCurrentIndex(2); QTRY_COMPARE(gridview->currentIndex(), 2); - QTRY_COMPARE(gridview->currentItem(), findItem(viewport, "wrapper", 2)); + QTRY_COMPARE(gridview->currentItem(), findItem(contentItem, "wrapper", 2)); QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); } diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 8ff6e56..048f0f3 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -336,24 +336,24 @@ void tst_QDeclarativeListView::items() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QTRY_VERIFY(testObject->error() == false); QTRY_VERIFY(listview->highlightItem() != 0); QTRY_COMPARE(listview->count(), model.count()); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item // current item should be first item - QTRY_COMPARE(listview->currentItem(), findItem(viewport, "wrapper", 0)); + QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 0)); for (int i = 0; i < model.count(); ++i) { - QDeclarativeText *name = findItem(viewport, "textName", i); + QDeclarativeText *name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem(viewport, "textNumber", i); + QDeclarativeText *number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -382,7 +382,7 @@ void tst_QDeclarativeListView::items() T model2; ctxt->setContextProperty("testModel", &model2); - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); QTRY_VERIFY(itemCount == 0); QTRY_COMPARE(listview->highlightResizeSpeed(), 1000.0); @@ -414,14 +414,14 @@ void tst_QDeclarativeListView::changed() QDeclarativeFlickable *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.modifyItem(1, "Will", "9876"); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -450,34 +450,34 @@ void tst_QDeclarativeListView::inserted() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.insertItem(1, "Will", "9876"); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); QTRY_COMPARE(item->y(), i*20.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - name = findItem(viewport, "textName", 0); + name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); @@ -485,7 +485,7 @@ void tst_QDeclarativeListView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); QTRY_COMPARE(item->y(), i*20.0); } @@ -501,13 +501,13 @@ void tst_QDeclarativeListView::inserted() // Confirm items positioned correctly for (int i = 5; i < 5+15; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 - 20.0); } -// QTRY_COMPARE(listview->viewportHeight(), model.count() * 20.0); +// QTRY_COMPARE(listview->contentItemHeight(), model.count() * 20.0); delete canvas; } @@ -534,22 +534,22 @@ void tst_QDeclarativeListView::removed(bool animated) QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.removeItem(1); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -560,17 +560,17 @@ void tst_QDeclarativeListView::removed(bool animated) QTest::qWait(300); - name = findItem(viewport, "textName", 0); + name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),i*20.0 + 20.0); @@ -581,9 +581,9 @@ void tst_QDeclarativeListView::removed(bool animated) qApp->processEvents(); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),i*20.0+20.0); @@ -598,7 +598,7 @@ void tst_QDeclarativeListView::removed(bool animated) // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),40+i*20.0); @@ -617,9 +617,9 @@ void tst_QDeclarativeListView::removed(bool animated) QTest::qWait(300); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),40+i*20.0); @@ -665,8 +665,8 @@ void tst_QDeclarativeListView::clear() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.clear(); @@ -699,29 +699,29 @@ void tst_QDeclarativeListView::moved() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.moveItem(1, 4); - QDeclarativeText *name = findItem(viewport, "textName", 1); + QDeclarativeText *name = findItem(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem(viewport, "textNumber", 1); + QDeclarativeText *number = findItem(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); - name = findItem(viewport, "textName", 4); + name = findItem(contentItem, "textName", 4); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(4)); - number = findItem(viewport, "textNumber", 4); + number = findItem(contentItem, "textNumber", 4); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(4)); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -734,14 +734,14 @@ void tst_QDeclarativeListView::moved() // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 + 20); - name = findItem(viewport, "textName", i); + name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); + number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -751,14 +751,14 @@ void tst_QDeclarativeListView::moved() // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 + 20); - name = findItem(viewport, "textName", i); + name = findItem(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); + number = findItem(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -787,22 +787,22 @@ void tst_QDeclarativeListView::enforceRange() QTRY_COMPARE(listview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(listview->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // view should be positioned at the top of the range. - QDeclarativeItem *item = findItem(viewport, "wrapper", 0); + QDeclarativeItem *item = findItem(contentItem, "wrapper", 0); QTRY_VERIFY(item); QTRY_COMPARE(listview->contentY(), -100.0); - QDeclarativeText *name = findItem(viewport, "textName", 0); + QDeclarativeText *name = findItem(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - QDeclarativeText *number = findItem(viewport, "textNumber", 0); + QDeclarativeText *number = findItem(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); - // Check currentIndex is updated when viewport moves + // Check currentIndex is updated when contentItem moves listview->setContentY(20); QTRY_COMPARE(listview->currentIndex(), 6); @@ -838,13 +838,13 @@ void tst_QDeclarativeListView::spacing() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -854,9 +854,9 @@ void tst_QDeclarativeListView::spacing() QTRY_VERIFY(listview->spacing() == 10); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*30); @@ -865,9 +865,9 @@ void tst_QDeclarativeListView::spacing() listview->setSpacing(0); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0); @@ -893,13 +893,13 @@ void tst_QDeclarativeListView::sections() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); QTRY_VERIFY(item); QTRY_COMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); } @@ -908,29 +908,29 @@ void tst_QDeclarativeListView::sections() model.removeItem(5); // New section header created - QDeclarativeItem *item = findItem(viewport, "wrapper", 5); + QDeclarativeItem *item = findItem(contentItem, "wrapper", 5); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); model.insertItem(3, "New Item", "0"); // Section header moved - item = findItem(viewport, "wrapper", 5); + item = findItem(contentItem, "wrapper", 5); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); - item = findItem(viewport, "wrapper", 6); + item = findItem(contentItem, "wrapper", 6); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); // insert item which will become a section header model.insertItem(6, "Replace header", "1"); - item = findItem(viewport, "wrapper", 6); + item = findItem(contentItem, "wrapper", 6); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); - item = findItem(viewport, "wrapper", 7); + item = findItem(contentItem, "wrapper", 7); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); @@ -942,7 +942,7 @@ void tst_QDeclarativeListView::sections() listview->setContentY(20); QTRY_COMPARE(listview->currentSection(), QString("0")); - item = findItem(viewport, "wrapper", 1); + item = findItem(contentItem, "wrapper", 1); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); @@ -970,14 +970,14 @@ void tst_QDeclarativeListView::currentIndex() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // current item should be 20th item at startup // and current item should be in view QCOMPARE(listview->currentIndex(), 20); QCOMPARE(listview->contentY(), 99.0); - QCOMPARE(listview->currentItem(), findItem(viewport, "wrapper", 20)); + QCOMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 20)); QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // no wrap @@ -1051,8 +1051,8 @@ void tst_QDeclarativeListView::itemList() QDeclarativeListView *listview = findItem(canvas->rootObject(), "view"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QDeclarativeVisualItemModel *model = canvas->rootObject()->findChild("itemModel"); QTRY_VERIFY(model != 0); @@ -1060,21 +1060,21 @@ void tst_QDeclarativeListView::itemList() QTRY_VERIFY(model->count() == 3); QTRY_COMPARE(listview->currentIndex(), 0); - QDeclarativeItem *item = findItem(viewport, "item1"); + QDeclarativeItem *item = findItem(contentItem, "item1"); QTRY_VERIFY(item); QTRY_COMPARE(item->x(), 0.0); - QDeclarativeText *text = findItem(viewport, "text1"); + QDeclarativeText *text = findItem(contentItem, "text1"); QTRY_VERIFY(text); QTRY_COMPARE(text->text(), QLatin1String("index: 0")); listview->setCurrentIndex(2); - item = findItem(viewport, "item3"); + item = findItem(contentItem, "item3"); QTRY_VERIFY(item); QTRY_COMPARE(item->x(), 480.0); - text = findItem(viewport, "text3"); + text = findItem(contentItem, "text3"); QTRY_VERIFY(text); QTRY_COMPARE(text->text(), QLatin1String("index: 2")); @@ -1101,16 +1101,16 @@ void tst_QDeclarativeListView::cacheBuffer() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_VERIFY(listview->delegate() != 0); QTRY_VERIFY(listview->model() != 0); QTRY_VERIFY(listview->highlight() != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1119,12 +1119,12 @@ void tst_QDeclarativeListView::cacheBuffer() testObject->setCacheBuffer(400); QTRY_VERIFY(listview->cacheBuffer() == 400); - int newItemCount = findItems(viewport, "wrapper").count(); + int newItemCount = findItems(contentItem, "wrapper").count(); QTRY_VERIFY(newItemCount > itemCount); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1153,13 +1153,13 @@ void tst_QDeclarativeListView::positionViewAtIndex() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1170,9 +1170,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 60.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1183,9 +1183,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 440.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1196,9 +1196,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 480.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1209,9 +1209,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 0.); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1278,13 +1278,13 @@ void tst_QDeclarativeListView::resetModel() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem(viewport, "displayText", i); + QDeclarativeText *display = findItem(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1296,7 +1296,7 @@ void tst_QDeclarativeListView::resetModel() QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem(viewport, "displayText", i); + QDeclarativeText *display = findItem(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1455,8 +1455,8 @@ void tst_QDeclarativeListView::QTBUG_9791() QDeclarativeListView *listview = qobject_cast(canvas->rootObject()); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_VERIFY(listview->delegate() != 0); QTRY_VERIFY(listview->model() != 0); @@ -1464,11 +1464,11 @@ void tst_QDeclarativeListView::QTBUG_9791() qApp->processEvents(); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); QVERIFY(itemCount == 3); for (int i = 0; i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), i*300.0); @@ -1495,17 +1495,17 @@ void tst_QDeclarativeListView::manualHighlight() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(listview->currentIndex(), 0); - QTRY_COMPARE(listview->currentItem(), findItem(viewport, "wrapper", 0)); + QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 0)); QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); listview->setCurrentIndex(2); QTRY_COMPARE(listview->currentIndex(), 2); - QTRY_COMPARE(listview->currentItem(), findItem(viewport, "wrapper", 2)); + QTRY_COMPARE(listview->currentItem(), findItem(contentItem, "wrapper", 2)); QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); } @@ -1529,13 +1529,13 @@ void tst_QDeclarativeListView::QTBUG_11105() QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem(viewport, "wrapper", i); + QDeclarativeItem *item = findItem(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1550,7 +1550,7 @@ void tst_QDeclarativeListView::QTBUG_11105() ctxt->setContextProperty("testModel", &model2); - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(contentItem, "wrapper").count(); QCOMPARE(itemCount, 5); delete canvas; diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 90c9c6f..43d4d06 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -173,10 +173,10 @@ void tst_qdeclarativevisualdatamodel::objectListModel() QDeclarativeListView *listview = qobject_cast(view.rootObject()); QVERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QVERIFY(contentItem != 0); - QDeclarativeText *name = findItem(viewport, "name", 0); + QDeclarativeText *name = findItem(contentItem, "name", 0); QCOMPARE(name->text(), QString("Item 1")); dataList[0]->setProperty("name", QLatin1String("Changed")); -- cgit v0.12 From 768209aebcbc66fec3a600be0a0f0e58d9f405d8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 24 Jun 2010 15:56:05 +1000 Subject: Restore neutral movement state if a view is manually positioned. Make sure the previous movement state is cancelled if contentX or contentY are set directly. Task-number: QTBUG-11650 --- .../graphicsitems/qdeclarativeflickable_p.h | 4 ++-- .../graphicsitems/qdeclarativegridview.cpp | 21 +++++++++++++++++++-- .../graphicsitems/qdeclarativegridview_p.h | 3 +++ .../graphicsitems/qdeclarativelistview.cpp | 21 +++++++++++++++++++-- .../graphicsitems/qdeclarativelistview_p.h | 3 +++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index be4846e..eb738d9 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -112,10 +112,10 @@ public: void setContentHeight(qreal); qreal contentX() const; - void setContentX(qreal pos); + virtual void setContentX(qreal pos); qreal contentY() const; - void setContentY(qreal pos); + virtual void setContentY(qreal pos); bool isMoving() const; bool isMovingHorizontally() const; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index af9b04e..dda1efb 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -151,9 +151,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeGridView); if (flow == QDeclarativeGridView::LeftToRight) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } int size() const { Q_Q(const QDeclarativeGridView); @@ -1742,6 +1742,22 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeGridView::setContentX(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeGridView::setContentY(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeGridView::event(QEvent *event) { Q_D(QDeclarativeGridView); @@ -2144,6 +2160,7 @@ void QDeclarativeGridView::componentComplete() d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } + d->moveReason = QDeclarativeGridViewPrivate::Other; d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 021aad9..64b91d8 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -151,6 +151,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + enum PositionMode { Beginning, Center, End, Visible, Contain }; Q_INVOKABLE void positionViewAtIndex(int index, int mode); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 59bb178..6fc066d 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -216,9 +216,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeListView); if (orient == QDeclarativeListView::Vertical) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } qreal size() const { Q_Q(const QDeclarativeListView); @@ -2182,6 +2182,22 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeListView::setContentX(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeListView::setContentY(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeListView::event(QEvent *event) { Q_D(QDeclarativeListView); @@ -2551,6 +2567,7 @@ void QDeclarativeListView::componentComplete() d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } + d->moveReason = QDeclarativeListViewPrivate::Other; d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index d6e8023..505f659 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -198,6 +198,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *); enum PositionMode { Beginning, Center, End, Visible, Contain }; -- cgit v0.12 From d86679ee600bd26788b5bbcd27abf078f0ec948c Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 24 Jun 2010 13:48:05 +0200 Subject: Fix import path in cppextensions declarative example. Reviewed-by: Erik Verbruggen --- examples/declarative/cppextensions/cppextensions.qmlproject | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/cppextensions/cppextensions.qmlproject b/examples/declarative/cppextensions/cppextensions.qmlproject index d4909f8..6b36284 100644 --- a/examples/declarative/cppextensions/cppextensions.qmlproject +++ b/examples/declarative/cppextensions/cppextensions.qmlproject @@ -12,5 +12,5 @@ Project { directory: "." } /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] + importPaths: [ "plugins" ] } -- cgit v0.12 From 2b61fd0d8720bf34ce7f2d4124fbac0ad306090e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 24 Jun 2010 19:44:23 +0200 Subject: Expand on warning message --- demos/qtdemo/qmlShell.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index 5c5f96c..f168ccc 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -130,7 +130,7 @@ Item { textFormat: Text.RichText //Note that if loader is Error, it is because the file was found but there was an error creating the component //This means either we have a bug in our demos, or the required modules (which ship with Qt) did not deploy correctly - text: "The example has failed to load.
If you installed Qt's QML modules this is a bug!
" + text: "The example has failed to load.
If you installed all Qt's C++ and QML modules then this is a bug!
" + 'Report it at http://bugreports.qt.nokia.com'; onLinkActivated: Qt.openUrlExternally(link); } -- cgit v0.12 From 46b53708a668e317de5a0f77d8dfd6ba632290e3 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 24 Jun 2010 19:45:40 +0200 Subject: Stop other mouse buttons propagating --- demos/qtdemo/qmlShell.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index f168ccc..1fea4a8 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -145,6 +145,7 @@ Item { z: 8 enabled: main.show hoverEnabled: main.show //To steal focus from the buttons + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton anchors.fill: parent onClicked: main.show=false; } -- cgit v0.12 From a0d4f94c0eb3f724df979d9d22c4c944f34d547a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 25 Jun 2010 10:51:56 +1000 Subject: Force font selection (and so ensure visual test passes). --- .../declarative/qdeclarativetext/data/alignments.qml | 2 -- .../declarative/qdeclarativetext/data/alignments_cb.png | Bin 528 -> 496 bytes .../declarative/qdeclarativetext/data/alignments_cc.png | Bin 549 -> 556 bytes .../declarative/qdeclarativetext/data/alignments_ct.png | Bin 564 -> 533 bytes .../declarative/qdeclarativetext/data/alignments_lb.png | Bin 522 -> 496 bytes .../declarative/qdeclarativetext/data/alignments_lc.png | Bin 541 -> 535 bytes .../declarative/qdeclarativetext/data/alignments_lt.png | Bin 558 -> 514 bytes .../declarative/qdeclarativetext/data/alignments_rb.png | Bin 530 -> 505 bytes .../declarative/qdeclarativetext/data/alignments_rc.png | Bin 550 -> 559 bytes .../declarative/qdeclarativetext/data/alignments_rt.png | Bin 564 -> 539 bytes .../qdeclarativetext/tst_qdeclarativetext.cpp | 7 +++++++ .../qdeclarativetextedit/data/alignments.qml | 2 -- .../qdeclarativetextedit/data/alignments_cb.png | Bin 528 -> 496 bytes .../qdeclarativetextedit/data/alignments_cc.png | Bin 549 -> 556 bytes .../qdeclarativetextedit/data/alignments_ct.png | Bin 564 -> 533 bytes .../qdeclarativetextedit/data/alignments_lb.png | Bin 522 -> 496 bytes .../qdeclarativetextedit/data/alignments_lc.png | Bin 541 -> 535 bytes .../qdeclarativetextedit/data/alignments_lt.png | Bin 558 -> 514 bytes .../qdeclarativetextedit/data/alignments_rb.png | Bin 530 -> 505 bytes .../qdeclarativetextedit/data/alignments_rc.png | Bin 550 -> 559 bytes .../qdeclarativetextedit/data/alignments_rt.png | Bin 564 -> 539 bytes .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 7 +++++++ 22 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments.qml b/tests/auto/declarative/qdeclarativetext/data/alignments.qml index b10c335..b1f701b 100644 --- a/tests/auto/declarative/qdeclarativetext/data/alignments.qml +++ b/tests/auto/declarative/qdeclarativetext/data/alignments.qml @@ -20,8 +20,6 @@ Rectangle { id: t anchors.fill: parent - font.family: "Misc Fixed" - font.pixelSize: 8 horizontalAlignment: TextEdit.AlignRight verticalAlignment: TextEdit.AlignBottom wrapMode: TextEdit.WordWrap diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png index b0ad381..99de219 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png index 98232ce..cb85251 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png index b606ba5..ddca549 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png index a8f095d..1b50a81 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png index c2a0679..f041b86 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png index c019551..c75e0d1 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png index 08d581a..b06a5da 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png index d607955..e468857 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png index 2acfb9e..576715f 100644 Binary files a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png and b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png differ diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 91b3ca0..dc92f07 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -424,6 +424,13 @@ void tst_qdeclarativetext::alignments() QFETCH(int, vAlign); QFETCH(QString, expectfile); +#ifdef Q_OS_LINUX + // Font-specific, but not likely platform-specific, so only test on one platform + QFont fn; + fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); + QApplication::setFont(fn); +#endif + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); canvas->show(); diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml index b10c335..b1f701b 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml @@ -20,8 +20,6 @@ Rectangle { id: t anchors.fill: parent - font.family: "Misc Fixed" - font.pixelSize: 8 horizontalAlignment: TextEdit.AlignRight verticalAlignment: TextEdit.AlignBottom wrapMode: TextEdit.WordWrap diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png index b0ad381..99de219 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png index 98232ce..cb85251 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png index b606ba5..ddca549 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png index a8f095d..1b50a81 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png index c2a0679..f041b86 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png index c019551..c75e0d1 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png index 08d581a..b06a5da 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png index d607955..e468857 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png index 2acfb9e..576715f 100644 Binary files a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png and b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png differ diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 009d354..adf8348 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -325,6 +325,13 @@ void tst_qdeclarativetextedit::alignments() QFETCH(int, vAlign); QFETCH(QString, expectfile); +#ifdef Q_OS_LINUX + // Font-specific, but not likely platform-specific, so only test on one platform + QFont fn; + fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); + QApplication::setFont(fn); +#endif + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); canvas->show(); -- cgit v0.12 From cfa9eee32081dc49ab0697b1f483db01c8aee7cd Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 12:44:12 +1000 Subject: Reading a property that doesn't exist throws a ReferenceError test QTBUG-11606 --- .../declarative/qdeclarativeecmascript/data/qtbug_11606.qml | 12 ++++++++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml new file mode 100644 index 0000000..6efb9c1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml @@ -0,0 +1,12 @@ +import Qt 4.7 + +QtObject { + property bool test: false + Component.onCompleted: { + try { + console.log(sorryNoSuchProperty); + } catch (e) { + test = true; + } + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 50da55d..7e8a272 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -155,6 +155,7 @@ private slots: void eval(); void function(); void qtbug_10696(); + void qtbug_11606(); void include(); @@ -2503,6 +2504,15 @@ void tst_qdeclarativeecmascript::qtbug_10696() delete o; } +void tst_qdeclarativeecmascript::qtbug_11606() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11606.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test").toBool(), true); + delete o; +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12 From 2426502f372f1c1a33ccaba3549dc0eda2a754de Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 13:11:09 +1000 Subject: Disallow global object properties as property names QTBUG-11605 --- src/declarative/qml/qdeclarativecompiler.cpp | 8 ++++++++ src/declarative/qml/qdeclarativeglobalscriptclass.cpp | 4 ++++ tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml | 4 ++-- tests/auto/declarative/qdeclarativeecmascript/testtypes.h | 2 ++ .../qdeclarativelanguage/data/invalidProperty.errors.txt | 1 + .../declarative/qdeclarativelanguage/data/invalidProperty.qml | 5 +++++ .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 1 + 7 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 80a1093..60128b7 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -2199,6 +2199,10 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) if (QString::fromUtf8(prop.name).at(0).isUpper()) COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter")); + + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(prop.name)) + COMPILE_EXCEPTION(&prop, tr("Illegal property name")); + propNames.insert(prop.name); } @@ -2208,6 +2212,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) COMPILE_EXCEPTION(obj, tr("Duplicate signal name")); if (QString::fromUtf8(name).at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter")); + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name)) + COMPILE_EXCEPTION(obj, tr("Illegal signal name")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { @@ -2216,6 +2222,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) COMPILE_EXCEPTION(obj, tr("Duplicate method name")); if (QString::fromUtf8(name).at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter")); + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name)) + COMPILE_EXCEPTION(obj, tr("Illegal method name")); methodNames.insert(name); } diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index f29b3f4..3e22c82 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -55,6 +55,7 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi : QScriptClass(engine) { QString eval = QLatin1String("eval"); + QString version = QLatin1String("version"); QScriptValue globalObject = engine->globalObject(); @@ -68,6 +69,9 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi QString name = iter.name(); + if (name == version) + continue; + if (name != eval) m_globalObject.setProperty(iter.scriptName(), iter.value()); newGlobalObject.setProperty(iter.scriptName(), iter.value()); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml index 4395ba3..2548005 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml @@ -1,10 +1,10 @@ import Qt 4.7 +import Qt.test 1.0 -Item { +MyQmlObject { id: root property int foo: 12 - property int console: 11 property bool test1: foo == 12 property bool test2: console != 11 diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 7bb8a8e..fef76ef 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -86,6 +86,7 @@ class MyQmlObject : public QObject Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int console READ console CONSTANT) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) Q_PROPERTY(QDeclarativeListProperty objectListProperty READ objectListProperty CONSTANT) @@ -142,6 +143,7 @@ public: QRegExp regExp() { return m_regExp; } void setRegExp(const QRegExp ®Exp) { m_regExp = regExp; } + int console() const { return 11; } signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c); diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt new file mode 100644 index 0000000..c83e5ae --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt @@ -0,0 +1 @@ +4:5:Illegal property name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml new file mode 100644 index 0000000..6077de4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +QtObject { + property int parseInt +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 413843a..3ce356e 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -370,6 +370,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("destroyedSignal") << "destroyedSignal.qml" << "destroyedSignal.errors.txt" << false; QTest::newRow("assignToNamespace") << "assignToNamespace.qml" << "assignToNamespace.errors.txt" << false; QTest::newRow("invalidOn") << "invalidOn.qml" << "invalidOn.errors.txt" << false; + QTest::newRow("invalidProperty") << "invalidProperty.qml" << "invalidProperty.errors.txt" << false; } -- cgit v0.12 From 5272bfe03522e671e832a8cbd9e5b2d4d71a18f2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 13:22:08 +1000 Subject: Fix assert QTBUG-11600 --- src/declarative/qml/qdeclarativetypenamescriptclass.cpp | 4 ++-- .../declarative/qdeclarativeecmascript/data/qtbug_11600.js | 1 + .../declarative/qdeclarativeecmascript/data/qtbug_11600.qml | 8 ++++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 11 +++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp index 2a3417a..764a8db 100644 --- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp +++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp @@ -107,8 +107,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na return 0; } - } else { - Q_ASSERT(data->type); + } else if (data->type) { QString strName = toString(name); @@ -134,6 +133,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na if (!object) return 0; return ep->objectClass->queryProperty(object, name, flags, 0); } + } return 0; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js new file mode 100644 index 0000000..092bc2b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js @@ -0,0 +1 @@ +; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml new file mode 100644 index 0000000..56e7885 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml @@ -0,0 +1,8 @@ +import Qt 4.7 +import "qtbug_11600.js" as Test + +QtObject { + id: goo + + property bool test: undefined == goo.Test.foo +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 7e8a272..5619f22 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -156,6 +156,7 @@ private slots: void function(); void qtbug_10696(); void qtbug_11606(); + void qtbug_11600(); void include(); @@ -2513,6 +2514,16 @@ void tst_qdeclarativeecmascript::qtbug_11606() delete o; } +void tst_qdeclarativeecmascript::qtbug_11600() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11600.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test").toBool(), true); + delete o; +} + + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12 From e0913d038b3df628bc180d397681b9e6ec53a75c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 13:42:06 +1000 Subject: Allow components to be created from .pragma library JS files QTBUG-11507 --- src/declarative/qml/qdeclarativecomponent.cpp | 4 +++- src/declarative/qml/qdeclarativeengine.cpp | 24 +++++++++++++++++----- src/declarative/qml/qdeclarativeengine_p.h | 1 + .../qdeclarativeqt/data/createComponent_lib.js | 4 ++++ .../qdeclarativeqt/data/createComponent_lib.qml | 2 ++ .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 6 ++---- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b4919ff..9d3032c 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -572,7 +572,9 @@ QScriptValue QDeclarativeComponent::createObject(QObject* parent) { Q_D(QDeclarativeComponent); QDeclarativeContext* ctxt = creationContext(); - if(!ctxt) + if(!ctxt && d->engine) + ctxt = d->engine->rootContext(); + if (!ctxt) return QScriptValue(QScriptValue::NullValue); QObject* ret = create(ctxt); if (!ret) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 5c4d229..98b4bbf 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1033,6 +1033,17 @@ QDeclarativeContextData *QDeclarativeEnginePrivate::getContext(QScriptContext *c return contextClass->contextFromValue(scopeNode); } +/*! + Returns the QUrl associated with the script \a ctxt for the case that there is + no QDeclarativeContext. +*/ +QUrl QDeclarativeEnginePrivate::getUrl(QScriptContext *ctxt) +{ + QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3); + Q_ASSERT(scopeNode.isValid()); + Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass); + return contextClass->urlFromValue(scopeNode); +} QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url) { @@ -1075,16 +1086,19 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS static_cast(engine)->p; QDeclarativeEngine* activeEngine = activeEnginePriv->q_func(); - QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt); - Q_ASSERT(context); - if(ctxt->argumentCount() != 1) { return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments")); - }else{ + } else { + QString arg = ctxt->argument(0).toString(); if (arg.isEmpty()) return engine->nullValue(); - QUrl url = QUrl(context->resolvedUrl(QUrl(arg))); + QUrl url; + QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt); + if (context) + url = QUrl(context->resolvedUrl(QUrl(arg))); + else + url = activeEnginePriv->getUrl(ctxt).resolved(QUrl(arg)); QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine); QDeclarativeComponentPrivate::get(c)->creationContext = context; QDeclarativeData::get(c, true)->setImplicitDestructible(); diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 3269e98..cfa9d73 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -315,6 +315,7 @@ public: static QDeclarativeEnginePrivate *get(QScriptEngine *e) { return static_cast(e)->p; } static QDeclarativeEngine *get(QDeclarativeEnginePrivate *p) { return p->q_func(); } QDeclarativeContextData *getContext(QScriptContext *); + QUrl getUrl(QScriptContext *); static QString urlToLocalFileOrQrc(const QUrl& url); diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js index c165e29..30499e9 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js +++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js @@ -5,3 +5,7 @@ function loadComponent() { return component.status; } +function createComponent() { + var component = Qt.createComponent("createComponentData.qml"); + return component.createObject(null); +} diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml index aae7a91..33203c7 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml +++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml @@ -3,8 +3,10 @@ import "createComponent_lib.js" as Test Item { property int status: Component.Null + property int readValue: 0 Component.onCompleted: { status = Test.loadComponent() + readValue = Test.createComponent().test; } } diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index fb100a5..895ee6c 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -365,14 +365,12 @@ void tst_qdeclarativeqt::createComponent() void tst_qdeclarativeqt::createComponent_pragmaLibrary() { // Currently, just loading createComponent_lib.qml causes crash on some platforms - /* QDeclarativeComponent component(&engine, TEST_FILE("createComponent_lib.qml")); QObject *object = component.create(); QVERIFY(object != 0); - - QEXPECT_FAIL("", "QTBUG-11507", Continue); QCOMPARE(object->property("status").toInt(), int(QDeclarativeComponent::Ready)); - */ + QCOMPARE(object->property("readValue").toInt(), int(1913)); + delete object; } void tst_qdeclarativeqt::createQmlObject() -- cgit v0.12 From 2d7e341646e302506531cb0bf87b8da5d088c319 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 14:26:23 +1000 Subject: Allow custom parsers to handle attached properties QTBUG-11283 --- src/declarative/qml/qdeclarativecompiler.cpp | 13 +++++++++---- src/declarative/qml/qdeclarativecustomparser_p.h | 12 +++++++++++- src/declarative/util/qdeclarativepropertychanges_p.h | 3 +++ .../qdeclarativestates/tst_qdeclarativestates.cpp | 1 - 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 60128b7..6917a5b 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -815,6 +815,10 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) } } + QDeclarativeCustomParser *cp = 0; + if (isCustomParser) + cp = output->types.at(obj->type).type->customParser(); + // Build all explicit properties specified foreach(Property *prop, obj->properties) { @@ -825,7 +829,9 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) bool canDefer = false; if (isCustomParser) { - if (doesPropertyExist(prop, obj)) { + if (doesPropertyExist(prop, obj) && + (!(cp->flags() & QDeclarativeCustomParser::AcceptsAttachedProperties) || + !isAttachedPropertyName(prop->name))) { int ids = compileState.ids.count(); COMPILE_CHECK(buildProperty(prop, obj, objCtxt)); canDefer = ids == compileState.ids.count(); @@ -876,8 +882,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) defaultProperty->release(); // Compile custom parser parts - if (isCustomParser/* && !customProps.isEmpty()*/) { - QDeclarativeCustomParser *cp = output->types.at(obj->type).type->customParser(); + if (isCustomParser && !customProps.isEmpty()) { cp->clearErrors(); cp->compiler = this; cp->object = obj; @@ -1356,7 +1361,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl Returns true if (value) property \a prop exists on obj, false otherwise. */ bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj) + QDeclarativeParser::Object *obj) { if(isAttachedPropertyName(prop->name) || prop->name == "id") return true; diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h index 0e397c5..1a746b4 100644 --- a/src/declarative/qml/qdeclarativecustomparser_p.h +++ b/src/declarative/qml/qdeclarativecustomparser_p.h @@ -113,10 +113,18 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeCustomParser { public: - QDeclarativeCustomParser() : compiler(0), object(0) {} + enum Flag { + NoFlag = 0x00000000, + AcceptsAttachedProperties = 0x00000001 + }; + Q_DECLARE_FLAGS(Flags, Flag); + + QDeclarativeCustomParser() : compiler(0), object(0), m_flags(NoFlag) {} + QDeclarativeCustomParser(Flags f) : compiler(0), object(0), m_flags(f) {} virtual ~QDeclarativeCustomParser() {} void clearErrors(); + Flags flags() const { return m_flags; } virtual QByteArray compile(const QList &)=0; virtual void setCustomData(QObject *, const QByteArray &)=0; @@ -134,8 +142,10 @@ private: QList exceptions; QDeclarativeCompiler *compiler; QDeclarativeParser::Object *object; + Flags m_flags; friend class QDeclarativeCompiler; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeCustomParser::Flags); #if 0 #define QML_REGISTER_CUSTOM_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, TYPE, CUSTOMTYPE) \ diff --git a/src/declarative/util/qdeclarativepropertychanges_p.h b/src/declarative/util/qdeclarativepropertychanges_p.h index c2ed466..bb0f944 100644 --- a/src/declarative/util/qdeclarativepropertychanges_p.h +++ b/src/declarative/util/qdeclarativepropertychanges_p.h @@ -79,6 +79,9 @@ public: class QDeclarativePropertyChangesParser : public QDeclarativeCustomParser { public: + QDeclarativePropertyChangesParser() + : QDeclarativeCustomParser(AcceptsAttachedProperties) {} + void compileList(QList > &list, const QByteArray &pre, const QDeclarativeCustomParserProperty &prop); virtual QByteArray compile(const QList &); diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 2913ddd..639b2f3 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -263,7 +263,6 @@ void tst_qdeclarativestates::attachedPropertyChanges() MyAttached *att = qobject_cast(attObj); QVERIFY(att); - QEXPECT_FAIL("", "QTBUG-11283", Abort); QCOMPARE(att->foo(), 1); } -- cgit v0.12 From 46233eaa956e57a4c948cec759a3be606a8bdcb8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 25 Jun 2010 15:13:20 +1000 Subject: Handle enums in method arguments in the same way as QtScript QML will now invoke methods with enums as arguments, in the same fashion as QtScript. QTBUG-11313 --- .../qml/qdeclarativeobjectscriptclass.cpp | 24 +++++++++++++++++++++- .../qml/qdeclarativeobjectscriptclass_p.h | 2 ++ .../declarative/qdeclarativeecmascript/testtypes.h | 4 ++++ .../tst_qdeclarativeecmascript.cpp | 7 +++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index aca01b2..3af892d 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -797,6 +797,26 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) } } +int QDeclarativeObjectMethodScriptClass::enumType(const QMetaObject *meta, const QString &strname) +{ + QByteArray str = strname.toUtf8(); + QByteArray scope; + QByteArray name; + int scopeIdx = str.lastIndexOf("::"); + if (scopeIdx != -1) { + scope = str.left(scopeIdx); + name = str.mid(scopeIdx + 2); + } else { + name = str; + } + for (int i = meta->enumeratorCount() - 1; i >= 0; --i) { + QMetaEnum m = meta->enumerator(i); + if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope))) + return QVariant::Int; + } + return QVariant::Invalid; +} + QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt) { MethodData *method = static_cast(o); @@ -810,7 +830,9 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: // ### Cache for (int ii = 0; ii < argTypeNames.count(); ++ii) { argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); - if (argTypes[ii] == QVariant::Invalid) + if (argTypes[ii] == QVariant::Invalid) + argTypes[ii] = enumType(method->object->metaObject(), argTypeNames.at(ii)); + if (argTypes[ii] == QVariant::Invalid) return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); } diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 4b27e53..75e384c 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -80,6 +80,8 @@ protected: virtual Value property(Object *, const Identifier &); private: + int enumType(const QMetaObject *, const QString &); + PersistentIdentifier m_connectId; PersistentIdentifier m_disconnectId; QScriptValue m_connect; diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index fef76ef..849879e 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -557,7 +557,9 @@ Q_DECLARE_METATYPE(QScriptValue); class MyInvokableObject : public QObject { Q_OBJECT + Q_ENUMS(TestEnum) public: + enum TestEnum { EnumValue1, EnumValue2 }; MyInvokableObject() { reset(); } int invoked() const { return m_invoked; } @@ -589,6 +591,8 @@ public: Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; } Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; } + Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(18); m_actuals << (int)e; } + private: void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} int m_invoked; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 5619f22..43900ae 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1721,6 +1721,13 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().count(), 2); QCOMPARE(o.actuals().at(0), QVariant(10)); QCOMPARE(o.actuals().at(1), QVariant(11)); + + o.reset(); + QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 18); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(o.actuals().at(0), QVariant(9)); } // QTBUG-5675 -- cgit v0.12 From c91030e308f8cd9ad66e7de127a1f9dbbedd11d3 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 25 Jun 2010 16:30:59 +1000 Subject: Test only on X11, not only on Linux (which includes embedded). --- tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp | 4 ++-- .../declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index dc92f07..8a4f152 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -424,7 +424,7 @@ void tst_qdeclarativetext::alignments() QFETCH(int, vAlign); QFETCH(QString, expectfile); -#ifdef Q_OS_LINUX +#ifdef Q_WS_X11 // Font-specific, but not likely platform-specific, so only test on one platform QFont fn; fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); @@ -450,7 +450,7 @@ void tst_qdeclarativetext::alignments() QImage expect(expectfile); -#ifdef Q_OS_LINUX +#ifdef Q_WS_X11 // Font-specific, but not likely platform-specific, so only test on one platform QCOMPARE(actual,expect); #endif diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index adf8348..f1a367f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -325,7 +325,7 @@ void tst_qdeclarativetextedit::alignments() QFETCH(int, vAlign); QFETCH(QString, expectfile); -#ifdef Q_OS_LINUX +#ifdef Q_WS_X11 // Font-specific, but not likely platform-specific, so only test on one platform QFont fn; fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); @@ -351,7 +351,7 @@ void tst_qdeclarativetextedit::alignments() QImage expect(expectfile); -#ifdef Q_OS_LINUX +#ifdef Q_WS_X11 // Font-specific, but not likely platform-specific, so only test on one platform QCOMPARE(actual,expect); #endif -- cgit v0.12 From 03df7f73de6a1fd482876caaf377a61593df8a38 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 25 Jun 2010 16:37:28 +1000 Subject: Test ListElement type via type system, not string comparison. Task-number: QTBUG-11222 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativecompiler.cpp | 12 ++++++++++++ src/declarative/qml/qdeclarativecompiler_p.h | 1 + src/declarative/qml/qdeclarativecustomparser.cpp | 10 ++++++++++ src/declarative/qml/qdeclarativecustomparser_p.h | 2 ++ src/declarative/util/qdeclarativelistmodel.cpp | 11 ++++++++--- src/declarative/util/qdeclarativelistmodel_p.h | 2 ++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 80a1093..a7cfa62 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -2176,6 +2176,18 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const return -1; } +const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const +{ + QDeclarativeType *qmltype = 0; + if (!enginePrivate->importDatabase.resolveType(unit->imports, name, &qmltype, + 0, 0, 0, 0)) + return 0; + if (!qmltype) + return 0; + return qmltype->metaObject(); +} + + // Ensures that the dynamic meta specification on obj is valid bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) { diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 908c703..caad376 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -161,6 +161,7 @@ public: static bool isSignalPropertyName(const QByteArray &); int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum + const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType private: static void reset(QDeclarativeCompiledData *); diff --git a/src/declarative/qml/qdeclarativecustomparser.cpp b/src/declarative/qml/qdeclarativecustomparser.cpp index 472a883..97a6a00 100644 --- a/src/declarative/qml/qdeclarativecustomparser.cpp +++ b/src/declarative/qml/qdeclarativecustomparser.cpp @@ -295,4 +295,14 @@ int QDeclarativeCustomParser::evaluateEnum(const QByteArray& script) const return compiler->evaluateEnum(script); } +/*! + Resolves \a name to a type, or 0 if it is not a type. This can be used + to type-check object nodes. +*/ +const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name) const +{ + return compiler->resolveType(name); +} + + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h index 0e397c5..8eb86e8 100644 --- a/src/declarative/qml/qdeclarativecustomparser_p.h +++ b/src/declarative/qml/qdeclarativecustomparser_p.h @@ -130,6 +130,8 @@ protected: int evaluateEnum(const QByteArray&) const; + const QMetaObject *resolveType(const QByteArray&) const; + private: QList exceptions; QDeclarativeCompiler *compiler; diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 9ed21a6..deb835d 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -551,9 +551,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QDeclarativeCustomParserNode node = qvariant_cast(value); - if (node.name() != "ListElement") { - error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); - return false; + if (node.name() != listElementTypeName) { + const QMetaObject *mo = resolveType(node.name()); + if (mo != &QDeclarativeListElement::staticMetaObject) { + error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); + return false; + } + listElementTypeName = node.name(); // cache right name for next time } { @@ -650,6 +654,7 @@ QByteArray QDeclarativeListModelParser::compile(const QList instr; QByteArray data; + listElementTypeName = QByteArray(); // unknown for(int ii = 0; ii < customProps.count(); ++ii) { const QDeclarativeCustomParserProperty &prop = customProps.at(ii); diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h index d09062e..6aff9c6 100644 --- a/src/declarative/util/qdeclarativelistmodel_p.h +++ b/src/declarative/util/qdeclarativelistmodel_p.h @@ -135,6 +135,8 @@ private: bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList &instr, QByteArray &data); bool definesEmptyList(const QString &); + + QByteArray listElementTypeName; }; -- cgit v0.12 From 543bbe2e122d1d3394ec589c32f9640d1fd88f3b Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 25 Jun 2010 16:39:28 +1000 Subject: Test QTBUG-11222 Task-number: QTBUG-11222 --- .../qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 3d66733..f15ac8f 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -559,6 +559,18 @@ void tst_qdeclarativelistmodel::error_data() QTest::newRow("QML elements not allowed in ListElement") << "import Qt 4.7\nListModel { ListElement { a: Item { } } }" << "ListElement: cannot contain nested elements"; + + QTest::newRow("qualified ListElement supported") + << "import Qt 4.7 as Foo\nFoo.ListModel { Foo.ListElement { a: 123 } }" + << ""; + + QTest::newRow("qualified ListElement required") + << "import Qt 4.7 as Foo\nFoo.ListModel { ListElement { a: 123 } }" + << "ListElement is not a type"; + + QTest::newRow("unknown qualified ListElement not allowed") + << "import Qt 4.7\nListModel { Foo.ListElement { a: 123 } }" + << "Foo.ListElement - Foo is not a namespace"; } void tst_qdeclarativelistmodel::error() -- cgit v0.12 From 156cabe79a64ffca8d6e1a2df99f35b413a48a39 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Mon, 21 Jun 2010 17:59:23 +0200 Subject: Make the QML viewer usable on the N900 --- tools/qml/deviceorientation_maemo.cpp | 127 --------- tools/qml/deviceorientation_maemo5.cpp | 127 +++++++++ tools/qml/loggerwidget.cpp | 25 +- tools/qml/loggerwidget.h | 16 +- tools/qml/main.cpp | 2 +- tools/qml/proxysettings.cpp | 5 +- tools/qml/proxysettings.h | 4 + tools/qml/proxysettings_maemo5.ui | 177 +++++++++++++ tools/qml/qml.pri | 10 +- tools/qml/qml.pro | 3 + tools/qml/qmlruntime.cpp | 471 +++++++++++++++++++++------------ tools/qml/qmlruntime.h | 19 +- tools/qml/recopts_maemo5.ui | 254 ++++++++++++++++++ tools/qml/texteditautoresizer_maemo5.h | 122 +++++++++ 14 files changed, 1036 insertions(+), 326 deletions(-) delete mode 100644 tools/qml/deviceorientation_maemo.cpp create mode 100644 tools/qml/deviceorientation_maemo5.cpp create mode 100644 tools/qml/proxysettings_maemo5.ui create mode 100644 tools/qml/recopts_maemo5.ui create mode 100644 tools/qml/texteditautoresizer_maemo5.h diff --git a/tools/qml/deviceorientation_maemo.cpp b/tools/qml/deviceorientation_maemo.cpp deleted file mode 100644 index 443edc8..0000000 --- a/tools/qml/deviceorientation_maemo.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "deviceorientation.h" -#include - -#include -#include - -class MaemoOrientation : public DeviceOrientation -{ - Q_OBJECT -public: - MaemoOrientation() - : o(UnknownOrientation) - { - // enable the orientation sensor - QDBusConnection::systemBus().call( - QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, - MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); - - // query the initial orientation - QDBusMessage reply = QDBusConnection::systemBus().call( - QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, - MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET)); - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage())); - } else { - o = toOrientation(reply.arguments().value(0).toString()); - } - - // connect to the orientation change signal - QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, - MCE_DEVICE_ORIENTATION_SIG, - this, - SLOT(deviceOrientationChanged(QString))); - } - - ~MaemoOrientation() - { - // disable the orientation sensor - QDBusConnection::systemBus().call( - QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, - MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); - } - - inline Orientation orientation() const - { - return o; - } - - void setOrientation(Orientation o) - { - } - -private Q_SLOTS: - void deviceOrientationChanged(const QString &newOrientation) - { - o = toOrientation(newOrientation); - - emit orientationChanged(); -// printf("%d\n", o); - } - -private: - static Orientation toOrientation(const QString &nativeOrientation) - { - if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE) - return Landscape; - else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED) - return LandscapeInverted; - else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT) - return Portrait; - else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED) - return PortraitInverted; - return UnknownOrientation; - } - -private: - Orientation o; -}; - -DeviceOrientation* DeviceOrientation::instance() -{ - static MaemoOrientation *o = new MaemoOrientation; - return o; -} - -#include "deviceorientation_maemo.moc" diff --git a/tools/qml/deviceorientation_maemo5.cpp b/tools/qml/deviceorientation_maemo5.cpp new file mode 100644 index 0000000..443edc8 --- /dev/null +++ b/tools/qml/deviceorientation_maemo5.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "deviceorientation.h" +#include + +#include +#include + +class MaemoOrientation : public DeviceOrientation +{ + Q_OBJECT +public: + MaemoOrientation() + : o(UnknownOrientation) + { + // enable the orientation sensor + QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); + + // query the initial orientation + QDBusMessage reply = QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET)); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage())); + } else { + o = toOrientation(reply.arguments().value(0).toString()); + } + + // connect to the orientation change signal + QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, + MCE_DEVICE_ORIENTATION_SIG, + this, + SLOT(deviceOrientationChanged(QString))); + } + + ~MaemoOrientation() + { + // disable the orientation sensor + QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); + } + + inline Orientation orientation() const + { + return o; + } + + void setOrientation(Orientation o) + { + } + +private Q_SLOTS: + void deviceOrientationChanged(const QString &newOrientation) + { + o = toOrientation(newOrientation); + + emit orientationChanged(); +// printf("%d\n", o); + } + +private: + static Orientation toOrientation(const QString &nativeOrientation) + { + if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE) + return Landscape; + else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED) + return LandscapeInverted; + else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT) + return Portrait; + else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED) + return PortraitInverted; + return UnknownOrientation; + } + +private: + Orientation o; +}; + +DeviceOrientation* DeviceOrientation::instance() +{ + static MaemoOrientation *o = new MaemoOrientation; + return o; +} + +#include "deviceorientation_maemo.moc" diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 3ae2b5e..71d20e8 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -39,29 +39,48 @@ ** ****************************************************************************/ -#include "loggerwidget.h" #include #include #include #include #include +#include +#ifdef Q_WS_MAEMO_5 +# include +# include +# include "texteditautoresizer_maemo5.h" +#endif + +#include "loggerwidget.h" QT_BEGIN_NAMESPACE LoggerWidget::LoggerWidget(QWidget *parent) : - QPlainTextEdit(parent), + QMainWindow(parent), m_visibilityOrigin(SettingsOrigin) { setAttribute(Qt::WA_QuitOnClose, false); setWindowTitle(tr("Warnings")); + m_plainTextEdit = new QPlainTextEdit(); + +#ifdef Q_WS_MAEMO_5 + new TextEditAutoResizer(m_plainTextEdit); + setAttribute(Qt::WA_Maemo5StackedWindow); + QScrollArea *area = new QScrollArea(); + area->setWidget(m_plainTextEdit); + area->setWidgetResizable(true); + setCentralWidget(area); +#else + setCentralWidget(m_plainTextEdit); +#endif readSettings(); setupPreferencesMenu(); } void LoggerWidget::append(const QString &msg) { - appendPlainText(msg); + m_plainTextEdit->appendPlainText(msg); if (!isVisible() && (defaultVisibility() == AutoShowWarnings)) setVisible(true); diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index fd20c41..0623432 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -42,12 +42,17 @@ #ifndef LOGGERWIDGET_H #define LOGGERWIDGET_H -#include +#include +#include -QT_BEGIN_NAMESPACE +QT_USE_NAMESPACE -class LoggerWidget : public QPlainTextEdit { -Q_OBJECT +class QPlainTextEdit; +class QMenu; +class QAction; + +class LoggerWidget : public QMainWindow { + Q_OBJECT public: LoggerWidget(QWidget *parent=0); @@ -80,14 +85,13 @@ private: QMenu *m_preferencesMenu; QAction *m_showWidgetAction; + QPlainTextEdit *m_plainTextEdit; enum ConfigOrigin { CommandLineOrigin, SettingsOrigin }; ConfigOrigin m_visibilityOrigin; Visibility m_visibility; }; -QT_END_NAMESPACE - Q_DECLARE_METATYPE(LoggerWidget::Visibility) #endif // LOGGERWIDGET_H diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index a75023b..de5bca2 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -346,7 +346,7 @@ int main(int argc, char ** argv) if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; - QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags); + QDeclarativeViewer *viewer = QDeclarativeViewer::instance(0, wflags); viewer->setAttribute(Qt::WA_DeleteOnClose, true); if (!scriptopts.isEmpty()) { QStringList options = diff --git a/tools/qml/proxysettings.cpp b/tools/qml/proxysettings.cpp index 3255e42..ffaa4c0 100644 --- a/tools/qml/proxysettings.cpp +++ b/tools/qml/proxysettings.cpp @@ -48,11 +48,14 @@ QT_BEGIN_NAMESPACE ProxySettings::ProxySettings (QWidget * parent) - : QDialog (parent), Ui::ProxySettings() + : QDialog (parent), Ui::ProxySettings() { setupUi (this); +#if !defined Q_WS_MAEMO_5 + // the onscreen keyboard can't cope with masks proxyServerEdit->setInputMask ("000.000.000.000;_"); +#endif QIntValidator *validator = new QIntValidator (0, 9999, this); proxyPortEdit->setValidator (validator); diff --git a/tools/qml/proxysettings.h b/tools/qml/proxysettings.h index 325929a..5d4d137 100644 --- a/tools/qml/proxysettings.h +++ b/tools/qml/proxysettings.h @@ -44,7 +44,11 @@ #include #include +#ifdef Q_WS_MAEMO_5 +#include "ui_proxysettings_maemo5.h" +#else #include "ui_proxysettings.h" +#endif QT_BEGIN_NAMESPACE /** diff --git a/tools/qml/proxysettings_maemo5.ui b/tools/qml/proxysettings_maemo5.ui new file mode 100644 index 0000000..83f0c2a --- /dev/null +++ b/tools/qml/proxysettings_maemo5.ui @@ -0,0 +1,177 @@ + + + ProxySettings + + + + 0 + 0 + 449 + 164 + + + + HTTP Proxy + + + + 16 + + + 0 + + + 16 + + + 8 + + + 16 + + + 0 + + + + + Use HTTP Proxy + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 16 + + + 0 + + + 0 + + + + + Server + + + + + + + Name or IP + + + + + + + Port + + + + + + + 8080 + + + + + + + Username + + + + + + + + + + Password + + + + + + + QLineEdit::Password + + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + proxyCheckBox + proxyServerEdit + proxyPortEdit + usernameEdit + passwordEdit + buttonBox + + + + + buttonBox + accepted() + ProxySettings + accept() + + + 318 + 100 + + + 157 + 116 + + + + + buttonBox + rejected() + ProxySettings + reject() + + + 318 + 100 + + + 286 + 116 + + + + + diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index 58d8cc1..3e5a88b 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -19,10 +19,12 @@ SOURCES += $$PWD/qmlruntime.cpp \ RESOURCES = $$PWD/qmlruntime.qrc maemo5 { QT += dbus - SOURCES += $$PWD/deviceorientation_maemo.cpp + HEADERS += $$PWD/texteditautoresizer_maemo5.h + SOURCES += $$PWD/deviceorientation_maemo5.cpp + FORMS = $$PWD/recopts_maemo5.ui \ + $$PWD/proxysettings_maemo5.ui } else { SOURCES += $$PWD/deviceorientation.cpp + FORMS = $$PWD/recopts.ui \ + $$PWD/proxysettings.ui } - -FORMS = $$PWD/recopts.ui \ - $$PWD/proxysettings.ui diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 9cdec77..63efff1 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -29,6 +29,9 @@ wince* { QT += webkit } } +maemo5 { + QT += maemo5 +} symbian { TARGET.UID3 = 0x20021317 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 676881d..090ca2a 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -44,7 +44,15 @@ #ifdef hz #undef hz #endif -#include "ui_recopts.h" +#ifdef Q_WS_MAEMO_5 +# include +# include +# include +# include +# include "ui_recopts_maemo5.h" +#else +# include "ui_recopts.h" +#endif #include "qmlruntime.h" #include @@ -136,24 +144,59 @@ private: }; -class SizedMenuBar : public QMenuBar -{ + +#if defined(Q_WS_MAEMO_5) + +class Maemo5PickerAction : public QWidgetAction { Q_OBJECT public: - SizedMenuBar(QWidget *parent, QWidget *referenceWidget) - : QMenuBar(parent), refWidget(referenceWidget) + Maemo5PickerAction(const QString &text, QActionGroup *actions, QObject *parent) + : QWidgetAction(parent), m_text(text), m_actions(actions) + { } + + QWidget *createWidget(QWidget *parent) { + QMaemo5ValueButton *button = new QMaemo5ValueButton(m_text, parent); + button->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered); + QMaemo5ListPickSelector *pick = new QMaemo5ListPickSelector(button); + button->setPickSelector(pick); + if (m_actions) { + QStringList sl; + int curIdx = -1, idx = 0; + foreach (QAction *a, m_actions->actions()) { + sl << a->text(); + if (a->isChecked()) + curIdx = idx; + idx++; + } + pick->setModel(new QStringListModel(sl)); + pick->setCurrentIndex(curIdx); + } else { + button->setEnabled(false); + } + connect(pick, SIGNAL(selected(QString)), this, SLOT(emitTriggered())); + return button; } - virtual QSize sizeHint() const +private slots: + void emitTriggered() { - return QSize(refWidget->sizeHint().width(), QMenuBar::sizeHint().height()); + QMaemo5ListPickSelector *pick = qobject_cast(sender()); + if (!pick) + return; + int idx = pick->currentIndex(); + + if (m_actions && idx >= 0 && idx < m_actions->actions().count()) + m_actions->actions().at(idx)->trigger(); } private: - QWidget *refWidget; + QString m_text; + QPointer m_actions; }; +#endif // Q_WS_MAEMO_5 + static struct { const char *name, *args; } ffmpegprofiles[] = { {"Maximum Quality", "-sameq"}, {"High Quality", "-qmax 2"}, @@ -170,7 +213,9 @@ public: RecordingDialog(QWidget *parent) : QDialog(parent) { setupUi(this); +#ifndef Q_WS_MAEMO_5 hz->setValidator(new QDoubleValidator(hz)); +#endif for (int i=0; ffmpegprofiles[i].name; ++i) { profile->addItem(ffmpegprofiles[i].name); } @@ -197,6 +242,132 @@ public: return ffmpegprofiles[i].args[0] ? QLatin1String(ffmpegprofiles[i].args) : customargs; } + void setOriginalSize(const QSize &s) + { + QString str = tr("Original (%1x%2)").arg(s.width()).arg(s.height()); + +#ifdef Q_WS_MAEMO_5 + sizeCombo->setItemText(0, str); +#else + sizeOriginal->setText(str); + if (sizeWidth->value()<=1) { + sizeWidth->setValue(s.width()); + sizeHeight->setValue(s.height()); + } +#endif + } + + void showffmpegOptions(bool b) + { +#ifdef Q_WS_MAEMO_5 + profileLabel->setVisible(b); + profile->setVisible(b); + ffmpegHelp->setVisible(b); + args->setVisible(b); +#else + ffmpegOptions->setVisible(b); +#endif + } + + void showRateOptions(bool b) + { +#ifdef Q_WS_MAEMO_5 + rateLabel->setVisible(b); + rateCombo->setVisible(b); +#else + rateOptions->setVisible(b); +#endif + } + + void setVideoRate(int rate) + { +#ifdef Q_WS_MAEMO_5 + int idx; + if (rate >= 60) + idx = 0; + else if (rate >= 50) + idx = 2; + else if (rate >= 25) + idx = 3; + else if (rate >= 24) + idx = 4; + else if (rate >= 20) + idx = 5; + else if (rate >= 15) + idx = 6; + else + idx = 7; + rateCombo->setCurrentIndex(idx); +#else + if (rate == 24) + hz24->setChecked(true); + else if (rate == 25) + hz25->setChecked(true); + else if (rate == 50) + hz50->setChecked(true); + else if (rate == 60) + hz60->setChecked(true); + else { + hzCustom->setChecked(true); + hz->setText(QString::number(rate)); + } +#endif + } + + int videoRate() const + { +#ifdef Q_WS_MAEMO_5 + switch (rateCombo->currentIndex()) { + case 0: return 60; + case 1: return 50; + case 2: return 25; + case 3: return 24; + case 4: return 20; + case 5: return 15; + case 7: return 10; + default: return 60; + } +#else + if (hz24->isChecked()) + return 24; + else if (hz25->isChecked()) + return 25; + else if (hz50->isChecked()) + return 50; + else if (hz60->isChecked()) + return 60; + else { + return hz->text().toInt(); + } +#endif + } + + QSize videoSize() const + { +#ifdef Q_WS_MAEMO_5 + switch (sizeCombo->currentIndex()) { + case 0: return QSize(); + case 1: return QSize(640,480); + case 2: return QSize(320,240); + case 3: return QSize(1280,720); + default: return QSize(); + } +#else + if (sizeOriginal->isChecked()) + return QSize(); + else if (size720p->isChecked()) + return QSize(1280,720); + else if (sizeVGA->isChecked()) + return QSize(640,480); + else if (sizeQVGA->isChecked()) + return QSize(320,240); + else + return QSize(sizeWidth->value(), sizeHeight->value()); +#endif + } + + + private slots: void pickProfile(int i) { @@ -363,15 +534,21 @@ QString QDeclarativeViewer::getVideoFileName() return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); } +QDeclarativeViewer *QDeclarativeViewer::inst = 0; + +QDeclarativeViewer *QDeclarativeViewer::instance(QWidget *parent, Qt::WindowFlags flags) +{ + if (!inst) { + inst = new QDeclarativeViewer(parent, flags); + inst->setAttribute(Qt::WA_DeleteOnClose); + } + return inst; +} QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) -#if defined(Q_OS_SYMBIAN) : QMainWindow(parent, flags) -#else - : QWidget(parent, flags) -#endif - , loggerWindow(new LoggerWidget()) - , frame_stream(0), mb(0) + , loggerWindow(new LoggerWidget(this)) + , frame_stream(0) , orientation(0) , showWarningsWindow(0) , m_scriptOptions(0) @@ -381,6 +558,10 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) { QDeclarativeViewer::registerTypes(); setWindowTitle(tr("Qt QML Viewer")); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow); +// setPalette(QApplication::palette("QLabel")); +#endif devicemode = false; canvas = 0; @@ -393,9 +574,9 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) senseFfmpeg(); senseImageMagick(); if (!ffmpegAvailable) - recdlg->ffmpegOptions->hide(); + recdlg->showffmpegOptions(false); if (!ffmpegAvailable && !convertAvailable) - recdlg->rateOptions->hide(); + recdlg->showRateOptions(false); QString warn; if (!ffmpegAvailable) { if (!convertAvailable) @@ -422,21 +603,14 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed())); if (!(flags & Qt::FramelessWindowHint)) { - createMenu(menuBar(),0); + createMenu(); changeOrientation(orientation->actions().value(0)); + } else { + setMenuBar(0); } -#if !defined(Q_OS_SYMBIAN) - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - if (mb) - layout->addWidget(mb); - layout->addWidget(canvas); -#else setCentralWidget(canvas); -#endif + namFactory = new NetworkAccessManagerFactory; canvas->engine()->setNetworkAccessManagerFactory(namFactory); @@ -468,26 +642,6 @@ void QDeclarativeViewer::enableExperimentalGestures() canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); } -int QDeclarativeViewer::menuBarHeight() const -{ - if (!(windowFlags() & Qt::FramelessWindowHint)) - return menuBar()->height(); - else - return 0; // don't create menu -} - -QMenuBar *QDeclarativeViewer::menuBar() const -{ -#if !defined(Q_OS_SYMBIAN) - if (!mb) - mb = new SizedMenuBar((QWidget*)this, canvas); -#else - mb = QMainWindow::menuBar(); -#endif - - return mb; -} - QDeclarativeView *QDeclarativeViewer::view() const { return canvas; @@ -498,120 +652,128 @@ LoggerWidget *QDeclarativeViewer::warningsWidget() const return loggerWindow; } -void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) +void QDeclarativeViewer::createMenu() { - QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu; - - QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File")); - - QAction *openAction = new QAction(tr("&Open..."), parent); + QAction *openAction = new QAction(tr("&Open..."), this); openAction->setShortcut(QKeySequence("Ctrl+O")); connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); - fileMenu->addAction(openAction); - QAction *reloadAction = new QAction(tr("&Reload"), parent); + QAction *reloadAction = new QAction(tr("&Reload"), this); reloadAction->setShortcut(QKeySequence("Ctrl+R")); connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); - fileMenu->addAction(reloadAction); -#if !defined(Q_OS_SYMBIAN) - if (flatmenu) flatmenu->addSeparator(); - - QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording")); - - QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent); + QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this); + snapshotAction->setShortcut(QKeySequence("F3")); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); - recordMenu->addAction(snapshotAction); - recordAction = new QAction(tr("Start Recording &Video\tF9"), parent); + recordAction = new QAction(tr("Start Recording &Video"), this); + recordAction->setShortcut(QKeySequence("F9")); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); - recordMenu->addAction(recordAction); - QAction *recordOptions = new QAction(tr("Video &Options..."), parent); + QAction *recordOptions = new QAction(tr("Video &Options..."), this); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); - if (flatmenu) - flatmenu->addAction(recordOptions); - - if (flatmenu) flatmenu->addSeparator(); - - QMenu *debugMenu = flatmenu ? flatmenu->addMenu(tr("&Debugging")) : menu->addMenu(tr("&Debugging")); - - QAction *slowAction = new QAction(tr("&Slow Down Animations"), parent); + QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); slowAction->setShortcut(QKeySequence("Ctrl+.")); slowAction->setCheckable(true); connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); - debugMenu->addAction(slowAction); - showWarningsWindow = new QAction(tr("Show Warnings"), parent); + showWarningsWindow = new QAction(tr("Show Warnings"), this); showWarningsWindow->setCheckable((true)); showWarningsWindow->setChecked(loggerWindow->isVisible()); connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); -#if !defined(Q_OS_SYMBIAN) - debugMenu->addAction(showWarningsWindow); -#endif - - if (flatmenu) flatmenu->addSeparator(); - -#endif // Q_OS_SYMBIAN - - QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings")); - QAction *proxyAction = new QAction(tr("Http &proxy..."), parent); + QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this); connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings())); - settingsMenu->addAction(proxyAction); -#if !defined(Q_OS_SYMBIAN) - if (!flatmenu) - settingsMenu->addAction(recordOptions); - settingsMenu->addMenu(loggerWindow->preferencesMenu()); -#else - QAction *fullscreenAction = new QAction(tr("Full Screen"), parent); + QAction *fullscreenAction = new QAction(tr("Full Screen"), this); fullscreenAction->setCheckable(true); connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); - settingsMenu->addAction(fullscreenAction); -#endif - if (flatmenu) flatmenu->addSeparator(); - - QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); - - orientation = new QActionGroup(parent); - - QAction *rotateOrientation = new QAction(tr("Rotate orientation"), parent); + QAction *rotateOrientation = new QAction(tr("Rotate orientation"), this); rotateOrientation->setShortcut(QKeySequence("Ctrl+T")); - settingsMenu->addAction(rotateOrientation); connect(rotateOrientation, SIGNAL(triggered()), this, SLOT(rotateOrientation())); + orientation = new QActionGroup(this); orientation->setExclusive(true); connect(orientation, SIGNAL(triggered(QAction*)), this, SLOT(changeOrientation(QAction*))); - orientation->addAction(tr("orientation: Portrait")); - orientation->addAction(tr("orientation: Landscape")); - orientation->addAction(tr("orientation: Portrait (Inverted)")); - orientation->addAction(tr("orientation: Landscape (Inverted)")); - QList actions = orientation->actions(); - for (int i=0; iaddAction(actions[i]); - actions[i]->setCheckable(true); - } + QAction *portraitAction = new QAction(tr("Portrait"), this); + portraitAction->setCheckable(true); + QAction *landscapeAction = new QAction(tr("Landscape"), this); + landscapeAction->setCheckable(true); + QAction *portraitInvAction = new QAction(tr("Portrait (inverted)"), this); + portraitInvAction->setCheckable(true); + QAction *landscapeInvAction = new QAction(tr("Landscape (inverted)"), this); + landscapeInvAction->setCheckable(true); - if (flatmenu) flatmenu->addSeparator(); - - QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help")); - QAction *aboutAction = new QAction(tr("&About Qt..."), parent); + QAction *aboutAction = new QAction(tr("&About Qt..."), this); connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - helpMenu->addAction(aboutAction); - QAction *quitAction = new QAction(tr("&Quit"), parent); + QAction *quitAction = new QAction(tr("&Quit"), this); quitAction->setShortcut(QKeySequence("Ctrl+Q")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + QMenuBar *menu = menuBar(); + if (!menu) + return; + +#if defined(Q_WS_MAEMO_5) + menu->addAction(openAction); + menu->addAction(reloadAction); + + menu->addAction(snapshotAction); + menu->addAction(recordAction); + + menu->addAction(recordOptions); + menu->addAction(proxyAction); + + menu->addAction(slowAction); + menu->addAction(showWarningsWindow); + + orientation->addAction(landscapeAction); + orientation->addAction(portraitAction); + menu->addAction(new Maemo5PickerAction(tr("Set orientation"), orientation, this)); + menu->addAction(fullscreenAction); + return; +#endif // Q_WS_MAEMO_5 + + QMenu *fileMenu = menu->addMenu(tr("&File")); + fileMenu->addAction(openAction); + fileMenu->addAction(reloadAction); fileMenu->addSeparator(); fileMenu->addAction(quitAction); - if (menu) { - menu->setFixedHeight(menu->sizeHint().height()); - menu->setMinimumWidth(10); - } + +#if !defined(Q_OS_SYMBIAN) + QMenu *recordMenu = menu->addMenu(tr("&Recording")); + recordMenu->addAction(snapshotAction); + recordMenu->addAction(recordAction); + + QMenu *debugMenu = menu->addMenu(tr("&Debugging")); + debugMenu->addAction(slowAction); + debugMenu->addAction(showWarningsWindow); +#endif // ! Q_OS_SYMBIAN + + QMenu *settingsMenu = menu->addMenu(tr("S&ettings")); + settingsMenu->addAction(proxyAction); +#if !defined(Q_OS_SYMBIAN) + settingsMenu->addAction(recordOptions); + settingsMenu->addMenu(loggerWindow->preferencesMenu()); +#else // ! Q_OS_SYMBIAN + settingsMenu->addAction(fullscreenAction); +#endif // Q_OS_SYMBIAN + settingsMenu->addAction(rotateOrientation); + + QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); + + orientation->addAction(portraitAction); + orientation->addAction(landscapeAction); + orientation->addAction(portraitInvAction); + orientation->addAction(landscapeInvAction); + propertiesMenu->addActions(orientation->actions()); + + QMenu *helpMenu = menu->addMenu(tr("&Help")); + helpMenu->addAction(aboutAction); } void QDeclarativeViewer::showProxySettings() @@ -685,25 +847,11 @@ void QDeclarativeViewer::chooseRecordingOptions() recdlg->file->setText(record_file); // Size - recdlg->sizeOriginal->setText(tr("Original (%1x%2)").arg(canvas->width()).arg(canvas->height())); - if (recdlg->sizeWidth->value()<=1) { - recdlg->sizeWidth->setValue(canvas->width()); - recdlg->sizeHeight->setValue(canvas->height()); - } + recdlg->setOriginalSize(canvas->size()); // Rate - if (record_rate == 24) - recdlg->hz24->setChecked(true); - else if (record_rate == 25) - recdlg->hz25->setChecked(true); - else if (record_rate == 50) - recdlg->hz50->setChecked(true); - else if (record_rate == 60) - recdlg->hz60->setChecked(true); - else { - recdlg->hzCustom->setChecked(true); - recdlg->hz->setText(QString::number(record_rate)); - } + recdlg->setVideoRate(record_rate); + // Profile recdlg->setArguments(record_args.join(" ")); @@ -711,28 +859,9 @@ void QDeclarativeViewer::chooseRecordingOptions() // File record_file = recdlg->file->text(); // Size - if (recdlg->sizeOriginal->isChecked()) - record_outsize = QSize(); - else if (recdlg->size720p->isChecked()) - record_outsize = QSize(1280,720); - else if (recdlg->sizeVGA->isChecked()) - record_outsize = QSize(640,480); - else if (recdlg->sizeQVGA->isChecked()) - record_outsize = QSize(320,240); - else - record_outsize = QSize(recdlg->sizeWidth->value(),recdlg->sizeHeight->value()); + record_outsize = recdlg->videoSize(); // Rate - if (recdlg->hz24->isChecked()) - record_rate = 24; - else if (recdlg->hz25->isChecked()) - record_rate = 25; - else if (recdlg->hz50->isChecked()) - record_rate = 50; - else if (recdlg->hz60->isChecked()) - record_rate = 60; - else { - record_rate = recdlg->hz->text().toDouble(); - } + record_rate = recdlg->videoRate(); // Profile record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts); } @@ -807,7 +936,8 @@ void QDeclarativeViewer::statusChanged() initialSize = canvas->initialSize(); if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { if (!isFullScreen() && !isMaximized()) { - resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); + canvas->setFixedSize(initialSize); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks updateSizeHints(); } } @@ -1181,14 +1311,14 @@ void QDeclarativeViewer::changeOrientation(QAction *action) return; action->setChecked(true); - QString o = action->text().split(QLatin1Char(':')).value(1).trimmed(); + QString o = action->text(); if (o == QLatin1String("Portrait")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait); else if (o == QLatin1String("Landscape")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape); - else if (o == QLatin1String("Portrait (Inverted)")) + else if (o == QLatin1String("Portrait (inverted)")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::PortraitInverted); - else if (o == QLatin1String("Landscape (Inverted)")) + else if (o == QLatin1String("Landscape (inverted)")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::LandscapeInverted); } @@ -1197,9 +1327,9 @@ void QDeclarativeViewer::orientationChanged() if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { if (canvas->rootObject()) { QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); - QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight()); - if (size() != newSize) { - resize(newSize); + if (size() != rootObjectSize.toSize()) { + canvas->setFixedSize(rootObjectSize.toSize()); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks } } } @@ -1253,16 +1383,13 @@ void QDeclarativeViewer::updateSizeHints() { if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { QSize newWindowSize = canvas->sizeHint(); - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); if (!isFullScreen() && !isMaximized()) { - resize(newWindowSize); - setFixedSize(newWindowSize); + canvas->setFixedSize(newWindowSize); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks } } else { // QDeclarativeView::SizeRootObjectToView canvas->setMinimumSize(QSize(0,0)); canvas->setMaximumSize(QSize(16777215,16777215)); - setMinimumSize(QSize(0,0)); - setMaximumSize(QSize(16777215,16777215)); } } diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 27bd217..cb1b438 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -43,7 +43,6 @@ #define QDECLARATIVEVIEWER_H #include -#include #include #include #include @@ -62,17 +61,17 @@ class QNetworkReply; class QNetworkCookieJar; class NetworkAccessManagerFactory; class QTranslator; +class QActionGroup; class QDeclarativeViewer -#if defined(Q_OS_SYMBIAN) : public QMainWindow -#else - : public QWidget -#endif { -Q_OBJECT + Q_OBJECT + QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0); + static QDeclarativeViewer *inst; + public: - QDeclarativeViewer(QWidget *parent=0, Qt::WindowFlags flags=0); + static QDeclarativeViewer *instance(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~QDeclarativeViewer(); static void registerTypes(); @@ -106,8 +105,6 @@ public: void updateSizeHints(); void setSizeToView(bool sizeToView); - QMenuBar *menuBar() const; - QDeclarativeView *view() const; LoggerWidget *warningsWidget() const; @@ -132,7 +129,7 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual bool event(QEvent *); - void createMenu(QMenuBar *menu, QMenu *flatmenu); + void createMenu(); private slots: void autoStartRecording(); @@ -150,7 +147,6 @@ private slots: private: QString getVideoFileName(); - int menuBarHeight() const; LoggerWidget *loggerWindow; QDeclarativeView *canvas; @@ -173,7 +169,6 @@ private: QAction *recordAction; QString currentSkin; bool scaleSkin; - mutable QMenuBar *mb; RecordingDialog *recdlg; void senseImageMagick(); diff --git a/tools/qml/recopts_maemo5.ui b/tools/qml/recopts_maemo5.ui new file mode 100644 index 0000000..3bb5eca --- /dev/null +++ b/tools/qml/recopts_maemo5.ui @@ -0,0 +1,254 @@ + + + RecordingOptions + + + + 0 + 0 + 469 + 142 + + + + Video options + + + + QLayout::SetMinAndMaxSize + + + 16 + + + 0 + + + 16 + + + 8 + + + 16 + + + 0 + + + + + + + + Qt::Vertical + + + + 72 + 56 + + + + + + + + Size + + + + + + + + + + + + + VGA + + + + + QVGA + + + + + 720p + + + + + + + + Rate + + + + + + + + 60 Hz + + + + + 50 Hz + + + + + 25 Hz + + + + + 24 Hz + + + + + 20 Hz + + + + + 15 Hz + + + + + 10 Hz + + + + + + + + + + + + + + Profile + + + + + + + warning + + + true + + + + + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + File + + + + + + + Options + + + + + + + + + buttonBox + accepted() + RecordingOptions + accept() + + + 258 + 424 + + + 60 + 219 + + + + + buttonBox + rejected() + RecordingOptions + reject() + + + 258 + 424 + + + 92 + 219 + + + + + profile + activated(int) + RecordingOptions + pickProfile(int) + + + 92 + 329 + + + 48 + 194 + + + + + args + textEdited(QString) + RecordingOptions + storeCustomArgs(QString) + + + 128 + 357 + + + 102 + 189 + + + + + + filePicked(QString) + argumentsPicked(QString) + pickFile() + pickProfile(int) + storeCustomArgs(QString) + + diff --git a/tools/qml/texteditautoresizer_maemo5.h b/tools/qml/texteditautoresizer_maemo5.h new file mode 100644 index 0000000..2b9a5f9 --- /dev/null +++ b/tools/qml/texteditautoresizer_maemo5.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#ifndef TEXTEDITAUTORESIZER_H +#define TEXTEDITAUTORESIZER_H + +class TextEditAutoResizer : public QObject +{ + Q_OBJECT +public: + TextEditAutoResizer(QWidget *parent) + : QObject(parent), plainTextEdit(qobject_cast(parent)), + textEdit(qobject_cast(parent)), edit(qobject_cast(parent)) + { + // parent must either inherit QPlainTextEdit or QTextEdit! + Q_ASSERT(plainTextEdit || textEdit); + + connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged())); + connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged())); + + textEditChanged(); + } + +private Q_SLOTS: + inline void textEditChanged(); + +private: + QPlainTextEdit *plainTextEdit; + QTextEdit *textEdit; + QFrame *edit; +}; + +void TextEditAutoResizer::textEditChanged() +{ + QTextDocument *doc = textEdit ? textEdit->document() : plainTextEdit->document(); + QRect cursor = textEdit ? textEdit->cursorRect() : plainTextEdit->cursorRect(); + + QSize s = doc->size().toSize(); + if (plainTextEdit) + s.setHeight((s.height() + 2) * edit->fontMetrics().lineSpacing()); + + const QRect fr = edit->frameRect(); + const QRect cr = edit->contentsRect(); + + edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height() - 1))); + +// QString s1; +// QDebug ts(&s1); +// ts << "DOC: " << s << " CURSOR: " << cursor << " MINH: " << edit->minimumHeight(); +// fprintf(stderr, "%s\n", qPrintable(s1)); + + // make sure the cursor is visible in case we have a QAbstractScrollArea parent + QPoint pos = edit->pos(); + QWidget *pw = edit->parentWidget(); + while (pw) { + if (qobject_cast(pw)) + break; + pw = pw->parentWidget(); + } + + if (pw) { + QScrollArea *area = static_cast(pw); + QPoint scrollto = area->widget()->mapFrom(edit, cursor.center()); + QPoint margin(10 + cursor.width(), 2 * cursor.height()); + + if (QAbstractKineticScroller *scroller = area->property("kineticScroller").value()) { + scroller->ensureVisible(scrollto, margin.x(), margin.y()); + } else { + area->ensureVisible(scrollto.x(), scrollto.y(), margin.x(), margin.y()); + } + } +// QDebug ts(&s2); +// ts << "ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area; +// ts << "PW: " << pw << " PPW: " << (pw ? pw->parentWidget() : 0); //ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area; +// fprintf(stderr, "%s\n", qPrintable(s2)); +} + +#endif -- cgit v0.12 From 7294f46ec0c5ea07e438c45a069a618ceb6e17a9 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Wed, 23 Jun 2010 12:15:36 +0200 Subject: forgot to cleanup the code a bit after adding Maemo5 support --- tools/qml/loggerwidget.cpp | 4 ++-- tools/qml/qmlruntime.cpp | 8 ++++---- tools/qml/texteditautoresizer_maemo5.h | 17 ++++------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 71d20e8..8aa029f 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -63,7 +63,7 @@ LoggerWidget::LoggerWidget(QWidget *parent) : setWindowTitle(tr("Warnings")); m_plainTextEdit = new QPlainTextEdit(); - + #ifdef Q_WS_MAEMO_5 new TextEditAutoResizer(m_plainTextEdit); setAttribute(Qt::WA_Maemo5StackedWindow); @@ -71,7 +71,7 @@ LoggerWidget::LoggerWidget(QWidget *parent) : area->setWidget(m_plainTextEdit); area->setWidgetResizable(true); setCentralWidget(area); -#else +#else setCentralWidget(m_plainTextEdit); #endif readSettings(); diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 090ca2a..3a8af60 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -254,9 +254,9 @@ public: sizeWidth->setValue(s.width()); sizeHeight->setValue(s.height()); } -#endif +#endif } - + void showffmpegOptions(bool b) { #ifdef Q_WS_MAEMO_5 @@ -268,7 +268,7 @@ public: ffmpegOptions->setVisible(b); #endif } - + void showRateOptions(bool b) { #ifdef Q_WS_MAEMO_5 @@ -297,7 +297,7 @@ public: idx = 6; else idx = 7; - rateCombo->setCurrentIndex(idx); + rateCombo->setCurrentIndex(idx); #else if (rate == 24) hz24->setChecked(true); diff --git a/tools/qml/texteditautoresizer_maemo5.h b/tools/qml/texteditautoresizer_maemo5.h index 2b9a5f9..bb5567a 100644 --- a/tools/qml/texteditautoresizer_maemo5.h +++ b/tools/qml/texteditautoresizer_maemo5.h @@ -61,7 +61,7 @@ public: connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged())); connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged())); - + textEditChanged(); } @@ -87,36 +87,27 @@ void TextEditAutoResizer::textEditChanged() const QRect cr = edit->contentsRect(); edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height() - 1))); - -// QString s1; -// QDebug ts(&s1); -// ts << "DOC: " << s << " CURSOR: " << cursor << " MINH: " << edit->minimumHeight(); -// fprintf(stderr, "%s\n", qPrintable(s1)); // make sure the cursor is visible in case we have a QAbstractScrollArea parent QPoint pos = edit->pos(); QWidget *pw = edit->parentWidget(); - while (pw) { + while (pw) { if (qobject_cast(pw)) break; pw = pw->parentWidget(); } - + if (pw) { QScrollArea *area = static_cast(pw); QPoint scrollto = area->widget()->mapFrom(edit, cursor.center()); QPoint margin(10 + cursor.width(), 2 * cursor.height()); - + if (QAbstractKineticScroller *scroller = area->property("kineticScroller").value()) { scroller->ensureVisible(scrollto, margin.x(), margin.y()); } else { area->ensureVisible(scrollto.x(), scrollto.y(), margin.x(), margin.y()); } } -// QDebug ts(&s2); -// ts << "ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area; -// ts << "PW: " << pw << " PPW: " << (pw ? pw->parentWidget() : 0); //ENSURE VIS: " << pos << " + " << cursor.center() << "(pos + cursor.center())" << scroller->isEnabled() << area; -// fprintf(stderr, "%s\n", qPrintable(s2)); } #endif -- cgit v0.12 From 9768a42358d1908701347d52887a964574b1b9b4 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Thu, 24 Jun 2010 18:37:32 +0200 Subject: fix QML Viewer resize modes --- tools/qml/qmlruntime.cpp | 10 ++++++---- tools/qml/qmlruntime.h | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 3a8af60..109de7d 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -937,8 +937,8 @@ void QDeclarativeViewer::statusChanged() if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { if (!isFullScreen() && !isMaximized()) { canvas->setFixedSize(initialSize); - resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks - updateSizeHints(); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrink + QTimer::singleShot(0, this, SLOT(updateSizeHints())); } } } @@ -1328,7 +1328,8 @@ void QDeclarativeViewer::orientationChanged() if (canvas->rootObject()) { QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); if (size() != rootObjectSize.toSize()) { - canvas->setFixedSize(rootObjectSize.toSize()); + canvas->setMinimumSize(rootObjectSize.toSize()); + canvas->resize(rootObjectSize.toSize()); resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks } } @@ -1384,7 +1385,8 @@ void QDeclarativeViewer::updateSizeHints() if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { QSize newWindowSize = canvas->sizeHint(); if (!isFullScreen() && !isMaximized()) { - canvas->setFixedSize(newWindowSize); + canvas->setMinimumSize(newWindowSize); + canvas->resize(newWindowSize); resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks } } else { // QDeclarativeView::SizeRootObjectToView diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index cb1b438..cec3204 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -102,7 +102,6 @@ public: void addPluginPath(const QString& plugin); void setUseGL(bool use); void setUseNativeFileBrowser(bool); - void updateSizeHints(); void setSizeToView(bool sizeToView); QDeclarativeView *view() const; @@ -145,6 +144,8 @@ private slots: void warningsWidgetOpened(); void warningsWidgetClosed(); + void updateSizeHints(); + private: QString getVideoFileName(); -- cgit v0.12 From 82e914952ad82063b31d11916e883e018111fe28 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Thu, 24 Jun 2010 18:53:30 +0200 Subject: fix namespace macros --- tools/qml/loggerwidget.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index 0623432..13c319f 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -45,7 +45,7 @@ #include #include -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QPlainTextEdit; class QMenu; @@ -92,6 +92,8 @@ private: Visibility m_visibility; }; +QT_END_NAMESPACE + Q_DECLARE_METATYPE(LoggerWidget::Visibility) #endif // LOGGERWIDGET_H -- cgit v0.12 From 842ccf428d4cbed3c4ce1e0c894fbebcfd59ce0e Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Thu, 24 Jun 2010 17:26:45 +0200 Subject: forget to rename the moc include when renaming deviceorientation_maemo.cpp --- tools/qml/deviceorientation_maemo5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/qml/deviceorientation_maemo5.cpp b/tools/qml/deviceorientation_maemo5.cpp index 443edc8..e942579 100644 --- a/tools/qml/deviceorientation_maemo5.cpp +++ b/tools/qml/deviceorientation_maemo5.cpp @@ -124,4 +124,4 @@ DeviceOrientation* DeviceOrientation::instance() return o; } -#include "deviceorientation_maemo.moc" +#include "deviceorientation_maemo5.moc" -- cgit v0.12 From aaa7dd6200ce272ea1e3dd78148844200ac698a7 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 25 Jun 2010 19:35:34 +0200 Subject: Tweak Qt Demo Behaviour Don't close on right click inside the demo. --- demos/qtdemo/qmlShell.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index 1fea4a8..e15d33c 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -99,6 +99,7 @@ Item { } MouseArea{ anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton onClicked: loader.focus=true;/* and don't propogate to the 'exit' area*/ } -- cgit v0.12 From 708ec4f1b80d0e9dcc6601a13bc32aee192ba5a4 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 24 Jun 2010 14:44:24 +1000 Subject: Improve appearance when scaling --- .../keyinteraction/focus/Core/ListViewDelegate.qml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml index fba9b05..cc13637 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml @@ -42,7 +42,7 @@ import Qt 4.7 Item { id: container - x: 5; width: ListView.view.width - 10; height: 60 + width: ListView.view.width; height: 60; anchors.leftMargin: 10; anchors.rightMargin: 10 Rectangle { id: content @@ -51,11 +51,15 @@ Item { smooth: true radius: 10 - Rectangle { color: "#91AA9D"; x: 3; y: 3; width: parent.width - 6; height: parent.height - 6; radius: 8 } - Text { - text: "List element " + (index + 1); color: "#193441"; font.bold: false; anchors.centerIn: parent - font.pixelSize: 14 - } + Rectangle { anchors.fill: parent; anchors.margins: 3; color: "#91AA9D"; smooth: true; radius: 8 } + } + + Text { + id: label + anchors.centerIn: content + text: "List element " + (index + 1) + color: "#193441" + font.pixelSize: 14 } MouseArea { @@ -72,6 +76,7 @@ Item { states: State { name: "active"; when: container.focus == true PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } + PropertyChanges { target: label; font.pixelSize: 16 } } transitions: Transition { -- cgit v0.12 From b7a609890f98f2687147605edfc5226ecee64f95 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 24 Jun 2010 15:32:23 +1000 Subject: Docs --- src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp | 2 ++ src/declarative/graphicsitems/qdeclarativeimage.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp index a349bec..0342c9f 100644 --- a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp @@ -180,6 +180,8 @@ void GraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent* event) When this item has keyboard focus, all keyboard input will be sent directly to the web page within. + + \sa {declarative/modelviews/webview}{WebView example}, {demos/declarative/webbrowser}{Web Browser demo} */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index ec08517..ff61302 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -199,6 +199,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) fillMode: Image.PreserveAspectCrop smooth: true source: "qtlogo.png" + clip: true } \endqml @@ -220,6 +221,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) Image { width: 120; height: 120 fillMode: Image.TileVertically + smooth: true source: "qtlogo.png" } \endqml @@ -231,11 +233,14 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) Image { width: 120; height: 120 fillMode: Image.TileHorizontally + smooth: true source: "qtlogo.png" } \endqml \endtable + + \sa {declarative/imageelements/image}{Image example} */ QDeclarativeImage::FillMode QDeclarativeImage::fillMode() const { -- cgit v0.12 From e86022a01152feacea589e14c031994836d665b9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 24 Jun 2010 15:32:40 +1000 Subject: Examples clean up --- doc/src/images/qml-focus-example.png | Bin 43921 -> 31370 bytes .../animation/behaviors/behavior-example.qml | 2 +- .../keyinteraction/focus/Core/GridMenu.qml | 7 ++++--- .../keyinteraction/focus/Core/ListViews.qml | 4 ++-- examples/declarative/keyinteraction/focus/focus.qml | 5 +++-- .../progressbar/content/ProgressBar.qml | 2 +- .../ui-components/searchbox/SearchBox.qml | 2 +- .../declarative/ui-components/tabwidget/main.qml | 6 +++--- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/src/images/qml-focus-example.png b/doc/src/images/qml-focus-example.png index 0ec2bff..107d2cb 100644 Binary files a/doc/src/images/qml-focus-example.png and b/doc/src/images/qml-focus-example.png differ diff --git a/examples/declarative/animation/behaviors/behavior-example.qml b/examples/declarative/animation/behaviors/behavior-example.qml index d187fbf..adefb9e 100644 --- a/examples/declarative/animation/behaviors/behavior-example.qml +++ b/examples/declarative/animation/behaviors/behavior-example.qml @@ -82,7 +82,7 @@ Rectangle { property string text - x: 62.5; y: 75; width: 75; height: 50 + x: 62; y: 75; width: 75; height: 50 radius: 6 border.width: 4; border.color: "white" color: "firebrick" diff --git a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml index d0b45f5..9a8d3f3 100644 --- a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml +++ b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml @@ -55,10 +55,11 @@ FocusScope { GridView { id: gridView - x: 20; width: parent.width - 40; height: parent.height + anchors.fill: parent; anchors.leftMargin: 20; anchors.rightMargin: 20 cellWidth: 152; cellHeight: 152 focus: true model: 12 + KeyNavigation.down: listViews KeyNavigation.left: contextMenu @@ -70,9 +71,9 @@ FocusScope { id: content color: "transparent" smooth: true - anchors.centerIn: parent; width: container.width - 40; height: container.height - 40; radius: 10 + anchors.fill: parent; anchors.margins: 20; radius: 10 - Rectangle { color: "#91AA9D"; x: 3; y: 3; width: parent.width - 6; height: parent.height - 6; radius: 8 } + Rectangle { color: "#91AA9D"; anchors.fill: parent; anchors.margins: 3; radius: 8; smooth: true } Image { source: "images/qt-logo.png"; anchors.centerIn: parent; smooth: true } } diff --git a/examples/declarative/keyinteraction/focus/Core/ListViews.qml b/examples/declarative/keyinteraction/focus/Core/ListViews.qml index 670a3fa..6f9ceb4 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViews.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViews.qml @@ -60,7 +60,7 @@ FocusScope { ListView { id: list2 - y: wantsFocus ? 10 : 40; x: parent.width / 3; width: parent.width / 3; height: parent.height - 20 + y: wantsFocus ? 10 : 40; x: parseInt(parent.width / 3); width: parent.width / 3; height: parent.height - 20 KeyNavigation.up: gridMenu; KeyNavigation.left: list1; KeyNavigation.right: list3 model: 10; cacheBuffer: 200 delegate: ListViewDelegate {} @@ -72,7 +72,7 @@ FocusScope { ListView { id: list3 - y: wantsFocus ? 10 : 40; x: 2 * parent.width / 3; width: parent.width / 3; height: parent.height - 20 + y: wantsFocus ? 10 : 40; x: parseInt(2 * parent.width / 3); width: parent.width / 3; height: parent.height - 20 KeyNavigation.up: gridMenu; KeyNavigation.left: list2 model: 10; cacheBuffer: 200 delegate: ListViewDelegate {} diff --git a/examples/declarative/keyinteraction/focus/focus.qml b/examples/declarative/keyinteraction/focus/focus.qml index 068ba1d..8b2af70 100644 --- a/examples/declarative/keyinteraction/focus/focus.qml +++ b/examples/declarative/keyinteraction/focus/focus.qml @@ -68,7 +68,8 @@ Rectangle { Rectangle { id: shade - color: "black"; opacity: 0; anchors.fill: parent + anchors.fill: parent + color: "black"; opacity: 0 } states: State { @@ -88,7 +89,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter MouseArea { - anchors { fill: parent; leftMargin: -10; topMargin: -10; rightMargin: -10; bottomMargin: -10 } + anchors.fill: parent; anchors.margins: -10 onClicked: window.state = "contextMenuOpen" } } diff --git a/examples/declarative/ui-components/progressbar/content/ProgressBar.qml b/examples/declarative/ui-components/progressbar/content/ProgressBar.qml index 829ab9b..6aa6765 100644 --- a/examples/declarative/ui-components/progressbar/content/ProgressBar.qml +++ b/examples/declarative/ui-components/progressbar/content/ProgressBar.qml @@ -66,7 +66,7 @@ Item { width: highlight.widthDest Behavior on width { SmoothedAnimation { velocity: 1200 } } - anchors { left: parent.left; top: parent.top; bottom: parent.bottom; leftMargin: 3; topMargin: 3; bottomMargin: 3 } + anchors { left: parent.left; top: parent.top; bottom: parent.bottom; margins: 3 } radius: 1 gradient: Gradient { GradientStop { id: gradient1; position: 0.0 } diff --git a/examples/declarative/ui-components/searchbox/SearchBox.qml b/examples/declarative/ui-components/searchbox/SearchBox.qml index e6b9c8f..6d87837 100644 --- a/examples/declarative/ui-components/searchbox/SearchBox.qml +++ b/examples/declarative/ui-components/searchbox/SearchBox.qml @@ -73,7 +73,7 @@ FocusScope { TextInput { id: textInput - anchors { left: parent.left; leftMargin: 8; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; leftMargin: 8; right: clear.left; rightMargin: 8; verticalCenter: parent.verticalCenter } focus: true } diff --git a/examples/declarative/ui-components/tabwidget/main.qml b/examples/declarative/ui-components/tabwidget/main.qml index e11902a..4a27806 100644 --- a/examples/declarative/ui-components/tabwidget/main.qml +++ b/examples/declarative/ui-components/tabwidget/main.qml @@ -50,7 +50,7 @@ TabWidget { color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#ff7f7f" Text { width: parent.width - 20 @@ -68,7 +68,7 @@ TabWidget { color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#7fff7f" Text { width: parent.width - 20 @@ -85,7 +85,7 @@ TabWidget { anchors.fill: parent; color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#7f7fff" Text { width: parent.width - 20 -- cgit v0.12 From de8daddf8823213eb8312e3a404e7a499b5e5011 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 28 Jun 2010 11:43:29 +1000 Subject: Allow positioning of ListView items width sub-pixel precision. Which makes having delegates with integer sizes more important, but allows proper animation of delegate size. Task-number: QTBUG-11738 --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 6fc066d..a69fc3f 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -105,7 +105,7 @@ public: else return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); } - int size() const { + qreal size() const { if (section) return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->height()); else @@ -476,7 +476,7 @@ public: QHash unrequestedItems; FxListItem *currentItem; QDeclarativeListView::Orientation orient; - int visiblePos; + qreal visiblePos; int visibleIndex; qreal averageSize; int currentIndex; @@ -655,7 +655,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) bool changed = false; FxListItem *item = 0; - int pos = itemEnd + 1; + qreal pos = itemEnd + 1; while (modelIndex < model->count() && pos <= fillTo) { // qDebug() << "refill: append item" << modelIndex << "pos" << pos; if (!(item = createItem(modelIndex))) @@ -744,8 +744,8 @@ void QDeclarativeListViewPrivate::layout() } updateSections(); if (!visibleItems.isEmpty()) { - int oldEnd = visibleItems.last()->endPosition(); - int pos = visibleItems.first()->endPosition() + spacing + 1; + qreal oldEnd = visibleItems.last()->endPosition(); + qreal pos = visibleItems.first()->endPosition() + spacing + 1; for (int i=1; i < visibleItems.count(); ++i) { FxListItem *item = visibleItems.at(i); item->setPosition(pos); @@ -1027,7 +1027,7 @@ void QDeclarativeListViewPrivate::updateAverage() qreal sum = 0.0; for (int i = 0; i < visibleItems.count(); ++i) sum += visibleItems.at(i)->size(); - averageSize = sum / visibleItems.count(); + averageSize = qRound(sum / visibleItems.count()); } void QDeclarativeListViewPrivate::updateFooter() @@ -1547,9 +1547,12 @@ void QDeclarativeListView::setModel(const QVariant &model) that is not needed for the normal display of the delegate in a \l Loader which can load additional elements when needed. - Tthe ListView will lay out the items based on the size of the root item + The ListView will lay out the items based on the size of the root item in the delegate. + It is recommended that the delagate's size be a whole number to avoid sub-pixel + alignment of items. + \note Delegates are instantiated as needed and may be destroyed at any time. State should \e never be stored in a delegate. */ -- cgit v0.12 From 3dae114528ecaed19b8ffca4739ed4e88477554e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 28 Jun 2010 14:18:22 +1000 Subject: VisualDataModel hasModelChildren role shadowed user roles. Task-number: BAUHAUS-773 --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 5092349..8071d7a 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -283,7 +283,7 @@ public: if (m_roles.count() == 1) m_roleNames.insert("modelData", m_roles.at(0)); if (m_roles.count()) - m_roleNames.insert("hasModelChildren", 0); + m_roleNames.insert("hasModelChildren", -1); } else if (m_listAccessor) { m_roleNames.insert("modelData", 0); if (m_listAccessor->type() == QDeclarativeListAccessor::Instance) { -- cgit v0.12 From 2999c11b25b03d39f5abfe0f00607be6d536e3ce Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 28 Jun 2010 13:53:52 +1000 Subject: Stop QMLLauncher from crashing on exit on Mac when quitting app via the menu. This sets the QGraphicsView::viewport() to 0 on exit to avoid "QGLContext::makeCurrent: Cannot make invalid context current" errors on exit, and deletes the logger window on exit so it does not receive error messages after the app is closed. The QGLContext errors appeared after 6d4e14ef0437ce8f73bddbcb267cf5ef708fbdec. --- tools/qml/qmlruntime.cpp | 12 ++++++++++++ tools/qml/qmlruntime.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 109de7d..e0482cf 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -623,6 +623,8 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) autoStopTimer.setRunning(false); recordTimer.setRunning(false); recordTimer.setRepeating(true); + + QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(appAboutToQuit())); } QDeclarativeViewer::~QDeclarativeViewer() @@ -1277,6 +1279,16 @@ void QDeclarativeViewer::ffmpegFinished(int code) qDebug() << "ffmpeg returned" << code << frame_stream->readAllStandardError(); } +void QDeclarativeViewer::appAboutToQuit() +{ + // avoid QGLContext errors about invalid contexts on exit + canvas->setViewport(0); + + // avoid crashes if messages are received after app has closed + delete loggerWindow; + loggerWindow = 0; +} + void QDeclarativeViewer::autoStartRecording() { setRecording(true); diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index cec3204..92c2969 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -131,6 +131,8 @@ protected: void createMenu(); private slots: + void appAboutToQuit(); + void autoStartRecording(); void autoStopRecording(); void recordFrame(); -- cgit v0.12