#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());
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)
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
, fillColor(Qt::transparent)
, renderTarget(QQuickPaintedItem::Image)
, performanceHints(0)
- , geometryDirty(false)
- , contentsDirty(false)
, opaquePainting(false)
, antialiasing(false)
, mipmap(false)
void QQuickPaintedItem::update(const QRect &rect)
{
Q_D(QQuickPaintedItem);
- d->contentsDirty = true;
if (rect.isNull() && !d->dirtyRect.isNull())
d->dirtyRect = contentsBoundingRect().toAlignedRect();
*/
/*!
- 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.
*/
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;
protected:
QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = 0);
- virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
private:
QRect dirtyRect;
- bool geometryDirty : 1;
- bool contentsDirty : 1;
bool opaquePainting: 1;
bool antialiasing: 1;
bool mipmap: 1;
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)
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; }