00001 #include <iostream>
00002 using namespace std;
00003
00004 #include <cmath>
00005 #include <cstdlib>
00006
00007 #include <qapplication.h>
00008
00009 #include "uilistbtntype.h"
00010 #include "xmlparse.h"
00011
00012 #ifdef USING_MINGW
00013 #undef LoadImage
00014 #endif
00015
00016 MPUBLIC QMap<QString, fontProp> globalFontMap;
00017
00018 XMLParse::XMLParse(void)
00019 {
00020 allTypes = new vector<LayerSet *>;
00021 }
00022
00023 XMLParse::~XMLParse()
00024 {
00025 vector<LayerSet *>::iterator i = allTypes->begin();
00026 for (; i != allTypes->end(); i++)
00027 {
00028 LayerSet *type = (*i);
00029 if (type)
00030 delete type;
00031 }
00032 delete allTypes;
00033 }
00034
00035 bool XMLParse::LoadTheme(QDomElement &ele, QString winName, QString specialfile)
00036 {
00037 usetrans = gContext->GetNumSetting("PlayBoxTransparency", 1);
00038
00039 fontSizeType = gContext->GetSetting("ThemeFontSizeType", "default");
00040
00041 QValueList<QString> searchpath = gContext->GetThemeSearchPath();
00042 for (QValueList<QString>::const_iterator ii = searchpath.begin();
00043 ii != searchpath.end(); ii++)
00044 {
00045 QString themefile = *ii + specialfile + "ui.xml";
00046 if (doLoadTheme(ele, winName, themefile))
00047 {
00048 VERBOSE(VB_GENERAL, "XMLParse::LoadTheme using " << themefile);
00049 return true;
00050 }
00051 }
00052
00053 return false;
00054 }
00055
00056 bool XMLParse::doLoadTheme(QDomElement &ele, QString winName, QString themeFile)
00057 {
00058 QDomDocument doc;
00059 QFile f(themeFile);
00060
00061 if (!f.open(IO_ReadOnly))
00062 {
00063
00064 return false;
00065 }
00066
00067 QString errorMsg;
00068 int errorLine = 0;
00069 int errorColumn = 0;
00070
00071 if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn))
00072 {
00073 cerr << "Error parsing: " << themeFile << endl;
00074 cerr << "at line: " << errorLine << " column: " << errorColumn << endl;
00075 cerr << errorMsg << endl;
00076 f.close();
00077 return false;
00078 }
00079
00080 f.close();
00081
00082 QDomElement docElem = doc.documentElement();
00083 QDomNode n = docElem.firstChild();
00084 while (!n.isNull())
00085 {
00086 QDomElement e = n.toElement();
00087 if (!e.isNull())
00088 {
00089 if (e.tagName() == "window")
00090 {
00091 QString name = e.attribute("name", "");
00092 if (name.isNull() || name.isEmpty())
00093 {
00094 cerr << "Window needs a name\n";
00095 return false;
00096 }
00097
00098 if (name == winName)
00099 {
00100 ele = e;
00101 return true;
00102 }
00103 }
00104 else
00105 {
00106 cerr << "Unknown element: " << e.tagName() << endl;
00107 return false;
00108 }
00109 }
00110 n = n.nextSibling();
00111 }
00112
00113 return false;
00114 }
00115
00116 QString XMLParse::getFirstText(QDomElement &element)
00117 {
00118 for (QDomNode dname = element.firstChild(); !dname.isNull();
00119 dname = dname.nextSibling())
00120 {
00121 QDomText t = dname.toText();
00122 if (!t.isNull())
00123 return t.data();
00124 }
00125 return "";
00126 }
00127
00128 void XMLParse::parseFont(QDomElement &element)
00129 {
00130 QString name;
00131 QString face;
00132 QString bold;
00133 QString ital;
00134 QString under;
00135
00136 int size = -1;
00137 int sizeSmall = -1;
00138 int sizeBig = -1;
00139 QPoint shadowOffset = QPoint(0, 0);
00140 QString color = "#ffffff";
00141 QString dropcolor = "#000000";
00142 QString hint;
00143 QFont::StyleHint styleHint = QFont::Helvetica;
00144
00145 bool haveSizeSmall = false;
00146 bool haveSizeBig = false;
00147 bool haveSize = false;
00148 bool haveFace = false;
00149 bool haveColor = false;
00150 bool haveDropColor = false;
00151 bool haveBold = false;
00152 bool haveShadow = false;
00153 bool haveItal = false;
00154 bool haveUnder = false;
00155
00156 fontProp *baseFont = NULL;
00157
00158 name = element.attribute("name", "");
00159 if (name.isNull() || name.isEmpty())
00160 {
00161 cerr << "Font needs a name\n";
00162 return;
00163 }
00164
00165 QString base = element.attribute("base", "");
00166 if (!base.isNull() && !base.isEmpty())
00167 {
00168 baseFont = GetFont(base);
00169 if (!baseFont)
00170 {
00171 cerr << "Specified base font '" << base << "' does not exist for font " << face << endl;
00172 return;
00173 }
00174 }
00175
00176 face = element.attribute("face", "");
00177 if (face.isNull() || face.isEmpty())
00178 {
00179 if (!baseFont)
00180 {
00181 cerr << "Font needs a face\n";
00182 return;
00183 }
00184 }
00185 else
00186 {
00187 haveFace = true;
00188 }
00189
00190 hint = element.attribute("stylehint", "");
00191 if (!hint.isNull() && !hint.isEmpty())
00192 {
00193 styleHint = (QFont::StyleHint)hint.toInt();
00194 }
00195
00196 for (QDomNode child = element.firstChild(); !child.isNull();
00197 child = child.nextSibling())
00198 {
00199 QDomElement info = child.toElement();
00200 if (!info.isNull())
00201 {
00202 if (info.tagName() == "size")
00203 {
00204 haveSize = true;
00205 size = getFirstText(info).toInt();
00206 }
00207 else if (info.tagName() == "size:small")
00208 {
00209 haveSizeSmall = true;
00210 sizeSmall = getFirstText(info).toInt();
00211 }
00212 else if (info.tagName() == "size:big")
00213 {
00214 haveSizeBig = true;
00215 sizeBig = getFirstText(info).toInt();
00216 }
00217 else if (info.tagName() == "color")
00218 {
00219 haveColor = true;
00220 color = getFirstText(info);
00221 }
00222 else if (info.tagName() == "dropcolor")
00223 {
00224 haveDropColor = true;
00225 dropcolor = getFirstText(info);
00226 }
00227 else if (info.tagName() == "shadow")
00228 {
00229 haveShadow = true;
00230 shadowOffset = parsePoint(getFirstText(info));
00231 shadowOffset.setX((int)(shadowOffset.x() * wmult));
00232 shadowOffset.setY((int)(shadowOffset.y() * hmult));
00233 }
00234 else if (info.tagName() == "bold")
00235 {
00236 haveBold = true;
00237 bold = getFirstText(info);
00238 }
00239 else if (info.tagName() == "italics")
00240 {
00241 haveItal = true;
00242 ital = getFirstText(info);
00243 }
00244 else if (info.tagName() == "underline")
00245 {
00246 haveUnder = true;
00247 under = getFirstText(info);
00248 }
00249 else
00250 {
00251 cerr << "Unknown tag " << info.tagName() << " in font\n";
00252 return;
00253 }
00254 }
00255 }
00256
00257 fontProp *testFont = GetFont(name, false);
00258 if (testFont)
00259 {
00260 cerr << "Error: already have a font called: " << name << endl;
00261 return;
00262 }
00263
00264 fontProp newFont;
00265
00266 if (baseFont)
00267 newFont = *baseFont;
00268
00269 if ( haveSizeSmall && fontSizeType == "small")
00270 {
00271 if (sizeSmall > 0)
00272 size = sizeSmall;
00273 }
00274 else if (haveSizeBig && fontSizeType == "big")
00275 {
00276 if (sizeBig > 0)
00277 size = sizeBig;
00278 }
00279
00280 if (size < 0 && !baseFont)
00281 {
00282 cerr << "Error: font size must be > 0\n";
00283 return;
00284 }
00285
00286 if (baseFont && !haveSize)
00287 size = baseFont->face.pointSize();
00288 else
00289 size = GetMythMainWindow()->NormalizeFontSize(size);
00290
00291
00292 if (!haveFace && baseFont)
00293 {
00294 newFont.face = baseFont->face;
00295 if (haveSize)
00296 newFont.face.setPointSize(size);
00297 }
00298 else
00299 {
00300 QFont temp(face, size);
00301 temp.setStyleHint(styleHint, QFont::PreferAntialias);
00302
00303 if (!temp.exactMatch())
00304 temp = QFont(QFontInfo(QApplication::font()).family(), size);
00305
00306 newFont.face = temp;
00307 }
00308
00309 if (baseFont && !haveBold)
00310 newFont.face.setBold(baseFont->face.bold());
00311 else
00312 {
00313 if (bold.lower() == "yes")
00314 newFont.face.setBold(true);
00315 else
00316 newFont.face.setBold(false);
00317 }
00318
00319 if (baseFont && !haveItal)
00320 newFont.face.setItalic(baseFont->face.italic());
00321 else
00322 {
00323 if (ital.lower() == "yes")
00324 newFont.face.setItalic(true);
00325 else
00326 newFont.face.setItalic(false);
00327 }
00328
00329 if (baseFont && !haveUnder)
00330 newFont.face.setUnderline(baseFont->face.underline());
00331 else
00332 {
00333 if (under.lower() == "yes")
00334 newFont.face.setUnderline(true);
00335 else
00336 newFont.face.setUnderline(false);
00337 }
00338
00339 if (haveColor)
00340 {
00341 QColor foreColor(color);
00342 newFont.color = foreColor;
00343 }
00344
00345 if (haveDropColor)
00346 {
00347 QColor dropColor(dropcolor);
00348 newFont.dropColor = dropColor;
00349 }
00350
00351 if (haveShadow)
00352 newFont.shadowOffset = shadowOffset;
00353
00354 fontMap[name] = newFont;
00355 }
00356
00357 void XMLParse::parseImage(LayerSet *container, QDomElement &element)
00358 {
00359 int context = -1;
00360 QString name = element.attribute("name", "");
00361 if (name.isNull() || name.isEmpty())
00362 {
00363 cerr << "Image needs a name\n";
00364 return;
00365 }
00366
00367 QString order = element.attribute("draworder", "");
00368 if (order.isNull() || order.isEmpty())
00369 {
00370 cerr << "Image needs an order\n";
00371 return;
00372 }
00373
00374 QString filename = "";
00375 QPoint pos = QPoint(0, 0);
00376
00377 QPoint scale = QPoint(-1, -1);
00378 QPoint skipin = QPoint(0, 0);
00379
00380 for (QDomNode child = element.firstChild(); !child.isNull();
00381 child = child.nextSibling())
00382 {
00383 QDomElement info = child.toElement();
00384 if (!info.isNull())
00385 {
00386 if (info.tagName() == "context")
00387 {
00388 context = getFirstText(info).toInt();
00389 }
00390 else if (info.tagName() == "filename")
00391 {
00392 filename = getFirstText(info);
00393 }
00394 else if (info.tagName() == "position")
00395 {
00396 pos = parsePoint(getFirstText(info));
00397 pos.setX((int)(pos.x() * wmult));
00398 pos.setY((int)(pos.y() * hmult));
00399 }
00400 else if (info.tagName() == "staticsize")
00401 {
00402 scale = parsePoint(getFirstText(info));
00403 }
00404 else if (info.tagName() == "skipin")
00405 {
00406 skipin = parsePoint(getFirstText(info));
00407 skipin.setX((int)(skipin.x() * wmult));
00408 skipin.setY((int)(skipin.y() * hmult));
00409 }
00410 else
00411 {
00412 cerr << "Unknown: " << info.tagName() << " in image\n";
00413 return;
00414 }
00415 }
00416 }
00417
00418 UIImageType *image = new UIImageType(name, filename, order.toInt(), pos);
00419 image->SetScreen(wmult, hmult);
00420 if (scale.x() != -1 || scale.y() != -1)
00421 image->SetSize(scale.x(), scale.y());
00422 image->SetSkip(skipin.x(), skipin.y());
00423 QString flex = element.attribute("fleximage", "");
00424 if (!flex.isNull() && !flex.isEmpty())
00425 {
00426 if (flex.lower() == "yes")
00427 image->SetFlex(true);
00428 else
00429 image->SetFlex(false);
00430 }
00431
00432 image->LoadImage();
00433
00434 QString visible = element.attribute("visible", "");
00435 if (!visible.isNull() && !visible.isEmpty())
00436 {
00437 if (visible.lower() == "yes")
00438 image->show();
00439 else
00440 image->hide();
00441 }
00442
00443 if (context != -1)
00444 {
00445 image->SetContext(context);
00446 }
00447 image->SetParent(container);
00448 container->AddType(image);
00449 container->bumpUpLayers(order.toInt());
00450 }
00451
00452 bool XMLParse::parseAnimatedImage(LayerSet *container, QDomElement &element)
00453 {
00454 int context = -1;
00455 QString name = element.attribute("name", "");
00456 if (name.isNull() || name.isEmpty())
00457 {
00458 VERBOSE(VB_IMPORTANT,
00459 "XMLParse::parseAnimatedImage(): image needs a name");
00460 return false;
00461 }
00462
00463 QString order = element.attribute("draworder", "");
00464 if (order.isNull() || order.isEmpty())
00465 {
00466 VERBOSE(VB_IMPORTANT,
00467 "XMLParse::parseAnimatedImage(): image needs a draw order");
00468 return false;
00469 }
00470
00471 QString filename = "";
00472 QPoint pos = QPoint(0, 0);
00473
00474 QPoint scale = QPoint(-1, -1);
00475 QPoint skipin = QPoint(0, 0);
00476 QString interval, startinterval, imagecount;
00477
00478 bool ok = true;
00479 for (QDomNode child = element.firstChild(); !child.isNull();
00480 child = child.nextSibling())
00481 {
00482 QDomElement info = child.toElement();
00483 if (!info.isNull())
00484 {
00485 if (info.tagName() == "context")
00486 {
00487 context = getFirstText(info).toInt();
00488 }
00489 else if (info.tagName() == "filename")
00490 {
00491 filename = getFirstText(info);
00492 }
00493 else if (info.tagName() == "position")
00494 {
00495 pos = parsePoint(getFirstText(info));
00496 pos.setX((int)(pos.x() * wmult));
00497 pos.setY((int)(pos.y() * hmult));
00498 }
00499 else if (info.tagName() == "staticsize")
00500 {
00501 scale = parsePoint(getFirstText(info));
00502 }
00503 else if (info.tagName() == "skipin")
00504 {
00505 skipin = parsePoint(getFirstText(info));
00506 skipin.setX((int)(skipin.x() * wmult));
00507 skipin.setY((int)(skipin.y() * hmult));
00508 }
00509 else if (info.tagName() == "interval")
00510 {
00511 interval = getFirstText(info);
00512 }
00513 else if (info.tagName() == "startinterval")
00514 {
00515 startinterval = getFirstText(info);
00516 }
00517 else if (info.tagName() == "imagecount")
00518 {
00519 imagecount = getFirstText(info);
00520 }
00521 else
00522 {
00523 VERBOSE(VB_IMPORTANT,
00524 QString("XMLParse::parseAnimatedImage(): Unknown "
00525 "tag (%1) in image").arg(info.tagName()));
00526 ok = false;
00527 }
00528 }
00529 }
00530 if (!ok)
00531 return ok;
00532
00533 UIAnimatedImageType *image = new UIAnimatedImageType(name, filename, imagecount.toInt(),
00534 interval.toInt(), startinterval.toInt(), order.toInt(), pos);
00535 image->SetScreen(wmult, hmult);
00536 if (scale.x() != -1 || scale.y() != -1)
00537 image->SetSize(scale.x(), scale.y());
00538 image->SetSkip(skipin.x(), skipin.y());
00539 QString flex = element.attribute("fleximage", "");
00540 if (!flex.isNull() && !flex.isEmpty())
00541 {
00542 if (flex.lower() == "yes")
00543 image->SetFlex(true);
00544 else
00545 image->SetFlex(false);
00546 }
00547
00548
00549 if (context != -1)
00550 {
00551 image->SetContext(context);
00552 }
00553 image->SetParent(container);
00554 container->AddType(image);
00555 container->bumpUpLayers(order.toInt());
00556 return true;
00557 }
00558
00559 void XMLParse::parseRepeatedImage(LayerSet *container, QDomElement &element)
00560 {
00561 int orientation = 0;
00562 int context = -1;
00563 QString name = element.attribute("name", "");
00564 if (name.isNull() || name.isEmpty())
00565 {
00566 cerr << "Repeated Image needs a name\n";
00567 return;
00568 }
00569
00570 QString order = element.attribute("draworder", "");
00571 if (order.isNull() || order.isEmpty())
00572 {
00573 cerr << "Repeated Image needs an order\n";
00574 return;
00575 }
00576
00577 QString filename = "";
00578 QPoint pos = QPoint(0, 0);
00579
00580 QPoint scale = QPoint(-1, -1);
00581 QPoint skipin = QPoint(0, 0);
00582
00583 for (QDomNode child = element.firstChild(); !child.isNull();
00584 child = child.nextSibling())
00585 {
00586 QDomElement info = child.toElement();
00587 if (!info.isNull())
00588 {
00589 if (info.tagName() == "context")
00590 {
00591 context = getFirstText(info).toInt();
00592 }
00593 else if (info.tagName() == "filename")
00594 {
00595 filename = getFirstText(info);
00596 }
00597 else if (info.tagName() == "position")
00598 {
00599 pos = parsePoint(getFirstText(info));
00600 pos.setX((int)(pos.x() * wmult));
00601 pos.setY((int)(pos.y() * hmult));
00602 }
00603 else if (info.tagName() == "staticsize")
00604 {
00605 scale = parsePoint(getFirstText(info));
00606 }
00607 else if (info.tagName() == "skipin")
00608 {
00609 skipin = parsePoint(getFirstText(info));
00610 skipin.setX((int)(skipin.x() * wmult));
00611 skipin.setY((int)(skipin.y() * hmult));
00612 }
00613 else if (info.tagName() == "orientation")
00614 {
00615 QString orient_string = getFirstText(info).lower();
00616 if (orient_string == "lefttoright")
00617 {
00618 orientation = 0;
00619 }
00620 if (orient_string == "righttoleft")
00621 {
00622 orientation = 1;
00623 }
00624 if (orient_string == "bottomtotop")
00625 {
00626 orientation = 2;
00627 }
00628 if (orient_string == "toptobottom")
00629 {
00630 orientation = 3;
00631 }
00632 }
00633 else
00634 {
00635 cerr << "Unknown: " << info.tagName() << " in repeated image\n";
00636 return;
00637 }
00638 }
00639 }
00640
00641 UIRepeatedImageType *image = new UIRepeatedImageType(name, filename, order.toInt(), pos);
00642 image->SetScreen(wmult, hmult);
00643 if (scale.x() != -1 || scale.y() != -1)
00644 image->SetSize(scale.x(), scale.y());
00645 image->SetSkip(skipin.x(), skipin.y());
00646 QString flex = element.attribute("fleximage", "");
00647 if (!flex.isNull() && !flex.isEmpty())
00648 {
00649 if (flex.lower() == "yes")
00650 image->SetFlex(true);
00651 else
00652 image->SetFlex(false);
00653 }
00654
00655 image->LoadImage();
00656 if (context != -1)
00657 {
00658 image->SetContext(context);
00659 }
00660 image->setOrientation(orientation);
00661 image->SetParent(container);
00662 container->AddType(image);
00663 container->bumpUpLayers(order.toInt());
00664 }
00665
00666 bool XMLParse::parseDefaultCategoryColors(QMap<QString, QString> &catColors)
00667 {
00668 QFile f;
00669 QValueList<QString> searchpath = gContext->GetThemeSearchPath();
00670 for (QValueList<QString>::const_iterator ii = searchpath.begin();
00671 ii != searchpath.end(); ii++)
00672 {
00673 f.setName(*ii + "categories.xml");
00674 if (f.open(IO_ReadOnly))
00675 break;
00676 }
00677 if (f.handle() == -1)
00678 {
00679 VERBOSE(VB_IMPORTANT, "Error: Unable to open " << f.name());
00680 return false;
00681 }
00682
00683 QDomDocument doc;
00684 QString errorMsg;
00685 int errorLine = 0;
00686 int errorColumn = 0;
00687
00688 if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn))
00689 {
00690 VERBOSE(VB_IMPORTANT, "Error parsing: " << f.name()
00691 << " line: " << errorLine << " column: " << errorColumn
00692 << ": " << errorMsg);
00693 f.close();
00694 return false;
00695 }
00696
00697 f.close();
00698
00699 QDomElement element = doc.documentElement();
00700 for (QDomNode child = element.firstChild(); !child.isNull();
00701 child = child.nextSibling())
00702 {
00703 QDomElement info = child.toElement();
00704 if (!info.isNull() && info.tagName() == "catcolor")
00705 {
00706 QString cat = "";
00707 QString col = "";
00708 cat = info.attribute("category");
00709 col = info.attribute("color");
00710
00711 catColors[cat.lower()] = col;
00712 }
00713 }
00714
00715 return true;
00716 }
00717
00718 void XMLParse::parseGuideGrid(LayerSet *container, QDomElement &element)
00719 {
00720 int context = -1;
00721 QString align = "";
00722 QString font = "";
00723 QString color = "";
00724 QString seltype = "";
00725 QString selcolor = "";
00726 QString reccolor = "";
00727 QString concolor = "";
00728 QRect area;
00729 QPoint textoff = QPoint(0, 0);
00730 bool cutdown = true;
00731 bool multiline = false;
00732 QMap<QString, QString> catColors;
00733 QMap<int, QString> recImgs;
00734 QMap<int, QString> arrows;
00735
00736 QString name = element.attribute("name", "");
00737 if (name.isNull() || name.isEmpty())
00738 {
00739 cerr << "Guide needs a name\n";
00740 return;
00741 }
00742
00743 QString order = element.attribute("draworder", "");
00744 if (order.isNull() || order.isEmpty())
00745 {
00746 cerr << "Guide needs an order\n";
00747 return;
00748 }
00749
00750 if (!parseDefaultCategoryColors(catColors))
00751 {
00752
00753 }
00754
00755 for (QDomNode child = element.firstChild(); !child.isNull();
00756 child = child.nextSibling())
00757 {
00758 QDomElement info = child.toElement();
00759 if (!info.isNull())
00760 {
00761 if (info.tagName() == "context")
00762 {
00763 context = getFirstText(info).toInt();
00764 }
00765 else if (info.tagName() == "font")
00766 {
00767 font = getFirstText(info);
00768 }
00769 else if (info.tagName() == "solidcolor")
00770 {
00771 color = getFirstText(info);
00772 catColors["none"] = color;
00773 }
00774 else if (info.tagName() == "area")
00775 {
00776 area = parseRect(getFirstText(info));
00777 normalizeRect(area);
00778 }
00779 else if (info.tagName() == "align")
00780 {
00781 align = getFirstText(info);
00782 }
00783 else if (info.tagName() == "cutdown")
00784 {
00785 if (getFirstText(info).lower() == "no")
00786 cutdown = false;
00787 }
00788 else if (info.tagName() == "textoffset")
00789 {
00790 textoff = parsePoint(getFirstText(info));
00791 textoff.setX((int)(textoff.x() * wmult));
00792 textoff.setY((int)(textoff.y() * hmult));
00793 }
00794 else if (info.tagName() == "recordingcolor")
00795 {
00796 reccolor = getFirstText(info);
00797 }
00798 else if (info.tagName() == "conflictingcolor")
00799 {
00800 concolor = getFirstText(info);
00801 }
00802 else if (info.tagName() == "multiline")
00803 {
00804 if (getFirstText(info).lower() == "yes")
00805 multiline = true;
00806 }
00807 else if (info.tagName() == "selector")
00808 {
00809 QString typ = "";
00810 QString col = "";
00811 typ = info.attribute("type");
00812 col = info.attribute("color");
00813
00814 selcolor = col;
00815 seltype = typ;
00816 }
00817 else if (info.tagName() == "recordstatus")
00818 {
00819 QString typ = "";
00820 QString img = "";
00821 int inttype = 0;
00822 typ = info.attribute("type");
00823 img = info.attribute("image");
00824
00825 if (typ == "SingleRecord")
00826 inttype = 1;
00827 else if (typ == "TimeslotRecord")
00828 inttype = 2;
00829 else if (typ == "ChannelRecord")
00830 inttype = 3;
00831 else if (typ == "AllRecord")
00832 inttype = 4;
00833 else if (typ == "WeekslotRecord")
00834 inttype = 5;
00835 else if (typ == "FindOneRecord")
00836 inttype = 6;
00837 else if (typ == "OverrideRecord")
00838 inttype = 7;
00839
00840 recImgs[inttype] = img;
00841 }
00842 else if (info.tagName() == "arrow")
00843 {
00844 QString dir = "";
00845 QString imag = "";
00846 dir = info.attribute("direction");
00847 imag = info.attribute("image");
00848
00849 if (dir == "left")
00850 arrows[0] = imag;
00851 else
00852 arrows[1] = imag;
00853 }
00854 else if (info.tagName() == "catcolor")
00855 {
00856 QString cat = "";
00857 QString col = "";
00858 cat = info.attribute("category");
00859 col = info.attribute("color");
00860
00861 catColors[cat.lower()] = col;
00862 }
00863 else
00864 {
00865 cerr << "Unknown: " << info.tagName() << " in bar\n";
00866 return;
00867 }
00868 }
00869 }
00870 fontProp *testfont = GetFont(font);
00871 if (!testfont)
00872 {
00873 cerr << "Unknown font: " << font << " in guidegrid: " << name << endl;
00874 return;
00875 }
00876
00877 UIGuideType *guide = new UIGuideType(name, order.toInt());
00878 guide->SetScreen(wmult, hmult);
00879 guide->SetFont(testfont);
00880 guide->SetSolidColor(color);
00881 guide->SetCutDown(cutdown);
00882 guide->SetArea(area);
00883 guide->SetCategoryColors(catColors);
00884 guide->SetTextOffset(textoff);
00885 if (concolor == "")
00886 concolor = reccolor;
00887 guide->SetRecordingColors(reccolor, concolor);
00888 guide->SetSelectorColor(selcolor);
00889 for (int i = 1; i <= 7; i++)
00890 guide->LoadImage(i, recImgs[i]);
00891 if (seltype.lower() == "box")
00892 guide->SetSelectorType(1);
00893 else
00894 guide->SetSelectorType(2);
00895
00896 guide->SetArrow(0, arrows[0]);
00897 guide->SetArrow(1, arrows[1]);
00898
00899 int jst = Qt::AlignLeft | Qt::AlignTop;
00900 if (multiline == true)
00901 jst = Qt::WordBreak;
00902
00903 if (!align.isNull() && !align.isEmpty())
00904 {
00905 if (align.lower() == "center")
00906 guide->SetJustification(Qt::AlignCenter | jst);
00907 else if (align.lower() == "right")
00908 guide->SetJustification(Qt::AlignRight | jst);
00909 else if (align.lower() == "left")
00910 guide->SetJustification(Qt::AlignLeft | jst);
00911 else if (align.lower() == "allcenter")
00912 guide->SetJustification(Qt::AlignHCenter | Qt::AlignVCenter | jst);
00913 else if (align.lower() == "vcenter")
00914 guide->SetJustification(Qt::AlignVCenter | jst);
00915 else if (align.lower() == "hcenter")
00916 guide->SetJustification(Qt::AlignHCenter | jst);
00917 }
00918 else
00919 guide->SetJustification(jst);
00920
00921 align = "";
00922
00923 if (context != -1)
00924 {
00925 guide->SetContext(context);
00926 }
00927 container->AddType(guide);
00928 }
00929
00930 void XMLParse::parseImageGrid(LayerSet *container, QDomElement &element)
00931 {
00932 int context = -1;
00933 QString align = "";
00934 QString activeFont = "";
00935 QString inactiveFont = "";
00936 QString selectedFont = "";
00937 QString color = "";
00938 QString textposition = "bottom";
00939 QRect area;
00940 int textheight = 0;
00941 int rowcount = 3;
00942 int columncount = 3;
00943 int padding = 10;
00944 bool cutdown = true;
00945 bool multiline = false;
00946 bool showChecks = false;
00947 bool showSelected = false;
00948 bool showScrollArrows = false;
00949 QString defaultImage = "";
00950 QString normalImage = "";
00951 QString selectedImage = "";
00952 QString highlightedImage = "";
00953
00954 QString name = element.attribute("name", "");
00955 if (name.isNull() || name.isEmpty())
00956 {
00957 cerr << "Image Grid needs a name\n";
00958 return;
00959 }
00960
00961 QString order = element.attribute("draworder", "");
00962 if (order.isNull() || order.isEmpty())
00963 {
00964 cerr << "Image Grid needs an order\n";
00965 return;
00966 }
00967
00968 for (QDomNode child = element.firstChild(); !child.isNull();
00969 child = child.nextSibling())
00970 {
00971 QDomElement info = child.toElement();
00972 if (!info.isNull())
00973 {
00974 if (info.tagName() == "context")
00975 {
00976 context = getFirstText(info).toInt();
00977 }
00978 else if (info.tagName() == "activefont")
00979 {
00980 activeFont = getFirstText(info);
00981 }
00982 else if (info.tagName() == "inactivefont")
00983 {
00984 inactiveFont = getFirstText(info);
00985 }
00986
00987 else if (info.tagName() == "selectedfont")
00988 {
00989 selectedFont = getFirstText(info);
00990 }
00991 else if (info.tagName() == "area")
00992 {
00993 area = parseRect(getFirstText(info));
00994 normalizeRect(area);
00995 }
00996 else if (info.tagName() == "columncount")
00997 {
00998 columncount = getFirstText(info).toInt();
00999 }
01000 else if (info.tagName() == "rowcount")
01001 {
01002 rowcount = getFirstText(info).toInt();
01003 }
01004 else if (info.tagName() == "padding")
01005 {
01006 padding = getFirstText(info).toInt();
01007 }
01008 else if (info.tagName() == "align")
01009 {
01010 align = getFirstText(info);
01011 }
01012 else if (info.tagName() == "cutdown")
01013 {
01014 if (getFirstText(info).lower() == "no")
01015 cutdown = false;
01016 }
01017 else if (info.tagName() == "showchecks")
01018 {
01019 if (getFirstText(info).lower() == "yes")
01020 showChecks = true;
01021 }
01022 else if (info.tagName() == "showselected")
01023 {
01024 if (getFirstText(info).lower() == "yes")
01025 showSelected = true;
01026 }
01027 else if (info.tagName() == "showscrollarrows")
01028 {
01029 if (getFirstText(info).lower() == "yes")
01030 showScrollArrows = true;
01031 }
01032 else if (info.tagName() == "textheight")
01033 {
01034 textheight = getFirstText(info).toInt();
01035 }
01036 else if (info.tagName() == "textposition")
01037 {
01038 textposition = getFirstText(info);
01039 }
01040 else if (info.tagName() == "multiline")
01041 {
01042 if (getFirstText(info).lower() == "yes")
01043 multiline = true;
01044 }
01045 else if (info.tagName() == "image")
01046 {
01047 QString imgname = "";
01048 QString file = "";
01049
01050 imgname = info.attribute("function", "");
01051 if (imgname.isNull() || imgname.isEmpty())
01052 {
01053 cerr << "Image in a image grid needs a function\n";
01054 return;
01055 }
01056
01057 file = info.attribute("filename", "");
01058 if (file.isNull() || file.isEmpty())
01059 {
01060 cerr << "Image in a image grid needs a filename\n";
01061 return;
01062 }
01063
01064 if (imgname.lower() == "normal")
01065 {
01066 normalImage = file;
01067 }
01068
01069 if (imgname.lower() == "selected")
01070 {
01071 selectedImage = file;
01072 }
01073
01074 if (imgname.lower() == "highlighted")
01075 {
01076 highlightedImage = file;
01077 }
01078
01079 if (imgname.lower() == "default")
01080 {
01081 defaultImage = file;
01082 }
01083
01084 }
01085 else
01086 {
01087 cerr << "Unknown: " << info.tagName() << " in bar\n";
01088 return;
01089 }
01090 }
01091 }
01092 fontProp *font1 = GetFont(activeFont);
01093 if (!font1)
01094 {
01095 cerr << "Unknown font: " << activeFont << " in image grid: " << name << endl;
01096 return;
01097 }
01098
01099 fontProp *font2 = GetFont(selectedFont);
01100 if (!font2)
01101 {
01102 cerr << "Unknown font: " << selectedFont << " in image grid: " << name << endl;
01103 return;
01104 }
01105
01106 fontProp *font3 = GetFont(inactiveFont);
01107 if (!font2)
01108 {
01109 cerr << "Unknown font: " << inactiveFont << " in image grid: " << name << endl;
01110 return;
01111 }
01112
01113 UIImageGridType *grid = new UIImageGridType(name, order.toInt());
01114 grid->SetScreen(wmult, hmult);
01115 grid->setActiveFont(font1);
01116 grid->setSelectedFont(font2);
01117 grid->setInactiveFont(font3);
01118 grid->setCutDown(cutdown);
01119 grid->setShowChecks(showChecks);
01120 grid->setShowSelected(showSelected);
01121 grid->setShowScrollArrows(showScrollArrows);
01122 grid->setArea(area);
01123 grid->setTextHeight(textheight);
01124 grid->setPadding(padding);
01125 grid->setRowCount(rowcount);
01126 grid->setColumnCount(columncount);
01127 grid->setDefaultImage(defaultImage);
01128 grid->setNormalImage(normalImage);
01129 grid->setSelectedImage(selectedImage);
01130 grid->setHighlightedImage(highlightedImage);
01131
01132 int jst = Qt::AlignLeft | Qt::AlignTop;
01133 if (multiline == true)
01134 jst = Qt::WordBreak;
01135
01136 if (!align.isNull() && !align.isEmpty())
01137 {
01138 if (align.lower() == "center")
01139 grid->setJustification(Qt::AlignCenter | jst);
01140 else if (align.lower() == "right")
01141 grid->setJustification(Qt::AlignRight | jst);
01142 else if (align.lower() == "allcenter")
01143 grid->setJustification(Qt::AlignHCenter | Qt::AlignVCenter | jst);
01144 else if (align.lower() == "vcenter")
01145 grid->setJustification(Qt::AlignVCenter | jst);
01146 else if (align.lower() == "hcenter")
01147 grid->setJustification(Qt::AlignHCenter | jst);
01148 }
01149 else
01150 grid->setJustification(jst);
01151
01152 align = "";
01153
01154 if (textposition == "top")
01155 grid->setTextPosition(UIImageGridType::textPosTop);
01156 else
01157 grid->setTextPosition(UIImageGridType::textPosBottom);
01158
01159 if (context != -1)
01160 {
01161 grid->SetContext(context);
01162 }
01163 container->AddType(grid);
01164 grid->calculateScreenArea();
01165 grid->recalculateLayout();
01166 }
01167
01168 void XMLParse::parseBar(LayerSet *container, QDomElement &element)
01169 {
01170 int context = -1;
01171 QString align = "";
01172 QString orientation = "horizontal";
01173 QString filename = "";
01174 QString font = "";
01175 QPoint textoff = QPoint(0, 0);
01176 QPoint iconoff = QPoint(0, 0);
01177 QPoint iconsize = QPoint(0, 0);
01178 QRect area;
01179
01180 QString name = element.attribute("name", "");
01181 if (name.isNull() || name.isEmpty())
01182 {
01183 cerr << "Bar needs a name\n";
01184 return;
01185 }
01186
01187 QString order = element.attribute("draworder", "");
01188 if (order.isNull() || order.isEmpty())
01189 {
01190 cerr << "Bar needs an order\n";
01191 return;
01192 }
01193
01194 for (QDomNode child = element.firstChild(); !child.isNull();
01195 child = child.nextSibling())
01196 {
01197 QDomElement info = child.toElement();
01198 if (!info.isNull())
01199 {
01200 if (info.tagName() == "context")
01201 {
01202 context = getFirstText(info).toInt();
01203 }
01204 else if (info.tagName() == "orientation")
01205 {
01206 orientation = getFirstText(info);
01207 }
01208 else if (info.tagName() == "area")
01209 {
01210 area = parseRect(getFirstText(info));
01211 normalizeRect(area);
01212 }
01213 else if (info.tagName() == "imagefile")
01214 {
01215 filename = getFirstText(info);
01216 }
01217 else if (info.tagName() == "font")
01218 {
01219 font = getFirstText(info);
01220 }
01221 else if (info.tagName() == "align")
01222 {
01223 align = getFirstText(info);
01224 }
01225 else if (info.tagName() == "textoffset")
01226 {
01227 textoff = parsePoint(getFirstText(info));
01228 textoff.setX((int)(textoff.x() * wmult));
01229 textoff.setY((int)(textoff.y() * hmult));
01230 }
01231 else if (info.tagName() == "iconoffset")
01232 {
01233 iconoff = parsePoint(getFirstText(info));
01234 iconoff.setX((int)(iconoff.x() * wmult));
01235 iconoff.setY((int)(iconoff.y() * hmult));
01236 }
01237 else if (info.tagName() == "iconsize")
01238 {
01239 iconsize = parsePoint(getFirstText(info));
01240 iconsize.setX((int)(iconsize.x() * wmult));
01241 iconsize.setY((int)(iconsize.y() * hmult));
01242 }
01243 else
01244 {
01245 cerr << "Unknown: " << info.tagName() << " in bar\n";
01246 return;
01247 }
01248 }
01249 }
01250 fontProp *testfont = GetFont(font);
01251 if (!testfont)
01252 {
01253 cerr << "Unknown font: " << font << " in bar: " << name << endl;
01254 return;
01255 }
01256
01257 UIBarType *bar = new UIBarType(name, filename, order.toInt(), area);
01258 bar->SetScreen(wmult, hmult);
01259 bar->SetFont(testfont);
01260 bar->SetTextOffset(textoff);
01261 bar->SetIconOffset(iconoff);
01262 bar->SetIconSize(iconsize);
01263 if (orientation == "horizontal")
01264 bar->SetOrientation(1);
01265 else if (orientation == "vertical")
01266 bar->SetOrientation(2);
01267
01268 if (!align.isNull() && !align.isEmpty())
01269 {
01270 if (align.lower() == "center")
01271 bar->SetJustification(Qt::AlignCenter);
01272 else if (align.lower() == "right")
01273 bar->SetJustification(Qt::AlignRight);
01274 else if (align.lower() == "left")
01275 bar->SetJustification(Qt::AlignLeft);
01276 else if (align.lower() == "allcenter")
01277 bar->SetJustification(Qt::AlignHCenter | Qt::AlignVCenter);
01278 else if (align.lower() == "vcenter")
01279 bar->SetJustification(Qt::AlignVCenter);
01280 else if (align.lower() == "hcenter")
01281 bar->SetJustification(Qt::AlignHCenter);
01282
01283 }
01284 align = "";
01285
01286 if (context != -1)
01287 {
01288 bar->SetContext(context);
01289 }
01290 container->AddType(bar);
01291 }
01292
01293
01294
01295 fontProp *XMLParse::GetFont(const QString &text, bool checkGlobal)
01296 {
01297 fontProp *ret;
01298 if (fontMap.contains(text))
01299 ret = &fontMap[text];
01300 else if (checkGlobal && globalFontMap.contains(text))
01301 ret = &globalFontMap[text];
01302 else
01303 ret = NULL;
01304 return ret;
01305 }
01306
01307 void XMLParse::normalizeRect(QRect &rect)
01308 {
01309 rect.setWidth((int)(rect.width() * wmult));
01310 rect.setHeight((int)(rect.height() * hmult));
01311 rect.moveTopLeft(QPoint((int)(rect.x() * wmult),
01312 (int)(rect.y() * hmult)));
01313 rect = rect.normalize();
01314 }
01315
01316 QPoint XMLParse::parsePoint(QString text)
01317 {
01318 int x, y;
01319 QPoint retval(0, 0);
01320 if (sscanf(text.data(), "%d,%d", &x, &y) == 2)
01321 retval = QPoint(x, y);
01322 return retval;
01323 }
01324
01325 QRect XMLParse::parseRect(QString text)
01326 {
01327 int x, y, w, h;
01328 QRect retval(0, 0, 0, 0);
01329 if (sscanf(text.data(), "%d,%d,%d,%d", &x, &y, &w, &h) == 4)
01330 retval = QRect(x, y, w, h);
01331
01332 return retval;
01333 }
01334
01335
01336 void XMLParse::parseContainer(QDomElement &element, QString &newname, int &context, QRect &area)
01337 {
01338 context = -1;
01339 QString debug = "";
01340 QString name = element.attribute("name", "");
01341 if (name.isNull() || name.isEmpty())
01342 {
01343 cerr << "Container needs a name\n";
01344 return;
01345 }
01346
01347 LayerSet *container = GetSet(name);
01348 if (container)
01349 {
01350 cerr << "Container: " << name << " already exists\n";
01351 return;
01352 }
01353 newname = name;
01354
01355 container = new LayerSet(name);
01356
01357 layerMap[name] = container;
01358
01359 bool ok = true;
01360 for (QDomNode child = element.firstChild(); !child.isNull();
01361 child = child.nextSibling())
01362 {
01363 QDomElement info = child.toElement();
01364 if (!info.isNull())
01365 {
01366 if (info.tagName() == "debug")
01367 {
01368 debug = getFirstText(info);
01369 if (debug.lower() == "yes")
01370 container->SetDebug(true);
01371 }
01372 else if (info.tagName() == "context")
01373 {
01374 context = getFirstText(info).toInt();
01375 }
01376 else if (info.tagName() == "image")
01377 {
01378 parseImage(container, info);
01379 }
01380 else if (info.tagName() == "animatedimage")
01381 {
01382 if (!parseAnimatedImage(container, info))
01383 ok = false;
01384 }
01385 else if (info.tagName() == "repeatedimage")
01386 {
01387 parseRepeatedImage(container, info);
01388 }
01389 else if (info.tagName() == "listarea")
01390 {
01391 parseListArea(container, info);
01392 }
01393 else if (info.tagName() == "listbtnarea")
01394 {
01395 parseListBtnArea(container, info);
01396 }
01397 else if (info.tagName() == "listtreearea")
01398 {
01399 parseListTreeArea(container, info);
01400 }
01401 else if (info.tagName() == "textarea")
01402 {
01403 parseTextArea(container, info);
01404 }
01405 else if (info.tagName() == "richtextarea")
01406 {
01407 parseRichTextArea(container, info);
01408 }
01409 else if (info.tagName() == "multitextarea")
01410 {
01411 parseMultiTextArea(container, info);
01412 }
01413 else if (info.tagName() == "remoteedit")
01414 {
01415 parseRemoteEdit(container, info);
01416 }
01417 else if (info.tagName() == "statusbar")
01418 {
01419 parseStatusBar(container, info);
01420 }
01421 else if (info.tagName() == "managedtreelist")
01422 {
01423 parseManagedTreeList(container, info);
01424 }
01425 else if (info.tagName() == "pushbutton")
01426 {
01427 parsePushButton(container, info);
01428 }
01429 else if (info.tagName() == "textbutton")
01430 {
01431 parseTextButton(container, info);
01432 }
01433 else if (info.tagName() == "checkbox")
01434 {
01435 parseCheckBox(container, info);
01436 }
01437 else if (info.tagName() == "selector")
01438 {
01439 parseSelector(container, info);
01440 }
01441 else if (info.tagName() == "blackhole")
01442 {
01443 parseBlackHole(container, info);
01444 }
01445 else if (info.tagName() == "area")
01446 {
01447 area = parseRect(getFirstText(info));
01448 normalizeRect(area);
01449 container->SetAreaRect(area);
01450 }
01451 else if (info.tagName() == "bar")
01452 {
01453 parseBar(container, info);
01454 }
01455 else if (info.tagName() == "keyboard")
01456 {
01457 parseKeyboard(container, info);
01458 }
01459 else if (info.tagName() == "guidegrid")
01460 {
01461 parseGuideGrid(container, info);
01462 }
01463 else if (info.tagName() == "imagegrid")
01464 {
01465 parseImageGrid(container, info);
01466 }
01467 else
01468 {
01469 VERBOSE(VB_IMPORTANT,
01470 QString("Container %1 contains unknown child: %2")
01471 .arg(name).arg(info.tagName()));
01472 ok = false;
01473 }
01474 }
01475 }
01476 if (!ok)
01477 {
01478 VERBOSE(VB_IMPORTANT, QString("Could not parse container '%1'. "
01479 "Ignoring.").arg(name));
01480 return;
01481 }
01482
01483 if (context != -1)
01484 container->SetContext(context);
01485
01486
01487 allTypes->push_back(container);
01488 }
01489
01490 void XMLParse::parseTextArea(LayerSet *container, QDomElement &element)
01491 {
01492 int context = -1;
01493 QRect area = QRect(0, 0, 0, 0);
01494 QRect altArea = QRect(0, 0, 0, 0);
01495 QPoint shadowOffset = QPoint(0, 0);
01496 QString font = "";
01497 QString cutdown = "";
01498 QString value = "";
01499 QString statictext = "";
01500 QString multiline = "";
01501 int draworder = 0;
01502
01503 QString name = element.attribute("name", "");
01504 if (name.isNull() || name.isEmpty())
01505 {
01506 cerr << "Text area needs a name\n";
01507 return;
01508 }
01509
01510 QString layerNum = element.attribute("draworder", "");
01511 if (layerNum.isNull() && layerNum.isEmpty())
01512 {
01513 cerr << "Text area needs a draworder\n";
01514 return;
01515 }
01516 draworder = layerNum.toInt();
01517
01518 for (QDomNode child = element.firstChild(); !child.isNull();
01519 child = child.nextSibling())
01520 {
01521 QDomElement info = child.toElement();
01522 if (!info.isNull())
01523 {
01524 if (info.tagName() == "context")
01525 {
01526 context = getFirstText(info).toInt();
01527 }
01528 else if (info.tagName() == "area")
01529 {
01530 area = parseRect(getFirstText(info));
01531 normalizeRect(area);
01532 }
01533 else if (info.tagName() == "altarea")
01534 {
01535 altArea = parseRect(getFirstText(info));
01536 normalizeRect(altArea);
01537 }
01538 else if (info.tagName() == "font")
01539 {
01540 font = getFirstText(info);
01541 }
01542 else if (info.tagName() == "value")
01543 {
01544 if ((value.isNull() || value.isEmpty()) &&
01545 info.attribute("lang","") == "")
01546 {
01547 value = qApp->translate("ThemeUI", getFirstText(info));
01548 }
01549 else if (info.attribute("lang","").lower() ==
01550 gContext->GetLanguageAndVariant())
01551 {
01552 value = getFirstText(info);
01553 }
01554 else if (info.attribute("lang","").lower() ==
01555 gContext->GetLanguage())
01556 {
01557 value = getFirstText(info);
01558 }
01559 }
01560 else if (info.tagName() == "cutdown")
01561 {
01562 cutdown = getFirstText(info);
01563 }
01564 else if (info.tagName() == "multiline")
01565 {
01566 multiline = getFirstText(info);
01567 }
01568 else if (info.tagName() == "shadow")
01569 {
01570 shadowOffset = parsePoint(getFirstText(info));
01571 shadowOffset.setX((int)(shadowOffset.x() * wmult));
01572 shadowOffset.setY((int)(shadowOffset.y() * hmult));
01573 }
01574 else
01575 {
01576 cerr << "Unknown tag in textarea: " << info.tagName() << endl;
01577 return;
01578 }
01579 }
01580 }
01581
01582 fontProp *testfont = GetFont(font);
01583 if (!testfont)
01584 {
01585 cerr << "Unknown font: " << font << " in textarea: " << name << endl;
01586 return;
01587 }
01588
01589 UITextType *text = new UITextType(name, testfont, value, draworder, area,
01590 altArea);
01591 text->SetScreen(wmult, hmult);
01592 if (context != -1)
01593 {
01594 text->SetContext(context);
01595 }
01596 if (multiline.lower() == "yes")
01597 text->SetJustification(Qt::WordBreak);
01598 if (!value.isNull() && !value.isEmpty())
01599 text->SetText(value);
01600 if (cutdown.lower() == "no")
01601 text->SetCutDown(false);
01602
01603 QString align = element.attribute("align", "");
01604 if (!align.isNull() && !align.isEmpty())
01605 {
01606 int jst = (Qt::AlignTop | Qt::AlignLeft);
01607 if (multiline.lower() == "yes")
01608 {
01609 jst = Qt::WordBreak;
01610 }
01611 if (align.lower() == "center")
01612 text->SetJustification(jst | Qt::AlignCenter);
01613 else if (align.lower() == "right")
01614 text->SetJustification(jst | Qt::AlignRight);
01615 else if (align.lower() == "left")
01616 text->SetJustification(jst | Qt::AlignLeft);
01617 else if (align.lower() == "allcenter")
01618 text->SetJustification(jst | Qt::AlignHCenter | Qt::AlignVCenter);
01619 else if (align.lower() == "vcenter")
01620 text->SetJustification(jst | Qt::AlignVCenter);
01621 else if (align.lower() == "hcenter")
01622 text->SetJustification(jst | Qt::AlignHCenter);
01623 }
01624 align = "";
01625 text->SetParent(container);
01626 text->calculateScreenArea();
01627 container->AddType(text);
01628 }
01629
01630 void XMLParse::parseRichTextArea(LayerSet *container, QDomElement &element)
01631 {
01632 int context = -1;
01633 QRect area = QRect(0, 0, 0, 0);
01634 QRect textArea = QRect(0, 0, 0, 0);
01635 QString font = "";
01636 QString value = "";
01637 QString bgImageReg = "", bgImageSel = "";
01638 int draworder = 0;
01639
01640 bool bShowArrows = true;
01641
01642 QPoint upArrowSelPos = QPoint(0,0);
01643 QPoint dnArrowSelPos = QPoint(0,0);
01644 QPoint upArrowRegPos = QPoint(0,0);
01645 QPoint dnArrowRegPos = QPoint(0,0);
01646
01647 QPixmap *upArrowSel = NULL;
01648 QPixmap *dnArrowSel = NULL;
01649 QPixmap *upArrowReg = NULL;
01650 QPixmap *dnArrowReg = NULL;
01651
01652 QString name = element.attribute("name", "");
01653 if (name.isNull() || name.isEmpty())
01654 {
01655 cerr << "Rich Text area needs a name\n";
01656 return;
01657 }
01658
01659 QString layerNum = element.attribute("draworder", "");
01660 if (layerNum.isNull() && layerNum.isEmpty())
01661 {
01662 cerr << "Rich Text area needs a draworder\n";
01663 return;
01664 }
01665 draworder = layerNum.toInt();
01666
01667 for (QDomNode child = element.firstChild(); !child.isNull();
01668 child = child.nextSibling())
01669 {
01670 QDomElement info = child.toElement();
01671 if (!info.isNull())
01672 {
01673 if (info.tagName() == "context")
01674 {
01675 context = getFirstText(info).toInt();
01676 }
01677 else if (info.tagName() == "area")
01678 {
01679 area = parseRect(getFirstText(info));
01680 normalizeRect(area);
01681 }
01682 else if (info.tagName() == "textarea")
01683 {
01684 textArea = parseRect(getFirstText(info));
01685 normalizeRect(textArea);
01686 }
01687 else if (info.tagName() == "font")
01688 {
01689 font = getFirstText(info);
01690 }
01691 else if (info.tagName() == "showscrollarrows")
01692 {
01693 if (getFirstText(info).lower() == "no")
01694 bShowArrows = false;
01695 }
01696 else if (info.tagName() == "backgroundsel")
01697 {
01698 bgImageSel = getFirstText(info);
01699 }
01700 else if (info.tagName() == "backgroundreg")
01701 {
01702 bgImageReg = getFirstText(info);
01703 }
01704 else if (info.tagName() == "value")
01705 {
01706 if ((value.isNull() || value.isEmpty()) &&
01707 info.attribute("lang","") == "")
01708 {
01709 value = qApp->translate("ThemeUI", getFirstText(info));
01710 }
01711 else if (info.attribute("lang","").lower() ==
01712 gContext->GetLanguageAndVariant())
01713 {
01714 value = getFirstText(info);
01715 }
01716 else if (info.attribute("lang","").lower() ==
01717 gContext->GetLanguage())
01718 {
01719 value = getFirstText(info);
01720 }
01721 }
01722 else if (info.tagName() == "image")
01723 {
01724 QString imgname = "";
01725 QString imgpoint = "";
01726 QString imgfile = "";
01727
01728 imgname = info.attribute("function", "");
01729 if (imgname.isNull() || imgname.isEmpty())
01730 {
01731 cerr << "Image needs a function\n";
01732 return;
01733 }
01734
01735 imgfile = info.attribute("filename", "");
01736 if (imgfile.isNull() || imgfile.isEmpty())
01737 {
01738 cerr << "Image needs a filename\n";
01739 return;
01740 }
01741
01742 imgpoint = info.attribute("location", "");
01743 if (imgpoint.isNull() && imgpoint.isEmpty())
01744 {
01745 cerr << "Image needs a location\n";
01746 return;
01747 }
01748
01749 if (imgname.lower() == "uparrow-reg")
01750 {
01751 upArrowReg = gContext->LoadScalePixmap(imgfile);
01752 upArrowRegPos = parsePoint(imgpoint);
01753 upArrowRegPos.setX((int)(upArrowRegPos.x() * wmult));
01754 upArrowRegPos.setY((int)(upArrowRegPos.y() * hmult));
01755 }
01756 if (imgname.lower() == "downarrow-reg")
01757 {
01758 dnArrowReg = gContext->LoadScalePixmap(imgfile);
01759 dnArrowRegPos = parsePoint(imgpoint);
01760 dnArrowRegPos.setX((int)(dnArrowRegPos.x() * wmult));
01761 dnArrowRegPos.setY((int)(dnArrowRegPos.y() * hmult));
01762 }
01763 if (imgname.lower() == "uparrow-sel")
01764 {
01765 upArrowSel = gContext->LoadScalePixmap(imgfile);
01766 upArrowSelPos = parsePoint(imgpoint);
01767 upArrowSelPos.setX((int)(upArrowSelPos.x() * wmult));
01768 upArrowSelPos.setY((int)(upArrowSelPos.y() * hmult));
01769 }
01770 if (imgname.lower() == "downarrow-sel")
01771 {
01772 dnArrowSel = gContext->LoadScalePixmap(imgfile);
01773 dnArrowSelPos = parsePoint(imgpoint);
01774 dnArrowSelPos.setX((int)(dnArrowSelPos.x() * wmult));
01775 dnArrowSelPos.setY((int)(dnArrowSelPos.y() * hmult));
01776 }
01777 }
01778 else
01779 {
01780 cerr << "Unknown tag in richtextarea: " << info.tagName() << endl;
01781 return;
01782 }
01783 }
01784 }
01785
01786 fontProp *testfont = GetFont(font);
01787 if (!testfont)
01788 {
01789 cerr << "Unknown font: " << font << " in richtextarea: " << name << endl;
01790 return;
01791 }
01792
01793 UIRichTextType *text = new UIRichTextType(name, testfont, value, draworder,
01794 area, textArea);
01795 text->SetScreen(wmult, hmult);
01796 if (context != -1)
01797 {
01798 text->SetContext(context);
01799 }
01800 if (!value.isNull() && !value.isEmpty())
01801 text->SetText(value);
01802
01803 if (upArrowReg)
01804 {
01805 text->SetImageUpArrowReg(*upArrowReg, upArrowRegPos);
01806 delete upArrowReg;
01807 }
01808 if (upArrowSel)
01809 {
01810 text->SetImageUpArrowSel(*upArrowSel, upArrowSelPos);
01811 delete upArrowSel;
01812 }
01813 if (dnArrowReg)
01814 {
01815 text->SetImageDnArrowReg(*dnArrowReg, dnArrowRegPos);
01816 delete dnArrowReg;
01817 }
01818 if (dnArrowSel)
01819 {
01820 text->SetImageDnArrowSel(*dnArrowSel, dnArrowSelPos);
01821 delete dnArrowSel;
01822 }
01823
01824 text->SetShowScrollArrows(bShowArrows);
01825 text->SetBackgroundImages(bgImageReg, bgImageSel);
01826 text->SetParent(container);
01827 text->calculateScreenArea();
01828 container->AddType(text);
01829 }
01830
01831 void XMLParse::parseMultiTextArea(LayerSet *container, QDomElement &element)
01832 {
01833 int context = -1;
01834 QRect area = QRect(0, 0, 0, 0);
01835 QRect altArea = QRect(0, 0, 0, 0);
01836 QPoint shadowOffset = QPoint(0, 0);
01837 QString font = "";
01838 QString cutdown = "";
01839 QString value = "";
01840 QString statictext = "";
01841 QString multiline = "";
01842 int padding = -1;
01843 int drop_delay = -1;
01844 int drop_pause = -1;
01845 int scroll_delay = -1;
01846 int scroll_pause = -1;
01847 int draworder = 0;
01848
01849 QString name = element.attribute("name", "");
01850 if (name.isNull() || name.isEmpty())
01851 {
01852 cerr << "Multitext area needs a name\n";
01853 return;
01854 }
01855
01856 QString layerNum = element.attribute("draworder", "");
01857 if (layerNum.isNull() && layerNum.isEmpty())
01858 {
01859 cerr << "Multitext area needs a draworder\n";
01860 return;
01861 }
01862 draworder = layerNum.toInt();
01863
01864 for (QDomNode child = element.firstChild(); !child.isNull();
01865 child = child.nextSibling())
01866 {
01867 QDomElement info = child.toElement();
01868 if (!info.isNull())
01869 {
01870 if (info.tagName() == "context")
01871 {
01872 context = getFirstText(info).toInt();
01873 }
01874 else if (info.tagName() == "padding")
01875 {
01876 padding = getFirstText(info).toInt();
01877 }
01878 else if (info.tagName() == "dropdelay")
01879 {
01880 drop_delay = getFirstText(info).toInt();
01881 }
01882 else if (info.tagName() == "droppause")
01883 {
01884 drop_pause = getFirstText(info).toInt();
01885 }
01886 else if (info.tagName() == "scrolldelay")
01887 {
01888 scroll_delay = getFirstText(info).toInt();
01889 }
01890 else if (info.tagName() == "scrollpause")
01891 {
01892 scroll_pause = getFirstText(info).toInt();
01893 }
01894 else if (info.tagName() == "area")
01895 {
01896 area = parseRect(getFirstText(info));
01897 normalizeRect(area);
01898 }
01899 else if (info.tagName() == "altarea")
01900 {
01901 altArea = parseRect(getFirstText(info));
01902 normalizeRect(altArea);
01903 }
01904 else if (info.tagName() == "font")
01905 {
01906 font = getFirstText(info);
01907 }
01908 else if (info.tagName() == "cutdown")
01909 {
01910 cutdown = getFirstText(info);
01911 }
01912 else if (info.tagName() == "shadow")
01913 {
01914 shadowOffset = parsePoint(getFirstText(info));
01915 shadowOffset.setX((int)(shadowOffset.x() * wmult));
01916 shadowOffset.setY((int)(shadowOffset.y() * hmult));
01917 }
01918 else
01919 {
01920 cerr << "Unknown tag in multitext area: "
01921 << info.tagName()
01922 << endl;
01923 return;
01924 }
01925 }
01926 }
01927
01928 fontProp *testfont = GetFont(font);
01929 if (!testfont)
01930 {
01931 cerr << "Unknown font: " << font << " in multitextarea: " << name << endl;
01932 return;
01933 }
01934
01935 UIMultiTextType *multitext = new UIMultiTextType(name, testfont, draworder,
01936 area, altArea);
01937 multitext->SetScreen(wmult, hmult);
01938 if (context != -1)
01939 {
01940 multitext->SetContext(context);
01941 }
01942
01943 if (padding > -1)
01944 {
01945 multitext->setMessageSpacePadding(padding);
01946 }
01947 if (drop_delay > -1)
01948 {
01949 multitext->setDropTimingLength(drop_delay);
01950 }
01951 if (drop_pause > -1)
01952 {
01953 multitext->setDropTimingPause(drop_pause);
01954 }
01955 if (scroll_delay > -1)
01956 {
01957 multitext->setScrollTimingLength(scroll_delay);
01958 }
01959 if (scroll_pause > -1)
01960 {
01961 multitext->setScrollTimingPause(scroll_pause);
01962 }
01963
01964 multitext->SetParent(container);
01965 multitext->calculateScreenArea();
01966 container->AddType(multitext);
01967 }
01968
01969 void XMLParse::parseRemoteEdit(LayerSet *container, QDomElement &element)
01970 {
01971 int context = -1;
01972 QRect area = QRect(0, 0, 0, 0);
01973 QString font = "";
01974 QString value = "";
01975 int draworder = 0;
01976 QColor selectedColor = QColor(0, 255, 255);
01977 QColor unselectedColor = QColor(100, 100, 100);
01978 QColor specialColor = QColor(255, 0, 0);
01979
01980 QString name = element.attribute("name", "");
01981 if (name.isNull() || name.isEmpty())
01982 {
01983 cerr << "RemoteEdit needs a name\n";
01984 return;
01985 }
01986
01987 QString layerNum = element.attribute("draworder", "");
01988 if (layerNum.isNull() && layerNum.isEmpty())
01989 {
01990 cerr << "RemoteEdit needs a draworder\n";
01991 return;
01992 }
01993 draworder = layerNum.toInt();
01994
01995 for (QDomNode child = element.firstChild(); !child.isNull();
01996 child = child.nextSibling())
01997 {
01998 QDomElement info = child.toElement();
01999 if (!info.isNull())
02000 {
02001 if (info.tagName() == "context")
02002 {
02003 context = getFirstText(info).toInt();
02004 }
02005 else if (info.tagName() == "area")
02006 {
02007 area = parseRect(getFirstText(info));
02008 normalizeRect(area);
02009 }
02010 else if (info.tagName() == "font")
02011 {
02012 font = getFirstText(info);
02013 }
02014 else if (info.tagName() == "value")
02015 {
02016 if ((value.isNull() || value.isEmpty()) &&
02017 info.attribute("lang","") == "")
02018 {
02019 value = qApp->translate("ThemeUI", getFirstText(info));
02020 }
02021 else if (info.attribute("lang","").lower() ==
02022 gContext->GetLanguageAndVariant())
02023 {
02024 value = getFirstText(info);
02025 }
02026 else if (info.attribute("lang","").lower() ==
02027 gContext->GetLanguage())
02028 {
02029 value = getFirstText(info);
02030 }
02031 }
02032 else if (info.tagName() == "charcolors")
02033 {
02034 QString selected = "";
02035 QString unselected = "";
02036 QString special = "";
02037 selected = info.attribute("selected");
02038 unselected = info.attribute("unselected");
02039 special = info.attribute("special");
02040
02041 if (selected != "")
02042 selectedColor = QColor(selected);
02043
02044 if (unselected != "")
02045 unselectedColor = QColor(unselected);
02046
02047 if (special != "")
02048 specialColor = QColor(special);
02049 }
02050
02051 else
02052 {
02053 cerr << "Unknown tag in RemoteEdit: " << info.tagName() << endl;
02054 return;
02055 }
02056 }
02057 }
02058
02059 fontProp *testfont = GetFont(font);
02060 if (!testfont)
02061 {
02062 cerr << "Unknown font: " << font << " in RemoteEdit: " << name << endl;
02063 return;
02064 }
02065
02066 UIRemoteEditType *edit = new UIRemoteEditType(name, testfont, value, draworder, area);
02067 edit->SetScreen(wmult, hmult);
02068 if (context != -1)
02069 {
02070 edit->SetContext(context);
02071 }
02072 if (!value.isNull() && !value.isEmpty())
02073 edit->setText(value);
02074
02075 edit->SetParent(container);
02076 edit->setCharacterColors(unselectedColor, selectedColor, specialColor);
02077 edit->calculateScreenArea();
02078 container->AddType(edit);
02079 }
02080
02081 void XMLParse::parseListArea(LayerSet *container, QDomElement &element)
02082 {
02083 int context = -1;
02084 int item_cnt = 0;
02085 QRect area = QRect(0, 0, 0, 0);
02086 QString force_color = "";
02087 QString act_font = "", in_font = "";
02088 QString statictext = "";
02089 int padding = 0;
02090 int draworder = 0;
02091 QMap<int, int> columnWidths;
02092 QMap<int, int> columnContexts;
02093 QMap<QString, QString> fontFunctions;
02094 QMap<QString, fontProp> theFonts;
02095 int colCnt = -1;
02096
02097 QRect fill_select_area = QRect(0, 0, 0, 0);
02098 QColor fill_select_color = QColor(255, 255, 255);
02099 int fill_type = -1;
02100
02101 QPoint uparrow_loc;
02102 QPoint dnarrow_loc;
02103 QPoint select_loc;
02104 QPoint rightarrow_loc;
02105 QPoint leftarrow_loc;
02106
02107 QPixmap *uparrow_img = NULL;
02108 QPixmap *dnarrow_img = NULL;
02109 QPixmap *select_img = NULL;
02110 QPixmap *right_img = NULL;
02111 QPixmap *left_img = NULL;
02112
02113 QString name = element.attribute("name", "");
02114 if (name.isNull() || name.isEmpty())
02115 {
02116 cerr << "List area needs a name\n";
02117 return;
02118 }
02119
02120 QString layerNum = element.attribute("draworder", "");
02121 if (layerNum.isNull() && layerNum.isEmpty())
02122 {
02123 cerr << "List area needs a draworder\n";
02124 return;
02125 }
02126 draworder = layerNum.toInt();
02127
02128 for (QDomNode child = element.firstChild(); !child.isNull();
02129 child = child.nextSibling())
02130 {
02131 QDomElement info = child.toElement();
02132 if (!info.isNull())
02133 {
02134 if (info.tagName() == "context")
02135 {
02136 context = getFirstText(info).toInt();
02137 }
02138 else if (info.tagName() == "area")
02139 {
02140 area = parseRect(getFirstText(info));
02141 normalizeRect(area);
02142 }
02143 else if (info.tagName() == "activefont")
02144 {
02145 act_font = getFirstText(info);
02146 }
02147 else if (info.tagName() == "inactivefont")
02148 {
02149 in_font = getFirstText(info);
02150 }
02151 else if (info.tagName() == "items")
02152 {
02153 item_cnt = getFirstText(info).toInt();
02154 }
02155 else if (info.tagName() == "columnpadding")
02156 {
02157 padding = getFirstText(info).toInt();
02158 }
02159 else if (info.tagName() == "fcnfont")
02160 {
02161 QString fontname = "";
02162 QString fontfcn = "";
02163
02164 fontname = info.attribute("name", "");
02165 fontfcn = info.attribute("function", "");
02166
02167 if (fontname.isNull() || fontname.isEmpty())
02168 {
02169 cerr << "FcnFont needs a name\n";
02170 return;
02171 }
02172
02173 if (fontfcn.isNull() || fontfcn.isEmpty())
02174 {
02175 cerr << "FcnFont needs a function\n";
02176 return;
02177 }
02178 fontFunctions[fontfcn] = fontname;
02179 }
02180 else if (info.tagName() == "fill")
02181 {
02182 QString fillfcn = "";
02183 QString fillcolor = "";
02184 QString fillarea = "";
02185 QString filltype = "";
02186
02187 fillfcn = info.attribute("function", "");
02188 fillcolor = info.attribute("color", "#ffffff");
02189 fillarea = info.attribute("area", "");
02190 filltype = info.attribute("type", "");
02191
02192 if (fillfcn.isNull() || fillfcn.isEmpty())
02193 {
02194 cerr << "Fill needs a function\n";
02195 return;
02196 }
02197 if (fillcolor.isNull() || fillcolor.isEmpty())
02198 {
02199 cerr << "Fill needs a color\n";
02200 return;
02201 }
02202 if (filltype == "5050")
02203 fill_type = 1;
02204 if (fill_type == -1)
02205 fill_type = 1;
02206
02207 if (fillarea.isNull() || fillarea.isEmpty())
02208 {
02209 fill_select_area = area;
02210 }
02211 else
02212 {
02213 fill_select_area = parseRect(fillarea);
02214 normalizeRect(fill_select_area);
02215 }
02216 fill_select_color = QColor(fillcolor);
02217
02218 }
02219 else if (info.tagName() == "image")
02220 {
02221 QString imgname = "";
02222 QString imgpoint = "";
02223 QString imgfile = "";
02224
02225 imgname = info.attribute("function", "");
02226 if (imgname.isNull() || imgname.isEmpty())
02227 {
02228 cerr << "Image needs a function\n";
02229 return;
02230 }
02231
02232 imgfile = info.attribute("filename", "");
02233 if (imgfile.isNull() || imgfile.isEmpty())
02234 {
02235 cerr << "Image needs a filename\n";
02236 return;
02237 }
02238
02239
02240 imgpoint = info.attribute("location", "");
02241 if (imgpoint.isNull() && imgpoint.isEmpty())
02242 {
02243 cerr << "Image needs a location\n";
02244 return;
02245 }
02246
02247 if (imgname.lower() == "selectionbar")
02248 {
02249 select_img = gContext->LoadScalePixmap(imgfile);
02250 select_loc = parsePoint(imgpoint);
02251 select_loc.setX((int)(select_loc.x() * wmult));
02252 select_loc.setY((int)(select_loc.y() * hmult));
02253 }
02254 if (imgname.lower() == "uparrow")
02255 {
02256 uparrow_img = gContext->LoadScalePixmap(imgfile);
02257 uparrow_loc = parsePoint(imgpoint);
02258 uparrow_loc.setX((int)(uparrow_loc.x() * wmult));
02259 uparrow_loc.setY((int)(uparrow_loc.y() * hmult));
02260 }
02261 if (imgname.lower() == "downarrow")
02262 {
02263 dnarrow_img = gContext->LoadScalePixmap(imgfile);
02264 dnarrow_loc = parsePoint(imgpoint);
02265 dnarrow_loc.setX((int)(dnarrow_loc.x() * wmult));
02266 dnarrow_loc.setY((int)(dnarrow_loc.y() * hmult));
02267 }
02268 if (imgname.lower() == "leftarrow")
02269 {
02270 left_img = gContext->LoadScalePixmap(imgfile);
02271 leftarrow_loc = parsePoint(imgpoint);
02272 leftarrow_loc.setX((int)(leftarrow_loc.x() * wmult));
02273 leftarrow_loc.setY((int)(leftarrow_loc.y() * hmult));
02274
02275 }
02276 else if (imgname.lower() == "rightarrow")
02277 {
02278 right_img = gContext->LoadScalePixmap(imgfile);
02279 rightarrow_loc = parsePoint(imgpoint);
02280 rightarrow_loc.setX((int)(rightarrow_loc.x() * wmult));
02281 rightarrow_loc.setY((int)(rightarrow_loc.y() * hmult));
02282 }
02283 }
02284 else if (info.tagName() == "column")
02285 {
02286 QString colnum = "";
02287 QString colwidth = "";
02288 QString colcontext = "";
02289 colnum = info.attribute("number", "");
02290 if (colnum.isNull() || colnum.isEmpty())
02291 {
02292 cerr << "Column needs a number\n";
02293 return;
02294 }
02295
02296 colwidth = info.attribute("width", "");
02297 if (colwidth.isNull() && colwidth.isEmpty())
02298 {
02299 cerr << "Column needs a width\n";
02300 return;
02301 }
02302
02303 colcontext = info.attribute("context", "");
02304 if (!colcontext.isNull() && !colcontext.isEmpty())
02305 {
02306 columnContexts[colnum.toInt()] = colcontext.toInt();
02307 }
02308 else
02309 columnContexts[colnum.toInt()] = -1;
02310
02311 columnWidths[colnum.toInt()] = (int)(wmult*colwidth.toInt());
02312 if (colnum.toInt() > colCnt)
02313 colCnt = colnum.toInt();
02314 }
02315 else
02316 {
02317 cerr << "Unknown tag in listarea: " << info.tagName() << endl;
02318 return;
02319 }
02320 }
02321 }
02322
02323 UIListType *list = new UIListType(name, area, draworder);
02324 list->SetCount(item_cnt);
02325 list->SetScreen(wmult, hmult);
02326 list->SetColumnPad(padding);
02327 if (select_img)
02328 {
02329 list->SetImageSelection(*select_img, select_loc);
02330 delete select_img;
02331 }
02332
02333 if (uparrow_img)
02334 {
02335 list->SetImageUpArrow(*uparrow_img, uparrow_loc);
02336 delete uparrow_img;
02337 }
02338
02339 if (dnarrow_img)
02340 {
02341 list->SetImageDownArrow(*dnarrow_img, dnarrow_loc);
02342 delete dnarrow_img;
02343 }
02344
02345 if (right_img)
02346 {
02347 list->SetImageRightArrow(*right_img, rightarrow_loc);
02348 delete right_img;
02349 }
02350
02351 if (left_img)
02352 {
02353 list->SetImageLeftArrow(*left_img, leftarrow_loc);
02354 delete left_img;
02355 }
02356
02357 typedef QMap<QString,QString> fontdata;
02358 fontdata::Iterator it;
02359 for ( it = fontFunctions.begin(); it != fontFunctions.end(); ++it )
02360 {
02361 fontProp *testFont = GetFont(it.data());
02362 if (testFont)
02363 theFonts[it.data()] = *testFont;
02364 }
02365 if (theFonts.size() > 0)
02366 list->SetFonts(fontFunctions, theFonts);
02367 if (fill_type != -1)
02368 list->SetFill(fill_select_area, fill_select_color, fill_type);
02369 if (context != -1)
02370 {
02371 list->SetContext(context);
02372 }
02373
02374 for (int i = 0; i <= colCnt; i++)
02375 {
02376 if (columnWidths[i] > 0)
02377 list->SetColumnWidth(i, columnWidths[i]);
02378 if (columnContexts[i] != -1)
02379 list->SetColumnContext(i, columnContexts[i]);
02380 else
02381 list->SetColumnContext(i, context);
02382 }
02383
02384 if (colCnt == -1)
02385 list->SetColumnContext(1, -1);
02386
02387 list->SetParent(container);
02388 list->calculateScreenArea();
02389 container->AddType(list);
02390
02391
02392 container->bumpUpLayers(8);
02393 }
02394
02395 LayerSet *XMLParse::GetSet(const QString &text)
02396 {
02397 LayerSet *ret = NULL;
02398 if (layerMap.contains(text))
02399 ret = layerMap[text];
02400
02401 return ret;
02402 }
02403
02404 void XMLParse::parseStatusBar(LayerSet *container, QDomElement &element)
02405 {
02406 int context = -1;
02407 int orientation = 0;
02408 int imgFillSpace = 0;
02409 QPixmap *imgFiller = NULL;
02410 QPixmap *imgContainer = NULL;
02411
02412 QString name = element.attribute("name", "");
02413 if (name.isNull() || name.isEmpty())
02414 {
02415 cerr << "StatusBar needs a name\n";
02416 return;
02417 }
02418
02419 QString order = element.attribute("draworder", "");
02420 if (order.isNull() || order.isEmpty())
02421 {
02422 cerr << "StatusBar needs an order\n";
02423 return;
02424 }
02425
02426 QPoint pos = QPoint(0, 0);
02427
02428 for (QDomNode child = element.firstChild(); !child.isNull();
02429 child = child.nextSibling())
02430 {
02431 QDomElement info = child.toElement();
02432 if (!info.isNull())
02433 {
02434 if (info.tagName() == "context")
02435 {
02436 context = getFirstText(info).toInt();
02437 }
02438 else if (info.tagName() == "container")
02439 {
02440 QString confile = getFirstText(info);
02441 QString flex = info.attribute("fleximage", "");
02442 if (!flex.isNull() && !flex.isEmpty())
02443 {
02444 if (flex.lower() == "yes")
02445 {
02446 int pathStart = confile.findRev('/');
02447 if (usetrans == 1)
02448 {
02449 if (pathStart < 0 )
02450 confile = "trans-" + confile;
02451 else
02452 confile.replace(pathStart, 1, "/trans-");
02453 }
02454 else
02455 {
02456 if (pathStart < 0 )
02457 confile = "solid-" + confile;
02458 else
02459 confile.replace(pathStart, 1, "/solid-");
02460 }
02461
02462 imgContainer = gContext->LoadScalePixmap(confile);
02463 }
02464 else
02465 imgContainer = gContext->LoadScalePixmap(confile);
02466 }
02467 else
02468 {
02469 imgContainer = gContext->LoadScalePixmap(confile);
02470 }
02471 }
02472 else if (info.tagName() == "position")
02473 {
02474 pos = parsePoint(getFirstText(info));
02475 pos.setX((int)(pos.x() * wmult));
02476 pos.setY((int)(pos.y() * hmult));
02477 }
02478 else if (info.tagName() == "fill")
02479 {
02480 QString fillfile = getFirstText(info);
02481 imgFillSpace = info.attribute("whitespace", "").toInt();
02482
02483 QString flex = info.attribute("fleximage", "");
02484 if (!flex.isNull() && !flex.isEmpty())
02485 {
02486 if (flex.lower() == "yes")
02487 {
02488 if (usetrans == 1)
02489 fillfile = "trans-" + fillfile;
02490 else
02491 fillfile = "solid-" + fillfile;
02492
02493 imgFiller = gContext->LoadScalePixmap(fillfile);
02494 }
02495 else
02496 imgFiller = gContext->LoadScalePixmap(fillfile);
02497 }
02498 else
02499 {
02500 imgFiller = gContext->LoadScalePixmap(fillfile);
02501 }
02502 }
02503 else if (info.tagName() == "orientation")
02504 {
02505 QString orient_string = getFirstText(info).lower();
02506 if (orient_string == "lefttoright")
02507 {
02508 orientation = 0;
02509 }
02510 if (orient_string == "righttoleft")
02511 {
02512 orientation = 1;
02513 }
02514 if (orient_string == "bottomtotop")
02515 {
02516 orientation = 2;
02517 }
02518 if (orient_string == "toptobottom")
02519 {
02520 orientation = 3;
02521 }
02522 }
02523 else
02524 {
02525 cerr << "Unknown: " << info.tagName() << " in statusbar\n";
02526 return;
02527 }
02528 }
02529 }
02530
02531 UIStatusBarType *sb = new UIStatusBarType(name, pos, order.toInt());
02532 sb->SetScreen(wmult, hmult);
02533 sb->SetFiller(imgFillSpace);
02534 if (imgContainer)
02535 {
02536 sb->SetContainerImage(*imgContainer);
02537 delete imgContainer;
02538 }
02539 if (imgFiller)
02540 {
02541 sb->SetFillerImage(*imgFiller);
02542 delete imgFiller;
02543 }
02544 if (context != -1)
02545 {
02546 sb->SetContext(context);
02547 }
02548 sb->SetParent(container);
02549 sb->calculateScreenArea();
02550 sb->setOrientation(orientation);
02551 container->AddType(sb);
02552 container->bumpUpLayers(order.toInt());
02553 }
02554
02555 struct TreeIcon { int i; QPixmap *img;};
02556 void XMLParse::parseManagedTreeList(LayerSet *container, QDomElement &element)
02557 {
02558 QRect area;
02559 QRect binarea;
02560 int bins = 1;
02561 int context = -1;
02562 int selectPadding = 0;
02563 bool selectScale = true;
02564
02565 QPixmap *uparrow_img = NULL;
02566 QPixmap *downarrow_img = NULL;
02567 QPixmap *leftarrow_img = NULL;
02568 QPixmap *rightarrow_img = NULL;
02569 QPixmap *icon_img = NULL;
02570 QPixmap *select_img = NULL;
02571 QPoint selectPoint(0,0);
02572 QPoint upArrowPoint(0,0);
02573 QPoint downArrowPoint(0,0);
02574 QPoint rightArrowPoint(0,0);
02575 QPoint leftArrowPoint(0,0);
02576
02577
02578
02579
02580
02581
02582
02583 typedef QMap<int, QRect> CornerMap;
02584 QPtrList<TreeIcon> iconList;
02585 iconList.setAutoDelete(true);
02586 CornerMap bin_corners;
02587 bin_corners.clear();
02588
02589
02590
02591
02592
02593 QMap<QString, QString> fontFunctions;
02594 QMap<QString, fontProp> theFonts;
02595
02596 QString name = element.attribute("name", "");
02597 if (name.isNull() || name.isEmpty())
02598 {
02599 cerr << "ManagedTreeList needs a name\n";
02600 return;
02601 }
02602
02603 QString order = element.attribute("draworder", "");
02604 if (order.isNull() || order.isEmpty())
02605 {
02606 cerr << "ManagedTreeList needs an order\n";
02607 return;
02608 }
02609
02610 QString bins_string = element.attribute("bins", "");
02611 if (bins_string.toInt() > 0)
02612 {
02613 bins = bins_string.toInt();
02614 }
02615
02616 for (QDomNode child = element.firstChild(); !child.isNull();
02617 child = child.nextSibling())
02618 {
02619 QDomElement info = child.toElement();
02620 if (!info.isNull())
02621 {
02622 if (info.tagName() == "area")
02623 {
02624 area = parseRect(getFirstText(info));
02625 normalizeRect(area);
02626 }
02627 else if (info.tagName() == "image")
02628 {
02629 QString imgname = "";
02630 QString file = "";
02631 int imgnumber = -1;
02632
02633 imgname = info.attribute("function", "");
02634 if (imgname.isNull() || imgname.isEmpty())
02635 {
02636 cerr << "Image needs a function\n";
02637 return;
02638 }
02639
02640 file = info.attribute("filename", "");
02641 if (file.isNull() || file.isEmpty())
02642 {
02643 cerr << "Image needs a filename\n";
02644 return;
02645 }
02646
02647 QString imgNumStr = info.attribute("number", "");
02648 imgnumber = atoi(imgNumStr);
02649
02650 if (info.tagName() == "context")
02651 {
02652 context = getFirstText(info).toInt();
02653 }
02654
02655 if (imgname.lower() == "selectionbar")
02656 {
02657 QString imgpoint = "";
02658 QString imgPad = "";
02659 QString imgScale = "";
02660 imgpoint = info.attribute("location", "");
02661 if (!imgpoint.isNull() && !imgpoint.isEmpty())
02662 {
02663 selectPoint = parsePoint(imgpoint);
02664 selectPoint.setX((int)(selectPoint.x() * wmult));
02665 selectPoint.setY((int)(selectPoint.y() * hmult));
02666 }
02667
02668 imgPad = info.attribute("padding", "");
02669 if (!imgPad.isNull() && !imgPad.isEmpty())
02670 {
02671 selectPadding = (int)(imgPad.toInt() * hmult);
02672 }
02673
02674 imgScale = info.attribute("scale", "");
02675 if (imgScale.lower() == "no")
02676 {
02677 selectScale = false;
02678 }
02679
02680 select_img = gContext->LoadScalePixmap(file);
02681 if (!select_img)
02682 {
02683 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02684 }
02685 }
02686 else if (imgname.lower() == "uparrow")
02687 {
02688 QString imgpoint = "";
02689 imgpoint = info.attribute("location", "");
02690 if (!imgpoint.isNull() && !imgpoint.isEmpty())
02691 {
02692 upArrowPoint = parsePoint(imgpoint);
02693 upArrowPoint.setX((int)(upArrowPoint.x() * wmult));
02694 upArrowPoint.setY((int)(upArrowPoint.y() * hmult));
02695 }
02696
02697 uparrow_img = gContext->LoadScalePixmap(file);
02698 if (!uparrow_img)
02699 {
02700 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02701 }
02702 }
02703 else if (imgname.lower() == "downarrow")
02704 {
02705 QString imgpoint = "";
02706 imgpoint = info.attribute("location", "");
02707 if (!imgpoint.isNull() && !imgpoint.isEmpty())
02708 {
02709 downArrowPoint = parsePoint(imgpoint);
02710 downArrowPoint.setX((int)(downArrowPoint.x() * wmult));
02711 downArrowPoint.setY((int)(downArrowPoint.y() * hmult));
02712 }
02713 downarrow_img = gContext->LoadScalePixmap(file);
02714 if (!downarrow_img)
02715 {
02716 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02717 }
02718 }
02719 else if (imgname.lower() == "leftarrow")
02720 {
02721 QString imgpoint = "";
02722 imgpoint = info.attribute("location", "");
02723 if (!imgpoint.isNull() && !imgpoint.isEmpty())
02724 {
02725 leftArrowPoint = parsePoint(imgpoint);
02726 leftArrowPoint.setX((int)(leftArrowPoint.x() * wmult));
02727 leftArrowPoint.setY((int)(leftArrowPoint.y() * hmult));
02728 }
02729 leftarrow_img = gContext->LoadScalePixmap(file);
02730 if (!leftarrow_img)
02731 {
02732 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02733 }
02734 }
02735 else if (imgname.lower() == "rightarrow")
02736 {
02737 QString imgpoint = "";
02738 imgpoint = info.attribute("location", "");
02739 if (!imgpoint.isNull() && !imgpoint.isEmpty())
02740 {
02741 rightArrowPoint = parsePoint(imgpoint);
02742 rightArrowPoint.setX((int)(rightArrowPoint.x() * wmult));
02743 rightArrowPoint.setY((int)(rightArrowPoint.y() * hmult));
02744 }
02745 rightarrow_img = gContext->LoadScalePixmap(file);
02746 if (!rightarrow_img)
02747 {
02748 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02749 }
02750 }
02751 else if ((imgname.lower() == "icon") && (imgnumber != -1))
02752 {
02753 icon_img = gContext->LoadScalePixmap(file);
02754 if (!icon_img)
02755 {
02756 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02757 }
02758 else
02759 {
02760 TreeIcon *icn = new TreeIcon;
02761 icn->img = icon_img;
02762 icn->i = imgnumber;
02763 iconList.append(icn);
02764 }
02765 }
02766 else
02767 {
02768 cerr << "xmlparse.o: I don't know what to do with an image tag who's function is " << imgname << endl;
02769 }
02770 }
02771 else if (info.tagName() == "bin")
02772 {
02773 QString whichbin_string = info.attribute("number", "");
02774 int whichbin = whichbin_string.toInt();
02775 if (whichbin < 1)
02776 {
02777 cerr << "xmlparse.o: Bad setting for bin number in bin tag" << endl;
02778 return;
02779 }
02780 if (whichbin > bins + 1)
02781 {
02782 cerr << "xmlparse.o: Attempt to set bin with a reference larger than number of bins" << endl;
02783 return;
02784 }
02785 for (QDomNode child = info.firstChild(); !child.isNull();
02786 child = child.nextSibling())
02787 {
02788 QDomElement info = child.toElement();
02789 if (!info.isNull())
02790 {
02791 if (info.tagName() == "area")
02792 {
02793 binarea = parseRect(getFirstText(info));
02794 normalizeRect(binarea);
02795 bin_corners[whichbin] = binarea;
02796 }
02797 else if (info.tagName() == "fcnfont")
02798 {
02799 QString fontname = "";
02800 QString fontfcn = "";
02801
02802 fontname = info.attribute("name", "");
02803 fontfcn = info.attribute("function", "");
02804
02805 if (fontname.isNull() || fontname.isEmpty())
02806 {
02807 cerr << "FcnFont needs a name\n";
02808 return;
02809 }
02810
02811 if (fontfcn.isNull() || fontfcn.isEmpty())
02812 {
02813 cerr << "FcnFont needs a function\n";
02814 return;
02815 }
02816 QString a_string = QString("bin%1-%2").arg(whichbin).arg(fontfcn);
02817 fontFunctions[a_string] = fontname;
02818 }
02819 else
02820 {
02821 cerr << "Unknown tag in bin: " << info.tagName() << endl;
02822 return;
02823 }
02824 }
02825 }
02826 }
02827 else
02828 {
02829 cerr << "Unknown: " << info.tagName() << " in ManagedTreeList\n";
02830 return;
02831 }
02832 }
02833 }
02834
02835
02836 UIManagedTreeListType *mtl = new UIManagedTreeListType(name);
02837 mtl->SetScreen(wmult, hmult);
02838 mtl->setArea(area);
02839 mtl->setBins(bins);
02840 mtl->setBinAreas(bin_corners);
02841 mtl->SetOrder(order.toInt());
02842 mtl->SetParent(container);
02843 mtl->SetContext(context);
02844
02845
02846
02847
02848
02849 typedef QMap<QString,QString> fontdata;
02850 fontdata::Iterator it;
02851 for ( it = fontFunctions.begin(); it != fontFunctions.end(); ++it )
02852 {
02853 fontProp *testFont = GetFont(it.data());
02854 if (testFont)
02855 theFonts[it.data()] = *testFont;
02856 }
02857
02858 if (theFonts.size() > 0)
02859 mtl->setFonts(fontFunctions, theFonts);
02860
02861 if (select_img)
02862 {
02863 mtl->setSelectScale(selectScale);
02864 mtl->setSelectPadding(selectPadding);
02865 mtl->setSelectPoint(selectPoint);
02866 mtl->setHighlightImage(*select_img);
02867 delete select_img;
02868 }
02869
02870 if (!uparrow_img)
02871 uparrow_img = new QPixmap();
02872 if (!downarrow_img)
02873 downarrow_img = new QPixmap();
02874 if (!leftarrow_img)
02875 leftarrow_img = new QPixmap();
02876 if (!rightarrow_img)
02877 rightarrow_img = new QPixmap();
02878
02879 mtl->setUpArrowOffset(upArrowPoint);
02880 mtl->setDownArrowOffset(downArrowPoint);
02881 mtl->setLeftArrowOffset(leftArrowPoint);
02882 mtl->setRightArrowOffset(rightArrowPoint);
02883 mtl->setArrowImages(*uparrow_img, *downarrow_img, *leftarrow_img,
02884 *rightarrow_img);
02885
02886 delete uparrow_img;
02887 delete downarrow_img;
02888 delete leftarrow_img;
02889 delete rightarrow_img;
02890
02891
02892 TreeIcon *icon;
02893 while ((icon=iconList.first()) != 0)
02894 {
02895 mtl->addIcon(icon->i, icon->img);
02896 iconList.remove();
02897 }
02898
02899 mtl->makeHighlights();
02900 mtl->calculateScreenArea();
02901 container->AddType(mtl);
02902 }
02903
02904 void XMLParse::parsePushButton(LayerSet *container, QDomElement &element)
02905 {
02906 int context = -1;
02907 QPoint pos = QPoint(0, 0);
02908 QPixmap *image_on = NULL;
02909 QPixmap *image_off = NULL;
02910 QPixmap *image_pushed = NULL;
02911
02912 QString name = element.attribute("name", "");
02913 if (name.isNull() || name.isEmpty())
02914 {
02915 cerr << "PushButton needs a name\n";
02916 return;
02917 }
02918
02919 QString order = element.attribute("draworder", "");
02920 if (order.isNull() || order.isEmpty())
02921 {
02922 cerr << "PushButton needs an order\n";
02923 return;
02924 }
02925
02926 for (QDomNode child = element.firstChild(); !child.isNull();
02927 child = child.nextSibling())
02928 {
02929 QDomElement info = child.toElement();
02930 if (!info.isNull())
02931 {
02932 if (info.tagName() == "context")
02933 {
02934 context = getFirstText(info).toInt();
02935 }
02936 else if (info.tagName() == "position")
02937 {
02938 pos = parsePoint(getFirstText(info));
02939 pos.setX((int)(pos.x() * wmult));
02940 pos.setY((int)(pos.y() * hmult));
02941 }
02942 else if (info.tagName() == "image")
02943 {
02944 QString imgname = "";
02945 QString file = "";
02946
02947 imgname = info.attribute("function", "");
02948 if (imgname.isNull() || imgname.isEmpty())
02949 {
02950 cerr << "Image in a push button needs a function\n";
02951 return;
02952 }
02953
02954 file = info.attribute("filename", "");
02955 if (file.isNull() || file.isEmpty())
02956 {
02957 cerr << "Image in a push button needs a filename\n";
02958 return;
02959 }
02960
02961 if (imgname.lower() == "on")
02962 {
02963 image_on = gContext->LoadScalePixmap(file);
02964 if (!image_on)
02965 {
02966 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02967 }
02968 }
02969 if (imgname.lower() == "off")
02970 {
02971 image_off = gContext->LoadScalePixmap(file);
02972 if (!image_off)
02973 {
02974 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02975 }
02976 }
02977 if (imgname.lower() == "pushed")
02978 {
02979 image_pushed = gContext->LoadScalePixmap(file);
02980 if (!image_pushed)
02981 {
02982 cerr << "xmparse.o: I can't find a file called " << file << endl ;
02983 }
02984 }
02985 }
02986 else
02987 {
02988 cerr << "Unknown: " << info.tagName() << " in PushButton\n";
02989 return;
02990 }
02991 }
02992 }
02993
02994 if (!image_on)
02995 image_on = new QPixmap();
02996 if (!image_off)
02997 image_off = new QPixmap();
02998 if (!image_pushed)
02999 image_pushed = new QPixmap();
03000
03001 UIPushButtonType *pbt = new UIPushButtonType(name, *image_on, *image_off,
03002 *image_pushed);
03003
03004 delete image_on;
03005 delete image_off;
03006 delete image_pushed;
03007
03008 pbt->SetScreen(wmult, hmult);
03009 pbt->setPosition(pos);
03010 pbt->SetOrder(order.toInt());
03011 if (context != -1)
03012 {
03013 pbt->SetContext(context);
03014 }
03015 pbt->SetParent(container);
03016 pbt->calculateScreenArea();
03017 container->AddType(pbt);
03018 }
03019
03020 void XMLParse::parseTextButton(LayerSet *container, QDomElement &element)
03021 {
03022 int context = -1;
03023 QString font = "";
03024 QPoint pos = QPoint(0, 0);
03025 QPixmap *image_on = NULL;
03026 QPixmap *image_off = NULL;
03027 QPixmap *image_pushed = NULL;
03028
03029 QString name = element.attribute("name", "");
03030 if (name.isNull() || name.isEmpty())
03031 {
03032 cerr << "TextButton needs a name\n";
03033 return;
03034 }
03035
03036 QString order = element.attribute("draworder", "");
03037 if (order.isNull() || order.isEmpty())
03038 {
03039 cerr << "TextButton needs an order\n";
03040 return;
03041 }
03042
03043 for (QDomNode child = element.firstChild(); !child.isNull();
03044 child = child.nextSibling())
03045 {
03046 QDomElement info = child.toElement();
03047 if (!info.isNull())
03048 {
03049 if (info.tagName() == "context")
03050 {
03051 context = getFirstText(info).toInt();
03052 }
03053 else if (info.tagName() == "position")
03054 {
03055 pos = parsePoint(getFirstText(info));
03056 pos.setX((int)(pos.x() * wmult));
03057 pos.setY((int)(pos.y() * hmult));
03058 }
03059 else if (info.tagName() == "font")
03060 {
03061 font = getFirstText(info);
03062 }
03063 else if (info.tagName() == "image")
03064 {
03065 QString imgname = "";
03066 QString file = "";
03067
03068 imgname = info.attribute("function", "");
03069 if (imgname.isNull() || imgname.isEmpty())
03070 {
03071 cerr << "Image in a text button needs a function\n";
03072 return;
03073 }
03074
03075 file = info.attribute("filename", "");
03076 if (file.isNull() || file.isEmpty())
03077 {
03078 cerr << "Image in a text button needs a filename\n";
03079 return;
03080 }
03081
03082 if (imgname.lower() == "on")
03083 {
03084 image_on = gContext->LoadScalePixmap(file);
03085 if (!image_on)
03086 {
03087 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03088 }
03089 }
03090 if (imgname.lower() == "off")
03091 {
03092 image_off = gContext->LoadScalePixmap(file);
03093 if (!image_off)
03094 {
03095 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03096 }
03097 }
03098 if (imgname.lower() == "pushed")
03099 {
03100 image_pushed = gContext->LoadScalePixmap(file);
03101
03102 if (!image_pushed)
03103 {
03104 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03105 }
03106 }
03107 }
03108 else
03109 {
03110 cerr << "Unknown: " << info.tagName() << " in TextButton\n";
03111 return;
03112 }
03113 }
03114 }
03115
03116 fontProp *testfont = GetFont(font);
03117 if (!testfont)
03118 {
03119 cerr << "Unknown font: " << font << " in textbutton: " << name << endl;
03120 return;
03121 }
03122
03123 if (!image_on)
03124 image_on = new QPixmap();
03125 if (!image_off)
03126 image_off = new QPixmap();
03127 if (!image_pushed)
03128 image_pushed = new QPixmap();
03129
03130 UITextButtonType *tbt = new UITextButtonType(name, *image_on, *image_off,
03131 *image_pushed);
03132
03133 delete image_on;
03134 delete image_off;
03135 delete image_pushed;
03136
03137 tbt->SetScreen(wmult, hmult);
03138 tbt->setPosition(pos);
03139 tbt->setFont(testfont);
03140 tbt->SetOrder(order.toInt());
03141 if (context != -1)
03142 {
03143 tbt->SetContext(context);
03144 }
03145 tbt->SetParent(container);
03146 tbt->calculateScreenArea();
03147 container->AddType(tbt);
03148 }
03149
03150 void XMLParse::parseCheckBox(LayerSet *container, QDomElement &element)
03151 {
03152 int context = -1;
03153 QPoint pos = QPoint(0, 0);
03154 QPixmap *image_checked = NULL;
03155 QPixmap *image_unchecked = NULL;
03156 QPixmap *image_checked_high = NULL;
03157 QPixmap *image_unchecked_high = NULL;
03158
03159 QString name = element.attribute("name", "");
03160 if (name.isNull() || name.isEmpty())
03161 {
03162 cerr << "CheckBox needs a name\n";
03163 return;
03164 }
03165
03166 QString order = element.attribute("draworder", "");
03167 if (order.isNull() || order.isEmpty())
03168 {
03169 cerr << "CheckBox needs an order\n";
03170 return;
03171 }
03172
03173 for (QDomNode child = element.firstChild(); !child.isNull();
03174 child = child.nextSibling())
03175 {
03176 QDomElement info = child.toElement();
03177 if (!info.isNull())
03178 {
03179 if (info.tagName() == "context")
03180 {
03181 context = getFirstText(info).toInt();
03182 }
03183 else if (info.tagName() == "position")
03184 {
03185 pos = parsePoint(getFirstText(info));
03186 pos.setX((int)(pos.x() * wmult));
03187 pos.setY((int)(pos.y() * hmult));
03188 }
03189 else if (info.tagName() == "image")
03190 {
03191 QString imgname = "";
03192 QString file = "";
03193
03194 imgname = info.attribute("function", "");
03195 if (imgname.isNull() || imgname.isEmpty())
03196 {
03197 cerr << "Image in a CheckBox needs a function\n";
03198 return;
03199 }
03200
03201 file = info.attribute("filename", "");
03202 if (file.isNull() || file.isEmpty())
03203 {
03204 cerr << "Image in a CheckBox needs a filename\n";
03205 return;
03206 }
03207
03208 if (imgname.lower() == "checked")
03209 {
03210 image_checked = gContext->LoadScalePixmap(file);
03211 if (!image_checked)
03212 {
03213 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03214 }
03215 }
03216 if (imgname.lower() == "unchecked")
03217 {
03218 image_unchecked = gContext->LoadScalePixmap(file);
03219 if (!image_unchecked)
03220 {
03221 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03222 }
03223 }
03224 if (imgname.lower() == "checked_high")
03225 {
03226 image_checked_high = gContext->LoadScalePixmap(file);
03227 if (!image_checked_high)
03228 {
03229 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03230 }
03231 }
03232 if (imgname.lower() == "unchecked_high")
03233 {
03234 image_unchecked_high = gContext->LoadScalePixmap(file);
03235 if (!image_unchecked_high)
03236 {
03237 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03238 }
03239 }
03240 }
03241 else
03242 {
03243 cerr << "Unknown: " << info.tagName() << " in CheckBox\n";
03244 return;
03245 }
03246 }
03247 }
03248
03249 if (!image_checked)
03250 image_checked = new QPixmap();
03251 if (!image_unchecked)
03252 image_unchecked = new QPixmap();
03253 if (!image_checked_high)
03254 image_checked_high = new QPixmap();
03255 if (!image_unchecked_high)
03256 image_unchecked_high = new QPixmap();
03257
03258 UICheckBoxType *cbt = new UICheckBoxType(name,
03259 *image_checked, *image_unchecked,
03260 *image_checked_high, *image_unchecked_high);
03261
03262 delete image_checked;
03263 delete image_unchecked;
03264 delete image_checked_high;
03265 delete image_unchecked_high;
03266
03267 cbt->SetScreen(wmult, hmult);
03268 cbt->setPosition(pos);
03269 cbt->SetOrder(order.toInt());
03270 if (context != -1)
03271 {
03272 cbt->SetContext(context);
03273 }
03274 cbt->SetParent(container);
03275 cbt->calculateScreenArea();
03276 container->AddType(cbt);
03277 }
03278
03279 void XMLParse::parseSelector(LayerSet *container, QDomElement &element)
03280 {
03281 int context = -1;
03282 QString font = "";
03283 QRect area;
03284 QPixmap *image_on = NULL;
03285 QPixmap *image_off = NULL;
03286 QPixmap *image_pushed = NULL;
03287
03288 QString name = element.attribute("name", "");
03289 if (name.isNull() || name.isEmpty())
03290 {
03291 cerr << "Selector needs a name\n";
03292 return;
03293 }
03294
03295 QString order = element.attribute("draworder", "");
03296 if (order.isNull() || order.isEmpty())
03297 {
03298 cerr << "Selector needs an order\n";
03299 return;
03300 }
03301
03302 for (QDomNode child = element.firstChild(); !child.isNull();
03303 child = child.nextSibling())
03304 {
03305 QDomElement info = child.toElement();
03306 if (!info.isNull())
03307 {
03308 if (info.tagName() == "context")
03309 {
03310 context = getFirstText(info).toInt();
03311 }
03312 else if (info.tagName() == "area")
03313 {
03314 area = parseRect(getFirstText(info));
03315 normalizeRect(area);
03316 }
03317 else if (info.tagName() == "font")
03318 {
03319 font = getFirstText(info);
03320 }
03321 else if (info.tagName() == "image")
03322 {
03323 QString imgname = "";
03324 QString file = "";
03325
03326 imgname = info.attribute("function", "");
03327 if (imgname.isNull() || imgname.isEmpty())
03328 {
03329 cerr << "Image in a selector needs a function\n";
03330 return;
03331 }
03332
03333 file = info.attribute("filename", "");
03334 if (file.isNull() || file.isEmpty())
03335 {
03336 cerr << "Image in a selector needs a filename\n";
03337 return;
03338 }
03339
03340 if (imgname.lower() == "on")
03341 {
03342 image_on = gContext->LoadScalePixmap(file);
03343 if (!image_on)
03344 {
03345 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03346 }
03347 }
03348 if (imgname.lower() == "off")
03349 {
03350 image_off = gContext->LoadScalePixmap(file);
03351 if (!image_off)
03352 {
03353 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03354 }
03355 }
03356 if (imgname.lower() == "pushed")
03357 {
03358 image_pushed = gContext->LoadScalePixmap(file);
03359
03360 if (!image_pushed)
03361 {
03362 cerr << "xmparse.o: I can't find a file called " << file << endl ;
03363 }
03364 }
03365 }
03366 else
03367 {
03368 cerr << "Unknown: " << info.tagName() << " in Selector\n";
03369 return;
03370 }
03371 }
03372 }
03373
03374 fontProp *testfont = GetFont(font);
03375 if (!testfont)
03376 {
03377 cerr << "Unknown font: " << font << " in Selector: " << name << endl;
03378 return;
03379 }
03380
03381 if (!image_on)
03382 image_on = new QPixmap();
03383 if (!image_off)
03384 image_off = new QPixmap();
03385 if (!image_pushed)
03386 image_pushed = new QPixmap();
03387
03388 UISelectorType *st = new UISelectorType(name, *image_on, *image_off,
03389 *image_pushed, area);
03390
03391 delete image_on;
03392 delete image_off;
03393 delete image_pushed;
03394
03395 st->SetScreen(wmult, hmult);
03396 st->setPosition(area.topLeft());
03397 st->setFont(testfont);
03398 st->SetOrder(order.toInt());
03399 if (context != -1)
03400 {
03401 st->SetContext(context);
03402 }
03403 st->SetParent(container);
03404 st->calculateScreenArea();
03405 container->AddType(st);
03406 }
03407
03408
03409 void XMLParse::parseBlackHole(LayerSet *container, QDomElement &element)
03410 {
03411 QRect area;
03412
03413 QString name = element.attribute("name", "");
03414 if (name.isNull() || name.isEmpty())
03415 {
03416 cerr << "BlackHole needs a name\n";
03417 return;
03418 }
03419
03420 for (QDomNode child = element.firstChild(); !child.isNull();
03421 child = child.nextSibling())
03422 {
03423 QDomElement info = child.toElement();
03424 if (!info.isNull())
03425 {
03426 if (info.tagName() == "area")
03427 {
03428 area = parseRect(getFirstText(info));
03429 normalizeRect(area);
03430 }
03431 else
03432 {
03433 cerr << "Unknown: " << info.tagName() << " in Black Hole\n";
03434 return;
03435 }
03436 }
03437 }
03438
03439
03440 UIBlackHoleType *bh = new UIBlackHoleType(name);
03441 bh->SetScreen(wmult, hmult);
03442 bh->setArea(area);
03443 bh->SetParent(container);
03444 bh->calculateScreenArea();
03445 container->AddType(bh);
03446 }
03447
03448 void XMLParse::parseListBtnArea(LayerSet *container, QDomElement &element)
03449 {
03450 int context = -1;
03451 QRect area = QRect(0,0,0,0);
03452 QString fontActive;
03453 QString fontInactive;
03454 QString align = QString::null;
03455 bool showArrow = true;
03456 bool showScrollArrows = false;
03457 int draworder = 0;
03458 QColor grUnselectedBeg(Qt::black);
03459 QColor grUnselectedEnd(80,80,80);
03460 uint grUnselectedAlpha(100);
03461 QColor grSelectedBeg(82,202,56);
03462 QColor grSelectedEnd(52,152,56);
03463 uint grSelectedAlpha(255);
03464 int spacing = 2;
03465 int margin = 3;
03466
03467 QString name = element.attribute("name", "");
03468 if (name.isEmpty()) {
03469 std::cerr << "ListBtn area needs a name" << std::endl;
03470 return;
03471 }
03472
03473 QString layerNum = element.attribute("draworder", "");
03474 if (layerNum.isNull() || layerNum.isEmpty())
03475 {
03476 cerr << "ListBtn area needs a draworder\n";
03477 return;
03478 }
03479
03480 draworder = layerNum.toInt();
03481 for (QDomNode child = element.firstChild(); !child.isNull();
03482 child = child.nextSibling()) {
03483 QDomElement info = child.toElement();
03484 if (!info.isNull())
03485 {
03486 if (info.tagName() == "area")
03487 {
03488 area = parseRect(getFirstText(info));
03489 normalizeRect(area);
03490 }
03491 else if (info.tagName() == "context")
03492 {
03493 context = getFirstText(info).toInt();
03494 }
03495 else if (info.tagName() == "fcnfont")
03496 {
03497 QString fontName = info.attribute("name", "");
03498 QString fontFcn = info.attribute("function", "");
03499
03500 if (fontFcn.lower() == "active")
03501 fontActive = fontName;
03502 else if (fontFcn.lower() == "inactive")
03503 fontInactive = fontName;
03504 else {
03505 std::cerr << "Unknown font function for listbtn area: "
03506 << fontFcn
03507 << std::endl;
03508 return;
03509 }
03510 }
03511 else if (info.tagName() == "showarrow") {
03512 if (getFirstText(info).lower() == "no")
03513 showArrow = false;
03514 }
03515 else if (info.tagName() == "align")
03516 {
03517 align = getFirstText(info);
03518 }
03519 else if (info.tagName() == "showscrollarrows") {
03520 if (getFirstText(info).lower() == "yes")
03521 showScrollArrows = true;
03522 }
03523 else if (info.tagName() == "gradient") {
03524
03525 if (info.attribute("type","").lower() == "selected") {
03526 grSelectedBeg = QColor(info.attribute("start"));
03527 grSelectedEnd = QColor(info.attribute("end"));
03528 grSelectedAlpha = info.attribute("alpha","255").toUInt();
03529 }
03530 else if (info.attribute("type","").lower() == "unselected") {
03531 grUnselectedBeg = QColor(info.attribute("start"));
03532 grUnselectedEnd = QColor(info.attribute("end"));
03533 grUnselectedAlpha = info.attribute("alpha","100").toUInt();
03534 }
03535 else {
03536 std::cerr << "Unknown type for gradient in listbtn area"
03537 << std::endl;
03538 return;
03539 }
03540
03541 if (!grSelectedBeg.isValid() || !grSelectedEnd.isValid() ||
03542 !grUnselectedBeg.isValid() || !grUnselectedEnd.isValid()) {
03543 std::cerr << "Unknown color for gradient in listbtn area"
03544 << std::endl;
03545 return;
03546 }
03547
03548 if (grSelectedAlpha > 255 || grUnselectedAlpha > 255) {
03549 std::cerr << "Incorrect alpha for gradient in listbtn area"
03550 << std::endl;
03551 return;
03552 }
03553 }
03554 else if (info.tagName() == "spacing") {
03555 spacing = getFirstText(info).toInt();
03556 }
03557 else if (info.tagName() == "margin") {
03558 margin = getFirstText(info).toInt();
03559 }
03560 else
03561 {
03562 std::cerr << "Unknown tag in listbtn area: "
03563 << info.tagName() << endl;
03564 return;
03565 }
03566
03567 }
03568 }
03569
03570 int jst = Qt::AlignLeft | Qt::AlignVCenter;
03571
03572 if (!align.isEmpty())
03573 {
03574 if (align.lower() == "center")
03575 jst = Qt::AlignCenter | Qt::AlignVCenter;
03576 else if (align.lower() == "right")
03577 jst = Qt::AlignRight | Qt::AlignVCenter;
03578 else if (align.lower() == "left")
03579 jst = Qt::AlignLeft | Qt::AlignVCenter;
03580 }
03581
03582 fontProp *fpActive = GetFont(fontActive);
03583 if (!fpActive)
03584 {
03585 cerr << "Unknown font: " << fontActive
03586 << " in listbtn area: " << name << endl;
03587 return;
03588 }
03589
03590 fontProp *fpInactive = GetFont(fontInactive);
03591 if (!fpInactive)
03592 {
03593 cerr << "Unknown font: " << fontInactive
03594 << " in listbtn area: " << name << endl;
03595 return;
03596 }
03597
03598
03599 UIListBtnType *l = new UIListBtnType(name, area, draworder, showArrow,
03600 showScrollArrows);
03601 l->SetScreen(wmult, hmult);
03602 l->SetFontActive(fpActive);
03603 l->SetFontInactive(fpInactive);
03604 l->SetJustification(jst);
03605 l->SetItemRegColor(grUnselectedBeg, grUnselectedEnd, grUnselectedAlpha);
03606 l->SetItemSelColor(grSelectedBeg, grSelectedEnd, grSelectedAlpha);
03607 l->SetSpacing((int)(spacing*hmult));
03608 l->SetMargin((int)(margin*wmult));
03609 l->SetParent(container);
03610 l->SetContext(context);
03611 l->calculateScreenArea();
03612
03613 container->AddType(l);
03614 container->bumpUpLayers(0);
03615 }
03616
03617 void XMLParse::parseListTreeArea(LayerSet *container, QDomElement &element)
03618 {
03619 int context = -1;
03620 QRect area = QRect(0,0,0,0);
03621 QRect listsize = QRect(0,0,0,0);
03622 int leveloffset = 0;
03623 QString fontActive;
03624 QString fontInactive;
03625 bool showArrow = true;
03626 bool showScrollArrows = false;
03627 int draworder = 0;
03628 QColor grUnselectedBeg(Qt::black);
03629 QColor grUnselectedEnd(80,80,80);
03630 uint grUnselectedAlpha(100);
03631 QColor grSelectedBeg(82,202,56);
03632 QColor grSelectedEnd(52,152,56);
03633 uint grSelectedAlpha(255);
03634 int spacing = 2;
03635 int margin = 3;
03636
03637 QString name = element.attribute("name", "");
03638 if (name.isEmpty()) {
03639 std::cerr << "ListTreeArea area needs a name" << std::endl;
03640 return;
03641 }
03642
03643 QString layerNum = element.attribute("draworder", "");
03644 if (layerNum.isNull() || layerNum.isEmpty())
03645 {
03646 cerr << "ListTreeArea needs a draworder\n";
03647 return;
03648 }
03649
03650 draworder = layerNum.toInt();
03651 for (QDomNode child = element.firstChild(); !child.isNull();
03652 child = child.nextSibling()) {
03653 QDomElement info = child.toElement();
03654 if (!info.isNull())
03655 {
03656 if (info.tagName() == "area")
03657 {
03658 area = parseRect(getFirstText(info));
03659 normalizeRect(area);
03660 }
03661 else if (info.tagName() == "context")
03662 {
03663 context = getFirstText(info).toInt();
03664 }
03665 else if (info.tagName() == "listsize")
03666 {
03667 listsize = parseRect(getFirstText(info));
03668 normalizeRect(listsize);
03669 }
03670 else if (info.tagName() == "leveloffset")
03671 {
03672 leveloffset = getFirstText(info).toInt();
03673 }
03674 else if (info.tagName() == "fcnfont")
03675 {
03676 QString fontName = info.attribute("name", "");
03677 QString fontFcn = info.attribute("function", "");
03678
03679 if (fontFcn.lower() == "active")
03680 fontActive = fontName;
03681 else if (fontFcn.lower() == "inactive")
03682 fontInactive = fontName;
03683 else {
03684 std::cerr << "Unknown font function for ListTreeArea: "
03685 << fontFcn
03686 << std::endl;
03687 return;
03688 }
03689 }
03690 else if (info.tagName() == "showarrow") {
03691 if (getFirstText(info).lower() == "no")
03692 showArrow = false;
03693 }
03694 else if (info.tagName() == "showscrollarrows") {
03695 if (getFirstText(info).lower() == "yes")
03696 showScrollArrows = true;
03697 }
03698 else if (info.tagName() == "gradient") {
03699
03700 if (info.attribute("type","").lower() == "selected") {
03701 grSelectedBeg = QColor(info.attribute("start"));
03702 grSelectedEnd = QColor(info.attribute("end"));
03703 grSelectedAlpha = info.attribute("alpha","255").toUInt();
03704 }
03705 else if (info.attribute("type","").lower() == "unselected") {
03706 grUnselectedBeg = QColor(info.attribute("start"));
03707 grUnselectedEnd = QColor(info.attribute("end"));
03708 grUnselectedAlpha = info.attribute("alpha","100").toUInt();
03709 }
03710 else {
03711 std::cerr << "Unknown type for gradient in ListTreeArea"
03712 << std::endl;
03713 return;
03714 }
03715
03716 if (!grSelectedBeg.isValid() || !grSelectedEnd.isValid() ||
03717 !grUnselectedBeg.isValid() || !grUnselectedEnd.isValid()) {
03718 std::cerr << "Unknown color for gradient in ListTreeArea area"
03719 << std::endl;
03720 return;
03721 }
03722
03723 if (grSelectedAlpha > 255 || grUnselectedAlpha > 255) {
03724 std::cerr << "Incorrect alpha for gradient in ListTreeArea area"
03725 << std::endl;
03726 return;
03727 }
03728 }
03729 else if (info.tagName() == "spacing") {
03730 spacing = getFirstText(info).toInt();
03731 }
03732 else if (info.tagName() == "margin") {
03733 margin = getFirstText(info).toInt();
03734 }
03735 else
03736 {
03737 std::cerr << "Unknown tag in ListTreeArea: "
03738 << info.tagName() << endl;
03739 return;
03740 }
03741
03742 }
03743 }
03744
03745 fontProp *fpActive = GetFont(fontActive);
03746 if (!fpActive)
03747 {
03748 cerr << "Unknown font: " << fontActive
03749 << " in ListTreeArea: " << name << endl;
03750 return;
03751 }
03752
03753 fontProp *fpInactive = GetFont(fontInactive);
03754 if (!fpInactive)
03755 {
03756 cerr << "Unknown font: " << fontInactive
03757 << " in ListTreeArea: " << name << endl;
03758 return;
03759 }
03760
03761
03762 UIListTreeType *l = new UIListTreeType(name, area, listsize, leveloffset,
03763 draworder);
03764
03765 l->SetScreen(wmult, hmult);
03766 l->SetFontActive(fpActive);
03767 l->SetFontInactive(fpInactive);
03768 l->SetItemRegColor(grUnselectedBeg, grUnselectedEnd, grUnselectedAlpha);
03769 l->SetItemSelColor(grSelectedBeg, grSelectedEnd, grSelectedAlpha);
03770 l->SetSpacing((int)(spacing*hmult));
03771 l->SetMargin((int)(margin*wmult));
03772 l->SetParent(container);
03773 l->calculateScreenArea();
03774 l->SetContext(context);
03775
03776 container->AddType(l);
03777 container->bumpUpLayers(0);
03778 }
03779
03780 void XMLParse::parseKey(LayerSet *container, QDomElement &element)
03781 {
03782 QPixmap *normalImage = NULL, *focusedImage = NULL;
03783 QPixmap *downImage = NULL, *downFocusedImage = NULL;
03784 QString normalFontName = "", focusedFontName = "";
03785 QString downFontName = "", downFocusedFontName = "";
03786 QString name, order, type;
03787 QString normalChar = "", shiftChar = "";
03788 QString altChar = "", shiftaltChar = "";
03789 QString moveLeft = "", moveRight = "";
03790 QString moveUp = "", moveDown = "";
03791 QPoint pos = QPoint(0, 0);
03792
03793 name = element.attribute("name", "");
03794 if (name.isNull() || name.isEmpty())
03795 {
03796 cerr << "key needs a name\n";
03797 return;
03798 }
03799
03800 type = element.attribute("type", "");
03801 if (type.isNull() || type.isEmpty())
03802 {
03803 cerr << "key needs a type\n";
03804 return;
03805 }
03806
03807 order = element.attribute("draworder", "");
03808 if (order.isNull() || order.isEmpty())
03809 {
03810 cerr << "key needs an order\n";
03811 return;
03812 }
03813
03814 for (QDomNode child = element.firstChild(); !child.isNull();
03815 child = child.nextSibling())
03816 {
03817 QDomElement e = child.toElement();
03818 if (!e.isNull())
03819 {
03820 if (e.tagName() == "position")
03821 {
03822 pos = parsePoint(getFirstText(e));
03823 pos.setX((int)(pos.x() * wmult));
03824 pos.setY((int)(pos.y() * hmult));
03825
03826 }
03827 else if (e.tagName() == "char")
03828 {
03829 normalChar = e.attribute("normal", "");
03830 shiftChar = e.attribute("shift", "");
03831 altChar = e.attribute("alt", "");
03832 shiftaltChar = e.attribute("altshift", "");
03833 }
03834 else if (e.tagName() == "move")
03835 {
03836 moveLeft = e.attribute("left", "");
03837 moveRight = e.attribute("right", "");
03838 moveUp = e.attribute("up", "");
03839 moveDown = e.attribute("down", "");
03840 }
03841 else if (e.tagName() == "image")
03842 {
03843 QString imgname = "";
03844 QString imgfunction = "";
03845
03846 imgfunction = e.attribute("function", "");
03847 if (imgfunction.isNull() || imgfunction.isEmpty())
03848 {
03849 cerr << "Image in a key needs a function\n";
03850 return;
03851 }
03852
03853 imgname = e.attribute("filename", "");
03854 if (imgname.isNull() || imgname.isEmpty())
03855 {
03856 cerr << "Image in a key needs a filename\n";
03857 return;
03858 }
03859
03860 if (imgfunction.lower() == "normal")
03861 {
03862 normalImage = gContext->LoadScalePixmap(imgname);
03863 if (!normalImage)
03864 {
03865 cerr << "xmparse.o: I can't find a file called "
03866 << imgname << endl;
03867 }
03868 }
03869 else if (imgfunction.lower() == "focused")
03870 {
03871 focusedImage = gContext->LoadScalePixmap(imgname);
03872 if (!focusedImage)
03873 {
03874 cerr << "xmparse.o: I can't find a file called "
03875 << imgname << endl;
03876 }
03877 }
03878 else if (imgfunction.lower() == "down")
03879 {
03880 downImage = gContext->LoadScalePixmap(imgname);
03881
03882 if (!downImage)
03883 {
03884 cerr << "xmparse.o: I can't find a file called "
03885 << imgname << endl;
03886 }
03887 }
03888 else if (imgfunction.lower() == "downfocused")
03889 {
03890 downFocusedImage = gContext->LoadScalePixmap(imgname);
03891
03892 if (!downFocusedImage)
03893 {
03894 cerr << "xmparse.o: I can't find a file called "
03895 << imgname << endl;
03896 }
03897 }
03898 else
03899 {
03900 std::cerr << "Unknown image function in key type: "
03901 << imgfunction << endl;
03902 return;
03903 }
03904 }
03905 else if (e.tagName() == "fcnfont")
03906 {
03907 QString fontName = e.attribute("name", "");
03908 QString fontFcn = e.attribute("function", "");
03909
03910 if (fontFcn.lower() == "normal")
03911 normalFontName = fontName;
03912 else if (fontFcn.lower() == "focused")
03913 focusedFontName = fontName;
03914 else if (fontFcn.lower() == "down")
03915 downFontName = fontName;
03916 else if (fontFcn.lower() == "downfocused")
03917 downFocusedFontName = fontName;
03918 else
03919 {
03920 cerr << "Unknown font function in key type: "
03921 << fontFcn << endl;
03922 return;
03923 }
03924 }
03925 else
03926 {
03927 cerr << "Unknown: " << e.tagName() << " in key\n";
03928 return;
03929 }
03930 }
03931 }
03932
03933 fontProp *normalFont = GetFont(normalFontName);
03934 fontProp *focusedFont = GetFont(focusedFontName);
03935 fontProp *downFont = GetFont(downFontName);
03936 fontProp *downFocusedFont = GetFont(downFocusedFontName);
03937
03938 UIKeyType *key = new UIKeyType(name);
03939 key->SetScreen(wmult, hmult);
03940 key->SetParent(container);
03941 key->SetOrder(order.toInt());
03942 key->SetType(type);
03943 key->SetChars(normalChar, shiftChar, altChar, shiftaltChar);
03944 key->SetMoves(moveLeft, moveRight, moveUp, moveDown);
03945 key->SetPosition(pos);
03946 key->SetImages(normalImage, focusedImage, downImage, downFocusedImage);
03947 key->SetFonts(normalFont, focusedFont, downFont, downFocusedFont);
03948
03949 container->AddType(key);
03950 }
03951
03952 void XMLParse::parseKeyboard(LayerSet *container, QDomElement &element)
03953 {
03954 QString normalFontName = "", focusedFontName = "";
03955 QString downFontName = "", downFocusedFontName = "";
03956 int context = -1;
03957 QRect area;
03958 QPixmap *normalImage = NULL, *focusedImage = NULL;
03959 QPixmap *downImage = NULL, *downFocusedImage = NULL;
03960
03961 QString name = element.attribute("name", "");
03962 if (name.isNull() || name.isEmpty())
03963 {
03964 cerr << "keyboard needs a name\n";
03965 return;
03966 }
03967
03968 QString order = element.attribute("draworder", "");
03969 if (order.isNull() || order.isEmpty())
03970 {
03971 cerr << "keyboard needs an order\n";
03972 return;
03973 }
03974
03975 for (QDomNode child = element.firstChild(); !child.isNull();
03976 child = child.nextSibling())
03977 {
03978 QDomElement e = child.toElement();
03979 if (!e.isNull())
03980 {
03981 if (e.tagName() == "key")
03982 {
03983 parseKey(container, e);
03984 }
03985 else if (e.tagName() == "area")
03986 {
03987 area = parseRect(getFirstText(e));
03988 normalizeRect(area);
03989 }
03990 else if (e.tagName() == "context")
03991 {
03992 context = getFirstText(e).toInt();
03993 }
03994
03995 else if (e.tagName() == "image")
03996 {
03997 QString imgname = "";
03998 QString imgfunction = "";
03999
04000 imgfunction = e.attribute("function", "");
04001 if (imgfunction.isNull() || imgfunction.isEmpty())
04002 {
04003 cerr << "Image in a keyboard needs a function\n";
04004 return;
04005 }
04006
04007 imgname = e.attribute("filename", "");
04008 if (imgname.isNull() || imgname.isEmpty())
04009 {
04010 cerr << "Image in a keyboard needs a filename\n";
04011 return;
04012 }
04013
04014 if (imgfunction.lower() == "normal")
04015 {
04016 normalImage = gContext->LoadScalePixmap(imgname);
04017 if (!normalImage)
04018 {
04019 cerr << "xmparse.o: I can't find a file called " << imgname << endl ;
04020 }
04021 }
04022 else if (imgfunction.lower() == "focused")
04023 {
04024 focusedImage = gContext->LoadScalePixmap(imgname);
04025 if (!focusedImage)
04026 {
04027 cerr << "xmparse.o: I can't find a file called " << imgname << endl ;
04028 }
04029 }
04030 else if (imgfunction.lower() == "down")
04031 {
04032 downImage = gContext->LoadScalePixmap(imgname);
04033
04034 if (!downImage)
04035 {
04036 cerr << "xmparse.o: I can't find a file called " << imgname << endl ;
04037 }
04038 }
04039 else if (imgfunction.lower() == "downfocused")
04040 {
04041 downFocusedImage = gContext->LoadScalePixmap(imgname);
04042
04043 if (!downFocusedImage)
04044 {
04045 cerr << "xmparse.o: I can't find a file called " << imgname << endl ;
04046 }
04047 }
04048 else
04049 {
04050 std::cerr << "Unknown image function in keyboard type: "
04051 << imgfunction
04052 << std::endl;
04053 return;
04054 }
04055 }
04056 else if (e.tagName() == "fcnfont")
04057 {
04058 QString fontName = e.attribute("name", "");
04059 QString fontFcn = e.attribute("function", "");
04060
04061 if (fontFcn.lower() == "normal")
04062 normalFontName = fontName;
04063 else if (fontFcn.lower() == "focused")
04064 focusedFontName = fontName;
04065 else if (fontFcn.lower() == "down")
04066 downFontName = fontName;
04067 else if (fontFcn.lower() == "downfocused")
04068 downFocusedFontName = fontName;
04069 else
04070 {
04071 std::cerr << "Unknown font function in keyboard type: "
04072 << fontFcn
04073 << std::endl;
04074 return;
04075 }
04076 }
04077 else
04078 {
04079 cerr << "Unknown: " << e.tagName() << " in keyboard\n";
04080 return;
04081 }
04082 }
04083 }
04084
04085 if (normalFontName == "")
04086 {
04087 cerr << "Keyboard need a normal font" << endl;
04088 return;
04089 }
04090
04091 if (focusedFontName == "")
04092 focusedFontName = normalFontName;
04093
04094 if (downFontName == "")
04095 downFontName = normalFontName;
04096
04097 if (downFocusedFontName == "")
04098 downFocusedFontName = normalFontName;
04099
04100 fontProp *normalFont = GetFont(normalFontName);
04101 if (!normalFont)
04102 {
04103 cerr << "Unknown font: " << normalFontName
04104 << " in Keyboard: " << name << endl;
04105 return;
04106 }
04107
04108 fontProp *focusedFont = GetFont(focusedFontName);
04109 if (!focusedFont)
04110 {
04111 cerr << "Unknown font: " << focusedFontName
04112 << " in Keyboard: " << name << endl;
04113 return;
04114 }
04115
04116 fontProp *downFont = GetFont(downFontName);
04117 if (!downFont)
04118 {
04119 cerr << "Unknown font: " << downFontName
04120 << " in Keyboard: " << name << endl;
04121 return;
04122 }
04123
04124 fontProp *downFocusedFont = GetFont(downFocusedFontName);
04125 if (!downFocusedFont)
04126 {
04127 cerr << "Unknown font: " << downFocusedFontName
04128 << " in Keyboard: " << name << endl;
04129 return;
04130 }
04131
04132 UIKeyboardType *kbd = new UIKeyboardType(name, order.toInt());
04133 kbd->SetScreen(wmult, hmult);
04134 kbd->SetParent(container);
04135 kbd->SetContext(context);
04136 kbd->SetArea(area);
04137 kbd->calculateScreenArea();
04138
04139 container->AddType(kbd);
04140
04141 vector<UIType *>::iterator i = container->getAllTypes()->begin();
04142 for (; i != container->getAllTypes()->end(); i++)
04143 {
04144 UIType *type = (*i);
04145 if (UIKeyType *keyt = dynamic_cast<UIKeyType*>(type))
04146 {
04147 kbd->AddKey(keyt);
04148 keyt->SetDefaultImages(normalImage, focusedImage, downImage, downFocusedImage);
04149 keyt->SetDefaultFonts(normalFont, focusedFont, downFont, downFocusedFont);
04150 keyt->calculateScreenArea();
04151 }
04152 }
04153 }
04154
04155