- Create a 'Theme' pref page in which 'StyleSheet' is moved, and a secondary color pref is created.

- 'StyleSheet' combobox is removed from general and replaced by a 'Theme' combobox.
- Theme combobox triggers the pref packs of type 'Theme'.
This commit is contained in:
Paddle
2023-07-30 07:26:13 +02:00
committed by Chris Hennes
parent 607f61a5d5
commit d73434639d
8 changed files with 467 additions and 45 deletions

View File

@@ -320,6 +320,7 @@ SET(Gui_UIC_SRCS
DlgSettingsNavigation.ui
DlgSettingsSelection.ui
DlgSettingsViewColor.ui
DlgSettingsTheme.ui
DlgSettingsColorGradient.ui
DlgSettingsDocument.ui
DlgSettingsImage.ui
@@ -565,6 +566,7 @@ SET(Dialog_Settings_CPP_SRCS
DlgSettingsNavigation.cpp
DlgSettingsSelection.cpp
DlgSettingsViewColor.cpp
DlgSettingsTheme.cpp
DlgSettingsColorGradientImp.cpp
DlgSettingsDocumentImp.cpp
DlgSettingsImageImp.cpp
@@ -584,6 +586,7 @@ SET(Dialog_Settings_HPP_SRCS
DlgSettingsNavigation.h
DlgSettingsSelection.h
DlgSettingsViewColor.h
DlgSettingsTheme.h
DlgSettingsColorGradientImp.h
DlgSettingsDocumentImp.h
DlgSettingsImageImp.h
@@ -605,6 +608,7 @@ SET(Dialog_Settings_SRCS
DlgSettingsNavigation.ui
DlgSettingsSelection.ui
DlgSettingsViewColor.ui
DlgSettingsTheme.ui
DlgSettingsColorGradient.ui
DlgSettingsDocument.ui
DlgSettingsImage.ui

View File

@@ -212,16 +212,16 @@ dot/period will always be printed.</string>
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="styleSheetLabel">
<widget class="QLabel" name="themesLabel">
<property name="text">
<string>Style sheet:</string>
<string>Theme:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="StyleSheets">
<widget class="QComboBox" name="themesCombobox">
<property name="toolTip">
<string>Style sheet how user interface will look like</string>
<string>Customize how user interface will look like</string>
</property>
</widget>
</item>

View File

@@ -66,6 +66,7 @@ using namespace Base;
DlgGeneralImp::DlgGeneralImp( QWidget* parent )
: PreferencePage(parent)
, localeIndex(0)
, themeChanged(false)
, ui(new Ui_DlgGeneral)
{
ui->setupUi(this);
@@ -74,6 +75,7 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent )
connect(ui->ImportConfig, &QPushButton::clicked, this, &DlgGeneralImp::onImportConfigClicked);
connect(ui->SaveNewPreferencePack, &QPushButton::clicked, this, &DlgGeneralImp::saveAsNewPreferencePack);
connect(ui->themesCombobox, qOverload<int>(&QComboBox::activated), this, &DlgGeneralImp::onThemeChanged);
ui->ManagePreferencePacks->setToolTip(tr("Manage preference packs"));
connect(ui->ManagePreferencePacks, &QPushButton::clicked, this, &DlgGeneralImp::onManagePreferencePacksClicked);
@@ -246,9 +248,8 @@ void DlgGeneralImp::saveSettings()
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
hGrp->SetBool("TiledBackground", ui->tiledBackground->isChecked());
QVariant sheet = ui->StyleSheets->itemData(ui->StyleSheets->currentIndex());
hGrp->SetASCII("StyleSheet", (const char*)sheet.toByteArray());
Application::Instance->setStyleSheet(sheet.toString(), ui->tiledBackground->isChecked());
if (themeChanged)
saveThemes();
}
void DlgGeneralImp::loadSettings()
@@ -348,54 +349,55 @@ void DlgGeneralImp::loadSettings()
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
ui->tiledBackground->setChecked(hGrp->GetBool("TiledBackground", false));
// List all .qss/.css files
QMap<QString, QString> cssFiles;
QDir dir;
QStringList filter;
filter << QString::fromLatin1("*.qss");
filter << QString::fromLatin1("*.css");
loadThemes();
}
// read from user, resource and built-in directory
QStringList qssPaths = QDir::searchPaths(QString::fromLatin1("qss"));
for (const auto & qssPath : qssPaths) {
dir.setPath(qssPath);
QFileInfoList fileNames = dir.entryInfoList(filter, QDir::Files, QDir::Name);
for (const auto & fileName : qAsConst(fileNames)) {
if (cssFiles.find(fileName.baseName()) == cssFiles.end()) {
cssFiles[fileName.baseName()] = fileName.fileName();
}
void DlgGeneralImp::saveThemes()
{
// First we save the name of the theme
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
std::string theme = ui->themesCombobox->currentText().toStdString();
hGrp->SetASCII("Theme", theme);
// Then we apply the themepack.
Application::Instance->prefPackManager()->rescan();
auto packs = Application::Instance->prefPackManager()->preferencePacks();
for (const auto& pack : packs) {
if (pack.first == theme) {
Application::Instance->prefPackManager()->apply(pack.first);
break;
}
}
// now add all unique items
ui->StyleSheets->clear();
ui->StyleSheets->addItem(tr("No style sheet"), QString::fromLatin1(""));
for (QMap<QString, QString>::iterator it = cssFiles.begin(); it != cssFiles.end(); ++it) {
ui->StyleSheets->addItem(it.key(), it.value());
}
// Set the StyleSheet
QString sheet = QString::fromStdString(hGrp->GetASCII("StyleSheet"));
bool tiledBackground = hGrp->GetBool("TiledBackground", false);
Application::Instance->setStyleSheet(sheet, tiledBackground);
}
QString selectedStyleSheet = QString::fromLatin1(hGrp->GetASCII("StyleSheet").c_str());
index = ui->StyleSheets->findData(selectedStyleSheet);
void DlgGeneralImp::loadThemes()
{
ui->themesCombobox->clear();
// might be an absolute path name
if (index < 0 && !selectedStyleSheet.isEmpty()) {
QFileInfo fi(selectedStyleSheet);
if (fi.isAbsolute()) {
QString path = fi.absolutePath();
if (qssPaths.indexOf(path) >= 0) {
selectedStyleSheet = fi.fileName();
}
else {
selectedStyleSheet = fi.absoluteFilePath();
ui->StyleSheets->addItem(fi.baseName(), selectedStyleSheet);
}
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
index = ui->StyleSheets->findData(selectedStyleSheet);
QString currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
Application::Instance->prefPackManager()->rescan();
auto packs = Application::Instance->prefPackManager()->preferencePacks();
for (const auto& pack : packs) {
if (pack.second.metadata().type() == "Theme") {
ui->themesCombobox->addItem(QString::fromStdString(pack.first));
}
}
if (index > -1)
ui->StyleSheets->setCurrentIndex(index);
int index = ui->themesCombobox->findText(currentTheme);
if (index >= 0 && index < ui->themesCombobox->count()) {
ui->themesCombobox->setCurrentIndex(index);
}
}
void DlgGeneralImp::changeEvent(QEvent *event)
@@ -561,4 +563,9 @@ void DlgGeneralImp::onUnitSystemIndexChanged(int index)
}
}
void DlgGeneralImp::onThemeChanged(int index) {
Q_UNUSED(index);
themeChanged = true;
}
#include "moc_DlgGeneralImp.cpp"

View File

@@ -54,6 +54,9 @@ public:
void saveSettings() override;
void loadSettings() override;
void saveThemes();
void loadThemes();
protected:
void changeEvent(QEvent *event) override;
@@ -63,6 +66,7 @@ protected Q_SLOTS:
void newPreferencePackDialogAccepted();
void onManagePreferencePacksClicked();
void onImportConfigClicked();
void onThemeChanged(int index);
public Q_SLOTS:
void onUnitSystemIndexChanged(int index);
@@ -77,6 +81,7 @@ private:
private:
int localeIndex;
bool themeChanged;
std::unique_ptr<Ui_DlgGeneral> ui;
std::unique_ptr<DlgCreateNewPreferencePackImp> newPreferencePackDialog;
std::unique_ptr<DlgPreferencePackManagementImp> preferencePackManagementDialog;

View File

@@ -0,0 +1,160 @@
/***************************************************************************
* Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QPushButton>
#endif
#include "DlgSettingsTheme.h"
#include "ui_DlgSettingsTheme.h"
#include "Application.h"
#include "PreferencePackManager.h"
using namespace Gui::Dialog;
/* TRANSLATOR Gui::Dialog::DlgSettingsTheme */
/**
* Constructs a DlgSettingsTheme which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
DlgSettingsTheme::DlgSettingsTheme(QWidget* parent)
: PreferencePage(parent)
, ui(new Ui_DlgSettingsTheme)
, styleSheetChanged(false)
{
ui->setupUi(this);
connect(ui->styleSheetsCombobox, qOverload<int>(&QComboBox::activated), this, &DlgSettingsTheme::onStyleSheetChanged);
}
/**
* Destroys the object and frees any allocated resources
*/
DlgSettingsTheme::~DlgSettingsTheme()
{
// no need to delete child widgets, Qt does it all for us
}
void DlgSettingsTheme::saveSettings()
{
ui->ThemeSecondaryColor->onSave();
if (styleSheetChanged)
saveStyleSheet();
}
void DlgSettingsTheme::loadSettings()
{
ui->ThemeSecondaryColor->onRestore();
loadStyleSheet();
}
void DlgSettingsTheme::saveStyleSheet()
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
QVariant sheet = ui->styleSheetsCombobox->itemData(ui->styleSheetsCombobox->currentIndex());
hGrp->SetASCII("StyleSheet", (const char*)sheet.toByteArray());
bool tiledBackground = hGrp->GetBool("TiledBackground", false);
Application::Instance->setStyleSheet(sheet.toString(), tiledBackground);
}
void DlgSettingsTheme::loadStyleSheet()
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
// List all .qss/.css files
QMap<QString, QString> cssFiles;
QDir dir;
QStringList filter;
filter << QString::fromLatin1("*.qss");
filter << QString::fromLatin1("*.css");
// read from user, resource and built-in directory
QStringList qssPaths = QDir::searchPaths(QString::fromLatin1("qss"));
for (const auto& qssPath : qssPaths) {
dir.setPath(qssPath);
QFileInfoList fileNames = dir.entryInfoList(filter, QDir::Files, QDir::Name);
for (const auto& fileName : qAsConst(fileNames)) {
if (cssFiles.find(fileName.baseName()) == cssFiles.end()) {
cssFiles[fileName.baseName()] = fileName.fileName();
}
}
}
// now add all unique items
ui->styleSheetsCombobox->clear();
ui->styleSheetsCombobox->addItem(tr("No style sheet"), QString::fromLatin1(""));
for (QMap<QString, QString>::iterator it = cssFiles.begin(); it != cssFiles.end(); ++it) {
ui->styleSheetsCombobox->addItem(it.key(), it.value());
}
QString selectedStyleSheet = QString::fromLatin1(hGrp->GetASCII("StyleSheet").c_str());
int index = ui->styleSheetsCombobox->findData(selectedStyleSheet);
// might be an absolute path name
if (index < 0 && !selectedStyleSheet.isEmpty()) {
QFileInfo fi(selectedStyleSheet);
if (fi.isAbsolute()) {
QString path = fi.absolutePath();
if (qssPaths.indexOf(path) >= 0) {
selectedStyleSheet = fi.fileName();
}
else {
selectedStyleSheet = fi.absoluteFilePath();
ui->styleSheetsCombobox->addItem(fi.baseName(), selectedStyleSheet);
}
index = ui->styleSheetsCombobox->findData(selectedStyleSheet);
}
}
if (index > -1)
ui->styleSheetsCombobox->setCurrentIndex(index);
}
void DlgSettingsTheme::onStyleSheetChanged(int index) {
Q_UNUSED(index);
Base::Console().Warning("Hello");
styleSheetChanged = true;
}
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgSettingsTheme::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
}
else {
QWidget::changeEvent(e);
}
}
#include "moc_DlgSettingsTheme.cpp"

View File

@@ -0,0 +1,66 @@
/***************************************************************************
* Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_DIALOG_DLGSETTINGSTHEME_H
#define GUI_DIALOG_DLGSETTINGSTHEME_H
#include "PropertyPage.h"
#include <memory>
namespace Gui {
namespace Dialog {
class Ui_DlgSettingsTheme;
/**
* The DlgSettingsTheme class implements a preference page to change theme settings.
* @author Pierre-Louis Boyer
*/
class DlgSettingsTheme : public PreferencePage
{
Q_OBJECT
public:
explicit DlgSettingsTheme(QWidget* parent = nullptr);
~DlgSettingsTheme() override;
void saveSettings() override;
void loadSettings() override;
void saveStyleSheet();
void loadStyleSheet();
protected:
void changeEvent(QEvent *e) override;
protected Q_SLOTS:
void onStyleSheetChanged(int index);
private:
std::unique_ptr<Ui_DlgSettingsTheme> ui;
bool styleSheetChanged;
};
} // namespace Dialog
} // namespace Gui
#endif // GUI_DIALOG_DLGSETTINGSTHEME_H

178
src/Gui/DlgSettingsTheme.ui Normal file
View File

@@ -0,0 +1,178 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgSettingsTheme</class>
<widget class="QWidget" name="Gui::Dialog::DlgSettingsTheme">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>405</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Theme</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel">
<property name="text">
<string>This page let you customize your current theme. The offered settings are optional for theme developpers so they may or may not have an effect in your current theme.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="styleSheetLabel">
<property name="text">
<string>Style sheet:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="styleSheetsCombobox">
<property name="toolTip">
<string>Style sheet how user interface will look like</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<property name="text">
<string>Secondary theme color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::PrefColorButton" name="ThemeSecondaryColor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>This color might be used by your theme to let you customize it.</string>
</property>
<property name="color" stdset="0">
<color>
<red>85</red>
<green>123</green>
<blue>182</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>ThemeSecondaryColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Themes</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<spacer name="spacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>183</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="spacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::ColorButton</class>
<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::PrefRadioButton</class>
<extends>QRadioButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>checkBoxPreselection</tabstop>
<tabstop>HighlightColor</tabstop>
<tabstop>checkBoxSelection</tabstop>
<tabstop>SelectionColor</tabstop>
<tabstop>SelectionColor_Background</tabstop>
<tabstop>backgroundColorFrom</tabstop>
<tabstop>backgroundColorTo</tabstop>
<tabstop>checkMidColor</tabstop>
<tabstop>backgroundColorMid</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>checkBoxPreselection</sender>
<signal>toggled(bool)</signal>
<receiver>HighlightColor</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>70</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>310</x>
<y>54</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBoxSelection</sender>
<signal>toggled(bool)</signal>
<receiver>SelectionColor</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>158</x>
<y>76</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>75</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -34,6 +34,7 @@
#include "DlgSettingsNavigation.h"
#include "DlgSettingsSelection.h"
#include "DlgSettingsViewColor.h"
#include "DlgSettingsTheme.h"
#include "DlgGeneralImp.h"
#include "DlgEditorImp.h"
#include "DlgSettingsNotificationArea.h"
@@ -73,6 +74,7 @@ WidgetFactorySupplier::WidgetFactorySupplier()
new PrefPageProducer<DlgSettings3DViewImp> ( QT_TRANSLATE_NOOP("QObject","Display") );
new PrefPageProducer<DlgSettingsNavigation> ( QT_TRANSLATE_NOOP("QObject","Display") );
new PrefPageProducer<DlgSettingsViewColor> ( QT_TRANSLATE_NOOP("QObject","Display") );
new PrefPageProducer<DlgSettingsTheme> ( QT_TRANSLATE_NOOP("QObject","Display") );
new PrefPageProducer<DlgSettingsWorkbenchesImp> ( QT_TRANSLATE_NOOP("QObject","Workbenches") );
new PrefPageProducer<DlgSettingsMacroImp> ( QT_TRANSLATE_NOOP("QObject", "Python"));
new PrefPageProducer<DlgSettingsPythonConsole> ( QT_TRANSLATE_NOOP("QObject", "Python"));