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> visitedIds() const;
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 bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
192#endif
193 void done(int result) override;
194 virtual void initializePage(int id);
195 virtual void cleanupPage(int id);
196
197private:
198 Q_DISABLE_COPY(QWizard)
199 Q_DECLARE_PRIVATE(QWizard)
200 Q_PRIVATE_SLOT(d_func(), void _q_emitCustomButtonClicked())
201 Q_PRIVATE_SLOT(d_func(), void _q_updateButtonStates())
202 Q_PRIVATE_SLOT(d_func(), void _q_handleFieldObjectDestroyed(QObject *))
203
204 friend class QWizardPage;
205};
206
207Q_DECLARE_OPERATORS_FOR_FLAGS(QWizard::WizardOptions)
208
209class QWizardPagePrivate;
210
211class Q_WIDGETS_EXPORT QWizardPage : public QWidget
212{
213 Q_OBJECT
214 Q_PROPERTY(QString title READ title WRITE setTitle)
215 Q_PROPERTY(QString subTitle READ subTitle WRITE setSubTitle)
216
217public:
218 explicit QWizardPage(QWidget *parent = nullptr);
219 ~QWizardPage();
220
221 void setTitle(const QString &title);
222 QString title() const;
223 void setSubTitle(const QString &subTitle);
224 QString subTitle() const;
225 void setPixmap(QWizard::WizardPixmap which, const QPixmap &pixmap);
226 QPixmap pixmap(QWizard::WizardPixmap which) const;
227 void setFinalPage(bool finalPage);
228 bool isFinalPage() const;
229 void setCommitPage(bool commitPage);
230 bool isCommitPage() const;
231 void setButtonText(QWizard::WizardButton which, const QString &text);
232 QString buttonText(QWizard::WizardButton which) const;
233
234 virtual void initializePage();
235 virtual void cleanupPage();
236 virtual bool validatePage();
237 virtual bool isComplete() const;
238 virtual int nextId() const;
239
240Q_SIGNALS:
241 void completeChanged();
242
243protected:
244 void setField(const QString &name, const QVariant &value);
245 QVariant field(const QString &name) const;
246 void registerField(const QString &name, QWidget *widget, const char *property = nullptr,
247 const char *changedSignal = nullptr);
248 QWizard *wizard() const;
249
250private:
251 Q_DISABLE_COPY(QWizardPage)
252 Q_DECLARE_PRIVATE(QWizardPage)
253 Q_PRIVATE_SLOT(d_func(), void _q_maybeEmitCompleteChanged())
254 Q_PRIVATE_SLOT(d_func(), void _q_updateCachedCompleteState())
255
256 friend class QWizard;
257 friend class QWizardPrivate;
258};
259
260QT_END_NAMESPACE
261
262#endif // QWIZARD_H
263