Add the beginnings of a unified cross-OS style

* First thing changed, auto-raise toolbuttons don't sink when enabled,
  but remain flat and highlighted.
This commit is contained in:
baldurk
2017-07-19 12:59:44 +01:00
parent 8aaa44d624
commit 83c413129e
5 changed files with 208 additions and 0 deletions
+128
View File
@@ -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 <QDebug>
#include <QPainter>
#include <QPen>
#include <QStyleOption>
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<const QStyleOptionToolButton *>(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<const QStyleOptionToolButton *>(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);
}
+55
View File
@@ -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 <QPalette>
#include <QProxyStyle>
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:
};
+2
View File
@@ -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 \
+8
View File
@@ -573,6 +573,7 @@
<ClCompile Include="Code\QRDUtils.cpp" />
<ClCompile Include="Code\Resources.cpp" />
<ClCompile Include="Code\ScintillaSyntax.cpp" />
<ClCompile Include="$(IntDir)generated\moc_RDStyle.cpp" />
<ClCompile Include="$(IntDir)generated\moc_AboutDialog.cpp" />
<ClCompile Include="$(IntDir)generated\moc_APIInspector.cpp" />
<ClCompile Include="$(IntDir)generated\moc_BufferFormatSpecifier.cpp" />
@@ -668,6 +669,7 @@
<ClCompile Include="Widgets\TextureGoto.cpp" />
<ClCompile Include="Widgets\ThumbnailStrip.cpp" />
<ClCompile Include="Code\CaptureContext.cpp" />
<ClCompile Include="Styles\RDStyle\RDStyle.cpp" />
<ClCompile Include="Widgets\CustomPaintWidget.cpp" />
<ClCompile Include="Windows\APIInspector.cpp" />
<ClCompile Include="Windows\BufferViewer.cpp" />
@@ -900,6 +902,12 @@
<Message>MOC %(Filename).h</Message>
<Outputs>$(IntDir)generated\moc_%(Filename).cpp</Outputs>
</CustomBuild>
<CustomBuild Include="Styles\RDStyle\RDStyle.h">
<AdditionalInputs>%(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs)</AdditionalInputs>
<Command>"$(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"</Command>
<Message>MOC %(Filename).h</Message>
<Outputs>$(IntDir)generated\moc_%(Filename).cpp</Outputs>
</CustomBuild>
<ClInclude Include="Code\ReplayManager.h" />
<ClInclude Include="Code\ScintillaSyntax.h" />
<CustomBuild Include="Widgets\BufferFormatSpecifier.h">
@@ -73,6 +73,12 @@
<Filter Include="PCH">
<UniqueIdentifier>{4869e303-055c-4458-91d6-89ecc827f338}</UniqueIdentifier>
</Filter>
<Filter Include="Styles">
<UniqueIdentifier>{f74a424c-ce15-4da6-9af4-c6bcf62aa581}</UniqueIdentifier>
</Filter>
<Filter Include="Styles\RDStyle">
<UniqueIdentifier>{1e176174-0c57-44df-82b1-638ced184b72}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="3rdparty\toolwindowmanager\ToolWindowManager.cpp">
@@ -627,6 +633,12 @@
<ClCompile Include="$(IntDir)generated\moc_TimelineBar.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Styles\RDStyle\RDStyle.cpp">
<Filter>Styles\RDStyle</Filter>
</ClCompile>
<ClCompile Include="$(IntDir)generated\moc_RDStyle.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="3rdparty\flowlayout\FlowLayout.h">
@@ -1412,5 +1424,8 @@
<CustomBuild Include="Windows\TimelineBar.h">
<Filter>Windows</Filter>
</CustomBuild>
<CustomBuild Include="Styles\RDStyle\RDStyle.h">
<Filter>Styles\RDStyle</Filter>
</CustomBuild>
</ItemGroup>
</Project>