From 45f39ab5b373189392b5effe94a2c7c1deb549e8 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 16 Dec 2024 16:59:32 +0100 Subject: [PATCH] QDrawUtil: Cleanup qDrawPlainRoundedRect/qDrawPlainRect Fix the style and use PainterStateGuard instead own save/restore functionality because PainterStateGuard is already available and used in those functions. Task-number: QTBUG-132187 Change-Id: Ie454b6cffe03444d88f13d15adb19a7e7783a493 Reviewed-by: Volker Hilsheimer (cherry picked from commit 1fb86f1f84bb56dab60bc15604c09a14157d6f10) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit f349040b39f6c560b2ccb17510fd6cc2c49ab6b9) --- src/widgets/styles/qdrawutil.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index 5bdbdb11395..192ea6d25c5 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -572,18 +572,19 @@ void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, */ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, - int lineWidth, const QBrush *fill) + int lineWidth, const QBrush *fill) { if (w == 0 || h == 0) return; if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) { qWarning("qDrawPlainRect: Invalid parameters"); + return; } PainterStateGuard painterGuard(p); + painterGuard.save(); const qreal devicePixelRatio = p->device()->devicePixelRatio(); if (!qFuzzyCompare(devicePixelRatio, qreal(1))) { - painterGuard.save(); const qreal inverseScale = qreal(1) / devicePixelRatio; p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); @@ -594,8 +595,6 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, p->translate(0.5, 0.5); } - QPen oldPen = p->pen(); - QBrush oldBrush = p->brush(); p->setPen(c); p->setBrush(Qt::NoBrush); for (int i=0; isetBrush(*fill); p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2); } - p->setPen(oldPen); - p->setBrush(oldBrush); } /*! @@ -638,19 +635,20 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, // ### Qt7: Pass QPen instead of QColor for frame drawing void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h, - qreal rx, qreal ry, const QColor &c, - int lineWidth, const QBrush *fill) + qreal rx, qreal ry, const QColor &c, + int lineWidth, const QBrush *fill) { if (w == 0 || h == 0) return; if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) { qWarning("qDrawPlainRect: Invalid parameters"); + return; } PainterStateGuard painterGuard(p); + painterGuard.save(); const qreal devicePixelRatio = p->device()->devicePixelRatio(); if (!qFuzzyCompare(devicePixelRatio, qreal(1))) { - painterGuard.save(); const qreal inverseScale = qreal(1) / devicePixelRatio; p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); @@ -661,7 +659,6 @@ void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h, p->translate(0.5, 0.5); } - p->save(); p->setPen(c); p->setBrush(Qt::NoBrush); for (int i=0; isetBrush(*fill); p->drawRoundedRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, rx, ry); } - p->restore(); } /*****************************************************************************