From 05a2f03c18435067d2e60e7ef6a8d025479d1c6c Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 1 Sep 2024 14:17:41 +0000 Subject: [PATCH] Make use of the proposed new KColorScheme API Make use of new API proposed in frameworks/kcolorscheme!12 --- CMakeLists.txt | 2 +- src/colorschemer.cpp | 18 ++---------------- src/colorschemer.h | 14 ++------------ src/main.cpp | 3 --- src/neochatconfig.kcfg | 3 --- src/settings/ColorScheme.qml | 8 ++------ 6 files changed, 7 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70ccf8467..98b1006fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_ project(NeoChat VERSION ${RELEASE_SERVICE_VERSION}) -set(KF_MIN_VERSION "6.4") +set(KF_MIN_VERSION "6.6") set(QT_MIN_VERSION "6.5") find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE) diff --git a/src/colorschemer.cpp b/src/colorschemer.cpp index cad39bdb1..e54e6da14 100644 --- a/src/colorschemer.cpp +++ b/src/colorschemer.cpp @@ -26,23 +26,9 @@ void ColorSchemer::apply(int idx) c->activateScheme(c->model()->index(idx, 0)); } -void ColorSchemer::apply(const QString &name) +int ColorSchemer::indexForCurrentScheme() { - c->activateScheme(c->indexForScheme(name)); -} - -int ColorSchemer::indexForScheme(const QString &name) const -{ - auto index = c->indexForScheme(name).row(); - if (index == -1) { - index = 0; - } - return index; -} - -QString ColorSchemer::nameForIndex(int index) const -{ - return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString(); + return c->indexForSchemeId(c->activeSchemeId()).row(); } #include "moc_colorschemer.cpp" diff --git a/src/colorschemer.h b/src/colorschemer.h index f9e2a02e2..fae7910c4 100644 --- a/src/colorschemer.h +++ b/src/colorschemer.h @@ -44,21 +44,11 @@ public: Q_INVOKABLE void apply(int idx); /** - * @brief Activates the KColorScheme with the given name. + * @brief Get the row for the current color scheme. * * @sa KColorScheme */ - Q_INVOKABLE void apply(const QString &name); - - /** - * @brief Returns the index for the scheme with the given name. - */ - Q_INVOKABLE int indexForScheme(const QString &name) const; - - /** - * @brief Returns the name for the scheme with the given index. - */ - Q_INVOKABLE QString nameForIndex(int index) const; + Q_INVOKABLE int indexForCurrentScheme(); private: KColorSchemeManager *c; diff --git a/src/main.cpp b/src/main.cpp index 30cbeb60e..5de0e1dc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -185,9 +185,6 @@ int main(int argc, char *argv[]) #endif ColorSchemer colorScheme; - if (!NeoChatConfig::self()->colorScheme().isEmpty()) { - colorScheme.apply(NeoChatConfig::self()->colorScheme()); - } QCommandLineParser parser; parser.setApplicationDescription(i18n("Client for the matrix communication protocol")); diff --git a/src/neochatconfig.kcfg b/src/neochatconfig.kcfg index 6f59d8a67..b82e57d9a 100644 --- a/src/neochatconfig.kcfg +++ b/src/neochatconfig.kcfg @@ -15,9 +15,6 @@ - - - false diff --git a/src/settings/ColorScheme.qml b/src/settings/ColorScheme.qml index 175c7e913..d190b78d2 100644 --- a/src/settings/ColorScheme.qml +++ b/src/settings/ColorScheme.qml @@ -15,10 +15,6 @@ FormCard.FormComboBoxDelegate { textRole: "display" valueRole: "display" model: ColorSchemer.model - Component.onCompleted: currentIndex = ColorSchemer.indexForScheme(NeoChatConfig.colorScheme) - onCurrentValueChanged: { - ColorSchemer.apply(currentIndex); - NeoChatConfig.colorScheme = ColorSchemer.nameForIndex(currentIndex); - NeoChatConfig.save(); - } + Component.onCompleted: currentIndex = ColorSchemer.indexForCurrentScheme() + onCurrentValueChanged: ColorSchemer.apply(currentIndex); }