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 +++++++++++++++++++-------- src/widgets/styles/qfusionstyle.cpp | 16 ++++------------ src/widgets/styles/qstyle.cpp | 5 +++++ src/widgets/styles/qstyle.h | 3 +++ src/widgets/widgets/qmdisubwindow.cpp | 10 ++++++++-- 5 files changed, 39 insertions(+), 22 deletions(-) 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 diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 5b6e47e2c6..a9cea0e2ab 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3102,6 +3102,9 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co case PM_DockWidgetTitleBarButtonMargin: val = 2; break; + case PM_TitleBarButtonSize: + val = 19; + break; case PM_MaximumDragDistance: return -1; // Do not dpi-scale because the value is magic case PM_TabCloseIndicatorWidth: @@ -3225,18 +3228,7 @@ QSize QFusionStyle::sizeFromContents(ContentsType type, const QStyleOption *opti newSize += QSize(4, 4); break; case CT_MdiControls: - if (const QStyleOptionComplex *styleOpt = qstyleoption_cast(option)) { - int width = 0; - if (styleOpt->subControls & SC_MdiMinButton) - width += 19 + 1; - if (styleOpt->subControls & SC_MdiNormalButton) - width += 19 + 1; - if (styleOpt->subControls & SC_MdiCloseButton) - width += 19 + 1; - newSize = QSize(width, 19); - } else { - newSize = QSize(60, 19); - } + newSize -= QSize(1, 0); break; default: break; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 103c49496e..16a11e6029 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1494,6 +1494,11 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value PM_HeaderDefaultSectionSizeVertical The default size of sections in a vertical header. This enum value has been introduced in Qt 5.5. + \value PM_TitleBarButtonIconSize The size of button icons on a title bar. + This enum value has been introduced in Qt 5.8. + \value PM_TitleBarButtonSize The size of buttons on a title bar. + This enum value has been introduced in Qt 5.8. + \value PM_CustomBase Base value for custom pixel metrics. Custom values must be greater than this value. diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 0f1259160e..0c8805e7a5 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -570,6 +570,9 @@ public: PM_HeaderDefaultSectionSizeHorizontal, PM_HeaderDefaultSectionSizeVertical, + PM_TitleBarButtonIconSize, + PM_TitleBarButtonSize, + // do not add any values below/greater than this PM_CustomBase = 0xf0000000 }; diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index bc364b1a26..afe87c6af9 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -412,6 +412,10 @@ bool ControlLabel::event(QEvent *event) { if (event->type() == QEvent::WindowIconChange) updateWindowIcon(); + else if (event->type() == QEvent::StyleChange) { + updateWindowIcon(); + setFixedSize(label.size()); + } #ifndef QT_NO_TOOLTIP else if (event->type() == QEvent::ToolTip) { QStyleOptionTitleBar options; @@ -480,7 +484,8 @@ void ControlLabel::updateWindowIcon() QIcon menuIcon = windowIcon(); if (menuIcon.isNull()) menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, parentWidget()); - label = menuIcon.pixmap(16, 16); + const int iconSize = style()->pixelMetric(QStyle::PM_TitleBarButtonIconSize, 0, parentWidget()); + label = menuIcon.pixmap(iconSize); update(); } @@ -556,7 +561,8 @@ QSize ControllerWidget::sizeHint() const ensurePolished(); QStyleOptionComplex opt; initStyleOption(&opt); - QSize size(48, 16); + const int buttonSize = style()->pixelMetric(QStyle::PM_TitleBarButtonSize, &opt, mdiArea); + QSize size(3 * buttonSize, buttonSize); return style()->sizeFromContents(QStyle::CT_MdiControls, &opt, size, mdiArea); } -- cgit v1.2.3