aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/painteditem/smile/main.cpp20
-rw-r--r--examples/declarative/painteditem/smile/smile.qml83
2 files changed, 95 insertions, 8 deletions
diff --git a/examples/declarative/painteditem/smile/main.cpp b/examples/declarative/painteditem/smile/main.cpp
index 1f0b3a3cb8..dc76e71185 100644
--- a/examples/declarative/painteditem/smile/main.cpp
+++ b/examples/declarative/painteditem/smile/main.cpp
@@ -43,16 +43,24 @@
#include <QtDeclarative/qdeclarative.h>
#include <QtDeclarative/qquickview.h>
#include <QtDeclarative/qquickpainteditem.h>
-
class MyPaintItem : public QQuickPaintedItem
{
Q_OBJECT
+ Q_PROPERTY(QString face READ face WRITE setFace NOTIFY faceChanged)
public:
- MyPaintItem() : QQuickPaintedItem()
+ MyPaintItem()
+ : QQuickPaintedItem()
+ , m_face(QLatin1String(":-)"))
{
setAntialiasing(true);
}
-
+ QString face() const {return m_face;}
+ void setFace(const QString &face) {
+ if (m_face != face) {
+ m_face = face;
+ emit faceChanged();
+ }
+ }
virtual void paint(QPainter *p)
{
QRectF rect(0, 0, width(), height());
@@ -62,8 +70,12 @@ public:
p->drawEllipse(rect);
p->setPen(Qt::black);
p->setFont(QFont(QLatin1String("Times"), qRound(rect.height() / 2)));
- p->drawText(rect, Qt::AlignCenter, QLatin1String(":-)"));
+ p->drawText(rect, Qt::AlignCenter, m_face);
}
+signals:
+ void faceChanged();
+private:
+ QString m_face;
};
int main(int argc, char ** argv)
diff --git a/examples/declarative/painteditem/smile/smile.qml b/examples/declarative/painteditem/smile/smile.qml
index bc4bd2664b..e09d9b1fa8 100644
--- a/examples/declarative/painteditem/smile/smile.qml
+++ b/examples/declarative/painteditem/smile/smile.qml
@@ -42,16 +42,91 @@ import QtQuick 2.0
import MyModule 1.0
Rectangle {
- width: 480
- height: 480
+ width: 500
+ height: 500
gradient: Gradient {
GradientStop { position: 0.0; color: "#00249a" }
GradientStop { position: 0.7; color: "#ffd94f" }
GradientStop { position: 1.0; color: "#ffa322" }
}
MyPaintItem {
- anchors.fill: parent
+ renderTarget:PaintedItem.Image
+ clip:true
+ width:240
+ height:240
+ anchors.left : parent.left
+ anchors.top :parent.top
anchors.margins: 10
smooth: true
+ MouseArea {
+ anchors.fill:parent
+ onClicked: {
+ if (parent.face == ":-)")
+ parent.face = ":-(";
+ else
+ parent.face = ":-)";
+ parent.update()
+ }
+ }
}
-}
+ MyPaintItem {
+ clip:true
+ renderTarget:PaintedItem.Image
+ width:240
+ height:240
+ anchors.right : parent.right
+ anchors.top :parent.top
+ anchors.margins: 10
+ smooth: true
+ MouseArea {
+ anchors.fill:parent
+ onClicked: {
+ if (parent.face == ":-)")
+ parent.face = ":-(";
+ else
+ parent.face = ":-)";
+ parent.update()
+ }
+ }
+ }
+ MyPaintItem {
+ clip:true
+ renderTarget:PaintedItem.Image
+ width:240
+ height:240
+ anchors.left : parent.left
+ anchors.bottom :parent.bottom
+ anchors.margins: 10
+ smooth: true
+ MouseArea {
+ anchors.fill:parent
+ onClicked: {
+ if (parent.face == ":-)")
+ parent.face = ":-(";
+ else
+ parent.face = ":-)";
+ parent.update()
+ }
+ }
+ }
+ MyPaintItem {
+ clip:true
+ renderTarget:PaintedItem.Image
+ width:240
+ height:240
+ anchors.right : parent.right
+ anchors.bottom :parent.bottom
+ anchors.margins: 10
+ smooth: true
+ MouseArea {
+ anchors.fill:parent
+ onClicked: {
+ if (parent.face == ":-)")
+ parent.face = ":-(";
+ else
+ parent.face = ":-)";
+ parent.update()
+ }
+ }
+ }
+} \ No newline at end of file