18#include <QtCore/QMetaEnum>
19#include <QtCore/QFileInfo>
20#include <QtGui/QFontDatabase>
34 qCDebug(lcQGtk3Interface) <<
"QGtk3Interface instantiated without QGtk3Storage."
35 <<
"No reaction to runtime theme changes.";
40 auto handleThemeChange = [] {
45 GtkSettings *
settings = gtk_settings_get_default();
46 const gboolean success = g_signal_connect(
settings,
"notify::gtk-theme-name",
47 G_CALLBACK(handleThemeChange),
nullptr);
48 if (success == FALSE) {
49 qCDebug(lcQGtk3Interface) <<
"Connection to theme change signal failed."
50 <<
"No reaction to runtime theme changes.";
63 gtk_widget_destroy(
v.second);
77 if (QLatin1String(QByteArray(state.toLatin1())) == #x ##_L1) \
78 return GTK_STATE_FLAG_ ##x
107#define CASE(x) case GTK_STATE_FLAG_ ##x: return QLatin1String(#x)
120void QGtk3Interface::initColorMap()
122 #define SAVE(src, state, prop, def)\
123 {ColorKey({QGtkColorSource::src, GTK_STATE_FLAG_ ##state}), ColorValue({#prop ##_L1, QGtkColorDefault::def})}
125 gtkColorMap = ColorMap {
145 qCDebug(lcQGtk3Interface) <<
"Color map populated from defaults.";
163 return qt_gtk_get_icon(GTK_STOCK_DELETE);
165 return qt_gtk_get_icon(GTK_STOCK_OK);
167 return qt_gtk_get_icon(GTK_STOCK_CANCEL);
169 return qt_gtk_get_icon(GTK_STOCK_YES);
171 return qt_gtk_get_icon(GTK_STOCK_NO);
173 return qt_gtk_get_icon(GTK_STOCK_OPEN);
175 return qt_gtk_get_icon(GTK_STOCK_CLOSE);
177 return qt_gtk_get_icon(GTK_STOCK_APPLY);
179 return qt_gtk_get_icon(GTK_STOCK_SAVE);
181 return qt_gtk_get_icon(GTK_STOCK_DIALOG_WARNING);
183 return qt_gtk_get_icon(GTK_STOCK_DIALOG_QUESTION);
185 return qt_gtk_get_icon(GTK_STOCK_DIALOG_INFO);
187 return qt_gtk_get_icon(GTK_STOCK_DIALOG_ERROR);
265QImage QGtk3Interface::qt_gtk_get_icon(
const char* iconName)
const
267 GtkIconSet* iconSet = gtk_icon_factory_lookup_default (iconName);
268 GdkPixbuf*
icon = gtk_icon_set_render_icon_pixbuf(iconSet,
context(), GTK_ICON_SIZE_DIALOG);
269 return qt_convert_gdk_pixbuf(
icon);
284QImage QGtk3Interface::qt_convert_gdk_pixbuf(GdkPixbuf *
buf)
const
289 const guint8 *gdata = gdk_pixbuf_read_pixels(
buf);
290 static_assert(std::is_same<
decltype(gdata),
const uchar *>
::value,
291 "guint8 has diverted from uchar. Code needs fixing.");
292 Q_ASSUME(gdk_pixbuf_get_bits_per_sample(
buf) == 8);
293 Q_ASSUME(gdk_pixbuf_get_n_channels(
buf) == 4);
296 const int width = gdk_pixbuf_get_width(
buf);
297 const int height = gdk_pixbuf_get_height(
buf);
298 const int bpl = gdk_pixbuf_get_rowstride(
buf);
300 return converted.copy();
310GtkWidget *QGtk3Interface::qt_new_gtkWidget(QGtkWidget
type)
const
313 case QGtkWidget::Type: return Type ##_new();
315 case QGtkWidget::Type: return Type ##_new(nullptr);
352GdkRGBA QGtk3Interface::genericColor(GtkStyleContext *
con, GtkStateFlags
state, QGtkColorDefault def)
const
356#define CASE(def, call)\
357 case QGtkColorDefault::def:\
358 gtk_style_context_get_ ##call(con, state, &color);\
385#define CASE(src, def)\
386 case QGtkColorSource::src: {\
387 const ColorKey key = ColorKey({QGtkColorSource::src, state});\
388 if (gtkColorMap.contains(key)) {\
389 const ColorValue val = gtkColorMap.value(key);\
390 if (!gtk_style_context_lookup_color(con, val.propertyName.toUtf8().constData(), &col)) {\
391 col = genericColor(con, state, val.genericSource);\
392 qCDebug(lcQGtk3Interface) << "Property name" << val.propertyName << "not found.\n"\
393 << "Falling back to " << val.genericSource;\
396 col = genericColor(con, state, QGtkColorDefault::def);\
397 qCDebug(lcQGtk3Interface) << "No color source found for" << QGtkColorSource::src\
398 << fromGtkState(state) << "\n Falling back to"\
399 << QGtkColorDefault::def;\
412 return fromGdkColor(col);
448GtkStyleContext *QGtk3Interface::context(
GtkWidget *
w)
const
451 return gtk_widget_get_style_context(
w);
481 GtkSettings *
settings = gtk_settings_get_default();
485 g_object_get(
settings,
"gtk-theme-name", &theme_name,
nullptr);
502 GTK_STATE_FLAG_ACTIVE);
505 GTK_STATE_FLAG_ACTIVE);
559inline constexpr QFont::Style QGtk3Interface::toFontStyle(PangoStyle style)
577inline constexpr int QGtk3Interface::toFontWeight(PangoWeight
weight)
581 static_assert(PANGO_WEIGHT_THIN == 100 && PANGO_WEIGHT_ULTRAHEAVY == 1000,
582 "Pango font weight enum changed. Fix conversion.");
585 "QFont::Weight enum changed. Fix conversion.");
608 GtkCssProvider *cssProvider =
nullptr;
610 cssProvider = gtk_css_provider_new();
611 gtk_style_context_add_class (
con, GTK_STYLE_CLASS_MONOSPACE);
612 const char *fontSpec =
"* {font-family: monospace;}";
613 gtk_css_provider_load_from_data(cssProvider, fontSpec, -1, NULL);
614 gtk_style_context_add_provider(
con, GTK_STYLE_PROVIDER(cssProvider),
615 GTK_STYLE_PROVIDER_PRIORITY_USER);
621 gtk_style_context_remove_provider(
con, GTK_STYLE_PROVIDER(cssProvider));
622 g_object_unref(cssProvider);
626 const PangoFontDescription *gtkFont = gtk_style_context_get_font(
con, GTK_STATE_FLAG_NORMAL);
634 const int weight = toFontWeight(pango_font_description_get_weight(gtkFont));
640 font.
setPointSizeF(
static_cast<float>(pango_font_description_get_size(gtkFont)/PANGO_SCALE));
641 font.
setStyle(toFontStyle(pango_font_description_get_style(gtkFont)));
646 qCDebug(lcQGtk3Interface) <<
"No fixed pitch font found in font family"
647 <<
font.
family() <<
". falling back to a default"
648 <<
"fixed pitch font";
666 GFileInfo *
info = g_file_query_info (
file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
667 G_FILE_QUERY_INFO_NONE,
nullptr,
nullptr);
669 g_object_unref(
file);
673 GIcon *
icon = g_file_info_get_icon(
info);
675 g_object_unref(
file);
676 g_object_unref(
info);
680 GtkIconTheme *theme = gtk_icon_theme_get_default();
681 GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme,
icon, GTK_ICON_SIZE_BUTTON,
682 GTK_ICON_LOOKUP_FORCE_SIZE);
684 g_object_unref(
file);
685 g_object_unref(
info);
686 g_object_unref(
icon);
690 GdkPixbuf *
buf = gtk_icon_info_load_icon(iconInfo,
nullptr);
692 g_object_unref(
file);
693 g_object_unref(
info);
694 g_object_unref(
icon);
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
The QColor class provides colors based on RGB, HSV or CMYK values.
int lightness() const noexcept
\inmodule QtCore \reentrant
QString absoluteFilePath() const
Returns an absolute path including the file name.
std::pair< iterator, bool > insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue) const
void setStyle(Style style)
Sets the style of the font to style.
QString family() const
Returns the requested font family name.
void setFixedPitch(bool)
If enable is true, sets fixed pitch on; otherwise sets fixed pitch off.
void setFamily(const QString &)
Sets the family name of the font.
void setPointSizeF(qreal)
Sets the point size to pointSize.
Style
This enum describes the different styles of glyphs that are used to display text.
QIcon fileIcon(const QFileInfo &fileInfo) const
Returns a GTK styled file icon for.
QFont font(QPlatformTheme::Font type) const
Return a GTK styled font.
Qt::ColorScheme colorSchemeByColors() const
Determine color scheme by colors.
QGtk3Interface(QGtk3Storage *)
QImage standardPixmap(QPlatformTheme::StandardPixmap standardPixmap) const
Returns a QImage corresponding to.
QBrush brush(QGtkWidget wtype, QGtkColorSource source, GtkStateFlags state) const
Create a QBrush from a GTK widget.
static const QLatin1String fromGtkState(GtkStateFlags state)
Returns.
const QString themeName() const
Returns the name of the current GTK theme.
@ gtk_separator_menu_item
static int toGtkState(const QString &state)
Converts a string into the GtkStateFlags enum.
void handleThemeChange()
Handles a theme change at runtime.
The QIcon class provides scalable icons in different modes and states.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
struct _GtkWidget GtkWidget
#define SAVE(src, state, prop, def)
static QGtk3Storage * m_storage
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLsizei const GLfloat * v
[13]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLuint GLuint GLfloat weight
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLchar * source
QFileInfo info(fileName)
[8]
QSettings settings("MySoft", "Star Runner")
[0]