Gui: Add ThemeTokenManager class to contain theme parameters
This class aims to implement Design Token idea into FreeCAD themes. It allows themes to use generic variables with generic values so we could use one qss theme and change the style based on values from preference packs.
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
#include "DlgSettingsUI.h"
|
||||
#include "ui_DlgSettingsUI.h"
|
||||
|
||||
#include "Dialogs/DlgThemeEditor.h"
|
||||
|
||||
#include <Base/ServiceProvider.h>
|
||||
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
|
||||
@@ -45,6 +49,10 @@ DlgSettingsUI::DlgSettingsUI(QWidget* parent)
|
||||
, ui(new Ui_DlgSettingsUI)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->themeEditorButton, &QPushButton::clicked, [this]() {
|
||||
openThemeEditor();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,13 +122,14 @@ void DlgSettingsUI::loadStyleSheet()
|
||||
populateStylesheets("OverlayActiveStyleSheet", "overlay", ui->OverlayStyleSheets, "Auto");
|
||||
}
|
||||
|
||||
void DlgSettingsUI::populateStylesheets(const char *key,
|
||||
const char *path,
|
||||
PrefComboBox *combo,
|
||||
const char *def,
|
||||
void DlgSettingsUI::populateStylesheets(const char* key,
|
||||
const char* path,
|
||||
PrefComboBox* combo,
|
||||
const char* def,
|
||||
QStringList filter)
|
||||
{
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow");
|
||||
// List all .qss/.css files
|
||||
QMap<QString, QString> cssFiles;
|
||||
QDir dir;
|
||||
@@ -172,6 +181,12 @@ void DlgSettingsUI::populateStylesheets(const char *key,
|
||||
combo->onRestore();
|
||||
}
|
||||
|
||||
void DlgSettingsUI::openThemeEditor()
|
||||
{
|
||||
Gui::DlgThemeEditor editor;
|
||||
editor.exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the strings of the subwidgets using the current language.
|
||||
*/
|
||||
@@ -190,6 +205,10 @@ namespace {
|
||||
|
||||
void applyStyleSheet(ParameterGrp *hGrp)
|
||||
{
|
||||
if (auto parameterManager = Base::provideService<Gui::StyleParameters::ParameterManager>()) {
|
||||
parameterManager->reload();
|
||||
}
|
||||
|
||||
auto sheet = hGrp->GetASCII("StyleSheet");
|
||||
bool tiledBG = hGrp->GetBool("TiledBackground", false);
|
||||
Gui::Application::Instance->setStyleSheet(QString::fromUtf8(sheet.c_str()), tiledBG);
|
||||
|
||||
@@ -62,6 +62,7 @@ protected:
|
||||
const char *def,
|
||||
QStringList filter = QStringList());
|
||||
|
||||
void openThemeEditor();
|
||||
private:
|
||||
std::unique_ptr<Ui_DlgSettingsUI> ui;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" columnstretch="2,1,0">
|
||||
<layout class="QGridLayout" columnstretch="2,1">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label1">
|
||||
<property name="text">
|
||||
@@ -53,7 +53,7 @@
|
||||
<property name="toolTip">
|
||||
<string>This color might be used by your theme to let you customize it.</string>
|
||||
</property>
|
||||
<property name="color" stdset="0">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>85</red>
|
||||
<green>123</green>
|
||||
@@ -119,7 +119,7 @@
|
||||
<property name="toolTip">
|
||||
<string>This color might be used by your theme to let you customize it.</string>
|
||||
</property>
|
||||
<property name="color" stdset="0">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>85</red>
|
||||
<green>123</green>
|
||||
@@ -145,7 +145,7 @@
|
||||
<property name="toolTip">
|
||||
<string>This color might be used by your theme to let you customize it.</string>
|
||||
</property>
|
||||
<property name="color" stdset="0">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>85</red>
|
||||
<green>123</green>
|
||||
@@ -165,12 +165,12 @@
|
||||
<property name="toolTip">
|
||||
<string>Style sheet how user interface will look like</string>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>MainWindow</cstring>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>StyleSheet</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>MainWindow</cstring>
|
||||
</property>
|
||||
<property name="prefType" stdset="0">
|
||||
<cstring></cstring>
|
||||
</property>
|
||||
@@ -178,12 +178,12 @@
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Gui::PrefComboBox" name="OverlayStyleSheets">
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>MainWindow</cstring>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>OverlayActiveStyleSheet</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>MainWindow</cstring>
|
||||
</property>
|
||||
<property name="prefType" stdset="0">
|
||||
<cstring></cstring>
|
||||
</property>
|
||||
@@ -191,6 +191,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="themeEditorButton">
|
||||
<property name="text">
|
||||
<string>Open Theme Editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -230,12 +237,12 @@
|
||||
<property name="value">
|
||||
<number>16</number>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>TreeView</cstring>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>IconSize</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>TreeView</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
@@ -285,12 +292,12 @@
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>TreeView</cstring>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ItemSpacing</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>TreeView</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
@@ -492,7 +499,7 @@
|
||||
<item>
|
||||
<spacer name="spacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -510,26 +517,26 @@
|
||||
<extends>QPushButton</extends>
|
||||
<header>Gui/Widgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefColorButton</class>
|
||||
<extends>Gui::ColorButton</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefSpinBox</class>
|
||||
<extends>QSpinBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefColorButton</class>
|
||||
<extends>Gui::ColorButton</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefCheckBox</class>
|
||||
<extends>QCheckBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>ThemeAccentColor1</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user