summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativepainteditem.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
index f52636fbe9..13d1b61a3d 100644
--- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
@@ -59,8 +59,8 @@ QT_BEGIN_NAMESPACE
\brief The QDeclarativePaintedItem class is an abstract base class for QDeclarativeView items that want cached painting.
\internal
- This is a convenience class for implementing items that paint their contents
- using a QPainter. The contents of the item are cached behind the scenes.
+ This is a convenience class for implementing items that cache their painting.
+ The contents of the item are cached behind the scenes.
The dirtyCache() function should be called if the contents change to
ensure the cache is refreshed the next time painting occurs.
@@ -152,8 +152,6 @@ void QDeclarativePaintedItem::setContentsSize(const QSize &size)
Q_D(QDeclarativePaintedItem);
if (d->contentsSize == size) return;
d->contentsSize = size;
- setImplicitWidth(size.width()*d->contentsScale);
- setImplicitHeight(size.height()*d->contentsScale);
clearCache();
update();
emit contentsSizeChanged();
@@ -170,8 +168,6 @@ void QDeclarativePaintedItem::setContentsScale(qreal scale)
Q_D(QDeclarativePaintedItem);
if (d->contentsScale == scale) return;
d->contentsScale = scale;
- setImplicitWidth(d->contentsSize.width()*scale);
- setImplicitHeight(d->contentsSize.height()*scale);
clearCache();
update();
emit contentsScaleChanged();
@@ -184,7 +180,6 @@ void QDeclarativePaintedItem::setContentsScale(qreal scale)
QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativeItem *parent)
: QDeclarativeItem(*(new QDeclarativePaintedItemPrivate), parent)
{
- init();
}
/*!
@@ -195,7 +190,6 @@ QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativeItem *parent)
QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativePaintedItemPrivate &dd, QDeclarativeItem *parent)
: QDeclarativeItem(dd, parent)
{
- init();
}
/*!
@@ -206,14 +200,23 @@ QDeclarativePaintedItem::~QDeclarativePaintedItem()
clearCache();
}
-/*!
- \internal
-*/
-void QDeclarativePaintedItem::init()
+void QDeclarativePaintedItem::geometryChanged(const QRectF &newGeometry,
+ const QRectF &oldGeometry)
{
- connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache()));
- connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache()));
- connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache()));
+ if (newGeometry.width() != oldGeometry.width() ||
+ newGeometry.height() != oldGeometry.height())
+ clearCache();
+
+ QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+}
+
+QVariant QDeclarativePaintedItem::itemChange(GraphicsItemChange change,
+ const QVariant &value)
+{
+ if (change == ItemVisibleHasChanged)
+ clearCache();
+
+ return QDeclarativeItem::itemChange(change, value);
}
void QDeclarativePaintedItem::setCacheFrozen(bool frozen)
@@ -225,8 +228,21 @@ void QDeclarativePaintedItem::setCacheFrozen(bool frozen)
// XXX clear cache?
}
+QRectF QDeclarativePaintedItem::boundingRect() const
+{
+ Q_D(const QDeclarativePaintedItem);
+ qreal w = d->mWidth;
+ QSizeF sz = d->contentsSize * d->contentsScale;
+ if (w < sz.width())
+ w = sz.width();
+ qreal h = d->mHeight;
+ if (h < sz.height())
+ h = sz.height();
+ return QRectF(0.0,0.0,w,h);
+}
+
/*!
- \reimp
+ \internal
*/
void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{