4 * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
7 * GiWoong Kim <giwoong.kim@samsung.com>
8 * SeokYeon Hwang <syeon.hwang@samsung.com>
9 * Sangho Park <sangho.p@samsung.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
31 #include "config-host.h"
33 #include "xmllayoutparser.h"
34 #include "xmllayoutkeyword.h"
35 #include "skinpainter.h"
36 #include "layout/keycodetype.h"
37 #include "controller/generalpurposecon.h"
38 #include "resource/ui_strings.h"
40 #define LOG_LINE_HEAD_CHAR "> "
41 #define LOG_INDENTATION_SIZE 2
42 #define QDEBUG_INDENT(x) qDebug().nospace() << qPrintable(getIndenting(x))
43 #define QWARN_INDENT(x) qWarning().nospace() << qPrintable(getIndenting(x))
45 /* Qt QLayout has a minimum size */
46 #define QT_LAYOUT_MINIMUM (73)
48 XmlLayoutParser::XmlLayoutParser(const QString &path, UiInformation *uiInfo)
51 this->uiInfo = uiInfo;
53 menuItems.insert(SEPARATOR_MENU_KEYWORD, MenuItemType::separator);
54 menuItems.insert(ADVANCED_MENU_KEYWORD, MenuItemType::advancedItem);
55 menuItems.insert(INFO_MENU_KEYWORD, MenuItemType::infoItem);
56 menuItems.insert(ONTOP_MENU_KEYWORD, MenuItemType::onTopItem);
57 menuItems.insert(MOVE_MENU_KEYWORD, MenuItemType::moveItem);
58 menuItems.insert(SWITCH_MENU_KEYWORD, MenuItemType::switchItem);
59 menuItems.insert(SCALE_MENU_KEYWORD, MenuItemType::scaleItem);
60 menuItems.insert(CONTROLLER_MENU_KEYWORD, MenuItemType::controllerItem);
61 menuItems.insert(HOSTKBD_MENU_KEYWORD, MenuItemType::hostKeyboardItem);
62 menuItems.insert(SHELL_MENU_KEYWORD, MenuItemType::shellItem);
63 menuItems.insert(ECP_MENU_KEYWORD, MenuItemType::controlPanelItem);
64 menuItems.insert(SCREENSHOT_MENU_KEYWORD, MenuItemType::screenShotItem);
65 menuItems.insert(ABOUT_MENU_KEYWORD, MenuItemType::aboutItem);
66 menuItems.insert(SYSTEM_RESET_MENU_KEYWORD, MenuItemType::systemResetItem);
67 menuItems.insert(FORCECLOSE_MENU_KEYWORD, MenuItemType::forceCloseItem);
68 menuItems.insert(CLOSE_MENU_KEYWORD, MenuItemType::closeItem);
71 QString XmlLayoutParser::getIndenting(int depth) {
72 QString indenting = LOG_LINE_HEAD_CHAR;
76 for (int i = 0; i < LOG_INDENTATION_SIZE; i++) {
77 indenting.append(QChar::Space);
85 QColor XmlLayoutParser::parseColor(QXmlStreamReader &xml, const int depth)
87 int red = 0, green = 0, blue = 0;
89 if (xml.name() == COLOR_KEYWORD &&
90 xml.tokenType() == QXmlStreamReader::StartElement) {
91 QXmlStreamAttributes attributes = xml.attributes();
93 if (attributes.hasAttribute(COLOR_RED_ATTR_KEYWORD)) {
94 red = attributes.value(COLOR_RED_ATTR_KEYWORD).toString().toInt();
96 if (attributes.hasAttribute(COLOR_GREEN_ATTR_KEYWORD)) {
97 green = attributes.value(COLOR_GREEN_ATTR_KEYWORD).toString().toInt();
99 if (attributes.hasAttribute(COLOR_BLUE_ATTR_KEYWORD)) {
100 blue = attributes.value(COLOR_BLUE_ATTR_KEYWORD).toString().toUInt();
104 return QColor(red, green, blue, 255);
107 HoverType XmlLayoutParser::parseHover(QXmlStreamReader &xml, const int depth)
109 QColor color(255, 255, 255);
112 QDEBUG_INDENT(depth) << HOVER_KEYWORD << " {";
114 fill = xml.attributes().value(HOVER_FILL_ATTR_KEYWORD).compare("true") == 0;
115 QDEBUG_INDENT(depth + 1) << HOVER_FILL_ATTR_KEYWORD << ": " << fill;
117 QXmlStreamReader::TokenType token = xml.readNext();
119 while (xml.atEnd() == false && (xml.name() == HOVER_KEYWORD &&
120 token == QXmlStreamReader::EndElement) == false) /* ~ </hover> */
122 if (token == QXmlStreamReader::StartElement) {
123 if (xml.name() == COLOR_KEYWORD) {
125 color = parseColor(xml, depth + 1);
126 QDEBUG_INDENT(depth + 1) << COLOR_KEYWORD << ": " << color.name();
128 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
132 token = xml.readNext();
135 QDEBUG_INDENT(depth) << "}";
137 return HoverType(color, fill);
140 QRect XmlLayoutParser::parseRegion(QXmlStreamReader &xml, const int depth)
142 int left = 0, top = 0;
143 unsigned int width = 0, height = 0;
145 if (xml.name() == REGION_KEYWORD &&
146 xml.tokenType() == QXmlStreamReader::StartElement) {
147 QXmlStreamAttributes attributes = xml.attributes();
149 if (attributes.hasAttribute(REGION_LEFT_ATTR_KEYWORD)) {
150 left = attributes.value(REGION_LEFT_ATTR_KEYWORD).toString().toInt();
152 if (attributes.hasAttribute(REGION_TOP_ATTR_KEYWORD)) {
153 top = attributes.value(REGION_TOP_ATTR_KEYWORD).toString().toInt();
155 if (attributes.hasAttribute(REGION_WIDTH_ATTR_KEYWORD)) {
156 width = attributes.value(REGION_WIDTH_ATTR_KEYWORD).toString().toUInt();
158 if (attributes.hasAttribute(REGION_HEIGHT_ATTR_KEYWORD)) {
159 height = attributes.value(REGION_HEIGHT_ATTR_KEYWORD).toString().toUInt();
163 return QRect(left, top, width, height);
166 DisplayType *XmlLayoutParser::parseDisplay(QXmlStreamReader &xml, const int depth)
168 QRect displayRect(0, 0, 0, 0);
172 QDEBUG_INDENT(depth) << DISPLAY_KEYWORD << " {";
174 QXmlStreamReader::TokenType token = xml.readNext();
176 while (xml.atEnd() == false && (xml.name() == DISPLAY_KEYWORD &&
177 token == QXmlStreamReader::EndElement) == false) /* ~ </display> */
179 if (token == QXmlStreamReader::StartElement) {
180 if (xml.name() == REGION_KEYWORD) {
182 displayRect = parseRegion(xml, depth + 1);
183 QDEBUG_INDENT(depth + 1) <<
184 "(" << displayRect.x() << "," << displayRect.y() << " " <<
185 displayRect.width() << "x" << displayRect.height() << ")";
186 } else if (xml.name() == ANGLE_KEYWORD) {
188 angle = xml.readElementText().toInt();
189 } else if (xml.name() == MASK_IMG_KEYWORD) {
191 QString maskImageFileName = xml.readElementText();
192 QDEBUG_INDENT(depth + 1) <<
193 MASK_IMG_KEYWORD << ": " << maskImageFileName;
196 xmlPath + QDir::separator() + maskImageFileName) == false) {
197 QWARN_INDENT(depth + 1) << "failed to load mask image";
200 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
204 token = xml.readNext();
207 QDEBUG_INDENT(depth) << "}";
209 return new DisplayType(displayRect, angle, maskImage);
212 KeycodeType XmlLayoutParser::parseKeycode(QXmlStreamReader &xml, const int depth)
214 int longPress = -1, shortPress = 0;
217 longPress = xml.attributes().value(KEYCODE_LONGPRESS_ATTR_KEYWORD).toString().toInt();
219 shortPress = xml.readElementText().toInt();
221 return KeycodeType(shortPress, longPress);
224 HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml, const int depth)
227 KeycodeType keycodeType;
229 QKeySequence keySequence;
232 QString keyName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
234 QXmlStreamReader::TokenType token = xml.readNext();
236 while (xml.atEnd() == false && (xml.name() == KEY_KEYWORD &&
237 token == QXmlStreamReader::EndElement) == false) /* ~ </key> */
239 if (token == QXmlStreamReader::StartElement) {
240 if (xml.name() == REGION_KEYWORD) {
242 keyRegion = parseRegion(xml, depth + 1);
243 } else if (xml.name() == KEYCODE_KEYWORD) {
245 keycodeType = parseKeycode(xml, depth + 1);
246 } else if (xml.name() == TOOLTIP_KEYWORD) {
248 keyTooptip = xml.readElementText();
249 } else if (xml.name() == SHORTCUT_KEYWORD) {
251 keySequence = parseShortcut(xml, depth + 1);
253 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
257 token = xml.readNext();
260 return new HardwareKey(keyName, keycodeType, keyRegion, keyTooptip, keySequence);
263 int XmlLayoutParser::parseKeyList(QXmlStreamReader &xml,
264 const int depth, QList<HardwareKey *> &list)
266 HardwareKey *hwKey = NULL;
268 QXmlStreamReader::TokenType token = xml.readNext();
270 while (xml.atEnd() == false && (xml.name() == KEYLIST_KEYWORD &&
271 token == QXmlStreamReader::EndElement) == false) /* ~ </keyList> */
273 if (token == QXmlStreamReader::StartElement) {
274 if (xml.name() == KEY_KEYWORD) {
275 hwKey = parseKey(xml, depth + 1);
280 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
284 token = xml.readNext();
290 MainForm *XmlLayoutParser::parseMainForm(QXmlStreamReader &xml, const int depth)
293 QString formName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
294 MainForm *form = new MainForm(formName);
296 qDebug(LOG_LINE_HEAD_CHAR);
297 QDEBUG_INDENT(depth) << form->getName() << " {";
299 QXmlStreamReader::TokenType token = xml.readNext();
301 while (xml.atEnd() == false && (xml.name() == FORM_KEYWORD &&
302 token == QXmlStreamReader::EndElement) == false) /* ~ </form> */
304 if (token == QXmlStreamReader::StartElement) {
305 if (xml.name() == DISPLAY_KEYWORD) {
307 form->setDpyType(parseDisplay(xml, depth + 1));
308 } else if (xml.name() == NORMAL_IMG_KEYWORD) {
310 QString normalImageFileName = xml.readElementText();
311 QDEBUG_INDENT(depth + 1) <<
312 NORMAL_IMG_KEYWORD << ": " << normalImageFileName;
314 if (form->skinImg[LayoutForm::normal].load(
315 xmlPath + QDir::separator() + normalImageFileName) == false) {
316 QWARN_INDENT(depth + 1) << "failed to load normal image";
318 } else if (xml.name() == PRESSED_IMG_KEYWORD) {
319 /* key pressed image */
320 QString pressedImageFileName = xml.readElementText();
321 QDEBUG_INDENT(depth + 1) <<
322 PRESSED_IMG_KEYWORD << ": " << pressedImageFileName;
324 if (form->skinImg[LayoutForm::pressed].load(
325 xmlPath + QDir::separator() + pressedImageFileName) == false) {
326 QWARN_INDENT(depth + 1) << "failed to load pressed image";
328 } else if (xml.name() == ROTARY_IMG_KEYWORD) {
330 QString rotaryImageFileName = xml.readElementText();
331 QDEBUG_INDENT(depth + 1) <<
332 ROTARY_IMG_KEYWORD << ": " << rotaryImageFileName;
334 form->setRotaryImage(new QPixmap(
335 xmlPath + QDir::separator() + rotaryImageFileName));
336 if (form->getRotaryImage()->isNull() == true) {
337 QWARN_INDENT(depth + 1) << "failed to load rotary image";
339 } else if (xml.name() == KEYLIST_KEYWORD) {
341 const int cnt = parseKeyList(xml, depth + 1, form->getKeyList());
342 QDEBUG_INDENT(depth + 1) << KEYLIST_KEYWORD << ": " << cnt;
343 } else if (xml.name() == HOVER_KEYWORD) {
345 form->setHoverType(parseHover(xml, depth + 1));
347 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
351 token = xml.readNext();
354 QDEBUG_INDENT(depth) << "}";
359 int XmlLayoutParser::parseMainFormList(QXmlStreamReader &xml,
360 const int depth, QList<MainForm *> &list)
362 MainForm *form = NULL;
364 QDEBUG_INDENT(depth) << FORMLIST_KEYWORD << " {";
366 QXmlStreamReader::TokenType token = xml.readNext();
368 while (xml.atEnd() == false && (xml.name() == FORMLIST_KEYWORD &&
369 token == QXmlStreamReader::EndElement) == false) /* ~ </formList> */
371 if (token == QXmlStreamReader::StartElement) {
372 if (xml.name() == FORM_KEYWORD) {
373 form = parseMainForm(xml, depth + 1);
375 /* image validation */
376 if (form->skinImg[LayoutForm::normal].size() == QSize(0, 0)) {
377 QDEBUG_INDENT(depth + 1) << "(general purpose skin type)";
379 SkinPainter painter("main-skin",
380 uiInfo->getResolution(), form->getDpyType()->getAngle(),
381 QPoint(30, 16), uiInfo->getVMColor());
382 form->setGeneralPurpose(true);
384 form->skinImg[LayoutForm::normal] = painter.getSkinImage();
385 form->getDpyType()->setRect(painter.getCenteralRect());
391 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
395 token = xml.readNext();
398 QDEBUG_INDENT(depth) << "}";
404 int XmlLayoutParser::parseFactorList(QXmlStreamReader &xml,
405 const int depth, QMap<int, QString> &map, int *defaultFactor)
407 QString defaultValue = xml.attributes().value(DEFAULT_ATTR_KEYWORD).toString();
408 *defaultFactor = defaultValue.toInt();
410 QXmlStreamReader::TokenType token = xml.readNext();
412 while (xml.atEnd() == false && (xml.name() == FACTORLIST_KEYWORD &&
413 token == QXmlStreamReader::EndElement) == false) /* ~ </factorList> */
415 if (token == QXmlStreamReader::StartElement) {
416 if (xml.name() == FACTOR_KEYWORD) {
417 QString value = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
418 map.insert(xml.readElementText().toInt(), value);
420 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
424 token = xml.readNext();
430 QKeySequence XmlLayoutParser::parseShortcut(QXmlStreamReader &xml, const int depth)
432 QString keyString = xml.readElementText();
435 /* QKeySequence Note: On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and
436 * Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard,
437 * and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to
438 * the Control keys. Developers on Mac OS X can use the same shortcut descriptions
439 * across all platforms, and their applications will automatically work as expected
442 /* According to Qt note, "Ctrl" will be treated as command key. This is not what we
443 * want. To be recognized as control key on MacOS, XML Parser should replace "Ctrl"
444 * with "Meta" text. */
446 keyString.replace(XML_QT_CTRLKEY_STRING, XML_QT_METAKEY_STRING);
449 return QKeySequence::fromString(keyString);
452 int XmlLayoutParser::parseShortcuts(QXmlStreamReader &xml,
453 const int depth, QMap<QString, QKeySequence> &map)
455 QString key = xml.attributes().value(PROP_ATTR_KEYWORD).toString();
456 map.insert(key, parseShortcut(xml, depth + 1));
461 AdvancedMenuItem *XmlLayoutParser::parseAdvancedMenuItem(
462 QXmlStreamReader &xml, const int depth)
465 QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
466 AdvancedMenuItem *item = new AdvancedMenuItem(menuName);
468 QDEBUG_INDENT(depth) << ADVANCED_MENU_KEYWORD << " {";
470 QXmlStreamReader::TokenType token = xml.readNext();
472 while (xml.atEnd() == false && (xml.name() == ADVANCED_MENU_KEYWORD &&
473 token == QXmlStreamReader::EndElement) == false) /* ~ </advancedItem> */
475 if (token == QXmlStreamReader::StartElement) {
476 if (xml.name() == SHORTCUT_KEYWORD) {
477 parseShortcuts(xml, depth + 1, item->getShortcuts());
478 } else if (xml.name() == MENULIST_KEYWORD) {
479 const int cnt = parseMenuList(xml, depth + 1, item->getMenuList());
480 QDEBUG_INDENT(depth + 1) << MENULIST_KEYWORD << ": " << cnt;
482 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
486 token = xml.readNext();
489 QDEBUG_INDENT(depth) << "}";
494 ScaleMenuItem *XmlLayoutParser::parseScaleMenuItem(
495 QXmlStreamReader &xml, const int depth)
498 QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
499 ScaleMenuItem *item = new ScaleMenuItem(menuName);
501 QDEBUG_INDENT(depth) << SCALE_MENU_KEYWORD << " {";
503 QXmlStreamReader::TokenType token = xml.readNext();
505 while (xml.atEnd() == false && (xml.name() == SCALE_MENU_KEYWORD &&
506 token == QXmlStreamReader::EndElement) == false) /* ~ </scaleItem> */
508 if (token == QXmlStreamReader::StartElement) {
509 if (xml.name() == SHORTCUT_KEYWORD) {
510 parseShortcuts(xml, depth + 1, item->getShortcuts());
511 } else if (xml.name() == FACTORLIST_KEYWORD) {
512 int defaultFactor = 0;
513 const int cnt = parseFactorList(xml, depth + 1,
514 item->getFactorMap(), &defaultFactor);
515 QDEBUG_INDENT(depth + 1) << FACTORLIST_KEYWORD << ": " << cnt;
517 item->setDefaultScaleFactor(defaultFactor);
519 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
523 token = xml.readNext();
526 QDEBUG_INDENT(depth) << "}";
531 MenuItem *XmlLayoutParser::parseGeneralMenuItem(
532 QXmlStreamReader &xml, const int depth, int menuType)
534 QString itemKeyword = xml.name().toString();
537 QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
538 MenuItem *item = new MenuItem(menuType, menuName);
541 QXmlStreamReader::TokenType token = xml.readNext();
543 while (xml.atEnd() == false && (xml.name().compare(itemKeyword) == 0 &&
544 token == QXmlStreamReader::EndElement) == false) /* ~ </xxItem> */
546 if (token == QXmlStreamReader::StartElement) {
547 if (xml.name() == SHORTCUT_KEYWORD) {
548 parseShortcuts(xml, depth + 1, item->getShortcuts());
550 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
554 token = xml.readNext();
560 int XmlLayoutParser::parseMenuList(QXmlStreamReader &xml,
561 const int depth, QList<MenuItem *> &list)
563 MenuItem *item = NULL;
565 qDebug(LOG_LINE_HEAD_CHAR);
566 QDEBUG_INDENT(depth) << MENULIST_KEYWORD << " {";
568 QXmlStreamReader::TokenType token = xml.readNext();
569 QString tokenName = xml.name().toString();
571 while (xml.atEnd() == false && (tokenName == MENULIST_KEYWORD &&
572 token == QXmlStreamReader::EndElement) == false) /* ~ </menuList> */
574 if (token == QXmlStreamReader::StartElement) {
575 const int menuType = menuItems.value(tokenName, -1);
578 case MenuItemType::separator:
580 item = new MenuItem(menuType, NULL);
582 case MenuItemType::advancedItem:
584 item = dynamic_cast<MenuItem *>(
585 parseAdvancedMenuItem(xml, depth + 1));
587 case MenuItemType::scaleItem:
589 item = dynamic_cast<MenuItem *>(
590 parseScaleMenuItem(xml, depth + 1));
592 case MenuItemType::infoItem:
593 case MenuItemType::onTopItem:
594 case MenuItemType::moveItem:
595 case MenuItemType::switchItem:
596 case MenuItemType::controllerItem:
597 case MenuItemType::hostKeyboardItem:
598 case MenuItemType::shellItem:
599 case MenuItemType::controlPanelItem:
600 case MenuItemType::screenShotItem:
601 case MenuItemType::aboutItem:
602 case MenuItemType::systemResetItem:
603 case MenuItemType::forceCloseItem:
605 case MenuItemType::closeItem:
606 item = parseGeneralMenuItem(xml, depth + 1, menuType);
609 QWARN_INDENT(depth + 1) << "undefined element: " << tokenName;
619 token = xml.readNext();
620 tokenName = xml.name().toString();
623 QDEBUG_INDENT(depth) << "}";
628 QString XmlLayoutParser::parseEmulatorUI(QXmlStreamReader &xml)
630 QString layoutVersion = GENERIC_TEXT_UNDEFINED;
633 qDebug(LOG_LINE_HEAD_CHAR);
634 QDEBUG_INDENT(depth) << EMULATOR_UI_KEYWORD << " {";
636 QXmlStreamReader::TokenType token = QXmlStreamReader::NoToken;
638 while (xml.atEnd() == false && xml.hasError() == false) {
639 token = xml.readNext();
641 /* If token is just StartDocument, go to next. */
642 if (token == QXmlStreamReader::StartDocument) {
646 if (token == QXmlStreamReader::StartElement) {
647 if (xml.name() == EMULATOR_UI_KEYWORD) {
651 if (xml.name() == LAYOUTVER_KEYWORD) {
652 layoutVersion = xml.readElementText();
654 } else if (xml.name() == FORMLIST_KEYWORD) {
656 const int cnt = parseMainFormList(xml,
657 depth + 1, uiInfo->getMainFormList());
658 QDEBUG_INDENT(depth + 1) << FORMLIST_KEYWORD << ": " << cnt;
659 } else if (xml.name() == MENULIST_KEYWORD) {
661 const int cnt = parseMenuList(xml,
662 depth + 1, uiInfo->getMenuList());
663 QDEBUG_INDENT(depth + 1) << MENULIST_KEYWORD << ": " << cnt;
665 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
670 QDEBUG_INDENT(depth) << "}";
672 if (xml.hasError() == true) {
673 printError(xml.error());
676 return layoutVersion;
680 ControllerForm *XmlLayoutParser::parseControllerForm(
681 QXmlStreamReader &xml, const int depth)
684 QString formName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
685 ControllerForm *form = new ControllerForm(
686 formName.isEmpty() ? xmlPath.section(QDir::separator(), -1) : formName);
688 QDEBUG_INDENT(depth) << form->getName() << " {";
690 QXmlStreamReader::TokenType token = xml.readNext();
692 while (xml.atEnd() == false && (xml.name() == FORM_KEYWORD &&
693 token == QXmlStreamReader::EndElement) == false) /* ~ </form> */
695 if (token == QXmlStreamReader::StartElement) {
696 if (xml.name() == NORMAL_IMG_KEYWORD) {
698 QString normalImageFileName = xml.readElementText();
699 QDEBUG_INDENT(depth + 1) <<
700 NORMAL_IMG_KEYWORD << ": " << normalImageFileName;
702 if (form->skinImg[LayoutForm::normal].load(
703 xmlPath + QDir::separator() + normalImageFileName) == false) {
704 QWARN_INDENT(depth + 1) << "failed to load normal image";
706 } else if (xml.name() == PRESSED_IMG_KEYWORD) {
707 /* key pressed image */
708 QString pressedImageFileName = xml.readElementText();
709 QDEBUG_INDENT(depth + 1) <<
710 PRESSED_IMG_KEYWORD << ": " << pressedImageFileName;
712 if (form->skinImg[LayoutForm::pressed].load(
713 xmlPath + QDir::separator() + pressedImageFileName) == false) {
714 QWARN_INDENT(depth + 1) << "failed to load pressed image";
716 } else if (xml.name() == KEYLIST_KEYWORD) {
718 const int cnt = parseKeyList(xml, depth + 1, form->getKeyList());
719 QDEBUG_INDENT(depth + 1) << KEYLIST_KEYWORD << ": " << cnt;
720 } else if (xml.name() == HOVER_KEYWORD) {
722 form->setHoverType(parseHover(xml, depth + 1));
724 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
728 token = xml.readNext();
731 QDEBUG_INDENT(depth) << "}";
736 QString XmlLayoutParser::parseControllerUI(QXmlStreamReader &xml)
738 QString layoutVersion = GENERIC_TEXT_UNDEFINED;
741 qDebug(LOG_LINE_HEAD_CHAR);
742 QDEBUG_INDENT(depth) << CONTROLLER_UI_KEYWORD << " {";
744 ControllerForm *form = NULL;
745 QXmlStreamReader::TokenType token = QXmlStreamReader::NoToken;
747 while (xml.atEnd() == false && xml.hasError() == false) {
748 token = xml.readNext();
750 /* If token is just StartDocument, go to next. */
751 if (token == QXmlStreamReader::StartDocument) {
755 if (token == QXmlStreamReader::StartElement) {
756 if (xml.name() == CONTROLLER_UI_KEYWORD) {
760 if (xml.name() == LAYOUTVER_KEYWORD) {
761 layoutVersion = xml.readElementText();
763 } else if (xml.name() == FORM_KEYWORD) {
764 form = parseControllerForm(xml, depth + 1);
766 /* image validation */
767 if (form->skinImg[LayoutForm::normal].size() == QSize(0, 0)) {
768 QDEBUG_INDENT(depth + 1) << "(general purpose con type)";
769 makeGeneralCon(form);
772 uiInfo->getConFormList().append(form);
775 QWARN_INDENT(depth + 1) << "undefined element: " << xml.name();
780 QDEBUG_INDENT(depth) << "}";
782 if (xml.hasError() == true) {
783 printError(xml.error());
786 return layoutVersion;
789 void XmlLayoutParser::makeGeneralCon(ControllerForm *form)
791 const int keyCount = form->getKeyList().count();
793 int width = GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING;
794 int height = GPC_HEAD_SPACING;
795 height += (GPC_KEYBUTTON_HEIGHT * keyCount) +
796 (GPC_KEYBUTTON_VSPACING * (keyCount - 1)) + GPC_TAIL_SPACING;
798 SkinPainter painter(QSize(width, qMax(height, QT_LAYOUT_MINIMUM - 20)), 0);
800 form->skinImg[LayoutForm::normal] = painter.getSkinImage();
801 form->setCenteralRect(painter.getCenteralRect());
802 form->setGeneralPurpose(true);
805 void XmlLayoutParser::printError(QXmlStreamReader::Error err)
808 case QXmlStreamReader::NoError:
811 case QXmlStreamReader::UnexpectedElementError:
812 qCritical("The parser encountered an element that was different to those it expected.");
814 case QXmlStreamReader::CustomError:
815 qCritical("A custom error has been raised with raiseError().");
817 case QXmlStreamReader::NotWellFormedError:
818 qCritical("The parser internally raised an error due to the read XML not being well-formed.");
820 case QXmlStreamReader::PrematureEndOfDocumentError:
821 qCritical("The input stream ended before a well-formed XML document was parsed.");
824 qCritical("Unexpected error type was returned.");