Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgtk3storage_p.h
Go to the documentation of this file.
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
4#ifndef QGTK3STORAGE_P_H
5#define QGTK3STORAGE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qgtk3interface_p.h"
19#if QT_CONFIG(dbus)
21#endif
22
23#include <QtCore/QJsonDocument>
24#include <QtCore/QCache>
25#include <QtCore/QString>
26#include <QtGui/QGuiApplication>
27#include <QtGui/QPalette>
28
29#include <qpa/qplatformtheme.h>
30#include <private/qflatmap_p.h>
31
34{
36public:
38
39 // Enum documented in cpp file. Please keep it in line with updates made here.
40 enum class SourceType {
41 Gtk,
42 Fixed,
45 };
47
48 // Standard GTK source: Populate a brush from GTK
49 struct Gtk3Source {
52 GtkStateFlags state;
53 int width = -1;
54 int height = -1;
56 {
57 return dbg << "QGtkStorage::Gtk3Source(gtkwidgetType=" << gtkWidgetType << ", source="
58 << source << ", state=" << state << ", width=" << width << ", height="
59 << height << ")";
60 }
61 };
62
63 // Recursive source: Populate a brush by altering another source
68 int lighter = 100;
69 int deltaRed = 0;
70 int deltaGreen = 0;
71 int deltaBlue = 0;
72 int width = -1;
73 int height = -1;
75 {
76 return dbg << "QGtkStorage::RecursiceSource(colorGroup=" << colorGroup << ", colorRole="
77 << colorRole << ", colorScheme=" << colorScheme << ", lighter=" << lighter
78 << ", deltaRed="<< deltaRed << "deltaBlue =" << deltaBlue << "deltaGreen="
79 << deltaGreen << ", width=" << width << ", height=" << height << ")";
80 }
81 };
82
83 // Fixed source: Populate a brush with fixed values rather than reading GTK
84 struct FixedSource {
87 {
88 return dbg << "QGtkStorage::FixedSource(" << fixedBrush << ")";
89 }
90 };
91
92 // Data source for brushes
93 struct Source {
98
99 // GTK constructor
101 GtkStateFlags cstate, int bwidth = -1, int bheight = -1) : sourceType(SourceType::Gtk)
102 {
103 gtk3.gtkWidgetType = wtype;
104 gtk3.source = csource;
105 gtk3.state = cstate;
106 gtk3.width = bwidth;
107 gtk3.height = bheight;
108 }
109
110 // Recursive constructor for darker/lighter colors
112 Qt::ColorScheme scheme, int p_lighter = 100)
114 {
116 rec.colorRole = role;
117 rec.colorScheme = scheme;
118 rec.lighter = p_lighter;
119 }
120
121 // Recursive ocnstructor for color modification
123 Qt::ColorScheme scheme, int p_red, int p_green, int p_blue)
125 {
127 rec.colorRole = role;
128 rec.colorScheme = scheme;
129 rec.deltaRed = p_red;
130 rec.deltaGreen = p_green;
131 rec.deltaBlue = p_blue;
132 }
133
134 // Recursive constructor for all: color modification and darker/lighter
136 Qt::ColorScheme scheme, int p_lighter,
137 int p_red, int p_green, int p_blue) : sourceType(SourceType::Modified)
138 {
140 rec.colorRole = role;
141 rec.colorScheme = scheme;
142 rec.lighter = p_lighter;
143 rec.deltaRed = p_red;
144 rec.deltaGreen = p_green;
145 rec.deltaBlue = p_blue;
146 }
147
148 // Fixed Source constructor
153
154 // Invalid constructor and getter
156 bool isValid() const { return sourceType != SourceType::Invalid; }
157
158 // Debug
160 {
161 return dbg << "QGtk3Storage::Source(sourceType=" << sourceType << ")";
162 }
163 };
164
165 // Struct with key attributes to identify a brush: color group, color role and color scheme
166 struct TargetBrush {
170
171 // Generic constructor
175
176 // Copy constructor with color scheme modifier for dark/light aware search
179
180 // struct becomes key of a map, so operator< is needed
181 bool operator<(const TargetBrush& other) const {
182 return std::tie(colorGroup, colorRole, colorScheme) <
183 std::tie(other.colorGroup, other.colorRole, other.colorScheme);
184 }
185 };
186
187 // Mapping a palette's brushes to their GTK sources
188 typedef QFlatMap<TargetBrush, Source> BrushMap;
189
190 // Storage of palettes and their GTK sources
191 typedef QFlatMap<QPlatformTheme::Palette, BrushMap> PaletteMap;
192
193 // Public getters
196 Qt::ColorScheme colorScheme() const { return m_colorScheme; };
197 static QPalette standardPalette();
198 const QString themeName() const { return m_interface ? m_interface->themeName() : QString(); };
199 const QFont *font(QPlatformTheme::Font type) const;
200 QIcon fileIcon(const QFileInfo &fileInfo) const;
201
202 // Initialization
203 void populateMap();
204 void handleThemeChange();
205
206private:
207 // Storage for palettes and their brushes
208 PaletteMap m_palettes;
209
210 std::unique_ptr<QGtk3Interface> m_interface;
211#if QT_CONFIG(dbus)
212 std::unique_ptr<QGtk3PortalInterface> m_portalInterface;
213#endif
214
216
217 // Caches for Pixmaps, fonts and palettes
218 mutable QCache<QPlatformTheme::StandardPixmap, QImage> m_pixmapCache;
219 mutable std::array<std::optional<QPalette>, QPlatformTheme::Palette::NPalettes> m_paletteCache;
220 mutable std::array<std::optional<QFont>, QPlatformTheme::NFonts> m_fontCache;
221
222 // Search brush with a given GTK3 source
223 QBrush brush(const Source &source, const BrushMap &map) const;
224
225 // Get GTK3 source for a target brush
226 Source brush (const TargetBrush &brush, const BrushMap &map) const;
227
228 // clear cache, palettes and color scheme
229 void clear();
230
231 // Data creation, import & export
232 void createMapping ();
233 const PaletteMap savePalettes() const;
234 bool save(const QString &filename, const QJsonDocument::JsonFormat f = QJsonDocument::Indented) const;
235 QJsonDocument save() const;
236 bool load(const QString &filename);
237};
238
240#endif // QGTK3STORAGE_H
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtCore
\reentrant
Definition qfont.h:22
void handleThemeChange()
Handles a theme change at runtime.
QFlatMap< QPlatformTheme::Palette, BrushMap > PaletteMap
static QPalette standardPalette()
Returns a simple, hard coded base palette.
const QString themeName() const
Qt::ColorScheme colorScheme() const
QFlatMap< TargetBrush, Source > BrushMap
QIcon fileIcon(const QFileInfo &fileInfo) const
Returns a GTK styled file icon corresponding to.
void populateMap()
Populates a map with information about how to locate colors in GTK.
SourceType
This enum represents the type of a color source.
QPixmap standardPixmap(QPlatformTheme::StandardPixmap standardPixmap, const QSizeF &size) const
Return a GTK styled standard pixmap if available.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore\reentrant
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
ColorGroup
\value Disabled \value Active \value Inactive \value Normal synonym for Active
Definition qpalette.h:49
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QMap< QString, QString > map
[6]
else opt state
[0]
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:50
Definition brush.cpp:5
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLint GLsizei width
GLenum type
GLboolean GLuint group
GLsizei GLsizei GLchar * source
#define Q_ENUM(x)
#define Q_GADGET
QSharedPointer< T > other(t)
[5]
QDebug operator<<(QDebug dbg)
QGtk3Interface::QGtkWidget gtkWidgetType
QDebug operator<<(QDebug dbg)
QGtk3Interface::QGtkColorSource source
QDebug operator<<(QDebug dbg)
QPalette::ColorRole colorRole
QPalette::ColorGroup colorGroup
Source(const QBrush &brush)
RecursiveSource rec
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Qt::ColorScheme scheme, int p_lighter, int p_red, int p_green, int p_blue)
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Qt::ColorScheme scheme, int p_red, int p_green, int p_blue)
Source(QGtk3Interface::QGtkWidget wtype, QGtk3Interface::QGtkColorSource csource, GtkStateFlags cstate, int bwidth=-1, int bheight=-1)
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Qt::ColorScheme scheme, int p_lighter=100)
QDebug operator<<(QDebug dbg)
QPalette::ColorRole colorRole
QPalette::ColorGroup colorGroup
TargetBrush(QPalette::ColorGroup group, QPalette::ColorRole role, Qt::ColorScheme scheme=Qt::ColorScheme::Unknown)
TargetBrush(const TargetBrush &other, Qt::ColorScheme scheme)
bool operator<(const TargetBrush &other) const