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