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
qgtk3interface_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 QGTK3INTERFACE_H
5#define QGTK3INTERFACE_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 <QtCore/QString>
19#include <QtCore/QCache>
20#include <private/qflatmap_p.h>
21#include <QtCore/QObject>
22#include <QtGui/QIcon>
23#include <QtGui/QPalette>
24#include <QtWidgets/QWidget>
25#include <QtCore/QLoggingCategory>
26#include <QtGui/QPixmap>
27#include <qpa/qplatformtheme.h>
28
29#undef signals // Collides with GTK symbols
30#include <gtk/gtk.h>
31#include <gdk/gdk.h>
32#include <glib.h>
33
35
37
38using namespace Qt::StringLiterals;
39
40class QGtk3Storage;
41
54{
56public:
59
90
91
100 enum class QGtkColorSource {
103 Text,
104 Base,
105 Border
106 };
108
109
121 enum class QGtkColorDefault {
124 Border
125 };
127
128 // Create a brush from GTK widget type, color source and color state
129 QBrush brush(QGtkWidget wtype, QGtkColorSource source, GtkStateFlags state) const;
130
131 // Font & icon getters
134 QIcon fileIcon(const QFileInfo &fileInfo) const;
135
136 // Return current GTK theme name
137 QString themeName() const;
138
139 // Derive color scheme from default colors
141
142 // Convert GTK state to/from string
143 static int toGtkState(const QString &state);
144 static const QLatin1String fromGtkState(GtkStateFlags state);
145
146private:
147
148 // Map colors to GTK property names and default to generic color getters
149 struct ColorKey {
151 GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
152
153 // struct becomes key of a map, so operator< is needed
154 bool operator<(const ColorKey& other) const {
155 return std::tie(colorSource, state) <
156 std::tie(other.colorSource, other.state);
157 }
158
159 QDebug operator<<(QDebug dbg)
160 {
161 return dbg << "QGtk3Interface::ColorKey(colorSource=" << colorSource << ", GTK state=" << fromGtkState(state) << ")";
162 }
163 };
164
165 struct ColorValue {
166 QString propertyName = QString();
168
169 QDebug operator<<(QDebug dbg)
170 {
171 return dbg << "QGtk3Interface::ColorValue(propertyName=" << propertyName << ", genericSource=" << genericSource << ")";
172 }
173 };
174
175 typedef QFlatMap<ColorKey, ColorValue> ColorMap;
176 ColorMap gtkColorMap;
177 void initColorMap();
178
179 GdkRGBA genericColor(GtkStyleContext *con, GtkStateFlags state, QGtkColorDefault def) const;
180
181 // Cache for GTK widgets
182 mutable QFlatMap<QGtkWidget, GtkWidget *> cache;
183
184 // Converters for GTK icon and GDK pixbuf
185 QImage qt_gtk_get_icon(const char *iconName) const;
186 QImage qt_convert_gdk_pixbuf(GdkPixbuf *buf) const;
187
188 // Create new GTK widget object
189 GtkWidget *qt_new_gtkWidget(QGtkWidget type) const;
190
191 // Deliver GTK Widget from cache or create new
193
194 // Get a GTK widget's style context. Default settings style context if nullptr
195 GtkStyleContext *context(GtkWidget *widget = nullptr) const;
196
197 // Convert GTK color into QColor
198 static inline QColor fromGdkColor (const GdkRGBA &c)
199 { return QColor::fromRgbF(c.red, c.green, c.blue, c.alpha); }
200
201 // get a QColor of a GTK widget (default settings style if nullptr)
202 QColor color (GtkWidget *widget, QGtkColorSource source, GtkStateFlags state) const;
203
204 // Mappings for GTK fonts
205 inline static constexpr QGtkWidget toWidgetType(QPlatformTheme::Font);
206 inline static constexpr QFont::Style toFontStyle(PangoStyle style);
207 inline static constexpr int toFontWeight(PangoWeight weight);
208
209};
211#endif // QGTK3INTERFACE_H
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
Definition qcolor.cpp:2427
\inmodule QtCore
\reentrant
Definition qfont.h:22
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:76
The QGtk3Interface class centralizes communication with the GTK3 library.
QIcon fileIcon(const QFileInfo &fileInfo) const
Returns a GTK styled file icon for.
Qt::ColorScheme colorSchemeByColors() const
Determine color scheme by colors.
QGtk3Interface(QGtk3Storage *)
QImage standardPixmap(QPlatformTheme::StandardPixmap standardPixmap) const
Returns a QImage corresponding to.
QString themeName() const
Returns the name of the current GTK theme.
static const QLatin1String fromGtkState(GtkStateFlags state)
Returns.
static int toGtkState(const QString &state)
Converts a string into the GtkStateFlags enum.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtGui
Definition qimage.h:37
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QOpenGLWidget * widget
[1]
else opt state
[0]
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:50
Definition brush.cpp:5
static void * context
struct _GtkWidget GtkWidget
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint GLuint GLfloat weight
GLuint color
[2]
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLsizei GLchar * source
const GLubyte * c
#define Q_ENUM(x)
#define Q_GADGET
QSharedPointer< T > other(t)
[5]