From 3574eed7f97e126459cdbd0ca63690e059f1e8d0 Mon Sep 17 00:00:00 2001 From: Louai Al-Khanji Date: Mon, 18 Aug 2014 09:44:07 +0300 Subject: Save and restore changed QPainter properties Change-Id: I67c604aa43d03207fd18fb41f54b445bd6bb34d9 Reviewed-by: Lars Knoll --- softwarecontext/glyphnode.cpp | 6 ++++++ softwarecontext/imagenode.cpp | 9 +++++++-- softwarecontext/rectanglenode.cpp | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/softwarecontext/glyphnode.cpp b/softwarecontext/glyphnode.cpp index eae8b626cb..ecb8b3f6dc 100644 --- a/softwarecontext/glyphnode.cpp +++ b/softwarecontext/glyphnode.cpp @@ -64,6 +64,9 @@ void GlyphNode::update() void GlyphNode::paint(QPainter *painter) { + QPen originalPen = painter->pen(); + QBrush originalBrush = painter->brush(); + painter->setBrush(QBrush()); QPointF pos = m_position - QPointF(0, m_glyphRun.rawFont().ascent()); @@ -88,4 +91,7 @@ void GlyphNode::paint(QPainter *painter) painter->setPen(m_color); painter->drawGlyphRun(pos, m_glyphRun); + + painter->setPen(originalPen); + painter->setBrush(originalBrush); } diff --git a/softwarecontext/imagenode.cpp b/softwarecontext/imagenode.cpp index 7718831b65..519f5dc6f6 100644 --- a/softwarecontext/imagenode.cpp +++ b/softwarecontext/imagenode.cpp @@ -380,6 +380,7 @@ static Qt::TileRule getTileRule(qreal factor) void ImageNode::paint(QPainter *painter) { + QPainter::RenderHints originalHints = painter->renderHints(); painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); const QPixmap &pm = pixmap(); @@ -395,7 +396,8 @@ void ImageNode::paint(QPainter *painter) } if (m_tileHorizontal || m_tileVertical) { - painter->save(); + QMatrix originalMatrix = painter->matrix(); + qreal sx = m_targetRect.width()/(m_subSourceRect.width()*pm.width()); qreal sy = m_targetRect.height()/(m_subSourceRect.height()*pm.height()); QMatrix transform(sx, 0, 0, sy, 0, 0); @@ -403,12 +405,15 @@ void ImageNode::paint(QPainter *painter) painter->drawTiledPixmap(QRectF(m_targetRect.x()/sx, m_targetRect.y()/sy, m_targetRect.width()/sx, m_targetRect.height()/sy), pm, QPointF(m_subSourceRect.left()*pm.width(), m_subSourceRect.top()*pm.height())); - painter->restore(); + + painter->setMatrix(originalMatrix); } else { QRectF sr(m_subSourceRect.left()*pm.width(), m_subSourceRect.top()*pm.height(), m_subSourceRect.width()*pm.width(), m_subSourceRect.height()*pm.height()); painter->drawPixmap(m_targetRect, pm, sr); } + + painter->setRenderHints(originalHints); } const QPixmap &ImageNode::pixmap() const diff --git a/softwarecontext/rectanglenode.cpp b/softwarecontext/rectanglenode.cpp index 8e3548cf23..a950b900c0 100644 --- a/softwarecontext/rectanglenode.cpp +++ b/softwarecontext/rectanglenode.cpp @@ -82,6 +82,9 @@ void RectangleNode::update() void RectangleNode::paint(QPainter *painter) { + QPen originalPen = painter->pen(); + QBrush originalBrush = painter->brush(); + painter->setPen(m_pen); painter->setBrush(m_brush); if (m_radius) @@ -90,4 +93,7 @@ void RectangleNode::paint(QPainter *painter) painter->fillRect(m_rect, m_color); else painter->drawRect(m_rect); + + painter->setPen(originalPen); + painter->setBrush(originalBrush); } -- cgit v1.2.3