From dbb7c6e5b8c7c6281ec82071c2eaa838e8a1122c Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:50:26 +0100 Subject: [PATCH 1/2] [Gui] Preferences - fix the theme combobox index lookup... ...when the user has FreeCAD-themes (and no doubt other theme addons) installed. --- .../PreferencePages/DlgSettingsGeneral.cpp | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index 9030ecd9e2..4980894b63 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -425,18 +425,44 @@ void DlgSettingsGeneral::loadThemes() { ui->themesCombobox->clear(); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/MainWindow"); QString currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str()); Application::Instance->prefPackManager()->rescan(); auto packs = Application::Instance->prefPackManager()->preferencePacks(); + QString currentStyleSheet = QString::fromLatin1(hGrp->GetASCII("StyleSheet", "").c_str()); + QFileInfo fi(currentStyleSheet); + currentStyleSheet = fi.baseName(); + QString themeClassic = QString::fromStdString("classic"); // handle the upcoming name change + QString similarTheme; + QString packName; for (const auto& pack : packs) { if (pack.second.metadata().type() == "Theme") { + packName = QString::fromStdString(pack.first); + if (packName.contains(themeClassic, Qt::CaseInsensitive)) { + themeClassic = QString::fromStdString(pack.first); + } + if (packName.contains(currentStyleSheet, Qt::CaseInsensitive)) { + similarTheme = QString::fromStdString(pack.first); + } ui->themesCombobox->addItem(QString::fromStdString(pack.first)); } } + if (currentTheme.isEmpty()) { + if (!currentStyleSheet.isEmpty() + && !similarTheme.isEmpty()) { // a user upgrading from 0.21 or earlier + hGrp->SetASCII("Theme", similarTheme.toStdString()); + currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str()); + } + else { // a brand new user + hGrp->SetASCII("Theme", themeClassic.toStdString()); + currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str()); + } + } + int index = ui->themesCombobox->findText(currentTheme); if (index >= 0 && index < ui->themesCombobox->count()) { ui->themesCombobox->setCurrentIndex(index); From 6669aa55f79d44cc8f7fbf50ecf95fcc819c7e11 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:17:58 +0100 Subject: [PATCH 2/2] [Gui] Apply requested changes --- src/Gui/PreferencePages/DlgSettingsGeneral.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index 4980894b63..2d2830e60a 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -329,8 +329,9 @@ void DlgSettingsGeneral::loadSettings() } QAbstractItemModel* model = ui->Languages->model(); - if (model) + if (model) { model->sort(0); + } addIconSizes(getCurrentIconSize()); @@ -435,7 +436,7 @@ void DlgSettingsGeneral::loadThemes() QString currentStyleSheet = QString::fromLatin1(hGrp->GetASCII("StyleSheet", "").c_str()); QFileInfo fi(currentStyleSheet); currentStyleSheet = fi.baseName(); - QString themeClassic = QString::fromStdString("classic"); // handle the upcoming name change + QString themeClassic = QStringLiteral("classic"); // handle the upcoming name change QString similarTheme; QString packName; for (const auto& pack : packs) {