]> git.sven.stormbind.net Git - sven/vym.git/blob - src/mapobj.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / mapobj.cpp
1 #include <QDebug>
2
3 #include "geometry.h"
4 #include "mapobj.h"
5 #include "misc.h"
6
7 /////////////////////////////////////////////////////////////////
8 // MapObj
9 /////////////////////////////////////////////////////////////////
10 MapObj::MapObj(QGraphicsItem *parent, TreeItem *ti) : QGraphicsItem(parent)
11 {
12     // qDebug() << "Const MapObj (this,ti)=("<<this<<","<<ti<<")";
13     treeItem = ti;
14     init();
15 }
16
17 MapObj::~MapObj()
18 {
19     // qDebug() << "Destr MapObj "<<this;
20     foreach (QGraphicsItem *i, childItems())
21         // Avoid tha QGraphicsScene deletes children
22         i->setParentItem(NULL);
23 }
24
25 void MapObj::init()
26 {
27     absPos = QPointF(0, 0);
28     visible = true;
29 }
30
31 void MapObj::copy(MapObj *other)
32 {
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()));
37 }
38
39 void MapObj::setTreeItem(TreeItem *ti) { treeItem = ti; }
40
41 TreeItem *MapObj::getTreeItem() const { return treeItem; }
42
43 qreal MapObj::x() { return getAbsPos().x(); }
44
45 qreal MapObj::y() { return getAbsPos().y(); }
46
47 qreal MapObj::width() { return bbox.width(); }
48
49 qreal MapObj::height() { return bbox.height(); }
50
51 QPointF MapObj::getAbsPos() { return absPos; }
52
53 QString MapObj::getPos() { return qpointFToString(absPos); }
54
55 void MapObj::move(double x, double y) { MapObj::move(QPointF(x, y)); }
56
57 void MapObj::move(QPointF p)
58 {
59     absPos = p;
60     bbox.moveTo(p);
61     clickPoly = QPolygonF(bbox);
62 }
63
64 void MapObj::moveBy(double x, double y)
65 {
66     QPointF v(x, y);
67     MapObj::move(absPos + v);
68     bbox.moveTo(bbox.topLeft() + v);
69     clickPoly.translate(v);
70 }
71
72 QRectF MapObj::boundingRect() const { return QRectF(); }
73
74 void MapObj::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
75
76 QRectF MapObj::getBBox() { return bbox; }
77
78 ConvexPolygon MapObj::getBoundingPolygon()
79 {
80     QPolygonF p;
81     p << bbox.topLeft() << bbox.topRight() << bbox.bottomRight()
82       << bbox.bottomLeft();
83     return p;
84 }
85
86 QPolygonF MapObj::getClickPoly() { return clickPoly; }
87
88 QPainterPath MapObj::getSelectionPath()
89 {
90     qreal d = 3; // Thickness of selection "border"
91     QPainterPath p;
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));
98     return p;
99 }
100
101 bool MapObj::isInClickBox(const QPointF &p)
102 {
103     return clickPoly.containsPoint(p, Qt::OddEvenFill);
104 }
105
106 QSizeF MapObj::getSize() { return bbox.size(); }
107
108 void MapObj::setRotation(const qreal &a) { angle = a; }
109
110 qreal MapObj::getRotation() { return angle; }
111
112 bool MapObj::isVisibleObj() { return visible; }
113
114 void MapObj::setVisibility(bool v) { visible = v; }
115
116 void MapObj::positionBBox() {}
117 void MapObj::calcBBoxSize() {}