summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2009-12-02 14:31:09 (GMT)
committerYoann Lopes <yoann.lopes@nokia.com>2009-12-02 14:31:09 (GMT)
commitccde429536ba29dceb1576b6b981a812b0b846fc (patch)
tree3bdf0ab86eb7f9c074c9cf2dfb9b93a2b4e368df
parent25023911295c201758faaa2c800b2388ddf1e0b0 (diff)
downloadQt-ccde429536ba29dceb1576b6b981a812b0b846fc.zip
Qt-ccde429536ba29dceb1576b6b981a812b0b846fc.tar.gz
Qt-ccde429536ba29dceb1576b6b981a812b0b846fc.tar.bz2
Fixes transformation problems with QGraphicsProxyWidget.
In the paintEvent of the widget used in a QGraphicsProxyWidget, the worldMatrix was wrongly used by the painter instead of the deviceMatrix. Similar problem in the WindowsXP Style, the worldMatrix was used instead of the deviceMatrix for determining if the widget is transformed (reviewed by eblomfel). Task-number: QTBUG-5939 Reviewed-by: bnilsen Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
-rw-r--r--src/gui/painting/qpainter.cpp2
-rw-r--r--src/gui/styles/qwindowsxpstyle.cpp3
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp58
3 files changed, 59 insertions, 4 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 443c9c5..30f8c9e 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -284,7 +284,7 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
// Update matrix.
if (q->d_ptr->state->WxF) {
- q->d_ptr->state->redirectionMatrix *= q->d_ptr->state->worldMatrix;
+ q->d_ptr->state->redirectionMatrix = q->d_ptr->state->matrix;
q->d_ptr->state->redirectionMatrix.translate(-offset.x(), -offset.y());
q->d_ptr->state->worldMatrix = QTransform();
q->d_ptr->state->WxF = false;
diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp
index fe7f5d7..0767083 100644
--- a/src/gui/styles/qwindowsxpstyle.cpp
+++ b/src/gui/styles/qwindowsxpstyle.cpp
@@ -623,8 +623,7 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
painter->save();
- QMatrix m = painter->matrix();
- bool complexXForm = m.m11() != 1.0 || m.m22() != 1.0 || m.m12() != 0.0 || m.m21() != 0.0;
+ bool complexXForm = painter->deviceTransform().type() > QTransform::TxTranslate;
bool translucentToplevel = false;
QPaintDevice *pdev = painter->device();
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index 8b71349..67d1972 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -41,7 +41,7 @@
#include <QtTest/QtTest>
-
+#include "../../shared/util.h"
#include <qpainter.h>
#include <qapplication.h>
@@ -67,6 +67,11 @@
#include <qqueue.h>
+#include <qgraphicsview.h>
+#include <qgraphicsscene.h>
+#include <qgraphicsproxywidget.h>
+#include <qlayout.h>
+
#if defined(Q_OS_SYMBIAN)
# define SRCDIR "."
#endif
@@ -244,6 +249,8 @@ private slots:
void setPenColorOnImage();
void setPenColorOnPixmap();
+ void QTBUG5939_attachPainterPrivate();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -4404,6 +4411,55 @@ void tst_QPainter::setPenColorOnPixmap()
setPenColor(p);
}
+class TestProxy : public QGraphicsProxyWidget
+{
+public:
+ TestProxy() : QGraphicsProxyWidget() {}
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ {
+ QGraphicsProxyWidget::paint(painter, option, widget);
+ deviceTransform = painter->deviceTransform();
+ }
+ QTransform deviceTransform;
+};
+
+class TestWidget : public QWidget
+{
+Q_OBJECT
+public:
+ TestWidget() : QWidget(), painted(false) {}
+ void paintEvent(QPaintEvent *)
+ {
+ QPainter p(this);
+ deviceTransform = p.deviceTransform();
+ worldTransform = p.worldTransform();
+ painted = true;
+ }
+ QTransform deviceTransform;
+ QTransform worldTransform;
+ bool painted;
+};
+
+void tst_QPainter::QTBUG5939_attachPainterPrivate()
+{
+ QWidget *w = new QWidget();
+ QGraphicsScene *scene = new QGraphicsScene();
+ QGraphicsView *view = new QGraphicsView(scene, w);
+ view->move(50 ,50);
+ TestProxy *proxy = new TestProxy();
+ TestWidget *widget = new TestWidget();
+ proxy->setWidget(widget);
+ scene->addItem(proxy);
+ proxy->rotate(45);
+ w->resize(scene->sceneRect().size().toSize());
+
+ w->show();
+ QTRY_VERIFY(widget->painted);
+
+ QVERIFY(widget->worldTransform.isIdentity());
+ QCOMPARE(widget->deviceTransform, proxy->deviceTransform);
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"