1// Copyright (C) 2016 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 QDIALOGBUTTONBOX_H
5#define QDIALOGBUTTONBOX_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9
10QT_REQUIRE_CONFIG(dialogbuttonbox);
11
12QT_BEGIN_NAMESPACE
13
14
15class QAbstractButton;
16class QPushButton;
17class QDialogButtonBoxPrivate;
18
19class Q_WIDGETS_EXPORT QDialogButtonBox : public QWidget
20{
21 Q_OBJECT
22 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
23 Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
24 Q_PROPERTY(bool centerButtons READ centerButtons WRITE setCenterButtons)
25
26public:
27 enum ButtonRole {
28 // keep this in sync with QMessageBox::ButtonRole and QPlatformDialogHelper::ButtonRole
29 InvalidRole = -1,
30 AcceptRole,
31 RejectRole,
32 DestructiveRole,
33 ActionRole,
34 HelpRole,
35 YesRole,
36 NoRole,
37 ResetRole,
38 ApplyRole,
39
40 NRoles
41 };
42
43 enum StandardButton {
44 // keep this in sync with QMessageBox::StandardButton and QPlatformDialogHelper::StandardButton
45 NoButton = 0x00000000,
46 Ok = 0x00000400,
47 Save = 0x00000800,
48 SaveAll = 0x00001000,
49 Open = 0x00002000,
50 Yes = 0x00004000,
51 YesToAll = 0x00008000,
52 No = 0x00010000,
53 NoToAll = 0x00020000,
54 Abort = 0x00040000,
55 Retry = 0x00080000,
56 Ignore = 0x00100000,
57 Close = 0x00200000,
58 Cancel = 0x00400000,
59 Discard = 0x00800000,
60 Help = 0x01000000,
61 Apply = 0x02000000,
62 Reset = 0x04000000,
63 RestoreDefaults = 0x08000000,
64
65#ifndef Q_MOC_RUN
66 FirstButton = Ok,
67 LastButton = RestoreDefaults
68#endif
69 };
70
71 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
72 Q_FLAG(StandardButtons)
73
74 enum ButtonLayout {
75 // keep this in sync with QPlatformDialogHelper::ButtonLayout
76 WinLayout,
77 MacLayout,
78 KdeLayout,
79 GnomeLayout,
80 AndroidLayout
81 };
82
83 QDialogButtonBox(QWidget *parent = nullptr);
84 QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr);
85 explicit QDialogButtonBox(StandardButtons buttons, QWidget *parent = nullptr);
86 QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation,
87 QWidget *parent = nullptr);
88 ~QDialogButtonBox();
89
90 void setOrientation(Qt::Orientation orientation);
91 Qt::Orientation orientation() const;
92
93 void addButton(QAbstractButton *button, ButtonRole role);
94 QPushButton *addButton(const QString &text, ButtonRole role);
95 QPushButton *addButton(StandardButton button);
96 void removeButton(QAbstractButton *button);
97 void clear();
98
99 QList<QAbstractButton *> buttons() const;
100 ButtonRole buttonRole(QAbstractButton *button) const;
101
102 void setStandardButtons(StandardButtons buttons);
103 StandardButtons standardButtons() const;
104 StandardButton standardButton(QAbstractButton *button) const;
105 QPushButton *button(StandardButton which) const;
106
107 void setCenterButtons(bool center);
108 bool centerButtons() const;
109
110Q_SIGNALS:
111 void clicked(QAbstractButton *button);
112 void accepted();
113 void helpRequested();
114 void rejected();
115
116protected:
117 void changeEvent(QEvent *event) override;
118 bool event(QEvent *event) override;
119
120private:
121 Q_DISABLE_COPY(QDialogButtonBox)
122 Q_DECLARE_PRIVATE(QDialogButtonBox)
123};
124
125Q_DECLARE_OPERATORS_FOR_FLAGS(QDialogButtonBox::StandardButtons)
126
127QT_END_NAMESPACE
128
129#endif // QDIALOGBUTTONBOX_H
130

source code of qtbase/src/widgets/widgets/qdialogbuttonbox.h