diff options
author | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2021-05-22 20:51:08 +0200 |
---|---|---|
committer | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2021-05-26 00:53:12 +0200 |
commit | e596e51739d02ea61c0ad37aee8b2c61c84d773f (patch) | |
tree | e734939f7e27ee8f946f1bee9bdce40da9bbbbc9 /src/preferences | |
parent | f28799864710bb82c8dfe58f9c51e89c90c8b4e5 (diff) |
DlgPrefInterface: Use QMap of skins
Diffstat (limited to 'src/preferences')
-rw-r--r-- | src/preferences/dialog/dlgprefinterface.cpp | 73 | ||||
-rw-r--r-- | src/preferences/dialog/dlgprefinterface.h | 8 |
2 files changed, 45 insertions, 36 deletions
diff --git a/src/preferences/dialog/dlgprefinterface.cpp b/src/preferences/dialog/dlgprefinterface.cpp index a4683f8ad0..b47cd9121e 100644 --- a/src/preferences/dialog/dlgprefinterface.cpp +++ b/src/preferences/dialog/dlgprefinterface.cpp @@ -32,6 +32,7 @@ DlgPrefInterface::DlgPrefInterface( m_pConfig(pConfig), m_mixxx(mixxx), m_pSkinLoader(pSkinLoader), + m_skin(QFileInfo(pSkinLoader->getConfiguredSkinPath())), m_dScaleFactorAuto(1.0), m_bUseAutoScaleFactor(false), m_dScaleFactor(1.0), @@ -110,28 +111,26 @@ DlgPrefInterface::DlgPrefInterface( skinDescriptionText->hide(); const QList<Skin> skins = m_pSkinLoader->getSkins(); - - QString configuredSkinPath = m_pSkinLoader->getConfiguredSkinPath(); int index = 0; - const auto* const pScreen = getScreen(); for (const Skin& skin : skins) { ComboBoxSkinconf->insertItem(index, skin.name()); - - if (skin.path() == configuredSkinPath) { - m_skin = skin.name(); - ComboBoxSkinconf->setCurrentIndex(index); - // schemes must be updated here to populate the drop-down box and set m_colorScheme - slotUpdateSchemes(); - skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin, m_colorScheme)); - if (skin.fitsScreenSize(*pScreen)) { - warningLabel->hide(); - } else { - warningLabel->show(); - } - slotSetSkinDescription(m_skin); - } + m_skins.insert(skin.name(), std::optional(skin)); index++; } + qWarning() << m_skins.keys(); + + ComboBoxSkinconf->setCurrentIndex(index); + // schemes must be updated here to populate the drop-down box and set m_colorScheme + slotUpdateSchemes(); + skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview( + m_skin.name(), m_colorScheme)); + const auto* const pScreen = getScreen(); + if (m_skin.fitsScreenSize(*pScreen)) { + warningLabel->hide(); + } else { + warningLabel->show(); + } + slotSetSkinDescription(m_skin.name()); connect(ComboBoxSkinconf, QOverload<int>::of(&QComboBox::currentIndexChanged), @@ -193,8 +192,7 @@ QScreen* DlgPrefInterface::getScreen() const { void DlgPrefInterface::slotUpdateSchemes() { // Re-populates the scheme combobox and attempts to pick the color scheme from config file. // Since this involves opening a file we won't do this as part of regular slotUpdate - const Skin skin(QFileInfo(m_pSkinLoader->getSkinPath(m_skin))); - QList<QString> schlist = skin.colorschemes(); + QList<QString> schlist = m_skin.colorschemes(); ComboBoxSchemeconf->clear(); @@ -228,11 +226,15 @@ void DlgPrefInterface::slotUpdateSchemes() { } void DlgPrefInterface::slotUpdate() { - m_skinOnUpdate = m_pConfig->getValueString(ConfigKey("[Config]", "ResizableSkin")); - if (m_skinOnUpdate.isEmpty()) { - m_skinOnUpdate = m_pSkinLoader->getDefaultSkinName(); + const QString skinNameOnUpdate = + m_pConfig->getValueString(ConfigKey("[Config]", "ResizableSkin")); + const std::optional<Skin> skinOnUpdate = m_skins[skinNameOnUpdate]; + if (skinOnUpdate) { + m_skinNameOnUpdate = (*skinOnUpdate).name(); + } else { + m_skinNameOnUpdate = m_pSkinLoader->getDefaultSkinName(); } - ComboBoxSkinconf->setCurrentIndex(ComboBoxSkinconf->findText(m_skinOnUpdate)); + ComboBoxSkinconf->setCurrentIndex(ComboBoxSkinconf->findText(m_skinNameOnUpdate)); slotUpdateSchemes(); m_bRebootMixxxView = false; @@ -334,7 +336,7 @@ void DlgPrefInterface::slotSetScheme(int) { m_colorScheme = newScheme; m_bRebootMixxxView = true; } - skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin, m_colorScheme)); + skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(m_skin.name(), m_colorScheme)); } void DlgPrefInterface::slotSetSkinDescription(const QString& skinName) { @@ -349,26 +351,29 @@ void DlgPrefInterface::slotSetSkinDescription(const QString& skinName) { } void DlgPrefInterface::slotSetSkin(int) { - QString newSkin = ComboBoxSkinconf->currentText(); - if (newSkin != m_skin) { - m_skin = newSkin; - const Skin skin(QFileInfo(m_pSkinLoader->getSkinPath(m_skin))); - m_bRebootMixxxView = newSkin != m_skinOnUpdate; + QString newSkinName = ComboBoxSkinconf->currentText(); + if (newSkinName != m_skin.name()) { + const std::optional<Skin> newSkin = m_skins[newSkinName]; + VERIFY_OR_DEBUG_ASSERT(newSkin) { + return; + } + m_skin = *newSkin; + m_bRebootMixxxView = newSkinName != m_skinNameOnUpdate; const auto* const pScreen = getScreen(); - if (pScreen && skin.fitsScreenSize(*pScreen)) { + if (pScreen && m_skin.fitsScreenSize(*pScreen)) { warningLabel->hide(); } else { warningLabel->show(); } slotUpdateSchemes(); - slotSetSkinDescription(m_skin); + slotSetSkinDescription(m_skin.name()); } - skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(newSkin, m_colorScheme)); + skinPreviewLabel->setPixmap(m_pSkinLoader->getSkinPreview(newSkinName, m_colorScheme)); } void DlgPrefInterface::slotApply() { - m_pConfig->set(ConfigKey("[Config]", "ResizableSkin"), m_skin); + m_pConfig->set(ConfigKey("[Config]", "ResizableSkin"), m_skin.name()); m_pConfig->set(ConfigKey("[Config]", "Scheme"), m_colorScheme); QString locale = ComboBoxLocale->itemData( @@ -407,7 +412,7 @@ void DlgPrefInterface::slotApply() { if (m_bRebootMixxxView) { m_mixxx->rebootMixxxView(); // Allow switching skins multiple times without closing the dialog - m_skinOnUpdate = m_skin; + m_skinNameOnUpdate = m_skin.name(); } m_bRebootMixxxView = false; } diff --git a/src/preferences/dialog/dlgprefinterface.h b/src/preferences/dialog/dlgprefinterface.h index 694abc2dc1..face751977 100644 --- a/src/preferences/dialog/dlgprefinterface.h +++ b/src/preferences/dialog/dlgprefinterface.h @@ -1,12 +1,15 @@ #pragma once +#include <QMap> #include <QWidget> #include <memory> +#include <optional> #include "preferences/constants.h" #include "preferences/dialog/dlgpreferencepage.h" #include "preferences/dialog/ui_dlgprefinterfacedlg.h" #include "preferences/usersettings.h" +#include "skin/legacy/skin.h" class ControlProxy; class ControlPotmeter; @@ -54,8 +57,9 @@ class DlgPrefInterface : public DlgPreferencePage, public Ui::DlgPrefControlsDlg MixxxMainWindow *m_mixxx; std::shared_ptr<SkinLoader> m_pSkinLoader; - QString m_skin; - QString m_skinOnUpdate; + QMap<QString, std::optional<mixxx::skin::legacy::Skin>> m_skins; + mixxx::skin::legacy::Skin m_skin; + QString m_skinNameOnUpdate; QString m_colorScheme; QString m_localeOnUpdate; mixxx::TooltipsPreference m_tooltipMode; |