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_ASSERT(gdk_pixbuf_get_bits_per_sample(
buf) == 8);
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);
312GtkWidget *QGtk3Interface::qt_new_gtkWidget(QGtkWidget
type)
const
315 case QGtkWidget::Type: return Type ##_new();
317 case QGtkWidget::Type: return Type ##_new(nullptr);
354GdkRGBA QGtk3Interface::genericColor(GtkStyleContext *
con, GtkStateFlags
state, QGtkColorDefault def)
const
358#define CASE(def, call)\
359 case QGtkColorDefault::def:\
360 gtk_style_context_get_ ##call(con, state, &color);\
387#define CASE(src, def)\
388 case QGtkColorSource::src: {\
389 const ColorKey key = ColorKey({QGtkColorSource::src, state});\
390 if (gtkColorMap.contains(key)) {\
391 const ColorValue val = gtkColorMap.value(key);\
392 if (!gtk_style_context_lookup_color(con, val.propertyName.toUtf8().constData(), &col)) {\
393 col = genericColor(con, state, val.genericSource);\
394 qCDebug(lcQGtk3Interface) << "Property name" << val.propertyName << "not found.\n"\
395 << "Falling back to " << val.genericSource;\
398 col = genericColor(con, state, QGtkColorDefault::def);\
399 qCDebug(lcQGtk3Interface) << "No color source found for" << QGtkColorSource::src\
400 << fromGtkState(state) << "\n Falling back to"\
401 << QGtkColorDefault::def;\
414 return fromGdkColor(col);
450GtkStyleContext *QGtk3Interface::context(
GtkWidget *
w)
const
453 return gtk_widget_get_style_context(
w);
484 if (GtkSettings *
settings = gtk_settings_get_default()) {
486 g_object_get(
settings,
"gtk-theme-name", &theme_name,
nullptr);
507 GTK_STATE_FLAG_ACTIVE);
510 GTK_STATE_FLAG_ACTIVE);
564inline constexpr QFont::Style QGtk3Interface::toFontStyle(PangoStyle style)
582inline constexpr int QGtk3Interface::toFontWeight(PangoWeight
weight)
586 static_assert(PANGO_WEIGHT_THIN == 100 && PANGO_WEIGHT_ULTRAHEAVY == 1000,
587 "Pango font weight enum changed. Fix conversion.");
590 "QFont::Weight enum changed. Fix conversion.");
613 GtkCssProvider *cssProvider =
nullptr;
615 cssProvider = gtk_css_provider_new();
616 gtk_style_context_add_class (
con, GTK_STYLE_CLASS_MONOSPACE);
617 const char *fontSpec =
"* {font-family: monospace;}";
618 gtk_css_provider_load_from_data(cssProvider, fontSpec, -1, NULL);
619 gtk_style_context_add_provider(
con, GTK_STYLE_PROVIDER(cssProvider),
620 GTK_STYLE_PROVIDER_PRIORITY_USER);
626 gtk_style_context_remove_provider(
con, GTK_STYLE_PROVIDER(cssProvider));
627 g_object_unref(cssProvider);
631 const PangoFontDescription *gtkFont = gtk_style_context_get_font(
con, GTK_STATE_FLAG_NORMAL);
639 const int weight = toFontWeight(pango_font_description_get_weight(gtkFont));
645 font.
setPointSizeF(
static_cast<float>(pango_font_description_get_size(gtkFont)/PANGO_SCALE));
646 font.
setStyle(toFontStyle(pango_font_description_get_style(gtkFont)));
651 qCDebug(lcQGtk3Interface) <<
"No fixed pitch font found in font family"
652 <<
font.
family() <<
". falling back to a default"
653 <<
"fixed pitch font";
671 GFileInfo *
info = g_file_query_info (
file, G_FILE_ATTRIBUTE_STANDARD_ICON,
672 G_FILE_QUERY_INFO_NONE,
nullptr,
nullptr);
674 g_object_unref(
file);
678 GIcon *
icon = g_file_info_get_icon(
info);
680 g_object_unref(
file);
681 g_object_unref(
info);
685 GtkIconTheme *theme = gtk_icon_theme_get_default();
686 GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme,
icon, 16,
687 GTK_ICON_LOOKUP_FORCE_SIZE);
689 g_object_unref(
file);
690 g_object_unref(
info);
694 GdkPixbuf *
buf = gtk_icon_info_load_icon(iconInfo,
nullptr);
696 g_object_unref(
file);
697 g_object_unref(
info);
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
QString absoluteFilePath() const
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.
QString themeName() const
Returns the name of the current GTK theme.
static const QLatin1String fromGtkState(GtkStateFlags state)
Returns.
@ gtk_separator_menu_item
static int toGtkState(const QString &state)
Converts a string into the GtkStateFlags enum.
The QIcon class provides scalable icons in different modes and states.
@ Format_ARGB32_Premultiplied
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 noexcept
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint GLfloat weight
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLsizei GLchar * source
QSettings settings("MySoft", "Star Runner")
[0]