summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouai Al-Khanji <louai.al-khanji@digia.com>2014-08-18 09:44:07 +0300
committerLars Knoll <lars.knoll@digia.com>2014-08-18 10:14:15 +0300
commit3574eed7f97e126459cdbd0ca63690e059f1e8d0 (patch)
tree88c0284b37ff13dad585b2b7baa218c09734831e
parent4cf478605e9d90d0bfaeec1f8e78cfdc71be402b (diff)
Save and restore changed QPainter properties
Change-Id: I67c604aa43d03207fd18fb41f54b445bd6bb34d9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--softwarecontext/glyphnode.cpp6
-rw-r--r--softwarecontext/imagenode.cpp9
-rw-r--r--softwarecontext/rectanglenode.cpp6
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);
}