1 #include "headingobj.h"
3 /////////////////////////////////////////////////////////////////
5 /////////////////////////////////////////////////////////////////
6 HeadingObj::HeadingObj() : MapObj()
8 // cout << "Const HeadingObj ()\n";
12 HeadingObj::HeadingObj(QCanvas* c) :MapObj(c)
14 // cout << "Const HeadingObj\n";
18 HeadingObj::~HeadingObj()
23 void HeadingObj::init()
25 textline.setAutoDelete (TRUE);
27 color=QColor ("black");
31 void HeadingObj::copy(HeadingObj *other)
34 textwidth=other->textwidth;
37 setText (other->text() );
40 void HeadingObj::move(double x, double y)
43 int h; // height of a textline
44 int ho; // offset of height while drawing all lines
45 if (textline.first() )
46 h=textline.first()->boundingRect().height();
51 for (t=textline.first(); t; t=textline.next() )
59 void HeadingObj::moveBy(double x, double y)
61 move (x+absPos.x(),y+absPos.y() );
64 void HeadingObj::positionBBox()
66 bbox.setX (absPos.x());
67 bbox.setY (absPos.y());
70 void HeadingObj::calcBBoxSize()
74 // Using Backspace an empty heading might easily be created, then there
75 // would be textline.first()==NULL This can be worked around by the following, but
76 // then no selection would be visible, thus we prevent it in ::setText()
77 if (!textline.isEmpty() )
80 for (t=textline.first(); t; t=textline.next() )
82 h+=t->boundingRect().height();
83 if (w<t->boundingRect().width() )
84 w=t->boundingRect().width();
87 bbox.setSize (QSize(w,h));
90 QCanvasText* HeadingObj::newLine(QString s)
93 t = new QCanvasText(canvas);
98 t->setTextFlags(Qt::AlignLeft);
103 void HeadingObj::setText (QString s)
107 // remove old textlines and prepare generating new ones
110 // prevent empty textline, so at least a small selection stays
111 // visible for this heading
112 if (s.length()==0) s=" ";
114 int i=0; // index for actual search for ws
115 int j=0; // index of last ws
116 int k=0; // index of "<br>" or similar linebreak
117 int br=0; // width of found break, e.g. for <br> it is 4
119 // set the text and wrap lines
122 // ok, some people wanted manual linebreaks, here we go
123 k=s.find ("<br>",i,false);
129 i=s.find (" ",i,false);
131 { // no ws found at all in s
133 textline.append (newLine(s));
138 { // no ws found in actual search
139 if (s.length()<=textwidth)
141 textline.append (newLine(s));
145 textline.append (newLine(s.left(j)));
146 s=s.mid(j+1,s.length());
151 if (i>= 0 && i<=static_cast <int> (textwidth))
152 { // there is a ws in textwidth
155 // here is a linebreak
156 textline.append (newLine(s.left(i)));
157 s=s.mid(i+br,s.length());
168 if (i>static_cast <int> (textwidth) )
171 { // a ws out of textwidth, but we have also one in
172 textline.append (newLine(s.left(j)));
173 s=s.mid(j+1,s.length());
177 { // a ws out of text, but none in
178 textline.append (newLine(s.left(i)));
179 s=s.mid(i+1,s.length());
187 setVisibility (visible);
191 QString HeadingObj::text ()
196 void HeadingObj::setFont (QFont f)
205 QFont HeadingObj::getFont()
211 void HeadingObj::setColor (QColor c)
217 for (t=textline.first(); t; t=textline.next() )
222 QColor HeadingObj::getColor()
227 void HeadingObj::setVisibility (bool v)
229 MapObj::setVisibility(v);
231 for (t=textline.first(); t; t=textline.next() )
238 int HeadingObj::getHeight ()
240 return bbox.height();
243 int HeadingObj::getWidth()