summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-06-02 18:25:49 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-09 07:31:19 (GMT)
commitbdb0c0fc98fc1998f6a7ee21be29513534be3713 (patch)
tree4b68e40cb799e04b083d1747ae4e8c8bbd8f631f /src
parentde776b777bd9c1884bda4049d8f75020d6092ab7 (diff)
downloadQt-bdb0c0fc98fc1998f6a7ee21be29513534be3713.zip
Qt-bdb0c0fc98fc1998f6a7ee21be29513534be3713.tar.gz
Qt-bdb0c0fc98fc1998f6a7ee21be29513534be3713.tar.bz2
Optimise effectiveOpacity and make it inlineable.
This cut's off some cycles in discardUpdateRequest() which is called from most places when something in the items changes.
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp16
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h26
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp4
3 files changed, 28 insertions, 18 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index ca39713..b913d89 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -2028,21 +2028,7 @@ qreal QGraphicsItem::opacity() const
*/
qreal QGraphicsItem::effectiveOpacity() const
{
- if (!d_ptr->parent)
- return d_ptr->opacity;
-
- int myFlags = d_ptr->flags;
- int parentFlags = d_ptr->parent ? d_ptr->parent->d_ptr->flags : 0;
-
- // If I have a parent, and I don't ignore my parent's opacity, and my
- // parent propagates to me, then combine my local opacity with my parent's
- // effective opacity into my effective opacity.
- if (!(myFlags & QGraphicsItem::ItemIgnoresParentOpacity)
- && !(parentFlags & QGraphicsItem::ItemDoesntPropagateOpacityToChildren)) {
- return d_ptr->opacity * d_ptr->parent->effectiveOpacity();
- }
-
- return d_ptr->opacity;
+ return d_ptr->effectiveOpacity();
}
/*!
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 61f6496..d92d76e 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -277,7 +277,31 @@ public:
void updateCachedClipPathFromSetPosHelper(const QPointF &newPos);
inline bool isFullyTransparent() const
- { return q_func()->effectiveOpacity() < .001; }
+ { return effectiveOpacity() < .001; }
+
+ inline qreal effectiveOpacity() const {
+ if (!parent)
+ return opacity;
+
+ qreal o = opacity;
+ QGraphicsItem *p = parent;
+ int myFlags = flags;
+ while (p) {
+ int parentFlags = p->d_ptr->flags;
+
+ // If I have a parent, and I don't ignore my parent's opacity, and my
+ // parent propagates to me, then combine my local opacity with my parent's
+ // effective opacity into my effective opacity.
+ if ((myFlags & QGraphicsItem::ItemIgnoresParentOpacity)
+ || (parentFlags & QGraphicsItem::ItemDoesntPropagateOpacityToChildren))
+ break;
+
+ o *= parent->d_ptr->opacity;
+ p = p->d_ptr->parent;
+ myFlags = parentFlags;
+ }
+ return o;
+ }
inline bool childrenCombineOpacity() const
{
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 73d6a93..25ac279 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -419,7 +419,7 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::estimateItemsInRect(const QRectF &
if (QGraphicsItem *item = unindexedItems.at(i)) {
if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
continue;
- if (item->d_ptr->visible && item->effectiveOpacity() > qreal(0.0))
+ if (item->d_ptr->visible && !item->d_ptr->isFullyTransparent())
itemsInRect << item;
}
}
@@ -427,7 +427,7 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::estimateItemsInRect(const QRectF &
if (QGraphicsItem *item = indexedItems.at(i)) {
if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
continue;
- if (item->d_ptr->visible && item->effectiveOpacity() > qreal(0.0))
+ if (item->d_ptr->visible && item->d_ptr->isFullyTransparent())
itemsInRect << item;
}
}