Compare commits

...

1 Commits

Author SHA1 Message Date
James Graham
6c182265b1 Now the KColorSchemeManager has QML API ColorSchemer is unnescessary so remove it. 2024-09-01 15:04:37 +01:00
5 changed files with 6 additions and 127 deletions

View File

@@ -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

View File

@@ -1,48 +0,0 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include <KColorSchemeManager>
#include <QAbstractItemModel>
#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"

View File

@@ -1,65 +0,0 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include <QObject>
#include <QQmlEngine>
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;
};

View File

@@ -37,6 +37,7 @@
#include <KCrash>
#endif
#include <KColorSchemeManager>
#include <KLocalizedContext>
#include <KLocalizedString>
@@ -45,7 +46,6 @@
#include <Quotient/networkaccessmanager.h>
#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"));

View File

@@ -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;
}