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