1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtWidgets 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 QDIALOGBUTTONBOX_H 41 #define QDIALOGBUTTONBOX_H 42 43 #include <QtWidgets/qtwidgetsglobal.h> 44 #include <QtWidgets/qwidget.h> 45 46 QT_REQUIRE_CONFIG(dialogbuttonbox); 47 48 QT_BEGIN_NAMESPACE 49 50 51 class QAbstractButton; 52 class QPushButton; 53 class QDialogButtonBoxPrivate; 54 55 class Q_WIDGETS_EXPORT QDialogButtonBox : public QWidget 56 { 57 Q_OBJECT 58 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) 59 Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons) 60 Q_PROPERTY(bool centerButtons READ centerButtons WRITE setCenterButtons) 61 62 public: 63 enum ButtonRole { 64 // keep this in sync with QMessageBox::ButtonRole and QPlatformDialogHelper::ButtonRole 65 InvalidRole = -1, 66 AcceptRole, 67 RejectRole, 68 DestructiveRole, 69 ActionRole, 70 HelpRole, 71 YesRole, 72 NoRole, 73 ResetRole, 74 ApplyRole, 75 76 NRoles 77 }; 78 79 enum StandardButton { 80 // keep this in sync with QMessageBox::StandardButton and QPlatformDialogHelper::StandardButton 81 NoButton = 0x00000000, 82 Ok = 0x00000400, 83 Save = 0x00000800, 84 SaveAll = 0x00001000, 85 Open = 0x00002000, 86 Yes = 0x00004000, 87 YesToAll = 0x00008000, 88 No = 0x00010000, 89 NoToAll = 0x00020000, 90 Abort = 0x00040000, 91 Retry = 0x00080000, 92 Ignore = 0x00100000, 93 Close = 0x00200000, 94 Cancel = 0x00400000, 95 Discard = 0x00800000, 96 Help = 0x01000000, 97 Apply = 0x02000000, 98 Reset = 0x04000000, 99 RestoreDefaults = 0x08000000, 100 101 #ifndef Q_MOC_RUN 102 FirstButton = Ok, 103 LastButton = RestoreDefaults 104 #endif 105 }; 106 107 Q_DECLARE_FLAGS(StandardButtons, StandardButton) 108 Q_FLAG(StandardButtons) 109 110 enum ButtonLayout { 111 // keep this in sync with QPlatformDialogHelper::ButtonLayout 112 WinLayout, 113 MacLayout, 114 KdeLayout, 115 GnomeLayout, 116 // MacModelessLayout, 117 AndroidLayout = GnomeLayout + 2 // ### Qt 6: reorder 118 }; 119 120 QDialogButtonBox(QWidget *parent = nullptr); 121 QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr); 122 explicit QDialogButtonBox(StandardButtons buttons, QWidget *parent = nullptr); 123 QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, 124 QWidget *parent = nullptr); 125 ~QDialogButtonBox(); 126 127 void setOrientation(Qt::Orientation orientation); 128 Qt::Orientation orientation() const; 129 130 void addButton(QAbstractButton *button, ButtonRole role); 131 QPushButton *addButton(const QString &text, ButtonRole role); 132 QPushButton *addButton(StandardButton button); 133 void removeButton(QAbstractButton *button); 134 void clear(); 135 136 QList<QAbstractButton *> buttons() const; 137 ButtonRole buttonRole(QAbstractButton *button) const; 138 139 void setStandardButtons(StandardButtons buttons); 140 StandardButtons standardButtons() const; 141 StandardButton standardButton(QAbstractButton *button) const; 142 QPushButton *button(StandardButton which) const; 143 144 void setCenterButtons(bool center); 145 bool centerButtons() const; 146 147 Q_SIGNALS: 148 void clicked(QAbstractButton *button); 149 void accepted(); 150 void helpRequested(); 151 void rejected(); 152 153 protected: 154 void changeEvent(QEvent *event) override; 155 bool event(QEvent *event) override; 156 157 private: 158 Q_DISABLE_COPY(QDialogButtonBox) 159 Q_DECLARE_PRIVATE(QDialogButtonBox) 160 Q_PRIVATE_SLOT(d_func(), void _q_handleButtonClicked()) 161 Q_PRIVATE_SLOT(d_func(), void _q_handleButtonDestroyed()) 162 }; 163 164 Q_DECLARE_OPERATORS_FOR_FLAGS(QDialogButtonBox::StandardButtons) 165 166 QT_END_NAMESPACE 167 168 #endif // QDIALOGBUTTONBOX_H 169