File indexing completed on 2025-01-05 04:29:55

0001 /**
0002  * SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0003  * SPDX-FileCopyrightText: 2023 Bart De Vries <bart@mogwai.be>
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QQmlEngine>
0011 #include <QtQml>
0012 
0013 class QAbstractItemModel;
0014 class KColorSchemeManager;
0015 
0016 class ColorSchemer : public QObject
0017 {
0018     Q_OBJECT
0019     QML_ELEMENT
0020     QML_SINGLETON
0021 
0022     Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT)
0023 
0024 public:
0025     static ColorSchemer *create(QQmlEngine *, QJSEngine *)
0026     {
0027         auto inst = &instance();
0028         QJSEngine::setObjectOwnership(inst, QJSEngine::ObjectOwnership::CppOwnership);
0029         return inst;
0030     }
0031 
0032     explicit ColorSchemer(QObject *parent = nullptr);
0033 
0034     static ColorSchemer &instance();
0035 
0036     QAbstractItemModel *model() const;
0037     Q_INVOKABLE void apply(int idx);
0038     Q_INVOKABLE void apply(const QString &name);
0039     Q_INVOKABLE int indexForScheme(const QString &name) const;
0040     Q_INVOKABLE QString nameForIndex(int index) const;
0041 
0042 private:
0043     KColorSchemeManager *c;
0044 };