ee9c4c253a06e3b2b47de5367b495b525d98052f
[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 QFont;
28 class QGraphicsItem;
29 class GraphicsScene;
30 class Reader;
31
32 class GraphicsElement
33 {
34 public:
35
36     struct AttributeDetails
37     {
38         QString name;
39         bool isInt;
40     };
41
42     GraphicsElement(Reader* reader);
43     static GraphicsElement* getElement(QString const& name, Reader* reader);
44     virtual bool setAttribute(QString const& name, QString const& value) = 0;
45     virtual void addToScene(GraphicsScene* scene) = 0;
46     virtual void update() = 0;
47     virtual QGraphicsItem* getElement() const = 0;
48     QString const& getError() const;
49
50 protected:
51     int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, int& intValue);
52     void setError(QString const& error);
53     bool readFile(QString const& name, QByteArray& data);
54     bool getFont(QString const& name, QFont& font);
55
56 private:
57     Reader* reader_;
58     QString error_;
59     QMap<QString, QString> loadedFonts_;
60 };
61
62 #endif