From a5c6bad4f02d78dff2afca84fd0c9fc12c3eaf49 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Sat, 27 Dec 2014 18:10:34 +0300 Subject: Take the size and the icon size for MDI buttons from a style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way they can be DPI-dependent. Change-Id: I117c337aaa3e2bf6fb85cb3b04bbbccd9db41070 Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/styles/qcommonstyle.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/widgets/styles/qcommonstyle.cpp') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 437becbf70..91d4bcc7ab 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -3724,6 +3724,8 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl btnOpt.state &= ~State_MouseOver; int bsx = 0; int bsy = 0; + const int buttonIconMetric = proxy()->pixelMetric(PM_TitleBarButtonIconSize, &btnOpt, widget); + const QSize buttonIconSize(buttonIconMetric, buttonIconMetric); if (opt->subControls & QStyle::SC_MdiCloseButton) { if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) { btnOpt.state |= State_Sunken; @@ -3738,7 +3740,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(qt_getWindow(widget), QSize(16, 16)); + QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(qt_getWindow(widget), buttonIconSize); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } if (opt->subControls & QStyle::SC_MdiNormalButton) { @@ -3755,7 +3757,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(qt_getWindow(widget), QSize(16, 16)); + QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(qt_getWindow(widget), buttonIconSize); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } if (opt->subControls & QStyle::SC_MdiMinButton) { @@ -3772,7 +3774,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(qt_getWindow(widget), QSize(16, 16)); + QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(qt_getWindow(widget), buttonIconSize); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } } @@ -4393,6 +4395,13 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid } break; } + case PM_TitleBarButtonSize: + ret = int(QStyleHelper::dpiScaled(16.)); + break; + case PM_TitleBarButtonIconSize: + ret = int(QStyleHelper::dpiScaled(16.)); + break; + case PM_ScrollBarSliderMin: ret = int(QStyleHelper::dpiScaled(9.)); break; @@ -4845,16 +4854,18 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, #endif // QT_NO_GROUPBOX case CT_MdiControls: if (const QStyleOptionComplex *styleOpt = qstyleoption_cast(opt)) { + const int buttonSize = proxy()->pixelMetric(PM_TitleBarButtonSize, styleOpt, widget); int width = 1; if (styleOpt->subControls & SC_MdiMinButton) - width += 16 + 1; + width += buttonSize + 1; if (styleOpt->subControls & SC_MdiNormalButton) - width += 16 + 1; + width += buttonSize + 1; if (styleOpt->subControls & SC_MdiCloseButton) - width += 16 + 1; - sz = QSize(width, 16); + width += buttonSize + 1; + sz = QSize(width, buttonSize); } else { - sz = QSize(52, 16); + const int buttonSize = proxy()->pixelMetric(PM_TitleBarButtonSize, opt, widget); + sz = QSize(1 + 3 * (buttonSize + 1), buttonSize); } break; #ifndef QT_NO_ITEMVIEWS -- cgit v1.2.3