Windows: Fix MDI child window titles in High-DPI displays

This change improves the appearance of MDI child windows in a High-DPI
display for applications using the WindowsVista style, with the
Qt::AA_EnableHighDpiScaling attribute set.

Task-number: QTBUG-64708
Change-Id: I5e9fbd23809b440ffd33e4948c83d115cc6e1910
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Andre de la Rocha 2018-04-11 13:13:58 +02:00
parent 15ff5cfedd
commit 0b9a301e89
2 changed files with 24 additions and 20 deletions

View File

@ -2171,12 +2171,12 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
if (!buttonVisible(subControl, tb))
return rect;
const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
const bool isToolTitle = false;
const int height = tb->rect.height();
const int width = tb->rect.width();
const int buttonWidth =
qRound(qreal(GetSystemMetrics(SM_CXSIZE)) * QWindowsStylePrivate::nativeMetricScaleFactor(widget)
- QStyleHelper::dpiScaled(4));
qRound(qreal(GetSystemMetrics(SM_CXSIZE)) * factor - QStyleHelper::dpiScaled(4));
const int frameWidth = proxy()->pixelMetric(PM_MdiSubWindowFrameWidth, option, widget);
const bool sysmenuHint = (tb->titleBarFlags & Qt::WindowSystemMenuHint) != 0;
@ -2190,31 +2190,31 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt
rect = QRect(frameWidth, 0, width - (buttonWidth + frameWidth + 10), height);
if (isToolTitle) {
if (sysmenuHint) {
rect.adjust(0, 0, -buttonWidth - 3, 0);
rect.adjust(0, 0, int(-buttonWidth - 3 * factor), 0);
}
if (minimizeHint || maximizeHint)
rect.adjust(0, 0, -buttonWidth - 2, 0);
rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0);
} else {
if (sysmenuHint) {
const int leftOffset = height - 8;
rect.adjust(leftOffset, 0, 0, 4);
const int leftOffset = int(height - 8 * factor);
rect.adjust(leftOffset, 0, 0, int(4 * factor));
}
if (minimizeHint)
rect.adjust(0, 0, -buttonWidth - 2, 0);
rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0);
if (maximizeHint)
rect.adjust(0, 0, -buttonWidth - 2, 0);
rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0);
if (contextHint)
rect.adjust(0, 0, -buttonWidth - 2, 0);
rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0);
if (shadeHint)
rect.adjust(0, 0, -buttonWidth - 2, 0);
rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0);
}
rect.translate(0, 2);
rect.translate(0, int(2 * factor));
rect = visualRect(option->direction, option->rect, rect);
break;
case SC_TitleBarSysMenu:
{
const int controlTop = 6;
const int controlHeight = height - controlTop - 3;
const int controlTop = int(6 * factor);
const int controlHeight = int(height - controlTop - 3 * factor);
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
QSize iconSize = tb->icon.actualSize(QSize(iconExtent, iconExtent));
if (tb->icon.isNull())
@ -2222,7 +2222,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt
int hPad = (controlHeight - iconSize.height())/2;
int vPad = (controlHeight - iconSize.width())/2;
rect = QRect(frameWidth + hPad, controlTop + vPad, iconSize.width(), iconSize.height());
rect.translate(0, 3);
rect.translate(0, int(3 * factor));
rect = visualRect(option->direction, option->rect, rect);
}
break;

View File

@ -492,7 +492,8 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData)
QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData)
{
HRGN hRgn = 0;
RECT rect = themeData.toRECT(themeData.rect);
const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget);
RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor));
if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId,
themeData.stateId, &rect, &hRgn))) {
return QRegion();
@ -521,7 +522,7 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData)
RECT *r = reinterpret_cast<RECT*>(rd->Buffer);
for (uint i = 0; i < rd->rdh.nCount; ++i) {
QRect rect;
rect.setCoords(r->left, r->top, r->right - 1, r->bottom - 1);
rect.setCoords(int(r->left * factor), int(r->top * factor), int((r->right - 1) * factor), int((r->bottom - 1) * factor));
++r;
region |= rect;
}
@ -1754,9 +1755,9 @@ case PE_Frame:
else
stateId = FS_INACTIVE;
int fwidth = frm->lineWidth + frm->midLineWidth;
int fwidth = int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
XPThemeData theme(0, p, themeNumber, 0, stateId);
XPThemeData theme(widget, p, themeNumber, 0, stateId);
if (!theme.isValid())
break;
@ -2947,6 +2948,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
{
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option))
{
const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
bool isActive = tb->titleBarState & QStyle::State_Active;
XPThemeData theme(widget, p, QWindowsXPStylePrivate::WindowTheme);
if (sub & SC_TitleBarLabel) {
@ -2973,13 +2975,15 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
p->setPen(textShadow);
p->drawText(ir.x() + 3, ir.y() + 2, ir.width() - 1, ir.height(),
p->drawText(int(ir.x() + 3 * factor), int(ir.y() + 2 * factor),
int(ir.width() - 1 * factor), ir.height(),
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
}
COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
p->setPen(textColor);
p->drawText(ir.x() + 2, ir.y() + 1, ir.width() - 2, ir.height(),
p->drawText(int(ir.x() + 2 * factor), int(ir.y() + 1 * factor),
int(ir.width() - 2 * factor), ir.height(),
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
}
if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {