summaryrefslogtreecommitdiffstats
path: root/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
blob: e5c4c72539637601efe977e65bd978e79d38746f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QGTK3DIALOGHELPERS_H
#define QGTK3DIALOGHELPERS_H

#include <QtCore/qhash.h>
#include <QtCore/qlist.h>
#include <QtCore/qurl.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qstring.h>
#include <qpa/qplatformdialoghelper.h>

typedef struct _GtkWidget GtkWidget;
typedef struct _GtkDialog GtkDialog;
typedef struct _GtkFileFilter GtkFileFilter;

QT_BEGIN_NAMESPACE

class QGtk3Dialog;
class QColor;

class QGtk3ColorDialogHelper : public QPlatformColorDialogHelper
{
    Q_OBJECT

public:
    QGtk3ColorDialogHelper();
    ~QGtk3ColorDialogHelper();

    bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override;
    void exec() override;
    void hide() override;

    void setCurrentColor(const QColor &color) override;
    QColor currentColor() const override;

private Q_SLOTS:
    void onAccepted();

private:
    static void onColorChanged(QGtk3ColorDialogHelper *helper);
    void applyOptions();

    QScopedPointer<QGtk3Dialog> d;
};

class QGtk3FileDialogHelper : public QPlatformFileDialogHelper
{
    Q_OBJECT

public:
    QGtk3FileDialogHelper();
    ~QGtk3FileDialogHelper();

    bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override;
    void exec() override;
    void hide() override;

    bool defaultNameFilterDisables() const override;
    void setDirectory(const QUrl &directory) override;
    QUrl directory() const override;
    void selectFile(const QUrl &filename) override;
    QList<QUrl> selectedFiles() const override;
    void setFilter() override;
    void selectNameFilter(const QString &filter) override;
    QString selectedNameFilter() const override;

private Q_SLOTS:
    void onAccepted();

private:
    static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
    static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
    static void onFilterChanged(QGtk3FileDialogHelper *helper);
    static void onUpdatePreview(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
    void applyOptions();
    void setNameFilters(const QStringList &filters);
    void selectFileInternal(const QUrl &filename);
    void setFileChooserAction();

    QUrl _dir;
    QList<QUrl> _selection;
    QHash<QString, GtkFileFilter*> _filters;
    QHash<GtkFileFilter*, QString> _filterNames;
    QScopedPointer<QGtk3Dialog> d;
    GtkWidget *previewWidget;
};

class QGtk3FontDialogHelper : public QPlatformFontDialogHelper
{
    Q_OBJECT

public:
    QGtk3FontDialogHelper();
    ~QGtk3FontDialogHelper();

    bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override;
    void exec() override;
    void hide() override;

    void setCurrentFont(const QFont &font) override;
    QFont currentFont() const override;

private Q_SLOTS:
    void onAccepted();

private:
    static void onFontChanged(QGtk3FontDialogHelper *helper);
    void applyOptions();

    QScopedPointer<QGtk3Dialog> d;
};

QT_END_NAMESPACE

#endif // QGTK3DIALOGHELPERS_H