summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-10 11:21:48 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-10 11:42:16 (GMT)
commite6efbad527e2b83ee8f4bb5e9fdbed9177ccd3a1 (patch)
tree46a55624c14e475788ecca984dcdf076fb20f06e
parent111eaf464eafbc1130e405373067b70fed089622 (diff)
downloadQt-e6efbad527e2b83ee8f4bb5e9fdbed9177ccd3a1.zip
Qt-e6efbad527e2b83ee8f4bb5e9fdbed9177ccd3a1.tar.gz
Qt-e6efbad527e2b83ee8f4bb5e9fdbed9177ccd3a1.tar.bz2
Wrong opacity set on the painter in QGraphicsEffect::draw.
We have to initialize the painter with the 'effected' item's opacity before calling QGraphicsEffect::draw; otherwise we'll use the previous rendered item's opacity (which is wrong). Reviewed-by: Michael Brasser
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp1
-rw-r--r--tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp25
2 files changed, 25 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 0fd1647..fbd78d9 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -4460,6 +4460,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
painter->setWorldTransform(*transformPtr * *effectTransform);
else
painter->setWorldTransform(*transformPtr);
+ painter->setOpacity(opacity);
item->d_ptr->graphicsEffect->draw(painter, source);
painter->setWorldTransform(restoreTransform);
sourced->info = 0;
diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
index 785b3ff..b36cf73 100644
--- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
+++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
@@ -62,6 +62,7 @@ private slots:
void boundingRectFor();
void boundingRect();
void draw();
+ void opacity();
};
void tst_QGraphicsEffect::initTestCase()
@@ -100,7 +101,7 @@ class CustomEffect : public QGraphicsEffect
public:
CustomEffect()
: QGraphicsEffect(), numRepaints(0), m_margin(10),
- doNothingInDraw(false), m_painter(0), m_styleOption(0), m_source(0)
+ doNothingInDraw(false), m_painter(0), m_styleOption(0), m_source(0), m_opacity(1.0)
{}
QRectF boundingRectFor(const QRectF &rect) const
@@ -113,6 +114,7 @@ public:
m_painter = 0;
m_styleOption = 0;
m_source = 0;
+ m_opacity = 1.0;
}
void setMargin(int margin)
@@ -132,6 +134,7 @@ public:
m_source = source;
m_painter = painter;
m_styleOption = source->styleOption();
+ m_opacity = painter->opacity();
source->draw(painter);
}
@@ -145,6 +148,7 @@ public:
QPainter *m_painter;
const QStyleOption *m_styleOption;
QGraphicsEffectSource *m_source;
+ qreal m_opacity;
};
void tst_QGraphicsEffect::setEnabled()
@@ -342,6 +346,25 @@ void tst_QGraphicsEffect::draw()
delete effect;
}
+void tst_QGraphicsEffect::opacity()
+{
+ // Make sure the painter's opacity is correct in QGraphicsEffect::draw.
+ QGraphicsScene scene;
+ CustomItem *item = new CustomItem(0, 0, 100, 100);
+ item->setOpacity(0.5);
+ CustomEffect *effect = new CustomEffect;
+ item->setGraphicsEffect(effect);
+ scene.addItem(item);
+
+ QGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(100);
+ QCOMPARE(effect->m_opacity, qreal(0.5));
+}
+
QTEST_MAIN(tst_QGraphicsEffect)
#include "tst_qgraphicseffect.moc"