1 | // Copyright (C) 2022 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QGTK3JSON_P_H |
4 | #define QGTK3JSON_P_H |
5 | |
6 | #include <QtCore/QCache> |
7 | #include <QtCore/QJsonArray> |
8 | #include <QtCore/QJsonDocument> |
9 | #include <QtCore/QJsonObject> |
10 | #include <QtCore/QMap> |
11 | #include <QtCore/QString> |
12 | #include <QtGui/QGuiApplication> |
13 | #include <QtGui/QPalette> |
14 | |
15 | #include <qpa/qplatformtheme.h> |
16 | #include "qgtk3interface_p.h" |
17 | #include "qgtk3storage_p.h" |
18 | |
19 | #undef signals // Collides with GTK symbols |
20 | #include <gtk/gtk.h> |
21 | #include <gdk/gdk.h> |
22 | #include <glib.h> |
23 | |
24 | // |
25 | // W A R N I N G |
26 | // ------------- |
27 | // |
28 | // This file is not part of the Qt API. It exists purely as an |
29 | // implementation detail. This header file may change from version to |
30 | // version without notice, or even be removed. |
31 | // |
32 | // We mean it. |
33 | // |
34 | |
35 | QT_BEGIN_NAMESPACE |
36 | |
37 | class QGtk3Json |
38 | { |
39 | Q_GADGET |
40 | private: |
41 | QGtk3Json(){}; |
42 | |
43 | public: |
44 | // Convert enums to strings |
45 | static QLatin1String fromPalette(QPlatformTheme::Palette palette); |
46 | static QLatin1String fromGtkState(GtkStateFlags type); |
47 | static QLatin1String fromColor(const QColor &Color); |
48 | static QLatin1String fromColorRole(QPalette::ColorRole role); |
49 | static QLatin1String fromColorGroup(QPalette::ColorGroup group); |
50 | static QLatin1String fromGdkSource(QGtk3Interface::QGtkColorSource source); |
51 | static QLatin1String fromSourceType(QGtk3Storage::SourceType sourceType); |
52 | static QLatin1String fromWidgetType(QGtk3Interface::QGtkWidget widgetType); |
53 | static QLatin1String fromColorScheme(Qt::ColorScheme colorScheme); |
54 | |
55 | // Convert strings to enums |
56 | static QPlatformTheme::Palette toPalette(const QString &palette); |
57 | static GtkStateFlags toGtkState(const QString &type); |
58 | static QColor toColor(const QString &Color); |
59 | static QPalette::ColorRole toColorRole(const QString &role); |
60 | static QPalette::ColorGroup toColorGroup(const QString &group); |
61 | static QGtk3Interface::QGtkColorSource toGdkSource(const QString &source); |
62 | static QGtk3Storage::SourceType toSourceType(const QString &sourceType); |
63 | static QGtk3Interface::QGtkWidget toWidgetType(const QString &widgetType); |
64 | static Qt::ColorScheme toColorScheme(const QString &colorScheme); |
65 | |
66 | // Json keys |
67 | static constexpr QLatin1StringView cePalettes = "QtGtk3Palettes"_L1; |
68 | static constexpr QLatin1StringView cePalette = "PaletteType"_L1; |
69 | static constexpr QLatin1StringView ceGtkState = "GtkStateType"_L1; |
70 | static constexpr QLatin1StringView ceGtkWidget = "GtkWidgetType"_L1; |
71 | static constexpr QLatin1StringView ceColor = "Color"_L1; |
72 | static constexpr QLatin1StringView ceColorRole = "ColorRole"_L1; |
73 | static constexpr QLatin1StringView ceColorGroup = "ColorGroup"_L1; |
74 | static constexpr QLatin1StringView ceGdkSource = "GdkSource"_L1; |
75 | static constexpr QLatin1StringView ceSourceType = "SourceType"_L1; |
76 | static constexpr QLatin1StringView ceLighter = "Lighter"_L1; |
77 | static constexpr QLatin1StringView ceRed = "DeltaRed"_L1; |
78 | static constexpr QLatin1StringView ceGreen = "DeltaGreen"_L1; |
79 | static constexpr QLatin1StringView ceBlue = "DeltaBlue"_L1; |
80 | static constexpr QLatin1StringView ceWidth = "Width"_L1; |
81 | static constexpr QLatin1StringView ceHeight = "Height"_L1; |
82 | static constexpr QLatin1StringView ceBrush = "FixedBrush"_L1; |
83 | static constexpr QLatin1StringView ceData = "SourceData"_L1; |
84 | static constexpr QLatin1StringView ceBrushes = "Brushes"_L1; |
85 | static constexpr QLatin1StringView ceColorScheme = "ColorScheme"_L1; |
86 | |
87 | // Save to a file |
88 | static bool save(const QGtk3Storage::PaletteMap &map, const QString &fileName, |
89 | QJsonDocument::JsonFormat format = QJsonDocument::Indented); |
90 | |
91 | // Save to a Json document |
92 | static const QJsonDocument save(const QGtk3Storage::PaletteMap &map); |
93 | |
94 | // Load from a file |
95 | static bool load(QGtk3Storage::PaletteMap &map, const QString &fileName); |
96 | |
97 | // Load from a Json document |
98 | static bool load(QGtk3Storage::PaletteMap &map, const QJsonDocument &doc); |
99 | }; |
100 | |
101 | QT_END_NAMESPACE |
102 | #endif // QGTK3JSON_P_H |
103 |