oops. removed debugging output from xml.cpp
1 #include "headingobj.h"
4 /////////////////////////////////////////////////////////////////
6 /////////////////////////////////////////////////////////////////
7 HeadingObj::HeadingObj() : MapObj()
9 // cout << "Const HeadingObj ()\n";
13 HeadingObj::HeadingObj(QCanvas* c) :MapObj(c)
15 // cout << "Const HeadingObj\n";
19 HeadingObj::~HeadingObj()
24 void HeadingObj::init()
26 textline.setAutoDelete (TRUE);
28 color=QColor ("black");
32 void HeadingObj::copy(HeadingObj *other)
35 textwidth=other->textwidth;
38 setText (other->text() );
41 void HeadingObj::move(double x, double y)
45 int h; // height of a textline
46 int ho; // offset of height while drawing all lines
48 if (textline.first() )
49 h=textline.first()->boundingRect().height();
54 for (t=textline.first(); t; t=textline.next() )
62 void HeadingObj::moveBy(double x, double y)
64 move (x+absPos.x(),y+absPos.y() );
67 void HeadingObj::positionBBox()
69 bbox.setX (absPos.x());
70 bbox.setY (absPos.y());
73 void HeadingObj::calcBBoxSize()
77 // Using Backspace an empty heading might easily be created, then there
78 // would be textline.first()==NULL This can be worked around by the following, but
79 // then no selection would be visible, thus we prevent it in ::setText()
80 if (!textline.isEmpty() )
83 for (t=textline.first(); t; t=textline.next() )
85 h+=t->boundingRect().height();
86 if (w<t->boundingRect().width() )
87 w=t->boundingRect().width();
90 bbox.setSize (QSize(w,h));
93 QCanvasText* HeadingObj::newLine(QString s)
96 t = new QCanvasText(canvas);
101 t->setTextFlags(Qt::AlignLeft);
106 void HeadingObj::setText (QString s)
110 // remove old textlines and prepare generating new ones
113 // prevent empty textline, so at least a small selection stays
114 // visible for this heading
115 if (s.length()==0) s=" ";
117 int i=0; // index for actual search for ws
118 int j=0; // index of last ws
119 int k=0; // index of "<br>" or similar linebreak
120 int br=0; // width of found break, e.g. for <br> it is 4
121 QRegExp re("<br.*/>");
122 re.setMinimal (true);
124 // set the text and wrap lines
127 // ok, some people wanted manual linebreaks, here we go
131 br=re.cap(0).length();
134 i=s.find (" ",i,false);
136 { // no ws found at all in s
138 textline.append (newLine(s));
143 { // no ws found in actual search
144 if (s.length()<=textwidth)
146 textline.append (newLine(s));
150 textline.append (newLine(s.left(j)));
151 s=s.mid(j+1,s.length());
156 if (i>= 0 && i<=static_cast <int> (textwidth))
157 { // there is a ws in textwidth
160 // here is a linebreak
161 textline.append (newLine(s.left(i)));
162 s=s.mid(i+br,s.length());
173 if (i>static_cast <int> (textwidth) )
176 { // a ws out of textwidth, but we have also one in
177 textline.append (newLine(s.left(j)));
178 s=s.mid(j+1,s.length());
182 { // a ws out of text, but none in
183 textline.append (newLine(s.left(i)));
184 s=s.mid(i+1,s.length());
192 setVisibility (visible);
193 move (absPos.x(),absPos.y());
197 QString HeadingObj::text ()
202 void HeadingObj::setFont (QFont f)
211 QFont HeadingObj::getFont()
217 void HeadingObj::setColor (QColor c)
223 for (t=textline.first(); t; t=textline.next() )
228 QColor HeadingObj::getColor()
233 void HeadingObj::setVisibility (bool v)
235 MapObj::setVisibility(v);
237 for (t=textline.first(); t; t=textline.next() )
244 int HeadingObj::getHeight ()
246 return bbox.height();
249 int HeadingObj::getWidth()