From 020196d16b6c25e16bf80483f08e0007a27eab13 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Fri, 2 Nov 2012 18:35:15 +0100 Subject: [PATCH] Make it possible to use mini and small size on mac without widget We need to add the styleoption when evaluating the small and mini size hints. Change-Id: I00f8709912aa2202caef4dbdeaebb5d67cc9a9b4 Reviewed-by: J-P Nurmi --- src/widgets/styles/qmacstyle_mac.h | 3 ++- src/widgets/styles/qmacstyle_mac.mm | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/widgets/styles/qmacstyle_mac.h b/src/widgets/styles/qmacstyle_mac.h index 60d5ec2..2e4d2ff 100644 --- a/src/widgets/styles/qmacstyle_mac.h +++ b/src/widgets/styles/qmacstyle_mac.h @@ -104,8 +104,9 @@ public: enum WidgetSizePolicy { SizeSmall, SizeLarge, SizeMini, SizeDefault }; + static void setWidgetSizePolicy(const QWidget *w, WidgetSizePolicy policy); - static WidgetSizePolicy widgetSizePolicy(const QWidget *w); + static WidgetSizePolicy widgetSizePolicy(const QWidget *w, const QStyleOption *opt = 0); QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *opt, const QWidget *widget = 0) const; diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index dbd4cf2..0da18c6 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -430,18 +430,13 @@ void drawTabBase(QPainter *p, const QStyleOptionTabBarBaseV2 *tbb, const QWidget static int getControlSize(const QStyleOption *option, const QWidget *widget) { - if (option) { - if (option->state & (QStyle::State_Small | QStyle::State_Mini)) - return (option->state & QStyle::State_Mini) ? QAquaSizeMini : QAquaSizeSmall; - } else if (widget) { - switch (QMacStyle::widgetSizePolicy(widget)) { - case QMacStyle::SizeSmall: - return QAquaSizeSmall; - case QMacStyle::SizeMini: - return QAquaSizeMini; - default: - break; - } + switch (QMacStyle::widgetSizePolicy(widget, option)) { + case QMacStyle::SizeSmall: + return QAquaSizeSmall; + case QMacStyle::SizeMini: + return QAquaSizeMini; + default: + break; } return QAquaSizeLarge; } @@ -1607,7 +1602,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti tdi->reserved = 0; tdi->filler1 = 0; bool isScrollbar = (cc == QStyle::CC_ScrollBar); - switch (aquaSizeConstrain(0, needToRemoveMe)) { + switch (aquaSizeConstrain(slider, needToRemoveMe)) { case QAquaSizeUnknown: case QAquaSizeLarge: if (isScrollbar) @@ -2924,7 +2919,7 @@ void QMacStyle::setWidgetSizePolicy(const QWidget *widget, WidgetSizePolicy poli wadget->setAttribute(Qt::WA_MacMiniSize, policy == SizeMini); } -QMacStyle::WidgetSizePolicy QMacStyle::widgetSizePolicy(const QWidget *widget) +QMacStyle::WidgetSizePolicy QMacStyle::widgetSizePolicy(const QWidget *widget, const QStyleOption *opt) { while (widget) { if (widget->testAttribute(Qt::WA_MacMiniSize)) { @@ -2936,6 +2931,12 @@ QMacStyle::WidgetSizePolicy QMacStyle::widgetSizePolicy(const QWidget *widget) } widget = widget->parentWidget(); } + + if (opt && opt->state & State_Mini) + return SizeMini; + else if (opt && opt->state & State_Small) + return SizeSmall; + return SizeDefault; } @@ -5007,7 +5008,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (cc == CC_ScrollBar) { const int scrollBarLength = (slider->orientation == Qt::Horizontal) ? slider->rect.width() : slider->rect.height(); - const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget); + const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget, opt); if (scrollBarLength < scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy)) tdi.attributes &= ~kThemeTrackShowThumb; if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) @@ -5615,7 +5616,7 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, // exclude them from the hit test. const int scrollBarLength = (sb->orientation == Qt::Horizontal) ? sb->rect.width() : sb->rect.height(); - if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget))) + if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget, opt))) sbi.enableState = kThemeTrackNothingToScroll; sbi.viewsize = sb->pageStep; @@ -6272,7 +6273,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, case CT_ScrollBar : // Make sure that the scroll bar is large enough to display the thumb indicator. if (const QStyleOptionSlider *slider = qstyleoption_cast(opt)) { - const int minimumSize = scrollButtonsCutoffSize(thumbIndicatorCutoff, widgetSizePolicy(widget)); + const int minimumSize = scrollButtonsCutoffSize(thumbIndicatorCutoff, widgetSizePolicy(widget, opt)); if (slider->orientation == Qt::Horizontal) sz = sz.expandedTo(QSize(minimumSize, sz.height())); else -- 2.7.4