diff --git a/kcms/icons/iconsmodel.cpp b/kcms/icons/iconsmodel.cpp --- a/kcms/icons/iconsmodel.cpp +++ b/kcms/icons/iconsmodel.cpp @@ -79,12 +79,11 @@ item.pendingDeletion = pendingDeletion; emit dataChanged(index, index, {PendingDeletionRole}); - // move to the next non-pending theme + // if we delete current selected theme move to the next non-pending theme const auto nonPending = match(index, PendingDeletionRole, false); - if (!nonPending.isEmpty()) { + if (index.row() == selectedThemeIndex() && !nonPending.isEmpty()) { setSelectedTheme(nonPending.first().data(ThemeNameRole).toString()); } - emit pendingDeletionsChanged(); return true; } diff --git a/kcms/icons/main.h b/kcms/icons/main.h --- a/kcms/icons/main.h +++ b/kcms/icons/main.h @@ -29,9 +29,10 @@ #include #include +#include #include -#include +#include class KIconTheme; class IconsSettings; @@ -80,11 +81,14 @@ Q_INVOKABLE void getNewStuff(QQuickItem *ctx); Q_INVOKABLE void installThemeFromFile(const QUrl &url); - Q_INVOKABLE QList availableIconSizes(int group); + Q_INVOKABLE QList availableIconSizes(int group) const; // QML doesn't understand QList, hence wrapped in a QVariantList Q_INVOKABLE QVariantList previewIcons(const QString &themeName, int size, qreal dpr, int limit = -1); + Q_INVOKABLE QString sizeDisplay(int index) const; + Q_INVOKABLE QString sizeSettingName(int index) const; + signals: void iconSizesChanged(); void downloadingFileChanged(); @@ -114,12 +118,30 @@ IconsModel *m_model; - QMap m_kicon_theme_map; + mutable QCache m_kiconThemeCache; QStringList m_iconGroups; QScopedPointer m_tempInstallFile; QPointer m_tempCopyJob; QPointer m_newStuffDialog; + + const QString m_sizeSettingNameArray[6] = { + QStringLiteral("desktopSize"), + QStringLiteral("toolbarSize"), + QStringLiteral("mainToolbarSize"), + QStringLiteral("smallSize"), + QStringLiteral("panelSize"), + QStringLiteral("dialogSize") + }; + + const QString m_sizeDisplayArray[6] = { + I18N_NOOP("Desktop"), + I18N_NOOP("Toolbar"), + I18N_NOOP("Main Toolbar"), + I18N_NOOP("Small Icons"), + I18N_NOOP("Panel"), + I18N_NOOP("Dialogs") + }; }; diff --git a/kcms/icons/main.cpp b/kcms/icons/main.cpp --- a/kcms/icons/main.cpp +++ b/kcms/icons/main.cpp @@ -98,18 +98,15 @@ setButtons(Apply | Default); - connect(m_model, SIGNAL(selectedThemeChanged()), this, SLOT(_k_settingsChanged())); - connect(m_model, SIGNAL(pendingDeletionsChanged()), this, SLOT(_k_settingsChanged())); + connect(m_model, &IconsModel::selectedThemeChanged, this, &IconModule::settingsChanged); + connect(m_model, &IconsModel::pendingDeletionsChanged, this, &IconModule::settingsChanged); // When user has a lot of themes installed, preview pixmaps might get evicted prematurely QPixmapCache::setCacheLimit(50 * 1024); // 50 MiB } IconModule::~IconModule() { - foreach (KIconTheme* theme, m_kicon_theme_map) { - delete theme; - } } IconsSettings *IconModule::iconsSettings() const @@ -132,13 +129,13 @@ return m_tempCopyJob; } -QList IconModule::availableIconSizes(int group) +QList IconModule::availableIconSizes(int group) const { - QString themeName(m_model->selectedTheme()); - if (!m_kicon_theme_map.contains(m_model->selectedTheme())) { - m_kicon_theme_map.insert(themeName, new KIconTheme(themeName)); + const auto themeName = m_model->selectedTheme(); + if (!m_kiconThemeCache.contains(m_model->selectedTheme())) { + m_kiconThemeCache.insert(themeName, new KIconTheme(themeName)); } - return m_kicon_theme_map[themeName]->querySizes(static_cast(group)); + return m_kiconThemeCache[themeName]->querySizes(static_cast(group)); } void IconModule::load() @@ -168,6 +165,9 @@ bool IconModule::isThemeDirty() const { + if (m_model->selectedThemeIndex() == -1) { + return false; + } return m_model->selectedTheme() != KIconTheme::current(); } @@ -533,4 +533,15 @@ return QPixmap(); } +QString IconModule::sizeDisplay(int index) const +{ + return m_sizeDisplayArray[index]; +} + +QString IconModule::sizeSettingName(int index) const +{ + return m_sizeSettingNameArray[index]; +} + + #include "main.moc" diff --git a/kcms/icons/package/contents/ui/IconSizePopup.qml b/kcms/icons/package/contents/ui/IconSizePopup.qml --- a/kcms/icons/package/contents/ui/IconSizePopup.qml +++ b/kcms/icons/package/contents/ui/IconSizePopup.qml @@ -77,25 +77,7 @@ highlightMoveDuration: 0 model: kcm.iconGroups - - property var sizesMap: [ - {"settingName":"desktopSize", "displayName": i18n("Desktop")}, - {"settingName":"toolbarSize", "displayName": i18n("Toolbar")}, - {"settingName":"mainToolbarSize", "displayName": i18n("Main Toolbar")}, - {"settingName":"smallSize", "displayName": i18n("Small Icons")}, - {"settingName":"panelSize", "displayName": i18n("Panel")}, - {"settingName":"dialogSize", "displayName": i18n("Dialogs")} - ] - - function sizeDisplayName(index) { - index = index <0 ? 0 : index; - return iconTypeList.sizesMap[index].displayName; - } - - function sizeSettingName(index) { - index = index <0 ? 0 : index; - return iconTypeList.sizesMap[index].settingName; - } + currentIndex: 0 // Initialize with the first item Keys.onLeftPressed: { LayoutMirroring.enabled ? iconSizeSlider.increase() : iconSizeSlider.decrease() @@ -109,7 +91,7 @@ delegate: QtControls.ItemDelegate { width: ListView.view.width highlighted: ListView.isCurrentItem - text: iconTypeList.sizeDisplayName(index) + text: kcm.sizeDisplay(index) onClicked: { ListView.view.currentIndex = index; @@ -131,14 +113,14 @@ enabled: sizes.length > 0 onMoved: { - kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] = iconSizeSlider.sizes[iconSizeSlider.value] || 0 + kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] = iconSizeSlider.sizes[iconSizeSlider.value] || 0 } function updateSizes() { // since the icon sizes are queried using invokables, always force an update when opening // in case the user clicked Default or something value = Qt.binding(function() { - var iconSize = kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] + var iconSize = kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] // I have no idea what this code does but it works and is just copied from the old KCM var index = -1; @@ -169,7 +151,7 @@ Kirigami.Icon { anchors.centerIn: parent - width: kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] + width: kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] height: width source: "folder" } @@ -179,7 +161,7 @@ id: iconSizeLabel Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter - text: kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] + text: kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] } } }