fbd785856e55dca22ac59a0345344b52f6c9ea33
[jspeed] / src / graphicselement.h
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 #ifndef GRAPHICSELEMENT_H
20 #define GRAPHICSELEMENT_H
21
22 #include <QtCore/QMap>
23 #include "location.h"
24
25 class QString;
26 class QByteArray;
27 class GraphicsScene;
28 class Reader;
29 class QFont;
30
31 class GraphicsElement
32 {
33 public:
34
35     struct AttributeDetails
36     {
37         QString name;
38         bool isInt;
39     };
40
41     GraphicsElement(Reader* reader);
42     static GraphicsElement* getElement(QString const& name, Reader* reader);
43     virtual bool setAttribute(QString const& name, QString const& value) = 0;
44     virtual void addToScene(GraphicsScene* scene) = 0;
45     virtual void update() = 0;
46     QString const& getError() const;
47
48 protected:
49     int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, int& intValue);
50     void setError(QString const& error);
51     bool readFile(QString const& name, QByteArray& data);
52     bool getFont(QString const& name, QFont& font);
53
54 private:
55     Reader* reader_;
56     QString error_;
57     QMap<QString, QString> loadedFonts_;
58 };
59
60 #endif