Move DlgSettingsTheme

This commit is contained in:
Paddle
2023-08-08 07:45:15 +02:00
committed by wwmayer
parent ccb9d7faeb
commit 8431d13bef
5 changed files with 8 additions and 8 deletions

View File

@@ -0,0 +1,164 @@
/***************************************************************************
* 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 <Gui/Application.h>
#include "DlgSettingsTheme.h"
#include "ui_DlgSettingsTheme.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();
ui->ThemeHighlightColor->onSave();
ui->ThemeFocusColor->onSave();
if (styleSheetChanged)
saveStyleSheet();
}
void DlgSettingsTheme::loadSettings()
{
ui->ThemeSecondaryColor->onRestore();
ui->ThemeHighlightColor->onRestore();
ui->ThemeFocusColor->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 <Gui/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

View File

@@ -0,0 +1,244 @@
<?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>
<item row="2" column="0">
<widget class="QLabel">
<property name="text">
<string>Highlight color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefColorButton" name="ThemeHighlightColor">
<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>ThemeHighlightColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Themes</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel">
<property name="text">
<string>Focus theme color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="ThemeFocusColor">
<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>ThemeFocusColor</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>