aboutsummaryrefslogtreecommitdiffstats
path: root/src/clapcontrols/qtclapstyle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/clapcontrols/qtclapstyle.h')
-rw-r--r--src/clapcontrols/qtclapstyle.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/clapcontrols/qtclapstyle.h b/src/clapcontrols/qtclapstyle.h
new file mode 100644
index 0000000..51905fc
--- /dev/null
+++ b/src/clapcontrols/qtclapstyle.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Qt-Commercial
+
+#ifndef QTCLAPCONTROLS_H
+#define QTCLAPCONTROLS_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qmap.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qanystringview.h>
+#include <QtCore/qdiriterator.h>
+#include <QtGui/qcolor.h>
+#include <QtQml/qqml.h>
+
+class QClapStyle : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+ QML_UNCREATABLE("QtClapStyle is an utility class")
+
+ Q_PROPERTY(QStringList themes READ themes NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QStringList fonts READ fonts NOTIFY fontChanged FINAL)
+
+ struct NamePath { QString name, path; };
+ static constexpr QAnyStringView QrcBasePath = ":/qt/qml/Clap/Controls/";
+public:
+ explicit QClapStyle(QObject* parent = nullptr);
+
+ bool initThemes(QAnyStringView schemeDir = QString(QrcBasePath.toString() + "themes"));
+ bool initFonts(QAnyStringView fontDir = QString(QrcBasePath.toString() + "fonts"));
+
+ Q_INVOKABLE bool loadTheme(qsizetype idx);
+ Q_INVOKABLE bool loadFont(qsizetype idx);
+ Q_INVOKABLE QColor color(QString name) const;
+
+ QString activeTheme(qsizetype idx) const;
+ QString activeFont(qsizetype idx) const;
+
+ QStringList themes() const;
+ QStringList fonts() const;
+
+signals:
+ void themeChanged();
+ void fontChanged();
+
+private:
+ std::map<QString, QColor> activeColors;
+ QList<NamePath> themesList;
+ QList<NamePath> fontsList;
+ qsizetype activeThemeIdx = -1;
+ qsizetype activeFontIdx = -1;
+ int activeFontId = -1;
+};
+
+
+#endif // QTCLAPCONTROLS_H