1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QPLATFORMDIALOGHELPER_H
41#define QPLATFORMDIALOGHELPER_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is part of the QPA API and is not meant to be used
48// in applications. Usage of this API may make your code
49// source and binary incompatible with future versions of Qt.
50//
51
52#include <QtGui/qtguiglobal.h>
53#include <QtCore/QtGlobal>
54#include <QtCore/QObject>
55#include <QtCore/QList>
56#include <QtCore/QSharedDataPointer>
57#include <QtCore/QSharedPointer>
58#include <QtCore/QDir>
59#include <QtCore/QUrl>
60#include <QtGui/QRgb>
61
62QT_BEGIN_NAMESPACE
63
64
65class QString;
66class QColor;
67class QFont;
68class QWindow;
69class QVariant;
70class QUrl;
71class QColorDialogOptionsPrivate;
72class QFontDialogOptionsPrivate;
73class QFileDialogOptionsPrivate;
74class QMessageDialogOptionsPrivate;
75
76#define QPLATFORMDIALOGHELPERS_HAS_CREATE
77
78class Q_GUI_EXPORT QPlatformDialogHelper : public QObject
79{
80 Q_OBJECT
81public:
82 enum StyleHint {
83 DialogIsQtWindow
84 };
85 enum DialogCode { Rejected, Accepted };
86
87 enum StandardButton {
88 // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton
89 NoButton = 0x00000000,
90 Ok = 0x00000400,
91 Save = 0x00000800,
92 SaveAll = 0x00001000,
93 Open = 0x00002000,
94 Yes = 0x00004000,
95 YesToAll = 0x00008000,
96 No = 0x00010000,
97 NoToAll = 0x00020000,
98 Abort = 0x00040000,
99 Retry = 0x00080000,
100 Ignore = 0x00100000,
101 Close = 0x00200000,
102 Cancel = 0x00400000,
103 Discard = 0x00800000,
104 Help = 0x01000000,
105 Apply = 0x02000000,
106 Reset = 0x04000000,
107 RestoreDefaults = 0x08000000,
108
109
110 FirstButton = Ok, // internal
111 LastButton = RestoreDefaults, // internal
112 LowestBit = 10, // internal: log2(FirstButton)
113 HighestBit = 27 // internal: log2(LastButton)
114 };
115
116 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
117 Q_FLAG(StandardButtons)
118
119 enum ButtonRole {
120 // keep this in sync with QDialogButtonBox::ButtonRole and QMessageBox::ButtonRole
121 // TODO Qt 6: make the enum copies explicit, and make InvalidRole == 0 so that
122 // AcceptRole can be or'ed with flags, and EOL can be the same as InvalidRole (null-termination)
123 InvalidRole = -1,
124 AcceptRole,
125 RejectRole,
126 DestructiveRole,
127 ActionRole,
128 HelpRole,
129 YesRole,
130 NoRole,
131 ResetRole,
132 ApplyRole,
133
134 NRoles,
135
136 RoleMask = 0x0FFFFFFF,
137 AlternateRole = 0x10000000,
138 Stretch = 0x20000000,
139 Reverse = 0x40000000,
140 EOL = InvalidRole
141 };
142 Q_ENUM(ButtonRole)
143
144 enum ButtonLayout {
145 // keep this in sync with QDialogButtonBox::ButtonLayout
146 UnknownLayout = -1,
147 WinLayout,
148 MacLayout,
149 KdeLayout,
150 GnomeLayout,
151 MacModelessLayout,
152 AndroidLayout
153 };
154 Q_ENUM(ButtonLayout)
155
156 QPlatformDialogHelper();
157 ~QPlatformDialogHelper();
158
159 virtual QVariant styleHint(StyleHint hint) const;
160
161 virtual void exec() = 0;
162 virtual bool show(Qt::WindowFlags windowFlags,
163 Qt::WindowModality windowModality,
164 QWindow *parent) = 0;
165 virtual void hide() = 0;
166
167 static QVariant defaultStyleHint(QPlatformDialogHelper::StyleHint hint);
168
169 static const int *buttonLayout(Qt::Orientation orientation = Qt::Horizontal, ButtonLayout policy = UnknownLayout);
170 static ButtonRole buttonRole(StandardButton button);
171
172Q_SIGNALS:
173 void accept();
174 void reject();
175};
176
177QT_END_NAMESPACE
178Q_DECLARE_METATYPE(QPlatformDialogHelper::StandardButton)
179Q_DECLARE_METATYPE(QPlatformDialogHelper::ButtonRole)
180QT_BEGIN_NAMESPACE
181
182class Q_GUI_EXPORT QColorDialogOptions
183{
184 Q_GADGET
185 Q_DISABLE_COPY(QColorDialogOptions)
186protected:
187 explicit QColorDialogOptions(QColorDialogOptionsPrivate *dd);
188 ~QColorDialogOptions();
189public:
190 enum ColorDialogOption {
191 ShowAlphaChannel = 0x00000001,
192 NoButtons = 0x00000002,
193 DontUseNativeDialog = 0x00000004
194 };
195
196 Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
197 Q_FLAG(ColorDialogOptions)
198
199 static QSharedPointer<QColorDialogOptions> create();
200 QSharedPointer<QColorDialogOptions> clone() const;
201
202 QString windowTitle() const;
203 void setWindowTitle(const QString &);
204
205 void setOption(ColorDialogOption option, bool on = true);
206 bool testOption(ColorDialogOption option) const;
207 void setOptions(ColorDialogOptions options);
208 ColorDialogOptions options() const;
209
210 static int customColorCount();
211 static QRgb customColor(int index);
212 static QRgb *customColors();
213 static void setCustomColor(int index, QRgb color);
214
215 static QRgb *standardColors();
216 static QRgb standardColor(int index);
217 static void setStandardColor(int index, QRgb color);
218
219private:
220 QColorDialogOptionsPrivate *d;
221};
222
223class Q_GUI_EXPORT QPlatformColorDialogHelper : public QPlatformDialogHelper
224{
225 Q_OBJECT
226public:
227 const QSharedPointer<QColorDialogOptions> &options() const;
228 void setOptions(const QSharedPointer<QColorDialogOptions> &options);
229
230 virtual void setCurrentColor(const QColor &) = 0;
231 virtual QColor currentColor() const = 0;
232
233Q_SIGNALS:
234 void currentColorChanged(const QColor &color);
235 void colorSelected(const QColor &color);
236
237private:
238 QSharedPointer<QColorDialogOptions> m_options;
239};
240
241class Q_GUI_EXPORT QFontDialogOptions
242{
243 Q_GADGET
244 Q_DISABLE_COPY(QFontDialogOptions)
245protected:
246 explicit QFontDialogOptions(QFontDialogOptionsPrivate *dd);
247 ~QFontDialogOptions();
248
249public:
250 enum FontDialogOption {
251 NoButtons = 0x00000001,
252 DontUseNativeDialog = 0x00000002,
253 ScalableFonts = 0x00000004,
254 NonScalableFonts = 0x00000008,
255 MonospacedFonts = 0x00000010,
256 ProportionalFonts = 0x00000020
257 };
258
259 Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)
260 Q_FLAG(FontDialogOptions)
261
262 static QSharedPointer<QFontDialogOptions> create();
263 QSharedPointer<QFontDialogOptions> clone() const;
264
265 QString windowTitle() const;
266 void setWindowTitle(const QString &);
267
268 void setOption(FontDialogOption option, bool on = true);
269 bool testOption(FontDialogOption option) const;
270 void setOptions(FontDialogOptions options);
271 FontDialogOptions options() const;
272
273private:
274 QFontDialogOptionsPrivate *d;
275};
276
277class Q_GUI_EXPORT QPlatformFontDialogHelper : public QPlatformDialogHelper
278{
279 Q_OBJECT
280public:
281 virtual void setCurrentFont(const QFont &) = 0;
282 virtual QFont currentFont() const = 0;
283
284 const QSharedPointer<QFontDialogOptions> &options() const;
285 void setOptions(const QSharedPointer<QFontDialogOptions> &options);
286
287Q_SIGNALS:
288 void currentFontChanged(const QFont &font);
289 void fontSelected(const QFont &font);
290
291private:
292 QSharedPointer<QFontDialogOptions> m_options;
293};
294
295class Q_GUI_EXPORT QFileDialogOptions
296{
297 Q_GADGET
298 Q_DISABLE_COPY(QFileDialogOptions)
299protected:
300 QFileDialogOptions(QFileDialogOptionsPrivate *dd);
301 ~QFileDialogOptions();
302
303public:
304 enum ViewMode { Detail, List };
305 Q_ENUM(ViewMode)
306
307 enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
308 Q_ENUM(FileMode)
309
310 enum AcceptMode { AcceptOpen, AcceptSave };
311 Q_ENUM(AcceptMode)
312
313 enum DialogLabel { LookIn, FileName, FileType, Accept, Reject, DialogLabelCount };
314 Q_ENUM(DialogLabel)
315
316 enum FileDialogOption
317 {
318 ShowDirsOnly = 0x00000001,
319 DontResolveSymlinks = 0x00000002,
320 DontConfirmOverwrite = 0x00000004,
321#if QT_DEPRECATED_SINCE(5, 14)
322 DontUseSheet Q_DECL_ENUMERATOR_DEPRECATED = 0x00000008,
323#endif
324 DontUseNativeDialog = 0x00000010,
325 ReadOnly = 0x00000020,
326 HideNameFilterDetails = 0x00000040,
327 DontUseCustomDirectoryIcons = 0x00000080
328 };
329 Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
330 Q_FLAG(FileDialogOptions)
331
332 static QSharedPointer<QFileDialogOptions> create();
333 QSharedPointer<QFileDialogOptions> clone() const;
334
335 QString windowTitle() const;
336 void setWindowTitle(const QString &);
337
338 void setOption(FileDialogOption option, bool on = true);
339 bool testOption(FileDialogOption option) const;
340 void setOptions(FileDialogOptions options);
341 FileDialogOptions options() const;
342
343 QDir::Filters filter() const;
344 void setFilter(QDir::Filters filters);
345
346 void setViewMode(ViewMode mode);
347 ViewMode viewMode() const;
348
349 void setFileMode(FileMode mode);
350 FileMode fileMode() const;
351
352 void setAcceptMode(AcceptMode mode);
353 AcceptMode acceptMode() const;
354
355 void setSidebarUrls(const QList<QUrl> &urls);
356 QList<QUrl> sidebarUrls() const;
357
358 bool useDefaultNameFilters() const;
359 void setUseDefaultNameFilters(bool d);
360
361 void setNameFilters(const QStringList &filters);
362 QStringList nameFilters() const;
363
364 void setMimeTypeFilters(const QStringList &filters);
365 QStringList mimeTypeFilters() const;
366
367 void setDefaultSuffix(const QString &suffix);
368 QString defaultSuffix() const;
369
370 void setHistory(const QStringList &paths);
371 QStringList history() const;
372
373 void setLabelText(DialogLabel label, const QString &text);
374 QString labelText(DialogLabel label) const;
375 bool isLabelExplicitlySet(DialogLabel label);
376
377 QUrl initialDirectory() const;
378 void setInitialDirectory(const QUrl &);
379
380 QString initiallySelectedMimeTypeFilter() const;
381 void setInitiallySelectedMimeTypeFilter(const QString &);
382
383 QString initiallySelectedNameFilter() const;
384 void setInitiallySelectedNameFilter(const QString &);
385
386 QList<QUrl> initiallySelectedFiles() const;
387 void setInitiallySelectedFiles(const QList<QUrl> &);
388
389 void setSupportedSchemes(const QStringList &schemes);
390 QStringList supportedSchemes() const;
391
392 static QString defaultNameFilterString();
393
394private:
395 QFileDialogOptionsPrivate *d;
396};
397
398class Q_GUI_EXPORT QPlatformFileDialogHelper : public QPlatformDialogHelper
399{
400 Q_OBJECT
401public:
402 virtual bool defaultNameFilterDisables() const = 0;
403 virtual void setDirectory(const QUrl &directory) = 0;
404 virtual QUrl directory() const = 0;
405 virtual void selectFile(const QUrl &filename) = 0;
406 virtual QList<QUrl> selectedFiles() const = 0;
407 virtual void setFilter() = 0;
408 virtual void selectMimeTypeFilter(const QString &filter);
409 virtual void selectNameFilter(const QString &filter) = 0;
410 virtual QString selectedMimeTypeFilter() const;
411 virtual QString selectedNameFilter() const = 0;
412
413 virtual bool isSupportedUrl(const QUrl &url) const;
414
415 const QSharedPointer<QFileDialogOptions> &options() const;
416 void setOptions(const QSharedPointer<QFileDialogOptions> &options);
417
418 static QStringList cleanFilterList(const QString &filter);
419 static const char filterRegExp[];
420
421Q_SIGNALS:
422 void fileSelected(const QUrl &file);
423 void filesSelected(const QList<QUrl> &files);
424 void currentChanged(const QUrl &path);
425 void directoryEntered(const QUrl &directory);
426 void filterSelected(const QString &filter);
427
428private:
429 QSharedPointer<QFileDialogOptions> m_options;
430};
431
432class Q_GUI_EXPORT QMessageDialogOptions
433{
434 Q_GADGET
435 Q_DISABLE_COPY(QMessageDialogOptions)
436protected:
437 QMessageDialogOptions(QMessageDialogOptionsPrivate *dd);
438 ~QMessageDialogOptions();
439
440public:
441 // Keep in sync with QMessageBox::Icon
442 enum Icon { NoIcon, Information, Warning, Critical, Question };
443 Q_ENUM(Icon)
444
445 static QSharedPointer<QMessageDialogOptions> create();
446 QSharedPointer<QMessageDialogOptions> clone() const;
447
448 QString windowTitle() const;
449 void setWindowTitle(const QString &);
450
451 void setIcon(Icon icon);
452 Icon icon() const;
453
454 void setText(const QString &text);
455 QString text() const;
456
457 void setInformativeText(const QString &text);
458 QString informativeText() const;
459
460 void setDetailedText(const QString &text);
461 QString detailedText() const;
462
463 void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
464 QPlatformDialogHelper::StandardButtons standardButtons() const;
465
466 struct CustomButton {
467 explicit CustomButton(
468 int id = -1, const QString &label = QString(),
469 QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::InvalidRole,
470 void *button = nullptr) :
471 label(label), role(role), id(id), button(button)
472 {}
473
474 QString label;
475 QPlatformDialogHelper::ButtonRole role;
476 int id;
477 void *button; // strictly internal use only
478 };
479
480 int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
481 void *buttonImpl = nullptr);
482 void removeButton(int id);
483 const QVector<CustomButton> &customButtons();
484 const CustomButton *customButton(int id);
485
486private:
487 QMessageDialogOptionsPrivate *d;
488};
489
490class Q_GUI_EXPORT QPlatformMessageDialogHelper : public QPlatformDialogHelper
491{
492 Q_OBJECT
493public:
494 const QSharedPointer<QMessageDialogOptions> &options() const;
495 void setOptions(const QSharedPointer<QMessageDialogOptions> &options);
496
497Q_SIGNALS:
498 void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);
499
500private:
501 QSharedPointer<QMessageDialogOptions> m_options;
502};
503
504QT_END_NAMESPACE
505
506#endif // QPLATFORMDIALOGHELPER_H
507

source code of qtbase/src/gui/kernel/qplatformdialoghelper.h