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 <QtCore/QString>
20 #include <QtCore/QByteArray>
21 #include <QtCore/QDebug>
22 #include <QtGui/QGraphicsScene>
23 #include <QtGui/QFont>
24 #include <QtGui/QFontDatabase>
25 #include "graphicselement.h"
27 #include "textelement.h"
28 #include "imageelement.h"
29 #include "rectangle.h"
33 GraphicsElement::GraphicsElement(Reader* reader): reader_(reader), error_("")
37 GraphicsElement* GraphicsElement::getElement(QString const& name, Reader* reader)
41 return new ImageElement(reader);
46 return new TextElement(reader);
49 if(name == "rectangle")
51 return new Rectangle(reader);
56 bool animate = Settings::instance().value("animate_pointer", true).toBool();
57 return new Pointer(reader, animate);
60 qDebug() << "Element not found: " << name;
64 QString const& GraphicsElement::getError() const
69 void GraphicsElement::setError(QString const& error)
74 bool GraphicsElement::readFile(QString const& filename, QByteArray& data)
77 if(!reader_->readFile(filename, data))
79 setError(reader_->errorString());
86 bool GraphicsElement::getFont(QString const& name, QFont& font)
90 QMap<QString, QString>::const_iterator it = loadedFonts_.find(name);
92 if(it != loadedFonts_.end())
94 font = QFont(it.value());
98 if(!reader_->fileExists(name))
104 if(!readFile(name, data))
109 int id = QFontDatabase::addApplicationFontFromData(data);
113 setError("Unable to load font: " + name);
114 loadedFonts_[name] = "";
118 QStringList families = QFontDatabase::applicationFontFamilies(id);
120 if(families.size() == 0)
122 setError("No fonts found in " + name);
126 loadedFonts_[name] = families.at(0);
127 font = QFont(families.at(0));
132 int GraphicsElement::getAttribute(QString const& name,
133 QString const& value,
134 const GraphicsElement::AttributeDetails details[],
138 QString lower = name.toLower();
140 for(int i = 0; i < count; i++)
142 if(details[i].name == lower)
144 if(!details[i].isInt)
151 int tmp = value.toInt(&ok);
160 setError("Value for " + name + " is not integer ("+value+")");
167 setError("Unknown attribute: " + name);