File indexing completed on 2024-05-26 05:08:24
0001 /* 0002 SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "ksettingsicons.h" 0007 0008 // ---------------------------------------------------------------------------- 0009 // QT Includes 0010 0011 #include <QIcon> 0012 #include <QDir> 0013 0014 // ---------------------------------------------------------------------------- 0015 // KDE Includes 0016 0017 // ---------------------------------------------------------------------------- 0018 // Project Includes 0019 0020 #include "ui_ksettingsicons.h" 0021 0022 class KSettingsIconsPrivate 0023 { 0024 Q_DISABLE_COPY(KSettingsIconsPrivate) 0025 0026 public: 0027 KSettingsIconsPrivate() : 0028 ui(new Ui::KSettingsIcons) 0029 { 0030 } 0031 0032 ~KSettingsIconsPrivate() 0033 { 0034 delete ui; 0035 } 0036 0037 Ui::KSettingsIcons *ui; 0038 QMap<int, QString> m_themesMap; 0039 }; 0040 0041 KSettingsIcons::KSettingsIcons(QWidget* parent) : 0042 QWidget(parent), 0043 d_ptr(new KSettingsIconsPrivate) 0044 { 0045 Q_D(KSettingsIcons); 0046 d->ui->setupUi(this); 0047 // hide the internally used holidayRegion field 0048 d->ui->kcfg_IconsTheme->hide(); 0049 0050 loadList(); 0051 0052 // setup connections so that region gets selected once field is filled 0053 connect(d->ui->kcfg_IconsTheme, &QLineEdit::textChanged, this, &KSettingsIcons::slotLoadTheme); 0054 0055 // setup connections so that changes are forwarded to the field 0056 connect(d->ui->m_IconsTheme, 0057 static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KSettingsIcons::slotSetTheme); 0058 } 0059 0060 KSettingsIcons::~KSettingsIcons() 0061 { 0062 Q_D(KSettingsIcons); 0063 delete d; 0064 } 0065 0066 void KSettingsIcons::loadList() 0067 { 0068 Q_D(KSettingsIcons); 0069 QStringList themes {QStringLiteral("oxygen"), QStringLiteral("Tango"), QStringLiteral("breeze"), QStringLiteral("breeze-dark")}; 0070 QStringList searchPaths = QIcon::themeSearchPaths(); 0071 d->ui->m_IconsTheme->addItem(QStringLiteral("system")); 0072 d->m_themesMap.insert(0, QStringLiteral("system")); 0073 for (auto i = 0; i < searchPaths.count(); ++i) { 0074 for (int j = 0; j < themes.count(); ++j) { 0075 QDir themeDir = QDir(searchPaths.at(i)).filePath(themes.at(j)); 0076 if (themeDir.exists(QStringLiteral("index.theme"))) { 0077 d->ui->m_IconsTheme->addItem(themes.at(j)); 0078 d->m_themesMap.insert(d->m_themesMap.count(), themes.at(j)); 0079 } 0080 } 0081 } 0082 } 0083 0084 void KSettingsIcons::slotSetTheme(const int &theme) 0085 { 0086 Q_D(KSettingsIcons); 0087 d->ui->kcfg_IconsTheme->setText(d->m_themesMap.value(theme)); 0088 } 0089 0090 void KSettingsIcons::slotLoadTheme(const QString &theme) 0091 { 0092 Q_D(KSettingsIcons); 0093 // only need this once 0094 disconnect(d->ui->kcfg_IconsTheme, &QLineEdit::textChanged, this, &KSettingsIcons::slotLoadTheme); 0095 auto i = 0; 0096 if (!theme.isEmpty()) 0097 i = d->ui->m_IconsTheme->findText(theme); 0098 if ((i > -1) && (i != d->ui->m_IconsTheme->currentIndex())) { 0099 QSignalBlocker blocked(d->ui->m_IconsTheme); 0100 d->ui->m_IconsTheme->setCurrentIndex(i); 0101 } 0102 } 0103 0104 void KSettingsIcons::slotResetTheme() 0105 { 0106 Q_D(KSettingsIcons); 0107 slotLoadTheme(d->ui->kcfg_IconsTheme->text()); 0108 }