Take the size and the icon size for MDI buttons from a style

This way they can be DPI-dependent.

Change-Id: I117c337aaa3e2bf6fb85cb3b04bbbccd9db41070
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Alexander Volkov 2014-12-27 18:10:34 +03:00
parent c736497483
commit a5c6bad4f0
5 changed files with 39 additions and 22 deletions

View File

@ -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<const QStyleOptionComplex *>(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

View File

@ -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<const QStyleOptionComplex *>(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;

View File

@ -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.

View File

@ -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
};

View File

@ -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);
}