5 #include <QGraphicsScene>
7 #include "misc.h" //for roof function
9 /////////////////////////////////////////////////////////////////
11 /////////////////////////////////////////////////////////////////
12 FrameObj::FrameObj(QGraphicsItem *parent) :MapObj(parent)
27 penColor=QColor (Qt::black);
28 brushColor=QColor (Qt::white);
29 includeChildren=false;
32 void FrameObj::clear()
41 case RoundedRectangle:
52 padding=0; // No frame requires also no padding
56 void FrameObj::move(double x, double y)
63 rectFrame->setPos (x,y);
65 case RoundedRectangle:
66 pathFrame->setPos (x,y);
69 ellipseFrame->setPos (x,y);
72 pathFrame->setPos (x,y);
77 void FrameObj::moveBy(double x, double y)
82 void FrameObj::positionBBox()
86 void FrameObj::calcBBoxSize()
90 void FrameObj::setRect(const QRectF &r)
99 rectFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
102 case RoundedRectangle:
104 QPointF tl=bbox.topLeft();
105 QPointF tr=bbox.topRight();
106 QPointF bl=bbox.bottomLeft();
107 QPointF br=bbox.bottomRight();
111 path.moveTo (tl.x() +n/2, tl.y());
114 path.lineTo (tr.x()-n, tr.y());
115 path.arcTo (tr.x()-n, tr.y(), n, n,90,-90);
116 path.lineTo (br.x() , br.y()-n);
117 path.arcTo (br.x()-n, br.y()-n, n, n,0,-90);
118 path.lineTo (bl.x()+n, br.y());
119 path.arcTo (bl.x() , bl.y()-n, n, n,-90,-90);
120 path.lineTo (tl.x() , tl.y()+n);
121 path.arcTo (tl.x() , tl.y(), n, n,180,-90);
122 pathFrame->setPath(path);
126 ellipseFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
127 xsize=20;//max(bbox.width(), bbox.height()) / 4;
131 QPointF tl=bbox.topLeft();
132 QPointF tr=bbox.topRight();
133 QPointF bl=bbox.bottomLeft();
137 float w=bbox.width(); // width
138 float h=bbox.height(); // height
139 int n=w/40; // number of intervalls
140 float d=w/n; // width of interwall
143 for (float i=0; i<n; i++)
146 tl.x() + i*d, tl.y()- 100*roof ((i+0.5)/n) ,
147 tl.x() + (i+1)*d, tl.y()- 100*roof ((i+0.5)/n) ,
148 tl.x() + (i+1)*d + 20*roof ((i+1)/n), tl.y()- 50*roof((i+1)/n) );
153 for (float i=0; i<n; i++)
156 tr.x()+ 100*roof ((i+0.5)/n) , tr.y() + i*d,
157 tr.x()+ 100*roof ((i+0.5)/n) , tr.y() + (i+1)*d,
158 tr.x() + 60*roof ((i+1)/n) , tr.y() + (i+1)*d );
163 for (float i=n; i>0; i--)
166 bl.x() + i*d, bl.y()+ 100*roof ((i-0.5)/n) ,
167 bl.x() + (i-1)*d, bl.y()+ 100*roof ((i-0.5)/n) ,
168 bl.x() + (i-1)*d + 20*roof ((i-1)/n), bl.y()+ 50*roof((i-1)/n) );
173 for (float i=n; i>0; i--)
176 tl.x()- 100*roof ((i-0.5)/n) , tr.y() + i*d,
177 tl.x()- 100*roof ((i-0.5)/n) , tr.y() + (i-1)*d,
178 tl.x()- 60*roof ((i-1)/n) , tr.y() + (i-1)*d );
180 pathFrame->setPath(path);
186 void FrameObj::setPadding (const int &i)
191 int FrameObj::getPadding()
199 qreal FrameObj::getTotalPadding()
201 return xsize + padding + borderWidth;
204 qreal FrameObj::getXPadding()
209 void FrameObj::setBorderWidth (const int &i)
215 int FrameObj::getBorderWidth()
220 FrameObj::FrameType FrameObj::getFrameType()
225 FrameObj::FrameType FrameObj::getFrameType(const QString &s)
229 else if (s=="RoundedRectangle")
230 return RoundedRectangle;
231 else if (s=="Ellipse")
238 QString FrameObj::getFrameTypeName()
245 case RoundedRectangle:
246 return "RoundedRectangle";
259 void FrameObj::setFrameType(const FrameType &t)
270 rectFrame = scene()->addRect(QRectF(0,0,0,0), QPen(penColor), brushColor);
271 rectFrame->setZValue(dZ_FRAME_LOW);
272 rectFrame->setParentItem (this);
275 case RoundedRectangle:
278 pathFrame = scene()->addPath(path, QPen(penColor), brushColor);
279 pathFrame->setZValue(dZ_FRAME_LOW);
280 pathFrame->setParentItem (this);
285 ellipseFrame = scene()->addEllipse(QRectF(0,0,0,0), QPen(penColor), brushColor);
286 ellipseFrame->setZValue(dZ_FRAME_LOW);
287 ellipseFrame->setParentItem (this);
288 ellipseFrame->show();
293 pathFrame = scene()->addPath(path, QPen(penColor), brushColor);
294 pathFrame->setZValue(dZ_FRAME_LOW);
295 pathFrame->setParentItem (this);
301 setVisibility (visible);
304 void FrameObj::setFrameType(const QString &t)
307 FrameObj::setFrameType (Rectangle);
308 else if (t=="RoundedRectangle")
309 FrameObj::setFrameType (RoundedRectangle);
310 else if (t=="Ellipse")
311 FrameObj::setFrameType (Ellipse);
313 FrameObj::setFrameType (Cloud);
315 FrameObj::setFrameType (NoFrame);
318 void FrameObj::setPenColor (QColor col)
324 QColor FrameObj::getPenColor ()
329 void FrameObj::setBrushColor (QColor col)
335 QColor FrameObj::getBrushColor ()
340 void FrameObj::setFrameIncludeChildren(bool b)
345 bool FrameObj::getFrameIncludeChildren()
347 return includeChildren;
350 void FrameObj::repaint()
353 pen.setColor (penColor);
354 pen.setWidth (borderWidth);
355 QBrush brush (brushColor);
359 rectFrame->setPen (pen);
360 rectFrame->setBrush (brush);
362 case RoundedRectangle:
363 pathFrame->setPen (pen);
364 pathFrame->setBrush (brush);
367 ellipseFrame->setPen (pen);
368 ellipseFrame->setBrush (brush);
371 pathFrame->setPen (pen);
372 pathFrame->setBrush (brush);
379 void FrameObj::setZValue (double z)
386 rectFrame->setZValue (z);
388 case RoundedRectangle:
389 pathFrame->setZValue (z);
392 ellipseFrame->setZValue (z);
395 pathFrame->setZValue (z);
400 void FrameObj::setVisibility (bool v)
402 MapObj::setVisibility(v);
413 case RoundedRectangle:
421 ellipseFrame->show();
423 ellipseFrame->hide();
434 QString FrameObj::saveToDir ()
436 QString frameTypeAttr=attribut ("frameType",getFrameTypeName());
438 return singleElement ("frame", frameTypeAttr);
440 QString penColAttr=attribut ("penColor",penColor.name() );
441 QString brushColAttr=attribut ("brushColor",brushColor.name() );
442 QString paddingAttr=attribut ("padding",QString::number (padding) );
443 QString borderWidthAttr=attribut ("borderWidth",QString::number (borderWidth) );
446 incChildren=attribut ("includeChildren","true");
447 return singleElement (
448 "frame",frameTypeAttr +