From 6c182265b1054aade9082d85841807cc3311b19d Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 1 Sep 2024 15:03:52 +0100 Subject: [PATCH] Now the KColorSchemeManager has QML API ColorSchemer is unnescessary so remove it. --- src/CMakeLists.txt | 2 -- src/colorschemer.cpp | 48 -------------------------- src/colorschemer.h | 65 ------------------------------------ src/main.cpp | 7 ++-- src/settings/ColorScheme.qml | 11 +++--- 5 files changed, 6 insertions(+), 127 deletions(-) delete mode 100644 src/colorschemer.cpp delete mode 100644 src/colorschemer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bbe2c1a83..1f0556587 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,8 +144,6 @@ add_library(neochat STATIC roomlastmessageprovider.h chatbarcache.cpp chatbarcache.h - colorschemer.cpp - colorschemer.h models/notificationsmodel.cpp models/notificationsmodel.h models/timelinemodel.cpp diff --git a/src/colorschemer.cpp b/src/colorschemer.cpp deleted file mode 100644 index cad39bdb1..000000000 --- a/src/colorschemer.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Carl Schwan -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include -#include - -#include "colorschemer.h" - -ColorSchemer::ColorSchemer(QObject *parent) - : QObject(parent) - , c(new KColorSchemeManager(this)) -{ -} - -ColorSchemer::~ColorSchemer() -{ -} - -QAbstractItemModel *ColorSchemer::model() const -{ - return c->model(); -} - -void ColorSchemer::apply(int idx) -{ - c->activateScheme(c->model()->index(idx, 0)); -} - -void ColorSchemer::apply(const QString &name) -{ - 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(); -} - -#include "moc_colorschemer.cpp" diff --git a/src/colorschemer.h b/src/colorschemer.h deleted file mode 100644 index f9e2a02e2..000000000 --- a/src/colorschemer.h +++ /dev/null @@ -1,65 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Carl Schwan -// SPDX-License-Identifier: LGPL-2.1-or-later - -#pragma once - -#include -#include - -class QAbstractItemModel; -class KColorSchemeManager; - -/** - * @class ColorSchemer - * - * A class to provide a wrapper around KColorSchemeManager to make it available in - * QML. - * - * @sa KColorSchemeManager - */ -class ColorSchemer : public QObject -{ - Q_OBJECT - QML_ELEMENT - QML_SINGLETON - - /** - * @brief A QAbstractItemModel of all available color schemes. - * - * @sa QAbstractItemModel - */ - Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT) - -public: - explicit ColorSchemer(QObject *parent = nullptr); - ~ColorSchemer(); - - QAbstractItemModel *model() const; - - /** - * @brief Activates the KColorScheme identified by the provided index. - * - * @sa KColorScheme - */ - Q_INVOKABLE void apply(int idx); - - /** - * @brief Activates the KColorScheme with the given name. - * - * @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; - -private: - KColorSchemeManager *c; -}; diff --git a/src/main.cpp b/src/main.cpp index 30cbeb60e..2ebdf7397 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ #include #endif +#include #include #include @@ -45,7 +46,6 @@ #include #include "blurhashimageprovider.h" -#include "colorschemer.h" #include "controller.h" #include "logger.h" #include "neochatconfig.h" @@ -184,10 +184,7 @@ int main(int argc, char *argv[]) QStringLiteral("/var/config/fontconfig/conf.d/99-noto-mono-color-emoji.conf")); #endif - ColorSchemer colorScheme; - if (!NeoChatConfig::self()->colorScheme().isEmpty()) { - colorScheme.apply(NeoChatConfig::self()->colorScheme()); - } + KColorSchemeManager::instance(); QCommandLineParser parser; parser.setApplicationDescription(i18n("Client for the matrix communication protocol")); diff --git a/src/settings/ColorScheme.qml b/src/settings/ColorScheme.qml index 175c7e913..52d709c01 100644 --- a/src/settings/ColorScheme.qml +++ b/src/settings/ColorScheme.qml @@ -5,6 +5,7 @@ import QtQuick import QtQuick.Layouts import org.kde.kirigamiaddons.formcard as FormCard +import org.kde.colorscheme import org.kde.neochat @@ -14,11 +15,7 @@ FormCard.FormComboBoxDelegate { text: i18n("Color theme") 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(); - } + model: ColorSchemeManager.model + Component.onCompleted: currentIndex = ColorSchemeManager.rowForCurrentScheme + onCurrentValueChanged: ColorSchemeManager.rowForCurrentScheme = currentIndex; }