Skip to content

Commit

Permalink
QDrawUtil: Cleanup qDrawPlainRoundedRect/qDrawPlainRect
Browse files Browse the repository at this point in the history
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 <volker.hilsheimer@qt.io>
(cherry picked from commit 1fb86f1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit f349040)
  • Loading branch information
chehrlic committed Dec 21, 2024
1 parent 7ce5b4f commit 45f39ab
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/widgets/styles/qdrawutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; i<lineWidth; i++)
Expand All @@ -605,8 +604,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);
}

/*!
Expand Down Expand Up @@ -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);
Expand All @@ -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; i<lineWidth; i++) {
Expand All @@ -674,7 +671,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();
}

/*****************************************************************************
Expand Down

0 comments on commit 45f39ab

Please sign in to comment.