QStyle/QWidget: Avoid repetitive invocation of QStyleHelper::dpiScaled()

Store the result of QStyleHelper::dpiScaled() or functions dependent on it
in a variable, preparing the addition of a DPI parameter.

Task-number: QTBUG-45055
Change-Id: Ic70d65b590793c29a4b1f7a7a5312dd169517fc5
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Friedemann Kleint 2019-04-05 12:51:10 +02:00
parent 58b4e07369
commit 6accc102d3
4 changed files with 23 additions and 14 deletions

View File

@ -1486,11 +1486,13 @@ case PE_Frame:
// Inner white border // Inner white border
p->setPen(QPen(option->palette.base().color(), 0)); p->setPen(QPen(option->palette.base().color(), 0));
p->drawRect(QRectF(option->rect).adjusted(QStyleHelper::dpiScaled(0.5), QStyleHelper::dpiScaled(0.5), const auto topLevelAdjustment = QStyleHelper::dpiScaled(0.5);
QStyleHelper::dpiScaled(-1), QStyleHelper::dpiScaled(-1))); const auto bottomRightAdjustment = QStyleHelper::dpiScaled(-1);
p->drawRect(QRectF(option->rect).adjusted(topLevelAdjustment, topLevelAdjustment,
bottomRightAdjustment, bottomRightAdjustment));
// Outer dark border // Outer dark border
p->setPen(QPen(bordercolor, 0)); p->setPen(QPen(bordercolor, 0));
p->drawRect(QRectF(option->rect).adjusted(0, 0, QStyleHelper::dpiScaled(-0.5), QStyleHelper::dpiScaled(-0.5))); p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
p->setPen(oldPen); p->setPen(oldPen);
return; return;
} else if (fillType == BT_NONE) { } else if (fillType == BT_NONE) {
@ -3534,9 +3536,12 @@ QRect QWindowsXPStyle::subControlRect(ComplexControl cc, const QStyleOptionCompl
qRound(QStyleHelper::dpiScaled(16)), he - qRound(QStyleHelper::dpiScaled(2))); qRound(QStyleHelper::dpiScaled(16)), he - qRound(QStyleHelper::dpiScaled(2)));
break; break;
case SC_ComboBoxEditField: case SC_ComboBoxEditField: {
rect = QRect(x + qRound(QStyleHelper::dpiScaled(2)), y + qRound(QStyleHelper::dpiScaled(2)), const int frame = qRound(QStyleHelper::dpiScaled(2));
wi - qRound(QStyleHelper::dpiScaled(3 + 16)), he - qRound(QStyleHelper::dpiScaled(4))); rect = QRect(x + frame, y + frame,
wi - qRound(QStyleHelper::dpiScaled(3 + 16)),
he - qRound(QStyleHelper::dpiScaled(4)));
}
break; break;
case SC_ComboBoxListBoxPopup: case SC_ComboBoxListBoxPopup:

View File

@ -1595,23 +1595,25 @@ bool QWizardPrivate::handleAeroStyleChange()
bool vistaMargins = false; bool vistaMargins = false;
if (isVistaThemeEnabled()) { if (isVistaThemeEnabled()) {
const int topOffset = vistaHelper->topOffset();
const int topPadding = vistaHelper->topPadding();
if (isVistaThemeEnabled(QVistaHelper::VistaAero)) { if (isVistaThemeEnabled(QVistaHelper::VistaAero)) {
if (isWindow) { if (isWindow) {
vistaHelper->setDWMTitleBar(QVistaHelper::ExtendedTitleBar); vistaHelper->setDWMTitleBar(QVistaHelper::ExtendedTitleBar);
q->installEventFilter(vistaHelper); q->installEventFilter(vistaHelper);
} }
q->setMouseTracking(true); q->setMouseTracking(true);
antiFlickerWidget->move(0, vistaHelper->titleBarSize() + vistaHelper->topOffset()); antiFlickerWidget->move(0, vistaHelper->titleBarSize() + topOffset);
vistaHelper->backButton()->move( vistaHelper->backButton()->move(
0, vistaHelper->topOffset() // ### should ideally work without the '+ 1' 0, topOffset // ### should ideally work without the '+ 1'
- qMin(vistaHelper->topOffset(), vistaHelper->topPadding() + 1)); - qMin(topOffset, topPadding + 1));
vistaMargins = true; vistaMargins = true;
vistaHelper->backButton()->show(); vistaHelper->backButton()->show();
} else { } else {
if (isWindow) if (isWindow)
vistaHelper->setDWMTitleBar(QVistaHelper::NormalTitleBar); vistaHelper->setDWMTitleBar(QVistaHelper::NormalTitleBar);
q->setMouseTracking(true); q->setMouseTracking(true);
antiFlickerWidget->move(0, vistaHelper->topOffset()); antiFlickerWidget->move(0, topOffset);
vistaHelper->backButton()->move(0, -1); // ### should ideally work with (0, 0) vistaHelper->backButton()->move(0, -1); // ### should ideally work with (0, 0)
} }
if (isWindow) if (isWindow)

View File

@ -293,9 +293,9 @@ void QVistaHelper::drawTitleBar(QPainter *painter)
int glowOffset = 0; int glowOffset = 0;
if (vistaState() == VistaAero) { if (vistaState() == VistaAero) {
textHeight += 2 * glowSize();
textWidth += 2 * glowSize();
glowOffset = glowSize(); glowOffset = glowSize();
textHeight += 2 * glowOffset;
textWidth += 2 * glowOffset;
} }
const int titleLeft = (wizard->layoutDirection() == Qt::LeftToRight const int titleLeft = (wizard->layoutDirection() == Qt::LeftToRight

View File

@ -802,8 +802,10 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
QPen oldPen = p->pen(); QPen oldPen = p->pen();
p->setPen(QPen(opt->palette.shadow().color(), 0)); p->setPen(QPen(opt->palette.shadow().color(), 0));
QRectF rect = opt->rect; QRectF rect = opt->rect;
rect.adjust(QStyleHelper::dpiScaled(0.5), QStyleHelper::dpiScaled(0.5), const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5);
QStyleHelper::dpiScaled(-1.5), QStyleHelper::dpiScaled(-1.5)); const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5);
rect.adjust(topLevelAdjustment, topLevelAdjustment,
bottomRightAdjustment, bottomRightAdjustment);
p->drawRect(rect); p->drawRect(rect);
p->setPen(oldPen); p->setPen(oldPen);
break; break;