insilmaril@754
|
1 |
#include "geometry.h"
|
insilmaril@0
|
2 |
#include "mapobj.h"
|
insilmaril@129
|
3 |
#include "misc.h"
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
6 |
// MapObj
|
insilmaril@0
|
7 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
8 |
MapObj::MapObj ()
|
insilmaril@0
|
9 |
{
|
insilmaril@408
|
10 |
//qWarning ( "Const MapObj (): Please set scene somehow!!!");
|
insilmaril@408
|
11 |
scene=NULL;
|
insilmaril@0
|
12 |
init ();
|
insilmaril@0
|
13 |
}
|
insilmaril@0
|
14 |
|
insilmaril@790
|
15 |
MapObj::MapObj (QGraphicsScene *s, TreeItem *ti)
|
insilmaril@0
|
16 |
{
|
insilmaril@0
|
17 |
// cout << "Const MapObj\n";
|
insilmaril@408
|
18 |
scene=s;
|
insilmaril@790
|
19 |
treeItem=ti;
|
insilmaril@0
|
20 |
init ();
|
insilmaril@0
|
21 |
}
|
insilmaril@0
|
22 |
|
insilmaril@0
|
23 |
|
insilmaril@0
|
24 |
MapObj::MapObj (MapObj* mo)
|
insilmaril@0
|
25 |
{
|
insilmaril@0
|
26 |
// cout << "CopyConst MapObj\n";
|
insilmaril@0
|
27 |
copy (mo);
|
insilmaril@0
|
28 |
}
|
insilmaril@0
|
29 |
|
insilmaril@0
|
30 |
MapObj::~MapObj ()
|
insilmaril@0
|
31 |
{
|
insilmaril@0
|
32 |
// cout << "Destr MapObj\n";
|
insilmaril@0
|
33 |
}
|
insilmaril@0
|
34 |
|
insilmaril@0
|
35 |
void MapObj::init ()
|
insilmaril@0
|
36 |
{
|
insilmaril@408
|
37 |
absPos=QPointF(0,0);
|
insilmaril@0
|
38 |
visible=true;
|
insilmaril@794
|
39 |
pi=NULL;
|
insilmaril@0
|
40 |
}
|
insilmaril@0
|
41 |
|
insilmaril@0
|
42 |
void MapObj::copy(MapObj* other)
|
insilmaril@0
|
43 |
{
|
insilmaril@408
|
44 |
// scene=other->scene; // already set in constr. of child, use that one...
|
insilmaril@0
|
45 |
absPos=other->absPos;
|
insilmaril@0
|
46 |
bbox.setX (other->bbox.x() );
|
insilmaril@0
|
47 |
bbox.setY (other->bbox.y() );
|
insilmaril@408
|
48 |
bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
|
insilmaril@0
|
49 |
}
|
insilmaril@0
|
50 |
|
insilmaril@790
|
51 |
void MapObj::setTreeItem (TreeItem *ti)
|
insilmaril@790
|
52 |
{
|
insilmaril@790
|
53 |
treeItem=ti;
|
insilmaril@790
|
54 |
}
|
insilmaril@790
|
55 |
|
insilmaril@790
|
56 |
TreeItem* MapObj::getTreeItem () const
|
insilmaril@790
|
57 |
{
|
insilmaril@790
|
58 |
return treeItem;
|
insilmaril@790
|
59 |
}
|
insilmaril@790
|
60 |
|
insilmaril@790
|
61 |
|
insilmaril@408
|
62 |
QGraphicsScene* MapObj::getScene()
|
insilmaril@0
|
63 |
{
|
insilmaril@408
|
64 |
return scene;
|
insilmaril@0
|
65 |
}
|
insilmaril@0
|
66 |
|
insilmaril@408
|
67 |
qreal MapObj::x()
|
insilmaril@0
|
68 |
{
|
insilmaril@0
|
69 |
return absPos.x();
|
insilmaril@0
|
70 |
}
|
insilmaril@0
|
71 |
|
insilmaril@408
|
72 |
qreal MapObj::y()
|
insilmaril@0
|
73 |
{
|
insilmaril@0
|
74 |
return absPos.y();
|
insilmaril@0
|
75 |
}
|
insilmaril@0
|
76 |
|
insilmaril@408
|
77 |
qreal MapObj::width()
|
insilmaril@0
|
78 |
{
|
insilmaril@0
|
79 |
return bbox.width();
|
insilmaril@0
|
80 |
}
|
insilmaril@0
|
81 |
|
insilmaril@408
|
82 |
qreal MapObj::height()
|
insilmaril@0
|
83 |
{
|
insilmaril@0
|
84 |
return bbox.height();
|
insilmaril@0
|
85 |
}
|
insilmaril@0
|
86 |
|
insilmaril@408
|
87 |
QPointF MapObj::getAbsPos()
|
insilmaril@227
|
88 |
{
|
insilmaril@227
|
89 |
return absPos;
|
insilmaril@227
|
90 |
}
|
insilmaril@227
|
91 |
|
insilmaril@129
|
92 |
QString MapObj::getPos()
|
insilmaril@129
|
93 |
{
|
insilmaril@792
|
94 |
return qpointFToString(absPos);
|
insilmaril@129
|
95 |
}
|
insilmaril@129
|
96 |
|
insilmaril@0
|
97 |
void MapObj::move (double x, double y)
|
insilmaril@0
|
98 |
{
|
insilmaril@408
|
99 |
absPos.setX( x);
|
insilmaril@408
|
100 |
absPos.setY( y);
|
insilmaril@408
|
101 |
bbox.moveTo(QPointF(x,y));
|
insilmaril@408
|
102 |
clickBox.moveTo(QPointF(x,y));
|
insilmaril@408
|
103 |
}
|
insilmaril@408
|
104 |
|
insilmaril@408
|
105 |
void MapObj::move (QPointF p)
|
insilmaril@408
|
106 |
{
|
insilmaril@408
|
107 |
absPos=p;
|
insilmaril@408
|
108 |
bbox.moveTo (p);
|
insilmaril@408
|
109 |
clickBox.moveTo (p);
|
insilmaril@0
|
110 |
}
|
insilmaril@0
|
111 |
|
insilmaril@0
|
112 |
void MapObj::moveBy (double x, double y)
|
insilmaril@0
|
113 |
{
|
insilmaril@336
|
114 |
MapObj::move (x+absPos.x(),y+absPos.y() );
|
insilmaril@408
|
115 |
bbox.moveTo (bbox.x()+x,bbox.y()+y);
|
insilmaril@408
|
116 |
clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
|
insilmaril@0
|
117 |
}
|
insilmaril@0
|
118 |
|
insilmaril@408
|
119 |
QRectF MapObj::getBBox()
|
insilmaril@0
|
120 |
{
|
insilmaril@0
|
121 |
return bbox;
|
insilmaril@0
|
122 |
}
|
insilmaril@0
|
123 |
|
insilmaril@792
|
124 |
ConvexPolygon MapObj::getBoundingPolygon()
|
insilmaril@792
|
125 |
{
|
insilmaril@792
|
126 |
QPolygonF p;
|
insilmaril@792
|
127 |
p<<bbox.topLeft()<<bbox.topRight()<<bbox.bottomRight()<<bbox.bottomLeft();
|
insilmaril@792
|
128 |
return p;
|
insilmaril@792
|
129 |
}
|
insilmaril@792
|
130 |
|
insilmaril@645
|
131 |
QRectF MapObj::getClickBox()
|
insilmaril@645
|
132 |
{
|
insilmaril@645
|
133 |
return clickBox;
|
insilmaril@645
|
134 |
}
|
insilmaril@175
|
135 |
|
insilmaril@754
|
136 |
bool MapObj::isInClickBox (const QPointF &p)
|
insilmaril@754
|
137 |
{
|
insilmaril@754
|
138 |
return isInBox (p,clickBox);
|
insilmaril@754
|
139 |
}
|
insilmaril@0
|
140 |
|
insilmaril@408
|
141 |
QSizeF MapObj::getSize()
|
insilmaril@0
|
142 |
{
|
insilmaril@0
|
143 |
return bbox.size();
|
insilmaril@0
|
144 |
}
|
insilmaril@0
|
145 |
|
insilmaril@0
|
146 |
|
insilmaril@0
|
147 |
bool MapObj::isVisibleObj()
|
insilmaril@0
|
148 |
{
|
insilmaril@0
|
149 |
return visible;
|
insilmaril@0
|
150 |
}
|
insilmaril@0
|
151 |
|
insilmaril@0
|
152 |
void MapObj::setVisibility(bool v)
|
insilmaril@0
|
153 |
{
|
insilmaril@0
|
154 |
visible=v;
|
insilmaril@0
|
155 |
}
|
insilmaril@93
|
156 |
|