Runs basically on Mac now. Undo debug output still enabled
1 #include "headingobj.h"
4 /////////////////////////////////////////////////////////////////
6 /////////////////////////////////////////////////////////////////
7 HeadingObj::HeadingObj() : MapObj()
9 // cout << "Const HeadingObj ()\n";
13 HeadingObj::HeadingObj(Q3Canvas* c) :MapObj(c)
15 // cout << "Const HeadingObj\n";
19 HeadingObj::~HeadingObj()
24 void HeadingObj::init()
26 textline.setAutoDelete (TRUE);
28 color=QColor ("black");
33 void HeadingObj::copy(HeadingObj *other)
36 textwidth=other->textwidth;
39 setText (other->text() );
42 void HeadingObj::move(double x, double y)
46 int h; // height of a textline
47 int ho; // offset of height while drawing all lines
49 if (textline.first() )
50 h=textline.first()->boundingRect().height();
55 for (t=textline.first(); t; t=textline.next() )
63 void HeadingObj::moveBy(double x, double y)
65 move (x+absPos.x(),y+absPos.y() );
68 void HeadingObj::positionBBox()
70 bbox.setX (absPos.x());
71 bbox.setY (absPos.y());
74 void HeadingObj::calcBBoxSize()
78 // Using Backspace an empty heading might easily be created, then there
79 // would be textline.first()==NULL This can be worked around by the following, but
80 // then no selection would be visible, thus we prevent it in ::setText()
81 if (!textline.isEmpty() )
84 for (t=textline.first(); t; t=textline.next() )
86 h+=t->boundingRect().height();
87 if (w<t->boundingRect().width() )
88 w=t->boundingRect().width();
91 bbox.setSize (QSize(w,h));
94 Q3CanvasText* HeadingObj::newLine(QString s)
97 t = new Q3CanvasText(canvas);
102 t->setTextFlags(Qt::AlignLeft);
107 void HeadingObj::setText (QString s)
111 // remove old textlines and prepare generating new ones
114 // prevent empty textline, so at least a small selection stays
115 // visible for this heading
116 if (s.length()==0) s=" ";
118 int i=0; // index for actual search for ws
119 int j=0; // index of last ws
120 int k=0; // index of "<br>" or similar linebreak
121 int br=0; // width of found break, e.g. for <br> it is 4
122 QRegExp re("<br.*/>");
123 re.setMinimal (true);
125 // set the text and wrap lines
128 // ok, some people wanted manual linebreaks, here we go
132 br=re.cap(0).length();
135 i=s.find (" ",i,false);
137 { // no ws found at all in s
139 textline.append (newLine(s));
144 { // no ws found in actual search
145 if (s.length()<=textwidth)
147 textline.append (newLine(s));
151 textline.append (newLine(s.left(j)));
152 s=s.mid(j+1,s.length());
157 if (i>= 0 && i<=static_cast <int> (textwidth))
158 { // there is a ws in textwidth
161 // here is a linebreak
162 textline.append (newLine(s.left(i)));
163 s=s.mid(i+br,s.length());
174 if (i>static_cast <int> (textwidth) )
177 { // a ws out of textwidth, but we have also one in
178 textline.append (newLine(s.left(j)));
179 s=s.mid(j+1,s.length());
183 { // a ws out of text, but none in
184 textline.append (newLine(s.left(i)));
185 s=s.mid(i+1,s.length());
193 setVisibility (visible);
194 move (absPos.x(),absPos.y());
198 QString HeadingObj::text ()
203 void HeadingObj::setFont (QFont f)
212 QFont HeadingObj::getFont()
218 void HeadingObj::setColor (QColor c)
224 for (t=textline.first(); t; t=textline.next() )
229 QColor HeadingObj::getColor()
234 void HeadingObj::setVisibility (bool v)
236 MapObj::setVisibility(v);
238 for (t=textline.first(); t; t=textline.next() )
245 int HeadingObj::getHeight ()
247 return bbox.height();
250 int HeadingObj::getWidth()