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)
44 int h; // height of a textline
45 int ho; // offset of height while drawing all lines
47 if (textline.first() )
48 h=textline.first()->boundingRect().height();
53 for (t=textline.first(); t; t=textline.next() )
61 void HeadingObj::moveBy(double x, double y)
63 move (x+absPos.x(),y+absPos.y() );
66 void HeadingObj::positionBBox()
68 bbox.setX (absPos.x());
69 bbox.setY (absPos.y());
72 void HeadingObj::calcBBoxSize()
76 // Using Backspace an empty heading might easily be created, then there
77 // would be textline.first()==NULL This can be worked around by the following, but
78 // then no selection would be visible, thus we prevent it in ::setText()
79 if (!textline.isEmpty() )
82 for (t=textline.first(); t; t=textline.next() )
84 h+=t->boundingRect().height();
85 if (w<t->boundingRect().width() )
86 w=t->boundingRect().width();
89 bbox.setSize (QSize(w,h));
92 QCanvasText* HeadingObj::newLine(QString s)
95 t = new QCanvasText(canvas);
100 t->setTextFlags(Qt::AlignLeft);
105 void HeadingObj::setText (QString s)
109 // remove old textlines and prepare generating new ones
112 // prevent empty textline, so at least a small selection stays
113 // visible for this heading
114 if (s.length()==0) s=" ";
116 int i=0; // index for actual search for ws
117 int j=0; // index of last ws
118 int k=0; // index of "<br>" or similar linebreak
119 int br=0; // width of found break, e.g. for <br> it is 4
121 // set the text and wrap lines
124 // ok, some people wanted manual linebreaks, here we go
125 k=s.find ("<br>",i,false);
131 i=s.find (" ",i,false);
133 { // no ws found at all in s
135 textline.append (newLine(s));
140 { // no ws found in actual search
141 if (s.length()<=textwidth)
143 textline.append (newLine(s));
147 textline.append (newLine(s.left(j)));
148 s=s.mid(j+1,s.length());
153 if (i>= 0 && i<=static_cast <int> (textwidth))
154 { // there is a ws in textwidth
157 // here is a linebreak
158 textline.append (newLine(s.left(i)));
159 s=s.mid(i+br,s.length());
170 if (i>static_cast <int> (textwidth) )
173 { // a ws out of textwidth, but we have also one in
174 textline.append (newLine(s.left(j)));
175 s=s.mid(j+1,s.length());
179 { // a ws out of text, but none in
180 textline.append (newLine(s.left(i)));
181 s=s.mid(i+1,s.length());
189 setVisibility (visible);
190 move (absPos.x(),absPos.y());
194 QString HeadingObj::text ()
199 void HeadingObj::setFont (QFont f)
208 QFont HeadingObj::getFont()
214 void HeadingObj::setColor (QColor c)
220 for (t=textline.first(); t; t=textline.next() )
225 QColor HeadingObj::getColor()
230 void HeadingObj::setVisibility (bool v)
232 MapObj::setVisibility(v);
234 for (t=textline.first(); t; t=textline.next() )
241 int HeadingObj::getHeight ()
243 return bbox.height();
246 int HeadingObj::getWidth()