From f88fe352c148b0aea633fca2b81d6a2c7782bb87 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 13 Oct 2009 09:45:42 +1000 Subject: Fix some of the ListView remove tests. The remainder are bugs. --- tests/auto/declarative/listview/tst_listview.cpp | 34 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 2a5fa1c..1875836 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -34,6 +34,8 @@ private: QmlView *createView(const QString &filename); template T *findItem(QFxItem *parent, const QString &id, int index=-1); + template + QList findItems(QFxItem *parent, const QString &objectName); }; class TestModel : public QListModelInterface @@ -336,7 +338,8 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -357,7 +360,8 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -370,7 +374,8 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -398,7 +403,8 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -493,6 +499,26 @@ T *tst_QFxListView::findItem(QFxItem *parent, const QString &objectName, int ind return 0; } +template +QList tst_QFxListView::findItems(QFxItem *parent, const QString &objectName) +{ + QList items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QFxItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast(item)); + items += findItems(item, objectName); + } + + return items; +} + + QTEST_MAIN(tst_QFxListView) #include "tst_listview.moc" -- cgit v0.12 From f0e328e0a59cdd9b9cfcea46cef07bf2ff8eebad Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Oct 2009 09:47:20 +1000 Subject: Add basic QML docs for the effects. --- doc/src/declarative/elements.qdoc | 7 ++ src/declarative/fx/fx.pri | 1 + src/declarative/fx/qfxeffects.cpp | 238 ++++++++++++++++++++++++++++++++++++++ src/declarative/fx/qfxitem.cpp | 24 ---- 4 files changed, 246 insertions(+), 24 deletions(-) create mode 100644 src/declarative/fx/qfxeffects.cpp diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 98c4ee1..4fa4ec5 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -185,6 +185,13 @@ The following table lists the QML elements provided by the Qt Declarative module \o \list +\o \l Blur +\o \l Colorize +\o \l Grayscale +\o \l Pixelize +\o \l DropShadow +\o \l Opacity +\o \l Bloom \o \l Particles \list \o \l ParticleMotionLinear diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index cfe78e1..fc4e640 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -44,6 +44,7 @@ HEADERS += \ fx/qfxlistview.h \ fx/qfxgraphicsobjectcontainer.h \ fx/qfxlayoutitem.h \ + fx/qfxeffects.cpp SOURCES += \ fx/qfxanchors.cpp \ diff --git a/src/declarative/fx/qfxeffects.cpp b/src/declarative/fx/qfxeffects.cpp new file mode 100644 index 0000000..ebdd880 --- /dev/null +++ b/src/declarative/fx/qfxeffects.cpp @@ -0,0 +1,238 @@ +#include +#include +#include + +QML_DECLARE_TYPE(QGraphicsEffect) +QML_DEFINE_NOCREATE_TYPE(QGraphicsEffect) + +QML_DECLARE_TYPE(QGraphicsBlurEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Blur,QGraphicsBlurEffect) + +/*! + \qmlclass Blur + \brief The Blur object provides a blur effect. + + A blur effect blurs the source item. This effect is useful for reducing details, + such as when the source loses focus and you want to draw attention to other + elements. The level of detail can be modified using the blurRadius property. + Use blurHint to choose the quality or performance blur hints. + + By default, the blur radius is 5 pixels. + + \img graphicseffect-blur.png +*/ + +/*! + \qmlproperty real Blur::blurRadius + + blurRadius controls how blurry an item will appear. + Using a smaller radius results in a sharper appearance, whereas a bigger + radius results in a more blurred appearance. + + By default, the blur radius is 5 pixels. +*/ +/*! + \qmlproperty enumeration Blur::blurHint + + Use the Qt.PerformanceHint hint to say that you want a faster blur, + and the Qt.QualityHint hint to say that you prefer a higher quality blur. + + When animating the blur radius it's recommended to use Qt.PerformanceHint. + + By default, the blur hint is Qt.PerformanceHint. +*/ + +QML_DECLARE_TYPE(QGraphicsGrayscaleEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grayscale,QGraphicsGrayscaleEffect) + +/*! + \qmlclass Grayscale + \brief The Grayscale object provides a grayscale effect. + + A grayscale effect renders the source item in shades of gray. + + \img graphicseffect-grayscale.png +*/ + +/*! + \qmlproperty real Grayscale::strength + + To what extent the source item is "grayed". A strength of 0.0 is equal to no effect, + while 1.0 means full grayscale. By default, the strength is 1.0. +*/ + +QML_DECLARE_TYPE(QGraphicsColorizeEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Colorize,QGraphicsColorizeEffect) + +/*! + \qmlclass Colorize + \brief The Colorize object provides a colorize effect. + + A colorize effect renders the source item with a tint of its color. + + By default, the color is light blue. + + \img graphicseffect-colorize.png +*/ + +/*! + \qmlproperty color Colorize::color + The color of the effect. + + By default, the color is light blue. +*/ + +/*! + \qmlproperty real Colorize::strength + + To what extent the source item is "colored". A strength of 0.0 is equal to no effect, + while 1.0 means full colorization. By default, the strength is 1.0. +*/ + +QML_DECLARE_TYPE(QGraphicsPixelizeEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pixelize,QGraphicsPixelizeEffect) + +/*! + \qmlclass Pixelize + \brief The Pixelize object provides a pixelize effect. + + A pixelize effect renders the source item in lower resolution. The resolution + can be modified using the pixelSize property. + + By default, the pixel size is 3. + + \img graphicseffect-pixelize.png +*/ + +/*! + \qmlproperty int Pixelize::pixelSize + The size of a pixel in the effect. + + Setting the pixel size to 2 means two pixels in the source item will be used to + represent one pixel in the output. Using a bigger size results in lower resolution. + + By default, the pixel size is 3. +*/ + + +QML_DECLARE_TYPE(QGraphicsDropShadowEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,DropShadow,QGraphicsDropShadowEffect) + +/*! + \qmlclass DropShadow + \brief The DropShadow object provides a drop shadow effect. + + A drop shadow effect renders the source item with a drop shadow. The color of + the drop shadow can be modified using the color property. The drop + shadow offset can be modified using the xOffset and yOffset properties and the blur + radius of the drop shadow can be changed with the blurRadius property. + + By default, the drop shadow is a semi-transparent dark gray shadow, + blurred with a radius of 1 at an offset of 8 pixels towards the lower right. + + \img graphicseffect-drop-shadow.png +*/ + +/*! + \qmlproperty real DropShadow::xOffset + \qmlproperty real DropShadow::yOffset + The shadow offset in pixels. + + By default, xOffset and yOffset are 8 pixels. +*/ + +/*! + \qmlproperty real DropShadow::blurRadius + The blur radius in pixels of the drop shadow. + + Using a smaller radius results in a sharper shadow, whereas using a bigger + radius results in a more blurred shadow. + + By default, the blur radius is 1 pixel. +*/ + +/*! + \qmlproperty color DropShadow::color + The color of the drop shadow. + + By default, the drop color is a semi-transparent dark gray. +*/ + +QML_DECLARE_TYPE(QGraphicsOpacityEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Opacity,QGraphicsOpacityEffect) + +/*! + \qmlclass Opacity + \brief The Opacity object provides an opacity effect. + + An opacity effect renders the source with an opacity. This effect is useful + for making the source semi-transparent, similar to a fade-in/fade-out + sequence. The opacity can be modified using the opacity property. + + By default, the opacity is 0.7. + + \img graphicseffect-opacity.png +*/ + +/*! + \qmlproperty real Opacity::opacity + This property specifies how opaque an item should appear. + + The value should be in the range of 0.0 to 1.0, where 0.0 is + fully transparent and 1.0 is fully opaque. + + By default, the opacity is 0.7. +*/ + +QML_DECLARE_TYPE(QGraphicsBloomEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Bloom,QGraphicsBloomEffect) + +/*! + \qmlclass Bloom + \brief The Bloom object provides a bloom/glow effect. + + A bloom/glow effect adds fringes of light around bright areas in the source item. + + \img graphicseffect-bloom.png +*/ + +/*! + \qmlproperty real Bloom::blurRadius + The blur radius in pixels of the effect. + + Using a smaller radius results in a sharper appearance, whereas a bigger + radius results in a more blurred appearance. + + By default, the blur radius is 5 pixels. +*/ + +/*! + \qmlproperty enumeration Bloom::blurHint + + Use the Qt.PerformanceHint hint to say that you want a faster blur, + and the Qt.QualityHint hint to say that you prefer a higher quality blur. + + When animating the blur radius it's recommended to use Qt.PerformanceHint. + + By default, the blur hint is Qt.PerformanceHint. +*/ + +/*! + \qmlproperty int Bloom::brightness + This property specifies how bright the glow should appear. + + The value should be in the range of 0 to 255, where 0 is dark + and 255 is bright. + + By default, the brightness is 70. +*/ + +/*! + \qmlproperty real Bloom::strength + The strength of the glow. + + A strength of 0.0 is equal to no effect, while 1.0 means maximum glow. + + By default, the strength is 0.7. +*/ + diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index a155d5a..8ba0759 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -76,30 +76,6 @@ QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Scale,QGraphicsScale) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) -QML_DECLARE_TYPE(QGraphicsEffect) -QML_DEFINE_NOCREATE_TYPE(QGraphicsEffect) - -QML_DECLARE_TYPE(QGraphicsBlurEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Blur,QGraphicsBlurEffect) - -QML_DECLARE_TYPE(QGraphicsGrayscaleEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grayscale,QGraphicsGrayscaleEffect) - -QML_DECLARE_TYPE(QGraphicsColorizeEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Colorize,QGraphicsColorizeEffect) - -QML_DECLARE_TYPE(QGraphicsPixelizeEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pixelize,QGraphicsPixelizeEffect) - -QML_DECLARE_TYPE(QGraphicsDropShadowEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,DropShadow,QGraphicsDropShadowEffect) - -QML_DECLARE_TYPE(QGraphicsOpacityEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Opacity,QGraphicsOpacityEffect) - -QML_DECLARE_TYPE(QGraphicsBloomEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Bloom,QGraphicsBloomEffect) - /*! \qmlclass Transform \brief A transformation. -- cgit v0.12 From a35d64024103df9150bbbc21298bee6e0ab8cd93 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Oct 2009 09:55:45 +1000 Subject: Readd basic Behavior documentation. --- src/declarative/extra/qmlbehavior.cpp | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/declarative/extra/qmlbehavior.cpp b/src/declarative/extra/qmlbehavior.cpp index e30bd39..1cf0d38 100644 --- a/src/declarative/extra/qmlbehavior.cpp +++ b/src/declarative/extra/qmlbehavior.cpp @@ -62,11 +62,43 @@ public: QmlAbstractAnimation *animation; }; +/*! + \qmlclass Behavior QmlBehavior + \brief The Behavior element allows you to specify a default animation for a property change. + + In example below, the rect 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 + y: Behavior { + NumberAnimation { + easing: "easeOutBounce(amplitude:100)" + duration: 200 + } + } + } + \endcode +*/ + + QmlBehavior::QmlBehavior(QObject *parent) : QObject(*(new QmlBehaviorPrivate), parent) { } +QmlBehavior::~QmlBehavior() +{ +} + +/*! + \qmlproperty Animation Behavior::animation + \default + + The animation to use when the behavior is triggered. +*/ + QmlAbstractAnimation *QmlBehavior::animation() { Q_D(QmlBehavior); @@ -86,10 +118,6 @@ void QmlBehavior::setAnimation(QmlAbstractAnimation *animation) d->animation->setTarget(d->property); } -QmlBehavior::~QmlBehavior() -{ -} - void QmlBehavior::write(const QVariant &value) { Q_D(QmlBehavior); -- cgit v0.12 From 3b0c979986a692c58b6c72a284070e700c09b9c4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Oct 2009 11:14:36 +1000 Subject: Add autotest for overriding a signal handler in a state change. --- .../declarative/states/data/ExtendedRectangle.qml | 19 ++++++++ .../declarative/states/data/signalOverride.qml | 18 ++++++++ .../declarative/states/data/signalOverride2.qml | 9 ++++ tests/auto/declarative/states/tst_states.cpp | 51 ++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 tests/auto/declarative/states/data/ExtendedRectangle.qml create mode 100644 tests/auto/declarative/states/data/signalOverride.qml create mode 100644 tests/auto/declarative/states/data/signalOverride2.qml diff --git a/tests/auto/declarative/states/data/ExtendedRectangle.qml b/tests/auto/declarative/states/data/ExtendedRectangle.qml new file mode 100644 index 0000000..8d64663 --- /dev/null +++ b/tests/auto/declarative/states/data/ExtendedRectangle.qml @@ -0,0 +1,19 @@ +import Qt 4.6 +Rectangle { + id: extendedRect + objectName: "extendedRect" + property color extendedColor: "orange" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: { + extendedRect.color = "green" + extendedColor = "green" + } + } + } +} diff --git a/tests/auto/declarative/states/data/signalOverride.qml b/tests/auto/declarative/states/data/signalOverride.qml new file mode 100644 index 0000000..5ba1566 --- /dev/null +++ b/tests/auto/declarative/states/data/signalOverride.qml @@ -0,0 +1,18 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + + onDidSomething: color = "blue" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: color = "green" + } + } +} diff --git a/tests/auto/declarative/states/data/signalOverride2.qml b/tests/auto/declarative/states/data/signalOverride2.qml new file mode 100644 index 0000000..527e165 --- /dev/null +++ b/tests/auto/declarative/states/data/signalOverride2.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + onDidSomething: color = "blue" + width: 100; height: 100 + ExtendedRectangle {} +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 3a61bd6..b2532a2 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -13,6 +13,7 @@ private slots: void basicChanges(); void basicExtension(); void basicBinding(); + void signalOverride(); }; void tst_states::basicChanges() @@ -262,6 +263,56 @@ void tst_states::basicBinding() } } +class MyRect : public QFxRect +{ + Q_OBJECT +public: + MyRect() {} + void doSomething() { emit didSomething(); } +Q_SIGNALS: + void didSomething(); +}; + +QML_DECLARE_TYPE(MyRect) +QML_DEFINE_TYPE(Qt.test, 1, 0, 0, MyRectangle,MyRect); + +void tst_states::signalOverride() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride.qml"); + MyRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("green")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride2.qml"); + MyRect *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("white")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + QFxRect *innerRect = qobject_cast(rect->findChild("extendedRect")); + + innerRect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(innerRect->color(),QColor("green")); + QCOMPARE(innerRect->property("extendedColor").value(),QColor("green")); + } +} + QTEST_MAIN(tst_states) #include "tst_states.moc" -- cgit v0.12 From d39b7ce65f051da342dcc931e303a73339288c5e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Oct 2009 11:27:26 +1000 Subject: Make sure effects are still included. --- src/declarative/fx/qfxitem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 8ba0759..6324724 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -76,6 +76,8 @@ QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Scale,QGraphicsScale) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) +#include "qfxeffects.cpp" + /*! \qmlclass Transform \brief A transformation. -- cgit v0.12