Move ColorSchemer to settings module
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
qt_add_library(settings STATIC)
|
||||
qt_add_library(Settings STATIC)
|
||||
|
||||
set_source_files_properties(
|
||||
RoomSettingsView.qml
|
||||
@@ -10,7 +10,7 @@ set_source_files_properties(
|
||||
QT_QML_SINGLETON_TYPE TRUE
|
||||
)
|
||||
|
||||
ecm_add_qml_module(settings GENERATE_PLUGIN_SOURCE
|
||||
ecm_add_qml_module(Settings GENERATE_PLUGIN_SOURCE
|
||||
URI org.kde.neochat.settings
|
||||
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat/settings
|
||||
QML_FILES
|
||||
@@ -44,4 +44,10 @@ ecm_add_qml_module(settings GENERATE_PLUGIN_SOURCE
|
||||
ExportKeysDialog.qml
|
||||
RoomSortParameterDialog.qml
|
||||
RoomProfile.qml
|
||||
SOURCES
|
||||
colorschemer.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(Settings PRIVATE
|
||||
KF6::ColorScheme
|
||||
)
|
||||
|
||||
34
src/settings/colorschemer.cpp
Normal file
34
src/settings/colorschemer.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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)
|
||||
{
|
||||
KColorSchemeManager::instance();
|
||||
}
|
||||
|
||||
ColorSchemer::~ColorSchemer()
|
||||
{
|
||||
}
|
||||
|
||||
QAbstractItemModel *ColorSchemer::model() const
|
||||
{
|
||||
return KColorSchemeManager::instance()->model();
|
||||
}
|
||||
|
||||
void ColorSchemer::apply(int idx)
|
||||
{
|
||||
KColorSchemeManager::instance()->activateScheme(KColorSchemeManager::instance()->model()->index(idx, 0));
|
||||
}
|
||||
|
||||
int ColorSchemer::indexForCurrentScheme()
|
||||
{
|
||||
return KColorSchemeManager::instance()->indexForSchemeId(KColorSchemeManager::instance()->activeSchemeId()).row();
|
||||
}
|
||||
|
||||
#include "moc_colorschemer.cpp"
|
||||
52
src/settings/colorschemer.h
Normal file
52
src/settings/colorschemer.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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 Get the row for the current color scheme.
|
||||
*
|
||||
* @sa KColorScheme
|
||||
*/
|
||||
Q_INVOKABLE int indexForCurrentScheme();
|
||||
};
|
||||
Reference in New Issue
Block a user