diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.cpp b/qrenderdoc/Styles/RDStyle/RDStyle.cpp new file mode 100644 index 000000000..ff2d06633 --- /dev/null +++ b/qrenderdoc/Styles/RDStyle/RDStyle.cpp @@ -0,0 +1,128 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2016-2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "RDStyle.h" +#include +#include +#include +#include + +RDStyle::RDStyle(ColorScheme scheme) : QProxyStyle() +{ +} + +RDStyle::~RDStyle() +{ +} + +QSize RDStyle::sizeFromContents(ContentsType type, const QStyleOption *opt, const QSize &size, + const QWidget *widget) const +{ + QSize sz = size; + + // Toolbuttons are always at least icon sized, for consistency. + if(type == QStyle::CT_ToolButton) + { + const QStyleOptionToolButton *toolbutton = qstyleoption_cast(opt); + if(toolbutton) + sz = sz.expandedTo(toolbutton->iconSize); + } + + return QProxyStyle::sizeFromContents(type, opt, sz, widget); +} + +int RDStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const +{ + // toolbuttons don't shift their text when clicked. + if(metric == QStyle::PM_ButtonShiftHorizontal || metric == QStyle::PM_ButtonShiftVertical) + { + if(opt && (opt->state & State_AutoRaise)) + return 0; + } + + return QProxyStyle::pixelMetric(metric, opt, widget); +} + +void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *opt, + QPainter *p, const QWidget *widget) const +{ + // 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); + + backCol.setAlphaF(0.2); + QStyle::State masked = opt->state & (State_On | State_MouseOver); + + // when the mouse is over, make it a little stronger + if(masked && (masked & State_MouseOver)) + backCol.setAlphaF(0.4); + + if(masked) + { + QRect rect = opt->rect.adjusted(0, 0, -1, -1); + p->setPen(opt->palette.color(QPalette::Shadow)); + p->drawRect(rect); + p->fillRect(rect, QBrush(backCol)); + } + + p->setPen(oldPen); + + 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 QProxyStyle::drawComplexControl(control, opt, p, widget); +} + +void RDStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *opt, QPainter *p, + const QWidget *widget) const +{ + QProxyStyle::drawPrimitive(element, opt, p, widget); +} + +void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPainter *p, + const QWidget *widget) const +{ + QProxyStyle::drawControl(control, opt, p, widget); +} diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.h b/qrenderdoc/Styles/RDStyle/RDStyle.h new file mode 100644 index 000000000..a2ca597e9 --- /dev/null +++ b/qrenderdoc/Styles/RDStyle/RDStyle.h @@ -0,0 +1,55 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +#include +#include + +class RDStyle : public QProxyStyle +{ +private: + Q_OBJECT +public: + enum ColorScheme + { + Light, + Dark + }; + RDStyle(ColorScheme scheme); + ~RDStyle(); + + QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, + const QWidget *widget) const override; + int pixelMetric(PixelMetric metric, const QStyleOption *option, + const QWidget *widget) const override; + void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, + QPainter *painter, const QWidget *widget) const override; + void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, + const QWidget *widget) const override; + void drawControl(ControlElement control, const QStyleOption *option, QPainter *painter, + const QWidget *widget) const override; + +protected: +}; diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index 79e8576c8..3ff87bdfe 100644 --- a/qrenderdoc/qrenderdoc.pro +++ b/qrenderdoc/qrenderdoc.pro @@ -166,6 +166,7 @@ SOURCES += Code/qrenderdoc.cpp \ Code/Interface/CommonPipelineState.cpp \ Code/Interface/PersistantConfig.cpp \ Code/Interface/RemoteHost.cpp \ + Styles/RDStyle/RDStyle.cpp \ Windows/Dialogs/AboutDialog.cpp \ Windows/MainWindow.cpp \ Windows/EventBrowser.cpp \ @@ -227,6 +228,7 @@ HEADERS += Code/CaptureContext.h \ Code/Interface/CommonPipelineState.h \ Code/Interface/PersistantConfig.h \ Code/Interface/RemoteHost.h \ + Styles/RDStyle/RDStyle.h \ Windows/Dialogs/AboutDialog.h \ Windows/MainWindow.h \ Windows/EventBrowser.h \ diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index 25d6f97ce..2ec46246b 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -573,6 +573,7 @@ + @@ -668,6 +669,7 @@ + @@ -900,6 +902,12 @@ MOC %(Filename).h $(IntDir)generated\moc_%(Filename).cpp + + %(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs) + "$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe" -DUNICODE -DWIN32 -DWIN64 -D_WIN32 -D_WIN64 -DRENDERDOC_PLATFORM_WIN32 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1900 -I"$(ProjectDir)." -I"$(SolutionDir)\renderdoc\api\replay" -I"$(ProjectDir)3rdparty\qt\$(Platform)\mkspecs/win32-msvc2015" -I"$(ProjectDir)3rdparty\qt\$(Platform)\include" -I"$(ProjectDir)3rdparty\qt\$(Platform)\include\QtWidgets" -I"$(ProjectDir)3rdparty\qt\$(Platform)\include\QtGui" -I"$(ProjectDir)3rdparty\qt\$(Platform)\include\QtCore" "%(Fullpath)" -o "$(IntDir)generated\moc_%(Filename).cpp" + MOC %(Filename).h + $(IntDir)generated\moc_%(Filename).cpp + diff --git a/qrenderdoc/qrenderdoc_local.vcxproj.filters b/qrenderdoc/qrenderdoc_local.vcxproj.filters index d7c1763c6..47b068318 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj.filters +++ b/qrenderdoc/qrenderdoc_local.vcxproj.filters @@ -73,6 +73,12 @@ {4869e303-055c-4458-91d6-89ecc827f338} + + {f74a424c-ce15-4da6-9af4-c6bcf62aa581} + + + {1e176174-0c57-44df-82b1-638ced184b72} + @@ -627,6 +633,12 @@ Generated Files + + Styles\RDStyle + + + Generated Files + @@ -1412,5 +1424,8 @@ Windows + + Styles\RDStyle + \ No newline at end of file