From 03cf4d2ce3c847d62d4806cdfda2fb2d47e50466 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 20 Jul 2017 15:23:41 +0100 Subject: [PATCH] Customise button rendering in RDStyle --- qrenderdoc/Styles/RDStyle/RDStyle.cpp | 96 +++++++++++++++++++ qrenderdoc/Styles/RDStyle/RDStyle.h | 2 + .../RDTweakedNativeStyle.cpp | 2 - 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.cpp b/qrenderdoc/Styles/RDStyle/RDStyle.cpp index 9e259a7f1..1f38d2ffb 100644 --- a/qrenderdoc/Styles/RDStyle/RDStyle.cpp +++ b/qrenderdoc/Styles/RDStyle/RDStyle.cpp @@ -23,8 +23,10 @@ ******************************************************************************/ #include "RDStyle.h" +#include #include #include +#include #include #include #include "Code/QRDUtils.h" @@ -139,6 +141,11 @@ QSize RDStyle::sizeFromContents(ContentsType type, const QStyleOption *opt, cons int RDStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const { + if(metric == QStyle::PM_ButtonShiftHorizontal || metric == QStyle::PM_ButtonShiftVertical) + { + if(opt && (opt->state & State_AutoRaise) == 0) + return 1; + } return RDTweakedNativeStyle::pixelMetric(metric, opt, widget); } @@ -151,6 +158,31 @@ QIcon RDStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *opt void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const { + // let the tweaked native style render autoraise tool buttons + if(control == QStyle::CC_ToolButton && (opt->state & State_AutoRaise) == 0) + { + drawControl(CE_PushButtonBevel, opt, p, widget); + + const QStyleOptionToolButton *toolbutton = qstyleoption_cast(opt); + + QStyleOptionToolButton labelTextIcon = *toolbutton; + labelTextIcon.rect = subControlRect(control, opt, SC_ToolButton, widget); + + // draw the label text/icon + drawControl(CE_ToolButtonLabel, &labelTextIcon, p, widget); + + // draw the menu arrow, if there is one + if((toolbutton->subControls & SC_ToolButtonMenu) || + (toolbutton->features & QStyleOptionToolButton::HasMenu)) + { + QStyleOptionToolButton menu = *toolbutton; + menu.rect = subControlRect(control, opt, SC_ToolButtonMenu, widget); + drawPrimitive(PE_IndicatorArrowDown, &menu, p, widget); + } + + return; + } + return RDTweakedNativeStyle::drawComplexControl(control, opt, p, widget); } @@ -160,8 +192,72 @@ void RDStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *opt, Q RDTweakedNativeStyle::drawPrimitive(element, opt, p, widget); } +QPalette::ColorRole RDStyle::outlineRole() const +{ + return m_Scheme == Light ? QPalette::Dark : QPalette::Light; +} + void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPainter *p, const QWidget *widget) const { + if(control == CE_PushButton) + { + drawControl(CE_PushButtonBevel, opt, p, widget); + + QCommonStyle::drawControl(CE_PushButtonLabel, opt, p, widget); + + return; + } + else if(control == CE_PushButtonBevel) + { + QPen outlinePen(opt->palette.brush(outlineRole()), 1.0); + + if(opt->state & State_HasFocus) + outlinePen = QPen(opt->palette.brush(QPalette::Highlight), 2.0); + + p->save(); + + p->setRenderHint(QPainter::Antialiasing); + + int xshift = pixelMetric(PM_ButtonShiftHorizontal, opt, widget); + int yshift = pixelMetric(PM_ButtonShiftVertical, opt, widget); + + QRect rect = opt->rect.adjusted(1, 1, -1, -1); + + if(opt->state & State_Sunken) + { + rect.setLeft(rect.left() + xshift); + rect.setTop(rect.top() + yshift); + + QPainterPath path; + path.addRoundedRect(rect, 1.0, 1.0); + + p->fillPath(path, opt->palette.brush(QPalette::Midlight)); + + p->setPen(outlinePen); + p->drawPath(path.translated(QPointF(0.5, 0.5))); + } + else + { + rect.setRight(rect.right() - xshift); + rect.setBottom(rect.bottom() - yshift); + + QPainterPath path; + path.addRoundedRect(rect, 1.0, 1.0); + + p->setPen(QPen(opt->palette.brush(QPalette::Shadow), 1.0)); + p->drawPath(path.translated(QPointF(1.0, 1.0))); + + p->fillPath(path, opt->palette.brush(QPalette::Button)); + + p->setPen(outlinePen); + p->drawPath(path.translated(QPointF(0.5, 0.5))); + } + + p->restore(); + + return; + } + RDTweakedNativeStyle::drawControl(control, opt, p, widget); } diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.h b/qrenderdoc/Styles/RDStyle/RDStyle.h index 0f7db3840..39356b5b9 100644 --- a/qrenderdoc/Styles/RDStyle/RDStyle.h +++ b/qrenderdoc/Styles/RDStyle/RDStyle.h @@ -60,4 +60,6 @@ public: protected: ColorScheme m_Scheme = Light; + + QPalette::ColorRole outlineRole() const; }; diff --git a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp index 3af6a0ac1..04c1bd126 100644 --- a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp +++ b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp @@ -102,8 +102,6 @@ void RDTweakedNativeStyle::drawComplexControl(ComplexControl control, const QSty // autoraise toolbuttons are rendered flat with a semi-transparent highlight to show their state. if(control == QStyle::CC_ToolButton && (opt->state & State_AutoRaise)) { - QRect dropdown = subControlRect(control, opt, SC_ToolButtonMenu, widget); - QPen oldPen = p->pen(); QColor backCol = opt->palette.color(QPalette::Normal, QPalette::Highlight);