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
246Q_DECLARE_OPERATORS_FOR_FLAGS(QFontDialogOptions::FontDialogOptions)
247
248class Q_GUI_EXPORT QPlatformFontDialogHelper : public QPlatformDialogHelper
249{
250 Q_OBJECT
251public:
252 virtual void setCurrentFont(const QFont &) = 0;
253 virtual QFont currentFont() const = 0;
254
255 const QSharedPointer<QFontDialogOptions> &options() const;
256 void setOptions(const QSharedPointer<QFontDialogOptions> &options);
257
258Q_SIGNALS:
259 void currentFontChanged(const QFont &font);
260 void fontSelected(const QFont &font);
261
262private:
263 QSharedPointer<QFontDialogOptions> m_options;
264};
265
266class Q_GUI_EXPORT QFileDialogOptions
267{
268 Q_GADGET
269 Q_DISABLE_COPY(QFileDialogOptions)
270protected:
271 QFileDialogOptions(QFileDialogOptionsPrivate *dd);
272 ~QFileDialogOptions();
273
274public:
275 enum ViewMode { Detail, List };
276 Q_ENUM(ViewMode)
277
278 enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
279 Q_ENUM(FileMode)
280
281 enum AcceptMode { AcceptOpen, AcceptSave };
282 Q_ENUM(AcceptMode)
283
284 enum DialogLabel { LookIn, FileName, FileType, Accept, Reject, DialogLabelCount };
285 Q_ENUM(DialogLabel)
286
287 // keep this in sync with QFileDialog::Options
288 enum FileDialogOption
289 {
290 ShowDirsOnly = 0x00000001,
291 DontResolveSymlinks = 0x00000002,
292 DontConfirmOverwrite = 0x00000004,
293 DontUseNativeDialog = 0x00000008,
294 ReadOnly = 0x00000010,
295 HideNameFilterDetails = 0x00000020,
296 DontUseCustomDirectoryIcons = 0x00000040
297 };
298 Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
299 Q_FLAG(FileDialogOptions)
300
301 static QSharedPointer<QFileDialogOptions> create();
302 QSharedPointer<QFileDialogOptions> clone() const;
303
304 QString windowTitle() const;
305 void setWindowTitle(const QString &);
306
307 void setOption(FileDialogOption option, bool on = true);
308 bool testOption(FileDialogOption option) const;
309 void setOptions(FileDialogOptions options);
310 FileDialogOptions options() const;
311
312 QDir::Filters filter() const;
313 void setFilter(QDir::Filters filters);
314
315 void setViewMode(ViewMode mode);
316 ViewMode viewMode() const;
317
318 void setFileMode(FileMode mode);
319 FileMode fileMode() const;
320
321 void setAcceptMode(AcceptMode mode);
322 AcceptMode acceptMode() const;
323
324 void setSidebarUrls(const QList<QUrl> &urls);
325 QList<QUrl> sidebarUrls() const;
326
327 bool useDefaultNameFilters() const;
328 void setUseDefaultNameFilters(bool d);
329
330 void setNameFilters(const QStringList &filters);
331 QStringList nameFilters() const;
332
333 void setMimeTypeFilters(const QStringList &filters);
334 QStringList mimeTypeFilters() const;
335
336 void setDefaultSuffix(const QString &suffix);
337 QString defaultSuffix() const;
338
339 void setHistory(const QStringList &paths);
340 QStringList history() const;
341
342 void setLabelText(DialogLabel label, const QString &text);
343 QString labelText(DialogLabel label) const;
344 bool isLabelExplicitlySet(DialogLabel label);
345
346 QUrl initialDirectory() const;
347 void setInitialDirectory(const QUrl &);
348
349 QString initiallySelectedMimeTypeFilter() const;
350 void setInitiallySelectedMimeTypeFilter(const QString &);
351
352 QString initiallySelectedNameFilter() const;
353 void setInitiallySelectedNameFilter(const QString &);
354
355 QList<QUrl> initiallySelectedFiles() const;
356 void setInitiallySelectedFiles(const QList<QUrl> &);
357
358 void setSupportedSchemes(const QStringList &schemes);
359 QStringList supportedSchemes() const;
360
361 static QString defaultNameFilterString();
362
363private:
364 QFileDialogOptionsPrivate *d;
365};
366
367class Q_GUI_EXPORT QPlatformFileDialogHelper : public QPlatformDialogHelper
368{
369 Q_OBJECT
370public:
371 virtual bool defaultNameFilterDisables() const = 0;
372 virtual void setDirectory(const QUrl &directory) = 0;
373 virtual QUrl directory() const = 0;
374 virtual void selectFile(const QUrl &filename) = 0;
375 virtual QList<QUrl> selectedFiles() const = 0;
376 virtual void setFilter() = 0;
377 virtual void selectMimeTypeFilter(const QString &filter);
378 virtual void selectNameFilter(const QString &filter) = 0;
379 virtual QString selectedMimeTypeFilter() const;
380 virtual QString selectedNameFilter() const = 0;
381
382 virtual bool isSupportedUrl(const QUrl &url) const;
383
384 const QSharedPointer<QFileDialogOptions> &options() const;
385 void setOptions(const QSharedPointer<QFileDialogOptions> &options);
386
387 static QStringList cleanFilterList(const QString &filter);
388 static const char filterRegExp[];
389
390Q_SIGNALS:
391 void fileSelected(const QUrl &file);
392 void filesSelected(const QList<QUrl> &files);
393 void currentChanged(const QUrl &path);
394 void directoryEntered(const QUrl &directory);
395 void filterSelected(const QString &filter);
396
397private:
398 QSharedPointer<QFileDialogOptions> m_options;
399};
400
401class Q_GUI_EXPORT QMessageDialogOptions
402{
403 Q_GADGET
404 Q_DISABLE_COPY(QMessageDialogOptions)
405protected:
406 QMessageDialogOptions(QMessageDialogOptionsPrivate *dd);
407 ~QMessageDialogOptions();
408
409public:
410 // Keep in sync with QMessageBox Option
411 enum class Option {
412 DontUseNativeDialog = 0x00000001,
413 };
414 Q_DECLARE_FLAGS(Options, Option)
415 Q_FLAG(Options)
416
417 // Keep in sync with QMessageBox::Icon
418 enum StandardIcon { NoIcon, Information, Warning, Critical, Question };
419 Q_ENUM(StandardIcon)
420
421 static QSharedPointer<QMessageDialogOptions> create();
422 QSharedPointer<QMessageDialogOptions> clone() const;
423
424 QString windowTitle() const;
425 void setWindowTitle(const QString &);
426
427 void setStandardIcon(StandardIcon icon);
428 StandardIcon standardIcon() const;
429
430 void setIconPixmap(const QPixmap &pixmap);
431 QPixmap iconPixmap() const;
432
433 void setText(const QString &text);
434 QString text() const;
435
436 void setInformativeText(const QString &text);
437 QString informativeText() const;
438
439 void setDetailedText(const QString &text);
440 QString detailedText() const;
441
442 void setOption(Option option, bool on = true);
443 bool testOption(Option option) const;
444 void setOptions(Options options);
445 Options options() const;
446
447 void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
448 QPlatformDialogHelper::StandardButtons standardButtons() const;
449
450 struct CustomButton {
451 explicit CustomButton(
452 int id = -1, const QString &label = QString(),
453 QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::InvalidRole,
454 void *button = nullptr) :
455 label(label), role(role), id(id), button(button)
456 {}
457
458 QString label;
459 QPlatformDialogHelper::ButtonRole role;
460 int id;
461 void *button; // strictly internal use only
462 };
463
464 int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
465 void *buttonImpl = nullptr, int buttonId = 0);
466 void removeButton(int id);
467 const QList<CustomButton> &customButtons();
468 const CustomButton *customButton(int id);
469 void clearCustomButtons();
470
471 void setCheckBox(const QString &label, Qt::CheckState state);
472 QString checkBoxLabel() const;
473 Qt::CheckState checkBoxState() const;
474
475 void setEscapeButton(int id);
476 int escapeButton() const;
477
478 void setDefaultButton(int id);
479 int defaultButton() const;
480
481private:
482 QMessageDialogOptionsPrivate *d;
483};
484
485class Q_GUI_EXPORT QPlatformMessageDialogHelper : public QPlatformDialogHelper
486{
487 Q_OBJECT
488public:
489 const QSharedPointer<QMessageDialogOptions> &options() const;
490 void setOptions(const QSharedPointer<QMessageDialogOptions> &options);
491
492Q_SIGNALS:
493 void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);
494 void checkBoxStateChanged(Qt::CheckState state);
495
496private:
497 QSharedPointer<QMessageDialogOptions> m_options;
498};
499
500QT_END_NAMESPACE
501
502#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 QPlatformMessageDialogHelper class allows for platform-specific customization of Message dialogs.
static bool operator==(const QMessageDialogOptions::CustomButton &a, const QMessageDialogOptions::CustomButton &b)