From 83d799a00dd4417f6d2efb02781e332f510dab6a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 20 Jul 2010 08:58:08 +1000 Subject: Improve QML text rendering when LCD smoothing is enabled for OS X. Text in QML is always painted into a pixmap, and with sub-pixel antialiasing enabled this produced incorrect results. This patch is a temporary fix until QTBUG-12252 and/or QTBUG-7747 can be properly addressed in a patch release. In the worst case, if using QML and QPainters are being constructed in a non-GUI thread, this patch could potentially turn off sub-pixel antialiasing for them. Task-number: QTBUG-11002 Reviewed-by: Aaron Kennedy Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../graphicsitems/qdeclarativepainteditem.cpp | 16 ++++++++++++++++ src/declarative/graphicsitems/qdeclarativetext.cpp | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 3b9b8df..a6db1fa 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -90,6 +90,8 @@ QT_BEGIN_NAMESPACE static int inpaint=0; static int inpaint_clearcache=0; +extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; + /*! Marks areas of the cache that intersect with the given \a rect as dirty and in need of being refreshed. @@ -287,7 +289,14 @@ void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem QRectF target(area.x(), area.y(), area.width(), area.height()); if (!d->cachefrozen) { if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { +#ifdef Q_WS_MAC + bool oldSmooth = qt_applefontsmoothing_enabled; + qt_applefontsmoothing_enabled = false; +#endif QPainter qp(&d->imagecache[i]->image); +#ifdef Q_WS_MAC + qt_applefontsmoothing_enabled = oldSmooth; +#endif qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); qp.translate(-area.x(), -area.y()); qp.scale(d->contentsScale,d->contentsScale); @@ -349,7 +358,14 @@ void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem if (d->fillColor.isValid()) img.fill(d->fillColor); { +#ifdef Q_WS_MAC + bool oldSmooth = qt_applefontsmoothing_enabled; + qt_applefontsmoothing_enabled = false; +#endif QPainter qp(&img); +#ifdef Q_WS_MAC + qt_applefontsmoothing_enabled = oldSmooth; +#endif qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); qp.translate(-r.x(),-r.y()); diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index ba4fa21..d63d633 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE +extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; + class QTextDocumentWithImageResources : public QTextDocument { Q_OBJECT @@ -1028,7 +1030,14 @@ QPixmap QDeclarativeTextPrivate::wrappedTextImage(bool drawStyle) QPixmap img(size); if (!size.isEmpty()) { img.fill(Qt::transparent); +#ifdef Q_WS_MAC + bool oldSmooth = qt_applefontsmoothing_enabled; + qt_applefontsmoothing_enabled = false; +#endif QPainter p(&img); +#ifdef Q_WS_MAC + qt_applefontsmoothing_enabled = oldSmooth; +#endif drawWrappedText(&p, QPointF(0,0), drawStyle); } return img; @@ -1051,7 +1060,14 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle) //paint text QPixmap img(size); img.fill(Qt::transparent); +#ifdef Q_WS_MAC + bool oldSmooth = qt_applefontsmoothing_enabled; + qt_applefontsmoothing_enabled = false; +#endif QPainter p(&img); +#ifdef Q_WS_MAC + qt_applefontsmoothing_enabled = oldSmooth; +#endif QAbstractTextDocumentLayout::PaintContext context; -- cgit v0.12 From 17cc89e918a969d85d2b46631ee8743288c7586d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 20 Jul 2010 10:14:38 +1000 Subject: Ensure released VisualItemModel items are removed from the scene. Also parent them back to the VIM to ensure correct destruction. Task-number: QTBUG-12261 --- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 8 +++--- .../qdeclarativerepeater/data/itemlist.qml | 29 +++++++++++++++++++--- .../tst_qdeclarativerepeater.cpp | 9 +++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index cfa1c6d..7952b97 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -77,7 +77,7 @@ public: QDeclarativeVisualItemModelPrivate() : QObjectPrivate() {} static void children_append(QDeclarativeListProperty *prop, QDeclarativeItem *item) { - item->QObject::setParent(prop->object); + QDeclarative_setParent_noEvent(item, prop->object); static_cast(prop->data)->children.append(item); static_cast(prop->data)->itemAppended(); static_cast(prop->data)->emitChildrenChanged(); @@ -185,9 +185,11 @@ QDeclarativeItem *QDeclarativeVisualItemModel::item(int index, bool) return d->children.at(index); } -QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *) +QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *item) { - // Nothing to do + if (item->scene()) + item->scene()->removeItem(item); + QDeclarative_setParent_noEvent(item, this); return 0; } diff --git a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml index e8dd8cc..4810736 100644 --- a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml +++ b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml @@ -4,21 +4,27 @@ import Qt 4.7 Rectangle { + id: root color: "lightgray" width: 240 height: 320 + property variant itemModel: itemModel1 function checkProperties() { testObject.error = false; - if (testObject.useModel && view.model != itemModel) { + if (testObject.useModel && view.model != root.itemModel) { console.log("model property incorrect"); testObject.error = true; } } + function switchModel() { + root.itemModel = itemModel2 + } + VisualItemModel { - id: itemModel - objectName: "itemModel" + id: itemModel1 + objectName: "itemModel1" Rectangle { objectName: "item1" height: 50; width: 100; color: "#FFFEF0" @@ -36,12 +42,27 @@ Rectangle { } } + VisualItemModel { + id: itemModel2 + objectName: "itemModel2" + Rectangle { + objectName: "item4" + height: 50; width: 100; color: "#FFFEF0" + Text { objectName: "text4"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } + } + Rectangle { + objectName: "item5" + height: 50; width: 100; color: "#F0FFF7" + Text { objectName: "text5"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } + } + } + Column { objectName: "container" Repeater { id: view objectName: "repeater" - model: testObject.useModel ? itemModel : 0 + model: testObject.useModel ? root.itemModel : 0 } } } diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp index 7299a43..623b3d7 100644 --- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp +++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp @@ -361,6 +361,15 @@ void tst_QDeclarativeRepeater::itemModel() QVERIFY(qobject_cast(container->childItems().at(2))->objectName() == "item3"); QVERIFY(container->childItems().at(3) == repeater); + QMetaObject::invokeMethod(canvas->rootObject(), "switchModel"); + QCOMPARE(container->childItems().count(), 3); + QVERIFY(qobject_cast(container->childItems().at(0))->objectName() == "item4"); + QVERIFY(qobject_cast(container->childItems().at(1))->objectName() == "item5"); + QVERIFY(container->childItems().at(2) == repeater); + + testObject->setUseModel(false); + QCOMPARE(container->childItems().count(), 1); + delete testObject; delete canvas; } -- cgit v0.12 From 06ef198e0812b514c261ef8f7c82db754450f1fa Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 20 Jul 2010 11:28:36 +1000 Subject: Improve documentation on setting arbitray transform origin points transformOriginPoint is undocumented for a reason. It shouldn't be used by Item. Added some docs to assist find the right way, i.e. Scale and Rotation elements. Task-number: QTBUG-12265 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 367a5d0..9d70beb 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1514,6 +1514,9 @@ QDeclarativeItem::~QDeclarativeItem() \endqml The default transform origin is \c Item.Center. + + To set an arbitrary transform origin point use the \l Scale or \l Rotation + transform elements. */ /*! @@ -2192,6 +2195,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) } \endqml \endtable + + \sa transform, Rotation */ /*! @@ -2228,6 +2233,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) } \endqml \endtable + + \sa transform, Scale */ /*! -- cgit v0.12 From 8e19cbbad806b710e03ff17e80646e0274cf63cc Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 19 Jul 2010 12:20:11 +1000 Subject: Change docs to show how to define enum properties --- doc/src/declarative/extending-tutorial.qdoc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/src/declarative/extending-tutorial.qdoc b/doc/src/declarative/extending-tutorial.qdoc index cc93e86..bc849b0 100644 --- a/doc/src/declarative/extending-tutorial.qdoc +++ b/doc/src/declarative/extending-tutorial.qdoc @@ -260,20 +260,34 @@ custom QML types may see unexpected behavior if bindings are not implemented. \example declarative/tutorials/extending/chapter4-customPropertyTypes The \c PieChart type currently has a string-type property and a color-type property. -It could have many other types of properties. For example, we could add an -integer-type property to store an identifier for each pie chart: +It could have many other types of properties. For example, it could have an +enum-type property to store a display mode for each chart: \code + // C++ class PieChart : public QDeclarativeItem { + Q_ENUMS(DisplayMode) + Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode) ... - Q_PROPERTY(int id READ id WRITE setId) + public: - ... - int id() const; - void setId(int id); + enum DisplayMode { + MultiLevel, + Exploded, + ThreeDimensional + }; + + void setDisplayMode(DisplayMode mode); + DisplayMode displayMode() const; ... }; + + // QML + PieChart { + ... + displayMode: PieChart.Exploded + } \endcode We can also use various other property types. QML has built-in support for the following -- cgit v0.12 From c95889b7896dc5418841ef72326d99296943e616 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 20 Jul 2010 11:40:37 +1000 Subject: fixes for dynamic object creation docs --- doc/src/declarative/dynamicobjects.qdoc | 77 ++++++++++++++--------- doc/src/snippets/declarative/componentCreation.js | 63 ++++++++++--------- doc/src/snippets/declarative/createComponent.qml | 4 +- doc/src/snippets/declarative/createQmlObject.qml | 3 +- 4 files changed, 84 insertions(+), 63 deletions(-) diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index a5e53a9..6bce4fa 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -39,31 +39,35 @@ QML also supports the dynamic creation of objects from within JavaScript code. This is useful if the existing QML elements do not fit the needs of your application, and there are no C++ components involved. -See the {declarative/toys/dynamicscene}{Dynamic Scene example} for a demonstration +See the \l {declarative/toys/dynamicscene}{Dynamic Scene example} for a demonstration of the concepts discussed on this page. \section1 Creating Objects Dynamically There are two ways to create objects dynamically from JavaScript. You can either call -\l {QML:Qt::createComponent()}{Qt.createComponent()} to create -a component which instantiates items, or use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} +\l {QML:Qt::createComponent()}{Qt.createComponent()} to dynamically create +a \l Component object, or use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} to create an item from a string of QML. -Creating a component is better if you have a predefined -item, and you want to create dynamic instances of that item; creating an item from -a string of QML is useful when the item QML itself is generated at runtime. +Creating a component is better if you have an existing component defined in a \c .qml +file, and you want to dynamically create instances of that component. Otherwise, +creating an item from a string of QML is useful when the item QML itself is generated +at runtime. -If you have a component specified in a QML file, you can dynamically load it with -the \l {QML:Qt::createComponent()}{Qt.createComponent()} function on the \l{QML Global Object}. -This function takes the URL of the QML file as its only argument and returns -a component object which can be used to create and load that QML file. -Once you have a component you can use its \l {Component::createObject()}{createObject()} method to create an instance of +\section2 Creating a Component dynamically + +To dynamically load a component defined in a QML file, call the +\l {QML:Qt::createComponent()}{Qt.createComponent()} function on the \l{QML Global Object}. +This function takes the URL of the QML file as its only argument and creates +a \l Component object from this URL. + +Once you have a \l Component, you can call its \l {Component::createObject()}{createObject()} method to create an instance of the component. This function takes exactly one argument, which is the parent for the new item. Since graphical items will not appear on the scene without a parent, it is recommended that you set the parent this way. However, if you wish to set -the parent later you can safely pass null to this function. +the parent later you can safely pass \c null to this function. -Here is an example. Here is a \c Sprite.qml, which defines a simple QML component: +Here is an example. First there is \c Sprite.qml, which defines a simple QML component: \snippet doc/src/snippets/declarative/Sprite.qml 0 @@ -72,35 +76,48 @@ that will create \c Sprite objects: \snippet doc/src/snippets/declarative/createComponent.qml 0 -Here is \c componentCreation.js. Remember that QML files that might be loaded -over the network cannot be expected to be ready immediately: +Here is \c componentCreation.js. Notice it checks whether the component \l{Component::status}{status} is +\c Component.Ready before calling \l {Component::createObject()}{createObject()} +in case the QML file is loaded over a network and thus is not ready immediately. -\snippet doc/src/snippets/declarative/componentCreation.js 0 +\snippet doc/src/snippets/declarative/componentCreation.js vars \codeline -\snippet doc/src/snippets/declarative/componentCreation.js 1 +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js remote +\snippet doc/src/snippets/declarative/componentCreation.js func-end +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js finishCreation -If you are certain the files will be local, you could simplify to: +If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation() +function and call \l {Component::createObject()}{createObject()} immediately: -\snippet doc/src/snippets/declarative/componentCreation.js 2 +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js local +\snippet doc/src/snippets/declarative/componentCreation.js func-end -Notice that once a \c Sprite object is created, its parent is set to \c appWindow (defined -in \c main.qml). After creating an item, you must set its parent to an item within the scene. -Otherwise your dynamically created item will not appear in the scene. +Notice in both instances, \l {Component::createObject()}{createObject()} is called with +\c appWindow passed as an argument so that the created object will become a child of the +\c appWindow item in \c main.qml. Otherwise, the new item will not appear in the scene. When using files with relative paths, the path should be relative to the file where \l {QML:Qt::createComponent()}{Qt.createComponent()} is executed. -If the QML component does not exist until runtime, you can create a QML item from + +\section2 Creating an object from a string of QML + +If the QML is not defined until runtime, you can create a QML item from a string of QML using the \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} function, as in the following example: \snippet doc/src/snippets/declarative/createQmlObject.qml 0 The first argument is the string of QML to create. Just like in a new file, you will need to -import any types you wish to use. For importing files with relative paths, the path should -be relative to the file where the item in the second argument is defined. Remember to set the parent after -creating the item. The second argument is another item in the scene, and the new item is created -in the same QML Context as this item. The third argument is the file path associated with this -item, which is used for error reporting. +import any types you wish to use. The second argument is the parent item for the new item; +this should be an existing item in the scene. The third argument is the file path to associate +with the new item; this is used for error reporting. + +If the string of QML imports files using relative paths, the path should be relative +to the file in which the parent item (the second argument to the method) is defined. + \section1 Maintaining Dynamically Created Objects @@ -114,9 +131,9 @@ The actual creation context depends on how an item is created: \o If \l {QML:Qt::createComponent()}{Qt.createComponent()} is used, the creation context is the QDeclarativeContext in which this method is called \o If \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} - if called, it is the context of the item used as the second argument to this method + if called, the creation context is the context of the parent item passed to this method \o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()} - is called on that item, it is the context in which the \c Component is defined + is called on that item, the creation context is the context in which the \c Component is defined \endlist Also, note that while dynamically created objects may be used the same as other objects, they diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js index 25bc10c..c29a1f9 100644 --- a/doc/src/snippets/declarative/componentCreation.js +++ b/doc/src/snippets/declarative/componentCreation.js @@ -1,7 +1,39 @@ -//![0] +//![vars] var component; var sprite; +//![vars] +//![func] +function createSpriteObjects() { +//![func] + +//![remote] + component = Qt.createComponent("Sprite.qml"); + if (component.status == Component.Ready) + finishCreation(); + else + component.statusChanged.connect(finishCreation); +//![remote] + +//![local] + component = Qt.createComponent("Sprite.qml"); + sprite = component.createObject(appWindow); + + if (sprite == null) { + // Error Handling + console.log("Error creating object"); + } else { + sprite.x = 100; + sprite.y = 100; + // ... + } +//![local] + +//![func-end] +} +//![func-end] + +//![finishCreation] function finishCreation() { if (component.status == Component.Ready) { sprite = component.createObject(appWindow); @@ -17,31 +49,4 @@ function finishCreation() { console.log("Error loading component:", component.errorString()); } } -//![0] - -function createSpriteObjects() { - -//![1] -component = Qt.createComponent("Sprite.qml"); -if (component.status == Component.Ready) - finishCreation(); -else - component.statusChanged.connect(finishCreation); -//![1] - -//![2] -component = Qt.createComponent("Sprite.qml"); -sprite = component.createObject(appWindow); - -if (sprite == null) { - // Error Handling - console.log("Error loading component:", component.errorString()); -} else { - sprite.x = 100; - sprite.y = 100; - // ... -} -//![2] - -} - +//![finishCreation] diff --git a/doc/src/snippets/declarative/createComponent.qml b/doc/src/snippets/declarative/createComponent.qml index 8bfed07..0f9fad5 100644 --- a/doc/src/snippets/declarative/createComponent.qml +++ b/doc/src/snippets/declarative/createComponent.qml @@ -40,12 +40,12 @@ //![0] import Qt 4.7 -import "componentCreation.js" as MyModule +import "componentCreation.js" as MyScript Rectangle { id: appWindow width: 300; height: 300 - Component.onCompleted: MyModule.createSpriteObjects(); + Component.onCompleted: MyScript.createSpriteObjects(); } //![0] diff --git a/doc/src/snippets/declarative/createQmlObject.qml b/doc/src/snippets/declarative/createQmlObject.qml index 380f6f1..64dd21d 100644 --- a/doc/src/snippets/declarative/createQmlObject.qml +++ b/doc/src/snippets/declarative/createQmlObject.qml @@ -42,14 +42,13 @@ import Qt 4.7 Rectangle { id: parentItem - property QtObject newObject width: 100 height: 100 function createIt() { //![0] -newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', +var newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', parentItem, "dynamicSnippet1"); //![0] } -- cgit v0.12 From 5b39b47255d04675f15b242252565ec0b7e8e78e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 20 Jul 2010 11:44:05 +1000 Subject: various doc improvements for animation elements --- doc/src/snippets/declarative/behavior.qml | 59 +++++ doc/src/snippets/declarative/parallelanimation.qml | 57 +++++ doc/src/snippets/declarative/parentchange.qml | 5 +- doc/src/snippets/declarative/rotationanimation.qml | 66 ++++++ .../snippets/declarative/sequentialanimation.qml | 57 +++++ doc/src/snippets/declarative/springanimation.qml | 6 +- src/declarative/qml/qdeclarativeengine.cpp | 15 +- src/declarative/util/qdeclarativeanimation.cpp | 257 +++++++++++---------- src/declarative/util/qdeclarativebehavior.cpp | 39 ++-- .../util/qdeclarativesmoothedanimation.cpp | 31 +-- .../util/qdeclarativespringanimation.cpp | 39 ++-- src/declarative/util/qdeclarativetransition.cpp | 2 - 12 files changed, 445 insertions(+), 188 deletions(-) create mode 100644 doc/src/snippets/declarative/behavior.qml create mode 100644 doc/src/snippets/declarative/parallelanimation.qml create mode 100644 doc/src/snippets/declarative/rotationanimation.qml create mode 100644 doc/src/snippets/declarative/sequentialanimation.qml diff --git a/doc/src/snippets/declarative/behavior.qml b/doc/src/snippets/declarative/behavior.qml new file mode 100644 index 0000000..420dfc4 --- /dev/null +++ b/doc/src/snippets/declarative/behavior.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ + +//![0] +import Qt 4.7 + +Rectangle { + id: rect + width: 100; height: 100 + color: "red" + + Behavior on width { + NumberAnimation { duration: 1000 } + } + + MouseArea { + anchors.fill: parent + onClicked: rect.width = 50 + } +} +//![0] diff --git a/doc/src/snippets/declarative/parallelanimation.qml b/doc/src/snippets/declarative/parallelanimation.qml new file mode 100644 index 0000000..d823b4f --- /dev/null +++ b/doc/src/snippets/declarative/parallelanimation.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ + +//![0] +import Qt 4.7 + +Rectangle { + id: rect + width: 100; height: 100 + color: "red" + + ParallelAnimation { + running: true + NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 } + } +} +//![0] + diff --git a/doc/src/snippets/declarative/parentchange.qml b/doc/src/snippets/declarative/parentchange.qml index 7f5718a..ea50832 100644 --- a/doc/src/snippets/declarative/parentchange.qml +++ b/doc/src/snippets/declarative/parentchange.qml @@ -41,9 +41,8 @@ //![0] import Qt 4.7 -Rectangle { - width: 200 - height: 100 +Item { + width: 200; height: 100 Rectangle { id: redRect diff --git a/doc/src/snippets/declarative/rotationanimation.qml b/doc/src/snippets/declarative/rotationanimation.qml new file mode 100644 index 0000000..c81395a --- /dev/null +++ b/doc/src/snippets/declarative/rotationanimation.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ + +//![0] +import Qt 4.7 + +Item { + width: 300; height: 300 + + Rectangle { + id: rect + width: 150; height: 100; anchors.centerIn: parent + color: "red" + smooth: true + + states: State { + name: "rotated"; PropertyChanges { target: rect; rotation: 180 } + } + + transitions: Transition { + RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise } + } + } + + MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" } +} +//![0] + diff --git a/doc/src/snippets/declarative/sequentialanimation.qml b/doc/src/snippets/declarative/sequentialanimation.qml new file mode 100644 index 0000000..a15f7f3 --- /dev/null +++ b/doc/src/snippets/declarative/sequentialanimation.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ + +//![0] +import Qt 4.7 + +Rectangle { + id: rect + width: 100; height: 100 + color: "red" + + SequentialAnimation { + running: true + NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 } + } +} +//![0] + diff --git a/doc/src/snippets/declarative/springanimation.qml b/doc/src/snippets/declarative/springanimation.qml index b73a9d2..8e810e1 100644 --- a/doc/src/snippets/declarative/springanimation.qml +++ b/doc/src/snippets/declarative/springanimation.qml @@ -41,7 +41,7 @@ //![0] import Qt 4.7 -Rectangle { +Item { width: 300; height: 300 Rectangle { @@ -56,8 +56,8 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - rect.x = mouse.x - rect.y = mouse.y + rect.x = mouse.x - rect.width/2 + rect.y = mouse.y - rect.height/2 } } } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index f2eb770..d1ba6ce 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1080,13 +1080,20 @@ Here is an example. Notice it checks whether the component \l{Component::status} \c Component.Ready before calling \l {Component::createObject()}{createObject()} in case the QML file is loaded over a network and thus is not ready immediately. -\snippet doc/src/snippets/declarative/componentCreation.js 0 +\snippet doc/src/snippets/declarative/componentCreation.js vars \codeline -\snippet doc/src/snippets/declarative/componentCreation.js 1 +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js remote +\snippet doc/src/snippets/declarative/componentCreation.js func-end +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js finishCreation -If you are certain the files will be local, you could simplify to: +If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation() +function and call \l {Component::createObject()}{createObject()} immediately: -\snippet doc/src/snippets/declarative/componentCreation.js 2 +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js local +\snippet doc/src/snippets/declarative/componentCreation.js func-end To create a QML object from an arbitrary string of QML (instead of a file), use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}. diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 88ec5ba..3617031 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -632,17 +632,18 @@ QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation() \qmlclass ColorAnimation QDeclarativeColorAnimation \since 4.7 \inherits PropertyAnimation - \brief The ColorAnimation element allows you to animate color changes. + \brief The ColorAnimation element animates changes in color values. - ColorAnimation defines an animation to be applied when a color value - changes. + ColorAnimation is a specialized PropertyAnimation that defines an + animation to be applied when a color value changes. Here is a ColorAnimation applied to the \c color property of a \l Rectangle - as a property value source: + as a property value source. It animates the \c color property's value from + its current value to a value of "red", over 1000 milliseconds: \snippet doc/src/snippets/declarative/coloranimation.qml 0 - Like any other animation element, a NumberAnimation can be applied in a + Like any other animation element, a ColorAnimation can be applied in a number of ways, including transitions, behaviors and property value sources. The \l PropertyAnimation documentation shows a variety of methods for creating animations. @@ -674,11 +675,12 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation() /*! \qmlproperty color ColorAnimation::from - This property holds the starting color. + This property holds the color value at which the animation should begin. For example, the following animation is not applied until a color value has reached "#c0c0c0": + \qml Item { states: [ ... ] @@ -686,6 +688,11 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation() NumberAnimation { from: "#c0c0c0"; duration: 2000 } } } + \endqml + + If this value is not set and the ColorAnimation is defined within + a \l Transition, it defaults to the value defined in the starting + state of the \l Transition. */ QColor QDeclarativeColorAnimation::from() const { @@ -700,7 +707,12 @@ void QDeclarativeColorAnimation::setFrom(const QColor &f) /*! \qmlproperty color ColorAnimation::to - This property holds the ending color. + + This property holds the color value at which the animation should end. + + If this value is not set and the ColorAnimation is defined within + a \l Transition or \l Behavior, it defaults to the value defined in the end + state of the \l Transition or \l Behavior. */ QColor QDeclarativeColorAnimation::to() const { @@ -869,18 +881,27 @@ QAbstractAnimation *QDeclarativeScriptAction::qtAnimation() \inherits Animation \brief The PropertyAction element allows immediate property changes during animation. - Explicitly set \c theimage.smooth=true during a transition: + PropertyAction is used to specify an immediate property change + during an animation. The property change is not animated. + + For example, to explicitly set \c {theImage.smooth = true} during a \l Transition: \code - PropertyAction { target: theimage; property: "smooth"; value: true } + transitions: Transition { + ... + PropertyAction { target: theImage; property: "smooth"; value: true } + ... + } \endcode - Set \c thewebview.url to the value set for the destination state: + Or, to set \c theWebView.url to the value set for the destination state: \code - PropertyAction { target: thewebview; property: "url" } + transitions: Transition { + ... + PropertyAction { target: theWebView; property: "url" } + ... + } \endcode - The PropertyAction is immediate - - the target property is not animated to the selected value in any way. \sa QtDeclarative */ @@ -906,14 +927,6 @@ void QDeclarativePropertyActionPrivate::init() QDeclarative_setParent_noEvent(spa, q); } -/*! - \qmlproperty Object PropertyAction::target - This property holds an explicit target object to animate. - - The exact effect of the \c target property depends on how the animation - is being used. Refer to the \l {QML Animation} documentation for details. -*/ - QObject *QDeclarativePropertyAction::target() const { Q_D(const QDeclarativePropertyAction); @@ -945,12 +958,12 @@ void QDeclarativePropertyAction::setProperty(const QString &n) } /*! + \qmlproperty Object PropertyAction::target \qmlproperty list PropertyAction::targets \qmlproperty string PropertyAction::property \qmlproperty string PropertyAction::properties - \qmlproperty Object PropertyAction::target - These properties are used as a set to determine which properties should be + These properties determine the items and their properties that are affected by this action. The details of how these properties are interpreted in different situations @@ -982,7 +995,7 @@ QDeclarativeListProperty QDeclarativePropertyAction::targets() /*! \qmlproperty list PropertyAction::exclude - This property holds the objects not to be affected by this animation. + This property holds the objects that should not be affected by this action. \sa targets */ @@ -1117,13 +1130,14 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions, \qmlclass NumberAnimation QDeclarativeNumberAnimation \since 4.7 \inherits PropertyAnimation - \brief The NumberAnimation element allows you to animate changes in properties of type qreal. + \brief The NumberAnimation element animates changes in qreal-type values. - NumberAnimation defines an animation to be applied when a numerical value - changes. + NumberAnimation is a specialized PropertyAnimation that defines an + animation to be applied when a numerical value changes. Here is a NumberAnimation applied to the \c x property of a \l Rectangle - as a property value source: + as a property value source. It animates the \c x value from its current + value to a value of 50, over 1000 milliseconds: \snippet doc/src/snippets/declarative/numberanimation.qml 0 @@ -1174,6 +1188,7 @@ void QDeclarativeNumberAnimation::init() For example, the following animation is not applied until the \c x value has reached 100: + \qml Item { states: [ ... ] @@ -1181,8 +1196,10 @@ void QDeclarativeNumberAnimation::init() NumberAnimation { properties: "x"; from: 100; duration: 200 } } } + \endqml - If this value is not set, it defaults to the value defined in the start + If this value is not set and the NumberAnimation is defined within + a \l Transition, it defaults to the value defined in the start state of the \l Transition. */ @@ -1201,7 +1218,8 @@ void QDeclarativeNumberAnimation::setFrom(qreal f) \qmlproperty real NumberAnimation::to This property holds the ending number value. - If this value is not set, it defaults to the value defined in the end + If this value is not set and the NumberAnimation is defined within + a \l Transition or \l Behavior, it defaults to the value defined in the end state of the \l Transition or \l Behavior. */ qreal QDeclarativeNumberAnimation::to() const @@ -1221,7 +1239,10 @@ void QDeclarativeNumberAnimation::setTo(qreal t) \qmlclass Vector3dAnimation QDeclarativeVector3dAnimation \since 4.7 \inherits PropertyAnimation - \brief The Vector3dAnimation element allows you to animate changes in properties of type QVector3d. + \brief The Vector3dAnimation element animates changes in QVector3d values. + + Vector3dAnimation is a specialized PropertyAnimation that defines an + animation to be applied when a Vector3d value changes. \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -1286,31 +1307,32 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t) \qmlclass RotationAnimation QDeclarativeRotationAnimation \since 4.7 \inherits PropertyAnimation - \brief The RotationAnimation element allows you to animate rotations. + \brief The RotationAnimation element animates changes in rotation values. RotationAnimation is a specialized PropertyAnimation that gives control - over the direction of rotation. By default, it will rotate in the direction + over the direction of rotation during an animation. + + By default, it rotates in the direction of the numerical change; a rotation from 0 to 240 will rotate 220 degrees clockwise, while a rotation from 240 to 0 will rotate 220 degrees - counterclockwise. + counterclockwise. The \l direction property can be set to specify the + direction in which the rotation should occur. + + In the following example we use RotationAnimation to animate the rotation + between states via the shortest path: - When used in a transition RotationAnimation will rotate all + \snippet doc/src/snippets/declarative/rotationanimation.qml 0 + + Notice the RotationAnimation did not need to set a \l {RotationAnimation::}{target} + value. As a convenience, when used in a transition, RotationAnimation will rotate all properties named "rotation" or "angle". You can override this by providing your own properties via \l {PropertyAnimation::properties}{properties} or \l {PropertyAnimation::property}{property}. - In the following example we use RotationAnimation to animate the rotation - between states via the shortest path. - \qml - states: { - State { name: "180"; PropertyChanges { target: myItem; rotation: 180 } } - State { name: "90"; PropertyChanges { target: myItem; rotation: 90 } } - State { name: "-90"; PropertyChanges { target: myItem; rotation: -90 } } - } - transition: Transition { - RotationAnimation { direction: RotationAnimation.Shortest } - } - \endqml + Like any other animation element, a RotationAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -1377,6 +1399,7 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation() For example, the following animation is not applied until the \c angle value has reached 100: + \qml Item { states: [ ... ] @@ -1384,6 +1407,7 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation() RotationAnimation { properties: "angle"; from: 100; duration: 2000 } } } + \endqml If this value is not set, it defaults to the value defined in the start state of the \l Transition. @@ -1419,7 +1443,7 @@ void QDeclarativeRotationAnimation::setTo(qreal t) /*! \qmlproperty enumeration RotationAnimation::direction - The direction in which to rotate. + This property holds the direction of the rotation. Possible values are: @@ -1512,19 +1536,26 @@ QDeclarativeListProperty QDeclarativeAnimationGro \qmlclass SequentialAnimation QDeclarativeSequentialAnimation \since 4.7 \inherits Animation - \brief The SequentialAnimation element allows you to run animations sequentially. + \brief The SequentialAnimation element allows animations to be run sequentially. - Animations controlled in SequentialAnimation will be run one after the other. + The SequentialAnimation and ParallelAnimation elements allow multiple + animations to be run together. Animations defined in a SequentialAnimation + are run one after the other, while animations defined in a ParallelAnimation + are run at the same time. - The following example chains two numeric animations together. The \c MyItem - object will animate from its current x position to 100, and then back to 0. + The following example runs two number animations in a sequence. The \l Rectangle + animates to a \c x position of 50, then to a \c y position of 50. - \code - SequentialAnimation { - NumberAnimation { target: MyItem; property: "x"; to: 100 } - NumberAnimation { target: MyItem; property: "x"; to: 0 } - } - \endcode + \snippet doc/src/snippets/declarative/sequentialanimation.qml 0 + + Animations defined within a \l Transition are automatically run in parallel, + so SequentialAnimation can be used to enclose the animations in a \l Transition + if this is the preferred behavior. + + Like any other animation element, a SequentialAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. \sa ParallelAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -1574,19 +1605,22 @@ void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actio \qmlclass ParallelAnimation QDeclarativeParallelAnimation \since 4.7 \inherits Animation - \brief The ParallelAnimation element allows you to run animations in parallel. + \brief The ParallelAnimation element allows animations to be run in parallel. - Animations contained in ParallelAnimation will be run at the same time. + The SequentialAnimation and ParallelAnimation elements allow multiple + animations to be run together. Animations defined in a SequentialAnimation + are run one after the other, while animations defined in a ParallelAnimation + are run at the same time. - The following animation demonstrates animating the \c MyItem item - to (100,100) by animating the x and y properties in parallel. + The following animation runs two number animations in parallel. The \l Rectangle + moves to (50,50) by animating its \c x and \c y properties at the same time. - \code - ParallelAnimation { - NumberAnimation { target: MyItem; property: "x"; to: 100 } - NumberAnimation { target: MyItem; property: "y"; to: 100 } - } - \endcode + \snippet doc/src/snippets/declarative/parallelanimation.qml 0 + + Like any other animation element, a ParallelAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. \sa SequentialAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -1685,7 +1719,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int \qmlclass PropertyAnimation QDeclarativePropertyAnimation \since 4.7 \inherits Animation - \brief The PropertyAnimation element allows you to animate property changes. + \brief The PropertyAnimation element animates changes in property values. PropertyAnimation provides a way to animate changes to a property's value. @@ -2353,43 +2387,30 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions \qmlclass ParentAnimation QDeclarativeParentAnimation \since 4.7 \inherits Animation - \brief The ParentAnimation element allows you to animate parent changes. + \brief The ParentAnimation element animates changes in parent values. - ParentAnimation is used in conjunction with NumberAnimation to smoothly - animate changing an item's parent. In the following example, - ParentAnimation wraps a NumberAnimation which animates from the - current position in the old parent to the new position in the new - parent. + ParentAnimation defines an animation to applied when a ParentChange + occurs. This allows parent changes to be smoothly animated. - \qml - ... - State { - //reparent myItem to newParent. myItem's final location - //should be 10,10 in newParent. - ParentChange { - target: myItem - parent: newParent - x: 10; y: 10 - } - } - ... - Transition { - //smoothly reparent myItem and move into new position - ParentAnimation { - target: theItem - NumberAnimation { properties: "x,y" } - } - } - \endqml + For example, the following ParentChange changes \c blueRect to become + a child of \c redRect when it is clicked. The inclusion of the + ParentAnimation, which defines a NumberAnimation to be applied during + the transition, ensures the item animates smoothly as it moves to + its new parent: + + \snippet doc/src/snippets/declarative/parentanimation.qml 0 - ParentAnimation can wrap any number of animations -- those animations will - be run in parallel (like those in a ParallelAnimation group). + A ParentAnimation can contain any number of animations. These animations will + be run in parallel; to run them sequentially, define them within a + SequentialAnimation. - In some cases, such as reparenting between items with clipping, it's useful - to animate the parent change via another item with no clipping. + In some cases, such as when reparenting between items with clipping enabled, it is useful + to animate the parent change via another item that does not have clipping + enabled. Such an item can be set using the \l via property. - When used in a transition, ParentAnimation will by default animate - all ParentChanges. + By default, when used in a transition, ParentAnimation animates all parent + changes. This can be overriden by setting a specific target item using the + \l target property. \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -2426,8 +2447,8 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation() \qmlproperty Item ParentAnimation::target The item to reparent. - When used in a transition, if no target is specified all - ParentChanges will be animated by the ParentAnimation. + When used in a transition, if no target is specified, all + ParentChange occurrences are animated by the ParentAnimation. */ QDeclarativeItem *QDeclarativeParentAnimation::target() const { @@ -2470,7 +2491,7 @@ void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent) /*! \qmlproperty Item ParentAnimation::via The item to reparent via. This provides a way to do an unclipped animation - when both the old parent and new parent are clipped + when both the old parent and new parent are clipped. \qml ParentAnimation { @@ -2720,28 +2741,14 @@ QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation() \qmlclass AnchorAnimation QDeclarativeAnchorAnimation \since 4.7 \inherits Animation - \brief The AnchorAnimation element allows you to animate anchor changes. + \brief The AnchorAnimation element animates changes in anchor values. - AnchorAnimation will animated any changes specified by a state's AnchorChanges. - In the following snippet we animate the addition of a right anchor to our item. - \qml - Item { - id: myItem - width: 100 - } - ... - State { - AnchorChanges { - target: myItem - anchors.right: container.right - } - } - ... - Transition { - //smoothly reanchor myItem and move into new position - AnchorAnimation {} - } - \endqml + AnchorAnimation is used to animate an AnchorChange. It will anchor all + anchor changes specified in a \l State. + + In the following snippet we animate the addition of a right anchor to a \l Rectangle: + + \snippet doc/src/snippets/declarative/anchoranimation.qml 0 \sa AnchorChanges */ diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 2bb28c3..3719085 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -75,28 +75,21 @@ public: \since 4.7 \brief The Behavior element allows you to specify a default animation for a property change. - Behaviors provide one way to specify \l{qdeclarativeanimation.html}{animations} in QML. - - In the example below, the rectangle will use a bounce easing curve over 200 millisecond for any changes to its y property: - \code - Rectangle { - width: 20; height: 20 - color: "#00ff00" - y: 200 // initial value - Behavior on y { - NumberAnimation { - easing.type: Easing.OutBounce - easing.amplitude: 100 - duration: 200 - } - } - } - \endcode + A Behavior defines the default animation to be applied whenever a + particular property value changes. + + For example, the following Behavior defines a NumberAnimation to be run + whenever the \l Rectangle's \c width value changes. When the MouseArea + is clicked, the \c width is changed, triggering the behavior's animation: + + \snippet doc/src/snippets/declarative/behavior.qml 0 - Currently only a single Behavior may be specified for a property; - this Behavior can be enabled and disabled via the \l{enabled} property. + To run multiple animations within a Behavior, use ParallelAnimation or + SequentialAnimation. - \sa {declarative/animation/behaviors}{Behavior example}, QtDeclarative + Note that a property cannot have more than one assigned Behavior. + + \sa {Property Behaviors}, {declarative/animation/behaviors}{Behavior example}, QtDeclarative */ @@ -113,7 +106,7 @@ QDeclarativeBehavior::~QDeclarativeBehavior() \qmlproperty Animation Behavior::animation \default - The animation to use when the behavior is triggered. + This property holds the animation to run when the behavior is triggered. */ QDeclarativeAbstractAnimation *QDeclarativeBehavior::animation() @@ -152,7 +145,9 @@ void QDeclarativeBehavior::qtAnimationStateChanged(QAbstractAnimation::State new /*! \qmlproperty bool Behavior::enabled - Whether the Behavior will be triggered when the property it is tracking changes. + + This property holds whether the behavior will be triggered when the tracked + property changes value. By default a Behavior is enabled. */ diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index e0d1097..11c3d4b 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -253,15 +253,22 @@ void QSmoothedAnimation::init() \inherits NumberAnimation \brief The SmoothedAnimation element allows a property to smoothly track a value. - The SmoothedAnimation animates a property's value to a set target value - using an ease in/out quad easing curve. If the animation is restarted - with a different target value, the easing curves used to animate to the old - and the new target values are smoothly spliced together to avoid any obvious - visual glitches by maintaining the current velocity. - - The property animation is configured by setting the velocity at which the - animation should occur, or the duration that the animation should take. - If both a velocity and a duration are specified, the one that results in + A SmoothedAnimation animates a property's value to a set target value + using an ease in/out quad easing curve. When the target value changes, + the easing curves used to animate between the old and new target values + are smoothly spliced together to create a smooth movement to the new + target value that maintains the current velocity. + + The follow example shows one \l Rectangle tracking the position of another + using SmoothedAnimation. The green rectangle's \c x and \c y values are + bound to those of the red rectangle. Whenever these values change, the + green rectangle smoothly animates to its new position: + + \snippet doc/src/snippets/declarative/smoothedanimation.qml 0 + + A SmoothedAnimation can be configured by setting the \l velocity at which the + animation should occur, or the \l duration that the animation should take. + If both the \l velocity and \l duration are specified, the one that results in the quickest animation is chosen for each change in the target value. For example, animating from 0 to 800 will take 4 seconds if a velocity @@ -271,10 +278,6 @@ void QSmoothedAnimation::init() will take 8 seconds with a duration of 8000 set, and will take 8 seconds with both a velocity of 200 and a duration of 8000 set. - The follow example shows one rectangle tracking the position of another. - - \snippet doc/src/snippets/declarative/smoothedanimation.qml 0 - The default velocity of SmoothedAnimation is 200 units/second. Note that if the range of the value being animated is small, then the velocity will need to be adjusted appropriately. For example, the opacity of an item ranges from 0 - 1.0. @@ -287,7 +290,7 @@ void QSmoothedAnimation::init() sources. The \l PropertyAnimation documentation shows a variety of methods for creating animations. - \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} + \sa SpringAnimation, NumberAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example} */ QDeclarativeSmoothedAnimation::QDeclarativeSmoothedAnimation(QObject *parent) diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp index be0af6d..8ce4832 100644 --- a/src/declarative/util/qdeclarativespringanimation.cpp +++ b/src/declarative/util/qdeclarativespringanimation.cpp @@ -215,7 +215,9 @@ void QDeclarativeSpringAnimationPrivate::updateMode() You can also limit the maximum \l velocity of the animation. The following \l Rectangle moves to the position of the mouse using a - SpringAnimation when the mouse is clicked: + SpringAnimation when the mouse is clicked. The use of the \l Behavior + on the \c x and \c y values indicates that whenever these values are + changed, a SpringAnimation should be applied. \snippet doc/src/snippets/declarative/springanimation.qml 0 @@ -224,7 +226,7 @@ void QDeclarativeSpringAnimationPrivate::updateMode() sources. The \l PropertyAnimation documentation shows a variety of methods for creating animations. - \sa {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example} + \sa SmoothedAnimation, {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example} */ QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent) @@ -284,8 +286,8 @@ qreal QDeclarativeSpringAnimation::from() const This property holds the value from which the animation will begin. - If not set, the animation will start regardless of the - value being tracked. + If not set, the animation will start whenever the tracked value has + changed, regardless of its value. */ void QDeclarativeSpringAnimation::setFrom(qreal value) @@ -303,7 +305,10 @@ void QDeclarativeSpringAnimation::setFrom(qreal value) /*! \qmlproperty real SpringAnimation::velocity + This property holds the maximum velocity allowed when tracking the source. + + The default value is 0 (no maximum velocity). */ qreal QDeclarativeSpringAnimation::velocity() const @@ -322,13 +327,14 @@ void QDeclarativeSpringAnimation::setVelocity(qreal velocity) /*! \qmlproperty real SpringAnimation::spring - This property holds the spring constant - The spring constant describes how strongly the target is pulled towards the - source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 + This property describes how strongly the target is pulled towards the + source. The default value is 0 (that is, the spring-like motion is disabled). + + The useful value range is 0 - 5.0. - When a spring constant is set and the velocity property is greater than 0, - velocity limits the maximum speed. + When this property is set and the \l velocity value is greater than 0, + the \l velocity limits the maximum speed. */ qreal QDeclarativeSpringAnimation::spring() const { @@ -347,10 +353,11 @@ void QDeclarativeSpringAnimation::setSpring(qreal spring) \qmlproperty real SpringAnimation::damping This property holds the spring damping value. - This value describes how quickly a sprung follower comes to rest. + This value describes how quickly the spring-like motion comes to rest. + The default value is 0. - The useful range is 0 - 1.0. The lower the value, the faster the - follower comes to rest. + The useful value range is 0 - 1.0. The lower the value, the faster it + comes to rest. */ qreal QDeclarativeSpringAnimation::damping() const { @@ -392,7 +399,7 @@ void QDeclarativeSpringAnimation::setEpsilon(qreal epsilon) /*! \qmlproperty real SpringAnimation::modulus - This property holds the modulus value. + This property holds the modulus value. The default value is 0. Setting a \a modulus forces the target value to "wrap around" at the modulus. For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10. @@ -417,8 +424,10 @@ void QDeclarativeSpringAnimation::setModulus(qreal modulus) \qmlproperty real SpringAnimation::mass This property holds the "mass" of the property being moved. - mass is 1.0 by default. Setting a different mass changes the dynamics of - a \l spring follow. + The value is 1.0 by default. + + A greater mass causes slower movement and a greater spring-like + motion when an item comes to rest. */ qreal QDeclarativeSpringAnimation::mass() const { diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index 6b7418e..6561b8c 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -66,8 +66,6 @@ QT_BEGIN_NAMESPACE \snippet doc/src/snippets/declarative/transition.qml 0 - Items can have multiple transitions, if - To specify multiple transitions, specify \l Item::transitions as a list: \qml -- cgit v0.12 From b2f90dedbeac285338af07fbffaec97ceaf0876f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 20 Jul 2010 12:20:21 +1000 Subject: Better defaults for MouseArea's drag. Allow essentially unbounded dragging once drag.target is set. The previous default of contraining the dragging to 0,0 (i.e. no drag) was unintuitive for learners. It's rare that unbounded is actually what you want, but it makes it much easier to get started with the element. Task-number: QTBUG-11184 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 5 +---- src/declarative/graphicsitems/qdeclarativemousearea.cpp | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 9d70beb..86ef0df 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -59,16 +59,13 @@ #include #include #include +#include #include #include #include QT_BEGIN_NAMESPACE -#ifndef FLT_MAX -#define FLT_MAX 1E+37 -#endif - /*! \qmlclass Transform QGraphicsTransform \since 4.7 diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index b7b0c9e..7e4a36f 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -45,12 +45,13 @@ #include "private/qdeclarativeevents_p_p.h" #include +#include QT_BEGIN_NAMESPACE static const int PressAndHoldDelay = 800; QDeclarativeDrag::QDeclarativeDrag(QObject *parent) -: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0), +: QObject(parent), _target(0), _axis(XandYAxis), _xmin(-FLT_MAX), _xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false) { } -- cgit v0.12 From 6c3cf7e2c5868bc77ffa66059889eda3132531b3 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 20 Jul 2010 12:26:13 +1000 Subject: Ensure the boundingRect() of Text is correctly calculated. We need to create our cached image in boundingRect() if it doesn't already exist, to prevents painting errors. Reviewed-by: Warwick Allison --- src/declarative/graphicsitems/qdeclarativetext.cpp | 2 ++ tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index d63d633..ec8bfb5 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -716,6 +716,8 @@ QRectF QDeclarativeText::boundingRect() const // Could include font max left/right bearings to either side of rectangle. if (d->cache || d->style != Normal) { + QDeclarativeTextPrivate *dd = const_cast(d); + dd->checkImgCache(); switch (d->hAlign) { case AlignLeft: x = 0; diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 80198eb..53862ec 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -246,6 +246,7 @@ void tst_qdeclarativetext::width() QDeclarativeText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); + QVERIFY(textObject->boundingRect().width() > 0); QCOMPARE(textObject->width(), qreal(metricWidth)); QVERIFY(textObject->textFormat() == QDeclarativeText::AutoText); // setting text doesn't change format } -- cgit v0.12 From 7fb140b63f03b96064ded4ec6f2ec7c93e87b825 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 20 Jul 2010 12:45:10 +1000 Subject: Make Item::transformOriginPoint read-only Using this property on Item will break transformOrigin property. We have never documented it. It should not have been used. Now it is enforced as best we can. Task-number: QTBUG-12265 Reviewed-by: Aaron Kennedy --- src/declarative/graphicsitems/qdeclarativeitem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 4f420f8..8878fa0 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -90,6 +90,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) Q_PROPERTY(QDeclarativeListProperty transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) + Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // transformOriginPoint is read-only for Item Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) Q_ENUMS(TransformOrigin) Q_CLASSINFO("DefaultProperty", "data") -- cgit v0.12 From 7725da34a828df00feb289515c11fa8aea1a55d8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 21 Jul 2010 08:46:43 +1000 Subject: Restore the FLT_MAX define. Seems some platforms don't have it. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 4 ++++ src/declarative/graphicsitems/qdeclarativemousearea.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 86ef0df..54aa3a9 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -64,6 +64,10 @@ #include #include +#ifndef FLT_MAX +#define FLT_MAX 1E+37 +#endif + QT_BEGIN_NAMESPACE /*! diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 7e4a36f..67de288 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -47,6 +47,10 @@ #include #include +#ifndef FLT_MAX +#define FLT_MAX 1E+37 +#endif + QT_BEGIN_NAMESPACE static const int PressAndHoldDelay = 800; -- cgit v0.12 From b325c90e5a0e5088aa8723d943f4c38b14048bd7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 21 Jul 2010 09:18:21 +1000 Subject: Compile: include for usage of FLT_MAX. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 5 +---- src/declarative/graphicsitems/qdeclarativemousearea.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 54aa3a9..1b0d7ef 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -59,14 +59,11 @@ #include #include #include -#include #include #include #include -#ifndef FLT_MAX -#define FLT_MAX 1E+37 -#endif +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 67de288..8ee6093 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -45,11 +45,8 @@ #include "private/qdeclarativeevents_p_p.h" #include -#include -#ifndef FLT_MAX -#define FLT_MAX 1E+37 -#endif +#include QT_BEGIN_NAMESPACE static const int PressAndHoldDelay = 800; -- cgit v0.12 From 164b2b54922d87a44a60efe6dbbe2fa3b7716820 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 20 Jul 2010 15:14:11 +1000 Subject: Rewinding AnchorChanges should not make target item's implicit width and height explicit Task-number: QTBUG-12273 Reviewed-by: Michael Brasser --- .../util/qdeclarativestateoperations.cpp | 8 +++-- .../qdeclarativestates/data/anchorRewindBug.qml | 37 ++++++++++++++++++++++ .../qdeclarativestates/tst_qdeclarativestates.cpp | 35 ++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 5590449..2291c16 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1501,8 +1501,12 @@ void QDeclarativeAnchorChanges::rewind() d->target->setX(d->rewindX); d->target->setY(d->rewindY); - d->target->setWidth(d->rewindWidth); - d->target->setHeight(d->rewindHeight); + if (targetPrivate->widthValid) { + d->target->setWidth(d->rewindWidth); + } + if (targetPrivate->heightValid) { + d->target->setHeight(d->rewindHeight); + } } void QDeclarativeAnchorChanges::saveCurrentValues() diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml b/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml new file mode 100644 index 0000000..e6b6020 --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml @@ -0,0 +1,37 @@ +import Qt 4.7 +Rectangle { + id: container + color: "red" + height: 200 + width: 200 + Column { + id: column + objectName: "column" + anchors.left: container.right + anchors.bottom: container.bottom + + Rectangle { + id: rectangle + color: "blue" + height: 100 + width: 200 + } + Rectangle { + color: "blue" + height: 100 + width: 200 + } + } + states: State { + name: "reanchored" + AnchorChanges { + target: column + anchors.left: undefined + anchors.right: container.right + } + PropertyChanges { + target: rectangle + opacity: 0 + } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 639b2f3..7bc4fd4 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -121,6 +121,7 @@ private slots: void anchorChanges4(); void anchorChanges5(); void anchorChangesCrash(); + void anchorRewindBug(); void script(); void restoreEntryValues(); void explicitChanges(); @@ -807,6 +808,40 @@ void tst_qdeclarativestates::anchorChangesCrash() delete rect; } +// QTBUG-12273 +void tst_qdeclarativestates::anchorRewindBug() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorRewindBug.qml"); + QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QDeclarativeItem * column = rect->findChild("column"); + + QVERIFY(column != 0); + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 200.0); + QDeclarativeItemPrivate::get(rect)->setState("reanchored"); + + // column height and width should stay implicit + // and column's implicit resizing should still work + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 100.0); + + QDeclarativeItemPrivate::get(rect)->setState(""); + + // column height and width should stay implicit + // and column's implicit resizing should still work + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 200.0); + + delete rect; +} + void tst_qdeclarativestates::script() { QDeclarativeEngine engine; -- cgit v0.12 From 78a01438e5a37fd1778924f73ca8bfa55960b0d0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 21 Jul 2010 10:36:17 +1000 Subject: font.letterSpacing used percentage rather than absolute values. ... and percentage is useless. Task-number: QTBUG-12282 Reviewed-by: Warwick Allison --- src/declarative/QmlChanges.txt | 5 ++++- src/declarative/graphicsitems/qdeclarativetext.cpp | 3 +-- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 3 +-- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 3 +-- src/declarative/qml/qdeclarativevaluetype.cpp | 2 +- tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp | 8 ++++---- .../declarative/qmlvisual/qdeclarativetext/font/plaintext.qml | 4 ++-- .../auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 872f6cb..6a2537b 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -1,9 +1,12 @@ ============================================================================= -The changes below are pre Qt 4.7.0 tech preview +The changes below are pre Qt 4.7.0 RC1 TextInput - copy(), cut() and paste() functions added +Font.letterSpacing + - was percentage based. Now specified in pixels. +============================================================================= The changes below are pre Qt 4.7.0 beta 2 QDeclarativeView diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index ec8bfb5..a1703c1 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -303,8 +303,7 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() Sets the letter spacing for the font. Letter spacing changes the default spacing between individual letters in the font. - A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by - the width of the character itself. + A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index d13e139..0cbada4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -213,8 +213,7 @@ QString QDeclarativeTextEdit::text() const Sets the letter spacing for the font. Letter spacing changes the default spacing between individual letters in the font. - A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by - the width of the character itself. + A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 2a5d73d..321b121 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -176,8 +176,7 @@ void QDeclarativeTextInput::setText(const QString &s) Sets the letter spacing for the font. Letter spacing changes the default spacing between individual letters in the font. - A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by - the width of the character itself. + A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. */ /*! diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index c17ec95..61e550a 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -973,7 +973,7 @@ qreal QDeclarativeFontValueType::letterSpacing() const void QDeclarativeFontValueType::setLetterSpacing(qreal size) { - font.setLetterSpacing(QFont::PercentageSpacing, size); + font.setLetterSpacing(QFont::AbsoluteSpacing, size); } qreal QDeclarativeFontValueType::wordSpacing() const diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 53862ec..821394d 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -848,22 +848,22 @@ void tst_qdeclarativetext::letterSpacing() QCOMPARE(textObject->font().letterSpacing(), 0.0); } { - QString componentStr = "import Qt 4.7\nText { text: \"Hello world!\"; font.letterSpacing: -50 }"; + QString componentStr = "import Qt 4.7\nText { text: \"Hello world!\"; font.letterSpacing: -2 }"; QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarativeText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); - QCOMPARE(textObject->font().letterSpacing(), -50.); + QCOMPARE(textObject->font().letterSpacing(), -2.); } { - QString componentStr = "import Qt 4.7\nText { text: \"Hello world!\"; font.letterSpacing: 200 }"; + QString componentStr = "import Qt 4.7\nText { text: \"Hello world!\"; font.letterSpacing: 3 }"; QDeclarativeComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarativeText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); - QCOMPARE(textObject->font().letterSpacing(), 200.); + QCOMPARE(textObject->font().letterSpacing(), 3.); } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml index 73dd4d7..e268a60 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml @@ -34,10 +34,10 @@ Rectangle { text: s.text; font.underline: true; font.overline: true; font.strikeout: true } Text { - text: s.text; font.letterSpacing: 200 + text: s.text; font.letterSpacing: 2 } Text { - text: s.text; font.underline: true; font.letterSpacing: 200; font.capitalization: "AllUppercase"; color: "blue" + text: s.text; font.underline: true; font.letterSpacing: 2; font.capitalization: "AllUppercase"; color: "blue" } Text { text: s.text; font.overline: true; font.wordSpacing: 25; font.capitalization: "Capitalize"; color: "green" diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml index b41b93a..a883b9c 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml @@ -34,10 +34,10 @@ Rectangle { text: s.text; font.underline: true; font.overline: true; font.strikeout: true } Text { - text: s.text; font.letterSpacing: 200 + text: s.text; font.letterSpacing: 2 } Text { - text: s.text; font.underline: true; font.letterSpacing: 200; font.capitalization: "AllUppercase"; color: "blue" + text: s.text; font.underline: true; font.letterSpacing: 2; font.capitalization: "AllUppercase"; color: "blue" } Text { text: s.text; font.overline: true; font.wordSpacing: 25; font.capitalization: "Capitalize"; color: "green" -- cgit v0.12 From 6d8b3453b6b4b151c777ad541ab25ca6bacc7381 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 21 Jul 2010 10:04:11 +1000 Subject: Fix clock example: make sure hands always moves forward. Task-number: QTBUG-12292 --- examples/declarative/toys/clocks/content/Clock.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/declarative/toys/clocks/content/Clock.qml b/examples/declarative/toys/clocks/content/Clock.qml index 24a07ec..eaa14c6 100644 --- a/examples/declarative/toys/clocks/content/Clock.qml +++ b/examples/declarative/toys/clocks/content/Clock.qml @@ -77,7 +77,7 @@ Item { origin.x: 7.5; origin.y: 73; angle: (clock.hours * 30) + (clock.minutes * 0.5) Behavior on angle { - NumberAnimation{} + RotationAnimation{ direction: RotationAnimation.Clockwise } } } } @@ -91,7 +91,7 @@ Item { origin.x: 6.5; origin.y: 83; angle: clock.minutes * 6 Behavior on angle { - NumberAnimation{} + RotationAnimation{ direction: RotationAnimation.Clockwise } } } } @@ -105,7 +105,7 @@ Item { origin.x: 2.5; origin.y: 80; angle: clock.seconds * 6 Behavior on angle { - NumberAnimation{} + RotationAnimation{ direction: RotationAnimation.Clockwise } } } } -- cgit v0.12 From 64833c0a648211f3fe7547436f022edc0ceb51ac Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 21 Jul 2010 10:52:08 +1000 Subject: Only ignore the same target value for a Behavior when it is running. Otherwise a Behavior may mistakenly not be triggered. This situation can arise when the property in question has been manipulated via the property system, followed by a direct function call (which correctly bypasses the Behavior), followed by a another change via the property system. Task-number: QTBUG-12295 --- src/declarative/util/qdeclarativebehavior.cpp | 2 +- .../qdeclarativebehaviors/data/qtbug12295.qml | 17 ++++++++++++++ .../tst_qdeclarativebehaviors.cpp | 27 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/qtbug12295.qml diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 3719085..fadb2ae 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -177,7 +177,7 @@ void QDeclarativeBehavior::write(const QVariant &value) return; } - if (value == d->targetValue) + if (d->animation->isRunning() && value == d->targetValue) return; d->currentValue = d->property.read(); diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/qtbug12295.qml b/tests/auto/declarative/qdeclarativebehaviors/data/qtbug12295.qml new file mode 100644 index 0000000..804559c --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/qtbug12295.qml @@ -0,0 +1,17 @@ +import Qt 4.7 + +Rectangle { + width: 200 + height: 200 + color: "blue" + + Rectangle { + id: myRect + objectName: "myRect" + width: 100 + height: 100 + Behavior on x { + NumberAnimation {} + } + } +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index 5c2c145..bb7fc7b 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -80,6 +80,7 @@ private slots: void startup(); void groupedPropertyCrash(); void runningTrue(); + void sameValue(); }; void tst_qdeclarativebehaviors::simpleBehavior() @@ -384,6 +385,32 @@ void tst_qdeclarativebehaviors::runningTrue() QTRY_VERIFY(runningSpy.count() > 0); } +//QTBUG-12295 +void tst_qdeclarativebehaviors::sameValue() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/qtbug12295.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *target = rect->findChild("myRect"); + QVERIFY(target); + + target->setX(100); + QCOMPARE(target->x(), qreal(100)); + + target->setProperty("x", 0); + QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); + + target->setX(100); + QCOMPARE(target->x(), qreal(100)); + + //this is the main point of the test -- the behavior needs to be triggered again + //even though we set 0 twice in a row. + target->setProperty("x", 0); + QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); +} + QTEST_MAIN(tst_qdeclarativebehaviors) #include "tst_qdeclarativebehaviors.moc" -- cgit v0.12 From c2c28428123cfd3a3994117bfea88a0ae68f6884 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 21 Jul 2010 11:30:20 +1000 Subject: Ensure redirects (and indeed all reply process) is done in the right thread. i.e. the thread with the QNAM the original reply was created in. Task-number: QTBUG-12302 Reviewed-by: Aaron Kennedy --- src/declarative/util/qdeclarativepixmapcache.cpp | 55 +++++++++++++--------- .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 2 + 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 00dd922..31813a6 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -114,6 +114,18 @@ public: static int downloadProgressIndex; }; +class QDeclarativePixmapReaderThreadObject : public QObject { + Q_OBJECT +public: + QDeclarativePixmapReaderThreadObject(QDeclarativePixmapReader *); + void processJobs(); + virtual bool event(QEvent *e); +private slots: + void networkRequestDone(); +private: + QDeclarativePixmapReader *reader; +}; + class QDeclarativePixmapData; class QDeclarativePixmapReader : public QThread { @@ -130,12 +142,11 @@ public: protected: void run(); -private slots: - void networkRequestDone(); - private: + friend class QDeclarativePixmapReaderThreadObject; void processJobs(); void processJob(QDeclarativePixmapReply *); + void networkRequestDone(QNetworkReply *); QList jobs; QList cancelled; @@ -143,14 +154,7 @@ private: QObject *eventLoopQuitHack; QMutex mutex; - class ThreadObject : public QObject { - public: - ThreadObject(QDeclarativePixmapReader *); - void processJobs(); - virtual bool event(QEvent *e); - private: - QDeclarativePixmapReader *reader; - } *threadObject; + QDeclarativePixmapReaderThreadObject *threadObject; QWaitCondition waitCondition; QNetworkAccessManager *networkAccessManager(); @@ -161,7 +165,7 @@ private: static int replyDownloadProgress; static int replyFinished; static int downloadProgress; - static int thisNetworkRequestDone; + static int threadNetworkRequestDone; static QHash readers; static QMutex readerMutex; }; @@ -232,7 +236,7 @@ QMutex QDeclarativePixmapReader::readerMutex; int QDeclarativePixmapReader::replyDownloadProgress = -1; int QDeclarativePixmapReader::replyFinished = -1; int QDeclarativePixmapReader::downloadProgress = -1; -int QDeclarativePixmapReader::thisNetworkRequestDone = -1; +int QDeclarativePixmapReader::threadNetworkRequestDone = -1; void QDeclarativePixmapReply::postReply(ReadError error, const QString &errorString, @@ -317,9 +321,8 @@ QDeclarativePixmapReader::~QDeclarativePixmapReader() wait(); } -void QDeclarativePixmapReader::networkRequestDone() +void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply) { - QNetworkReply *reply = static_cast(sender()); QDeclarativePixmapReply *job = replies.take(reply); if (job) { @@ -335,7 +338,7 @@ void QDeclarativePixmapReader::networkRequestDone() reply = networkAccessManager()->get(req); QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress); - QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone); + QMetaObject::connect(reply, replyFinished, threadObject, threadNetworkRequestDone); replies.insert(reply, job); return; @@ -368,17 +371,17 @@ void QDeclarativePixmapReader::networkRequestDone() threadObject->processJobs(); } -QDeclarativePixmapReader::ThreadObject::ThreadObject(QDeclarativePixmapReader *i) +QDeclarativePixmapReaderThreadObject::QDeclarativePixmapReaderThreadObject(QDeclarativePixmapReader *i) : reader(i) { } -void QDeclarativePixmapReader::ThreadObject::processJobs() +void QDeclarativePixmapReaderThreadObject::processJobs() { QCoreApplication::postEvent(this, new QEvent(QEvent::User)); } -bool QDeclarativePixmapReader::ThreadObject::event(QEvent *e) +bool QDeclarativePixmapReaderThreadObject::event(QEvent *e) { if (e->type() == QEvent::User) { reader->processJobs(); @@ -388,6 +391,12 @@ bool QDeclarativePixmapReader::ThreadObject::event(QEvent *e) } } +void QDeclarativePixmapReaderThreadObject::networkRequestDone() +{ + QNetworkReply *reply = static_cast(sender()); + reader->networkRequestDone(reply); +} + void QDeclarativePixmapReader::processJobs() { QMutexLocker locker(&mutex); @@ -469,7 +478,7 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob) QNetworkReply *reply = networkAccessManager()->get(req); QMetaObject::connect(reply, replyDownloadProgress, runningJob, downloadProgress); - QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone); + QMetaObject::connect(reply, replyFinished, threadObject, threadNetworkRequestDone); replies.insert(reply, runningJob); } @@ -520,15 +529,15 @@ void QDeclarativePixmapReader::run() if (replyDownloadProgress == -1) { const QMetaObject *nr = &QNetworkReply::staticMetaObject; const QMetaObject *pr = &QDeclarativePixmapReply::staticMetaObject; - const QMetaObject *ir = &QDeclarativePixmapReader::staticMetaObject; + const QMetaObject *ir = &QDeclarativePixmapReaderThreadObject::staticMetaObject; replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)"); replyFinished = nr->indexOfSignal("finished()"); downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)"); - thisNetworkRequestDone = ir->indexOfSlot("networkRequestDone()"); + threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()"); } mutex.lock(); - threadObject = new ThreadObject(this); + threadObject = new QDeclarativePixmapReaderThreadObject(this); mutex.unlock(); processJobs(); diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 38fd458..b8d2828 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -136,6 +136,7 @@ void tst_qdeclarativeimage::imageSource_data() QTest::newRow("local async not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() << 0.0 << 0.0 << false << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString(); QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << ""; + QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << ""; QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << ""; QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true << false << "file::2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; @@ -155,6 +156,7 @@ void tst_qdeclarativeimage::imageSource() if (remote) { QVERIFY(server.isValid()); server.serveDirectory(SRCDIR "/data"); + server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png"); } if (!error.isEmpty()) -- cgit v0.12 From 4f6e480acce94d8ae920c3eda4879fc4f9cb2598 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 21 Jul 2010 11:36:03 +1000 Subject: Do not show copyright header in documentation. --- doc/src/declarative/qdeclarativeintro.qdoc | 2 +- doc/src/snippets/declarative/comments.qml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/src/declarative/qdeclarativeintro.qdoc b/doc/src/declarative/qdeclarativeintro.qdoc index 3f1b184..75055d8 100644 --- a/doc/src/declarative/qdeclarativeintro.qdoc +++ b/doc/src/declarative/qdeclarativeintro.qdoc @@ -129,7 +129,7 @@ Commenting in QML is similar to JavaScript. \o Multiline comments start with /* and finish with *\/ \endlist -\quotefile doc/src/snippets/declarative/comments.qml +\snippet doc/src/snippets/declarative/comments.qml 0 Comments are ignored by the engine. They are useful for explaining what you are doing; for referring back to at a later date, or for others reading diff --git a/doc/src/snippets/declarative/comments.qml b/doc/src/snippets/declarative/comments.qml index f4bedb8..bafa26d 100644 --- a/doc/src/snippets/declarative/comments.qml +++ b/doc/src/snippets/declarative/comments.qml @@ -40,6 +40,7 @@ import Qt 4.7 +//![0] Text { text: "Hello world!" //a basic greeting /* @@ -49,3 +50,4 @@ Text { font.family: "Helvetica" font.pointSize: 24 } +//![0] -- cgit v0.12 From 21806ff0921641b4e4d9d39721ab4ebeae74dddc Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 21 Jul 2010 12:23:15 +1000 Subject: QML focus API updates. The wantsFocus property has been renamed to activeFocus, to better reflect its value. Reading and writing the focus property is also now consistent -- this property represents focus within a scope. Other small changes were made to keep things consistent with the new naming. Reviewed-by: Aaron Kennedy --- .../photoviewer/PhotoViewerCore/EditableButton.qml | 2 +- demos/declarative/twitter/TwitterCore/Button.qml | 2 +- demos/declarative/webbrowser/content/UrlInput.qml | 2 +- doc/src/declarative/focus.qdoc | 8 +- .../keyinteraction/focus/Core/GridMenu.qml | 6 +- .../keyinteraction/focus/Core/ListViewDelegate.qml | 4 +- .../keyinteraction/focus/Core/ListViews.qml | 8 +- .../declarative/keyinteraction/focus/focus.qml | 4 +- .../declarative/toys/dynamicscene/dynamicscene.qml | 1 - src/declarative/QmlChanges.txt | 7 ++ src/declarative/graphicsitems/qdeclarativeitem.cpp | 95 ++++++++++++--- src/declarative/graphicsitems/qdeclarativeitem.h | 8 +- src/declarative/graphicsitems/qdeclarativeitem_p.h | 9 +- .../graphicsitems/qdeclarativetextedit.cpp | 42 +++---- .../graphicsitems/qdeclarativetextedit_p.h | 4 +- .../graphicsitems/qdeclarativetextinput.cpp | 44 +++---- .../graphicsitems/qdeclarativetextinput_p.h | 4 +- src/gui/graphicsview/qgraphicsitem.cpp | 12 ++ src/gui/graphicsview/qgraphicsitem_p.h | 1 + .../qdeclarativefocusscope/data/chain.qml | 10 +- .../qdeclarativefocusscope/data/forcefocus.qml | 22 ++-- .../qdeclarativefocusscope/data/test.qml | 14 +-- .../qdeclarativefocusscope/data/test2.qml | 10 +- .../qdeclarativefocusscope/data/test3.qml | 2 +- .../qdeclarativefocusscope/data/test4.qml | 14 +-- .../qdeclarativefocusscope/data/test5.qml | 10 +- .../tst_qdeclarativefocusscope.cpp | 131 ++++++++++----------- .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 28 ++--- .../qdeclarativestates/data/propertyErrors.qml | 2 +- .../qdeclarativestates/tst_qdeclarativestates.cpp | 2 +- .../tst_qdeclarativetextedit.cpp | 28 ++--- .../tst_qdeclarativetextinput.cpp | 40 +++---- 32 files changed, 330 insertions(+), 246 deletions(-) diff --git a/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml b/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml index be7dfa4..decc0fe 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml @@ -81,6 +81,6 @@ Item { MouseArea { anchors { fill: parent; leftMargin: -20; topMargin: -20; rightMargin: -20; bottomMargin: -20 } - onClicked: { textInput.forceFocus(); textInput.openSoftwareInputPanel(); } + onClicked: { textInput.forceActiveFocus(); textInput.openSoftwareInputPanel(); } } } diff --git a/demos/declarative/twitter/TwitterCore/Button.qml b/demos/declarative/twitter/TwitterCore/Button.qml index 9c90c2c..d326c64 100644 --- a/demos/declarative/twitter/TwitterCore/Button.qml +++ b/demos/declarative/twitter/TwitterCore/Button.qml @@ -80,7 +80,7 @@ Item { }, State { name: "Focused" - when: container.focus == true + when: container.activeFocus == true PropertyChanges { target: btnText; color: "#FFFFFF" } } ] diff --git a/demos/declarative/webbrowser/content/UrlInput.qml b/demos/declarative/webbrowser/content/UrlInput.qml index 9992456..4f49821 100644 --- a/demos/declarative/webbrowser/content/UrlInput.qml +++ b/demos/declarative/webbrowser/content/UrlInput.qml @@ -69,7 +69,7 @@ Item { TextInput { id: urlText horizontalAlignment: TextEdit.AlignLeft - font.pixelSize: 14; focusOnPress: true + font.pixelSize: 14; onTextChanged: container.urlChanged() diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index 0dd5eb3..e3ca963 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -73,12 +73,12 @@ See also the \l {Keys}{Keys attached property} and \l {KeyNavigation}{KeyNavigat \section1 Querying the Active Focus Item Whether or not an \l Item has \e {active focus} can be queried through the -property \c {Item::focus}. For example, here we have a \l Text +property \c {Item::activeFocus}. For example, here we have a \l Text element whose text is determined by whether or not it has \e {active focus}. \code Text { - text: focus ? "I have active focus!" : "I do not have active focus" + text: activeFocus ? "I have active focus!" : "I do not have active focus" } \endcode @@ -174,7 +174,7 @@ Rectangle { The right hand side of the example shows the expanded code - the equivalent QML without the use of the component \c {MyWidget}. From this, the problem is evident - there are no less than three elements that have the \c {Item::focus} -property set to true. Ultimately only one element can have focus, and the +property set to true. Ultimately only one element can have keyboard focus, and the system has to decide which on. In this case the first appearance of the \c {Item::focus} property being set to true on line 4 is selected, and the value of \c {Item::focus} in the other two instances is reverted back to false. This @@ -233,7 +233,7 @@ and the others are unset, just like when there are no \e {focus scopes}. \o When a \e {focus scope} receives \e {active focus}, the contained element with \c {Item::focus} set (if any) also gets \e {active focus}. If this element is also a \l FocusScope, the proxying behaviour continues. Both the -\e {focus scope} and the sub-focused item will have \c {Item::focus} set. +\e {focus scope} and the sub-focused item will have \c {Item::activeFocus} set. \endlist So far the example has the second component statically selected. It is trivial diff --git a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml index 9a8d3f3..19f7235 100644 --- a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml +++ b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml @@ -43,7 +43,7 @@ import Qt 4.7 FocusScope { property alias interactive: gridView.interactive - onWantsFocusChanged: if (wantsFocus) mainView.state = "" + onActiveFocusChanged: if (activeFocus) mainView.state = "" Rectangle { anchors.fill: parent @@ -84,12 +84,12 @@ FocusScope { onClicked: { GridView.view.currentIndex = index - container.forceFocus() + container.forceActiveFocus() } } states: State { - name: "active"; when: container.focus == true + name: "active"; when: container.activeFocus PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } } diff --git a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml index cc13637..602b52b 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml @@ -69,12 +69,12 @@ Item { onClicked: { ListView.view.currentIndex = index - container.forceFocus() + container.forceActiveFocus() } } states: State { - name: "active"; when: container.focus == true + name: "active"; when: container.activeFocus PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } PropertyChanges { target: label; font.pixelSize: 16 } } diff --git a/examples/declarative/keyinteraction/focus/Core/ListViews.qml b/examples/declarative/keyinteraction/focus/Core/ListViews.qml index 6f9ceb4..3d6ceab 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViews.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViews.qml @@ -43,11 +43,11 @@ import Qt 4.7 FocusScope { clip: true - onWantsFocusChanged: if (wantsFocus) mainView.state = "showListViews" + onActiveFocusChanged: if (activeFocus) mainView.state = "showListViews" ListView { id: list1 - y: wantsFocus ? 10 : 40; width: parent.width / 3; height: parent.height - 20 + y: activeFocus ? 10 : 40; width: parent.width / 3; height: parent.height - 20 focus: true KeyNavigation.up: gridMenu; KeyNavigation.left: contextMenu; KeyNavigation.right: list2 model: 10; cacheBuffer: 200 @@ -60,7 +60,7 @@ FocusScope { ListView { id: list2 - y: wantsFocus ? 10 : 40; x: parseInt(parent.width / 3); width: parent.width / 3; height: parent.height - 20 + y: activeFocus ? 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: parseInt(2 * parent.width / 3); width: parent.width / 3; height: parent.height - 20 + y: activeFocus ? 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 8b2af70..56fdffc 100644 --- a/examples/declarative/keyinteraction/focus/focus.qml +++ b/examples/declarative/keyinteraction/focus/focus.qml @@ -58,7 +58,7 @@ Rectangle { width: parent.width; height: 320 focus: true - interactive: parent.wantsFocus + interactive: parent.activeFocus } ListViews { @@ -98,7 +98,7 @@ Rectangle { states: State { name: "contextMenuOpen" - when: !mainView.wantsFocus + when: !mainView.activeFocus PropertyChanges { target: contextMenu; x: 0; open: true } PropertyChanges { target: mainView; x: 130 } PropertyChanges { target: shade; opacity: 0.25 } diff --git a/examples/declarative/toys/dynamicscene/dynamicscene.qml b/examples/declarative/toys/dynamicscene/dynamicscene.qml index 1edb841..2a22a5f 100644 --- a/examples/declarative/toys/dynamicscene/dynamicscene.qml +++ b/examples/declarative/toys/dynamicscene/dynamicscene.qml @@ -184,7 +184,6 @@ Item { id: qmlText anchors.fill: parent; anchors.margins: 5 readOnly: false - focusOnPress: true font.pixelSize: 14 wrapMode: TextEdit.WordWrap diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 6a2537b..6e07330 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -5,6 +5,13 @@ TextInput - copy(), cut() and paste() functions added Font.letterSpacing - was percentage based. Now specified in pixels. +Item + - wantsFocus renamed to activeFocus + - forceFocus() renamed to forceActiveFocus() + - focus now returns the scoped focus (i.e. focus read/write now manipulate + the same value) +TextInput and TextEdit: + - focusOnPress renamed to activeFocusOnPress ============================================================================= The changes below are pre Qt 4.7.0 beta 2 diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 1b0d7ef..301779a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1430,7 +1430,7 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec */ /*! - \fn void QDeclarativeItem::wantsFocusChanged(bool) + \fn void QDeclarativeItem::activeFocusChanged(bool) \internal */ @@ -2370,12 +2370,12 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea } /*! - \qmlmethod Item::forceFocus() + \qmlmethod Item::forceActiveFocus() - Force the focus on the item. - This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus. + Force active focus on the item. + This method sets focus on the item and makes sure that all the focus scopes higher in the object hierarchy are also given focus. */ -void QDeclarativeItem::forceFocus() +void QDeclarativeItem::forceActiveFocus() { setFocus(true); QGraphicsItem *parent = parentItem(); @@ -2412,8 +2412,19 @@ void QDeclarativeItemPrivate::focusChanged(bool flag) { Q_Q(QDeclarativeItem); if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent) - emit q->wantsFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange() - emit q->focusChanged(flag); + emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange() + + bool inScope = false; + QGraphicsItem *p = parent; + while (p) { + if (p->flags() & QGraphicsItem::ItemIsFocusScope) { + inScope = true; + break; + } + p = p->parentItem(); + } + if (!inScope) + emit q->focusChanged(flag); } /*! \internal */ @@ -2690,7 +2701,7 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) { - d->focusChanged(hasFocus()); + d->focusChanged(hasActiveFocus()); } return rv; } @@ -3104,15 +3115,32 @@ void QDeclarativeItem::setSize(const QSizeF &size) } /*! - \qmlproperty bool Item::wantsFocus + \qmlproperty bool Item::activeFocus + + This property indicates whether the item has active focus. + + An item with active focus will receive keyboard input, + or is a FocusScope ancestor of the item that will receive keyboard input. - This property indicates whether the item has has an active focus request. + Usually, activeFocus is gained by setting focus on an item and its enclosing + FocusScopes. In the following example \c input will have activeFocus. + \qml + Rectangle { + FocusScope { + focus: true + TextInput { + id: input + focus: true + } + } + } + \endqml - \sa {qmlfocus}{Keyboard Focus} + \sa focus, {qmlfocus}{Keyboard Focus} */ /*! \internal */ -bool QDeclarativeItem::wantsFocus() const +bool QDeclarativeItem::hasActiveFocus() const { Q_D(const QDeclarativeItem); return focusItem() == this || @@ -3122,16 +3150,51 @@ bool QDeclarativeItem::wantsFocus() const /*! \qmlproperty bool Item::focus - This property indicates whether the item has keyboard input focus. Set this - property to true to request focus. + This property indicates whether the item has focus within the enclosing focus scope. If true, this item + will gain active focus when the enclosing focus scope gains active focus. + In the following example, \c input will be given active focus when \c scope gains active focus. + \qml + Rectangle { + FocusScope { + id: scope + TextInput { + id: input + focus: true + } + } + } + \endqml - \sa {qmlfocus}{Keyboard Focus} + For the purposes of this property, the top level item in the scene + is assumed to act like a focus scope, and to always have active focus + when the scene has focus. On a practical level, that means the following + QML will give active focus to \c input on startup. + + \qml + Rectangle { + TextInput { + id: input + focus: true + } + } + \endqml + + \sa activeFocus, {qmlfocus}{Keyboard Focus} */ /*! \internal */ bool QDeclarativeItem::hasFocus() const { - return QGraphicsItem::hasFocus(); + Q_D(const QDeclarativeItem); + QGraphicsItem *p = d->parent; + while (p) { + if (p->flags() & QGraphicsItem::ItemIsFocusScope) { + return p->focusScopeItem() == this; + } + p = p->parentItem(); + } + + return hasActiveFocus() ? true : (!QGraphicsItem::parentItem() ? true : false); } /*! \internal */ diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 8878fa0..cd9b910 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -87,7 +87,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) - Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) + Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged) Q_PROPERTY(QDeclarativeListProperty transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // transformOriginPoint is read-only for Item @@ -139,7 +139,7 @@ public: QRectF boundingRect() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - bool wantsFocus() const; + bool hasActiveFocus() const; bool hasFocus() const; void setFocus(bool); @@ -148,7 +148,7 @@ public: Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; - Q_INVOKABLE void forceFocus(); + Q_INVOKABLE void forceActiveFocus(); Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const; Q_SIGNALS: @@ -157,7 +157,7 @@ Q_SIGNALS: void baselineOffsetChanged(qreal); void stateChanged(const QString &); void focusChanged(bool); - void wantsFocusChanged(bool); + void activeFocusChanged(bool); void parentChanged(QDeclarativeItem *); void transformOriginChanged(TransformOrigin); void smoothChanged(bool); diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index bc5d809..8c3e084 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -285,11 +285,18 @@ public: virtual void subFocusItemChange() { if (flags & QGraphicsItem::ItemIsFocusScope || !parent) - emit q_func()->wantsFocusChanged(subFocusItem != 0); + emit q_func()->activeFocusChanged(subFocusItem != 0); //see also QDeclarativeItemPrivate::focusChanged } // Reimplemented from QGraphicsItemPrivate + virtual void focusScopeItemChange(bool isSubFocusItem) + { + emit q_func()->focusChanged(isSubFocusItem); + } + + + // Reimplemented from QGraphicsItemPrivate virtual void siblingOrderChange() { Q_Q(QDeclarativeItem); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 0cbada4..f7b2ebf 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -624,7 +624,7 @@ void QDeclarativeTextEdit::moveCursorSelection(int pos) \qmlproperty bool TextEdit::cursorVisible If true the text edit shows a cursor. - This property is set and unset when the text edit gets focus, but it can also + This property is set and unset when the text edit gets active focus, but it can also be set directly (useful, for example, if a KeyProxy might forward keys to it). */ bool QDeclarativeTextEdit::isCursorVisible() const @@ -783,9 +783,9 @@ QString QDeclarativeTextEdit::selectedText() const } /*! - \qmlproperty bool TextEdit::focusOnPress + \qmlproperty bool TextEdit::activeFocusOnPress - Whether the TextEdit should gain focus on a mouse press. By default this is + Whether the TextEdit should gain active focus on a mouse press. By default this is set to true. */ bool QDeclarativeTextEdit::focusOnPress() const @@ -800,13 +800,13 @@ void QDeclarativeTextEdit::setFocusOnPress(bool on) if (d->focusOnPress == on) return; d->focusOnPress = on; - emit focusOnPressChanged(d->focusOnPress); + emit activeFocusOnPressChanged(d->focusOnPress); } /*! \qmlproperty bool TextEdit::persistentSelection - Whether the TextEdit should keep the selection visible when it loses focus to another + Whether the TextEdit should keep the selection visible when it loses active focus to another item in the scene. By default this is set to true; */ bool QDeclarativeTextEdit::persistentSelection() const @@ -1106,15 +1106,15 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); if (d->focusOnPress){ - bool hadFocus = hasFocus(); - forceFocus(); + bool hadActiveFocus = hasActiveFocus(); + forceActiveFocus(); if (d->showInputPanelOnFocus) { - if (hasFocus() && hadFocus && !isReadOnly()) { + if (hasActiveFocus() && hadActiveFocus && !isReadOnly()) { // re-open input panel on press if already focused openSoftwareInputPanel(); } } else { // show input panel on click - if (hasFocus() && !hadFocus) { + if (hasActiveFocus() && !hadActiveFocus) { d->clickCausedFocus = true; } } @@ -1427,10 +1427,10 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption() By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clicking TextEdit. On other platforms - the panels are automatically opened when TextEdit element gains focus. Input panels are - always closed if no editor owns focus. + the panels are automatically opened when TextEdit element gains active focus. Input panels are + always closed if no editor has active focus. - You can disable the automatic behavior by setting the property \c focusOnPress to false + You can disable the automatic behavior by setting the property \c activeFocusOnPress to false and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement the behavior you want. @@ -1441,12 +1441,12 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption() TextEdit { id: textEdit text: "Hello world!" - focusOnPress: false + activeFocusOnPress: false MouseArea { anchors.fill: parent onClicked: { - if (!textEdit.focus) { - textEdit.focus = true; + if (!textEdit.activeFocus) { + textEdit.forceActiveFocus(); textEdit.openSoftwareInputPanel(); } else { textEdit.focus = false; @@ -1478,10 +1478,10 @@ void QDeclarativeTextEdit::openSoftwareInputPanel() By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clicking TextEdit. On other platforms - the panels are automatically opened when TextEdit element gains focus. Input panels are - always closed if no editor owns focus. + the panels are automatically opened when TextEdit element gains active focus. Input panels are + always closed if no editor has active focus. - You can disable the automatic behavior by setting the property \c focusOnPress to false + You can disable the automatic behavior by setting the property \c activeFocusOnPress to false and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement the behavior you want. @@ -1492,12 +1492,12 @@ void QDeclarativeTextEdit::openSoftwareInputPanel() TextEdit { id: textEdit text: "Hello world!" - focusOnPress: false + activeFocusOnPress: false MouseArea { anchors.fill: parent onClicked: { - if (!textEdit.focus) { - textEdit.focus = true; + if (!textEdit.activeFocus) { + textEdit.forceActiveFocus(); textEdit.openSoftwareInputPanel(); } else { textEdit.focus = false; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 279af78..68fde3d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -85,7 +85,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged) Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged) Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) + Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged) Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged) Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) @@ -216,7 +216,7 @@ Q_SIGNALS: void readOnlyChanged(bool isReadOnly); void cursorVisibleChanged(bool isCursorVisible); void cursorDelegateChanged(); - void focusOnPressChanged(bool focusIsPressed); + void activeFocusOnPressChanged(bool activeFocusOnPressed); void persistentSelectionChanged(bool isPersistentSelection); void textMarginChanged(qreal textMargin); void selectByMouseChanged(bool selectByMouse); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 321b121..34f5897 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -375,14 +375,14 @@ void QDeclarativeTextInput::setMaxLength(int ml) \qmlproperty bool TextInput::cursorVisible Set to true when the TextInput shows a cursor. - This property is set and unset when the TextInput gets focus, so that other + This property is set and unset when the TextInput gets active focus, so that other properties can be bound to whether the cursor is currently showing. As it gets set and unset automatically, when you set the value yourself you must keep in mind that your value may be overwritten. It can be set directly in script, for example if a KeyProxy might forward keys to it and you desire it to look active when this happens - (but without actually giving it the focus). + (but without actually giving it active focus). It should not be set directly on the element, like in the below QML, as the specified value will be overridden an lost on focus changes. @@ -395,7 +395,7 @@ void QDeclarativeTextInput::setMaxLength(int ml) \endcode In the above snippet the cursor will still become visible when the - TextInput gains focus. + TextInput gains active focus. */ bool QDeclarativeTextInput::isCursorVisible() const { @@ -510,9 +510,9 @@ QString QDeclarativeTextInput::selectedText() const } /*! - \qmlproperty bool TextInput::focusOnPress + \qmlproperty bool TextInput::activeFocusOnPress - Whether the TextInput should gain focus on a mouse press. By default this is + Whether the TextInput should gain active focus on a mouse press. By default this is set to true. */ bool QDeclarativeTextInput::focusOnPress() const @@ -529,7 +529,7 @@ void QDeclarativeTextInput::setFocusOnPress(bool b) d->focusOnPress = b; - emit focusOnPressChanged(d->focusOnPress); + emit activeFocusOnPressChanged(d->focusOnPress); } /*! @@ -945,15 +945,15 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); if(d->focusOnPress){ - bool hadFocus = hasFocus(); - forceFocus(); + bool hadActiveFocus = hasActiveFocus(); + forceActiveFocus(); if (d->showInputPanelOnFocus) { - if (hasFocus() && hadFocus && !isReadOnly()) { + if (hasActiveFocus() && hadActiveFocus && !isReadOnly()) { // re-open input panel on press if already focused openSoftwareInputPanel(); } } else { // show input panel on click - if (hasFocus() && !hadFocus) { + if (hasActiveFocus() && !hadActiveFocus) { d->clickCausedFocus = true; } } @@ -1312,10 +1312,10 @@ void QDeclarativeTextInput::moveCursorSelection(int position) By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clicking TextInput. On other platforms - the panels are automatically opened when TextInput element gains focus. Input panels are - always closed if no editor owns focus. + the panels are automatically opened when TextInput element gains active focus. Input panels are + always closed if no editor has active focus. - . You can disable the automatic behavior by setting the property \c focusOnPress to false + . You can disable the automatic behavior by setting the property \c activeFocusOnPress to false and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement the behavior you want. @@ -1326,12 +1326,12 @@ void QDeclarativeTextInput::moveCursorSelection(int position) TextInput { id: textInput text: "Hello world!" - focusOnPress: false + activeFocusOnPress: false MouseArea { anchors.fill: parent onClicked: { - if (!textInput.focus) { - textInput.focus = true; + if (!textInput.activeFocus) { + textInput.forceActiveFocus() textInput.openSoftwareInputPanel(); } else { textInput.focus = false; @@ -1363,10 +1363,10 @@ void QDeclarativeTextInput::openSoftwareInputPanel() By default the opening of input panels follows the platform style. On Symbian^1 and Symbian^3 -based devices the panels are opened by clicking TextInput. On other platforms - the panels are automatically opened when TextInput element gains focus. Input panels are - always closed if no editor owns focus. + the panels are automatically opened when TextInput element gains active focus. Input panels are + always closed if no editor has active focus. - . You can disable the automatic behavior by setting the property \c focusOnPress to false + . You can disable the automatic behavior by setting the property \c activeFocusOnPress to false and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement the behavior you want. @@ -1377,12 +1377,12 @@ void QDeclarativeTextInput::openSoftwareInputPanel() TextInput { id: textInput text: "Hello world!" - focusOnPress: false + activeFocusOnPress: false MouseArea { anchors.fill: parent onClicked: { - if (!textInput.focus) { - textInput.focus = true; + if (!textInput.activeFocus) { + textInput.forceActiveFocus(); textInput.openSoftwareInputPanel(); } else { textInput.focus = false; diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index b1862c6..ba3f5b1 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -87,7 +87,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativePaintedItem Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) + Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged) Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged) Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged) Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged) @@ -211,7 +211,7 @@ Q_SIGNALS: void echoModeChanged(EchoMode echoMode); void passwordCharacterChanged(); void displayTextChanged(); - void focusOnPressChanged(bool focusOnPress); + void activeFocusOnPressChanged(bool activeFocusOnPress); void autoScrollChanged(bool autoScroll); void selectByMouseChanged(bool selectByMouse); diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 6249822..56182d1 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1150,6 +1150,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) { parentFocusScopeItem = fsi; p->d_ptr->focusScopeItem = 0; + fsi->d_ptr->focusScopeItemChange(false); } break; } @@ -1182,6 +1183,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q while (p) { if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) { p->d_ptr->focusScopeItem = newFocusScopeItem; + newFocusScopeItem->d_ptr->focusScopeItemChange(true); // Ensure the new item is no longer the subFocusItem. The // only way to set focus on a child of a focus scope is // by setting focus on the scope itself. @@ -5587,6 +5589,16 @@ void QGraphicsItemPrivate::subFocusItemChange() /*! \internal + Subclasses can reimplement this function to be notified when an item + becomes a focusScopeItem (or is no longer a focusScopeItem). +*/ +void QGraphicsItemPrivate::focusScopeItemChange(bool isSubFocusItem) +{ +} + +/*! + \internal + Subclasses can reimplement this function to be notified when its siblingIndex order is changed. */ diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 5b9a710..d60dffb 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -482,6 +482,7 @@ public: void clearSubFocus(QGraphicsItem *rootItem = 0); void resetFocusProxy(); virtual void subFocusItemChange(); + virtual void focusScopeItemChange(bool isSubFocusItem); static void children_append(QDeclarativeListProperty *list, QGraphicsObject *item); static int children_count(QDeclarativeListProperty *list); diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml b/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml index 6c39f20..42b50cf 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml @@ -4,11 +4,11 @@ Rectangle { id: root width:300; height:400 - property bool focus1: root.wantsFocus - property bool focus2: item1.wantsFocus - property bool focus3: fs1.wantsFocus - property bool focus4: fs2.wantsFocus - property bool focus5: theItem.wantsFocus + property bool focus1: root.activeFocus + property bool focus2: item1.activeFocus + property bool focus3: fs1.activeFocus + property bool focus4: fs2.activeFocus + property bool focus5: theItem.activeFocus Item { id: item1 diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml index af9c420..9144854 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml @@ -15,28 +15,28 @@ Rectangle { height: 120; width: 420 color: "transparent" - border.width: 5; border.color: firstScope.wantsFocus?"blue":"black" + border.width: 5; border.color: firstScope.activeFocus?"blue":"black" Rectangle { id: item1; objectName: "item1" x: 10; y: 10; width: 100; height: 100; color: "green" - border.width: 5; border.color: wantsFocus?"blue":"black" + border.width: 5; border.color: activeFocus?"blue":"black" focus: true Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } Rectangle { id: item2; objectName: "item2" x: 310; y: 10; width: 100; height: 100; color: "green" - border.width: 5; border.color: wantsFocus?"blue":"black" + border.width: 5; border.color: activeFocus?"blue":"black" Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } } @@ -50,32 +50,32 @@ Rectangle { y: 160; height: 120; width: 420 color: "transparent" - border.width: 5; border.color: secondScope.wantsFocus?"blue":"black" + border.width: 5; border.color: secondScope.activeFocus?"blue":"black" Rectangle { id: item4; objectName: "item4" x: 10; y: 10; width: 100; height: 100; color: "green" - border.width: 5; border.color: wantsFocus?"blue":"black" + border.width: 5; border.color: activeFocus?"blue":"black" Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } Rectangle { id: item5; objectName: "item5" x: 310; y: 10; width: 100; height: 100; color: "green" - border.width: 5; border.color: wantsFocus?"blue":"black" + border.width: 5; border.color: activeFocus?"blue":"black" Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } } } } Keys.onDigit4Pressed: item4.focus = true - Keys.onDigit5Pressed: item5.forceFocus() + Keys.onDigit5Pressed: item5.forceActiveFocus() } diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml index aa43ba8..55be103 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml @@ -20,21 +20,21 @@ Rectangle { color: "transparent" border.width: 5 - border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.activeFocus?"blue":"black" Rectangle { id: item1; objectName: "item1" x: 10; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.debug("Top Left"); KeyNavigation.right: item2 focus: true Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } @@ -43,13 +43,13 @@ Rectangle { x: 310; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" KeyNavigation.left: item1 Keys.onDigit9Pressed: console.log("Top Right"); Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } } @@ -63,14 +63,14 @@ Rectangle { x: 10; y: 300 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.log("Bottom Left"); KeyNavigation.up: myScope Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml index 216277e..5ed701d 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml @@ -10,27 +10,27 @@ Rectangle { FocusScope { y: 100 focus: true; objectName: "item1" - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true; objectName: "item2" - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true; objectName: "item3" - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true; objectName: "item4" - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true; objectName: "item5" - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } } } } diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml index 2ac0d18..c6d112f 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml @@ -13,7 +13,7 @@ Rectangle { ListElement { name: "4" } ListElement { name: "5" } ListElement { name: "6" } - ListElement { name: "6" } + ListElement { name: "7" } ListElement { name: "8" } ListElement { name: "9" } } diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml index 8862b39..3c6d3bd 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml @@ -19,21 +19,21 @@ Rectangle { color: "transparent" border.width: 5 - border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.activeFocus?"blue":"black" Rectangle { id: item1; objectName: "item1" x: 10; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.log("Error - Top Left"); KeyNavigation.right: item2 focus: true Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } @@ -42,13 +42,13 @@ Rectangle { x: 310; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" KeyNavigation.left: item1 Keys.onDigit9Pressed: console.log("Error - Top Right"); Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } } @@ -62,14 +62,14 @@ Rectangle { x: 10; y: 300 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.log("Error - Bottom Left"); KeyNavigation.up: myScope Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml index cdb5164..4417d5f 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml @@ -20,13 +20,13 @@ Rectangle { color: "transparent" border.width: 5 - border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.activeFocus?"blue":"black" Rectangle { x: 10; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: item1.wantsFocus?"blue":"black" + border.color: item1.activeFocus?"blue":"black" } TextEdit { @@ -47,13 +47,13 @@ Rectangle { x: 310; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" KeyNavigation.left: item1 Keys.onReturnPressed: console.log("Top Right"); Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.focus?"red":"transparent" + color: parent.activeFocus?"red":"transparent" } } } @@ -66,7 +66,7 @@ Rectangle { x: 10; y: 300 width: 100; height: 100; color: "green" border.width: 5 - border.color: item3.wantsFocus?"blue":"black" + border.color: item3.activeFocus?"blue":"black" } TextEdit { diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index 2559087..b0c9c03 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -118,22 +118,22 @@ void tst_qdeclarativefocusscope::basic() QVERIFY(view->hasFocus()); QVERIFY(view->scene()->hasFocus()); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == true); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == true); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == true); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == true); delete view; } @@ -166,16 +166,11 @@ void tst_qdeclarativefocusscope::nested() QVERIFY(view->hasFocus()); QVERIFY(view->scene()->hasFocus()); - QVERIFY(item1->wantsFocus() == true); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->wantsFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->wantsFocus() == true); - QVERIFY(item3->hasFocus() == false); - QVERIFY(item4->wantsFocus() == true); - QVERIFY(item4->hasFocus() == false); - QVERIFY(item5->wantsFocus() == true); - QVERIFY(item5->hasFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == true); + QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(item4->hasActiveFocus() == true); + QVERIFY(item5->hasActiveFocus() == true); delete view; } @@ -204,22 +199,22 @@ void tst_qdeclarativefocusscope::noFocus() QVERIFY(view->hasFocus()); QVERIFY(view->scene()->hasFocus()); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); delete view; } @@ -249,32 +244,32 @@ void tst_qdeclarativefocusscope::textEdit() QVERIFY(view->hasFocus()); QVERIFY(view->scene()->hasFocus()); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == true); - QVERIFY(item3->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == true); + QVERIFY(item3->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->hasFocus() == true); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == true); delete view; } @@ -308,28 +303,28 @@ void tst_qdeclarativefocusscope::forceFocus() QVERIFY(view->hasFocus()); QVERIFY(view->scene()->hasFocus()); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->wantsFocus() == false); - QVERIFY(item4->hasFocus() == false); - QVERIFY(item5->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item4->hasActiveFocus() == false); + QVERIFY(item5->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_4); - QVERIFY(item0->wantsFocus() == true); - QVERIFY(item1->hasFocus() == true); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->wantsFocus() == false); - QVERIFY(item4->hasFocus() == false); - QVERIFY(item5->hasFocus() == false); + QVERIFY(item0->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus() == true); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item4->hasActiveFocus() == false); + QVERIFY(item5->hasActiveFocus() == false); QTest::keyClick(view, Qt::Key_5); - QVERIFY(item0->wantsFocus() == false); - QVERIFY(item1->hasFocus() == false); - QVERIFY(item2->hasFocus() == false); - QVERIFY(item3->wantsFocus() == true); - QVERIFY(item4->hasFocus() == false); - QVERIFY(item5->hasFocus() == true); + QVERIFY(item0->hasActiveFocus() == false); + QVERIFY(item1->hasActiveFocus() == false); + QVERIFY(item2->hasActiveFocus() == false); + QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(item4->hasActiveFocus() == false); + QVERIFY(item5->hasActiveFocus() == true); delete view; } diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index ffb2105..345ce38 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -371,7 +371,7 @@ void tst_QDeclarativeItem::keyNavigation() QDeclarativeItem *item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // right QKeyEvent key(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier, "", false, 1); @@ -380,7 +380,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item2"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // down key = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); @@ -389,7 +389,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item4"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // left key = QKeyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier, "", false, 1); @@ -398,7 +398,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item3"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // up key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1); @@ -407,7 +407,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // tab key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); @@ -416,7 +416,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item2"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // backtab key = QKeyEvent(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier, "", false, 1); @@ -425,7 +425,7 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); delete canvas; } @@ -618,21 +618,21 @@ void tst_QDeclarativeItem::mouseFocus() QDeclarativeItem *item = findItem(canvas->rootObject(), "declarativeItem"); QVERIFY(item); - QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool))); + QSignalSpy focusSpy(item, SIGNAL(activeFocusChanged(bool))); QTest::mouseClick(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(item->scenePos())); QApplication::processEvents(); QCOMPARE(focusSpy.count(), 1); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); // make sure focusable graphics widget underneath does not steal focus QTest::mouseClick(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(item->scenePos())); QApplication::processEvents(); QCOMPARE(focusSpy.count(), 1); - QVERIFY(item->hasFocus()); + QVERIFY(item->hasActiveFocus()); item->setFocus(false); - QVERIFY(!item->hasFocus()); + QVERIFY(!item->hasActiveFocus()); QCOMPARE(focusSpy.count(), 2); item->setFocus(true); QCOMPARE(focusSpy.count(), 3); @@ -664,7 +664,7 @@ void tst_QDeclarativeItem::propertyChanges() QSignalSpy baselineOffsetSpy(item, SIGNAL(baselineOffsetChanged(qreal))); QSignalSpy childrenRectSpy(parentItem, SIGNAL(childrenRectChanged(QRectF))); QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool))); - QSignalSpy wantsFocusSpy(parentItem, SIGNAL(wantsFocusChanged(bool))); + QSignalSpy wantsFocusSpy(parentItem, SIGNAL(activeFocusChanged(bool))); item->setParentItem(parentItem); item->setWidth(100.0); @@ -696,14 +696,14 @@ void tst_QDeclarativeItem::propertyChanges() QVERIFY(childrenRectArguments.count() == 1); QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); - QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); QCOMPARE(focusSpy.count(),1); QList focusArguments = focusSpy.first(); QVERIFY(focusArguments.count() == 1); QCOMPARE(focusArguments.at(0).toBool(), true); + QCOMPARE(parentItem->hasActiveFocus(), false); QCOMPARE(parentItem->hasFocus(), false); - QCOMPARE(parentItem->wantsFocus(), false); QCOMPARE(wantsFocusSpy.count(),0); delete canvas; diff --git a/tests/auto/declarative/qdeclarativestates/data/propertyErrors.qml b/tests/auto/declarative/qdeclarativestates/data/propertyErrors.qml index 807eec9..8f9a7f2 100644 --- a/tests/auto/declarative/qdeclarativestates/data/propertyErrors.qml +++ b/tests/auto/declarative/qdeclarativestates/data/propertyErrors.qml @@ -5,6 +5,6 @@ Rectangle { color: "red" states: State { name: "blue" - PropertyChanges { target: myRectangle; colr: "blue"; wantsFocus: true } + PropertyChanges { target: myRectangle; colr: "blue"; activeFocus: true } } } diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 7bc4fd4..3b6a420 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -922,7 +922,7 @@ void tst_qdeclarativestates::propertyErrors() QCOMPARE(rect->color(),QColor("red")); QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); - QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to read-only property \"wantsFocus\""); + QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to read-only property \"activeFocus\""); QDeclarativeItemPrivate::get(rect)->setState("blue"); } diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 4783bc7..93351a8 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -604,7 +604,7 @@ void tst_qdeclarativetextedit::persistentSelection() void tst_qdeclarativetextedit::focusOnPress() { { - QString componentStr = "import Qt 4.7\nTextEdit { focusOnPress: true; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.7\nTextEdit { activeFocusOnPress: true; text: \"Hello World\" }"; QDeclarativeComponent texteditComponent(&engine); texteditComponent.setData(componentStr.toLatin1(), QUrl()); QDeclarativeTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -613,7 +613,7 @@ void tst_qdeclarativetextedit::focusOnPress() } { - QString componentStr = "import Qt 4.7\nTextEdit { focusOnPress: false; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.7\nTextEdit { activeFocusOnPress: false; text: \"Hello World\" }"; QDeclarativeComponent texteditComponent(&engine); texteditComponent.setData(componentStr.toLatin1(), QUrl()); QDeclarativeTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -840,15 +840,15 @@ void tst_qdeclarativetextedit::navigation() QDeclarativeItem *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasFocus() == true); + QTRY_VERIFY(input->hasActiveFocus() == true); simulateKey(canvas, Qt::Key_Left); - QVERIFY(input->hasFocus() == false); + QVERIFY(input->hasActiveFocus() == false); simulateKey(canvas, Qt::Key_Right); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); simulateKey(canvas, Qt::Key_Right); - QVERIFY(input->hasFocus() == false); + QVERIFY(input->hasActiveFocus() == false); simulateKey(canvas, Qt::Key_Left); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); } void tst_qdeclarativetextedit::copyAndPaste() { @@ -908,7 +908,7 @@ void tst_qdeclarativetextedit::readOnly() QDeclarativeTextEdit *edit = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(edit != 0); - QTRY_VERIFY(edit->hasFocus() == true); + QTRY_VERIFY(edit->hasActiveFocus() == true); QVERIFY(edit->isReadOnly() == true); QString initial = edit->text(); for(int k=Qt::Key_0; k<=Qt::Key_Z; k++) @@ -968,7 +968,7 @@ void tst_qdeclarativetextedit::openInputPanelOnClick() MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextEdit edit; - QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool))); + QSignalSpy focusOnPressSpy(&edit, SIGNAL(activeFocusOnPressChanged(bool))); edit.setText("Hello world"); edit.setPos(0, 0); scene.addItem(&edit); @@ -1016,7 +1016,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus() MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextEdit edit; - QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool))); + QSignalSpy focusOnPressSpy(&edit, SIGNAL(activeFocusOnPressChanged(bool))); edit.setText("Hello world"); edit.setPos(0, 0); scene.addItem(&edit); @@ -1038,7 +1038,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); - QVERIFY(edit.hasFocus()); + QVERIFY(edit.hasActiveFocus()); QCOMPARE(ic.openInputPanelReceived, true); ic.openInputPanelReceived = false; @@ -1048,7 +1048,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus() ic.openInputPanelReceived = false; // if already focused, input panel can be opened on press - QVERIFY(edit.hasFocus()); + QVERIFY(edit.hasActiveFocus()); QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); QCOMPARE(ic.openInputPanelReceived, true); @@ -1076,7 +1076,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus() QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled)); // no automatic input panel events should - // be sent if focusOnPress is false + // be sent if activeFocusOnPress is false edit.setFocusOnPress(false); QCOMPARE(focusOnPressSpy.count(),1); edit.setFocusOnPress(false); @@ -1103,7 +1103,7 @@ void tst_qdeclarativetextedit::openInputPanelOnFocus() QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; - // set focusOnPress back to true + // set activeFocusOnPress back to true edit.setFocusOnPress(true); QCOMPARE(focusOnPressSpy.count(),2); edit.setFocusOnPress(true); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index a48bc39..e5e495e 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -494,7 +494,7 @@ void tst_qdeclarativetextinput::maxLength() } textinputObject->setText(""); - QTRY_VERIFY(textinputObject->hasFocus() == true); + QTRY_VERIFY(textinputObject->hasActiveFocus() == true); for(int i=0; i<20; i++){ QCOMPARE(textinputObject->text().length(), qMin(i,10)); //simulateKey(canvas, Qt::Key_A); @@ -515,7 +515,7 @@ void tst_qdeclarativetextinput::masks() QVERIFY(canvas->rootObject() != 0); QDeclarativeTextInput *textinputObject = qobject_cast(canvas->rootObject()); QVERIFY(textinputObject != 0); - QTRY_VERIFY(textinputObject->hasFocus() == true); + QTRY_VERIFY(textinputObject->hasActiveFocus() == true); QVERIFY(textinputObject->text().length() == 0); QCOMPARE(textinputObject->inputMask(), QString("HHHHhhhh; ")); for(int i=0; i<10; i++){ @@ -544,7 +544,7 @@ void tst_qdeclarativetextinput::validators() QDeclarativeTextInput *intInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("intInput"))); QVERIFY(intInput); intInput->setFocus(true); - QTRY_VERIFY(intInput->hasFocus()); + QTRY_VERIFY(intInput->hasActiveFocus()); QTest::keyPress(canvas, Qt::Key_1); QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); QCOMPARE(intInput->text(), QLatin1String("1")); @@ -565,7 +565,7 @@ void tst_qdeclarativetextinput::validators() QDeclarativeTextInput *dblInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("dblInput"))); QTRY_VERIFY(dblInput); dblInput->setFocus(true); - QVERIFY(dblInput->hasFocus() == true); + QVERIFY(dblInput->hasActiveFocus() == true); QTest::keyPress(canvas, Qt::Key_1); QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); QCOMPARE(dblInput->text(), QLatin1String("1")); @@ -594,7 +594,7 @@ void tst_qdeclarativetextinput::validators() QDeclarativeTextInput *strInput = qobject_cast(qvariant_cast(canvas->rootObject()->property("strInput"))); QTRY_VERIFY(strInput); strInput->setFocus(true); - QVERIFY(strInput->hasFocus() == true); + QVERIFY(strInput->hasActiveFocus() == true); QTest::keyPress(canvas, Qt::Key_1); QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); QCOMPARE(strInput->text(), QLatin1String("")); @@ -642,7 +642,7 @@ void tst_qdeclarativetextinput::inputMethods() QVERIFY(canvas->rootObject() != 0); input->setFocus(true); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); // test that input method event is committed QInputMethodEvent event; event.setCommitString( "My ", -12, 0); @@ -669,11 +669,11 @@ void tst_qdeclarativetextinput::navigation() QVERIFY(input != 0); input->setCursorPosition(0); - QTRY_VERIFY(input->hasFocus() == true); + QTRY_VERIFY(input->hasActiveFocus() == true); simulateKey(canvas, Qt::Key_Left); - QVERIFY(input->hasFocus() == false); + QVERIFY(input->hasActiveFocus() == false); simulateKey(canvas, Qt::Key_Right); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); //QT-2944: If text is selected, ensure we deselect upon cursor motion input->setCursorPosition(input->text().length()); input->select(0,input->text().length()); @@ -681,11 +681,11 @@ void tst_qdeclarativetextinput::navigation() simulateKey(canvas, Qt::Key_Right); QVERIFY(input->selectionStart() == input->selectionEnd()); QVERIFY(input->selectionStart() == input->text().length()); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); simulateKey(canvas, Qt::Key_Right); - QVERIFY(input->hasFocus() == false); + QVERIFY(input->hasActiveFocus() == false); simulateKey(canvas, Qt::Key_Left); - QVERIFY(input->hasFocus() == true); + QVERIFY(input->hasActiveFocus() == true); // Up and Down should NOT do Home/End, even on Mac OS X (QTBUG-10438). input->setCursorPosition(2); @@ -784,7 +784,7 @@ void tst_qdeclarativetextinput::readOnly() QDeclarativeTextInput *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasFocus() == true); + QTRY_VERIFY(input->hasActiveFocus() == true); QVERIFY(input->isReadOnly() == true); QString initial = input->text(); for(int k=Qt::Key_0; k<=Qt::Key_Z; k++) @@ -808,7 +808,7 @@ void tst_qdeclarativetextinput::echoMode() QDeclarativeTextInput *input = qobject_cast(qvariant_cast(canvas->rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasFocus() == true); + QTRY_VERIFY(input->hasActiveFocus() == true); QString initial = input->text(); Qt::InputMethodHints ref; QCOMPARE(initial, QLatin1String("ABCDefgh")); @@ -901,7 +901,7 @@ void tst_qdeclarativetextinput::openInputPanelOnClick() MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextInput input; - QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool))); + QSignalSpy focusOnPressSpy(&input, SIGNAL(activeFocusOnPressChanged(bool))); input.setText("Hello world"); input.setPos(0, 0); scene.addItem(&input); @@ -948,7 +948,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus() MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextInput input; - QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool))); + QSignalSpy focusOnPressSpy(&input, SIGNAL(activeFocusOnPressChanged(bool))); input.setText("Hello world"); input.setPos(0, 0); scene.addItem(&input); @@ -970,7 +970,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); - QVERIFY(input.hasFocus()); + QVERIFY(input.hasActiveFocus()); QCOMPARE(ic.openInputPanelReceived, true); ic.openInputPanelReceived = false; @@ -980,7 +980,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus() ic.openInputPanelReceived = false; // if already focused, input panel can be opened on press - QVERIFY(input.hasFocus()); + QVERIFY(input.hasActiveFocus()); QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); QCOMPARE(ic.openInputPanelReceived, true); @@ -1008,7 +1008,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus() QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled)); // no automatic input panel events should - // be sent if focusOnPress is false + // be sent if activeFocusOnPress is false input.setFocusOnPress(false); QCOMPARE(focusOnPressSpy.count(),1); input.setFocusOnPress(false); @@ -1035,7 +1035,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus() QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; - // set focusOnPress back to true + // set activeFocusOnPress back to true input.setFocusOnPress(true); QCOMPARE(focusOnPressSpy.count(),2); input.setFocusOnPress(true); -- cgit v0.12 From ed89fd5ff5aab99ee0fd47f7fdcb4824f1c92102 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 21 Jul 2010 12:51:55 +1000 Subject: Add QML tutorials to the tutorials page --- doc/src/getting-started/tutorials.qdoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/src/getting-started/tutorials.qdoc b/doc/src/getting-started/tutorials.qdoc index 0a83170..46a5808 100644 --- a/doc/src/getting-started/tutorials.qdoc +++ b/doc/src/getting-started/tutorials.qdoc @@ -84,6 +84,18 @@ \o \row + \o{2,1} \l{QML Tutorial}{\bold QML Tutorial} + \o{2,1} \l{QML Advanced Tutorial}{\bold SameGame} + \row + \o{2,1} + This tutorial provides a very basic introduction to QML. + \o \image qml-samegame-demo-small.png Samegame + \o + This tutorial walks through creating a complete application with QML, + in this case a simple game. It is recommended that you complete the basic QML + tutorial first. + + \row \o{2,1} \l{QTestLib Tutorial}{\bold QTestLib} \o{2,1} \l{qmake Tutorial}{\bold qmake} \row -- cgit v0.12 From 3aeafb4839f49f524f10eae65be27fd189d37060 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 21 Jul 2010 14:16:34 +1000 Subject: Bounding rect of text was not always calculated correctly. The boundingRect depended upon the image cache which may not become valid until after boundingRect is called. Task-number: QTBUG-12291 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativetext.cpp | 80 ++++++++-------------- .../declarative/qdeclarativetext/data/rotated.qml | 18 +++++ .../qdeclarativetext/tst_qdeclarativetext.cpp | 19 +++++ 3 files changed, 64 insertions(+), 53 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetext/data/rotated.qml diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index a1703c1..ab2be9c 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -712,63 +712,37 @@ QRectF QDeclarativeText::boundingRect() const int x = 0; int y = 0; - // Could include font max left/right bearings to either side of rectangle. - - if (d->cache || d->style != Normal) { - QDeclarativeTextPrivate *dd = const_cast(d); - dd->checkImgCache(); - 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; - } + QSize size = d->cachedLayoutSize; + if (d->style != Normal) + size += QSize(2,2); - 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; - } + // Could include font max left/right bearings to either side of rectangle. - 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; - } + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - size.width(); + break; + case AlignHCenter: + x = (w - size.width()) / 2; + break; + } - return QRectF(x,y,d->cachedLayoutSize.width(),d->cachedLayoutSize.height()); + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - size.height(); + break; + case AlignVCenter: + y = (h - size.height()) / 2; + break; } + + return QRectF(x,y,size.width(),size.height()); } void QDeclarativeText::geometryChanged(const QRectF &newGeometry, diff --git a/tests/auto/declarative/qdeclarativetext/data/rotated.qml b/tests/auto/declarative/qdeclarativetext/data/rotated.qml new file mode 100644 index 0000000..01eec44 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/rotated.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + width : 200 + height : 100 + + Text { + objectName: "text" + x: 20 + y: 20 + height : 20 + width : 80 + text : "Something" + rotation : 30 + transformOrigin : Item.TopLeft + } +} + diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 821394d..658f381 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -97,6 +97,8 @@ private slots: void clickLink(); + void QTBUG_12291(); + private: QStringList standard; QStringList richText; @@ -898,6 +900,23 @@ void tst_qdeclarativetext::wordSpacing() } } +void tst_qdeclarativetext::QTBUG_12291() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/rotated.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + + QDeclarativeText *text = ob->findChild("text"); + QVERIFY(text); + QVERIFY(text->boundingRect().isValid()); +} + class EventSender : public QGraphicsItem { public: -- cgit v0.12 From bd7d4947940593e7f56eccfae57db90d3b4acc4d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 21 Jul 2010 14:36:51 +1000 Subject: Rename remaining 'wantsFocus'. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 +- tests/auto/declarative/qmlvisual/focusscope/test.qml | 8 ++++---- tests/auto/declarative/qmlvisual/focusscope/test2.qml | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 301779a..c5c1a47 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2872,7 +2872,7 @@ void QDeclarativeItem::setSmooth(bool smooth) */ /*! - \property QDeclarativeItem::wantsFocus + \property QDeclarativeItem::activeFocus \internal */ diff --git a/tests/auto/declarative/qmlvisual/focusscope/test.qml b/tests/auto/declarative/qmlvisual/focusscope/test.qml index d83bad4..24b4b99 100644 --- a/tests/auto/declarative/qmlvisual/focusscope/test.qml +++ b/tests/auto/declarative/qmlvisual/focusscope/test.qml @@ -19,14 +19,14 @@ Rectangle { color: "transparent" border.width: 5 - border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.activeFocus?"blue":"black" Rectangle { id: item1 x: 10; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.log("Top Left"); KeyNavigation.right: item2 focus: true @@ -42,7 +42,7 @@ Rectangle { x: 310; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" KeyNavigation.left: item1 Keys.onDigit9Pressed: console.log("Top Right"); @@ -62,7 +62,7 @@ Rectangle { x: 10; y: 300 width: 100; height: 100; color: "green" border.width: 5 - border.color: wantsFocus?"blue":"black" + border.color: activeFocus?"blue":"black" Keys.onDigit9Pressed: console.log("Bottom Left"); KeyNavigation.up: myScope diff --git a/tests/auto/declarative/qmlvisual/focusscope/test2.qml b/tests/auto/declarative/qmlvisual/focusscope/test2.qml index 7a6ed83..19c8bed 100644 --- a/tests/auto/declarative/qmlvisual/focusscope/test2.qml +++ b/tests/auto/declarative/qmlvisual/focusscope/test2.qml @@ -10,27 +10,27 @@ Rectangle { FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.activeFocus?"red":"blue" } } } } -- cgit v0.12 From cc6980310b097701e8f8026393715d802ac6f9ba Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 20 Jul 2010 13:16:15 +1000 Subject: Use snippets instead to avoid quoting license headers --- doc/src/snippets/declarative/comments.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/src/snippets/declarative/comments.qml b/doc/src/snippets/declarative/comments.qml index bafa26d..9be0ce5 100644 --- a/doc/src/snippets/declarative/comments.qml +++ b/doc/src/snippets/declarative/comments.qml @@ -38,6 +38,7 @@ ** ****************************************************************************/ +//![0] import Qt 4.7 //![0] -- cgit v0.12 From 481e52e1ef66abc583527624fdbeb1d25d97a6c7 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 20 Jul 2010 13:41:00 +1000 Subject: Indicate default values --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 16 ++++++++++++---- src/declarative/graphicsitems/qdeclarativelistview.cpp | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 14a4f08..89b3958 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1293,9 +1293,15 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate) \qmlproperty int GridView::currentIndex \qmlproperty Item GridView::currentItem - \c currentIndex holds the index of the current item. - \c currentItem is the current item. Note that the position of the current item - may only be approximate until it becomes visible in the view. + The \c currentIndex property holds the index of the current item, and + \c currentItem holds the current item. + + If highlightFollowsCurrentItem is \c true, setting either of these + properties will smoothly scroll the GridView so that the current + item becomes visible. + + Note that the position of the current item + may only be approximate until it becomes visible in the view. */ int QDeclarativeGridView::currentIndex() const { @@ -1385,7 +1391,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) \qmlproperty bool GridView::highlightFollowsCurrentItem This property sets whether the highlight is managed by the view. - If this property is true, the highlight is moved smoothly + If this property is true (the default value), the highlight is moved smoothly to follow the current item. Otherwise, the highlight is not moved by the view, and any movement must be implemented by the highlight. @@ -1568,6 +1574,8 @@ void QDeclarativeGridView::setFlow(Flow flow) If this is true, key navigation that would move the current item selection past one end of the view instead wraps around and moves the selection to the other end of the view. + + By default, key navigation is not wrapped. */ bool QDeclarativeGridView::isWrapEnabled() const { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 38bc6f5..8b616ce 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1632,8 +1632,14 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) \qmlproperty int ListView::currentIndex \qmlproperty Item ListView::currentItem - \c currentIndex holds the index of the current item. - \c currentItem is the current item. Note that the position of the current item + The \c currentIndex property holds the index of the current item, and + \c currentItem holds the current item. + + If highlightFollowsCurrentItem is \c true, setting either of these + properties will smoothly scroll the ListView so that the current + item becomes visible. + + Note that the position of the current item may only be approximate until it becomes visible in the view. */ int QDeclarativeListView::currentIndex() const @@ -1727,7 +1733,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) \qmlproperty bool ListView::highlightFollowsCurrentItem This property holds whether the highlight is managed by the view. - If this property is true, the highlight is moved smoothly + If this property is true (the default value), the highlight is moved smoothly to follow the current item. Otherwise, the highlight is not moved by the view, and any movement must be implemented by the highlight. @@ -1848,6 +1854,8 @@ void QDeclarativeListView::setHighlightRangeMode(HighlightRangeMode mode) \qmlproperty real ListView::spacing This property holds the spacing between items. + + The default value is 0. */ qreal QDeclarativeListView::spacing() const { @@ -1914,11 +1922,13 @@ void QDeclarativeListView::setOrientation(QDeclarativeListView::Orientation orie /*! \qmlproperty bool ListView::keyNavigationWraps - This property holds whether the list wraps key navigation. + This property holds whether the list wraps key navigation. If this is true, key navigation that would move the current item selection past the end of the list instead wraps around and moves the selection to the start of the list, and vice-versa. + + By default, key navigation is not wrapped. */ bool QDeclarativeListView::isWrapEnabled() const { -- cgit v0.12 From db04871bda0e470b51dfadef4acbcde08f910f1c Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 20 Jul 2010 14:47:34 +1000 Subject: Expand QtObject doc --- doc/src/snippets/declarative/qtobject.qml | 55 ++++++++++++++++++++++++++++++ src/declarative/qml/qdeclarativeengine.cpp | 47 +++++++++++++++++++++---- 2 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 doc/src/snippets/declarative/qtobject.qml diff --git a/doc/src/snippets/declarative/qtobject.qml b/doc/src/snippets/declarative/qtobject.qml new file mode 100644 index 0000000..970fa16 --- /dev/null +++ b/doc/src/snippets/declarative/qtobject.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ +//![0] +import Qt 4.7 + +Item { + QtObject { + id: attributes + property string name + property int size + property variant attributes + } + + Text { text: attributes.name } +} +//![0] + diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index d1ba6ce..9dae64d 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -115,22 +115,55 @@ QT_BEGIN_NAMESPACE /*! \qmlclass QtObject QObject \since 4.7 - \brief The QtObject element is the most basic element in QML + \brief The QtObject element is the most basic element in QML. The QtObject element is a non-visual element which contains only the - objectName property. It is useful for when you need an extremely - lightweight element to place your own custom properties in. + objectName property. + + It can be useful to create a QtObject if you need an extremely + lightweight element to enclose a set of custom properties: + + \snippet doc/src/snippets/declarative/qtobject.qml 0 It can also be useful for C++ integration, as it is just a plain QObject. See the QObject documentation for further details. */ /*! \qmlproperty string QML:QtObject::objectName - This property allows you to give a name to this specific object instance. + This property holds the QObject::objectName for this specific object instance. + + This allows a C++ application to locate an item within a QML component + using the QObject::findChild() method. For example, the following C++ + application locates the child \l Rectangle item and dynamically changes its + \c color value: + + \qml + // MyRect.qml + + import Qt 4.7 + + Item { + width: 200; height: 200 + + Rectangle { + anchors.fill: parent + color: "red" + objectName: "myRect" + } + } + \endqml + + \code + // main.cpp + + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("MyRect.qml")); + view.show(); - See \l{scripting.html#accessing-child-qobjects}{Accessing Child QObjects} - in the scripting documentation for details how objectName can be used from - scripts. + QDeclarativeItem *item = view.rootObject()->findChild("myRect"); + if (item) + item->setProperty("color", QColor(Qt::yellow)); + \endcode */ struct StaticQtMetaObject : public QObject -- cgit v0.12 From bbc400805f965129341fc3c6a98c4f8b0f9523a4 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 21 Jul 2010 14:32:34 +1000 Subject: Add missing snippet files --- doc/src/snippets/declarative/anchoranimation.qml | 65 +++++++++++++++++++++ doc/src/snippets/declarative/parentanimation.qml | 74 ++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 doc/src/snippets/declarative/anchoranimation.qml create mode 100644 doc/src/snippets/declarative/parentanimation.qml diff --git a/doc/src/snippets/declarative/anchoranimation.qml b/doc/src/snippets/declarative/anchoranimation.qml new file mode 100644 index 0000000..6c7aaf6 --- /dev/null +++ b/doc/src/snippets/declarative/anchoranimation.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import Qt 4.7 + +Item { + id: container + width: 200; height: 200 + + Rectangle { + id: myRect + width: 100; height: 100 + color: "red" + } + + states: State { + name: "reanchored" + AnchorChanges { target: myRect; anchors.right: container.right } + } + + transitions: Transition { + // smoothly reanchor myRect and move into new position + AnchorAnimation { duration: 1000 } + } + + Component.onCompleted: container.state = "reanchored" +} +//![0] diff --git a/doc/src/snippets/declarative/parentanimation.qml b/doc/src/snippets/declarative/parentanimation.qml new file mode 100644 index 0000000..7f11a43 --- /dev/null +++ b/doc/src/snippets/declarative/parentanimation.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 QtDeclarative module 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$ +** +****************************************************************************/ +//![0] +import Qt 4.7 + +Item { + width: 200; height: 100 + + Rectangle { + id: redRect + width: 100; height: 100 + color: "red" + } + + Rectangle { + id: blueRect + x: redRect.width + width: 50; height: 50 + color: "blue" + + states: State { + name: "reparented" + ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 } + } + + transitions: Transition { + ParentAnimation { + NumberAnimation { properties: "x,y"; duration: 1000 } + } + } + + MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" } + } +} +//![0] + -- cgit v0.12 From 2c6312bcb2a80431e6f0cf16d6c4c1d016d40b03 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 21 Jul 2010 15:27:32 +1000 Subject: Expand QDeclarativeExtensionPlugin docs --- .../declarative/cppextensions/plugins/plugin.cpp | 6 ++ .../declarative/cppextensions/plugins/plugins.qml | 3 +- .../qml/qdeclarativeextensionplugin.cpp | 77 ++++++++++++++++++---- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/examples/declarative/cppextensions/plugins/plugin.cpp b/examples/declarative/cppextensions/plugins/plugin.cpp index 355ca3f..01d5361 100644 --- a/examples/declarative/cppextensions/plugins/plugin.cpp +++ b/examples/declarative/cppextensions/plugins/plugin.cpp @@ -96,11 +96,13 @@ private: QBasicTimer timer; }; +//![0] class TimeModel : public QObject { Q_OBJECT Q_PROPERTY(int hour READ hour NOTIFY timeChanged) Q_PROPERTY(int minute READ minute NOTIFY timeChanged) +//![0] public: TimeModel(QObject *parent=0) : QObject(parent) @@ -135,6 +137,7 @@ private: int TimeModel::instances=0; MinuteTimer *TimeModel::timer=0; +//![plugin] class QExampleQmlPlugin : public QDeclarativeExtensionPlugin { Q_OBJECT @@ -145,7 +148,10 @@ public: qmlRegisterType(uri, 1, 0, "Time"); } }; +//![plugin] #include "plugin.moc" +//![export] Q_EXPORT_PLUGIN2(qmlqtimeexampleplugin, QExampleQmlPlugin); +//![export] diff --git a/examples/declarative/cppextensions/plugins/plugins.qml b/examples/declarative/cppextensions/plugins/plugins.qml index 1832017..8d1085c 100644 --- a/examples/declarative/cppextensions/plugins/plugins.qml +++ b/examples/declarative/cppextensions/plugins/plugins.qml @@ -37,7 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - +//![0] import com.nokia.TimeExample 1.0 // import types from the plugin Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml) @@ -49,3 +49,4 @@ Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml) hours: time.hour minutes: time.minute } +//![0] diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp index 0660599..448fde2 100644 --- a/src/declarative/qml/qdeclarativeextensionplugin.cpp +++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp @@ -50,23 +50,76 @@ QT_BEGIN_NAMESPACE \ingroup plugins - QDeclarativeExtensionPlugin is a plugin interface that makes it - possible to offer extensions that can be loaded dynamically into - applications using the QDeclarativeEngine class. - - Writing a QML extension plugin is achieved by subclassing this - base class, reimplementing the pure virtual registerTypes() - function, and exporting the class using the Q_EXPORT_PLUGIN2() - macro. + QDeclarativeExtensionPlugin is a plugin interface that makes it possible to + create QML extensions that can be loaded dynamically into QML applications. + These extensions allow custom QML types to be made available to the QML engine. + + To write a QML extension plugin: + + \list + \o Subclass QDeclarativeExtensionPlugin, implement registerTypes() method + to register types using qmlRegisterType(), and export the class using the Q_EXPORT_PLUGIN2() macro + \o Write an appropriate project file for the plugin + \o Create a \l{The qmldir file}{qmldir file} to describe the plugin + \endlist QML extension plugins can be used to provide either application-specific or library-like plugins. Library plugins should limit themselves to registering types, as any manipulation of the engine's root context may cause conflicts or other issues in the library user's code. - See \l {Tutorial: Writing QML extensions with C++} for details on creating - QML extensions, including how to build a plugin with with QDeclarativeExtensionPlugin. - For a simple overview, see the \l{declarative/cppextensions/plugins}{plugins} example. + + \section1 An example + + Suppose there is a new \c TimeModel C++ class that should be made available + as a new QML element. It provides the current time through \c hour and \c minute + properties, like this: + + \snippet examples/declarative/cppextensions/plugins/plugin.cpp 0 + \dots + + To make this class available as a QML type, create a plugin that registers + this type using qmlRegisterType(). For this example the plugin + module will be named \c com.nokia.TimeExample (as defined in the project + file further below). + + \snippet examples/declarative/cppextensions/plugins/plugin.cpp plugin + \codeline + \snippet examples/declarative/cppextensions/plugins/plugin.cpp export + + This registers the \c TimeModel class with the 1.0 version of this + plugin library, as a QML type called \c Time. The Q_ASSERT statement + ensures the module is imported correctly by any QML components that use this plugin. + + The project file defines the project as a plugin library and specifies + it should be built into the \c com/nokia/TimeExample directory: + + \code + TEMPLATE = lib + CONFIG += qt plugin + QT += declarative + + DESTDIR = com/nokia/TimeExample + TARGET = qmlqtimeexampleplugin + ... + \endcode + + Finally, a \l{The qmldir file}{qmldir file} is required in the \c com/nokia/TimeExample directory + that describes the plugin. This directory includes a \c Clock.qml file that + should be bundled with the plugin, so it needs to be specified in the \c qmldir + file: + + \quotefile examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir + + Once the project is built and installed, the new \c Time element can be + used by any QML component that imports the \c com.nokia.TimeExample module: + + \snippet examples/declarative/cppextensions/plugins/plugins.qml 0 + + The full source code is available in the \l {declarative/cppextensions/plugins}{plugins example}. + + The \l {Tutorial: Writing QML extensions with C++} also contains a chapter + on creating QML plugins. \sa QDeclarativeEngine::importPlugin(), {How to Create Qt Plugins} */ @@ -95,7 +148,7 @@ QDeclarativeExtensionPlugin::QDeclarativeExtensionPlugin(QObject *parent) } /*! - Destroys the plugin. + \internal */ QDeclarativeExtensionPlugin::~QDeclarativeExtensionPlugin() { -- cgit v0.12