Added POI text field. Some tuning to detail screen item position.
[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/QObject>
23 #include <QtCore/QMap>
24
25 class QString;
26 class QByteArray;
27 class QFont;
28 class QGraphicsItem;
29 class GraphicsScene;
30 class QGraphicsEffect;
31 class Reader;
32 class Effect;
33
34 class GraphicsElement : public QObject
35 {
36     Q_OBJECT
37
38 public:
39
40     struct AttributeDetails
41     {
42         QString name;
43         bool isInt;
44     };
45
46     GraphicsElement(Reader* reader);
47     static GraphicsElement* getElement(QString const& name, Reader* reader);
48     virtual bool setAttribute(QString const& name, QString const& value) = 0;
49     virtual void addToScene(GraphicsScene* scene) = 0;
50     virtual void update() = 0;
51     virtual QGraphicsItem* getElement() const = 0;
52     QString const& getError() const;
53     bool setEffect(QString const& effect);
54     bool setEffectAttribute(QString const& name, QString const& value);
55     void applyEffect();
56     bool canBeVisible() const;
57
58 protected:
59     enum VisibleWhen {ALWAYS, POI_VISIBLE, SPEED_EXCEEDED};
60
61     int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, int& intValue);
62     void setError(QString const& error);
63     bool readFile(QString const& name, QByteArray& data);
64     bool getFont(QString const& name, QFont& font);
65     void setVisibleWhen(VisibleWhen when);
66     VisibleWhen strToVisibleWhen(QString const& str) const;
67
68 private slots:
69     void updateVisibility(bool visible);
70
71 private:
72     Reader* reader_;
73     QString error_;
74     Effect* effect_;
75     QMap<QString, QString> loadedFonts_;
76     VisibleWhen visibleWhen_;
77     bool canBeVisible_;
78 };
79
80 #endif