...
[jspeed] / src / textelement.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 TEXTELEMENT_H
20 #define TEXTELEMENT_H
21
22 #include "graphicselement.h"
23
24 class QString;
25 class QGraphicsItem;
26 class QGraphicsTextItem;
27 class Reader;
28 class GraphicsScene;
29
30 class TextElement : public GraphicsElement
31 {
32 public:
33     enum Attribute {XPOS, YPOS, ZPOS, VISIBLEWHEN, DATA, FORMAT, WIDTH, ALIGN, COLOR, SIZE, FONT, BOLD, ITALIC, UPPERCASE, LETTERSPACING, TIMEFORMAT, DATEFORMAT, ATTRIBUTE_COUNT};
34     enum Field {TRIP, TOTAL, SPEED, MAXSPEED, AVGSPEED, UNIT, SPEEDUNIT, TIME, DATE, POIDISTANCE, POITEXT, ANGLE, LATITUDE, LONGITUDE, ALTITUDE, DISTANCEUNIT, FIELD_COUNT};
35     TextElement(Reader* reader);
36     virtual bool setAttribute(QString const& name, QString const& value);
37     virtual void addToScene(GraphicsScene* scene);
38     virtual void update();
39     virtual QGraphicsItem* getElement() const;
40
41 private:
42     QString handleEmpty(double value);
43     void updateHtml(QString data);
44     void replaceSpecialFields(QString& value);
45     void replaceValue(QString& value, Field field, QString const& replace);
46     bool applyFont();
47     QString formatString(double val);
48     QGraphicsTextItem* element_;
49     QString data_;
50     QString format_;
51     QString align_;
52     QString timeFormat_;
53     QString dateFormat_;
54     int fontSize_;
55     bool bold_;
56     bool italic_;
57     bool uppercase_;
58     int letterSpacing_;
59     QString fontFile_;
60     QList<Field> specialFields_;
61 };
62
63 #endif