From 4c45c0716018033879d7672f933a0661785e51ea Mon Sep 17 00:00:00 2001 From: William Pearson Date: Wed, 12 Apr 2023 16:16:52 -0700 Subject: [PATCH] Move subControlRect for CC_ToolButton to RDTweakedNativeStyle This means the full rect won't be returned for SC_ToolButtonMenu if it is used in a context where the default style doesn't expect the menu. This is a separate commit to isolate future changes to this function. --- qrenderdoc/Styles/RDStyle/RDStyle.cpp | 28 +--------------- .../RDTweakedNativeStyle.cpp | 33 +++++++++++++++++++ .../RDTweakedNativeStyle.h | 2 ++ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.cpp b/qrenderdoc/Styles/RDStyle/RDStyle.cpp index 8cf5a5325..150393a06 100644 --- a/qrenderdoc/Styles/RDStyle/RDStyle.cpp +++ b/qrenderdoc/Styles/RDStyle/RDStyle.cpp @@ -317,33 +317,7 @@ bool RDStyle::eventFilter(QObject *watched, QEvent *event) QRect RDStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const { - if(cc == QStyle::CC_ToolButton) - { - int indicatorWidth = proxy()->pixelMetric(PM_MenuButtonIndicator, opt, widget); - - QRect ret = opt->rect; - - const QStyleOptionToolButton *toolbutton = qstyleoption_cast(opt); - - // return the normal rect if there's no menu - if(!(toolbutton->subControls & SC_ToolButtonMenu) && - !(toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)) - { - return ret; - } - - if(sc == QStyle::SC_ToolButton) - { - ret.setRight(ret.right() - indicatorWidth); - } - else if(sc == QStyle::SC_ToolButtonMenu) - { - ret.setLeft(ret.right() - indicatorWidth); - } - - return ret; - } - else if(cc == QStyle::CC_GroupBox) + if(cc == QStyle::CC_GroupBox) { QRect ret = opt->rect; diff --git a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp index 01af671c1..7beb815c7 100644 --- a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp +++ b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp @@ -51,6 +51,39 @@ RDTweakedNativeStyle::~RDTweakedNativeStyle() { } +QRect RDTweakedNativeStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, + SubControl sc, const QWidget *widget) const +{ + if(cc == QStyle::CC_ToolButton) + { + int indicatorWidth = proxy()->pixelMetric(PM_MenuButtonIndicator, opt, widget); + + QRect ret = opt->rect; + + const QStyleOptionToolButton *toolbutton = qstyleoption_cast(opt); + + // return the normal rect if there's no menu + if(!(toolbutton->subControls & SC_ToolButtonMenu) && + !(toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)) + { + return ret; + } + + if(sc == QStyle::SC_ToolButton) + { + ret.setRight(ret.right() - indicatorWidth); + } + else if(sc == QStyle::SC_ToolButtonMenu) + { + ret.setLeft(ret.right() - indicatorWidth); + } + + return ret; + } + + return QProxyStyle::subControlRect(cc, opt, sc, widget); +} + QRect RDTweakedNativeStyle::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const { diff --git a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h index 548a395c9..2ed8d25b3 100644 --- a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h +++ b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h @@ -35,6 +35,8 @@ public: RDTweakedNativeStyle(QStyle *parent); ~RDTweakedNativeStyle(); + virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, + const QWidget *widget = Q_NULLPTR) const override; virtual QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override; virtual QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size,