--- a/src/hbwidgets/itemviews/hbabstractviewitem.cpp Wed Aug 18 10:05:37 2010 +0300
+++ b/src/hbwidgets/itemviews/hbabstractviewitem.cpp Thu Sep 02 20:44:51 2010 +0300
@@ -68,7 +68,7 @@
The HbAbstractViewItem class provides an item that is used by HbAbstractItemView class to
visualize content within single model index. By default HbAbstractViewItem supports QString and QStringList
stored into Qt::DisplayRole role and QIcon, HbIcon or list of them in QVariantList stored into
- Qt::DecoratorRole role.
+ Qt::DecoratorRole role.
This class is provided mainly for customization purposes but it also acts as a default
item prototype inside HbAbstractItemView. See HbAbstractItemView how to set customized class as a item prototype.
@@ -428,63 +428,80 @@
if (!child->isVisible() || child == mNonCachableItem || child == mFrontPixmapPainter || child == mBackPixmapPainter) {
continue;
}
-
+
if (!itemPainted && child->zValue() >= 0) {
- painter->save();
option->exposedRect = q->boundingRect();
q->paint(painter, option, 0);
- painter->restore();
itemPainted = true;
}
- painter->save();
if (child == mFrame) {
+ QPainter::CompositionMode mode = painter->compositionMode();
painter->setCompositionMode(QPainter::CompositionMode_Source);
+ painter->translate(child->pos());
+ option->exposedRect = child->boundingRect();
+ child->paint(painter, option, 0);
+ painter->setCompositionMode(mode);
+ painter->translate(-child->pos());
+ continue;
}
-
- painter->translate(child->pos());
-
- option->exposedRect = child->boundingRect();
- child->paint(painter, option, 0);
-
- painter->restore();
+ paintChildItemsRecursively(child,painter,option);
}
-
mInPaintItems = false;
}
+void HbAbstractViewItemPrivate::paintChildItemsRecursively(QGraphicsItem *child, QPainter *painter,QStyleOptionGraphicsItem *option)
+{
+ if (!child->isVisible())
+ return;
+ int i = 0;
+ QList<QGraphicsItem *> children = child->childItems();
+ int count(children.size());
+ painter->translate(child->pos());
+ // Draw children behind
+ for (i = 0; i < count; ++i) {
+ QGraphicsItem *subChild = children.at(i);
+ if (!(subChild->flags() & QGraphicsItem::ItemStacksBehindParent))
+ break;
+ paintChildItemsRecursively(subChild, painter,option);
+ }
+ option->exposedRect = child->boundingRect();
+ child->paint(painter, option, 0);
+ // Draw children in front
+ for (; i < count; ++i) {
+ QGraphicsItem *subChild = children.at(i);
+ paintChildItemsRecursively(subChild, painter,option);
+ }
+ painter->translate(-child->pos());
+}
+
+
void HbAbstractViewItemPrivate::setChildFlags(QGraphicsItem *child, bool pixmapCacheEnabled)
{
- Q_Q(HbAbstractViewItem);
+ QGraphicsItem::GraphicsItemFlags itemFlags = child->flags();
+ if (pixmapCacheEnabled) {
+ itemFlags |= QGraphicsItem::ItemHasNoContents;
+ itemFlags |= QGraphicsItem::ItemIgnoresParentOpacity;
+ }
+ else {
+ itemFlags &= ~QGraphicsItem::ItemHasNoContents;
+ itemFlags &= ~QGraphicsItem::ItemIgnoresParentOpacity;
+ }
+ child->setFlags(itemFlags);
+ foreach (QGraphicsItem *subChild, child->childItems()) {
+ setChildFlags(subChild,pixmapCacheEnabled);
+ }
+}
- if (child) {
- QGraphicsItem::GraphicsItemFlags itemFlags = child->flags();
- if (pixmapCacheEnabled) {
- itemFlags |= QGraphicsItem::ItemHasNoContents;
- itemFlags |= QGraphicsItem::ItemIgnoresParentOpacity;
- }
- else {
- itemFlags &= ~QGraphicsItem::ItemHasNoContents;
- itemFlags &= ~QGraphicsItem::ItemIgnoresParentOpacity;
- }
- child->setFlags(itemFlags);
- } else {
- foreach (QGraphicsItem *child, q->childItems()) {
- if (child == mNonCachableItem || child == mFrontPixmapPainter || child == mBackPixmapPainter) {
- continue;
- }
-
- QGraphicsItem::GraphicsItemFlags itemFlags = child->flags();
- if (pixmapCacheEnabled) {
- itemFlags |= QGraphicsItem::ItemHasNoContents;
- itemFlags |= QGraphicsItem::ItemIgnoresParentOpacity;
- }
- else {
- itemFlags &= ~QGraphicsItem::ItemHasNoContents;
- itemFlags &= ~QGraphicsItem::ItemIgnoresParentOpacity;
- }
- child->setFlags(itemFlags);
+void HbAbstractViewItemPrivate::setChildFlagRecursively(bool pixmapCacheEnabled)
+{
+ Q_Q(HbAbstractViewItem);
+ foreach (QGraphicsItem *subChild, q->childItems()) {
+ if (subChild == mNonCachableItem || subChild == mFrontPixmapPainter ||
+ subChild == mBackPixmapPainter) {
+ continue;
}
+ setChildFlags(subChild, pixmapCacheEnabled);
}
}
@@ -512,20 +529,10 @@
void HbAbstractViewItemPrivate::releasePixmaps()
{
- if (mFrontCachePixmap) {
- delete mFrontCachePixmap;
- mFrontCachePixmap = 0;
- }
-
if (mFrontPixmapPainter) {
mFrontPixmapPainter->setPixmap(0);
}
- if (mBackCachePixmap) {
- delete mBackCachePixmap;
- mBackCachePixmap = 0;
- }
-
if (mBackPixmapPainter) {
mBackPixmapPainter->setPixmap(0);
}
@@ -587,8 +594,6 @@
if (d && !d->isPrototype()) {
sd->mCloneItems.removeOne(this);
}
- delete d->mFrontCachePixmap;
- delete d->mBackCachePixmap;
}
/*!
@@ -774,11 +779,7 @@
{
switch (e->type()) {
case QEvent::GraphicsSceneResize: {
- Q_D(HbAbstractViewItem );
- d->releasePixmaps();
-
- updatePixmapCache();
-
+ Q_D(HbAbstractViewItem );
QGraphicsSceneResizeEvent *resizeEvent = static_cast<QGraphicsSceneResizeEvent *>(e);
if (d->mFrontPixmapPainter) {
@@ -852,27 +853,22 @@
QVariant HbAbstractViewItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
switch (change) {
- case ItemTransformHasChanged: {
- Q_D(HbAbstractViewItem);
-
+ case ItemTransformHasChanged: {
QGraphicsLayoutItem *parentLayoutItem = this->parentLayoutItem();
if (parentLayoutItem && parentLayoutItem->isLayout()) {
QGraphicsLayout *parentLayout = static_cast<QGraphicsLayout *>(parentLayoutItem);
parentLayout->invalidate();
}
- d->releasePixmaps();
-
- updatePixmapCache();
break;
}
- case ItemEnabledHasChanged: {
+ case ItemEnabledHasChanged: {
updateChildItems();
break;
}
- case ItemVisibleHasChanged: {
+ case ItemVisibleHasChanged: {
Q_D(HbAbstractViewItem);
if (!value.toBool() && d->usePixmapCache()) {
- d->setChildFlags(0, false);
+ d->setChildFlagRecursively(false);
d->releasePixmaps();
d->mResetPixmapCache = true;
}
@@ -885,8 +881,8 @@
}
break;
}
- default:
- break;
+ default:
+ break;
}
return HbWidget::itemChange(change, value);
@@ -956,7 +952,7 @@
if (d->mFocusItem) {
HbStylePrivate::updatePrimitive(d->mFocusItem, HbStylePrivate::P_ItemViewItem_focus, d->mSharedData->mStyleOption);
}
-
+
updatePixmapCache();
}
@@ -1242,10 +1238,6 @@
return;
}
- if (d->polished && !d->repolishOutstanding && !d->mRepolishRequested) {
- return;
- }
-
if (sd->mItemView) {
setProperty("layoutName", sd->mItemView->layoutName());
}
@@ -1348,7 +1340,6 @@
Q_UNUSED(widget);
Q_D(HbAbstractViewItem);
-
if (!d->mInPaintItems) {
bool usePixmapCache = d->usePixmapCache();
@@ -1356,12 +1347,16 @@
QRectF deviceBounds = painter->worldTransform().mapRect(boundingRect());
QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1);
+ if (deviceRect.size() != d->mFrontPixmapPainter->pixmapSize()) {
+ d->mResetPixmapCache = true;
+ d->releasePixmaps();
+ }
+
if (d->mResetPixmapCache) {
- if (!d->mFrontCachePixmap) {
- d->setChildFlags(0, true);
-
- d->mFrontCachePixmap = new QPixmap(deviceRect.size());
- d->mFrontPixmapPainter->setPixmap(d->mFrontCachePixmap);
+ if (!d->mFrontPixmapPainter->pixmap()) {
+ d->setChildFlagRecursively(true);
+ QPixmap *pixmap = new QPixmap(deviceRect.size());
+ d->mFrontPixmapPainter->setPixmap(pixmap);
}
// Construct an item-to-pixmap transform.
@@ -1370,14 +1365,14 @@
if (!p.isNull())
itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y());
- d->updatePixmap(d->mFrontCachePixmap, painter, itemToPixmap, option, d->mNonCachableItem, 0);
+ d->updatePixmap(d->mFrontPixmapPainter->pixmap(), painter, itemToPixmap, option, d->mNonCachableItem, 0);
if (d->mNonCachableItem) {
- if (!d->mBackCachePixmap) {
- d->mBackCachePixmap = new QPixmap(deviceRect.size());
+ if (!d->mBackPixmapPainter->pixmap()) {
+ QPixmap *pixmap = new QPixmap(deviceRect.size());
+ d->mBackPixmapPainter->setPixmap(pixmap);
}
- d->mBackPixmapPainter->setPixmap(d->mBackCachePixmap);
- d->updatePixmap(d->mBackCachePixmap, painter, itemToPixmap, option, 0, d->mNonCachableItem);
+ d->updatePixmap(d->mBackPixmapPainter->pixmap(), painter, itemToPixmap, option, 0, d->mNonCachableItem);
} else if (d->mBackPixmapPainter) {
d->mBackPixmapPainter->setPixmap(0);
}
@@ -1393,9 +1388,8 @@
d->mFrontPixmapPainter->setDeviceRect(deviceRect);
}
} else {
- if (d->mFrontCachePixmap) {
- d->setChildFlags(0, false);
-
+ if (d->mFrontPixmapPainter->pixmap()) {
+ d->setChildFlagRecursively(false);
d->releasePixmaps();
}
}
@@ -1412,7 +1406,7 @@
{
Q_D(HbAbstractViewItem);
- if (d->usePixmapCache()) {
+ if (!d->mResetPixmapCache && d->usePixmapCache()) {
d->mResetPixmapCache = true;
update();
}