From e1dd37f6b54881aef3b9e1e686dc56bb96fc14ed Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 28 Aug 2009 22:13:09 +1000 Subject: Add graphics effects support --- examples/declarative/effects/pic.jpg | Bin 0 -> 7016 bytes examples/declarative/effects/test.qml | 75 ++++++++++++++++++++++++++++++++++ src/declarative/fx/qfxitem.cpp | 21 ++++++++++ src/declarative/fx/qfxitem.h | 1 + 4 files changed, 97 insertions(+) create mode 100644 examples/declarative/effects/pic.jpg create mode 100644 examples/declarative/effects/test.qml diff --git a/examples/declarative/effects/pic.jpg b/examples/declarative/effects/pic.jpg new file mode 100644 index 0000000..5775518 Binary files /dev/null and b/examples/declarative/effects/pic.jpg differ diff --git a/examples/declarative/effects/test.qml b/examples/declarative/effects/test.qml new file mode 100644 index 0000000..4cc8746 --- /dev/null +++ b/examples/declarative/effects/test.qml @@ -0,0 +1,75 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 800 + height: 600 + + Image { + source: "pic.jpg" + + effect: Blur { + blurRadius: NumberAnimation { id: BS; from: 0; to: 10; duration: 200; repeat: true } + } + + MouseRegion { anchors.fill: parent; onClicked: BS.running = !BS.running } + + Text { color: "white"; text: "Blur" } + } + + Image { + source: "pic.jpg" + + x: 200 + effect: Grayscale {} + + Text { color: "white"; text: "Grayscale" } + } + + Image { + source: "pic.jpg" + + x: 400 + effect: Colorize { color: "blue" } + + Text { color: "white"; text: "Colorize" } + } + + Image { + source: "pic.jpg" + + y: 300 + effect: Pixelize { + pixelSize: NumberAnimation { id: PS; from: 0; to: 10; duration: 200; repeat: true } + } + + MouseRegion { anchors.fill: parent; onClicked: PS.running = !PS.running } + + Text { color: "white"; text: "Pixelize" } + } + + + Image { + source: "pic.jpg" + + x: 200 + y: 300 + effect: DropShadow { + blurRadius: 3 + offset.x: 3 + offset.y: NumberAnimation { id: DS; from: 0; to: 10; duration: 200; repeat: true; } + } + + MouseRegion { anchors.fill: parent; onClicked: DS.running = !DS.running } + + Text { color: "white"; text: "DropShadow" } + } + + + Text { + x: 400; y: 300 + text: "Clicking Blur, Pixelize or DropShadow will \ntoggle animation." + color: "black" + } + +} diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 9b9355e..c436622 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,26 @@ 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) /*! \qmlclass Transform \brief A transformation. diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 165e4cc..5b95478 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -93,6 +93,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) + Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect); Q_ENUMS(TransformOrigin) Q_CLASSINFO("DefaultProperty", "data") -- cgit v0.12