summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <[email protected]>2024-12-16 16:59:32 +0100
committerChristian Ehrlicher <[email protected]>2024-12-20 14:15:58 +0100
commit1fb86f1f84bb56dab60bc15604c09a14157d6f10 (patch)
tree6e64bafba3760bdae158760c1f7398ef92ef2a72
parentb957dfc6e06deed64e20e8eee5d2164250b28b95 (diff)
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. Pick-to: 6.9 6.8 Task-number: QTBUG-132187 Change-Id: Ie454b6cffe03444d88f13d15adb19a7e7783a493 Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/widgets/styles/qdrawutil.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp
index 14fb3a41678..e0d7cbb42c4 100644
--- a/src/widgets/styles/qdrawutil.cpp
+++ b/src/widgets/styles/qdrawutil.cpp
@@ -573,18 +573,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 = QStyleHelper::getDpr(p);
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
- painterGuard.save();
const qreal inverseScale = qreal(1) / devicePixelRatio;
p->scale(inverseScale, inverseScale);
x = qRound(devicePixelRatio * x);
@@ -595,8 +596,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; i<lineWidth; i++)
@@ -606,8 +605,6 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c,
p->setBrush(*fill);
p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2);
}
- p->setPen(oldPen);
- p->setBrush(oldBrush);
}
/*!
@@ -639,19 +636,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 = QStyleHelper::getDpr(p);
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
- painterGuard.save();
const qreal inverseScale = qreal(1) / devicePixelRatio;
p->scale(inverseScale, inverseScale);
x = qRound(devicePixelRatio * x);
@@ -662,7 +660,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; i<lineWidth; i++) {
@@ -675,7 +672,6 @@ void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h,
p->setBrush(*fill);
p->drawRoundedRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, rx, ry);
}
- p->restore();
}
/*****************************************************************************