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