]> git.sven.stormbind.net Git - sven/vym.git/blob - mapobj.cpp
Import Upstream version 2.6.11
[sven/vym.git] / 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     boundingPolygon=NULL;
30 }
31
32 void MapObj::copy(MapObj* other)
33 {
34     absPos=other->absPos;
35     bbox.setX (other->bbox.x() );
36     bbox.setY (other->bbox.y() );
37     bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
38 }
39
40 void MapObj::setTreeItem (TreeItem *ti)
41 {
42     treeItem=ti;
43 }
44
45 TreeItem* MapObj::getTreeItem () const
46 {
47     return treeItem;
48 }
49
50 qreal MapObj::x() 
51 {
52     return getAbsPos().x();
53 }
54
55 qreal MapObj::y() 
56 {
57     return getAbsPos().y();
58 }
59
60 qreal MapObj::width() 
61 {
62     return bbox.width();
63 }
64
65 qreal MapObj::height() 
66 {
67     return bbox.height();
68 }
69
70 QPointF MapObj::getAbsPos() 
71 {
72     return absPos;
73 }
74
75 QString MapObj::getPos()
76 {
77     return qpointFToString(absPos);
78 }
79
80 void MapObj::move (double x, double y) 
81 {
82     MapObj::move (QPointF(x,y));
83 }
84
85 void MapObj::move (QPointF p)
86 {
87     absPos=p;
88     bbox.moveTo (p);
89     clickPoly=QPolygonF (bbox);
90 }
91
92 void MapObj::moveBy (double x, double y) 
93 {
94     QPointF v(x,y);
95     MapObj::move (absPos + v );
96     bbox.moveTo (bbox.topLeft() + v);
97     clickPoly.translate (v);
98 }
99
100 QRectF MapObj::boundingRect () const 
101 {
102     return QRectF();
103 }
104
105 void MapObj::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
106 {
107 }
108
109 QRectF MapObj::getBBox()
110 {
111     return bbox;
112 }
113
114 ConvexPolygon MapObj::getBoundingPolygon()
115 {
116     QPolygonF p;
117     p<<bbox.topLeft()<<bbox.topRight()<<bbox.bottomRight()<<bbox.bottomLeft();
118     return p;
119 }
120
121 QPolygonF MapObj::getClickPoly()
122 {
123     return clickPoly;
124 }
125
126 QPainterPath MapObj::getClickPath()
127 {
128     QPainterPath p;
129     QRectF br=clickPoly.boundingRect();
130     p.moveTo (br.topLeft() );
131     p.lineTo (br.topRight() );
132     p.lineTo (br.bottomRight() );
133     p.lineTo (br.bottomLeft() );
134     p.lineTo (br.topLeft() );
135     return p;
136 }
137
138 bool MapObj::isInClickBox (const QPointF &p)
139 {
140     return  clickPoly.containsPoint (p,Qt::OddEvenFill);
141 }
142
143 QSizeF MapObj::getSize()
144 {
145     return bbox.size();
146 }
147
148
149 void MapObj::setRotation (const qreal &a)
150 {
151     angle=a;
152 }
153
154 qreal MapObj::getRotation ()
155 {
156     return angle;
157 }
158
159 bool MapObj::isVisibleObj()
160 {
161     return visible;
162 }
163
164 void MapObj::setVisibility(bool v)
165 {
166     visible=v;
167 }
168
169 void MapObj::positionBBox() {}
170 void MapObj::calcBBoxSize() {}