1
/***************************************************************************
2
* Copyright (c) 2007 Werner Mayer <wmayer@users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
28
Wizard::Wizard(QWidget* parent)
31
textLabel = new QLabel();
33
topLine = new QFrame();
34
topLine->setFrameShape(QFrame::HLine);
35
topLine->setFrameShadow(QFrame::Sunken);
36
bottomLine = new QFrame();
37
bottomLine->setFrameShape(QFrame::HLine);
38
bottomLine->setFrameShadow(QFrame::Sunken);
40
_cancelButton = new QPushButton(tr("Cancel"));
41
_backButton = new QPushButton(tr("< &Back"));
42
_backButton->setDisabled(true);
43
_nextButton = new QPushButton(tr("Next >"));
44
_nextButton->setDisabled(true);
45
_finishButton = new QPushButton(tr("&Finish"));
46
_finishButton->setDisabled(true);
48
connect(_cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
49
connect(_backButton, SIGNAL(clicked()), this, SLOT(backButtonClicked()));
50
connect(_nextButton, SIGNAL(clicked()), this, SLOT(nextButtonClicked()));
51
connect(_finishButton, SIGNAL(clicked()), this, SLOT(accept()));
53
buttonLayout = new QHBoxLayout;
54
buttonLayout->addStretch(1);
55
buttonLayout->addWidget(_cancelButton);
56
buttonLayout->addWidget(_backButton);
57
buttonLayout->addWidget(_nextButton);
58
buttonLayout->addWidget(_finishButton);
60
stackWidget = new QStackedWidget();
62
mainLayout = new QVBoxLayout();
63
mainLayout->addWidget(textLabel);
64
mainLayout->addWidget(topLine);
65
mainLayout->addWidget(stackWidget);
66
mainLayout->addWidget(bottomLine);
67
mainLayout->addLayout(buttonLayout);
68
setLayout(mainLayout);
71
QSize Wizard::sizeHint() const
73
return QSize(200, 150);
76
void Wizard::addPage(QWidget* page)
78
insertPage(count(), page);
81
void Wizard::removePage(int index)
83
QWidget* widget = stackWidget->widget(index);
84
stackWidget->removeWidget(widget);
86
index = currentIndex();
87
_backButton->setEnabled(index > 0);
88
_nextButton->setEnabled(index < count() - 1);
91
int Wizard::count() const
93
return stackWidget->count();
96
int Wizard::currentIndex() const
98
return stackWidget->currentIndex();
101
void Wizard::insertPage(int index, QWidget* page)
103
page->setParent(stackWidget);
105
stackWidget->insertWidget(index, page);
107
QString title = page->windowTitle();
108
if (title.isEmpty()) {
109
title = tr("Page %1").arg(stackWidget->count());
110
page->setWindowTitle(title);
113
if (currentIndex() == index) {
114
textLabel->setText(title);
117
int current = currentIndex();
118
_backButton->setEnabled(current > 0);
119
_nextButton->setEnabled(current < count() - 1);
122
void Wizard::backButtonClicked()
124
int index = currentIndex();
126
setCurrentIndex(index - 1);
130
void Wizard::nextButtonClicked()
132
int index = currentIndex();
133
if (index < count() - 1) {
134
setCurrentIndex(index + 1);
138
QPushButton* Wizard::backButton() const
143
QPushButton* Wizard::nextButton() const
148
void Wizard::setCurrentIndex(int index)
150
if (index != currentIndex()) {
151
stackWidget->setCurrentIndex(index);
152
textLabel->setText(stackWidget->currentWidget()->windowTitle());
153
_backButton->setEnabled(index > 0);
154
_nextButton->setEnabled(index < count() - 1);
155
Q_EMIT currentIndexChanged(index);
159
QWidget* Wizard::widget(int index)
161
return stackWidget->widget(index);
164
QString Wizard::pageTitle() const
166
return stackWidget->currentWidget()->windowTitle();
169
void Wizard::setPageTitle(QString const& newTitle)
171
stackWidget->currentWidget()->setWindowTitle(newTitle);
172
textLabel->setText(newTitle);
173
Q_EMIT pageTitleChanged(newTitle);
176
WizardExtension::WizardExtension(Wizard* widget, QObject* parent)
182
void WizardExtension::addWidget(QWidget* widget)
184
myWidget->addPage(widget);
187
int WizardExtension::count() const
189
return myWidget->count();
192
int WizardExtension::currentIndex() const
194
return myWidget->currentIndex();
197
void WizardExtension::insertWidget(int index, QWidget* widget)
199
myWidget->insertPage(index, widget);
202
void WizardExtension::remove(int index)
204
myWidget->removePage(index);
207
void WizardExtension::setCurrentIndex(int index)
209
myWidget->setCurrentIndex(index);
212
QWidget* WizardExtension::widget(int index) const
214
return myWidget->widget(index);
217
WizardExtensionFactory::WizardExtensionFactory(QExtensionManager* parent)
218
: QExtensionFactory(parent)
222
WizardExtensionFactory::createExtension(QObject* object, const QString& iid, QObject* parent) const
224
Wizard* widget = qobject_cast<Wizard*>(object);
226
if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
227
return new WizardExtension(widget, parent);