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] [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);