File indexing completed on 2024-09-15 04:28:26
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QQmlEngine> 0008 0009 class QAbstractItemModel; 0010 class KColorSchemeManager; 0011 0012 /** 0013 * @class ColorSchemer 0014 * 0015 * A class to provide a wrapper around KColorSchemeManager to make it available in 0016 * QML. 0017 * 0018 * @sa KColorSchemeManager 0019 */ 0020 class ColorSchemer : public QObject 0021 { 0022 Q_OBJECT 0023 QML_ELEMENT 0024 QML_SINGLETON 0025 0026 /** 0027 * @brief A QAbstractItemModel of all available color schemes. 0028 * 0029 * @sa QAbstractItemModel 0030 */ 0031 Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT) 0032 0033 public: 0034 explicit ColorSchemer(QObject *parent = nullptr); 0035 ~ColorSchemer(); 0036 0037 QAbstractItemModel *model() const; 0038 0039 /** 0040 * @brief Activates the KColorScheme identified by the provided index. 0041 * 0042 * @sa KColorScheme 0043 */ 0044 Q_INVOKABLE void apply(int idx); 0045 0046 /** 0047 * @brief Activates the KColorScheme with the given name. 0048 * 0049 * @sa KColorScheme 0050 */ 0051 Q_INVOKABLE void apply(const QString &name); 0052 0053 /** 0054 * @brief Returns the index for the scheme with the given name. 0055 */ 0056 Q_INVOKABLE int indexForScheme(const QString &name) const; 0057 0058 /** 0059 * @brief Returns the name for the scheme with the given index. 0060 */ 0061 Q_INVOKABLE QString nameForIndex(int index) const; 0062 0063 private: 0064 KColorSchemeManager *c; 0065 };