2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtGui/QApplication>
20 #include <QtGui/QWidget>
21 #include <QtGui/QGraphicsItem>
22 #include <QtCore/QString>
23 #include <QtCore/QDebug>
24 #include <QtXml/QDomNode>
25 #include <QtXml/QDomNodeList>
26 #include "themescreen.h"
27 #include "graphicselement.h"
29 #include "graphicsscene.h"
31 ThemeScreen::ThemeScreen(QWidget* parent): GraphicsScreen(parent)
35 bool ThemeScreen::load(QDomNode const& data, Reader* reader)
37 QDomNodeList childNodes = data.childNodes();
39 if(childNodes.size() == 0)
41 error_ = "No elements specified for " + data.nodeName();
45 for(int i = 0; i < childNodes.size(); i++)
47 GraphicsElement* element = GraphicsElement::getElement(childNodes.at(i).nodeName(), reader);
51 qDebug() << "Warning: invalid element: " << childNodes.at(i).nodeName();
55 elements_.push_back(element);
57 QDomNodeList options = childNodes.at(i).childNodes();
59 for(int i = 0; i < options.size(); i++)
61 QString nodeName = options.at(i).nodeName();
65 if(nodeName == "effect")
67 QDomNode effectName = options.at(i).attributes().namedItem("name");
69 if(effectName.isNull())
71 qDebug() << "Missing name for effect";
75 if(!element->setEffect(effectName.toAttr().value()))
77 qDebug() << "Invalid effect: " << effectName.toAttr().value();
81 QDomNodeList themeOptions = options.at(i).childNodes();
83 for(int i = 0; i < themeOptions.size(); i++)
85 if(!element->setEffectAttribute(themeOptions.at(i).nodeName(), themeOptions.at(i).toElement().text()))
87 qDebug() << "Warning: invalid effect option: " << themeOptions.at(i).nodeName();
91 element->applyEffect();
97 if(!element->setAttribute(nodeName, options.at(i).toElement().text()))
99 qDebug() << "Warning: invalid option: " << options.at(i).nodeName();
104 element->addToScene(getScene());
113 void ThemeScreen::removeElements()
115 for(int i = 0; i < elements_.size(); i++)
117 QGraphicsItem* item = elements_.at(i)->getElement();
121 getScene()->removeItem(item);
125 delete elements_.at(i);
131 void ThemeScreen::update()
133 for(int i = 0; i < elements_.size(); i++)
135 elements_.at(i)->update();
139 void ThemeScreen::setColor(QString const& color)