QtBase  v6.3.1
qplatformdialoghelper.h
Go to the documentation of this file.
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>
63 
65 
66 
67 class QString;
68 class QColor;
69 class QFont;
70 class QWindow;
71 class QVariant;
72 class QUrl;
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 
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,
135 
137 
138  RoleMask = 0x0FFFFFFF,
139  AlternateRole = 0x10000000,
140  Stretch = 0x20000000,
141  Reverse = 0x40000000,
142  EOL = InvalidRole
143  };
144  Q_ENUM(ButtonRole)
145 
147  // keep this in sync with QDialogButtonBox::ButtonLayout
148  UnknownLayout = -1,
153  AndroidLayout
154  };
155  Q_ENUM(ButtonLayout)
156 
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 
182 
183 class Q_GUI_EXPORT QColorDialogOptions
184 {
185  Q_GADGET
187 protected:
190 public:
192  ShowAlphaChannel = 0x00000001,
193  NoButtons = 0x00000002,
194  DontUseNativeDialog = 0x00000004
195  };
196 
197  Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
198  Q_FLAG(ColorDialogOptions)
199 
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:
222 };
223 
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:
236  void colorSelected(const QColor &color);
237 
238 private:
240 };
241 
242 class Q_GUI_EXPORT QFontDialogOptions
243 {
244  Q_GADGET
246 protected:
249 
250 public:
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 
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:
276 };
277 
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:
290  void fontSelected(const QFont &font);
291 
292 private:
294 };
295 
296 class Q_GUI_EXPORT QFileDialogOptions
297 {
298  Q_GADGET
300 protected:
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  // keep this in sync with QFileDialog::Options
319  {
320  ShowDirsOnly = 0x00000001,
321  DontResolveSymlinks = 0x00000002,
322  DontConfirmOverwrite = 0x00000004,
323  DontUseNativeDialog = 0x00000008,
324  ReadOnly = 0x00000010,
325  HideNameFilterDetails = 0x00000020,
326  DontUseCustomDirectoryIcons = 0x00000040
327  };
328  Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
329  Q_FLAG(FileDialogOptions)
330 
333 
334  QString windowTitle() const;
335  void setWindowTitle(const QString &);
336 
337  void setOption(FileDialogOption option, bool on = true);
338  bool testOption(FileDialogOption option) const;
339  void setOptions(FileDialogOptions options);
340  FileDialogOptions options() const;
341 
342  QDir::Filters filter() const;
343  void setFilter(QDir::Filters filters);
344 
345  void setViewMode(ViewMode mode);
346  ViewMode viewMode() const;
347 
348  void setFileMode(FileMode mode);
349  FileMode fileMode() const;
350 
351  void setAcceptMode(AcceptMode mode);
352  AcceptMode acceptMode() const;
353 
354  void setSidebarUrls(const QList<QUrl> &urls);
355  QList<QUrl> sidebarUrls() const;
356 
357  bool useDefaultNameFilters() const;
358  void setUseDefaultNameFilters(bool d);
359 
360  void setNameFilters(const QStringList &filters);
361  QStringList nameFilters() const;
362 
365 
366  void setDefaultSuffix(const QString &suffix);
367  QString defaultSuffix() const;
368 
369  void setHistory(const QStringList &paths);
370  QStringList history() const;
371 
372  void setLabelText(DialogLabel label, const QString &text);
373  QString labelText(DialogLabel label) const;
374  bool isLabelExplicitlySet(DialogLabel label);
375 
376  QUrl initialDirectory() const;
377  void setInitialDirectory(const QUrl &);
378 
379  QString initiallySelectedMimeTypeFilter() const;
380  void setInitiallySelectedMimeTypeFilter(const QString &);
381 
382  QString initiallySelectedNameFilter() const;
383  void setInitiallySelectedNameFilter(const QString &);
384 
385  QList<QUrl> initiallySelectedFiles() const;
386  void setInitiallySelectedFiles(const QList<QUrl> &);
387 
388  void setSupportedSchemes(const QStringList &schemes);
389  QStringList supportedSchemes() const;
390 
391  static QString defaultNameFilterString();
392 
393 private:
395 };
396 
398 {
399  Q_OBJECT
400 public:
401  virtual bool defaultNameFilterDisables() const = 0;
402  virtual void setDirectory(const QUrl &directory) = 0;
403  virtual QUrl directory() const = 0;
404  virtual void selectFile(const QUrl &filename) = 0;
405  virtual QList<QUrl> selectedFiles() const = 0;
406  virtual void setFilter() = 0;
407  virtual void selectMimeTypeFilter(const QString &filter);
408  virtual void selectNameFilter(const QString &filter) = 0;
409  virtual QString selectedMimeTypeFilter() const;
410  virtual QString selectedNameFilter() const = 0;
411 
412  virtual bool isSupportedUrl(const QUrl &url) const;
413 
414  const QSharedPointer<QFileDialogOptions> &options() const;
415  void setOptions(const QSharedPointer<QFileDialogOptions> &options);
416 
417  static QStringList cleanFilterList(const QString &filter);
418  static const char filterRegExp[];
419 
420 Q_SIGNALS:
421  void fileSelected(const QUrl &file);
423  void currentChanged(const QUrl &path);
424  void directoryEntered(const QUrl &directory);
426 
427 private:
429 };
430 
431 class Q_GUI_EXPORT QMessageDialogOptions
432 {
433  Q_GADGET
435 protected:
438 
439 public:
440  // Keep in sync with QMessageBox::Icon
441  enum Icon { NoIcon, Information, Warning, Critical, Question };
442  Q_ENUM(Icon)
443 
446 
447  QString windowTitle() const;
448  void setWindowTitle(const QString &);
449 
450  void setIcon(Icon icon);
451  Icon icon() const;
452 
453  void setText(const QString &text);
454  QString text() const;
455 
456  void setInformativeText(const QString &text);
457  QString informativeText() const;
458 
459  void setDetailedText(const QString &text);
460  QString detailedText() const;
461 
462  void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
463  QPlatformDialogHelper::StandardButtons standardButtons() const;
464 
465  struct CustomButton {
466  explicit CustomButton(
467  int id = -1, const QString &label = QString(),
469  void *button = nullptr) :
470  label(label), role(role), id(id), button(button)
471  {}
472 
475  int id;
476  void *button; // strictly internal use only
477  };
478 
479  int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
480  void *buttonImpl = nullptr);
481  void removeButton(int id);
482  const QList<CustomButton> &customButtons();
483  const CustomButton *customButton(int id);
484 
485 private:
487 };
488 
490 {
491  Q_OBJECT
492 public:
493  const QSharedPointer<QMessageDialogOptions> &options() const;
494  void setOptions(const QSharedPointer<QMessageDialogOptions> &options);
495 
496 Q_SIGNALS:
498 
499 private:
501 };
502 
504 
505 #endif // QPLATFORMDIALOGHELPER_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
virtual void setCurrentColor(const QColor &)=0
void currentColorChanged(const QColor &color)
void colorSelected(const QColor &color)
virtual QColor currentColor() const =0
virtual void exec()=0
virtual void hide()=0
virtual bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent)=0
virtual void selectNameFilter(const QString &filter)=0
void fileSelected(const QUrl &file)
virtual void setFilter()=0
virtual QList< QUrl > selectedFiles() const =0
virtual QUrl directory() const =0
virtual QString selectedNameFilter() const =0
virtual void setDirectory(const QUrl &directory)=0
void currentChanged(const QUrl &path)
virtual void selectFile(const QUrl &filename)=0
void directoryEntered(const QUrl &directory)
void filterSelected(const QString &filter)
virtual bool defaultNameFilterDisables() const =0
void filesSelected(const QList< QUrl > &files)
virtual QFont currentFont() const =0
void fontSelected(const QFont &font)
virtual void setCurrentFont(const QFont &)=0
void currentFontChanged(const QFont &font)
void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:130
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
msgBox setStandardButtons(QMessageBox::Yes|QMessageBox::No)
msgBox setInformativeText("Do you want to save your changes?")
QPushButton * button
[2]
@ NoButton
Definition: qnamespace.h:82
WindowModality
Definition: qnamespace.h:1563
Orientation
Definition: qnamespace.h:123
@ Horizontal
Definition: qnamespace.h:124
#define QString()
Definition: parse-defines.h:51
@ Ok
Definition: qbezier.cpp:209
@ Discard
Definition: qbezier.cpp:210
SharedPointerFileDialogOptions m_options
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
@ text
#define Q_DECLARE_METATYPE(TYPE)
Definition: qmetatype.h:1417
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum mode
GLuint index
[2]
GLuint color
[2]
GLsizei const GLuint * paths
GLuint GLsizei const GLchar * label
[43]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
GLuint GLenum option
Definition: qopenglext.h:5929
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition: qrgb.h:49
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_FLAG(x)
Definition: qtmetamacros.h:105
#define Q_GADGET
Definition: qtmetamacros.h:193
#define Q_MOC_INCLUDE(...)
Definition: qtmetamacros.h:115
#define Q_SIGNALS
Definition: qtmetamacros.h:81
QIcon icon
[15]
QFile file
[0]
QUrl url("http://www.example.com/List of holidays.xml")
[0]
MyClass setText
QStringList mimeTypeFilters({"image/jpeg", "image/png", "application/octet-stream" })
[12]
dialog setViewMode(QFileDialog::Detail)
[3]
dialog setMimeTypeFilters(mimeTypeFilters)
dialog setNameFilters(filters)
QStringList files
[8]
dialog setFileMode(QFileDialog::AnyFile)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
myAction setIcon(SomeIcon)
QSizePolicy policy
view create()
CustomButton(int id=-1, const QString &label=QString(), QPlatformDialogHelper::ButtonRole role=QPlatformDialogHelper::InvalidRole, void *button=nullptr)
QPlatformDialogHelper::ButtonRole role
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
virtual HRESULT STDMETHODCALLTYPE Close(void)=0