FreeCAD

Форк
0
232 строки · 6.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2007 Werner Mayer <wmayer@users.sourceforge.net>        *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include <QtGui>
25

26
#include "wizard.h"
27

28
Wizard::Wizard(QWidget* parent)
29
    : QDialog(parent)
30
{
31
    textLabel = new QLabel();
32

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);
39

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);
47

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()));
52

53
    buttonLayout = new QHBoxLayout;
54
    buttonLayout->addStretch(1);
55
    buttonLayout->addWidget(_cancelButton);
56
    buttonLayout->addWidget(_backButton);
57
    buttonLayout->addWidget(_nextButton);
58
    buttonLayout->addWidget(_finishButton);
59

60
    stackWidget = new QStackedWidget();
61

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);
69
}
70

71
QSize Wizard::sizeHint() const
72
{
73
    return QSize(200, 150);
74
}
75

76
void Wizard::addPage(QWidget* page)
77
{
78
    insertPage(count(), page);
79
}
80

81
void Wizard::removePage(int index)
82
{
83
    QWidget* widget = stackWidget->widget(index);
84
    stackWidget->removeWidget(widget);
85

86
    index = currentIndex();
87
    _backButton->setEnabled(index > 0);
88
    _nextButton->setEnabled(index < count() - 1);
89
}
90

91
int Wizard::count() const
92
{
93
    return stackWidget->count();
94
}
95

96
int Wizard::currentIndex() const
97
{
98
    return stackWidget->currentIndex();
99
}
100

101
void Wizard::insertPage(int index, QWidget* page)
102
{
103
    page->setParent(stackWidget);
104

105
    stackWidget->insertWidget(index, page);
106

107
    QString title = page->windowTitle();
108
    if (title.isEmpty()) {
109
        title = tr("Page %1").arg(stackWidget->count());
110
        page->setWindowTitle(title);
111
    }
112

113
    if (currentIndex() == index) {
114
        textLabel->setText(title);
115
    }
116

117
    int current = currentIndex();
118
    _backButton->setEnabled(current > 0);
119
    _nextButton->setEnabled(current < count() - 1);
120
}
121

122
void Wizard::backButtonClicked()
123
{
124
    int index = currentIndex();
125
    if (index > 0) {
126
        setCurrentIndex(index - 1);
127
    }
128
}
129

130
void Wizard::nextButtonClicked()
131
{
132
    int index = currentIndex();
133
    if (index < count() - 1) {
134
        setCurrentIndex(index + 1);
135
    }
136
}
137

138
QPushButton* Wizard::backButton() const
139
{
140
    return _backButton;
141
}
142

143
QPushButton* Wizard::nextButton() const
144
{
145
    return _nextButton;
146
}
147

148
void Wizard::setCurrentIndex(int index)
149
{
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);
156
    }
157
}
158

159
QWidget* Wizard::widget(int index)
160
{
161
    return stackWidget->widget(index);
162
}
163

164
QString Wizard::pageTitle() const
165
{
166
    return stackWidget->currentWidget()->windowTitle();
167
}
168

169
void Wizard::setPageTitle(QString const& newTitle)
170
{
171
    stackWidget->currentWidget()->setWindowTitle(newTitle);
172
    textLabel->setText(newTitle);
173
    Q_EMIT pageTitleChanged(newTitle);
174
}
175

176
WizardExtension::WizardExtension(Wizard* widget, QObject* parent)
177
    : QObject(parent)
178
{
179
    myWidget = widget;
180
}
181

182
void WizardExtension::addWidget(QWidget* widget)
183
{
184
    myWidget->addPage(widget);
185
}
186

187
int WizardExtension::count() const
188
{
189
    return myWidget->count();
190
}
191

192
int WizardExtension::currentIndex() const
193
{
194
    return myWidget->currentIndex();
195
}
196

197
void WizardExtension::insertWidget(int index, QWidget* widget)
198
{
199
    myWidget->insertPage(index, widget);
200
}
201

202
void WizardExtension::remove(int index)
203
{
204
    myWidget->removePage(index);
205
}
206

207
void WizardExtension::setCurrentIndex(int index)
208
{
209
    myWidget->setCurrentIndex(index);
210
}
211

212
QWidget* WizardExtension::widget(int index) const
213
{
214
    return myWidget->widget(index);
215
}
216

217
WizardExtensionFactory::WizardExtensionFactory(QExtensionManager* parent)
218
    : QExtensionFactory(parent)
219
{}
220

221
QObject*
222
WizardExtensionFactory::createExtension(QObject* object, const QString& iid, QObject* parent) const
223
{
224
    Wizard* widget = qobject_cast<Wizard*>(object);
225

226
    if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
227
        return new WizardExtension(widget, parent);
228
    }
229
    else {
230
        return 0;
231
    }
232
}
233

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.