|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbUtils module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbdocumentloadersyntax_p.h" |
|
27 #include "hbdocumentloaderactions_p.h" |
|
28 #include "hbdocumentloader_p.h" |
|
29 #include "hbdocumentloader.h" |
|
30 |
|
31 #include <hbicon.h> |
|
32 #include <hbfontspec.h> |
|
33 #include <QDebug> |
|
34 #include <QMetaEnum> |
|
35 |
|
36 #include <QTranslator> |
|
37 #include <hbmainwindow.h> |
|
38 |
|
39 |
|
40 // Document loader version number |
|
41 #define VERSION_MAJOR 1 |
|
42 #define VERSION_MINOR 0 |
|
43 |
|
44 #define MIN_SUPPORTED_VERSION_MAJOR 0 |
|
45 #define MIN_SUPPORTED_VERSION_MINOR 1 |
|
46 |
|
47 /* |
|
48 \class HbDocumentLoaderSyntax |
|
49 \internal |
|
50 \proto |
|
51 */ |
|
52 |
|
53 HbDocumentLoaderSyntax::HbDocumentLoaderSyntax( HbDocumentLoaderActions *actions, const HbMainWindow *window ) |
|
54 : HbXmlLoaderAbstractSyntax( actions ), mRealActions( actions ), mMainWindow(window) |
|
55 { |
|
56 } |
|
57 |
|
58 HbDocumentLoaderSyntax::~HbDocumentLoaderSyntax() |
|
59 { |
|
60 } |
|
61 |
|
62 bool HbDocumentLoaderSyntax::load( QIODevice *device, const QString §ion ) |
|
63 { |
|
64 mCurrentProfile = HbDeviceProfile::profile(mMainWindow); |
|
65 return HbXmlLoaderAbstractSyntax::loadDevice( device, section ); |
|
66 } |
|
67 |
|
68 bool HbDocumentLoaderSyntax::readLayoutStartItem() |
|
69 { |
|
70 bool result = false; |
|
71 switch( mCurrentLayoutType ) { |
|
72 case LAYOUT_ANCHOR: |
|
73 { |
|
74 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: ANCHOR ITEM" ); |
|
75 if( mReader.name() == lexemValue( AL_ANCHOR ) ) { |
|
76 |
|
77 const QString src = attribute( AL_SRC_NAME ); |
|
78 const QString dst = attribute( AL_DST_NAME ); |
|
79 const QString srcEdge = attribute( AL_SRC_EDGE ); |
|
80 const QString dstEdge = attribute( AL_DST_EDGE ); |
|
81 const QString spacing = attribute( AL_SPACING ); |
|
82 const QString spacer = attribute( AL_SPACER ); |
|
83 qreal spacingVal = 0; |
|
84 result = true; |
|
85 if( !spacing.isEmpty() ) { |
|
86 result = toPixels( spacing, spacingVal ); |
|
87 } |
|
88 if (result) { |
|
89 result = mRealActions->addAnchorLayoutEdge( src, srcEdge, dst, dstEdge, spacingVal, spacer ); |
|
90 } |
|
91 } |
|
92 break; |
|
93 } |
|
94 case LAYOUT_GRID: |
|
95 { |
|
96 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: GRID ITEM" ); |
|
97 if( mReader.name() == lexemValue( GL_GRIDCELL ) ) { |
|
98 |
|
99 const QString src = attribute( GL_ITEMNAME ); |
|
100 |
|
101 const QString row = attribute( GL_ROW ); |
|
102 const QString column = attribute( GL_COLUMN ); |
|
103 const QString rowspan = attribute( GL_ROWSPAN ); |
|
104 const QString columnspan = attribute( GL_COLUMNSPAN ); |
|
105 const QString alignment = attribute( TYPE_ALIGNMENT ); |
|
106 result = mRealActions->addGridLayoutCell( src, row, column, rowspan, columnspan, alignment ); |
|
107 } else if( mReader.name() == lexemValue( GL_GRIDROW ) ) { |
|
108 const QString row = attribute( GL_ROW ); |
|
109 const QString stretchfactor = attribute( ATTR_STRETCHFACTOR ); |
|
110 const QString alignment = attribute( TYPE_ALIGNMENT ); |
|
111 result = mRealActions->setGridLayoutRowProperties( row, stretchfactor, alignment ); |
|
112 if (result) { |
|
113 result = processRowHeights( row ); |
|
114 } |
|
115 } else if( mReader.name() == lexemValue( GL_GRIDCOLUMN ) ) { |
|
116 const QString column = attribute( GL_COLUMN ); |
|
117 const QString stretchfactor = attribute( ATTR_STRETCHFACTOR ); |
|
118 const QString alignment = attribute( TYPE_ALIGNMENT ); |
|
119 result = mRealActions->setGridLayoutColumnProperties( column, stretchfactor, alignment ); |
|
120 if (result) { |
|
121 result = processColumnWidths( column ); |
|
122 } |
|
123 } else if( mReader.name() == lexemValue( TYPE_CONTENTSMARGINS ) ) { |
|
124 result = processContentsMargins(); |
|
125 } |
|
126 break; |
|
127 } |
|
128 case LAYOUT_LINEAR: |
|
129 { |
|
130 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: LINEAR ITEM" ); |
|
131 if( mReader.name() == lexemValue( LL_LINEARITEM ) ) { |
|
132 result = true; |
|
133 const QString index = attribute( LL_INDEX ); |
|
134 const QString itemname = attribute( LL_ITEMNAME ); |
|
135 const QString spacing = attribute( LL_SPACING ); |
|
136 const QString stretchfactor = attribute( ATTR_STRETCHFACTOR ); |
|
137 const QString alignment = attribute( TYPE_ALIGNMENT ); |
|
138 |
|
139 qreal spacingValue(0); |
|
140 qreal *spacingPtr(0); |
|
141 if( !spacing.isEmpty() ) { |
|
142 result = toPixels( spacing, spacingValue ); |
|
143 spacingPtr = &spacingValue; |
|
144 } |
|
145 if (result) { |
|
146 result = mRealActions->addLinearLayoutItem( itemname, index, stretchfactor, alignment, spacingPtr ); |
|
147 } |
|
148 } else if( mReader.name() == lexemValue( LL_STRETCH ) ) { |
|
149 const QString index = attribute( LL_INDEX ); |
|
150 const QString stretchfactor = attribute( ATTR_STRETCHFACTOR ); |
|
151 |
|
152 result = mRealActions->addLinearLayoutStretch( index, stretchfactor ); |
|
153 } else if( mReader.name() == lexemValue( TYPE_CONTENTSMARGINS ) ) { |
|
154 result = processContentsMargins(); |
|
155 } |
|
156 break; |
|
157 } |
|
158 case LAYOUT_STACK: |
|
159 { |
|
160 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: STACK ITEM" ); |
|
161 if( mReader.name() == lexemValue( SL_STACKITEM ) ) { |
|
162 |
|
163 const QString index = attribute( SL_INDEX ); |
|
164 const QString itemname = attribute( SL_ITEMNAME ); |
|
165 |
|
166 result = mRealActions->addStackedLayoutItem( itemname, index ); |
|
167 } |
|
168 break; |
|
169 |
|
170 } |
|
171 case LAYOUT_NULL: |
|
172 { |
|
173 HB_DOCUMENTLOADER_PRINT( "GENERAL LAYOUT START ITEM: NULL ITEM (MUST NOT EXIST)" ); |
|
174 break; |
|
175 } |
|
176 default: |
|
177 { |
|
178 qWarning() << "Internal error, wrong layout type, line " << mReader.lineNumber(); |
|
179 } |
|
180 } |
|
181 return result; |
|
182 } |
|
183 |
|
184 bool HbDocumentLoaderSyntax::processContentsMargins() |
|
185 { |
|
186 const QString leftS = attribute( ATTR_LEFT ); |
|
187 const QString topS = attribute( ATTR_TOP ); |
|
188 const QString rightS = attribute( ATTR_RIGHT ); |
|
189 const QString bottomS = attribute( ATTR_BOTTOM ); |
|
190 |
|
191 bool result = true; |
|
192 qreal left = 0, top = 0, right = 0, bottom = 0; |
|
193 if ( !leftS.isEmpty() ) { |
|
194 result = toPixels(leftS, left); |
|
195 } |
|
196 if ( result && !topS.isEmpty() ) { |
|
197 result = toPixels(topS, top); |
|
198 } |
|
199 if ( result && !rightS.isEmpty() ) { |
|
200 result = toPixels(rightS, right); |
|
201 } |
|
202 if ( result && !bottomS.isEmpty() ) { |
|
203 result = toPixels(bottomS, bottom); |
|
204 } |
|
205 |
|
206 if ( result ) { |
|
207 result = mRealActions->setLayoutContentsMargins( left, top, right, bottom ); |
|
208 } |
|
209 |
|
210 if (!result) { |
|
211 qWarning() << "Invalid contents margins, line " << mReader.lineNumber(); |
|
212 } |
|
213 |
|
214 return result; |
|
215 } |
|
216 |
|
217 bool HbDocumentLoaderSyntax::processRowHeights( const QString &row ) |
|
218 { |
|
219 const QString minHeightS = attribute( GL_MINHEIGHT ); |
|
220 const QString maxHeightS = attribute( GL_MAXHEIGHT ); |
|
221 const QString prefHeightS = attribute( GL_PREFHEIGHT ); |
|
222 const QString fixedHeightS = attribute( GL_FIXEDHEIGHT ); |
|
223 const QString rowSpacingS = attribute( GL_SPACING ); |
|
224 qreal minHeight = -1; |
|
225 qreal maxHeight = -1; |
|
226 qreal prefHeight = -1; |
|
227 qreal fixedHeight = -1; |
|
228 qreal rowSpacing = -1; |
|
229 |
|
230 bool result = true; |
|
231 int propertyAvailable = 0; |
|
232 |
|
233 if ( !minHeightS.isEmpty() ) { |
|
234 result = toPixels(minHeightS, minHeight); |
|
235 propertyAvailable |= HbDocumentLoaderActions::propertyMin; |
|
236 } |
|
237 |
|
238 if ( result && !maxHeightS.isEmpty() ) { |
|
239 result = toPixels(maxHeightS, maxHeight); |
|
240 propertyAvailable |= HbDocumentLoaderActions::propertyMax; |
|
241 } |
|
242 |
|
243 if ( result && !prefHeightS.isEmpty() ) { |
|
244 result = toPixels(prefHeightS, prefHeight); |
|
245 propertyAvailable |= HbDocumentLoaderActions::propertyPref; |
|
246 } |
|
247 |
|
248 if ( result && !fixedHeightS.isEmpty() ) { |
|
249 result = toPixels(fixedHeightS, fixedHeight); |
|
250 propertyAvailable |= HbDocumentLoaderActions::propertyFixed; |
|
251 } |
|
252 |
|
253 if ( result && !rowSpacingS.isEmpty() ) { |
|
254 result = toPixels(rowSpacingS, rowSpacing); |
|
255 propertyAvailable |= HbDocumentLoaderActions::propertySpacing; |
|
256 } |
|
257 |
|
258 if ( result && propertyAvailable ) { |
|
259 result = mRealActions->setGridLayoutRowHeights( row, minHeight, maxHeight, |
|
260 prefHeight, fixedHeight, |
|
261 rowSpacing, propertyAvailable); |
|
262 } |
|
263 |
|
264 return result; |
|
265 } |
|
266 |
|
267 bool HbDocumentLoaderSyntax::processColumnWidths( const QString &column ) |
|
268 { |
|
269 const QString minWidthS = attribute( GL_MINWIDTH ); |
|
270 const QString maxWidthS = attribute( GL_MAXWIDTH ); |
|
271 const QString prefWidthS = attribute( GL_PREFWIDTH ); |
|
272 const QString fixedWidthS = attribute( GL_FIXEDWIDTH ); |
|
273 const QString columnSpacingS = attribute( GL_SPACING ); |
|
274 qreal minWidth = -1; |
|
275 qreal maxWidth = -1; |
|
276 qreal prefWidth = -1; |
|
277 qreal fixedWidth = -1; |
|
278 qreal columnSpacing = -1; |
|
279 |
|
280 bool result = true; |
|
281 int propertyAvailable = 0; |
|
282 |
|
283 if ( !minWidthS.isEmpty() ) { |
|
284 result = toPixels(minWidthS, minWidth); |
|
285 propertyAvailable |= HbDocumentLoaderActions::propertyMin; |
|
286 } |
|
287 |
|
288 if ( result && !maxWidthS.isEmpty() ) { |
|
289 result = toPixels(maxWidthS, maxWidth); |
|
290 propertyAvailable |= HbDocumentLoaderActions::propertyMax; |
|
291 } |
|
292 |
|
293 if ( result && !prefWidthS.isEmpty() ) { |
|
294 result = toPixels(prefWidthS, prefWidth); |
|
295 propertyAvailable |= HbDocumentLoaderActions::propertyPref; |
|
296 } |
|
297 |
|
298 if ( result && !fixedWidthS.isEmpty() ) { |
|
299 result = toPixels(fixedWidthS, fixedWidth); |
|
300 propertyAvailable |= HbDocumentLoaderActions::propertyFixed; |
|
301 } |
|
302 |
|
303 if ( result && !columnSpacingS.isEmpty() ) { |
|
304 result = toPixels(columnSpacingS, columnSpacing); |
|
305 propertyAvailable |= HbDocumentLoaderActions::propertySpacing; |
|
306 } |
|
307 |
|
308 if ( result && propertyAvailable ) { |
|
309 result = mRealActions->setGridLayoutColumnWidths( column, minWidth, maxWidth, |
|
310 prefWidth, fixedWidth, |
|
311 columnSpacing, propertyAvailable); |
|
312 } |
|
313 |
|
314 return result; |
|
315 } |
|
316 |
|
317 bool HbDocumentLoaderSyntax::readContainerStartItem() |
|
318 { |
|
319 bool result = false; |
|
320 switch ( mCurrentElementType ) { |
|
321 case PROPERTY: |
|
322 { |
|
323 HB_DOCUMENTLOADER_PRINT( "CONTAINER START ITEM: PROPERTY" ); |
|
324 |
|
325 switch( mCurrentContainerType ) { |
|
326 case CONTAINER_STRINGLIST: |
|
327 { |
|
328 // check that we are only trying to put strings into a string list |
|
329 |
|
330 HB_DOCUMENTLOADER_PRINT( "GENERAL CONTAINER START ITEM: STRING LIST" ); |
|
331 if( mReader.name() == lexemValue( TYPE_STRING ) |
|
332 || mReader.name() == lexemValue( TYPE_ENUMS ) |
|
333 || mReader.name() == lexemValue( TYPE_LOCALIZED_STRING ) ) { |
|
334 result = processContainedProperty(); |
|
335 } |
|
336 break; |
|
337 } |
|
338 case CONTAINER_NULL: |
|
339 { |
|
340 HB_DOCUMENTLOADER_PRINT( "GENERAL CONTAINER START ITEM: NULL ITEM (MUST NOT EXIST)" ); |
|
341 break; |
|
342 } |
|
343 default: |
|
344 { |
|
345 qWarning() << "Internal error, wrong container type, line " << mReader.lineNumber(); |
|
346 break; |
|
347 } |
|
348 } |
|
349 break; |
|
350 } |
|
351 default: |
|
352 { |
|
353 break; |
|
354 } |
|
355 } |
|
356 |
|
357 return result; |
|
358 } |
|
359 |
|
360 bool HbDocumentLoaderSyntax::readContainerEndItem() |
|
361 { |
|
362 bool result = false; |
|
363 QString currentPropertyName; |
|
364 QVariant variant; |
|
365 |
|
366 switch( mCurrentElementType ) { |
|
367 case CONTAINER: |
|
368 { |
|
369 currentPropertyName = mCurrentContainer.back(); |
|
370 mCurrentContainer.removeLast(); |
|
371 |
|
372 if (mRealActions->mCurrentContainer) { |
|
373 // in order for the conversion to work, all of the contained types need to be suitable and equivalent, e.g. strings |
|
374 QVariant variantContainer = QVariant(*(mRealActions->mCurrentContainer)); |
|
375 if (variantContainer.isValid()) { |
|
376 switch(mCurrentContainerType) { |
|
377 case CONTAINER_STRINGLIST: |
|
378 { |
|
379 QStringList list = variantContainer.toStringList(); |
|
380 variant = QVariant(list); |
|
381 break; |
|
382 } |
|
383 default: |
|
384 { |
|
385 variant = variantContainer; |
|
386 break; |
|
387 } |
|
388 } |
|
389 } |
|
390 } |
|
391 |
|
392 result = mRealActions->pushProperty(currentPropertyName, variant); |
|
393 |
|
394 HB_DOCUMENTLOADER_PRINT( "CONTAINER END ITEM : SWITCHING TO GENERAL ITEM PROCESSING MODE" ); |
|
395 mElementState = ES_GENERAL_ITEM; |
|
396 |
|
397 result = true; |
|
398 break; |
|
399 } |
|
400 default: |
|
401 { |
|
402 result = HbXmlLoaderAbstractSyntax::readGeneralEndItem(); |
|
403 break; |
|
404 } |
|
405 } |
|
406 return result; |
|
407 } |
|
408 |
|
409 bool HbDocumentLoaderSyntax::readGeneralStartItem() |
|
410 { |
|
411 bool result = false; |
|
412 switch( mCurrentElementType ) { |
|
413 case OBJECT: |
|
414 { |
|
415 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: OBJECT" ); |
|
416 result = processObject(); |
|
417 break; |
|
418 } |
|
419 case WIDGET: |
|
420 { |
|
421 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: WIDGET" ); |
|
422 result = processWidget(); |
|
423 break; |
|
424 } |
|
425 case SPACERITEM: |
|
426 { |
|
427 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: SPACERITEM" ); |
|
428 result = processSpacerItem(); |
|
429 break; |
|
430 } |
|
431 case CONNECT: |
|
432 { |
|
433 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: CONNECT" ); |
|
434 result = processConnect(); |
|
435 break; |
|
436 } |
|
437 case PROPERTY: |
|
438 { |
|
439 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: PROPERTY" ); |
|
440 result = processProperty(); |
|
441 break; |
|
442 } |
|
443 case REF: |
|
444 { |
|
445 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: REF" ); |
|
446 result = processRef(); |
|
447 break; |
|
448 } |
|
449 case VARIABLE: |
|
450 { |
|
451 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: VARIABLE" ); |
|
452 result = processVariable(); |
|
453 break; |
|
454 } |
|
455 case DEPRECATED: |
|
456 { |
|
457 HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: DEPRECATED" ); |
|
458 result = true; |
|
459 break; |
|
460 } |
|
461 default: |
|
462 { |
|
463 result = HbXmlLoaderAbstractSyntax::readGeneralStartItem(); |
|
464 } |
|
465 } |
|
466 return result; |
|
467 } |
|
468 |
|
469 bool HbDocumentLoaderSyntax::processDocument() |
|
470 { |
|
471 bool ok, ok1, ok2, res = true; |
|
472 |
|
473 QString ver_str = attribute( ATTR_VERSION ); |
|
474 |
|
475 ver_str.toDouble( &ok ); |
|
476 QStringList ver = ver_str.split( '.' ); |
|
477 |
|
478 if( ( !ok ) || ( ver.size() != 2 ) ) { |
|
479 qWarning() << "Wrong document version format " << mReader.lineNumber(); |
|
480 return false; |
|
481 } |
|
482 |
|
483 int major = ver.at(0).toInt( &ok1 ); |
|
484 int minor = ver.at(1).toInt( &ok2 ); |
|
485 |
|
486 if( ( !ok1 ) || ( !ok2 ) ) { |
|
487 qWarning() << "Wrong document version format " << mReader.lineNumber(); |
|
488 return false; |
|
489 } |
|
490 |
|
491 |
|
492 if( ( major > VERSION_MAJOR ) || ( major < MIN_SUPPORTED_VERSION_MAJOR ) ) { |
|
493 res = false; |
|
494 } else if( ( ( major == VERSION_MAJOR ) && ( minor > VERSION_MINOR ) ) || |
|
495 ( ( major == MIN_SUPPORTED_VERSION_MAJOR ) && ( minor < MIN_SUPPORTED_VERSION_MINOR ) ) ) { |
|
496 res = false; |
|
497 } |
|
498 |
|
499 if( ! res ) { |
|
500 qWarning() << "Not supported document version " + ver_str + ". Current parser version is: " + version(); |
|
501 return false; |
|
502 |
|
503 } |
|
504 return mRealActions->pushDocument( attribute( ATTR_CONTEXT ) ); |
|
505 } |
|
506 |
|
507 bool HbDocumentLoaderSyntax::processObject() |
|
508 { |
|
509 const QString type = attribute( ATTR_TYPE ); |
|
510 const QString name = attribute( ATTR_NAME ); |
|
511 |
|
512 if( !mRealActions->pushObject( type, name ) ) { |
|
513 qWarning() << "Error in object processing, line " << mReader.lineNumber(); |
|
514 return false; |
|
515 } |
|
516 return true; |
|
517 } |
|
518 |
|
519 bool HbDocumentLoaderSyntax::processWidget() |
|
520 { |
|
521 const QString type = attribute( ATTR_TYPE ); |
|
522 const QString name = attribute( ATTR_NAME ); |
|
523 const QString role = attribute( ATTR_ROLE ); |
|
524 const QString plugin = attribute( ATTR_PLUGIN ); |
|
525 if( !mRealActions->pushWidget( type, name, role, plugin) ) { |
|
526 qWarning() << "Error in widget processing, line " << mReader.lineNumber(); |
|
527 return false; |
|
528 } |
|
529 return true; |
|
530 } |
|
531 |
|
532 bool HbDocumentLoaderSyntax::processSpacerItem() |
|
533 { |
|
534 const QString name = attribute( ATTR_NAME ); |
|
535 const QString widget = attribute( ATTR_WIDGET ); |
|
536 |
|
537 if( !mRealActions->pushSpacerItem( name, widget ) ) { |
|
538 qWarning() << "Error in object processing, line " << mReader.lineNumber(); |
|
539 return false; |
|
540 } |
|
541 return true; |
|
542 } |
|
543 |
|
544 bool HbDocumentLoaderSyntax::processLayout() |
|
545 { |
|
546 bool result = false; |
|
547 const QString layout_type = attribute( ATTR_TYPE ); |
|
548 const QString widget = attribute( ATTR_WIDGET ); |
|
549 |
|
550 if( layout_type == lexemValue( LAYOUT_ANCHOR ) ) { |
|
551 |
|
552 mCurrentLayoutType = LAYOUT_ANCHOR; |
|
553 result = mRealActions->createAnchorLayout( widget ); |
|
554 |
|
555 } else if( layout_type == lexemValue( LAYOUT_GRID ) ) { |
|
556 |
|
557 result = true; |
|
558 mCurrentLayoutType = LAYOUT_GRID; |
|
559 const QString spacing = attribute( GL_SPACING ); |
|
560 qreal spacingValue(0); |
|
561 qreal *spacingPtr(0); |
|
562 if( !spacing.isEmpty() ) { |
|
563 result = toPixels( spacing, spacingValue ); |
|
564 spacingPtr = &spacingValue; |
|
565 } |
|
566 if (result) { |
|
567 result = mRealActions->createGridLayout( widget, spacingPtr ); |
|
568 } |
|
569 |
|
570 } else if( layout_type == lexemValue( LAYOUT_LINEAR ) ) { |
|
571 |
|
572 result = true; |
|
573 mCurrentLayoutType = LAYOUT_LINEAR; |
|
574 const QString orientation = attribute( LL_ORIENTATION ); |
|
575 const QString spacing = attribute( LL_SPACING ); |
|
576 qreal spacingValue(0); |
|
577 qreal *spacingPtr(0); |
|
578 if( !spacing.isEmpty() ) { |
|
579 result = toPixels( spacing, spacingValue ); |
|
580 spacingPtr = &spacingValue; |
|
581 } |
|
582 if (result) { |
|
583 result = mRealActions->createLinearLayout( widget, orientation, spacingPtr ); |
|
584 } |
|
585 |
|
586 } else if( layout_type == lexemValue( LAYOUT_STACK ) ) { |
|
587 |
|
588 mCurrentLayoutType = LAYOUT_STACK; |
|
589 result = mRealActions->createStackedLayout( widget ); |
|
590 |
|
591 } else if( layout_type == lexemValue( LAYOUT_NULL ) ) { |
|
592 |
|
593 mCurrentLayoutType = LAYOUT_NULL; |
|
594 result = mRealActions->createNullLayout( widget ); |
|
595 |
|
596 } else { |
|
597 return HbXmlLoaderAbstractSyntax::processLayout(); |
|
598 } |
|
599 |
|
600 if( !result ) { |
|
601 qWarning() << "Unable to create layout, line " << mReader.lineNumber(); |
|
602 return false; |
|
603 } |
|
604 return true; |
|
605 } |
|
606 |
|
607 bool HbDocumentLoaderSyntax::processConnect() |
|
608 { |
|
609 const QString srcName = attribute( ATTR_SRC ); |
|
610 const QString signalName = attribute( ATTR_SIGNAL ); |
|
611 const QString dstName = attribute( ATTR_DST ); |
|
612 const QString slotName = attribute( ATTR_SLOT ); |
|
613 |
|
614 if( !mRealActions->pushConnect( srcName, signalName, dstName, slotName ) ) { |
|
615 qWarning() << "Error in connect processing, line " << mReader.lineNumber(); |
|
616 return false; |
|
617 |
|
618 } |
|
619 return true; |
|
620 } |
|
621 |
|
622 bool HbDocumentLoaderSyntax::processContainer() |
|
623 { |
|
624 bool result = false; |
|
625 const QString container_type = attribute( ATTR_TYPE ); |
|
626 |
|
627 if( container_type == lexemValue( CONTAINER_STRINGLIST ) ) { |
|
628 |
|
629 mCurrentContainerType = CONTAINER_STRINGLIST; |
|
630 |
|
631 const QString propertyName = attribute ( ATTR_NAME ); |
|
632 mCurrentContainer << propertyName; |
|
633 result = mRealActions->createContainer(); |
|
634 |
|
635 } else { |
|
636 return HbXmlLoaderAbstractSyntax::processContainer(); |
|
637 } |
|
638 |
|
639 if( !result ) { |
|
640 qWarning() << "Unable to create container, line " << mReader.lineNumber(); |
|
641 return false; |
|
642 } |
|
643 return true; |
|
644 } |
|
645 |
|
646 bool HbDocumentLoaderSyntax::processContainedProperty() |
|
647 { |
|
648 const QVariant value = decodeValue(); |
|
649 if( ! value.isValid() ) { |
|
650 qWarning() << "Invalid property, line " << mReader.lineNumber(); |
|
651 return false; |
|
652 } |
|
653 |
|
654 if( !mRealActions->appendPropertyToContainer( value ) ) { |
|
655 qWarning() << "Unable to set property, line " << mReader.lineNumber(); |
|
656 return false; |
|
657 } |
|
658 return true; |
|
659 } |
|
660 |
|
661 bool HbDocumentLoaderSyntax::processProperty() |
|
662 { |
|
663 const QVariant value = decodeValue(); |
|
664 if( ! value.isValid() ) { |
|
665 qWarning() << "Invalid property, line " << mReader.lineNumber(); |
|
666 return false; |
|
667 } |
|
668 |
|
669 const QString propertyName = attribute( ATTR_NAME ); |
|
670 |
|
671 if( !mRealActions->pushProperty( propertyName, value ) ) { |
|
672 qWarning() << "Unable to set property, line " << mReader.lineNumber(); |
|
673 return false; |
|
674 } |
|
675 return true; |
|
676 } |
|
677 |
|
678 bool HbDocumentLoaderSyntax::processRef() |
|
679 { |
|
680 const QString objectName = attribute( ATTR_OBJECT ); |
|
681 const QString role = attribute( ATTR_ROLE ); |
|
682 |
|
683 if( !mRealActions->pushRef( objectName, role ) ) { |
|
684 qWarning() << "Error in reference processing, line " << mReader.lineNumber(); |
|
685 return false; |
|
686 } |
|
687 return true; |
|
688 } |
|
689 |
|
690 static bool convertSizePolicy_Policy( const QString& policyS, QSizePolicy::Policy *&policy ) |
|
691 { |
|
692 if ( policyS.isEmpty() ) { |
|
693 return false; |
|
694 } |
|
695 |
|
696 const QMetaObject *meta = &QSizePolicy::staticMetaObject; |
|
697 const int enumIndex = meta->indexOfEnumerator("Policy"); |
|
698 Q_ASSERT( enumIndex != -1 ); |
|
699 QMetaEnum metaEnum = meta->enumerator(enumIndex); |
|
700 const QByteArray byteArray = policyS.toUtf8(); |
|
701 const int policyI = metaEnum.keyToValue(byteArray.data()); |
|
702 |
|
703 if ( policyI == -1 ) { |
|
704 return false; |
|
705 } |
|
706 |
|
707 policy = (QSizePolicy::Policy *)new int(policyI); |
|
708 return true; |
|
709 } |
|
710 |
|
711 bool HbDocumentLoaderSyntax::processVariable() |
|
712 { |
|
713 bool result = false; |
|
714 const QString type = mReader.name().toString(); |
|
715 |
|
716 if( type == lexemValue( TYPE_CONTENTSMARGINS ) ) { |
|
717 |
|
718 const QString leftS = attribute( ATTR_LEFT ); |
|
719 const QString topS = attribute( ATTR_TOP ); |
|
720 const QString rightS = attribute( ATTR_RIGHT ); |
|
721 const QString bottomS = attribute( ATTR_BOTTOM ); |
|
722 |
|
723 result = true; |
|
724 qreal left = 0, top = 0, right = 0, bottom = 0; |
|
725 if ( !leftS.isEmpty() ) { |
|
726 result = toPixels(leftS, left); |
|
727 } |
|
728 if ( result && !topS.isEmpty() ) { |
|
729 result = toPixels(topS, top); |
|
730 } |
|
731 if ( result && !rightS.isEmpty() ) { |
|
732 result = toPixels(rightS, right); |
|
733 } |
|
734 if ( result && !bottomS.isEmpty() ) { |
|
735 result = toPixels(bottomS, bottom); |
|
736 } |
|
737 |
|
738 if ( result ) { |
|
739 result = mRealActions->setContentsMargins( left, top, right, bottom ); |
|
740 } |
|
741 |
|
742 if (!result) { |
|
743 qWarning() << "Invalid contents margins, line " << mReader.lineNumber(); |
|
744 } |
|
745 |
|
746 } else if ( type == lexemValue( TYPE_SIZEPOLICY ) ) { |
|
747 const QString horizontalPolicyS = attribute( ATTR_HORIZONTALPOLICY ); |
|
748 const QString verticalPolicyS = attribute( ATTR_VERTICALPOLICY ); |
|
749 const QString horizontalStretchS = attribute( ATTR_HORIZONTALSTRETCH ); |
|
750 const QString verticalStretchS = attribute( ATTR_VERTICALSTRETCH ); |
|
751 |
|
752 result = true; |
|
753 |
|
754 QSizePolicy::Policy *hPol = 0; |
|
755 if ( !horizontalPolicyS.isEmpty() ) { |
|
756 result = convertSizePolicy_Policy( horizontalPolicyS, hPol ); |
|
757 } |
|
758 |
|
759 QSizePolicy::Policy *vPol = 0; |
|
760 if ( result && !verticalPolicyS.isEmpty() ) { |
|
761 result = convertSizePolicy_Policy( verticalPolicyS, vPol ); |
|
762 } |
|
763 |
|
764 int *hStretch = 0; |
|
765 if ( result && !horizontalStretchS.isEmpty() ) { |
|
766 const int intValue = horizontalStretchS.toInt( &result ); |
|
767 if ( result ) { |
|
768 if ( intValue >= 0 && intValue < 256 ) { |
|
769 hStretch = new int( intValue ); |
|
770 } else { |
|
771 result = false; |
|
772 } |
|
773 } |
|
774 } |
|
775 |
|
776 int *vStretch = 0; |
|
777 if ( result && !verticalStretchS.isEmpty() ) { |
|
778 const int intValue = verticalStretchS.toInt( &result ); |
|
779 if ( result ) { |
|
780 if ( intValue >= 0 && intValue < 256 ) { |
|
781 vStretch = new int( intValue ); |
|
782 } else { |
|
783 result = false; |
|
784 } |
|
785 } |
|
786 } |
|
787 |
|
788 if ( result ) { |
|
789 result = mRealActions->setSizePolicy( hPol, vPol, hStretch, vStretch ); |
|
790 } |
|
791 delete hPol; |
|
792 delete vPol; |
|
793 delete hStretch; |
|
794 delete vStretch; |
|
795 |
|
796 if (!result) { |
|
797 qWarning() << "Invalid size policy, line " << mReader.lineNumber(); |
|
798 } |
|
799 |
|
800 } else if ( type == lexemValue( TYPE_SIZEHINT ) ) { |
|
801 |
|
802 Qt::SizeHint hint = Qt::PreferredSize; |
|
803 bool fixed = false; |
|
804 |
|
805 if (convertSizeHintType(attribute( ATTR_TYPE ), hint, fixed)) { |
|
806 |
|
807 result = true; |
|
808 |
|
809 qreal *sizeHintWidth = 0; |
|
810 const QString width = attribute( ATTR_WIDTH ); |
|
811 if (!width.isEmpty()) { |
|
812 qreal widthInPixels; |
|
813 result = toPixels(width, widthInPixels); |
|
814 if (result) { |
|
815 sizeHintWidth = new qreal; |
|
816 *sizeHintWidth = widthInPixels; |
|
817 } |
|
818 } |
|
819 |
|
820 qreal *sizeHintHeight = 0; |
|
821 const QString height = attribute( ATTR_HEIGHT ); |
|
822 if (result && !height.isEmpty()) { |
|
823 qreal heightInPixels; |
|
824 result = toPixels(height, heightInPixels); |
|
825 if (result) { |
|
826 sizeHintHeight = new qreal; |
|
827 *sizeHintHeight = heightInPixels; |
|
828 } |
|
829 } |
|
830 |
|
831 if (result) { |
|
832 result = mRealActions->setSizeHint(hint, sizeHintWidth, sizeHintHeight, fixed); |
|
833 } |
|
834 } |
|
835 |
|
836 if (!result) { |
|
837 qWarning() << "Invalid size hint, line " << mReader.lineNumber(); |
|
838 } |
|
839 } else if ( type == lexemValue( TYPE_ZVALUE ) ) { |
|
840 const QString zValueAsString = attribute( ATTR_VALUE ); |
|
841 if (!zValueAsString.isEmpty()) { |
|
842 qreal zValueAsReal; |
|
843 result = toReal(zValueAsString, zValueAsReal); |
|
844 if ( result ) { |
|
845 result = mRealActions->setZValue( zValueAsReal ); |
|
846 } |
|
847 } |
|
848 |
|
849 if (!result) { |
|
850 qWarning() << "Invalid z value, line " << mReader.lineNumber(); |
|
851 } |
|
852 } else if ( type == lexemValue( TYPE_TOOLTIP ) ) { |
|
853 const QString value = attribute( ATTR_VALUE ); |
|
854 const QString comment = attribute( ATTR_COMMENT ); |
|
855 const QString locId = attribute( ATTR_LOCID ); |
|
856 |
|
857 if (!locId.isEmpty()) { |
|
858 QByteArray locIdUtf8(locId.toUtf8()); |
|
859 const QString translated = hbTrId(locIdUtf8); |
|
860 result = mRealActions->setToolTip( translated ); |
|
861 } else { |
|
862 const QString translated = mRealActions->translate( value, comment ); |
|
863 result = mRealActions->setToolTip( translated ); |
|
864 } |
|
865 |
|
866 if (!result) { |
|
867 qWarning() << "Invalid tooltip, line " << mReader.lineNumber(); |
|
868 } |
|
869 } |
|
870 |
|
871 return result; |
|
872 } |
|
873 |
|
874 ElementType |
|
875 HbDocumentLoaderSyntax::elementType( QStringRef name ) const |
|
876 { |
|
877 const QString stringName = name.toString(); |
|
878 |
|
879 if( stringName == lexemValue(TYPE_DOCUMENT) ){ |
|
880 return DOCUMENT; |
|
881 } |
|
882 return HbXmlLoaderAbstractSyntax::elementType( name ); |
|
883 } |
|
884 |
|
885 QVariant HbDocumentLoaderSyntax::decodeValue() |
|
886 { |
|
887 QVariant result = QVariant::Invalid; |
|
888 |
|
889 const QString type = mReader.name().toString(); |
|
890 |
|
891 bool ok = false; |
|
892 if( type == lexemValue( TYPE_INT ) ) { |
|
893 const QString value = attribute( ATTR_VALUE ); |
|
894 int int_res = value.toInt( &ok ); |
|
895 if( ok ) { |
|
896 result = int_res; |
|
897 } |
|
898 } else if( type == lexemValue( TYPE_REAL ) ) { |
|
899 const QString value = attribute( ATTR_VALUE ); |
|
900 qreal qreal_res; |
|
901 ok = toPixels( value, qreal_res ); |
|
902 if( ok ) { |
|
903 result = qreal_res; |
|
904 } |
|
905 } else if( type == lexemValue( TYPE_LOCALIZED_STRING ) ) { |
|
906 const QString value = |
|
907 mRealActions->translate( attribute( ATTR_VALUE ), attribute( ATTR_COMMENT ) ); |
|
908 result = value; |
|
909 } else if( type == lexemValue( TYPE_STRING ) ) { |
|
910 const QString value = attribute( ATTR_VALUE ); |
|
911 const QString locId = attribute( ATTR_LOCID ); |
|
912 if (!locId.isEmpty()) { |
|
913 QByteArray locIdUtf8(locId.toUtf8()); |
|
914 result = hbTrId(locIdUtf8); |
|
915 } else { |
|
916 result = value; |
|
917 } |
|
918 } else if( type == lexemValue( TYPE_ENUMS ) ) { |
|
919 result = attribute( ATTR_VALUE ); |
|
920 } else if ( type == lexemValue( TYPE_BOOL ) ) { |
|
921 const QString value = attribute( ATTR_VALUE ); |
|
922 if (value == lexemValue( VALUE_BOOL_TRUE ) ) { |
|
923 result = QVariant(true); |
|
924 } else if (value == lexemValue( VALUE_BOOL_FALSE ) ) { |
|
925 result = QVariant(false); |
|
926 } |
|
927 } else if ( type == lexemValue( TYPE_ICON ) ) { |
|
928 |
|
929 HbIcon icon; |
|
930 ok = true; |
|
931 |
|
932 // Read optional iconName attribute (if not given, it's null icon) |
|
933 const QString iconName = attribute( ATTR_ICONNAME ); |
|
934 if ( !iconName.isEmpty() ) { |
|
935 icon.setIconName( iconName ); |
|
936 } |
|
937 |
|
938 qreal desiredWidth = 0; |
|
939 qreal desiredHeight = 0; |
|
940 |
|
941 // Read optional width attribute |
|
942 const QString width = attribute( ATTR_WIDTH ); |
|
943 if (!width.isEmpty()) { |
|
944 ok = toPixels( width, desiredWidth ); |
|
945 } |
|
946 |
|
947 // Read optional height attribute |
|
948 const QString height = attribute( ATTR_HEIGHT ); |
|
949 if (ok && !height.isEmpty()) { |
|
950 ok = toPixels( height, desiredHeight ); |
|
951 } |
|
952 |
|
953 if (ok) { |
|
954 if (!width.isEmpty() && !height.isEmpty()) { |
|
955 icon.setSize(QSizeF(desiredWidth, desiredHeight)); |
|
956 } else if (!width.isEmpty()) { |
|
957 icon.setWidth(desiredWidth); |
|
958 } else if (!height.isEmpty()) { |
|
959 icon.setHeight(desiredHeight); |
|
960 } else { |
|
961 // neither defined. |
|
962 } |
|
963 |
|
964 result = icon; |
|
965 } |
|
966 } else if ( type == lexemValue(TYPE_SIZE) ) { |
|
967 |
|
968 const QString width = attribute( ATTR_WIDTH ); |
|
969 const QString height = attribute( ATTR_HEIGHT ); |
|
970 |
|
971 if (!width.isEmpty() && !height.isEmpty()) { |
|
972 ok = true; |
|
973 QSizeF size; |
|
974 qreal widthVal, heightVal; |
|
975 ok = toPixels(width, widthVal); |
|
976 if (ok) { |
|
977 size.setWidth(widthVal); |
|
978 ok = toPixels(height, heightVal); |
|
979 } |
|
980 if (ok) { |
|
981 size.setHeight(heightVal); |
|
982 result = size; |
|
983 } |
|
984 } |
|
985 |
|
986 } else if ( type == lexemValue(TYPE_RECT) ) { |
|
987 |
|
988 const QString posx = attribute( ATTR_X ); |
|
989 const QString posy = attribute( ATTR_Y ); |
|
990 const QString width = attribute( ATTR_WIDTH ); |
|
991 const QString height = attribute( ATTR_HEIGHT ); |
|
992 |
|
993 if (!width.isEmpty() && !height.isEmpty() && !posx.isEmpty() && !posy.isEmpty()) { |
|
994 ok = true; |
|
995 QSizeF size; |
|
996 QPointF point; |
|
997 qreal widthVal, heightVal, posxVal, posyVal; |
|
998 ok = toPixels(width, widthVal); |
|
999 if (ok) { |
|
1000 size.setWidth(widthVal); |
|
1001 ok = toPixels(height, heightVal); |
|
1002 } |
|
1003 if (ok) { |
|
1004 size.setHeight(heightVal); |
|
1005 ok = toPixels(posx, posxVal); |
|
1006 } |
|
1007 if (ok) { |
|
1008 point.setX(posxVal); |
|
1009 ok = toPixels(posy, posyVal); |
|
1010 } |
|
1011 if (ok) { |
|
1012 point.setY(posyVal); |
|
1013 result = QRectF(point, size); |
|
1014 } |
|
1015 } |
|
1016 |
|
1017 } else if ( type == lexemValue(TYPE_POINT) ) { |
|
1018 |
|
1019 const QString posx = attribute( ATTR_X ); |
|
1020 const QString posy = attribute( ATTR_Y ); |
|
1021 if (!posx.isEmpty() && !posy.isEmpty()) { |
|
1022 ok = true; |
|
1023 QPointF point; |
|
1024 qreal posxVal, posyVal; |
|
1025 ok = toPixels(posx, posxVal); |
|
1026 if (ok) { |
|
1027 point.setX(posxVal); |
|
1028 ok = toPixels(posy, posyVal); |
|
1029 } |
|
1030 if (ok) { |
|
1031 point.setY(posyVal); |
|
1032 result = point; |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 } else if ( type == lexemValue(TYPE_ALIGNMENT) ) { |
|
1037 |
|
1038 const QString alignment = attribute( ATTR_VALUE ); |
|
1039 if (!alignment.isEmpty() ) { |
|
1040 result = alignment; |
|
1041 } |
|
1042 |
|
1043 } else if ( type == lexemValue(LL_ORIENTATION) ) { |
|
1044 |
|
1045 const QString orientation = attribute( ATTR_VALUE ); |
|
1046 if (!orientation.isEmpty() ) { |
|
1047 result = orientation; |
|
1048 } |
|
1049 |
|
1050 } else if ( type == lexemValue(TYPE_COLOR) ) { |
|
1051 |
|
1052 const QString curColor = attribute( ATTR_VALUE ); |
|
1053 if (!curColor.isEmpty() ) { |
|
1054 ok = true; |
|
1055 result = QColor(curColor); |
|
1056 } |
|
1057 |
|
1058 } else if ( type == lexemValue(TYPE_FONTSPEC) ) { |
|
1059 QString roleString = attribute( ATTR_FONTSPECROLE ); |
|
1060 HbFontSpec::Role role(HbFontSpec::Undefined); |
|
1061 ok = true; |
|
1062 if (!roleString.isEmpty()) { |
|
1063 ok = toFontSpecRole(roleString, role); // sets role if ok |
|
1064 } |
|
1065 if (ok) { |
|
1066 HbFontSpec spec(role); |
|
1067 QString textHeightString = attribute( ATTR_TEXTHEIGHT ); |
|
1068 if (textHeightString.isEmpty()) { |
|
1069 // Deprecated. |
|
1070 textHeightString = attribute( ATTR_TEXTPANEHEIGHT ); |
|
1071 } |
|
1072 if (!textHeightString.isEmpty()) { |
|
1073 qreal height(0); |
|
1074 ok = toPixels(textHeightString, height); |
|
1075 if (ok) { |
|
1076 spec.setTextHeight(qRound(height)); |
|
1077 } |
|
1078 } |
|
1079 if (ok) { |
|
1080 result = spec; |
|
1081 } |
|
1082 } |
|
1083 } |
|
1084 |
|
1085 else { |
|
1086 // unknown property. |
|
1087 } |
|
1088 |
|
1089 return result; |
|
1090 } |
|
1091 |
|
1092 bool HbDocumentLoaderSyntax::convertSizeHintType( |
|
1093 const QString &type, |
|
1094 Qt::SizeHint &resultHint, |
|
1095 bool &resultFixed) |
|
1096 { |
|
1097 bool ok = true; |
|
1098 resultFixed = false; |
|
1099 |
|
1100 if (type == QLatin1String("MINIMUM")) { |
|
1101 resultHint = Qt::MinimumSize; |
|
1102 } else if (type == QLatin1String("MAXIMUM")) { |
|
1103 resultHint = Qt::MaximumSize; |
|
1104 } else if (type == QLatin1String("PREFERRED")) { |
|
1105 resultHint = Qt::PreferredSize; |
|
1106 } else if (type == QLatin1String("FIXED")) { |
|
1107 resultHint = Qt::PreferredSize; |
|
1108 resultFixed = true; |
|
1109 } else { |
|
1110 ok = false; |
|
1111 } |
|
1112 return ok; |
|
1113 } |
|
1114 |
|
1115 QString HbDocumentLoaderSyntax::version() |
|
1116 { |
|
1117 return ( QString::number( VERSION_MAJOR ) + QString( "." ) |
|
1118 + QString::number( VERSION_MINOR ) + QString( " (" ) |
|
1119 + QString::number( MIN_SUPPORTED_VERSION_MAJOR ) + QString( "." ) |
|
1120 + QString::number( MIN_SUPPORTED_VERSION_MINOR ) + QString( ")" ) ); |
|
1121 } |
|
1122 |
|
1123 bool HbDocumentLoaderSyntax::toFontSpecRole(const QString &roleString, HbFontSpec::Role &role) |
|
1124 { |
|
1125 bool success(false); |
|
1126 int enumInt = HbFontSpec::staticMetaObject.enumerator( |
|
1127 HbFontSpec::staticMetaObject.indexOfEnumerator("Role")).keyToValue(roleString.toLatin1()); |
|
1128 if (enumInt >= 0) { |
|
1129 success = true; |
|
1130 role = static_cast<HbFontSpec::Role>(enumInt); |
|
1131 } |
|
1132 return success; |
|
1133 } |