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