Initial commit.
[jspeed] / src / themescreen.cpp
1 /*
2  * This file is part of jSpeed.
3  *
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.
8  *
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.
13  *
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/>.
16  *
17  */
18
19 #include <QtGui/QWidget>
20 #include <QtCore/QString>
21 #include <QtCore/QDebug>
22 #include <QtXml/QDomNode>
23 #include <QtXml/QDomNodeList>
24 #include "themescreen.h"
25 #include "graphicselement.h"
26 #include "reader.h"
27
28 ThemeScreen::ThemeScreen(QWidget* parent): GraphicsScreen(parent)
29 {
30 }
31
32 bool ThemeScreen::load(QDomNode const& data, Reader* reader)
33 {
34     QDomNodeList childNodes = data.childNodes();
35
36     if(childNodes.size() == 0)
37     {
38         error_ = "No elements specified for " + data.nodeName();
39         return false;
40     }
41
42     for(int i = 0; i < childNodes.size(); i++)
43     {
44         GraphicsElement* element = GraphicsElement::getElement(childNodes.at(i).nodeName(), reader);
45
46         if(element == 0)
47         {
48             qDebug() << "Warning: invalid element: " << childNodes.at(i).nodeName();
49             continue;
50         }
51
52         elements_.push_back(element);
53
54         QDomNodeList options = childNodes.at(i).childNodes();
55
56         for(int i = 0; i < options.size(); i++)
57         {
58             if(!element->setAttribute(options.at(i).nodeName(), options.at(i).toElement().text()))
59             {
60                 qDebug() << "Warning: invalid option: " << options.at(i).nodeName();
61             }
62         }
63
64         element->addToScene(getScene());
65
66     }
67
68     return true;
69 }
70
71 void ThemeScreen::update()
72 {
73     for(int i = 0; i < elements_.size(); i++)
74     {
75         elements_.at(i)->update();
76     }
77 }