Enable RDStyle by default, add style selection in the settings dialog

This commit is contained in:
baldurk
2017-08-16 17:39:37 +01:00
parent b70e897838
commit cfd816d7f3
11 changed files with 291 additions and 26 deletions
@@ -22,9 +22,11 @@
* THE SOFTWARE.
******************************************************************************/
#include <QApplication>
#include <QDebug>
#include <QDir>
#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)
+20 -1
View File
@@ -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<QString>, 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 <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);
+20
View File
@@ -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();
+53
View File
@@ -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 <QApplication>
#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);
};
+48
View File
@@ -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 <QString>
#include <functional>
class QStyle;
namespace StyleData
{
struct ThemeDescriptor
{
ThemeDescriptor(const QString &id, const QString &name, const QString &desc,
std::function<QStyle *()> cr)
: styleID(id), styleName(name), styleDescription(desc), creator(cr)
{
}
QString styleID;
QString styleName;
QString styleDescription;
std::function<QStyle *()> creator;
};
extern const ThemeDescriptor availStyles[];
extern const int numAvailable;
};
@@ -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("<br>- ") + 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?<br><br>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();
}
@@ -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();
+52 -25
View File
@@ -61,7 +61,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<property name="documentMode">
<bool>true</bool>
@@ -89,7 +89,7 @@
<string>General</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="toolTip">
<string>Any numbers larger than this exponent will be displayed in scientific notation.
@@ -100,7 +100,7 @@ e.g. 1000 * 10 = 1e4</string>
</property>
</widget>
</item>
<item row="10" column="0">
<item row="12" column="0">
<widget class="QLabel" name="label_9">
<property name="toolTip">
<string>Wherever possible a monospaced font will be used instead of the default font</string>
@@ -110,7 +110,7 @@ e.g. 1000 * 10 = 1e4</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="Formatter_MinFigures">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>Changes the default directory for the save dialog when saving capture files.
@@ -133,7 +133,7 @@ Defaults to blank, which follows system default behaviour.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="10" column="0">
<widget class="QLabel" name="globalHookLabel">
<property name="toolTip">
<string>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
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="9" column="0">
<item row="11" column="0">
<widget class="QLabel" name="label_8">
<property name="toolTip">
<string>Allows RenderDoc to phone home to https://renderdoc.org to anonymously check for new versions.</string>
@@ -191,7 +191,7 @@ e.g. a value of 5 means 0.123456789 will display as 0.12345</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Changes the directory where capture files are saved after being created, until saved manually or deleted.
@@ -203,7 +203,7 @@ Defaults to %TEMP%.</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="Formatter_NegExp">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="14" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -227,7 +227,7 @@ E.g. a value of 3 means 0.005 / 10 = 5E-4</string>
</property>
</spacer>
</item>
<item row="5" column="0">
<item row="7" column="0">
<widget class="QLineEdit" name="tempDirectory">
<property name="toolTip">
<string>Changes the directory where capture files are saved after being created, until saved manually or deleted.
@@ -236,7 +236,7 @@ Defaults to %TEMP%.</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="7" column="1">
<widget class="QPushButton" name="browseTempCaptureDirectory">
<property name="toolTip">
<string>Changes the directory where capture files are saved after being created, until saved manually or deleted.
@@ -248,7 +248,7 @@ Defaults to %TEMP%.</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="9" column="1">
<widget class="QPushButton" name="browseSaveCaptureDirectory">
<property name="toolTip">
<string>Changes the default directory for the save dialog when saving capture files.
@@ -260,7 +260,7 @@ Defaults to blank, which follows system default behaviour.</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="10" column="1">
<widget class="QCheckBox" name="AllowGlobalHook">
<property name="toolTip">
<string>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
</property>
</widget>
</item>
<item row="9" column="1">
<item row="11" column="1">
<widget class="QCheckBox" name="CheckUpdate_AllowChecks">
<property name="toolTip">
<string>Allows RenderDoc to phone home to https://renderdoc.org to anonymously check for new versions.</string>
@@ -285,7 +285,7 @@ Since this is a global system hook it must be used carefully and only when neces
</property>
</widget>
</item>
<item row="10" column="1">
<item row="12" column="1">
<widget class="QCheckBox" name="Font_PreferMonospaced">
<property name="toolTip">
<string>Wherever possible a monospaced font will be used instead of the default font</string>
@@ -295,7 +295,7 @@ Since this is a global system hook it must be used carefully and only when neces
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="Formatter_MaxFigures">
<property name="toolTip">
<string>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</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="9" column="0">
<widget class="QLineEdit" name="saveDirectory">
<property name="toolTip">
<string>Changes the default directory for the save dialog when saving capture files.
@@ -315,7 +315,7 @@ Defaults to blank, which follows system default behaviour.</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="Formatter_PosExp">
<property name="toolTip">
<string>Any numbers larger than this exponent will be displayed in scientific notation.
@@ -329,7 +329,7 @@ e.g. 1000 * 10 = 1e4</string>
</property>
</widget>
</item>
<item row="11" column="0">
<item row="13" column="0">
<widget class="QLabel" name="label_10">
<property name="toolTip">
<string>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
</property>
</widget>
</item>
<item row="11" column="1">
<item row="13" column="1">
<widget class="QCheckBox" name="AlwaysReplayLocally">
<property name="toolTip">
<string>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
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="UIStyle">
<property name="toolTip">
<string>Selects the theme to display the UI in. These themes are available:&lt;br&gt;</string>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="UIStyle_label">
<property name="text">
<string>Visual theme of the UI</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -901,7 +928,7 @@ This can enable debugging of Vulkan apps that don't already contain the layer.</
<item row="3" column="1">
<widget class="QCheckBox" name="Android_AutoPushLayerToApp">
<property name="toolTip">
<string>Automatically push the RenderDoc layer to applications that need it when running on a device with root access.
<string>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.</string>
</property>
</widget>
+2
View File
@@ -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 \
+2
View File
@@ -671,6 +671,7 @@
<ClCompile Include="Widgets\ThumbnailStrip.cpp" />
<ClCompile Include="Code\CaptureContext.cpp" />
<ClCompile Include="Styles\RDStyle\RDStyle.cpp" />
<ClCompile Include="Styles\StyleData.cpp" />
<ClCompile Include="Styles\RDTweakedNativeStyle\RDTweakedNativeStyle.cpp" />
<ClCompile Include="Widgets\CustomPaintWidget.cpp" />
<ClCompile Include="Windows\APIInspector.cpp" />
@@ -891,6 +892,7 @@
<ClInclude Include="$(IntDir)generated\ui_VulkanPipelineStateViewer.h" />
<ClInclude Include="Resources\resource.h" />
<ClInclude Include="Code\CaptureContext.h" />
<ClInclude Include="Styles\StyleData.h" />
<ClInclude Include="Code\qprocessinfo.h" />
<CustomBuild Include="Code\pyrenderdoc\PythonContext.h">
<AdditionalInputs>%(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs)</AdditionalInputs>
@@ -648,6 +648,9 @@
<ClCompile Include="Styles\RDTweakedNativeStyle\RDTweakedNativeStyle.cpp">
<Filter>Styles\RDTweakedNativeStyle</Filter>
</ClCompile>
<ClCompile Include="Styles\StyleData.cpp">
<Filter>Styles</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="3rdparty\flowlayout\FlowLayout.h">
@@ -959,6 +962,9 @@
<ClInclude Include="Code\precompiled.h">
<Filter>PCH</Filter>
</ClInclude>
<ClInclude Include="Styles\StyleData.h">
<Filter>Styles</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Resources\128.png">