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 | |
4 | #ifndef QGTK3DIALOGHELPERS_H |
5 | #define QGTK3DIALOGHELPERS_H |
6 | |
7 | #include <QtCore/qhash.h> |
8 | #include <QtCore/qlist.h> |
9 | #include <QtCore/qurl.h> |
10 | #include <QtCore/qscopedpointer.h> |
11 | #include <QtCore/qstring.h> |
12 | #include <qpa/qplatformdialoghelper.h> |
13 | |
14 | typedef struct _GtkWidget GtkWidget; |
15 | typedef struct _GtkDialog GtkDialog; |
16 | typedef struct _GtkFileFilter GtkFileFilter; |
17 | |
18 | QT_BEGIN_NAMESPACE |
19 | |
20 | class QGtk3Dialog; |
21 | class QColor; |
22 | |
23 | class QGtk3ColorDialogHelper : public QPlatformColorDialogHelper |
24 | { |
25 | Q_OBJECT |
26 | |
27 | public: |
28 | QGtk3ColorDialogHelper(); |
29 | ~QGtk3ColorDialogHelper(); |
30 | |
31 | bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override; |
32 | void exec() override; |
33 | void hide() override; |
34 | |
35 | void setCurrentColor(const QColor &color) override; |
36 | QColor currentColor() const override; |
37 | |
38 | private: |
39 | static void onColorChanged(QGtk3ColorDialogHelper *helper); |
40 | void applyOptions(); |
41 | |
42 | QScopedPointer<QGtk3Dialog> d; |
43 | }; |
44 | |
45 | class QGtk3FileDialogHelper : public QPlatformFileDialogHelper |
46 | { |
47 | Q_OBJECT |
48 | |
49 | public: |
50 | QGtk3FileDialogHelper(); |
51 | ~QGtk3FileDialogHelper(); |
52 | |
53 | bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override; |
54 | void exec() override; |
55 | void hide() override; |
56 | |
57 | bool defaultNameFilterDisables() const override; |
58 | void setDirectory(const QUrl &directory) override; |
59 | QUrl directory() const override; |
60 | void selectFile(const QUrl &filename) override; |
61 | QList<QUrl> selectedFiles() const override; |
62 | void setFilter() override; |
63 | void selectNameFilter(const QString &filter) override; |
64 | QString selectedNameFilter() const override; |
65 | |
66 | private: |
67 | static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper); |
68 | static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper); |
69 | static void onFilterChanged(QGtk3FileDialogHelper *helper); |
70 | static void onUpdatePreview(GtkDialog *dialog, QGtk3FileDialogHelper *helper); |
71 | void applyOptions(); |
72 | void setNameFilters(const QStringList &filters); |
73 | void selectFileInternal(const QUrl &filename); |
74 | void setFileChooserAction(); |
75 | |
76 | QUrl _dir; |
77 | QList<QUrl> _selection; |
78 | QHash<QString, GtkFileFilter*> _filters; |
79 | QHash<GtkFileFilter*, QString> _filterNames; |
80 | QScopedPointer<QGtk3Dialog> d; |
81 | GtkWidget *previewWidget; |
82 | }; |
83 | |
84 | class QGtk3FontDialogHelper : public QPlatformFontDialogHelper |
85 | { |
86 | Q_OBJECT |
87 | |
88 | public: |
89 | QGtk3FontDialogHelper(); |
90 | ~QGtk3FontDialogHelper(); |
91 | |
92 | bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override; |
93 | void exec() override; |
94 | void hide() override; |
95 | |
96 | void setCurrentFont(const QFont &font) override; |
97 | QFont currentFont() const override; |
98 | |
99 | private: |
100 | static void onFontChanged(QGtk3FontDialogHelper *helper); |
101 | void applyOptions(); |
102 | |
103 | QScopedPointer<QGtk3Dialog> d; |
104 | }; |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #endif // QGTK3DIALOGHELPERS_H |
109 | |