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:
Kacper Donat
2025-04-06 22:36:06 +02:00
parent 8d1f65e992
commit a32594faea
23 changed files with 3749 additions and 93 deletions

View File

@@ -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);