16#include <private/qguiapplication_p.h>
17#include <private/qgenericunixservices_p.h>
18#include <qpa/qplatformintegration.h>
19#include <qpa/qplatformfontdatabase.h>
24#include <pango/pango.h>
26#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
30#ifdef GDK_WINDOWING_WAYLAND
31#include <gdk/gdkwayland.h>
39#define PREVIEW_WIDTH 256
40#define PREVIEW_HEIGHT 512
68 : gtkWidget(gtkWidget)
71 g_signal_connect_swapped(G_OBJECT(gtkWidget),
"response", G_CALLBACK(
onResponse), helper);
72 g_signal_connect(G_OBJECT(gtkWidget),
"delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
77 gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
78 gtk_widget_destroy(gtkWidget);
83 return GTK_DIALOG(gtkWidget);
103 this->modality = modality;
105 gtk_widget_realize(gtkWidget);
107 GdkWindow *gdkWindow = gtk_widget_get_window(gtkWidget);
110#if defined(GDK_WINDOWING_WAYLAND) && GTK_CHECK_VERSION(3, 22, 0)
111 }
else if (GDK_IS_WAYLAND_WINDOW(gdkWindow)) {
116 if (
handle.startsWith(
"wayland:"_L1)) {
117 auto handleBa =
handle.sliced(8).toUtf8();
118 gdk_wayland_window_set_transient_for_exported(gdkWindow, handleBa.data());
122#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
123 }
else if (GDK_IS_X11_WINDOW(gdkWindow)) {
124 GdkDisplay *gdkDisplay = gdk_window_get_display(gdkWindow);
125 XSetTransientForHint(gdk_x11_display_get_xdisplay(gdkDisplay),
126 gdk_x11_window_get_xid(gdkWindow),
133 gdk_window_set_modal_hint(gdkWindow,
true);
136 gtk_widget_show(gtkWidget);
137 gdk_window_focus(gdkWindow, GDK_CURRENT_TIME);
143 gtk_widget_hide(gtkWidget);
148 if (response == GTK_RESPONSE_OK)
157 g_signal_connect_swapped(d->
gtkDialog(),
"notify::rgba", G_CALLBACK(onColorChanged),
this);
183 if (
color.alpha() < 255)
184 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog),
true);
186 gdkColor.red =
color.redF();
187 gdkColor.green =
color.greenF();
188 gdkColor.blue =
color.blueF();
189 gdkColor.alpha =
color.alphaF();
190 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
197 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
198 return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
206void QGtk3ColorDialogHelper::applyOptions()
211 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog),
options()->testOption(QColorDialogOptions::ShowAlphaChannel));
217 GTK_FILE_CHOOSER_ACTION_OPEN,
222 g_signal_connect(GTK_FILE_CHOOSER(d->
gtkDialog()),
"selection-changed", G_CALLBACK(onSelectionChanged),
this);
223 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->
gtkDialog()),
"current-folder-changed", G_CALLBACK(onCurrentFolderChanged),
this);
224 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->
gtkDialog()),
"notify::filter", G_CALLBACK(onFilterChanged),
this);
226 previewWidget = gtk_image_new();
227 g_signal_connect(G_OBJECT(d->
gtkDialog()),
"update-preview", G_CALLBACK(onUpdatePreview),
this);
228 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(d->
gtkDialog()), previewWidget);
280 gchar *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(gtkDialog));
290 setFileChooserAction();
291 selectFileInternal(filename);
294void QGtk3FileDialogHelper::selectFileInternal(
const QUrl &filename)
299 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtkDialog),
qUtf8Printable(fi.path()));
300 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(gtkDialog),
qUtf8Printable(fi.fileName()));
315 GSList *filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(gtkDialog));
316 for (GSList *
it = filenames;
it;
it =
it->next)
318 g_slist_free(filenames);
332 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
339 GtkFileFilter *gtkFilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(gtkDialog));
340 return _filterNames.
value(gtkFilter);
346 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtkDialog));
366 gchar *filename = gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(gtkDialog));
368 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog),
false);
375 if (!fileinfo.exists() || !fileinfo.isFile()) {
377 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog),
false);
385 gtk_image_set_from_pixbuf(GTK_IMAGE(helper->previewWidget), pixbuf);
386 g_object_unref(pixbuf);
388 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), pixbuf ?
true :
false);
393 switch (options->fileMode()) {
398 return GTK_FILE_CHOOSER_ACTION_OPEN;
400 return GTK_FILE_CHOOSER_ACTION_SAVE;
405 return GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
407 return GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
411void QGtk3FileDialogHelper::setFileChooserAction()
416 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
419void QGtk3FileDialogHelper::applyOptions()
422 const QSharedPointer<QFileDialogOptions> &opts =
options();
424 gtk_window_set_title(GTK_WINDOW(gtkDialog),
qUtf8Printable(opts->windowTitle()));
425 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog),
true);
427 setFileChooserAction();
430 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple);
433 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(gtkDialog), confirmOverwrite);
436 gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(gtkDialog), !readOnly);
438 const QStringList nameFilters = opts->nameFilters();
439 if (!nameFilters.isEmpty())
440 setNameFilters(nameFilters);
442 if (opts->initialDirectory().isLocalFile())
445 foreach (
const QUrl &filename, opts->initiallySelectedFiles())
446 selectFileInternal(filename);
448 const QString initialNameFilter = opts->initiallySelectedNameFilter();
449 if (!initialNameFilter.isEmpty())
452 GtkWidget *acceptButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_OK);
462 GtkWidget *rejectButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_CANCEL);
475 gtk_file_chooser_remove_filter(GTK_FILE_CHOOSER(gtkDialog),
filter);
478 _filterNames.
clear();
486 foreach (
const QString &ext, extensions)
489 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
499 g_signal_connect_swapped(d->
gtkDialog(),
"notify::font", G_CALLBACK(onFontChanged),
this);
524 PangoFontDescription *desc = pango_font_description_new();
530 pango_font_description_set_weight(desc, PANGO_WEIGHT_HEAVY);
532 pango_font_description_set_weight(desc, PANGO_WEIGHT_ULTRABOLD);
534 pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
536 pango_font_description_set_weight(desc, PANGO_WEIGHT_SEMIBOLD);
538 pango_font_description_set_weight(desc, PANGO_WEIGHT_MEDIUM);
540 pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
542 pango_font_description_set_weight(desc, PANGO_WEIGHT_LIGHT);
544 pango_font_description_set_weight(desc, PANGO_WEIGHT_ULTRALIGHT);
546 pango_font_description_set_weight(desc, PANGO_WEIGHT_THIN);
550 pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
552 pango_font_description_set_style(desc, PANGO_STYLE_OBLIQUE);
554 pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
556 char *
str = pango_font_description_to_string(desc);
558 pango_font_description_free(desc);
566 PangoFontDescription *desc = pango_font_description_from_string(
qUtf8Printable(
name));
567 font.
setPointSizeF(
static_cast<float>(pango_font_description_get_size(desc)) / PANGO_SCALE);
575 PangoStyle style = pango_font_description_get_style(desc);
576 if (style == PANGO_STYLE_ITALIC)
578 else if (style == PANGO_STYLE_OBLIQUE)
583 pango_font_description_free(desc);
589 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->
gtkDialog());
595 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->
gtkDialog());
596 gchar *
name = gtk_font_chooser_get_font(gtkDialog);
607void QGtk3FontDialogHelper::applyOptions()
610 const QSharedPointer<QFontDialogOptions> &opts =
options();
612 gtk_window_set_title(GTK_WINDOW(gtkDialog),
qUtf8Printable(opts->windowTitle()));
617#include "moc_qgtk3dialoghelpers.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
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,...
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
QString selectedNameFilter() const
void filterSelected(const QString &filter)
QDir directory() const
Returns the directory currently being displayed in the dialog.
void directoryEntered(const QString &directory)
qreal pointSizeF() const
Returns the point size of the matched window system font.
void setStyle(Style style)
Sets the style of the font to style.
void setFamilies(const QStringList &)
Weight weight() const
Returns the weight of the font, using the same scale as the \l{QFont::Weight} enumeration.
qreal pointSizeF() const
Returns the point size of the font.
Style style() const
Returns the style of the font.
void setPointSizeF(qreal)
Sets the point size to pointSize.
Weight
Qt uses a weighting scale from 1 to 1000 compatible with OpenType.
void setWeight(Weight weight)
Sets the weight of the font to weight, using the scale defined by \l QFont::Weight enumeration.
virtual QString portalWindowIdentifier(QWindow *window)
void setCurrentColor(const QColor &color) override
QColor currentColor() const override
~QGtk3ColorDialogHelper()
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
static void onResponse(QPlatformDialogHelper *helper, int response)
QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper)
GtkDialog * gtkDialog() const
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
void setDirectory(const QUrl &directory) override
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
void setFilter() override
QString selectedNameFilter() const override
void selectNameFilter(const QString &filter) override
void selectFile(const QUrl &filename) override
QList< QUrl > selectedFiles() const override
QUrl directory() const override
bool defaultNameFilterDisables() const override
void setCurrentFont(const QFont &font) override
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
QFont currentFont() const override
static QPlatformIntegration * platformIntegration()
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isEmpty() const noexcept
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
void clear()
Resets the content of the QUrl.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer< QFileDialogOptions > &options)
static QFont qt_fontFromString(const QString &name)
static QString qt_fontToString(const QFont &font)
struct _GtkDialog GtkDialog
struct _GtkFileFilter GtkFileFilter
struct _GtkWidget GtkWidget
GLuint64 GLenum void * handle
GLuint GLuint GLfloat weight
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
#define qUtf8Printable(string)
static QString windowTitle(HWND hwnd)
QFileDialog dialog(this)
[1]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QItemSelection * selection
[0]