From 185ac83c5686c575eb9856c76c4f66a5c1463919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammet=20=C5=9E=C3=BCkr=C3=BC=20Demir?= <41967334+dsm@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:26:56 +0300 Subject: [PATCH] settings improvements. --- .gitignore | 3 +- qucs/dialogs/qucssettingsdialog.cpp | 114 ++++++++++++++++++++-------- qucs/dialogs/qucssettingsdialog.h | 5 +- qucs/main.cpp | 8 ++ qucs/settings.cpp | 6 +- 5 files changed, 99 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index e1e1299a..e9ea22d1 100644 --- a/.gitignore +++ b/.gitignore @@ -57,5 +57,6 @@ __pycache__ .vscode/settings.json .vscode/tasks.json /cmake-build-debug/ - +.cache/ +/qt/ build-qucs-s-spar-viewer-Desktop-Debug/ diff --git a/qucs/dialogs/qucssettingsdialog.cpp b/qucs/dialogs/qucssettingsdialog.cpp index b539a615..41626617 100644 --- a/qucs/dialogs/qucssettingsdialog.cpp +++ b/qucs/dialogs/qucssettingsdialog.cpp @@ -54,9 +54,24 @@ #include #include #include +#include +#include +#include using namespace std; +auto getFontDescription = [](const auto& Font) -> QString { + const QChar comma(u','); + QString fontDescription = Font.family() + comma + + QString::number(Font.pointSize()); + + QString fontStyle = Font.styleName(); + if (!fontStyle.isEmpty()) + fontDescription += comma + fontStyle; + + return fontDescription; +}; + QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent) : QDialog(parent) { @@ -75,30 +90,34 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent) QWidget *appSettingsTab = new QWidget(t); QGridLayout *appSettingsGrid = new QGridLayout(appSettingsTab); + const QStringList appLanguages = { + tr("system language"), + tr("English") + " (en)", + tr("Arabic") + " (ar)", + tr("Catalan") + " (ca)", + tr("Chinese") + " (zh_CN)", + tr("Czech") + " (cs)", + tr("French") + " (fr)", + tr("German") + " (de)", + tr("Hebrew") + " (he)", + tr("Hungarian") + " (hu)", + tr("Italian") + " (it)", + tr("Japanese") + " (jp)", + tr("Kazakh") + " (kk)", + tr("Polish") + " (pl)", + tr("Portuguese-BR") + " (pt_BR)", + tr("Portuguese-PT") + " (pt_PT)", + tr("Romanian") + " (ro)", + tr("Russian") + " (ru)", + tr("Spanish") + " (es)", + tr("Swedish") + " (sv)", + tr("Turkish") + " (tr)", + tr("Ukrainian") + " (uk)" + }; + appSettingsGrid->addWidget(new QLabel(tr("Language (set after reload):"), appSettingsTab) ,1, 0); LanguageCombo = new QComboBox(appSettingsTab); - LanguageCombo->insertItem(-1, tr("Ukrainian")+" (uk)"); - LanguageCombo->insertItem(-1, tr("Turkish")+" (tr)"); - LanguageCombo->insertItem(-1, tr("Swedish")+" (sv)"); - LanguageCombo->insertItem(-1, tr("Spanish")+" (es)"); - LanguageCombo->insertItem(-1, tr("Russian")+" (ru)"); - LanguageCombo->insertItem(-1, tr("Romanian")+" (ro)"); - LanguageCombo->insertItem(-1, tr("Portuguese-PT")+" (pt_PT)"); - LanguageCombo->insertItem(-1, tr("Portuguese-BR")+" (pt_BR)"); - LanguageCombo->insertItem(-1, tr("Polish")+" (pl)"); - LanguageCombo->insertItem(-1, tr("Kazakh")+" (kk)"); - LanguageCombo->insertItem(-1, tr("Japanese")+" (jp)"); - LanguageCombo->insertItem(-1, tr("Italian")+" (it)"); - LanguageCombo->insertItem(-1, tr("Hungarian")+" (hu)"); - LanguageCombo->insertItem(-1, tr("Hebrew")+" (he)"); - LanguageCombo->insertItem(-1, tr("German")+" (de)"); - LanguageCombo->insertItem(-1, tr("French")+" (fr)"); - LanguageCombo->insertItem(-1, tr("Chinese")+" (zh_CN)"); - LanguageCombo->insertItem(-1, tr("Czech")+" (cs)"); - LanguageCombo->insertItem(-1, tr("Catalan")+" (ca)"); - LanguageCombo->insertItem(-1, tr("Arabic")+" (ar)"); - LanguageCombo->insertItem(-1, tr("English")+" (en)"); - LanguageCombo->insertItem(-1, tr("system language")); + LanguageCombo->addItems(appLanguages); appSettingsGrid->addWidget(LanguageCombo, 1, 1); val200 = new QIntValidator(0, 200, this); @@ -181,7 +200,21 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent) appAppearanceGrid->addWidget(new QLabel(tr("Default graph line thickness:"), appSettingsTab), 8, 0); graphLineWidthEdit = new QLineEdit(appSettingsTab); graphLineWidthEdit->setValidator(val50); - appAppearanceGrid->addWidget(graphLineWidthEdit, 8, 1); + appAppearanceGrid->addWidget(graphLineWidthEdit, 8, 1); + + appAppearanceGrid->addWidget(new QLabel(tr("App Style:"), appSettingsTab), 9, 0); + QStringList styles = QStyleFactory::keys(); // Get available styles + StyleCombo = new QComboBox(appSettingsTab); + StyleCombo->addItems(styles); + appAppearanceGrid->addWidget(StyleCombo,9,1); + + + // Retrieve the current style and set it as selected + QString currentStyle = QApplication::style()->objectName(); + int index = StyleCombo->findText(currentStyle, Qt::MatchFixedString); + if (index != -1) { + StyleCombo->setCurrentIndex(index); + } t->addTab(appAppearanceTab, tr("Appearance")); @@ -456,9 +489,12 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent) Font = QucsSettings.font; AppFont = QucsSettings.appFont; TextFont = QucsSettings.textFont; - FontButton->setText(Font.toString()); - AppFontButton->setText(AppFont.toString()); - TextFontButton->setText(TextFont.toString()); + + + + FontButton->setText(getFontDescription(Font)); + AppFontButton->setText(getFontDescription(AppFont)); + TextFontButton->setText(getFontDescription(TextFont)); QString s = QString::number(QucsSettings.largeFontSize, 'f', 1); LargeFontSizeEdit->setText(s); graphLineWidthEdit->setText(_settings::Get().item("DefaultGraphLineWidth")); @@ -595,10 +631,22 @@ void QucsSettingsDialog::slotApply() QPalette p = vp->palette(); p.setColor(vp->backgroundRole(), QucsSettings.BGColor); vp->setPalette(p); + } changed = true; } + QString selectedStyle = StyleCombo->currentText(); + if (_settings::Get().item("AppStyle") != selectedStyle ) + { + QStyle* style = QStyleFactory::create(selectedStyle); + if (style) { + QApplication::setStyle(style); + _settings::Get().setItem("AppStyle", selectedStyle); + changed = true; + } + } + // Update all open schematics with the new grid color. if (_settings::Get().item("GridColor") != GridColorButton->palette().color(GridColorButton->backgroundRole())) { _settings::Get().setItem("GridColor", GridColorButton->palette().color(GridColorButton->backgroundRole())); @@ -769,7 +817,7 @@ void QucsSettingsDialog::slotFontDialog() if(ok) { Font = tmpFont; - FontButton->setText(Font.toString()); + FontButton->setText(getFontDescription(Font)); } } @@ -780,7 +828,7 @@ void QucsSettingsDialog::slotAppFontDialog() if(ok) { AppFont = tmpFont; - AppFontButton->setText(AppFont.toString()); + AppFontButton->setText(getFontDescription(AppFont)); } } @@ -791,7 +839,7 @@ void QucsSettingsDialog::slotTextFontDialog() if(ok) { TextFont = tmpFont; - TextFontButton->setText(TextFont.toString()); + TextFontButton->setText(getFontDescription(TextFont)); } } @@ -828,13 +876,13 @@ void QucsSettingsDialog::slotDefaultValues() Font = QApplication::font(); AppFont = QucsSettings.sysDefaultFont; TextFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); - FontButton->setText(Font.toString()); - AppFontButton->setText(AppFont.toString()); - TextFontButton->setText(TextFont.toString()); + FontButton->setText(getFontDescription(Font)); + AppFontButton->setText(getFontDescription(AppFont)); + TextFontButton->setText(getFontDescription(TextFont)); LargeFontSizeEdit->setText(QString::number(16.0)); LanguageCombo->setCurrentIndex(0); - + p = BGColorButton->palette(); p.setColor(BGColorButton->backgroundRole(), QColor(255,250,225)); BGColorButton->setPalette(p); diff --git a/qucs/dialogs/qucssettingsdialog.h b/qucs/dialogs/qucssettingsdialog.h index 318882bf..b928a5bd 100644 --- a/qucs/dialogs/qucssettingsdialog.h +++ b/qucs/dialogs/qucssettingsdialog.h @@ -88,7 +88,8 @@ public: QCheckBox *checkWiring, *checkLoadFromFutureVersions, *checkAntiAliasing, *checkTextAntiAliasing, *checkFullTraceNames; - QComboBox *LanguageCombo; + QComboBox *LanguageCombo, + *StyleCombo; QPushButton *FontButton, *AppFontButton, *TextFontButton, *BGColorButton, *GridColorButton; QLineEdit *LargeFontSizeEdit, *undoNumEdit, *editorEdit, *Input_Suffix, *Input_Program, *homeEdit, *admsXmlEdit, *ascoEdit, *octaveEdit, @@ -108,7 +109,7 @@ public: private: QStringList currentPaths; - + private: void makePathTable(); diff --git a/qucs/main.cpp b/qucs/main.cpp index 287cd5b8..cf0797f8 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -783,6 +783,14 @@ int main(int argc, char *argv[]) // load existing settings (if any) loadSettings(); + /* restore saved style */ + QString savedStyle = _settings::Get().item("AppStyle"); + QStyle* style = QStyleFactory::create(savedStyle); + if (style) { + QApplication::setStyle(style); + } + /* restore saved style */ + QDir().mkpath(QucsSettings.qucsWorkspaceDir.absolutePath()); QDir().mkpath(QucsSettings.tempFilesDir.absolutePath()); diff --git a/qucs/settings.cpp b/qucs/settings.cpp index 6df63fb9..7e462d76 100644 --- a/qucs/settings.cpp +++ b/qucs/settings.cpp @@ -61,7 +61,11 @@ void settingsManager::initDefaults() m_Defaults["OctaveExecutable"] = "octave.exe"; #else m_Defaults["NgspiceExecutable"] = "ngspice"; - m_Defaults["XyceExecutable"] = "/usr/local/Xyce-Release-6.8.0-OPENSOURCE/bin/Xyce"; + #ifndef Q_OS_MACOS + m_Defaults["XyceExecutable"] = "/usr/local/Xyce-Release-6.8.0-OPENSOURCE/bin/Xyce"; + #else + m_Defaults["XyceExecutable"] = "Xyce"; + #endif m_Defaults["RFLayoutExecutable"] = "qucsrflayout"; m_Defaults["OctaveExecutable"] = "octave"; #endif