From cfd816d7f382de9b5d4d3a5ef7eae406495e937a Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 16 Aug 2017 17:39:37 +0100 Subject: [PATCH] Enable RDStyle by default, add style selection in the settings dialog --- .../Code/Interface/PersistantConfig.cpp | 19 +++++ qrenderdoc/Code/Interface/PersistantConfig.h | 21 ++++- qrenderdoc/Code/qrenderdoc.cpp | 20 +++++ qrenderdoc/Styles/StyleData.cpp | 53 +++++++++++++ qrenderdoc/Styles/StyleData.h | 48 ++++++++++++ qrenderdoc/Windows/Dialogs/SettingsDialog.cpp | 68 ++++++++++++++++ qrenderdoc/Windows/Dialogs/SettingsDialog.h | 1 + qrenderdoc/Windows/Dialogs/SettingsDialog.ui | 77 +++++++++++++------ qrenderdoc/qrenderdoc.pro | 2 + qrenderdoc/qrenderdoc_local.vcxproj | 2 + qrenderdoc/qrenderdoc_local.vcxproj.filters | 6 ++ 11 files changed, 291 insertions(+), 26 deletions(-) create mode 100644 qrenderdoc/Styles/StyleData.cpp create mode 100644 qrenderdoc/Styles/StyleData.h diff --git a/qrenderdoc/Code/Interface/PersistantConfig.cpp b/qrenderdoc/Code/Interface/PersistantConfig.cpp index ede918b96..5c97f039f 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.cpp +++ b/qrenderdoc/Code/Interface/PersistantConfig.cpp @@ -22,9 +22,11 @@ * THE SOFTWARE. ******************************************************************************/ +#include #include #include #include "Code/QRDUtils.h" +#include "Styles/StyleData.h" #include "QRDInterface.h" #define JSON_ID "rdocConfigData" @@ -220,6 +222,23 @@ void PersistantConfig::AddAndroidHosts() } } +bool PersistantConfig::SetStyle() +{ + for(int i = 0; i < StyleData::numAvailable; i++) + { + if(UIStyle == StyleData::availStyles[i].styleID) + { + QApplication::setStyle(StyleData::availStyles[i].creator()); + return true; + } + } + + if(UIStyle != QString()) + qCritical() << "Unrecognised UI style" << UIStyle; + + return false; +} + PersistantConfig::~PersistantConfig() { for(RemoteHost *h : RemoteHosts) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.h b/qrenderdoc/Code/Interface/PersistantConfig.h index 334b40831..354a0013a 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.h +++ b/qrenderdoc/Code/Interface/PersistantConfig.h @@ -59,6 +59,8 @@ DECLARE_REFLECTION_STRUCT(SPIRVDisassembler); // Note that only public properties should be documented. #define CONFIG_SETTINGS() \ \ + CONFIG_SETTING_VAL(public, QString, QString, UIStyle, QString()) \ + \ CONFIG_SETTING_VAL(public, QString, QString, LastLogPath, QString()) \ \ CONFIG_SETTING(public, QVariantList, QList, RecentLogFiles) \ @@ -198,6 +200,12 @@ settings and information that needs to be preserved from one run to the next. For more information about some of these settings that are user-facing see :ref:`the documentation for the settings window `. +.. data:: UIStyle + + The style to load for the UI. Possible values include 'Native', 'RDLight', 'RDDark'. If empty, + the closest of RDLight and RDDark will be chosen, based on the overall light-on-dark or + dark-on-light theme of the application native style. + .. data:: LastLogPath The path to the last capture to be opened, which is useful as a default location for browsing. @@ -420,7 +428,6 @@ public: DOCUMENT(""); CONFIG_SETTINGS() - public: PersistantConfig() {} ~PersistantConfig(); @@ -468,6 +475,18 @@ storing custom settings to be persisted without needing to modify code. )"); QString GetConfigSetting(const QString &name); + DOCUMENT(R"(Sets the UI style to the value in :data:`UIStyle`. + +Changing the style after the application has started may not properly update everything, so to be +sure the new style is applied, the application should be restarted. + +:param str name: The name of the setting. +:return: ``True`` if the style was set successfully, ``False`` if there was a problem e.g. the value + of :data:`UIStyle` was unrecognised or empty. +:rtype: ``bool`` +)"); + bool SetStyle(); + private: bool Deserialize(const QString &filename); bool Serialize(const QString &filename); diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index b5d7d2b60..d09a4219a 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -166,6 +166,26 @@ int main(int argc, char *argv[]) config.SetupFormatting(); + bool isDarkTheme = false; + + { + float baseLum = getLuminance(application.palette().color(QPalette::Base)); + float textLum = getLuminance(application.palette().color(QPalette::Text)); + + // if the base is dark than the text, then it's a light-on-dark theme (aka dark theme) + isDarkTheme = (baseLum < textLum); + } + + bool styleSet = config.SetStyle(); + + // unrecognised style, or empty (none set), choose a default + if(!styleSet) + { + config.UIStyle = isDarkTheme ? lit("RDDark") : lit("RDLight"); + + config.SetStyle(); + } + Resources::Initialise(); GUIInvoke::init(); diff --git a/qrenderdoc/Styles/StyleData.cpp b/qrenderdoc/Styles/StyleData.cpp new file mode 100644 index 000000000..1a24899c0 --- /dev/null +++ b/qrenderdoc/Styles/StyleData.cpp @@ -0,0 +1,53 @@ +/****************************************************************************** + * 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. + ******************************************************************************/ + +#include "StyleData.h" +#include +#include "RDStyle/RDStyle.h" +#include "RDTweakedNativeStyle/RDTweakedNativeStyle.h" + +namespace StyleData +{ +const ThemeDescriptor availStyles[] = { + ThemeDescriptor( + lit("RDLight"), QApplication::translate("RDStyle", "Light"), + QApplication::translate( + "RDStyle", "Light: Cross-platform custom RenderDoc dark theme (black-on-white)."), + []() { return new RDStyle(RDStyle::Light); }), + + ThemeDescriptor( + lit("RDDark"), QApplication::translate("RDStyle", "Dark"), + QApplication::translate( + "RDStyle", "Dark: Cross-platform custom RenderDoc dark theme (white-on-black)."), + []() { return new RDStyle(RDStyle::Dark); }), + + ThemeDescriptor( + lit("Native"), QApplication::translate("RDStyle", "Native"), + QApplication::translate("RDStyle", + "Native: uses the built-in Qt native widgets for your platform."), + []() { return new RDTweakedNativeStyle(NULL); }), +}; + +const int numAvailable = sizeof(availStyles) / sizeof(ThemeDescriptor); +}; \ No newline at end of file diff --git a/qrenderdoc/Styles/StyleData.h b/qrenderdoc/Styles/StyleData.h new file mode 100644 index 000000000..381cc2835 --- /dev/null +++ b/qrenderdoc/Styles/StyleData.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * 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. + ******************************************************************************/ + +#include +#include + +class QStyle; + +namespace StyleData +{ +struct ThemeDescriptor +{ + ThemeDescriptor(const QString &id, const QString &name, const QString &desc, + std::function cr) + : styleID(id), styleName(name), styleDescription(desc), creator(cr) + { + } + + QString styleID; + QString styleName; + QString styleDescription; + std::function creator; +}; + +extern const ThemeDescriptor availStyles[]; +extern const int numAvailable; +}; \ No newline at end of file diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp b/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp index d4caba724..600531602 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp @@ -26,6 +26,7 @@ #include "Code/CaptureContext.h" #include "Code/Interface/QRDInterface.h" #include "Code/QRDUtils.h" +#include "Styles/StyleData.h" #include "Windows/Dialogs/OrderedListEditor.h" #include "CaptureDialog.h" #include "ui_SettingsDialog.h" @@ -35,6 +36,17 @@ SettingsDialog::SettingsDialog(ICaptureContext &ctx, QWidget *parent) { ui->setupUi(this); + QString styleChooseTooltip = ui->UIStyle->toolTip(); + + for(int i = 0; i < StyleData::numAvailable; i++) + styleChooseTooltip += lit("
- ") + StyleData::availStyles[i].styleDescription; + + ui->UIStyle->setToolTip(styleChooseTooltip); + ui->UIStyle_label->setToolTip(styleChooseTooltip); + + for(int i = 0; i < StyleData::numAvailable; i++) + ui->UIStyle->addItem(StyleData::availStyles[i].styleName); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); ui->tabWidget->tabBar()->setVisible(false); @@ -53,6 +65,15 @@ SettingsDialog::SettingsDialog(ICaptureContext &ctx, QWidget *parent) ui->pages->setItemSelected(ui->pages->item(0), true); ui->tabWidget->setCurrentIndex(0); + for(int i = 0; i < StyleData::numAvailable; i++) + { + if(StyleData::availStyles[i].styleID == m_Ctx.Config().UIStyle) + { + ui->UIStyle->setCurrentIndex(i); + break; + } + } + ui->saveDirectory->setText(m_Ctx.Config().DefaultCaptureSaveDirectory); ui->tempDirectory->setText(m_Ctx.Config().TemporaryCaptureDirectory); @@ -386,3 +407,50 @@ void SettingsDialog::on_Android_AutoPushLayerToApp_toggled(bool checked) m_Ctx.Config().Save(); } + +void SettingsDialog::on_UIStyle_currentIndexChanged(int index) +{ + if(index < 0 || index >= StyleData::numAvailable) + return; + + // don't do anything until the dialog is initialised and visible + if(!isVisible()) + return; + + QString oldStyle = m_Ctx.Config().UIStyle; + QString newStyle = StyleData::availStyles[index].styleID; + + if(oldStyle == newStyle) + return; + + QMessageBox::StandardButton ret = RDDialog::question( + this, tr("Switch to new theme?"), + tr("Would you like to switch to the new theme now?

Some parts of a theme might " + "require a full application restart to properly apply."), + RDDialog::YesNoCancel, QMessageBox::Yes); + + if(ret == QMessageBox::Cancel) + { + // change the index back. Since we haven't changed the style yet, this will early out above + // instead of recursing. + + for(int i = 0; i < StyleData::numAvailable; i++) + { + if(StyleData::availStyles[i].styleID == oldStyle) + { + ui->UIStyle->setCurrentIndex(i); + break; + } + } + + return; + } + + // set the style but don't change anything unless the user selected yes. + m_Ctx.Config().UIStyle = newStyle; + + if(ret == QMessageBox::Yes) + m_Ctx.Config().SetStyle(); + + m_Ctx.Config().Save(); +} diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.h b/qrenderdoc/Windows/Dialogs/SettingsDialog.h index d4d94fee4..fbe9d4657 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.h +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.h @@ -51,6 +51,7 @@ private slots: void on_okButton_accepted(); // general + void on_UIStyle_currentIndexChanged(int index); void on_tempDirectory_textEdited(const QString &temp); void on_saveDirectory_textEdited(const QString &save); void on_browseSaveCaptureDirectory_clicked(); diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.ui b/qrenderdoc/Windows/Dialogs/SettingsDialog.ui index 730fbe065..5e34b3a7a 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.ui +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.ui @@ -61,7 +61,7 @@ QTabWidget::West - 3 + 0 true @@ -89,7 +89,7 @@ General - + Any numbers larger than this exponent will be displayed in scientific notation. @@ -100,7 +100,7 @@ e.g. 1000 * 10 = 1e4 - + Wherever possible a monospaced font will be used instead of the default font @@ -110,7 +110,7 @@ e.g. 1000 * 10 = 1e4 - + Decimals will display at least this many digits. @@ -121,7 +121,7 @@ e.g. a value of 2 means 0 will display as 0.00, 0.5 as 0.50 - + Changes the default directory for the save dialog when saving capture files. @@ -133,7 +133,7 @@ Defaults to blank, which follows system default behaviour. - + Any numbers smaller than this exponent will be displayed in scientific notation. @@ -144,7 +144,7 @@ E.g. a value of 3 means 0.005 / 10 = 5E-4 - + Decimals will display at least this many digits. @@ -155,7 +155,7 @@ e.g. a value of 2 means 0 will display as 0.00, 0.5 as 0.50 - + Enables functionality on the capture application window that will insert RenderDoc automatically @@ -170,7 +170,7 @@ Since this is a global system hook it must be used carefully and only when neces - + No more significant figures than this will be displayed on floats. @@ -181,7 +181,7 @@ e.g. a value of 5 means 0.123456789 will display as 0.12345 - + Allows RenderDoc to phone home to https://renderdoc.org to anonymously check for new versions. @@ -191,7 +191,7 @@ e.g. a value of 5 means 0.123456789 will display as 0.12345 - + Changes the directory where capture files are saved after being created, until saved manually or deleted. @@ -203,7 +203,7 @@ Defaults to %TEMP%. - + Any numbers smaller than this exponent will be displayed in scientific notation. @@ -214,7 +214,7 @@ E.g. a value of 3 means 0.005 / 10 = 5E-4 - + Qt::Vertical @@ -227,7 +227,7 @@ E.g. a value of 3 means 0.005 / 10 = 5E-4 - + Changes the directory where capture files are saved after being created, until saved manually or deleted. @@ -236,7 +236,7 @@ Defaults to %TEMP%. - + Changes the directory where capture files are saved after being created, until saved manually or deleted. @@ -248,7 +248,7 @@ Defaults to %TEMP%. - + Changes the default directory for the save dialog when saving capture files. @@ -260,7 +260,7 @@ Defaults to blank, which follows system default behaviour. - + Enables functionality on the capture application window that will insert RenderDoc automatically @@ -275,7 +275,7 @@ Since this is a global system hook it must be used carefully and only when neces - + Allows RenderDoc to phone home to https://renderdoc.org to anonymously check for new versions. @@ -285,7 +285,7 @@ Since this is a global system hook it must be used carefully and only when neces - + Wherever possible a monospaced font will be used instead of the default font @@ -295,7 +295,7 @@ Since this is a global system hook it must be used carefully and only when neces - + No more significant figures than this will be displayed on floats. @@ -306,7 +306,7 @@ e.g. a value of 5 means 0.123456789 will display as 0.12345 - + Changes the default directory for the save dialog when saving capture files. @@ -315,7 +315,7 @@ Defaults to blank, which follows system default behaviour. - + Any numbers larger than this exponent will be displayed in scientific notation. @@ -329,7 +329,7 @@ e.g. 1000 * 10 = 1e4 - + If a capture is marked as being created on a significantly different system (different OS or platform) @@ -342,7 +342,7 @@ This option overrides that and will always replay locally if the local context i - + If a capture is marked as being created on a significantly different system (different OS or platform) @@ -355,6 +355,33 @@ This option overrides that and will always replay locally if the local context i + + + + Selects the theme to display the UI in. These themes are available:<br> + + + QComboBox::NoInsert + + + QComboBox::AdjustToContents + + + + + + + Visual theme of the UI + + + + + + + Qt::Horizontal + + + @@ -901,7 +928,7 @@ This can enable debugging of Vulkan apps that don't already contain the layer. - Automatically push the RenderDoc layer to applications that need it when running on a device with root access. + Automatically push the RenderDoc layer to applications that need it when running on a device with root access. This can enable debugging of Vulkan apps that don't already contain the layer. diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index 5a8123b6d..018f254cf 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/StyleData.cpp \ Styles/RDStyle/RDStyle.cpp \ Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp \ Windows/Dialogs/AboutDialog.cpp \ @@ -229,6 +230,7 @@ HEADERS += Code/CaptureContext.h \ Code/Interface/CommonPipelineState.h \ Code/Interface/PersistantConfig.h \ Code/Interface/RemoteHost.h \ + Styles/StyleData.h \ Styles/RDStyle/RDStyle.h \ Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h \ Windows/Dialogs/AboutDialog.h \ diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index 484018a3a..fe1f7e8ee 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -671,6 +671,7 @@ + @@ -891,6 +892,7 @@ + %(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs) diff --git a/qrenderdoc/qrenderdoc_local.vcxproj.filters b/qrenderdoc/qrenderdoc_local.vcxproj.filters index 6c476fad5..6751a50fc 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj.filters +++ b/qrenderdoc/qrenderdoc_local.vcxproj.filters @@ -648,6 +648,9 @@ Styles\RDTweakedNativeStyle + + Styles + @@ -959,6 +962,9 @@ PCH + + Styles +