7 /////////////////////////////////////////////////////////////////
9 /////////////////////////////////////////////////////////////////
10 MapObj::MapObj(QGraphicsItem *parent, TreeItem *ti) : QGraphicsItem(parent)
12 // qDebug() << "Const MapObj (this,ti)=("<<this<<","<<ti<<")";
19 // qDebug() << "Destr MapObj "<<this;
20 foreach (QGraphicsItem *i, childItems())
21 // Avoid tha QGraphicsScene deletes children
22 i->setParentItem(NULL);
27 absPos = QPointF(0, 0);
31 void MapObj::copy(MapObj *other)
33 absPos = other->absPos;
34 bbox.setX(other->bbox.x());
35 bbox.setY(other->bbox.y());
36 bbox.setSize(QSizeF(other->bbox.width(), other->bbox.height()));
39 void MapObj::setTreeItem(TreeItem *ti) { treeItem = ti; }
41 TreeItem *MapObj::getTreeItem() const { return treeItem; }
43 qreal MapObj::x() { return getAbsPos().x(); }
45 qreal MapObj::y() { return getAbsPos().y(); }
47 qreal MapObj::width() { return bbox.width(); }
49 qreal MapObj::height() { return bbox.height(); }
51 QPointF MapObj::getAbsPos() { return absPos; }
53 QString MapObj::getPos() { return qpointFToString(absPos); }
55 void MapObj::move(double x, double y) { MapObj::move(QPointF(x, y)); }
57 void MapObj::move(QPointF p)
61 clickPoly = QPolygonF(bbox);
64 void MapObj::moveBy(double x, double y)
67 MapObj::move(absPos + v);
68 bbox.moveTo(bbox.topLeft() + v);
69 clickPoly.translate(v);
72 QRectF MapObj::boundingRect() const { return QRectF(); }
74 void MapObj::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
76 QRectF MapObj::getBBox() { return bbox; }
78 ConvexPolygon MapObj::getBoundingPolygon()
81 p << bbox.topLeft() << bbox.topRight() << bbox.bottomRight()
86 QPolygonF MapObj::getClickPoly() { return clickPoly; }
88 QPainterPath MapObj::getSelectionPath()
90 qreal d = 3; // Thickness of selection "border"
92 QRectF br = clickPoly.boundingRect();
93 p.moveTo(br.topLeft() + QPointF(-d, -d));
94 p.lineTo(br.topRight() + QPointF(d, -d));
95 p.lineTo(br.bottomRight() + QPointF(d, d));
96 p.lineTo(br.bottomLeft() + QPointF(-d, d));
97 p.lineTo(br.topLeft() + QPointF(-d, -d));
101 bool MapObj::isInClickBox(const QPointF &p)
103 return clickPoly.containsPoint(p, Qt::OddEvenFill);
106 QSizeF MapObj::getSize() { return bbox.size(); }
108 void MapObj::setRotation(const qreal &a) { angle = a; }
110 qreal MapObj::getRotation() { return angle; }
112 bool MapObj::isVisibleObj() { return visible; }
114 void MapObj::setVisibility(bool v) { visible = v; }
116 void MapObj::positionBBox() {}
117 void MapObj::calcBBoxSize() {}