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.8 Task-number: QTBUG-132187 Change-Id: Ie454b6cffe03444d88f13d15adb19a7e7783a493 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 1fb86f1f84bb56dab60bc15604c09a14157d6f10) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
319b31a5a2
commit
f349040b39
@ -579,12 +579,13 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c,
|
|||||||
return;
|
return;
|
||||||
if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
|
if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
|
||||||
qWarning("qDrawPlainRect: Invalid parameters");
|
qWarning("qDrawPlainRect: Invalid parameters");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PainterStateGuard painterGuard(p);
|
PainterStateGuard painterGuard(p);
|
||||||
|
painterGuard.save();
|
||||||
const qreal devicePixelRatio = QStyleHelper::getDpr(p);
|
const qreal devicePixelRatio = QStyleHelper::getDpr(p);
|
||||||
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
|
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
|
||||||
painterGuard.save();
|
|
||||||
const qreal inverseScale = qreal(1) / devicePixelRatio;
|
const qreal inverseScale = qreal(1) / devicePixelRatio;
|
||||||
p->scale(inverseScale, inverseScale);
|
p->scale(inverseScale, inverseScale);
|
||||||
x = qRound(devicePixelRatio * x);
|
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);
|
p->translate(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPen oldPen = p->pen();
|
|
||||||
QBrush oldBrush = p->brush();
|
|
||||||
p->setPen(c);
|
p->setPen(c);
|
||||||
p->setBrush(Qt::NoBrush);
|
p->setBrush(Qt::NoBrush);
|
||||||
for (int i=0; i<lineWidth; i++)
|
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->setBrush(*fill);
|
||||||
p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2);
|
p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2);
|
||||||
}
|
}
|
||||||
p->setPen(oldPen);
|
|
||||||
p->setBrush(oldBrush);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -646,12 +643,13 @@ void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h,
|
|||||||
return;
|
return;
|
||||||
if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
|
if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
|
||||||
qWarning("qDrawPlainRect: Invalid parameters");
|
qWarning("qDrawPlainRect: Invalid parameters");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PainterStateGuard painterGuard(p);
|
PainterStateGuard painterGuard(p);
|
||||||
|
painterGuard.save();
|
||||||
const qreal devicePixelRatio = QStyleHelper::getDpr(p);
|
const qreal devicePixelRatio = QStyleHelper::getDpr(p);
|
||||||
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
|
if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
|
||||||
painterGuard.save();
|
|
||||||
const qreal inverseScale = qreal(1) / devicePixelRatio;
|
const qreal inverseScale = qreal(1) / devicePixelRatio;
|
||||||
p->scale(inverseScale, inverseScale);
|
p->scale(inverseScale, inverseScale);
|
||||||
x = qRound(devicePixelRatio * x);
|
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->translate(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->save();
|
|
||||||
p->setPen(c);
|
p->setPen(c);
|
||||||
p->setBrush(Qt::NoBrush);
|
p->setBrush(Qt::NoBrush);
|
||||||
for (int i=0; i<lineWidth; i++) {
|
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->setBrush(*fill);
|
||||||
p->drawRoundedRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, rx, ry);
|
p->drawRoundedRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, rx, ry);
|
||||||
}
|
}
|
||||||
p->restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user