author | jake |
Wed, 27 Oct 2010 12:06:29 +0300 | |
changeset 9 | 6967ff0a31f5 |
parent 6 | ac3b45850c50 |
permissions | -rw-r--r-- |
0 | 1 |
#include "mainwindow.h" |
2 |
#include "ui_mainwindow.h" |
|
3 |
||
4 |
#include "widgetcreator.h" |
|
5 |
#include "renderercreator.h" |
|
6 |
#include "publishercreator.h" |
|
7 |
||
8 |
#include <QMessageBox> |
|
9 |
#include <QDir> |
|
10 |
#include <QTextStream> |
|
11 |
#include <QTimer> |
|
12 |
||
13 |
||
14 |
MainWindow::MainWindow(QWidget *parent) : |
|
15 |
QMainWindow(parent), ui(new Ui::MainWindow), iLayoutIndex( 0 ), iLayoutCount( -1 ) |
|
16 |
{ |
|
17 |
ui->setupUi(this); |
|
18 |
iTimer = new QTimer(this); |
|
19 |
connect(iTimer, SIGNAL(timeout()), this, SLOT(updateLayout())); |
|
20 |
} |
|
21 |
||
22 |
MainWindow::~MainWindow() |
|
23 |
{ |
|
24 |
delete ui; |
|
25 |
} |
|
26 |
||
27 |
void MainWindow::changeEvent(QEvent *e) |
|
28 |
{ |
|
29 |
QMainWindow::changeEvent(e); |
|
30 |
switch (e->type()) { |
|
31 |
case QEvent::LanguageChange: |
|
32 |
ui->retranslateUi(this); |
|
33 |
break; |
|
34 |
default: |
|
35 |
break; |
|
36 |
} |
|
37 |
} |
|
38 |
||
39 |
QString MainWindow::widgetName() |
|
40 |
{ |
|
6 | 41 |
return ui->widgetName->text(); |
0 | 42 |
} |
43 |
||
44 |
QString MainWindow::widgetUid() |
|
45 |
{ |
|
46 |
return ui->widgetUid->text().toLower(); |
|
47 |
} |
|
48 |
||
49 |
QCheckBox& MainWindow::rendererCheckBox() |
|
50 |
{ |
|
51 |
return *ui->renderingCheckBox; |
|
52 |
} |
|
53 |
||
54 |
QString MainWindow::rendererName() |
|
55 |
{ |
|
56 |
return ui->rendererName->text(); |
|
57 |
} |
|
58 |
||
59 |
QString MainWindow::rendererUid() |
|
60 |
{ |
|
6 | 61 |
return ui->rendererUid->text().toLower(); |
0 | 62 |
} |
63 |
||
64 |
void MainWindow::on_pushButton_clicked() |
|
65 |
{ |
|
66 |
if( widgetName().isEmpty() || widgetUid().isEmpty() ) |
|
67 |
{ |
|
68 |
QMessageBox msgBox; |
|
69 |
msgBox.setText("Widget name and UID must be given."); |
|
70 |
msgBox.exec(); |
|
71 |
return; |
|
72 |
} |
|
73 |
||
74 |
bool ok; |
|
75 |
uint uidVal = widgetUid().toUInt(&ok, 16 ); |
|
76 |
if( widgetUid().length() != 10 || !widgetUid().startsWith( "0x",Qt::CaseInsensitive ) || !ok ) |
|
77 |
{ |
|
78 |
QMessageBox msgBox; |
|
79 |
msgBox.setText("UID must be in 4 byte hexadecimal format\n 0x11223344."); |
|
80 |
msgBox.exec(); |
|
81 |
return; |
|
82 |
} |
|
83 |
||
84 |
if( uidVal >= 2147483648 ) //0x80000000 |
|
85 |
{ |
|
86 |
QMessageBox msgBox; |
|
87 |
msgBox.setText("UID must be less than\n 0x80000000."); |
|
88 |
msgBox.exec(); |
|
89 |
return; |
|
90 |
} |
|
91 |
||
6 | 92 |
if (widgetLayout().length() == 0 && !rendererCheckBox().isChecked()) |
93 |
{ |
|
94 |
QMessageBox msgBox; |
|
95 |
msgBox.setText("Layout data not available yet."); |
|
96 |
msgBox.exec(); |
|
97 |
return; |
|
98 |
} |
|
99 |
||
0 | 100 |
generateMainBuildFile(); |
101 |
||
102 |
PublisherCreator* publisherCreator = new PublisherCreator(*this); |
|
103 |
delete publisherCreator; |
|
104 |
||
105 |
WidgetCreator* widgetCreator = new WidgetCreator(*this); |
|
106 |
delete widgetCreator; |
|
107 |
||
108 |
if( ui->renderingCheckBox->isChecked() ) |
|
109 |
{ |
|
110 |
if( rendererName().isEmpty() || rendererUid().isEmpty() ) |
|
111 |
{ |
|
112 |
QMessageBox msgBox; |
|
113 |
msgBox.setText("Renderer name and UID must be given."); |
|
114 |
msgBox.exec(); |
|
115 |
return; |
|
116 |
} |
|
117 |
if( rendererUid().length() != 10 || !rendererUid().startsWith( "0x",Qt::CaseInsensitive )) |
|
118 |
{ |
|
119 |
QMessageBox msgBox; |
|
120 |
msgBox.setText("UID must be in hexadecimal format\n 0x11223344."); |
|
121 |
msgBox.exec(); |
|
122 |
return; |
|
123 |
} |
|
124 |
RendererCreator * renderer = new RendererCreator(*this); |
|
125 |
delete renderer; |
|
126 |
} |
|
2
0c23d71853fe
added copying of two png images into publishercreator.cpp
jake
parents:
0
diff
changeset
|
127 |
|
0 | 128 |
QMessageBox msgBox; |
129 |
msgBox.setText("Widget created."); |
|
130 |
msgBox.exec(); |
|
2
0c23d71853fe
added copying of two png images into publishercreator.cpp
jake
parents:
0
diff
changeset
|
131 |
return; |
0 | 132 |
} |
133 |
||
134 |
void MainWindow::generateMainBuildFile() |
|
135 |
{ |
|
136 |
QDir dir; |
|
6 | 137 |
dir.mkpath( widgetName().toLower() + "/group"); |
138 |
dir.setPath( widgetName().toLower() + "/group"); |
|
0 | 139 |
QFile file( dir.filePath("bld.inf")); |
140 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) |
|
141 |
return; |
|
142 |
||
143 |
QTextStream out(&file); |
|
144 |
generateLicense( out ); |
|
145 |
||
146 |
//out << "#include \"../publisherif/group/bld.inf\"\n"; |
|
147 |
out << "#include \"../testpublisher/group/bld.inf\"\n"; |
|
148 |
out << "#include \"../widget/group/bld.inf\"\n"; |
|
149 |
if( ui->renderingCheckBox->isChecked() ) |
|
150 |
{ |
|
151 |
out << "#include \"../renderingplugin/group/bld.inf\"\n\n"; |
|
152 |
} |
|
153 |
out << "// End of File\n"; |
|
154 |
} |
|
155 |
||
156 |
void MainWindow::generateLicense( QTextStream& aStream ) |
|
157 |
{ |
|
158 |
aStream << "/*\n"; |
|
159 |
aStream << "* Copyright (c) {Year(s)} {Copyright owner}.\n"; |
|
160 |
aStream << "* All rights reserved.\n"; |
|
161 |
aStream << "* This component and the accompanying materials are made available\n"; |
|
162 |
aStream << "* under the terms of the \"Eclipse Public License v1.0\"\n"; |
|
163 |
aStream << "* which accompanies this distribution, and is available\n"; |
|
164 |
aStream << "* at the URL \"http://www.symbianfoundation.org/legal/sfl-v10.html\".\n"; |
|
165 |
aStream << "*\n"; |
|
166 |
aStream << "* Initial Contributors:\n"; |
|
167 |
aStream << "* {Name} {Company} – Initial contribution\n"; |
|
168 |
aStream << "*\n"; |
|
169 |
aStream << "* Contributors:\n"; |
|
170 |
aStream << "* {Name} {Company} – {{Description of contribution}}\n"; |
|
171 |
aStream << "*\n"; |
|
172 |
aStream << "* Description:\n"; |
|
173 |
aStream << "* {{Description of the file}}\n"; |
|
174 |
aStream << "*\n"; |
|
175 |
aStream << "*/\n\n"; |
|
176 |
} |
|
177 |
||
178 |
QString MainWindow::widgetUidNoHex() |
|
179 |
{ |
|
180 |
QString uid( widgetUid() ); |
|
181 |
if( uid.startsWith( "0x",Qt::CaseInsensitive )) |
|
182 |
{ |
|
183 |
return uid.right(8); |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
return uid; |
|
188 |
} |
|
189 |
||
190 |
} |
|
191 |
||
192 |
void MainWindow::replaceData( QString sourceFile, QString destFile, bool noHexUid ) |
|
193 |
{ |
|
194 |
QString path = QDir::currentPath(); |
|
195 |
QFile infile(sourceFile); |
|
196 |
if (!infile.open(QIODevice::ReadWrite | QIODevice::Text)) |
|
197 |
return; |
|
198 |
||
199 |
QTextStream in(&infile); |
|
200 |
||
201 |
QFile outfile(destFile); |
|
202 |
if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text)) |
|
203 |
return; |
|
204 |
||
205 |
QTextStream out(&outfile); |
|
206 |
||
207 |
while (!in.atEnd()) |
|
208 |
{ |
|
209 |
QString line = in.readLine(); |
|
210 |
line.replace(QString("#replace#"), widgetName()); |
|
6 | 211 |
|
0 | 212 |
if( noHexUid ) |
213 |
{ |
|
214 |
line.replace(QString("#replaceuid#"), widgetUidNoHex()); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
line.replace(QString("#replaceuid#"), widgetUid()); |
|
219 |
} |
|
220 |
out << line << "\n"; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
void MainWindow::on_renderingCheckBox_stateChanged(int state ) |
|
225 |
{ |
|
6 | 226 |
iTimer->stop(); |
0 | 227 |
if( state == Qt::Unchecked ) |
228 |
{ |
|
229 |
ui->rendererName->setEnabled( false ); |
|
230 |
ui->rendererUid->setEnabled( false ); |
|
6 | 231 |
ui->comboBox->setEnabled( true ); |
232 |
updateLayout(); |
|
0 | 233 |
} |
234 |
else if ( state == Qt::Checked) |
|
235 |
{ |
|
236 |
ui->rendererName->setEnabled( true ); |
|
237 |
ui->rendererUid->setEnabled( true); |
|
6 | 238 |
ui->comboBox->setEnabled( false ); |
0 | 239 |
} |
240 |
||
241 |
} |
|
242 |
||
243 |
QString MainWindow::widgetLayout() |
|
244 |
{ |
|
245 |
switch (iLayoutIndex) |
|
246 |
{ |
|
247 |
case 0: |
|
248 |
{ |
|
249 |
return QString( "feed" ); |
|
250 |
} |
|
251 |
break; |
|
252 |
case 1: |
|
253 |
{ |
|
254 |
return QString( "text" ); |
|
255 |
} |
|
256 |
break; |
|
257 |
case 2: |
|
258 |
{ |
|
259 |
return QString( "iconstext" ); |
|
260 |
} |
|
261 |
break; |
|
262 |
case 3: |
|
263 |
{ |
|
264 |
return QString( "graphictext" ); |
|
265 |
} |
|
266 |
break; |
|
6 | 267 |
case 4: |
268 |
{ |
|
269 |
return QString( "graphiciconstext" ); |
|
270 |
} |
|
271 |
break; |
|
272 |
||
0 | 273 |
}; |
6 | 274 |
|
275 |
return QString( "" ); |
|
0 | 276 |
} |
277 |
||
278 |
void MainWindow::on_comboBox_currentIndexChanged(int index) |
|
279 |
{ |
|
280 |
iLayoutIndex = index; |
|
281 |
iLayoutCount = 3; |
|
282 |
updateLayout(); |
|
283 |
} |
|
284 |
||
285 |
void MainWindow::updateLayout() |
|
286 |
{ |
|
287 |
switch (iLayoutIndex) |
|
288 |
{ |
|
289 |
case 0: |
|
290 |
{ |
|
291 |
iTimer->stop(); |
|
292 |
showFeedsLayout(); |
|
293 |
} |
|
294 |
break; |
|
295 |
case 1: |
|
296 |
{ |
|
297 |
showTextLayout(); |
|
298 |
iTimer->start(2000); |
|
299 |
} |
|
300 |
break; |
|
301 |
case 2: |
|
302 |
{ |
|
303 |
showIconsTextLayout(); |
|
304 |
iTimer->start(2000); |
|
305 |
} |
|
306 |
break; |
|
307 |
case 3: |
|
308 |
{ |
|
6 | 309 |
showGraphicsTextLayout(); |
310 |
iTimer->start(2000); |
|
311 |
} |
|
312 |
break; |
|
313 |
case 4: |
|
314 |
{ |
|
315 |
showGraphicsIconTextLayout(); |
|
0 | 316 |
iTimer->start(2000); |
317 |
} |
|
318 |
break; |
|
6 | 319 |
case 5: |
320 |
{ |
|
321 |
iTimer->stop(); |
|
322 |
showGraphicsGridLayout(); |
|
323 |
} |
|
324 |
break; |
|
325 |
case 6: |
|
326 |
{ |
|
327 |
iTimer->stop(); |
|
328 |
showGraphicsGridTextLayout(); |
|
329 |
} |
|
330 |
break; |
|
331 |
case 7: |
|
332 |
{ |
|
333 |
iTimer->stop(); |
|
334 |
showWidgeImageLayout(); |
|
335 |
} |
|
336 |
break; |
|
337 |
case 8: |
|
338 |
{ |
|
339 |
iTimer->stop(); |
|
340 |
showGraphicsCarouselLayout(); |
|
341 |
} |
|
342 |
break; |
|
0 | 343 |
}; |
344 |
||
345 |
if( iLayoutCount > 1) |
|
346 |
{ |
|
347 |
iLayoutCount--; |
|
348 |
} |
|
349 |
else |
|
350 |
{ |
|
351 |
iLayoutCount = 3; |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
void MainWindow::showFeedsLayout() |
|
356 |
{ |
|
357 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/feeds_layout.jpg"))); |
|
358 |
} |
|
359 |
||
6 | 360 |
void MainWindow::showGraphicsGridLayout() |
361 |
{ |
|
362 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/graphicsgrid_layout.jpg"))); |
|
363 |
} |
|
364 |
||
365 |
void MainWindow::showGraphicsGridTextLayout() |
|
366 |
{ |
|
367 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/graphicsgridtext_layout.jpg"))); |
|
368 |
} |
|
369 |
||
370 |
void MainWindow::showWidgeImageLayout() |
|
371 |
{ |
|
372 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/wideimage_layout.jpg"))); |
|
373 |
} |
|
374 |
||
375 |
void MainWindow::showGraphicsCarouselLayout() |
|
376 |
{ |
|
377 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/graphicscarousel_layout.jpg"))); |
|
378 |
} |
|
379 |
||
0 | 380 |
void MainWindow::showTextLayout() |
381 |
{ |
|
382 |
QString imagePath(":/widgets/images/text_layout_"); |
|
383 |
QString cnt; |
|
384 |
cnt.setNum( iLayoutCount ); |
|
385 |
imagePath.append( cnt ); |
|
386 |
imagePath.append( ".jpg" ); |
|
387 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath)); |
|
388 |
} |
|
389 |
||
390 |
void MainWindow::showIconsTextLayout() |
|
391 |
{ |
|
392 |
QString imagePath(":/widgets/images/iconstext_layout_"); |
|
393 |
QString cnt; |
|
394 |
cnt.setNum( iLayoutCount ); |
|
395 |
imagePath.append( cnt ); |
|
396 |
imagePath.append( ".jpg" ); |
|
397 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath)); |
|
398 |
} |
|
399 |
||
6 | 400 |
void MainWindow::showGraphicsTextLayout() |
0 | 401 |
{ |
6 | 402 |
QString imagePath(":/widgets/images/graphicstext_layout_"); |
0 | 403 |
QString cnt; |
404 |
cnt.setNum( iLayoutCount ); |
|
405 |
imagePath.append( cnt ); |
|
406 |
imagePath.append( ".jpg" ); |
|
407 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath)); |
|
408 |
} |
|
6 | 409 |
|
410 |
void MainWindow::showGraphicsIconTextLayout() |
|
411 |
{ |
|
412 |
QString imagePath(":/widgets/images/graphicsiconstext_layout_"); |
|
413 |
QString cnt; |
|
414 |
cnt.setNum( iLayoutCount ); |
|
415 |
imagePath.append( cnt ); |
|
416 |
imagePath.append( ".jpg" ); |
|
417 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath)); |
|
418 |
} |
|
419 |