| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#include <QPushButton> |
| 24 |
|
| 25 |
|
| 26 |
#include <Gui/Application.h> |
| 27 |
#include <Gui/ParamHandler.h> |
| 28 |
|
| 29 |
#include "DlgSettingsUI.h" |
| 30 |
#include "ui_DlgSettingsUI.h" |
| 31 |
|
| 32 |
#include "Dialogs/DlgThemeEditor.h" |
| 33 |
|
| 34 |
#include <Base/ServiceProvider.h> |
| 35 |
|
| 36 |
|
| 37 |
using namespace Gui::Dialog; |
| 38 |
|
| 39 |
/* TRANSLATOR Gui::Dialog::DlgSettingsUI */ |
| 40 |
|
| 41 |
/** |
| 42 |
* Constructs a DlgSettingsUI which is a child of 'parent', with the |
| 43 |
* name 'name' and widget flags set to 'f' |
| 44 |
*/ |
| 45 |
DlgSettingsUI::DlgSettingsUI(QWidget* parent) |
| 46 |
: PreferencePage(parent) |
| 47 |
, ui(new Ui_DlgSettingsUI) |
| 48 |
{ |
| 49 |
ui->setupUi(this); |
| 50 |
|
| 51 |
connect(ui->themeEditorButton, &QPushButton::clicked, [this]() { openThemeEditor(); }); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Destroys the object and frees any allocated resources |
| 56 |
*/ |
| 57 |
DlgSettingsUI::~DlgSettingsUI() = default; |
| 58 |
|
| 59 |
void DlgSettingsUI::saveSettings() |
| 60 |
{ |
| 61 |
// Theme |
| 62 |
ui->ThemeAccentColor1->onSave(); |
| 63 |
ui->ThemeAccentColor2->onSave(); |
| 64 |
ui->ThemeAccentColor3->onSave(); |
| 65 |
ui->StyleSheets->onSave(); |
| 66 |
ui->OverlayStyleSheets->onSave(); |
| 67 |
|
| 68 |
// Tree View |
| 69 |
ui->fontSizeSpinBox->onSave(); |
| 70 |
ui->iconSizeSpinBox->onSave(); |
| 71 |
ui->resizableColumnsCheckBox->onSave(); |
| 72 |
ui->showVisibilityIconCheckBox->onSave(); |
| 73 |
ui->hideDescriptionCheckBox->onSave(); |
| 74 |
ui->hideInternalNamesCheckBox->onSave(); |
| 75 |
ui->hideTreeViewScrollBarCheckBox->onSave(); |
| 76 |
ui->hideHeaderCheckBox->onSave(); |
| 77 |
|
| 78 |
// Overlay |
| 79 |
ui->hideTabBarCheckBox->onSave(); |
| 80 |
ui->hintShowTabBarCheckBox->onSave(); |
| 81 |
ui->hidePropertyViewScrollBarCheckBox->onSave(); |
| 82 |
ui->overlayAutoHideCheckBox->onSave(); |
| 83 |
ui->mouseClickPassThroughCheckBox->onSave(); |
| 84 |
ui->mouseWheelPassThroughCheckBox->onSave(); |
| 85 |
|
| 86 |
// TaskWatcher |
| 87 |
ui->showTaskWatcherCheckBox->onSave(); |
| 88 |
} |
| 89 |
|
| 90 |
void DlgSettingsUI::loadSettings() |
| 91 |
{ |
| 92 |
// Theme |
| 93 |
ui->ThemeAccentColor1->onRestore(); |
| 94 |
ui->ThemeAccentColor2->onRestore(); |
| 95 |
ui->ThemeAccentColor3->onRestore(); |
| 96 |
|
| 97 |
// Tree View |
| 98 |
ui->fontSizeSpinBox->onRestore(); |
| 99 |
ui->iconSizeSpinBox->onRestore(); |
| 100 |
ui->resizableColumnsCheckBox->onRestore(); |
| 101 |
ui->showVisibilityIconCheckBox->onRestore(); |
| 102 |
ui->hideDescriptionCheckBox->onRestore(); |
| 103 |
ui->hideInternalNamesCheckBox->onRestore(); |
| 104 |
ui->hideTreeViewScrollBarCheckBox->onRestore(); |
| 105 |
ui->hideHeaderCheckBox->onRestore(); |
| 106 |
|
| 107 |
// Overlay |
| 108 |
ui->hideTabBarCheckBox->onRestore(); |
| 109 |
ui->hintShowTabBarCheckBox->onRestore(); |
| 110 |
ui->hidePropertyViewScrollBarCheckBox->onRestore(); |
| 111 |
ui->overlayAutoHideCheckBox->onRestore(); |
| 112 |
ui->mouseClickPassThroughCheckBox->onRestore(); |
| 113 |
ui->mouseWheelPassThroughCheckBox->onRestore(); |
| 114 |
|
| 115 |
// TaskWatcher |
| 116 |
ui->showTaskWatcherCheckBox->onRestore(); |
| 117 |
|
| 118 |
loadStyleSheet(); |
| 119 |
} |
| 120 |
|
| 121 |
void DlgSettingsUI::loadStyleSheet() |
| 122 |
{ |
| 123 |
static std::string translatedString; // Make sure the memory doesn't disappear on us |
| 124 |
translatedString = tr("No style sheet").toStdString(); |
| 125 |
populateStylesheets("StyleSheet", "qss", ui->StyleSheets, translatedString.c_str()); |
| 126 |
populateStylesheets("OverlayActiveStyleSheet", "overlay", ui->OverlayStyleSheets, "Auto"); |
| 127 |
} |
| 128 |
|
| 129 |
void DlgSettingsUI::populateStylesheets( |
| 130 |
const char* key, |
| 131 |
const char* path, |
| 132 |
PrefComboBox* combo, |
| 133 |
const char* def, |
| 134 |
QStringList filter |
| 135 |
) |
| 136 |
{ |
| 137 |
auto hGrp = App::GetApplication().GetParameterGroupByPath( |
| 138 |
"User parameter:BaseApp/Preferences/MainWindow" |
| 139 |
); |
| 140 |
// List all .qss/.css files |
| 141 |
QMap<QString, QString> cssFiles; |
| 142 |
QDir dir; |
| 143 |
if (filter.isEmpty()) { |
| 144 |
filter << QStringLiteral("*.qss"); |
| 145 |
filter << QStringLiteral("*.css"); |
| 146 |
} |
| 147 |
QFileInfoList fileNames; |
| 148 |
|
| 149 |
// read from user, resource and built-in directory |
| 150 |
QStringList qssPaths = QDir::searchPaths(QString::fromUtf8(path)); |
| 151 |
for (QStringList::iterator it = qssPaths.begin(); it != qssPaths.end(); ++it) { |
| 152 |
dir.setPath(*it); |
| 153 |
fileNames = dir.entryInfoList(filter, QDir::Files, QDir::Name); |
| 154 |
for (QFileInfoList::iterator jt = fileNames.begin(); jt != fileNames.end(); ++jt) { |
| 155 |
if (cssFiles.find(jt->baseName()) == cssFiles.end()) { |
| 156 |
cssFiles[jt->baseName()] = jt->fileName(); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
combo->clear(); |
| 162 |
|
| 163 |
// now add all unique items |
| 164 |
combo->addItem(tr(def), QStringLiteral("")); |
| 165 |
for (QMap<QString, QString>::iterator it = cssFiles.begin(); it != cssFiles.end(); ++it) { |
| 166 |
combo->addItem(it.key(), it.value()); |
| 167 |
} |
| 168 |
|
| 169 |
QString selectedStyleSheet = QString::fromUtf8(hGrp->GetASCII(key).c_str()); |
| 170 |
int index = combo->findData(selectedStyleSheet); |
| 171 |
|
| 172 |
// might be an absolute path name |
| 173 |
if (index < 0 && !selectedStyleSheet.isEmpty()) { |
| 174 |
QFileInfo fi(selectedStyleSheet); |
| 175 |
if (fi.isAbsolute()) { |
| 176 |
QString path = fi.absolutePath(); |
| 177 |
if (qssPaths.indexOf(path) >= 0) { |
| 178 |
selectedStyleSheet = fi.fileName(); |
| 179 |
} |
| 180 |
else { |
| 181 |
selectedStyleSheet = fi.absoluteFilePath(); |
| 182 |
combo->addItem(fi.baseName(), selectedStyleSheet); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
combo->setCurrentIndex(index); |
| 188 |
combo->onRestore(); |
| 189 |
} |
| 190 |
|
| 191 |
void DlgSettingsUI::openThemeEditor() |
| 192 |
{ |
| 193 |
Gui::DlgThemeEditor editor; |
| 194 |
editor.exec(); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Sets the strings of the subwidgets using the current language. |
| 199 |
*/ |
| 200 |
void DlgSettingsUI::changeEvent(QEvent* e) |
| 201 |
{ |
| 202 |
if (e->type() == QEvent::LanguageChange) { |
| 203 |
ui->retranslateUi(this); |
| 204 |
loadStyleSheet(); |
| 205 |
} |
| 206 |
else { |
| 207 |
QWidget::changeEvent(e); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
#include "moc_DlgSettingsUI.cpp" |