From: Charles Yin Date: Thu, 27 Oct 2011 03:06:57 +0000 (+1000) Subject: Fix PaintedItem redraw bug X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=1bc655b46738811268b50b318a3f3cd03ff02aff;p=konrad%2Fqtdeclarative.git Fix PaintedItem redraw bug 1) After QQuickItem::update() being called (means item's content is dirty), the paint() function should always been called, so the contentsDirty and geometryDirty flags are not needed. 2) Update the smile example to validate the above changes Task-number:QTBUG-22250 Change-Id: I5a72f18e6982bdb3ba23e78a253c2876aca2e8cb Reviewed-by: Michael Brasser Reviewed-by: Yoann Lopes --- diff --git a/examples/declarative/painteditem/smile/main.cpp b/examples/declarative/painteditem/smile/main.cpp index 1f0b3a3..dc76e71 100644 --- a/examples/declarative/painteditem/smile/main.cpp +++ b/examples/declarative/painteditem/smile/main.cpp @@ -43,16 +43,24 @@ #include #include #include - 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 bc4bd26..e09d9b1 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 diff --git a/src/declarative/items/qquickpainteditem.cpp b/src/declarative/items/qquickpainteditem.cpp index ac67f6a..4d96da2 100644 --- a/src/declarative/items/qquickpainteditem.cpp +++ b/src/declarative/items/qquickpainteditem.cpp @@ -123,8 +123,6 @@ QQuickPaintedItemPrivate::QQuickPaintedItemPrivate() , fillColor(Qt::transparent) , renderTarget(QQuickPaintedItem::Image) , performanceHints(0) - , geometryDirty(false) - , contentsDirty(false) , opaquePainting(false) , antialiasing(false) , mipmap(false) @@ -171,7 +169,6 @@ QQuickPaintedItem::~QQuickPaintedItem() void QQuickPaintedItem::update(const QRect &rect) { Q_D(QQuickPaintedItem); - d->contentsDirty = true; if (rect.isNull() && !d->dirtyRect.isNull()) d->dirtyRect = contentsBoundingRect().toAlignedRect(); @@ -492,17 +489,6 @@ void QQuickPaintedItem::setRenderTarget(RenderTarget target) */ /*! - This function is called after the item's geometry has changed. -*/ -void QQuickPaintedItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickPaintedItem); - d->geometryDirty = true; - QQuickItem::geometryChanged(newGeometry, oldGeometry); -} - - -/*! This function is called when the Scene Graph node associated to the item needs to be updated. */ @@ -531,11 +517,9 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat node->setOpaquePainting(d->opaquePainting); node->setFillColor(d->fillColor); node->setContentsScale(d->contentsScale); - node->setDirty(d->contentsDirty || d->geometryDirty, d->dirtyRect); + node->setDirty(d->dirtyRect); node->update(); - d->contentsDirty = false; - d->geometryDirty = false; d->dirtyRect = QRect(); return node; diff --git a/src/declarative/items/qquickpainteditem.h b/src/declarative/items/qquickpainteditem.h index 1ddfa25..b2da9e6 100644 --- a/src/declarative/items/qquickpainteditem.h +++ b/src/declarative/items/qquickpainteditem.h @@ -114,7 +114,6 @@ Q_SIGNALS: protected: QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = 0); - virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); private: diff --git a/src/declarative/items/qquickpainteditem_p.h b/src/declarative/items/qquickpainteditem_p.h index 00061d9..b847b0a 100644 --- a/src/declarative/items/qquickpainteditem_p.h +++ b/src/declarative/items/qquickpainteditem_p.h @@ -61,8 +61,6 @@ public: QRect dirtyRect; - bool geometryDirty : 1; - bool contentsDirty : 1; bool opaquePainting: 1; bool antialiasing: 1; bool mipmap: 1; diff --git a/src/declarative/scenegraph/util/qsgpainternode.cpp b/src/declarative/scenegraph/util/qsgpainternode.cpp index a89dd75..f3e5202 100644 --- a/src/declarative/scenegraph/util/qsgpainternode.cpp +++ b/src/declarative/scenegraph/util/qsgpainternode.cpp @@ -378,9 +378,9 @@ void QSGPainterNode::setSize(const QSize &size) m_dirtyTexture = true; } -void QSGPainterNode::setDirty(bool d, const QRect &dirtyRect) +void QSGPainterNode::setDirty(const QRect &dirtyRect) { - m_dirtyContents = d; + m_dirtyContents = true; m_dirtyRect = dirtyRect; if (m_mipmapping) diff --git a/src/declarative/scenegraph/util/qsgpainternode_p.h b/src/declarative/scenegraph/util/qsgpainternode_p.h index c838ed1..8e95107 100644 --- a/src/declarative/scenegraph/util/qsgpainternode_p.h +++ b/src/declarative/scenegraph/util/qsgpainternode_p.h @@ -83,7 +83,7 @@ public: void setSize(const QSize &size); QSize size() const { return m_size; } - void setDirty(bool d, const QRect &dirtyRect = QRect()); + void setDirty(const QRect &dirtyRect = QRect()); void setOpaquePainting(bool opaque); bool opaquePainting() const { return m_opaquePainting; }