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