14#include <private/qguiapplication_p.h>
15#include <private/qgenericunixservices_p.h>
16#include <qpa/qplatformintegration.h>
17#include <qpa/qplatformfontdatabase.h>
22#include <pango/pango.h>
24#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
28#ifdef GDK_WINDOWING_WAYLAND
29#include <gdk/gdkwayland.h>
37#define PREVIEW_WIDTH 256
38#define PREVIEW_HEIGHT 512
66 : gtkWidget(gtkWidget)
69 g_signal_connect_swapped(G_OBJECT(gtkWidget),
"response", G_CALLBACK(
onResponse), helper);
70 g_signal_connect(G_OBJECT(gtkWidget),
"delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
75 gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
76 gtk_widget_destroy(gtkWidget);
81 return GTK_DIALOG(gtkWidget);
101 this->modality = modality;
103 gtk_widget_realize(gtkWidget);
105 GdkWindow *gdkWindow = gtk_widget_get_window(gtkWidget);
108#if defined(GDK_WINDOWING_WAYLAND) && GTK_CHECK_VERSION(3, 22, 0)
109 }
else if (GDK_IS_WAYLAND_WINDOW(gdkWindow)) {
114 if (
handle.startsWith(
"wayland:"_L1)) {
116 gdk_wayland_window_set_transient_for_exported(gdkWindow, handleBa.data());
120#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
121 }
else if (GDK_IS_X11_WINDOW(gdkWindow)) {
122 GdkDisplay *gdkDisplay = gdk_window_get_display(gdkWindow);
123 XSetTransientForHint(gdk_x11_display_get_xdisplay(gdkDisplay),
124 gdk_x11_window_get_xid(gdkWindow),
131 gdk_window_set_modal_hint(gdkWindow,
true);
134 gtk_widget_show(gtkWidget);
135 gdk_window_focus(gdkWindow, GDK_CURRENT_TIME);
141 gtk_widget_hide(gtkWidget);
146 if (response == GTK_RESPONSE_OK)
155 g_signal_connect_swapped(d->
gtkDialog(),
"notify::rgba", G_CALLBACK(onColorChanged),
this);
181 if (
color.alpha() < 255)
182 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog),
true);
184 gdkColor.red =
color.redF();
185 gdkColor.green =
color.greenF();
186 gdkColor.blue =
color.blueF();
187 gdkColor.alpha =
color.alphaF();
188 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
195 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
196 return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
204void QGtk3ColorDialogHelper::applyOptions()
209 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog),
options()->testOption(QColorDialogOptions::ShowAlphaChannel));
215 GTK_FILE_CHOOSER_ACTION_OPEN,
220 g_signal_connect(GTK_FILE_CHOOSER(d->
gtkDialog()),
"selection-changed", G_CALLBACK(onSelectionChanged),
this);
221 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->
gtkDialog()),
"current-folder-changed", G_CALLBACK(onCurrentFolderChanged),
this);
222 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->
gtkDialog()),
"notify::filter", G_CALLBACK(onFilterChanged),
this);
224 previewWidget = gtk_image_new();
225 g_signal_connect(G_OBJECT(d->
gtkDialog()),
"update-preview", G_CALLBACK(onUpdatePreview),
this);
226 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(d->
gtkDialog()), previewWidget);
278 gchar *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(gtkDialog));
288 setFileChooserAction();
289 selectFileInternal(filename);
292void QGtk3FileDialogHelper::selectFileInternal(
const QUrl &filename)
313 GSList *filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(gtkDialog));
314 for (GSList *
it = filenames;
it;
it =
it->next)
316 g_slist_free(filenames);
330 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
337 GtkFileFilter *gtkFilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(gtkDialog));
338 return _filterNames.
value(gtkFilter);
344 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtkDialog));
364 gchar *filename = gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(gtkDialog));
366 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog),
false);
373 if (!fileinfo.exists() || !fileinfo.isFile()) {
375 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog),
false);
383 gtk_image_set_from_pixbuf(GTK_IMAGE(helper->previewWidget), pixbuf);
384 g_object_unref(pixbuf);
386 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), pixbuf ?
true :
false);
391 switch (options->fileMode()) {
396 return GTK_FILE_CHOOSER_ACTION_OPEN;
398 return GTK_FILE_CHOOSER_ACTION_SAVE;
403 return GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
405 return GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
409void QGtk3FileDialogHelper::setFileChooserAction()
414 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
417void QGtk3FileDialogHelper::applyOptions()
422 gtk_window_set_title(GTK_WINDOW(gtkDialog),
qUtf8Printable(opts->windowTitle()));
423 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog),
true);
425 setFileChooserAction();
428 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple);
431 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(gtkDialog), confirmOverwrite);
434 gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(gtkDialog), !readOnly);
436 const QStringList nameFilters = opts->nameFilters();
437 if (!nameFilters.isEmpty())
438 setNameFilters(nameFilters);
440 if (opts->initialDirectory().isLocalFile())
443 foreach (
const QUrl &filename, opts->initiallySelectedFiles())
444 selectFileInternal(filename);
446 const QString initialNameFilter = opts->initiallySelectedNameFilter();
447 if (!initialNameFilter.
isEmpty())
450 GtkWidget *acceptButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_OK);
460 GtkWidget *rejectButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_CANCEL);
473 gtk_file_chooser_remove_filter(GTK_FILE_CHOOSER(gtkDialog),
filter);
476 _filterNames.
clear();
487 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
497 g_signal_connect_swapped(d->
gtkDialog(),
"notify::font", G_CALLBACK(onFontChanged),
this);
522 PangoFontDescription *
desc = pango_font_description_new();
528 pango_font_description_set_weight(
desc, PANGO_WEIGHT_HEAVY);
530 pango_font_description_set_weight(
desc, PANGO_WEIGHT_ULTRABOLD);
532 pango_font_description_set_weight(
desc, PANGO_WEIGHT_BOLD);
534 pango_font_description_set_weight(
desc, PANGO_WEIGHT_SEMIBOLD);
536 pango_font_description_set_weight(
desc, PANGO_WEIGHT_MEDIUM);
538 pango_font_description_set_weight(
desc, PANGO_WEIGHT_NORMAL);
540 pango_font_description_set_weight(
desc, PANGO_WEIGHT_LIGHT);
542 pango_font_description_set_weight(
desc, PANGO_WEIGHT_ULTRALIGHT);
544 pango_font_description_set_weight(
desc, PANGO_WEIGHT_THIN);
548 pango_font_description_set_style(
desc, PANGO_STYLE_ITALIC);
550 pango_font_description_set_style(
desc, PANGO_STYLE_OBLIQUE);
552 pango_font_description_set_style(
desc, PANGO_STYLE_NORMAL);
554 char *
str = pango_font_description_to_string(
desc);
556 pango_font_description_free(
desc);
573 PangoStyle style = pango_font_description_get_style(
desc);
574 if (style == PANGO_STYLE_ITALIC)
576 else if (style == PANGO_STYLE_OBLIQUE)
581 pango_font_description_free(
desc);
587 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->
gtkDialog());
593 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->
gtkDialog());
594 gchar *
name = gtk_font_chooser_get_font(gtkDialog);
605void QGtk3FontDialogHelper::applyOptions()
610 gtk_window_set_title(GTK_WINDOW(gtkDialog),
qUtf8Printable(opts->windowTitle()));
615#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)
\inmodule QtCore \reentrant
QString fileName() const
Returns the name of the file, excluding the path.
QString path() const
Returns the file's path.
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
static QString fromUtf8(QByteArrayView utf8)
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.
QString sliced(qsizetype pos) const
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
QByteArray toUtf8() const &
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 QT_BEGIN_NAMESPACE QString windowTitle(HWND hwnd)
QFileInfo fi("c:/temp/foo")
[newstuff]
QFileDialog dialog(this)
[1]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QItemSelection * selection
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent