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