]> Shamusworld >> Repos - architektonas/blob - src/base/rs_text.h
626d0ab587c6ea8e9a091c6084c8025c06b2cd06
[architektonas] / src / base / rs_text.h
1 #ifndef RS_TEXT_H
2 #define RS_TEXT_H
3
4 #include "rs_entity.h"
5 #include "rs_entitycontainer.h"
6
7 /**
8  * Holds the data that defines a text entity.
9  */
10 class RS_TextData
11 {
12         public:
13                 /**
14                  * Default constructor. Leaves the data object uninitialized.
15                  */
16                 RS_TextData() {}
17
18                 /**
19                  * Constructor with initialisation.
20                  *
21                  * @param insertionPoint Insertion point
22                  * @param height Nominal (initial) text height
23                  * @param width Reference rectangle width
24                  * @param valign Vertical alignment
25                  * @param halign Horizontal alignment
26                  * @param drawingDirection Drawing direction
27                  * @param lineSpacingStyle Line spacing style
28                  * @param lineSpacingFactor Line spacing factor
29                  * @param text Text string
30                  * @param style Text style name
31                  * @param angle Rotation angle
32                  * @param updateMode RS2::Update will update the text entity instantly
33                  *    RS2::NoUpdate will not update the entity. You can update
34                  *    it later manually using the update() method. This is
35                  *    often the case since you might want to adjust attributes
36                  *    after creating a text entity.
37                  */
38                 RS_TextData(const Vector & insertionPoint, double height, double width,
39                         RS2::VAlign valign, RS2::HAlign halign, RS2::TextDrawingDirection drawingDirection,
40                         RS2::TextLineSpacingStyle lineSpacingStyle, double lineSpacingFactor,
41                         const QString& text, const QString & style, double angle,
42                         RS2::UpdateMode updateMode = RS2::Update)
43                 {
44                         this->insertionPoint = insertionPoint;
45                         this->height = height;
46                         this->width = width;
47                         this->valign = valign;
48                         this->halign = halign;
49                         this->drawingDirection = drawingDirection;
50                         this->lineSpacingStyle = lineSpacingStyle;
51                         this->lineSpacingFactor = lineSpacingFactor;
52                         this->style = style;
53                         this->angle = angle;
54                         this->text = text;
55                         this->updateMode = updateMode;
56                 }
57
58                 friend class RS_Text;
59
60                 friend std::ostream & operator<<(std::ostream & os, const RS_TextData & td)
61                 {
62                         os << "(" << td.text.toLatin1().data() << ")";
63                         return os;
64                 }
65
66         public:
67                 /** Insertion point */
68                 Vector insertionPoint;
69                 /** Nominal (initial) text height */
70                 double height;
71                 /** Reference rectangle width */
72                 double width;
73                 /** Vertical alignment */
74                 RS2::VAlign valign;
75                 /** Horizontal alignment */
76                 RS2::HAlign halign;
77                 /** Drawing direction */
78                 RS2::TextDrawingDirection drawingDirection;
79                 /** Line spacing style */
80                 RS2::TextLineSpacingStyle lineSpacingStyle;
81                 /** Line spacing factor */
82                 double lineSpacingFactor;
83                 /** Text string */
84                 QString text;
85                 /** Text style name */
86                 QString style;
87                 /** Rotation angle */
88                 double angle;
89                 /** Update mode */
90                 RS2::UpdateMode updateMode;
91 };
92
93 /**
94  * Class for a text entity.
95  * Please note that text strings can contain special
96  * characters such as %%c for a diameter sign as well as unicode
97  * characters. Line feeds are stored as real line feeds in the string.
98  *
99  * @author Andrew Mustun
100  */
101 class RS_Text: public RS_EntityContainer
102 {
103         public:
104                 RS_Text(RS_EntityContainer * parent, const RS_TextData & d);
105                 virtual ~RS_Text();
106
107                 virtual RS_Entity * clone();
108                 virtual RS2::EntityType rtti() const;
109                 RS_TextData getData() const;
110                 void update();
111                 void updateAddLine(RS_EntityContainer * textLine, int lineCounter);
112                 int getNumberOfLines();
113
114                 Vector getInsertionPoint();
115                 double getHeight();
116                 void setHeight(double h);
117                 double getWidth();
118                 void setAlignment(int a);
119                 int getAlignment();
120                 RS2::VAlign getVAlign();
121                 void setVAlign(RS2::VAlign va);
122                 RS2::HAlign getHAlign();
123                 void setHAlign(RS2::HAlign ha);
124                 RS2::TextDrawingDirection getDrawingDirection();
125                 RS2::TextLineSpacingStyle getLineSpacingStyle();
126                 void setLineSpacingFactor(double f);
127                 double getLineSpacingFactor();
128                 void setText(const QString & t);
129                 QString getText();
130                 void setStyle(const QString & s);
131                 QString getStyle();
132                 void setAngle(double a);
133                 double getAngle();
134                 double getUsedTextWidth();
135                 double getUsedTextHeight();
136                 virtual double getLength();
137
138                 virtual VectorSolutions getRefPoints();
139                 virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
140
141                 virtual void move(Vector offset);
142                 virtual void rotate(Vector center, double angle);
143                 virtual void scale(Vector center, Vector factor);
144                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
145                 virtual bool hasEndpointsWithinWindow(Vector v1, Vector v2);
146                 virtual void stretch(Vector firstCorner, Vector secondCorner, Vector offset);
147
148                 friend std::ostream & operator<<(std::ostream & os, const RS_Text & p);
149
150         protected:
151                 RS_TextData data;
152                 /**
153                 * Text width used by the current contents of this text entity.
154                 * This property is updated by the update method.
155                 * @see update
156                 */
157                 double usedTextWidth;
158                 /**
159                 * Text height used by the current contents of this text entity.
160                 * This property is updated by the update method.
161                 * @see update
162                 */
163                 double usedTextHeight;
164 };
165
166 #endif