Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "addlibrarywizard.h"
#include "ui_librarydetailswidget.h"
#include "librarydetailscontroller.h"
#include <QtGui/QVBoxLayout>
#include <QtGui/QRadioButton>
#include <QtGui/QLabel>
#include <QtCore/QFileInfo>
#include <QDebug>
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
const char *qt_file_dialog_filter_reg_exp =
"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
// taken from qfiledialog.cpp
QStringList qt_clean_filter_list(const QString &filter)
{
QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
QString f = filter;
int i = regexp.indexIn(f);
if (i >= 0)
f = regexp.cap(2);
return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
}
LibraryPathChooser::LibraryPathChooser(QWidget *parent)
: Utils::PathChooser(parent)
{
}
bool LibraryPathChooser::validatePath(const QString &path, QString *errorMessage)
{
bool result = PathChooser::validatePath(path, errorMessage);
if (!result)
return false;
QFileInfo fi(path);
if (!fi.exists())
return false;
const QString fileName = fi.fileName();
QStringList filters = qt_clean_filter_list(promptDialogFilter());
for (int i = 0; i < filters.count(); i++) {
QRegExp regExp(filters.at(i));
regExp.setPatternSyntax(QRegExp::Wildcard);
if (regExp.exactMatch(fileName))
return true;
}
return false;
}
AddLibraryWizard::AddLibraryWizard(const QString &fileName, QWidget *parent) :
Utils::Wizard(parent), m_proFile(fileName)
{
setWindowTitle(tr("Add Library"));
setAutomaticProgressCreationEnabled(false);
m_libraryTypePage = new LibraryTypePage(this);
m_detailsPage = new DetailsPage(this);
m_summaryPage = new SummaryPage(this);
setPage(LibraryTypePageId, m_libraryTypePage);
setPage(DetailsPageId, m_detailsPage);
setPage(SummaryPageId, m_summaryPage);
Utils::WizardProgress *progress = wizardProgress();
Utils::WizardProgressItem *kindItem = progress->addItem(tr("Type"));
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Utils::WizardProgressItem *detailsItem = progress->addItem(tr("Details"));
Utils::WizardProgressItem *summaryItem = progress->addItem(tr("Summary"));
kindItem->addPage(LibraryTypePageId);
detailsItem->addPage(DetailsPageId);
summaryItem->addPage(SummaryPageId);
kindItem->setNextItems(QList<Utils::WizardProgressItem *>() << detailsItem);
detailsItem->setNextItems(QList<Utils::WizardProgressItem *>() << summaryItem);
setStartId(LibraryTypePageId);
}
AddLibraryWizard::~AddLibraryWizard()
{
}
QString AddLibraryWizard::proFile() const
{
return m_proFile;
}
AddLibraryWizard::LibraryKind AddLibraryWizard::libraryKind() const
{
return m_libraryTypePage->libraryKind();
}
QString AddLibraryWizard::snippet() const
{
return m_detailsPage->snippet();
}
/////////////
LibraryTypePage::LibraryTypePage(AddLibraryWizard *parent)
: QWizardPage(parent)
{
setTitle(tr("Library Type"));
setSubTitle(tr("Choose the type of the library to link to"));
QVBoxLayout *layout = new QVBoxLayout(this);
m_systemRadio = new QRadioButton(tr("System library"), this);
m_systemRadio->setChecked(true);
layout->addWidget(m_systemRadio);
QLabel *systemLabel = new QLabel(tr("Links to a system library."
"\nNeither the path to the "
"library nor the path to its "
"includes is added to the .pro file."));
systemLabel->setWordWrap(true);
systemLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(systemLabel);
m_externalRadio = new QRadioButton(tr("External library"), this);
layout->addWidget(m_externalRadio);
QLabel *externalLabel = new QLabel(tr("Links to a library "
"that is not located in your "
"build tree.\nAdds the library "
"and include paths to the .pro file."));
externalLabel->setWordWrap(true);
externalLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(externalLabel);
m_internalRadio = new QRadioButton(tr("Internal library"), this);
layout->addWidget(m_internalRadio);
QLabel *internalLabel = new QLabel(tr("Links to a library "
"that is located in your build "
"tree.\nAdds the library and "
"include paths to the .pro file."));
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
internalLabel->setWordWrap(true);
internalLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(internalLabel);
}
AddLibraryWizard::LibraryKind LibraryTypePage::libraryKind() const
{
if (m_internalRadio->isChecked())
return AddLibraryWizard::InternalLibrary;
if (m_systemRadio->isChecked())
return AddLibraryWizard::SystemLibrary;
return AddLibraryWizard::ExternalLibrary;
}
int LibraryTypePage::nextId() const
{
return AddLibraryWizard::DetailsPageId;
}
/////////////
DetailsPage::DetailsPage(AddLibraryWizard *parent)
: QWizardPage(parent), m_libraryWizard(parent), m_libraryDetailsController(0)
{
m_libraryDetailsWidget = new Ui::LibraryDetailsWidget();
m_libraryDetailsWidget->setupUi(this);
}
bool DetailsPage::isComplete() const
{
if (m_libraryDetailsController)
return m_libraryDetailsController->isComplete();
return false;
}
int DetailsPage::nextId() const
{
return AddLibraryWizard::SummaryPageId;
}
QString DetailsPage::snippet() const
{
if (m_libraryDetailsController)
return m_libraryDetailsController->snippet();
return QString();
}
void DetailsPage::initializePage()
{
if (m_libraryDetailsController) {
delete m_libraryDetailsController;
m_libraryDetailsController = 0;
}
QString title;
QString subTitle;
switch (m_libraryWizard->libraryKind()) {
case AddLibraryWizard::SystemLibrary:
title = tr("System Library");
subTitle = tr("Specify the library to link to");
m_libraryDetailsController = new SystemLibraryDetailsController(
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
break;
case AddLibraryWizard::ExternalLibrary:
title = tr("External Library");
subTitle = tr("Specify the library to link to and the includes path");
m_libraryDetailsController = new ExternalLibraryDetailsController(
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
break;
case AddLibraryWizard::InternalLibrary:
title = tr("Internal Library");
subTitle = tr("Choose the project file of the library to link to");
m_libraryDetailsController = new InternalLibraryDetailsController(
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
break;
default:
break;
}
setTitle(title);
setSubTitle(subTitle);
if (m_libraryDetailsController) {
connect(m_libraryDetailsController, SIGNAL(completeChanged()),
this, SIGNAL(completeChanged()));
}
}
/////////////
SummaryPage::SummaryPage(AddLibraryWizard *parent)
: QWizardPage(parent), m_libraryWizard(parent)
{
setTitle(tr("Summary"));
setFinalPage(true);
QVBoxLayout *layout = new QVBoxLayout(this);
m_summaryLabel = new QLabel(this);
m_snippetLabel = new QLabel(this);
layout->addWidget(m_summaryLabel);
layout->addWidget(m_snippetLabel);
m_summaryLabel->setTextFormat(Qt::RichText);
m_snippetLabel->setTextFormat(Qt::RichText);
m_snippetLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
}
void SummaryPage::initializePage()
{
m_snippet = m_libraryWizard->snippet();
QFileInfo fi(m_libraryWizard->proFile());
m_summaryLabel->setText(
tr("The following snippet will be added to the<br><b>%1</b> file:")
.arg(fi.fileName()));
QString richSnippet;
{
QTextStream str(&richSnippet);
str << "<code>";
QString text = m_snippet;
text.replace(QLatin1Char('\n'), QLatin1String("<br>"));
str << text;
str << "</code>";
}
m_snippetLabel->setText(richSnippet);
}
QString SummaryPage::snippet() const
{
return m_snippet;
}