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
70
71
72
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "mobileappwizardpages.h"
#include "ui_mobileappwizardgenericoptionspage.h"
#include "ui_mobileappwizardmaemooptionspage.h"
#include "ui_mobileappwizardharmattanoptionspage.h"
#include "ui_mobileappwizardsymbianoptionspage.h"
#include <coreplugin/coreconstants.h>
#include <utils/fileutils.h>
#include <QtCore/QTemporaryFile>
#include <QtGui/QDesktopServices>
#include <QtGui/QFileDialog>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
namespace Qt4ProjectManager {
namespace Internal {
class MobileAppWizardGenericOptionsPagePrivate
{
Ui::MobileAppWizardGenericOptionsPage ui;
friend class MobileAppWizardGenericOptionsPage;
};
class MobileAppWizardSymbianOptionsPagePrivate
{
Ui::MobileAppWizardSymbianOptionsPage ui;
QString svgIcon;
friend class MobileAppWizardSymbianOptionsPage;
};
class MobileAppWizardMaemoOptionsPagePrivate
{
Ui::MobileAppWizardMaemoOptionsPage ui;
QSize iconSize;
QString pngIcon;
friend class MobileAppWizardMaemoOptionsPage;
};
class MobileAppWizardHarmattanOptionsPagePrivate
{
Ui::MobileAppWizardHarmattanOptionsPage ui;
QSize iconSize;
QString pngIcon;
friend class MobileAppWizardHarmattanOptionsPage;
};
MobileAppWizardGenericOptionsPage::MobileAppWizardGenericOptionsPage(QWidget *parent)
: QWizardPage(parent)
, d(new MobileAppWizardGenericOptionsPagePrivate)
{
d->ui.setupUi(this);
d->ui.orientationBehaviorComboBox->addItem(tr("Automatically Rotate Orientation"),
AbstractMobileApp::ScreenOrientationAuto);
d->ui.orientationBehaviorComboBox->addItem(tr("Lock to Landscape Orientation"),
AbstractMobileApp::ScreenOrientationLockLandscape);
d->ui.orientationBehaviorComboBox->addItem(tr("Lock to Portrait Orientation"),
AbstractMobileApp::ScreenOrientationLockPortrait);
}
MobileAppWizardGenericOptionsPage::~MobileAppWizardGenericOptionsPage()
{
delete d;
}
void MobileAppWizardGenericOptionsPage::setOrientation(AbstractMobileApp::ScreenOrientation orientation)
{
QComboBox *const comboBox = d->ui.orientationBehaviorComboBox;
for (int i = 0; i < comboBox->count(); ++i) {
if (comboBox->itemData(i).toInt() == static_cast<int>(orientation)) {
comboBox->setCurrentIndex(i);
break;
}
}
}
AbstractMobileApp::ScreenOrientation MobileAppWizardGenericOptionsPage::orientation() const
{
QComboBox *const comboBox = d->ui.orientationBehaviorComboBox;
const int index = comboBox->currentIndex();
return static_cast<AbstractMobileApp::ScreenOrientation>(comboBox->itemData(index).toInt());
}
MobileAppWizardSymbianOptionsPage::MobileAppWizardSymbianOptionsPage(QWidget *parent)
: QWizardPage(parent)
, d(new MobileAppWizardSymbianOptionsPagePrivate)
{
d->ui.setupUi(this);
const QIcon open = QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon);
d->ui.appIconLoadToolButton->setIcon(open);
connect(d->ui.appIconLoadToolButton, SIGNAL(clicked()), SLOT(openSvgIcon()));
}
MobileAppWizardSymbianOptionsPage::~MobileAppWizardSymbianOptionsPage()
{
delete d;
}
QString MobileAppWizardSymbianOptionsPage::svgIcon() const
{
return d->svgIcon;
}
void MobileAppWizardSymbianOptionsPage::setSvgIcon(const QString &icon)
{
QPixmap iconPixmap(icon);
if (!iconPixmap.isNull()) {
const int symbianIconSize = 44;
if (iconPixmap.height() > symbianIconSize || iconPixmap.width() > symbianIconSize)
iconPixmap = iconPixmap.scaledToHeight(symbianIconSize, Qt::SmoothTransformation);
d->ui.appIconPreview->setPixmap(iconPixmap);
d->svgIcon = icon;
}
}
QString MobileAppWizardSymbianOptionsPage::symbianUid() const
{
return d->ui.uid3LineEdit->text();
}
void MobileAppWizardSymbianOptionsPage::setSymbianUid(const QString &uid)
{
d->ui.uid3LineEdit->setText(uid);
}
void MobileAppWizardSymbianOptionsPage::setNetworkEnabled(bool enableIt)
{
d->ui.enableNetworkCheckBox->setChecked(enableIt);
}
bool MobileAppWizardSymbianOptionsPage::networkEnabled() const
{
return d->ui.enableNetworkCheckBox->isChecked();
}
void MobileAppWizardSymbianOptionsPage::openSvgIcon()
{
const QString svgIcon = QFileDialog::getOpenFileName(
this,
d->ui.appIconLabel->text(),
QDesktopServices::storageLocation(QDesktopServices::PicturesLocation),
QLatin1String("*.svg"));
if (!svgIcon.isEmpty())
setSvgIcon(svgIcon);
}
MobileAppWizardMaemoOptionsPage::MobileAppWizardMaemoOptionsPage(QWidget *parent)
: QWizardPage(parent)
, d(new MobileAppWizardMaemoOptionsPagePrivate)
{
d->ui.setupUi(this);
d->iconSize = QSize(64, 64);
d->ui.pngIconButton->setIconSize(d->iconSize);
connect(d->ui.pngIconButton, SIGNAL(clicked()), this, SLOT(openPngIcon()));
}
MobileAppWizardMaemoOptionsPage::~MobileAppWizardMaemoOptionsPage()
{
delete d;
}
QString MobileAppWizardMaemoOptionsPage::pngIcon() const
{
return d->pngIcon;
}
class PngIconScaler : public QObject
{
Q_OBJECT
public:
PngIconScaler(const QSize &expectedSize, const QString &iconPath)
: m_expectedSize(expectedSize)
, m_iconPath(iconPath)
, m_pixmap(iconPath)
{
}
bool hasRightSize() const { return m_expectedSize == m_pixmap.size(); }
QPixmap pixmap() const { return m_pixmap; }
bool scale(QString *newPath) {
const QMessageBox::StandardButton button
= QMessageBox::warning(QApplication::activeWindow(),
tr("Wrong Icon Size"),
tr("The icon needs to be %1x%2 pixels big, "
"but is not. Do you want Qt Creator to scale it?")
.arg(m_expectedSize.width()).arg(m_expectedSize.height()),
QMessageBox::Ok | QMessageBox::Cancel);
if (button != QMessageBox::Ok)
return false;
m_pixmap = m_pixmap.scaled(m_expectedSize);
Utils::TempFileSaver saver;
saver.setAutoRemove(false);
if (!saver.hasError())
saver.setResult(m_pixmap.save(
saver.file(), QFileInfo(m_iconPath).suffix().toAscii().constData()));
if (!saver.finalize()) {
QMessageBox::critical(QApplication::activeWindow(),
tr("File Error"),
tr("Could not copy icon file: %1").arg(saver.errorString()));
return false;
}
*newPath = saver.fileName();
return true;
}
private:
QSize m_expectedSize;
QString m_iconPath;
QPixmap m_pixmap;
};
void MobileAppWizardMaemoOptionsPage::setPngIcon(const QString &icon)
{
QString actualIconPath;
PngIconScaler scaler(d->iconSize, icon);
if (scaler.hasRightSize()) {
actualIconPath = icon;
} else {
if (!scaler.scale(&actualIconPath))
return;
}
d->ui.pngIconButton->setIcon(scaler.pixmap());
d->pngIcon = actualIconPath;
}
void MobileAppWizardMaemoOptionsPage::openPngIcon()
{
const QString iconPath = QFileDialog::getOpenFileName(this,
d->ui.appIconLabel->text(), d->pngIcon,
QLatin1String("*.png"));
if (!iconPath.isEmpty())
setPngIcon(iconPath);
}
MobileAppWizardHarmattanOptionsPage::MobileAppWizardHarmattanOptionsPage(QWidget *parent)
: QWizardPage(parent)
, d(new MobileAppWizardHarmattanOptionsPagePrivate)
{
d->ui.setupUi(this);
d->iconSize = QSize(80, 80);
d->ui.pngIconButton->setIconSize(d->iconSize);
connect(d->ui.pngIconButton, SIGNAL(clicked()), this, SLOT(openPngIcon()));
}
MobileAppWizardHarmattanOptionsPage::~MobileAppWizardHarmattanOptionsPage()
{
delete d;
}
QString MobileAppWizardHarmattanOptionsPage::pngIcon() const
{
return d->pngIcon;
}
void MobileAppWizardHarmattanOptionsPage::setPngIcon(const QString &icon)
{
QString actualIconPath;
PngIconScaler scaler(d->iconSize, icon);
if (scaler.hasRightSize()) {
actualIconPath = icon;
} else {
if (!scaler.scale(&actualIconPath))
return;
}
d->ui.pngIconButton->setIcon(scaler.pixmap());
d->pngIcon = actualIconPath;
}
void MobileAppWizardHarmattanOptionsPage::openPngIcon()
{
const QString iconPath = QFileDialog::getOpenFileName(this,
d->ui.appIconLabel->text(), d->pngIcon,
QLatin1String("*.png"));
if (!iconPath.isEmpty())
setPngIcon(iconPath);
}
void MobileAppWizardHarmattanOptionsPage::setBoosterOptionEnabled(bool enable)
{
d->ui.makeBoostableCheckBox->setEnabled(enable);
d->ui.makeBoostableCheckBox->setChecked(enable);
}
bool MobileAppWizardHarmattanOptionsPage::supportsBooster() const
{
return d->ui.makeBoostableCheckBox->isChecked();
}
} // namespace Internal
} // namespace Qt4ProjectManager
#include "mobileappwizardpages.moc"
|