qwizard.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 QWIZARD_H
  40. #define QWIZARD_H
  41. #include <QtWidgets/qdialog.h>
  42. QT_BEGIN_NAMESPACE
  43. #ifndef QT_NO_WIZARD
  44. class QAbstractButton;
  45. class QWizardPage;
  46. class QWizardPrivate;
  47. class Q_WIDGETS_EXPORT QWizard : public QDialog
  48. {
  49. Q_OBJECT
  50. Q_FLAGS(WizardOptions)
  51. Q_PROPERTY(WizardStyle wizardStyle READ wizardStyle WRITE setWizardStyle)
  52. Q_PROPERTY(WizardOptions options READ options WRITE setOptions)
  53. Q_PROPERTY(Qt::TextFormat titleFormat READ titleFormat WRITE setTitleFormat)
  54. Q_PROPERTY(Qt::TextFormat subTitleFormat READ subTitleFormat WRITE setSubTitleFormat)
  55. Q_PROPERTY(int startId READ startId WRITE setStartId)
  56. Q_PROPERTY(int currentId READ currentId NOTIFY currentIdChanged)
  57. public:
  58. enum WizardButton {
  59. BackButton,
  60. NextButton,
  61. CommitButton,
  62. FinishButton,
  63. CancelButton,
  64. HelpButton,
  65. CustomButton1,
  66. CustomButton2,
  67. CustomButton3,
  68. Stretch,
  69. NoButton = -1,
  70. NStandardButtons = 6,
  71. NButtons = 9
  72. };
  73. enum WizardPixmap {
  74. WatermarkPixmap,
  75. LogoPixmap,
  76. BannerPixmap,
  77. BackgroundPixmap,
  78. NPixmaps
  79. };
  80. enum WizardStyle {
  81. ClassicStyle,
  82. ModernStyle,
  83. MacStyle,
  84. AeroStyle,
  85. NStyles
  86. };
  87. Q_ENUM(WizardStyle)
  88. enum WizardOption {
  89. IndependentPages = 0x00000001,
  90. IgnoreSubTitles = 0x00000002,
  91. ExtendedWatermarkPixmap = 0x00000004,
  92. NoDefaultButton = 0x00000008,
  93. NoBackButtonOnStartPage = 0x00000010,
  94. NoBackButtonOnLastPage = 0x00000020,
  95. DisabledBackButtonOnLastPage = 0x00000040,
  96. HaveNextButtonOnLastPage = 0x00000080,
  97. HaveFinishButtonOnEarlyPages = 0x00000100,
  98. NoCancelButton = 0x00000200,
  99. CancelButtonOnLeft = 0x00000400,
  100. HaveHelpButton = 0x00000800,
  101. HelpButtonOnRight = 0x00001000,
  102. HaveCustomButton1 = 0x00002000,
  103. HaveCustomButton2 = 0x00004000,
  104. HaveCustomButton3 = 0x00008000,
  105. NoCancelButtonOnLastPage = 0x00010000
  106. };
  107. Q_ENUM(WizardOption)
  108. Q_DECLARE_FLAGS(WizardOptions, WizardOption)
  109. explicit QWizard(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
  110. ~QWizard();
  111. int addPage(QWizardPage *page);
  112. void setPage(int id, QWizardPage *page);
  113. void removePage(int id);
  114. QWizardPage *page(int id) const;
  115. bool hasVisitedPage(int id) const;
  116. QList<int> visitedPages() const; // ### Qt 6: visitedIds()?
  117. QList<int> pageIds() const;
  118. void setStartId(int id);
  119. int startId() const;
  120. QWizardPage *currentPage() const;
  121. int currentId() const;
  122. virtual bool validateCurrentPage();
  123. virtual int nextId() const;
  124. void setField(const QString &name, const QVariant &value);
  125. QVariant field(const QString &name) const;
  126. void setWizardStyle(WizardStyle style);
  127. WizardStyle wizardStyle() const;
  128. void setOption(WizardOption option, bool on = true);
  129. bool testOption(WizardOption option) const;
  130. void setOptions(WizardOptions options);
  131. WizardOptions options() const;
  132. void setButtonText(WizardButton which, const QString &text);
  133. QString buttonText(WizardButton which) const;
  134. void setButtonLayout(const QList<WizardButton> &layout);
  135. void setButton(WizardButton which, QAbstractButton *button);
  136. QAbstractButton *button(WizardButton which) const;
  137. void setTitleFormat(Qt::TextFormat format);
  138. Qt::TextFormat titleFormat() const;
  139. void setSubTitleFormat(Qt::TextFormat format);
  140. Qt::TextFormat subTitleFormat() const;
  141. void setPixmap(WizardPixmap which, const QPixmap &pixmap);
  142. QPixmap pixmap(WizardPixmap which) const;
  143. void setSideWidget(QWidget *widget);
  144. QWidget *sideWidget() const;
  145. void setDefaultProperty(const char *className, const char *property,
  146. const char *changedSignal);
  147. void setVisible(bool visible) Q_DECL_OVERRIDE;
  148. QSize sizeHint() const Q_DECL_OVERRIDE;
  149. Q_SIGNALS:
  150. void currentIdChanged(int id);
  151. void helpRequested();
  152. void customButtonClicked(int which);
  153. void pageAdded(int id);
  154. void pageRemoved(int id);
  155. public Q_SLOTS:
  156. void back();
  157. void next();
  158. void restart();
  159. protected:
  160. bool event(QEvent *event) Q_DECL_OVERRIDE;
  161. void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
  162. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  163. #ifdef Q_OS_WIN
  164. bool nativeEvent(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
  165. #endif
  166. void done(int result) Q_DECL_OVERRIDE;
  167. virtual void initializePage(int id);
  168. virtual void cleanupPage(int id);
  169. private:
  170. Q_DISABLE_COPY(QWizard)
  171. Q_DECLARE_PRIVATE(QWizard)
  172. Q_PRIVATE_SLOT(d_func(), void _q_emitCustomButtonClicked())
  173. Q_PRIVATE_SLOT(d_func(), void _q_updateButtonStates())
  174. Q_PRIVATE_SLOT(d_func(), void _q_handleFieldObjectDestroyed(QObject *))
  175. friend class QWizardPage;
  176. };
  177. Q_DECLARE_OPERATORS_FOR_FLAGS(QWizard::WizardOptions)
  178. class QWizardPagePrivate;
  179. class Q_WIDGETS_EXPORT QWizardPage : public QWidget
  180. {
  181. Q_OBJECT
  182. Q_PROPERTY(QString title READ title WRITE setTitle)
  183. Q_PROPERTY(QString subTitle READ subTitle WRITE setSubTitle)
  184. public:
  185. explicit QWizardPage(QWidget *parent = Q_NULLPTR);
  186. ~QWizardPage();
  187. void setTitle(const QString &title);
  188. QString title() const;
  189. void setSubTitle(const QString &subTitle);
  190. QString subTitle() const;
  191. void setPixmap(QWizard::WizardPixmap which, const QPixmap &pixmap);
  192. QPixmap pixmap(QWizard::WizardPixmap which) const;
  193. void setFinalPage(bool finalPage);
  194. bool isFinalPage() const;
  195. void setCommitPage(bool commitPage);
  196. bool isCommitPage() const;
  197. void setButtonText(QWizard::WizardButton which, const QString &text);
  198. QString buttonText(QWizard::WizardButton which) const;
  199. virtual void initializePage();
  200. virtual void cleanupPage();
  201. virtual bool validatePage();
  202. virtual bool isComplete() const;
  203. virtual int nextId() const;
  204. Q_SIGNALS:
  205. void completeChanged();
  206. protected:
  207. void setField(const QString &name, const QVariant &value);
  208. QVariant field(const QString &name) const;
  209. void registerField(const QString &name, QWidget *widget, const char *property = Q_NULLPTR,
  210. const char *changedSignal = Q_NULLPTR);
  211. QWizard *wizard() const;
  212. private:
  213. Q_DISABLE_COPY(QWizardPage)
  214. Q_DECLARE_PRIVATE(QWizardPage)
  215. Q_PRIVATE_SLOT(d_func(), void _q_maybeEmitCompleteChanged())
  216. Q_PRIVATE_SLOT(d_func(), void _q_updateCachedCompleteState())
  217. friend class QWizard;
  218. friend class QWizardPrivate;
  219. };
  220. QT_END_NAMESPACE
  221. #endif // QT_NO_WIZARD
  222. #endif // QWIZARD_H