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

source code of qtbase/src/widgets/dialogs/qwizard.h