changed MapEditor::undo and saveState so that selection is saved, too (bgugfix)
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);
102 void HeadingObj::setText (QString s)
106 // remove old textlines and prepare generating new ones
109 // prevent empty textline, so at least a small selection stays
110 // visible for this heading
111 if (s.length()==0) s=" ";
113 int i=0; // index for actual search for ws
114 int j=0; // index of last ws
115 int k=0; // index of "<br>" or similar linebreak
116 int br=0; // width of found break, e.g. for <br> it is 4
118 // set the text and wrap lines
121 // ok, some people wanted manual linebreaks, here we go
122 k=s.find ("<br>",i,false);
128 i=s.find (" ",i,false);
130 { // no ws found at all in s
132 textline.append (newLine(s));
137 { // no ws found in actual search
138 if (s.length()<=textwidth)
140 textline.append (newLine(s));
144 textline.append (newLine(s.left(j)));
145 s=s.mid(j+1,s.length());
150 if (i>= 0 && i<=static_cast <int> (textwidth))
151 { // there is a ws in textwidth
154 // here is a linebreak
155 textline.append (newLine(s.left(i)));
156 s=s.mid(i+br,s.length());
167 if (i>static_cast <int> (textwidth) )
170 { // a ws out of textwidth, but we have also one in
171 textline.append (newLine(s.left(j)));
172 s=s.mid(j+1,s.length());
176 { // a ws out of text, but none in
177 textline.append (newLine(s.left(i)));
178 s=s.mid(i+1,s.length());
186 setVisibility (visible);
190 QString HeadingObj::text ()
195 void HeadingObj::setFont (QFont f)
204 QFont HeadingObj::getFont()
210 void HeadingObj::setColor (QColor c)
216 for (t=textline.first(); t; t=textline.next() )
221 QColor HeadingObj::getColor()
226 void HeadingObj::setVisibility (bool v)
228 MapObj::setVisibility(v);
230 for (t=textline.first(); t; t=textline.next() )
237 int HeadingObj::getHeight ()
239 return bbox.height();
242 int HeadingObj::getWidth()