5 #include <QGraphicsScene>
7 #include "misc.h" //for roof function
9 /////////////////////////////////////////////////////////////////
11 /////////////////////////////////////////////////////////////////
12 FrameObj::FrameObj(QGraphicsItem *parent) : MapObj(parent) { init(); }
14 FrameObj::~FrameObj() { clear(); }
21 penColor = QColor(Qt::black);
22 brushColor = QColor(Qt::white);
23 includeChildren = false;
26 void FrameObj::clear()
34 case RoundedRectangle:
45 padding = 0; // No frame requires also no padding
49 void FrameObj::move(double x, double y)
55 rectFrame->setPos(x, y);
57 case RoundedRectangle:
58 pathFrame->setPos(x, y);
61 ellipseFrame->setPos(x, y);
64 pathFrame->setPos(x, y);
69 void FrameObj::moveBy(double x, double y) { MapObj::moveBy(x, y); }
71 void FrameObj::positionBBox() {}
73 void FrameObj::calcBBoxSize() {}
75 void FrameObj::setRect(const QRectF &r)
84 QRectF(bbox.x(), bbox.y(), bbox.width(), bbox.height()));
87 case RoundedRectangle: {
88 QPointF tl = bbox.topLeft();
89 QPointF tr = bbox.topRight();
90 QPointF bl = bbox.bottomLeft();
91 QPointF br = bbox.bottomRight();
95 path.moveTo(tl.x() + n / 2, tl.y());
98 path.lineTo(tr.x() - n, tr.y());
99 path.arcTo(tr.x() - n, tr.y(), n, n, 90, -90);
100 path.lineTo(br.x(), br.y() - n);
101 path.arcTo(br.x() - n, br.y() - n, n, n, 0, -90);
102 path.lineTo(bl.x() + n, br.y());
103 path.arcTo(bl.x(), bl.y() - n, n, n, -90, -90);
104 path.lineTo(tl.x(), tl.y() + n);
105 path.arcTo(tl.x(), tl.y(), n, n, 180, -90);
106 pathFrame->setPath(path);
109 ellipseFrame->setRect(
110 QRectF(bbox.x(), bbox.y(), bbox.width(), bbox.height()));
111 xsize = 20; // max(bbox.width(), bbox.height()) / 4;
115 QPointF tl = bbox.topLeft();
116 QPointF tr = bbox.topRight();
117 QPointF bl = bbox.bottomLeft();
121 float w = bbox.width(); // width
122 float h = bbox.height(); // height
123 int n = w / 40; // number of intervalls
124 float d = w / n; // width of interwall
127 for (float i = 0; i < n; i++) {
128 path.cubicTo(tl.x() + i * d, tl.y() - 100 * roof((i + 0.5) / n),
129 tl.x() + (i + 1) * d,
130 tl.y() - 100 * roof((i + 0.5) / n),
131 tl.x() + (i + 1) * d + 20 * roof((i + 1) / n),
132 tl.y() - 50 * roof((i + 1) / n));
137 for (float i = 0; i < n; i++) {
138 path.cubicTo(tr.x() + 100 * roof((i + 0.5) / n), tr.y() + i * d,
139 tr.x() + 100 * roof((i + 0.5) / n),
140 tr.y() + (i + 1) * d, tr.x() + 60 * roof((i + 1) / n),
141 tr.y() + (i + 1) * d);
146 for (float i = n; i > 0; i--) {
147 path.cubicTo(bl.x() + i * d, bl.y() + 100 * roof((i - 0.5) / n),
148 bl.x() + (i - 1) * d,
149 bl.y() + 100 * roof((i - 0.5) / n),
150 bl.x() + (i - 1) * d + 20 * roof((i - 1) / n),
151 bl.y() + 50 * roof((i - 1) / n));
156 for (float i = n; i > 0; i--) {
157 path.cubicTo(tl.x() - 100 * roof((i - 0.5) / n), tr.y() + i * d,
158 tl.x() - 100 * roof((i - 0.5) / n),
159 tr.y() + (i - 1) * d, tl.x() - 60 * roof((i - 1) / n),
160 tr.y() + (i - 1) * d);
162 pathFrame->setPath(path);
168 void FrameObj::setPadding(const int &i) { padding = i; }
170 int FrameObj::getPadding()
178 qreal FrameObj::getTotalPadding() { return xsize + padding + borderWidth; }
180 qreal FrameObj::getXPadding() { return xsize; }
182 void FrameObj::setBorderWidth(const int &i)
188 int FrameObj::getBorderWidth() { return borderWidth; }
190 FrameObj::FrameType FrameObj::getFrameType() { return type; }
192 FrameObj::FrameType FrameObj::getFrameType(const QString &s)
194 if (s == "Rectangle")
196 else if (s == "RoundedRectangle")
197 return RoundedRectangle;
198 else if (s == "Ellipse")
200 else if (s == "Cloud")
205 QString FrameObj::getFrameTypeName()
211 case RoundedRectangle:
212 return "RoundedRectangle";
225 void FrameObj::setFrameType(const FrameType &t)
234 rectFrame = scene()->addRect(QRectF(0, 0, 0, 0), QPen(penColor),
236 rectFrame->setZValue(dZ_FRAME_LOW);
237 rectFrame->setParentItem(this);
240 case RoundedRectangle: {
242 pathFrame = scene()->addPath(path, QPen(penColor), brushColor);
243 pathFrame->setZValue(dZ_FRAME_LOW);
244 pathFrame->setParentItem(this);
248 ellipseFrame = scene()->addEllipse(QRectF(0, 0, 0, 0),
249 QPen(penColor), brushColor);
250 ellipseFrame->setZValue(dZ_FRAME_LOW);
251 ellipseFrame->setParentItem(this);
252 ellipseFrame->show();
256 pathFrame = scene()->addPath(path, QPen(penColor), brushColor);
257 pathFrame->setZValue(dZ_FRAME_LOW);
258 pathFrame->setParentItem(this);
264 setVisibility(visible);
267 void FrameObj::setFrameType(const QString &t)
269 if (t == "Rectangle")
270 FrameObj::setFrameType(Rectangle);
271 else if (t == "RoundedRectangle")
272 FrameObj::setFrameType(RoundedRectangle);
273 else if (t == "Ellipse")
274 FrameObj::setFrameType(Ellipse);
275 else if (t == "Cloud")
276 FrameObj::setFrameType(Cloud);
278 FrameObj::setFrameType(NoFrame);
281 void FrameObj::setPenColor(QColor col)
287 QColor FrameObj::getPenColor() { return penColor; }
289 void FrameObj::setBrushColor(QColor col)
295 QColor FrameObj::getBrushColor() { return brushColor; }
297 void FrameObj::setFrameIncludeChildren(bool b) { includeChildren = b; }
299 bool FrameObj::getFrameIncludeChildren() { return includeChildren; }
301 void FrameObj::repaint()
304 pen.setColor(penColor);
305 pen.setWidth(borderWidth);
306 QBrush brush(brushColor);
309 rectFrame->setPen(pen);
310 rectFrame->setBrush(brush);
312 case RoundedRectangle:
313 pathFrame->setPen(pen);
314 pathFrame->setBrush(brush);
317 ellipseFrame->setPen(pen);
318 ellipseFrame->setBrush(brush);
321 pathFrame->setPen(pen);
322 pathFrame->setBrush(brush);
329 void FrameObj::setZValue(double z)
335 rectFrame->setZValue(z);
337 case RoundedRectangle:
338 pathFrame->setZValue(z);
341 ellipseFrame->setZValue(z);
344 pathFrame->setZValue(z);
349 void FrameObj::setVisibility(bool v)
351 MapObj::setVisibility(v);
361 case RoundedRectangle:
369 ellipseFrame->show();
371 ellipseFrame->hide();
382 QString FrameObj::saveToDir()
384 QString frameTypeAttr = attribut("frameType", getFrameTypeName());
386 return singleElement("frame", frameTypeAttr);
388 QString penColAttr = attribut("penColor", penColor.name());
389 QString brushColAttr = attribut("brushColor", brushColor.name());
390 QString paddingAttr = attribut("padding", QString::number(padding));
391 QString borderWidthAttr =
392 attribut("borderWidth", QString::number(borderWidth));
395 incChildren = attribut("includeChildren", "true");
396 return singleElement("frame", frameTypeAttr + penColAttr + brushColAttr +
397 paddingAttr + borderWidthAttr +