/* * Qt UI * * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * GiWoong Kim * SeokYeon Hwang * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * Contributors: * - S-Core Co., Ltd * */ #include "config-host.h" #include "xmllayoutparser.h" #include "xmllayoutkeyword.h" #include "skinpainter.h" #include "layout/keycodetype.h" #include "controller/generalpurposecon.h" #include "resource/ui_strings.h" #define LOG_LINE_HEAD_CHAR "> " #define LOG_INDENTATION_SIZE 2 #define QDEBUG_INDENT(x) qDebug().nospace() << qPrintable(getIndenting(x)) #define QWARN_INDENT(x) qWarning().nospace() << qPrintable(getIndenting(x)) /* Qt QLayout has a minimum size */ #define QT_LAYOUT_MINIMUM (73) XmlLayoutParser::XmlLayoutParser(const QString &path, UiInformation *uiInfo) { this->xmlPath = path; this->uiInfo = uiInfo; menuItems.insert(SEPARATOR_MENU_KEYWORD, MenuItemType::separator); menuItems.insert(ADVANCED_MENU_KEYWORD, MenuItemType::advancedItem); menuItems.insert(INFO_MENU_KEYWORD, MenuItemType::infoItem); menuItems.insert(ONTOP_MENU_KEYWORD, MenuItemType::onTopItem); menuItems.insert(MOVE_MENU_KEYWORD, MenuItemType::moveItem); menuItems.insert(SWITCH_MENU_KEYWORD, MenuItemType::switchItem); menuItems.insert(SCALE_MENU_KEYWORD, MenuItemType::scaleItem); menuItems.insert(CONTROLLER_MENU_KEYWORD, MenuItemType::controllerItem); menuItems.insert(HOSTKBD_MENU_KEYWORD, MenuItemType::hostKeyboardItem); menuItems.insert(SHELL_MENU_KEYWORD, MenuItemType::shellItem); menuItems.insert(ECP_MENU_KEYWORD, MenuItemType::controlPanelItem); menuItems.insert(SCREENSHOT_MENU_KEYWORD, MenuItemType::screenShotItem); menuItems.insert(ABOUT_MENU_KEYWORD, MenuItemType::aboutItem); menuItems.insert(SYSTEM_RESET_MENU_KEYWORD, MenuItemType::systemResetItem); menuItems.insert(FORCECLOSE_MENU_KEYWORD, MenuItemType::forceCloseItem); menuItems.insert(CLOSE_MENU_KEYWORD, MenuItemType::closeItem); } QString XmlLayoutParser::getIndenting(int depth) { QString indenting = LOG_LINE_HEAD_CHAR; if (depth > 0) { while (depth--) { for (int i = 0; i < LOG_INDENTATION_SIZE; i++) { indenting.append(QChar::Space); } } } return indenting; } QColor XmlLayoutParser::parseColor(QXmlStreamReader &xml, const int depth) { int red = 0, green = 0, blue = 0; if (xml.name() == COLOR_KEYWORD && xml.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = xml.attributes(); if (attributes.hasAttribute(COLOR_RED_ATTR_KEYWORD)) { red = attributes.value(COLOR_RED_ATTR_KEYWORD).toString().toInt(); } if (attributes.hasAttribute(COLOR_GREEN_ATTR_KEYWORD)) { green = attributes.value(COLOR_GREEN_ATTR_KEYWORD).toString().toInt(); } if (attributes.hasAttribute(COLOR_BLUE_ATTR_KEYWORD)) { blue = attributes.value(COLOR_BLUE_ATTR_KEYWORD).toString().toUInt(); } } return QColor(red, green, blue, 255); } HoverType XmlLayoutParser::parseHover(QXmlStreamReader &xml, const int depth) { QColor color(255, 255, 255); bool fill = false; QDEBUG_INDENT(depth) << HOVER_KEYWORD << " {"; fill = xml.attributes().value(HOVER_FILL_ATTR_KEYWORD).compare("true") == 0; QDEBUG_INDENT(depth + 1) << HOVER_FILL_ATTR_KEYWORD << ": " << fill; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == HOVER_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == COLOR_KEYWORD) { /* color */ color = parseColor(xml, depth + 1); QDEBUG_INDENT(depth + 1) << COLOR_KEYWORD << ": " << color.name(); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return HoverType(color, fill); } QRect XmlLayoutParser::parseRegion(QXmlStreamReader &xml, const int depth) { int left = 0, top = 0; unsigned int width = 0, height = 0; if (xml.name() == REGION_KEYWORD && xml.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = xml.attributes(); if (attributes.hasAttribute(REGION_LEFT_ATTR_KEYWORD)) { left = attributes.value(REGION_LEFT_ATTR_KEYWORD).toString().toInt(); } if (attributes.hasAttribute(REGION_TOP_ATTR_KEYWORD)) { top = attributes.value(REGION_TOP_ATTR_KEYWORD).toString().toInt(); } if (attributes.hasAttribute(REGION_WIDTH_ATTR_KEYWORD)) { width = attributes.value(REGION_WIDTH_ATTR_KEYWORD).toString().toUInt(); } if (attributes.hasAttribute(REGION_HEIGHT_ATTR_KEYWORD)) { height = attributes.value(REGION_HEIGHT_ATTR_KEYWORD).toString().toUInt(); } } return QRect(left, top, width, height); } DisplayType *XmlLayoutParser::parseDisplay(QXmlStreamReader &xml, const int depth) { QRect displayRect(0, 0, 0, 0); int angle = 0; QPixmap maskImage; QDEBUG_INDENT(depth) << DISPLAY_KEYWORD << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == DISPLAY_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == REGION_KEYWORD) { /* region */ displayRect = parseRegion(xml, depth + 1); QDEBUG_INDENT(depth + 1) << "(" << displayRect.x() << "," << displayRect.y() << " " << displayRect.width() << "x" << displayRect.height() << ")"; } else if (xml.name() == ANGLE_KEYWORD) { /* angle */ angle = xml.readElementText().toInt(); } else if (xml.name() == MASK_IMG_KEYWORD) { /* display mask */ QString maskImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << MASK_IMG_KEYWORD << ": " << maskImageFileName; if (maskImage.load( xmlPath + QDir::separator() + maskImageFileName) == false) { QWARN_INDENT(depth + 1) << "failed to load mask image"; } } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return new DisplayType(displayRect, angle, maskImage); } KeycodeType XmlLayoutParser::parseKeycode(QXmlStreamReader &xml, const int depth) { int longPress = -1, shortPress = 0; /* attribute */ longPress = xml.attributes().value(KEYCODE_LONGPRESS_ATTR_KEYWORD).toString().toInt(); shortPress = xml.readElementText().toInt(); return KeycodeType(shortPress, longPress); } HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml, const int depth) { QRect keyRegion; KeycodeType keycodeType; QString keyTooptip; QKeySequence keySequence; /* attribute */ QString keyName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == KEY_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == REGION_KEYWORD) { /* region */ keyRegion = parseRegion(xml, depth + 1); } else if (xml.name() == KEYCODE_KEYWORD) { /* keycode */ keycodeType = parseKeycode(xml, depth + 1); } else if (xml.name() == TOOLTIP_KEYWORD) { /* tooltip */ keyTooptip = xml.readElementText(); } else if (xml.name() == SHORTCUT_KEYWORD) { /* shortcut */ keySequence = parseShortcut(xml, depth + 1); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } return new HardwareKey(keyName, keycodeType, keyRegion, keyTooptip, keySequence); } int XmlLayoutParser::parseKeyList(QXmlStreamReader &xml, const int depth, QList &list) { HardwareKey *hwKey = NULL; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == KEYLIST_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == KEY_KEYWORD) { hwKey = parseKey(xml, depth + 1); if (hwKey != NULL) { list.append(hwKey); } } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } return list.count(); } MainForm *XmlLayoutParser::parseMainForm(QXmlStreamReader &xml, const int depth) { /* attribute */ QString formName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); MainForm *form = new MainForm(formName); qDebug(LOG_LINE_HEAD_CHAR); QDEBUG_INDENT(depth) << form->getName() << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == FORM_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == DISPLAY_KEYWORD) { /* display */ form->setDpyType(parseDisplay(xml, depth + 1)); } else if (xml.name() == NORMAL_IMG_KEYWORD) { /* normal image */ QString normalImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << NORMAL_IMG_KEYWORD << ": " << normalImageFileName; if (form->skinImg[LayoutForm::normal].load( xmlPath + QDir::separator() + normalImageFileName) == false) { QWARN_INDENT(depth + 1) << "failed to load normal image"; } } else if (xml.name() == PRESSED_IMG_KEYWORD) { /* key pressed image */ QString pressedImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << PRESSED_IMG_KEYWORD << ": " << pressedImageFileName; if (form->skinImg[LayoutForm::pressed].load( xmlPath + QDir::separator() + pressedImageFileName) == false) { QWARN_INDENT(depth + 1) << "failed to load pressed image"; } } else if (xml.name() == ROTARY_IMG_KEYWORD) { /* rotary image */ QString rotaryImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << ROTARY_IMG_KEYWORD << ": " << rotaryImageFileName; form->setRotaryImage(new QPixmap( xmlPath + QDir::separator() + rotaryImageFileName)); if (form->getRotaryImage()->isNull() == true) { QWARN_INDENT(depth + 1) << "failed to load rotary image"; } } else if (xml.name() == KEYLIST_KEYWORD) { /* HW keys */ const int cnt = parseKeyList(xml, depth + 1, form->getKeyList()); QDEBUG_INDENT(depth + 1) << KEYLIST_KEYWORD << ": " << cnt; } else if (xml.name() == HOVER_KEYWORD) { /* hover */ form->setHoverType(parseHover(xml, depth + 1)); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return form; } int XmlLayoutParser::parseMainFormList(QXmlStreamReader &xml, const int depth, QList &list) { MainForm *form = NULL; QDEBUG_INDENT(depth) << FORMLIST_KEYWORD << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == FORMLIST_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == FORM_KEYWORD) { form = parseMainForm(xml, depth + 1); if (form != NULL) { /* image validation */ if (form->skinImg[LayoutForm::normal].size() == QSize(0, 0)) { QDEBUG_INDENT(depth + 1) << "(general purpose skin type)"; SkinPainter painter("main-skin", uiInfo->getResolution(), form->getDpyType()->getAngle(), QPoint(30, 16), uiInfo->getVMColor()); form->setGeneralPurpose(true); form->skinImg[LayoutForm::normal] = painter.getSkinImage(); form->getDpyType()->setRect(painter.getCenteralRect()); } list.append(form); } } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return list.count(); } /* menu */ int XmlLayoutParser::parseFactorList(QXmlStreamReader &xml, const int depth, QMap &map, int *defaultFactor) { QString defaultValue = xml.attributes().value(DEFAULT_ATTR_KEYWORD).toString(); *defaultFactor = defaultValue.toInt(); QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == FACTORLIST_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == FACTOR_KEYWORD) { QString value = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); map.insert(xml.readElementText().toInt(), value); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } return map.count(); } QKeySequence XmlLayoutParser::parseShortcut(QXmlStreamReader &xml, const int depth) { QString keyString = xml.readElementText(); #ifdef CONFIG_DARWIN /* QKeySequence Note: On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and * Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, * and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to * the Control keys. Developers on Mac OS X can use the same shortcut descriptions * across all platforms, and their applications will automatically work as expected * on Mac OS X. */ /* According to Qt note, "Ctrl" will be treated as command key. This is not what we * want. To be recognized as control key on MacOS, XML Parser should replace "Ctrl" * with "Meta" text. */ keyString.replace(XML_QT_CTRLKEY_STRING, XML_QT_METAKEY_STRING); #endif return QKeySequence::fromString(keyString); } int XmlLayoutParser::parseShortcuts(QXmlStreamReader &xml, const int depth, QMap &map) { QString key = xml.attributes().value(PROP_ATTR_KEYWORD).toString(); map.insert(key, parseShortcut(xml, depth + 1)); return map.count(); } AdvancedMenuItem *XmlLayoutParser::parseAdvancedMenuItem( QXmlStreamReader &xml, const int depth) { /* attribute */ QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); AdvancedMenuItem *item = new AdvancedMenuItem(menuName); QDEBUG_INDENT(depth) << ADVANCED_MENU_KEYWORD << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == ADVANCED_MENU_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == SHORTCUT_KEYWORD) { parseShortcuts(xml, depth + 1, item->getShortcuts()); } else if (xml.name() == MENULIST_KEYWORD) { const int cnt = parseMenuList(xml, depth + 1, item->getMenuList()); QDEBUG_INDENT(depth + 1) << MENULIST_KEYWORD << ": " << cnt; } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return item; } ScaleMenuItem *XmlLayoutParser::parseScaleMenuItem( QXmlStreamReader &xml, const int depth) { /* attribute */ QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); ScaleMenuItem *item = new ScaleMenuItem(menuName); QDEBUG_INDENT(depth) << SCALE_MENU_KEYWORD << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == SCALE_MENU_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == SHORTCUT_KEYWORD) { parseShortcuts(xml, depth + 1, item->getShortcuts()); } else if (xml.name() == FACTORLIST_KEYWORD) { int defaultFactor = 0; const int cnt = parseFactorList(xml, depth + 1, item->getFactorMap(), &defaultFactor); QDEBUG_INDENT(depth + 1) << FACTORLIST_KEYWORD << ": " << cnt; item->setDefaultScaleFactor(defaultFactor); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return item; } MenuItem *XmlLayoutParser::parseGeneralMenuItem( QXmlStreamReader &xml, const int depth, int menuType) { QString itemKeyword = xml.name().toString(); /* attribute */ QString menuName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); MenuItem *item = new MenuItem(menuType, menuName); QString shortcut; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name().compare(itemKeyword) == 0 && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == SHORTCUT_KEYWORD) { parseShortcuts(xml, depth + 1, item->getShortcuts()); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } return item; } int XmlLayoutParser::parseMenuList(QXmlStreamReader &xml, const int depth, QList &list) { MenuItem *item = NULL; qDebug(LOG_LINE_HEAD_CHAR); QDEBUG_INDENT(depth) << MENULIST_KEYWORD << " {"; QXmlStreamReader::TokenType token = xml.readNext(); QString tokenName = xml.name().toString(); while (xml.atEnd() == false && (tokenName == MENULIST_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { const int menuType = menuItems.value(tokenName, -1); switch(menuType) { case MenuItemType::separator: // separator item = new MenuItem(menuType, NULL); break; case MenuItemType::advancedItem: // Advanced item = dynamic_cast( parseAdvancedMenuItem(xml, depth + 1)); break; case MenuItemType::scaleItem: // Scale item = dynamic_cast( parseScaleMenuItem(xml, depth + 1)); break; case MenuItemType::infoItem: case MenuItemType::onTopItem: case MenuItemType::moveItem: case MenuItemType::switchItem: case MenuItemType::controllerItem: case MenuItemType::hostKeyboardItem: case MenuItemType::shellItem: case MenuItemType::controlPanelItem: case MenuItemType::screenShotItem: case MenuItemType::aboutItem: case MenuItemType::systemResetItem: case MenuItemType::forceCloseItem: /* fall through */ case MenuItemType::closeItem: item = parseGeneralMenuItem(xml, depth + 1, menuType); break; default: QWARN_INDENT(depth + 1) << "undefined element: " << tokenName; item = NULL; break; } if (item != NULL) { list.append(item); } } token = xml.readNext(); tokenName = xml.name().toString(); } QDEBUG_INDENT(depth) << "}"; return list.count(); } QString XmlLayoutParser::parseEmulatorUI(QXmlStreamReader &xml) { QString layoutVersion = GENERIC_TEXT_UNDEFINED; const int depth = 0; qDebug(LOG_LINE_HEAD_CHAR); QDEBUG_INDENT(depth) << EMULATOR_UI_KEYWORD << " {"; QXmlStreamReader::TokenType token = QXmlStreamReader::NoToken; while (xml.atEnd() == false && xml.hasError() == false) { token = xml.readNext(); /* If token is just StartDocument, go to next. */ if (token == QXmlStreamReader::StartDocument) { continue; } if (token == QXmlStreamReader::StartElement) { if (xml.name() == EMULATOR_UI_KEYWORD) { continue; } if (xml.name() == LAYOUTVER_KEYWORD) { layoutVersion = xml.readElementText(); continue; } else if (xml.name() == FORMLIST_KEYWORD) { /* forms */ const int cnt = parseMainFormList(xml, depth + 1, uiInfo->getMainFormList()); QDEBUG_INDENT(depth + 1) << FORMLIST_KEYWORD << ": " << cnt; } else if (xml.name() == MENULIST_KEYWORD) { /* menus */ const int cnt = parseMenuList(xml, depth + 1, uiInfo->getMenuList()); QDEBUG_INDENT(depth + 1) << MENULIST_KEYWORD << ": " << cnt; } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } } QDEBUG_INDENT(depth) << "}"; if (xml.hasError() == true) { printError(xml.error()); } return layoutVersion; } /* controller */ ControllerForm *XmlLayoutParser::parseControllerForm( QXmlStreamReader &xml, const int depth) { /* attribute */ QString formName = xml.attributes().value(NAME_ATTR_KEYWORD).toString(); ControllerForm *form = new ControllerForm( formName.isEmpty() ? xmlPath.section(QDir::separator(), -1) : formName); QDEBUG_INDENT(depth) << form->getName() << " {"; QXmlStreamReader::TokenType token = xml.readNext(); while (xml.atEnd() == false && (xml.name() == FORM_KEYWORD && token == QXmlStreamReader::EndElement) == false) /* ~ */ { if (token == QXmlStreamReader::StartElement) { if (xml.name() == NORMAL_IMG_KEYWORD) { /* normal image */ QString normalImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << NORMAL_IMG_KEYWORD << ": " << normalImageFileName; if (form->skinImg[LayoutForm::normal].load( xmlPath + QDir::separator() + normalImageFileName) == false) { QWARN_INDENT(depth + 1) << "failed to load normal image"; } } else if (xml.name() == PRESSED_IMG_KEYWORD) { /* key pressed image */ QString pressedImageFileName = xml.readElementText(); QDEBUG_INDENT(depth + 1) << PRESSED_IMG_KEYWORD << ": " << pressedImageFileName; if (form->skinImg[LayoutForm::pressed].load( xmlPath + QDir::separator() + pressedImageFileName) == false) { QWARN_INDENT(depth + 1) << "failed to load pressed image"; } } else if (xml.name() == KEYLIST_KEYWORD) { /* HW keys */ const int cnt = parseKeyList(xml, depth + 1, form->getKeyList()); QDEBUG_INDENT(depth + 1) << KEYLIST_KEYWORD << ": " << cnt; } else if (xml.name() == HOVER_KEYWORD) { /* hover */ form->setHoverType(parseHover(xml, depth + 1)); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } token = xml.readNext(); } QDEBUG_INDENT(depth) << "}"; return form; } QString XmlLayoutParser::parseControllerUI(QXmlStreamReader &xml) { QString layoutVersion = GENERIC_TEXT_UNDEFINED; const int depth = 0; qDebug(LOG_LINE_HEAD_CHAR); QDEBUG_INDENT(depth) << CONTROLLER_UI_KEYWORD << " {"; ControllerForm *form = NULL; QXmlStreamReader::TokenType token = QXmlStreamReader::NoToken; while (xml.atEnd() == false && xml.hasError() == false) { token = xml.readNext(); /* If token is just StartDocument, go to next. */ if (token == QXmlStreamReader::StartDocument) { continue; } if (token == QXmlStreamReader::StartElement) { if (xml.name() == CONTROLLER_UI_KEYWORD) { continue; } if (xml.name() == LAYOUTVER_KEYWORD) { layoutVersion = xml.readElementText(); continue; } else if (xml.name() == FORM_KEYWORD) { form = parseControllerForm(xml, depth + 1); if (form != NULL) { /* image validation */ if (form->skinImg[LayoutForm::normal].size() == QSize(0, 0)) { QDEBUG_INDENT(depth + 1) << "(general purpose con type)"; makeGeneralCon(form); } uiInfo->getConFormList().append(form); } } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } } } QDEBUG_INDENT(depth) << "}"; if (xml.hasError() == true) { printError(xml.error()); } return layoutVersion; } void XmlLayoutParser::makeGeneralCon(ControllerForm *form) { const int keyCount = form->getKeyList().count(); int width = GPC_KEYBUTTON_WIDTH; int height = GPC_HEAD_SPACING; if (keyCount < GPC_KEYBUTTON_DEFAULT_CNT) { height += (GPC_KEYBUTTON_HEIGHT * keyCount) + (GPC_KEYBUTTON_VSPACING * (keyCount - 1)) + GPC_TAIL_SPACING; } else { width += (GPC_SCROLLBAR_WIDTH + GPC_SCROLLBAR_HSPACING); height += (GPC_KEYBUTTON_HEIGHT * GPC_KEYBUTTON_DEFAULT_CNT) + (GPC_KEYBUTTON_VSPACING * (GPC_KEYBUTTON_DEFAULT_CNT - 1)) + GPC_TAIL_SPACING; } SkinPainter painter("controller-skin", QSize(width, qMax(height, QT_LAYOUT_MINIMUM - 20)), 0, QPoint(14, GPC_HEAD_SPACING - 1), uiInfo->getVMColor()); form->skinImg[LayoutForm::normal] = painter.getSkinImage(); form->setCenteralRect(painter.getCenteralRect()); form->setGeneralPurpose(true); } void XmlLayoutParser::printError(QXmlStreamReader::Error err) { switch (err) { case QXmlStreamReader::NoError: /* do nothing */ break; case QXmlStreamReader::UnexpectedElementError: qCritical("The parser encountered an element that was different to those it expected."); break; case QXmlStreamReader::CustomError: qCritical("A custom error has been raised with raiseError()."); break; case QXmlStreamReader::NotWellFormedError: qCritical("The parser internally raised an error due to the read XML not being well-formed."); break; case QXmlStreamReader::PrematureEndOfDocumentError: qCritical("The input stream ended before a well-formed XML document was parsed."); break; default: qCritical("Unexpected error type was returned."); break; } }