qdialogbuttonbox.h 5.6 KB

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