Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgtk3dialoghelpers.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
6
8#include "qgtk3theme.h"
9
10#include <qeventloop.h>
11#include <qwindow.h>
12#include <qcolor.h>
13#include <qdebug.h>
14#include <qfont.h>
15#include <qfileinfo.h>
16
17#include <private/qguiapplication_p.h>
18#include <private/qdesktopunixservices_p.h>
19#include <qpa/qplatformintegration.h>
20#include <qpa/qplatformfontdatabase.h>
21
22#undef signals
23#include <gtk/gtk.h>
24#include <gdk/gdk.h>
25#include <pango/pango.h>
26
27#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
28#include <gdk/gdkx.h>
29#endif
30
31#ifdef GDK_WINDOWING_WAYLAND
32#include <gdk/gdkwayland.h>
33#endif
34
35// The size of the preview we display for selected image files. We set height
36// larger than width because generally there is more free space vertically
37// than horizontally (setting the preview image will always expand the width of
38// the dialog, but usually not the height). The image's aspect ratio will always
39// be preserved.
40#define PREVIEW_WIDTH 256
41#define PREVIEW_HEIGHT 512
42
43QT_BEGIN_NAMESPACE
44
45using namespace Qt::StringLiterals;
46
48{
49public:
50 QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper);
52
54
55 void exec();
56 bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
57 void hide();
58
59protected:
60 static void onResponse(QPlatformDialogHelper *helper, int response);
61
62private:
63 GtkWidget *gtkWidget;
64 QPlatformDialogHelper *helper;
65 Qt::WindowModality modality;
66};
67
68QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper)
69 : gtkWidget(gtkWidget)
70 , helper(helper)
71{
72 g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), helper);
73 g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
74}
75
77{
78 gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
79 gtk_widget_destroy(gtkWidget);
80}
81
83{
84 return GTK_DIALOG(gtkWidget);
85}
86
88{
89 if (modality == Qt::ApplicationModal) {
90 // block input to the whole app, including other GTK dialogs
91 gtk_dialog_run(gtkDialog());
92 } else {
93 // block input to the window, allow input to other GTK dialogs
94 QEventLoop loop;
95 loop.connect(helper, SIGNAL(accept()), SLOT(quit()));
96 loop.connect(helper, SIGNAL(reject()), SLOT(quit()));
97 loop.exec();
98 }
99}
100
101bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
102{
103 Q_UNUSED(flags);
104 this->modality = modality;
105
106 gtk_widget_realize(gtkWidget); // creates X window
107
108 GdkWindow *gdkWindow = gtk_widget_get_window(gtkWidget);
109 if (parent) {
110 if (false) {
111#if defined(GDK_WINDOWING_WAYLAND) && GTK_CHECK_VERSION(3, 22, 0)
112 } else if (GDK_IS_WAYLAND_WINDOW(gdkWindow)) {
113 const auto unixServices = dynamic_cast<QDesktopUnixServices *>(
114 QGuiApplicationPrivate::platformIntegration()->services());
115 if (unixServices) {
116 const auto handle = unixServices->portalWindowIdentifier(parent);
117 if (handle.startsWith("wayland:"_L1)) {
118 auto handleBa = handle.sliced(8).toUtf8();
119 gdk_wayland_window_set_transient_for_exported(gdkWindow, handleBa.data());
120 }
121 }
122#endif
123#if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11)
124 } else if (GDK_IS_X11_WINDOW(gdkWindow)) {
125 GdkDisplay *gdkDisplay = gdk_window_get_display(gdkWindow);
126 XSetTransientForHint(gdk_x11_display_get_xdisplay(gdkDisplay),
127 gdk_x11_window_get_xid(gdkWindow),
128 parent->winId());
129#endif
130 }
131 }
132
133 if (modality != Qt::NonModal) {
134 gdk_window_set_modal_hint(gdkWindow, true);
135 }
136
137 gtk_widget_show(gtkWidget);
138 gdk_window_focus(gdkWindow, GDK_CURRENT_TIME);
139 return true;
140}
141
143{
144 gtk_widget_hide(gtkWidget);
145}
146
147void QGtk3Dialog::onResponse(QPlatformDialogHelper *helper, int response)
148{
149 if (response == GTK_RESPONSE_OK)
150 emit helper->accept();
151 else
152 emit helper->reject();
153}
154
155QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
156{
157 d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr), this));
158 g_signal_connect_swapped(d->gtkDialog(), "notify::rgba", G_CALLBACK(onColorChanged), this);
159}
160
164
165bool QGtk3ColorDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
166{
167 applyOptions();
168 return d->show(flags, modality, parent);
169}
170
172{
173 d->exec();
174}
175
177{
178 d->hide();
179}
180
181void QGtk3ColorDialogHelper::setCurrentColor(const QColor &color)
182{
183 GtkDialog *gtkDialog = d->gtkDialog();
184 if (color.alpha() < 255)
185 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog), true);
186 GdkRGBA gdkColor;
187 gdkColor.red = color.redF();
188 gdkColor.green = color.greenF();
189 gdkColor.blue = color.blueF();
190 gdkColor.alpha = color.alphaF();
191 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
192}
193
195{
196 GtkDialog *gtkDialog = d->gtkDialog();
197 GdkRGBA gdkColor;
198 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
199 return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
200}
201
202void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
203{
204 emit dialog->currentColorChanged(dialog->currentColor());
205}
206
207void QGtk3ColorDialogHelper::applyOptions()
208{
209 GtkDialog *gtkDialog = d->gtkDialog();
210 gtk_window_set_title(GTK_WINDOW(gtkDialog), qUtf8Printable(options()->windowTitle()));
211
212 gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog), options()->testOption(QColorDialogOptions::ShowAlphaChannel));
213}
214
215QGtk3FileDialogHelper::QGtk3FileDialogHelper()
216{
217 d.reset(new QGtk3Dialog(gtk_file_chooser_dialog_new("", nullptr,
218 GTK_FILE_CHOOSER_ACTION_OPEN,
219 qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)), GTK_RESPONSE_CANCEL,
220 qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Ok)), GTK_RESPONSE_OK,
221 NULL), this));
222
223 g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
224 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
225 g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "notify::filter", G_CALLBACK(onFilterChanged), this);
226
227 previewWidget = gtk_image_new();
228 g_signal_connect(G_OBJECT(d->gtkDialog()), "update-preview", G_CALLBACK(onUpdatePreview), this);
229 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(d->gtkDialog()), previewWidget);
230}
231
235
236bool QGtk3FileDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
237{
238 _dir.clear();
239 _selection.clear();
240
241 applyOptions();
242 return d->show(flags, modality, parent);
243}
244
246{
247 d->exec();
248}
249
251{
252 // After GtkFileChooserDialog has been hidden, gtk_file_chooser_get_current_folder()
253 // & gtk_file_chooser_get_filenames() will return bogus values -> cache the actual
254 // values before hiding the dialog
255 _dir = directory();
256 _selection = selectedFiles();
257
258 d->hide();
259}
260
262{
263 return false;
264}
265
266void QGtk3FileDialogHelper::setDirectory(const QUrl &directory)
267{
268 GtkDialog *gtkDialog = d->gtkDialog();
269 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtkDialog), qUtf8Printable(directory.toLocalFile()));
270}
271
273{
274 // While GtkFileChooserDialog is hidden, gtk_file_chooser_get_current_folder()
275 // returns a bogus value -> return the cached value before hiding
276 if (!_dir.isEmpty())
277 return _dir;
278
279 QString ret;
280 GtkDialog *gtkDialog = d->gtkDialog();
281 gchar *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(gtkDialog));
282 if (folder) {
283 ret = QString::fromUtf8(folder);
284 g_free(folder);
285 }
286 return QUrl::fromLocalFile(ret);
287}
288
289void QGtk3FileDialogHelper::selectFile(const QUrl &filename)
290{
291 setFileChooserAction();
292 selectFileInternal(filename);
293}
294
295void QGtk3FileDialogHelper::selectFileInternal(const QUrl &filename)
296{
297 GtkDialog *gtkDialog = d->gtkDialog();
298 if (options()->acceptMode() == QFileDialogOptions::AcceptSave) {
299 QFileInfo fi(filename.toLocalFile());
300 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtkDialog), qUtf8Printable(fi.path()));
301 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(gtkDialog), qUtf8Printable(fi.fileName()));
302 } else {
303 gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(gtkDialog), qUtf8Printable(filename.toLocalFile()));
304 }
305}
306
308{
309 // While GtkFileChooserDialog is hidden, gtk_file_chooser_get_filenames()
310 // returns a bogus value -> return the cached value before hiding
311 if (!_selection.isEmpty())
312 return _selection;
313
314 QList<QUrl> selection;
315 GtkDialog *gtkDialog = d->gtkDialog();
316 GSList *filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(gtkDialog));
317 for (GSList *it = filenames; it; it = it->next)
318 selection += QUrl::fromLocalFile(QString::fromUtf8((const char*)it->data));
319 g_slist_free(filenames);
320 return selection;
321}
322
324{
325 applyOptions();
326}
327
328void QGtk3FileDialogHelper::selectNameFilter(const QString &filter)
329{
330 GtkFileFilter *gtkFilter = _filters.value(filter);
331 if (gtkFilter) {
332 GtkDialog *gtkDialog = d->gtkDialog();
333 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
334 }
335}
336
338{
339 GtkDialog *gtkDialog = d->gtkDialog();
340 GtkFileFilter *gtkFilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(gtkDialog));
341 return _filterNames.value(gtkFilter);
342}
343
344void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
345{
346 QString selection;
347 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtkDialog));
348 if (filename) {
349 selection = QString::fromUtf8(filename);
350 g_free(filename);
351 }
352 emit helper->currentChanged(QUrl::fromLocalFile(selection));
353}
354
355void QGtk3FileDialogHelper::onCurrentFolderChanged(QGtk3FileDialogHelper *dialog)
356{
357 emit dialog->directoryEntered(dialog->directory());
358}
359
360void QGtk3FileDialogHelper::onFilterChanged(QGtk3FileDialogHelper *dialog)
361{
362 emit dialog->filterSelected(dialog->selectedNameFilter());
363}
364
365void QGtk3FileDialogHelper::onUpdatePreview(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
366{
367 gchar *filename = gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(gtkDialog));
368 if (!filename) {
369 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), false);
370 return;
371 }
372
373 // Don't attempt to open anything which isn't a regular file. If a named pipe,
374 // this may hang.
375 QFileInfo fileinfo(filename);
376 if (!fileinfo.exists() || !fileinfo.isFile()) {
377 g_free(filename);
378 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), false);
379 return;
380 }
381
382 // This will preserve the image's aspect ratio.
383 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, PREVIEW_WIDTH, PREVIEW_HEIGHT, 0);
384 g_free(filename);
385 if (pixbuf) {
386 gtk_image_set_from_pixbuf(GTK_IMAGE(helper->previewWidget), pixbuf);
387 g_object_unref(pixbuf);
388 }
389 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), pixbuf ? true : false);
390}
391
392static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer<QFileDialogOptions> &options)
393{
394 switch (options->fileMode()) {
395 case QFileDialogOptions::AnyFile:
396 case QFileDialogOptions::ExistingFile:
397 case QFileDialogOptions::ExistingFiles:
398 if (options->acceptMode() == QFileDialogOptions::AcceptOpen)
399 return GTK_FILE_CHOOSER_ACTION_OPEN;
400 else
401 return GTK_FILE_CHOOSER_ACTION_SAVE;
402 case QFileDialogOptions::Directory:
403 case QFileDialogOptions::DirectoryOnly:
404 default:
405 if (options->acceptMode() == QFileDialogOptions::AcceptOpen)
406 return GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
407 else
408 return GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
409 }
410}
411
412void QGtk3FileDialogHelper::setFileChooserAction()
413{
414 GtkDialog *gtkDialog = d->gtkDialog();
415
416 const GtkFileChooserAction action = gtkFileChooserAction(options());
417 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
418}
419
420void QGtk3FileDialogHelper::applyOptions()
421{
422 GtkDialog *gtkDialog = d->gtkDialog();
423 const QSharedPointer<QFileDialogOptions> &opts = options();
424
425 gtk_window_set_title(GTK_WINDOW(gtkDialog), qUtf8Printable(opts->windowTitle()));
426 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), true);
427
428 setFileChooserAction();
429
430 const bool selectMultiple = opts->fileMode() == QFileDialogOptions::ExistingFiles;
431 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple);
432
433 const bool confirmOverwrite = !opts->testOption(QFileDialogOptions::DontConfirmOverwrite);
434 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(gtkDialog), confirmOverwrite);
435
436 const bool readOnly = opts->testOption(QFileDialogOptions::ReadOnly);
437 gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(gtkDialog), !readOnly);
438
439 const QStringList nameFilters = opts->nameFilters();
440 if (!nameFilters.isEmpty())
441 setNameFilters(nameFilters);
442
443 if (opts->initialDirectory().isLocalFile())
444 setDirectory(opts->initialDirectory());
445
446 const auto initiallySelected = opts->initiallySelectedFiles();
447 for (const QUrl &filename : initiallySelected)
448 selectFileInternal(filename);
449
450 const QString initialNameFilter = opts->initiallySelectedNameFilter();
451 if (!initialNameFilter.isEmpty())
452 selectNameFilter(initialNameFilter);
453
454 GtkWidget *acceptButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_OK);
455 if (acceptButton) {
456 if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
457 gtk_button_set_label(GTK_BUTTON(acceptButton), qUtf8Printable(opts->labelText(QFileDialogOptions::Accept)));
458 else if (opts->acceptMode() == QFileDialogOptions::AcceptOpen)
459 gtk_button_set_label(GTK_BUTTON(acceptButton), qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Open)));
460 else
461 gtk_button_set_label(GTK_BUTTON(acceptButton), qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Save)));
462 }
463
464 GtkWidget *rejectButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_CANCEL);
465 if (rejectButton) {
466 if (opts->isLabelExplicitlySet(QFileDialogOptions::Reject))
467 gtk_button_set_label(GTK_BUTTON(rejectButton), qUtf8Printable(opts->labelText(QFileDialogOptions::Reject)));
468 else
469 gtk_button_set_label(GTK_BUTTON(rejectButton), qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)));
470 }
471}
472
473void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters)
474{
475 GtkDialog *gtkDialog = d->gtkDialog();
476 foreach (GtkFileFilter *filter, _filters)
477 gtk_file_chooser_remove_filter(GTK_FILE_CHOOSER(gtkDialog), filter);
478
479 _filters.clear();
480 _filterNames.clear();
481
482 for (const QString &filter : filters) {
483 GtkFileFilter *gtkFilter = gtk_file_filter_new();
484 const QString name = filter.left(filter.indexOf(u'('));
485 const QStringList extensions = cleanFilterList(filter);
486
487 gtk_file_filter_set_name(gtkFilter, qUtf8Printable(name.isEmpty() ? extensions.join(", "_L1) : name));
488 for (const QString &ext : extensions)
489 gtk_file_filter_add_pattern(gtkFilter, qUtf8Printable(ext));
490
491 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
492
493 _filters.insert(filter, gtkFilter);
494 _filterNames.insert(gtkFilter, filter);
495 }
496}
497
498QGtk3FontDialogHelper::QGtk3FontDialogHelper()
499{
500 d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr), this));
501 g_signal_connect_swapped(d->gtkDialog(), "notify::font", G_CALLBACK(onFontChanged), this);
502}
503
507
508bool QGtk3FontDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
509{
510 applyOptions();
511 return d->show(flags, modality, parent);
512}
513
515{
516 d->exec();
517}
518
520{
521 d->hide();
522}
523
524static QString qt_fontToString(const QFont &font)
525{
526 PangoFontDescription *desc = pango_font_description_new();
527 pango_font_description_set_size(desc, (font.pointSizeF() > 0.0 ? font.pointSizeF() : QFontInfo(font).pointSizeF()) * PANGO_SCALE);
528 pango_font_description_set_family(desc, qUtf8Printable(QFontInfo(font).family()));
529
530 int weight = font.weight();
531 if (weight >= QFont::Black)
532 pango_font_description_set_weight(desc, PANGO_WEIGHT_HEAVY);
533 else if (weight >= QFont::ExtraBold)
534 pango_font_description_set_weight(desc, PANGO_WEIGHT_ULTRABOLD);
535 else if (weight >= QFont::Bold)
536 pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
537 else if (weight >= QFont::DemiBold)
538 pango_font_description_set_weight(desc, PANGO_WEIGHT_SEMIBOLD);
539 else if (weight >= QFont::Medium)
540 pango_font_description_set_weight(desc, PANGO_WEIGHT_MEDIUM);
541 else if (weight >= QFont::Normal)
542 pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
543 else if (weight >= QFont::Light)
544 pango_font_description_set_weight(desc, PANGO_WEIGHT_LIGHT);
545 else if (weight >= QFont::ExtraLight)
546 pango_font_description_set_weight(desc, PANGO_WEIGHT_ULTRALIGHT);
547 else
548 pango_font_description_set_weight(desc, PANGO_WEIGHT_THIN);
549
550 int style = font.style();
551 if (style == QFont::StyleItalic)
552 pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
553 else if (style == QFont::StyleOblique)
554 pango_font_description_set_style(desc, PANGO_STYLE_OBLIQUE);
555 else
556 pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
557
558 char *str = pango_font_description_to_string(desc);
559 QString name = QString::fromUtf8(str);
560 pango_font_description_free(desc);
561 g_free(str);
562 return name;
563}
564
565static QFont qt_fontFromString(const QString &name)
566{
567 QFont font;
568 PangoFontDescription *desc = pango_font_description_from_string(qUtf8Printable(name));
569 font.setPointSizeF(static_cast<float>(pango_font_description_get_size(desc)) / PANGO_SCALE);
570
571 QString family = QString::fromUtf8(pango_font_description_get_family(desc));
572 if (!family.isEmpty())
573 font.setFamilies(QStringList{family});
574
575 font.setWeight(QFont::Weight(pango_font_description_get_weight(desc)));
576
577 PangoStyle style = pango_font_description_get_style(desc);
578 if (style == PANGO_STYLE_ITALIC)
579 font.setStyle(QFont::StyleItalic);
580 else if (style == PANGO_STYLE_OBLIQUE)
581 font.setStyle(QFont::StyleOblique);
582 else
583 font.setStyle(QFont::StyleNormal);
584
585 pango_font_description_free(desc);
586 return font;
587}
588
589void QGtk3FontDialogHelper::setCurrentFont(const QFont &font)
590{
591 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->gtkDialog());
592 gtk_font_chooser_set_font(gtkDialog, qUtf8Printable(qt_fontToString(font)));
593}
594
596{
597 GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->gtkDialog());
598 gchar *name = gtk_font_chooser_get_font(gtkDialog);
599 QFont font = qt_fontFromString(QString::fromUtf8(name));
600 g_free(name);
601 return font;
602}
603
604void QGtk3FontDialogHelper::onFontChanged(QGtk3FontDialogHelper *dialog)
605{
606 emit dialog->currentFontChanged(dialog->currentFont());
607}
608
609void QGtk3FontDialogHelper::applyOptions()
610{
611 GtkDialog *gtkDialog = d->gtkDialog();
612 const QSharedPointer<QFontDialogOptions> &opts = options();
613
614 gtk_window_set_title(GTK_WINDOW(gtkDialog), qUtf8Printable(opts->windowTitle()));
615}
616
617QT_END_NAMESPACE
618
619#include "moc_qgtk3dialoghelpers.cpp"
\inmodule QtCore
Definition qeventloop.h:16
\reentrant
Definition qfont.h:22
void setCurrentColor(const QColor &color) override
QColor currentColor() const 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
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
QFont currentFont() const override
static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer< QFileDialogOptions > &options)
#define PREVIEW_HEIGHT
#define PREVIEW_WIDTH
static QFont qt_fontFromString(const QString &name)
static QString qt_fontToString(const QFont &font)
struct _GtkDialog GtkDialog
struct _GtkFileFilter GtkFileFilter