insilmaril@0
|
1 |
#include "mapobj.h"
|
insilmaril@129
|
2 |
#include "misc.h"
|
insilmaril@0
|
3 |
|
insilmaril@0
|
4 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
5 |
// MapObj
|
insilmaril@0
|
6 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
7 |
MapObj::MapObj ()
|
insilmaril@0
|
8 |
{
|
insilmaril@408
|
9 |
//qWarning ( "Const MapObj (): Please set scene somehow!!!");
|
insilmaril@408
|
10 |
scene=NULL;
|
insilmaril@0
|
11 |
init ();
|
insilmaril@0
|
12 |
}
|
insilmaril@0
|
13 |
|
insilmaril@408
|
14 |
MapObj::MapObj (QGraphicsScene *s)
|
insilmaril@0
|
15 |
{
|
insilmaril@0
|
16 |
// cout << "Const MapObj\n";
|
insilmaril@408
|
17 |
scene=s;
|
insilmaril@0
|
18 |
init ();
|
insilmaril@0
|
19 |
}
|
insilmaril@0
|
20 |
|
insilmaril@0
|
21 |
|
insilmaril@0
|
22 |
MapObj::MapObj (MapObj* mo)
|
insilmaril@0
|
23 |
{
|
insilmaril@0
|
24 |
// cout << "CopyConst MapObj\n";
|
insilmaril@0
|
25 |
copy (mo);
|
insilmaril@0
|
26 |
}
|
insilmaril@0
|
27 |
|
insilmaril@0
|
28 |
MapObj::~MapObj ()
|
insilmaril@0
|
29 |
{
|
insilmaril@0
|
30 |
// cout << "Destr MapObj\n";
|
insilmaril@0
|
31 |
}
|
insilmaril@0
|
32 |
|
insilmaril@0
|
33 |
void MapObj::init ()
|
insilmaril@0
|
34 |
{
|
insilmaril@408
|
35 |
absPos=QPointF(0,0);
|
insilmaril@0
|
36 |
visible=true;
|
insilmaril@0
|
37 |
}
|
insilmaril@0
|
38 |
|
insilmaril@0
|
39 |
void MapObj::copy(MapObj* other)
|
insilmaril@0
|
40 |
{
|
insilmaril@408
|
41 |
// scene=other->scene; // already set in constr. of child, use that one...
|
insilmaril@0
|
42 |
absPos=other->absPos;
|
insilmaril@0
|
43 |
bbox.setX (other->bbox.x() );
|
insilmaril@0
|
44 |
bbox.setY (other->bbox.y() );
|
insilmaril@408
|
45 |
bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
|
insilmaril@0
|
46 |
}
|
insilmaril@0
|
47 |
|
insilmaril@408
|
48 |
QGraphicsScene* MapObj::getScene()
|
insilmaril@0
|
49 |
{
|
insilmaril@408
|
50 |
return scene;
|
insilmaril@0
|
51 |
}
|
insilmaril@0
|
52 |
|
insilmaril@408
|
53 |
qreal MapObj::x()
|
insilmaril@0
|
54 |
{
|
insilmaril@0
|
55 |
return absPos.x();
|
insilmaril@0
|
56 |
}
|
insilmaril@0
|
57 |
|
insilmaril@408
|
58 |
qreal MapObj::y()
|
insilmaril@0
|
59 |
{
|
insilmaril@0
|
60 |
return absPos.y();
|
insilmaril@0
|
61 |
}
|
insilmaril@0
|
62 |
|
insilmaril@408
|
63 |
qreal MapObj::width()
|
insilmaril@0
|
64 |
{
|
insilmaril@0
|
65 |
return bbox.width();
|
insilmaril@0
|
66 |
}
|
insilmaril@0
|
67 |
|
insilmaril@408
|
68 |
qreal MapObj::height()
|
insilmaril@0
|
69 |
{
|
insilmaril@0
|
70 |
return bbox.height();
|
insilmaril@0
|
71 |
}
|
insilmaril@0
|
72 |
|
insilmaril@408
|
73 |
QPointF MapObj::getAbsPos()
|
insilmaril@227
|
74 |
{
|
insilmaril@227
|
75 |
return absPos;
|
insilmaril@227
|
76 |
}
|
insilmaril@227
|
77 |
|
insilmaril@129
|
78 |
QString MapObj::getPos()
|
insilmaril@129
|
79 |
{
|
insilmaril@408
|
80 |
return qpointfToString(absPos);
|
insilmaril@129
|
81 |
}
|
insilmaril@129
|
82 |
|
insilmaril@0
|
83 |
void MapObj::move (double x, double y)
|
insilmaril@0
|
84 |
{
|
insilmaril@408
|
85 |
absPos.setX( x);
|
insilmaril@408
|
86 |
absPos.setY( y);
|
insilmaril@408
|
87 |
bbox.moveTo(QPointF(x,y));
|
insilmaril@408
|
88 |
clickBox.moveTo(QPointF(x,y));
|
insilmaril@408
|
89 |
}
|
insilmaril@408
|
90 |
|
insilmaril@408
|
91 |
void MapObj::move (QPointF p)
|
insilmaril@408
|
92 |
{
|
insilmaril@408
|
93 |
absPos=p;
|
insilmaril@408
|
94 |
bbox.moveTo (p);
|
insilmaril@408
|
95 |
clickBox.moveTo (p);
|
insilmaril@0
|
96 |
}
|
insilmaril@0
|
97 |
|
insilmaril@0
|
98 |
void MapObj::moveBy (double x, double y)
|
insilmaril@0
|
99 |
{
|
insilmaril@336
|
100 |
MapObj::move (x+absPos.x(),y+absPos.y() );
|
insilmaril@408
|
101 |
bbox.moveTo (bbox.x()+x,bbox.y()+y);
|
insilmaril@408
|
102 |
clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
|
insilmaril@0
|
103 |
}
|
insilmaril@0
|
104 |
|
insilmaril@408
|
105 |
bool MapObj::inBox(const QPointF &p)
|
insilmaril@0
|
106 |
{
|
insilmaril@408
|
107 |
/* FIXME testing QT4 only
|
insilmaril@408
|
108 |
cout << "MO::inBox "<<p<<" "<<
|
insilmaril@408
|
109 |
clickBox.left()<<","<<
|
insilmaril@408
|
110 |
clickBox.right()<<","<<
|
insilmaril@408
|
111 |
clickBox.top()<<","<<
|
insilmaril@408
|
112 |
clickBox.bottom()<<endl;
|
insilmaril@408
|
113 |
*/
|
insilmaril@175
|
114 |
if (p.x() >= clickBox.left() && p.x() <= clickBox.right()
|
insilmaril@175
|
115 |
&& p.y() <= clickBox.bottom() && p.y() >= clickBox.top() )
|
insilmaril@166
|
116 |
return true;
|
insilmaril@0
|
117 |
return false;
|
insilmaril@0
|
118 |
}
|
insilmaril@0
|
119 |
|
insilmaril@408
|
120 |
QRectF MapObj::getBBox()
|
insilmaril@0
|
121 |
{
|
insilmaril@0
|
122 |
return bbox;
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@408
|
125 |
QRectF MapObj::addBBox(QRectF r1, QRectF r2)
|
insilmaril@175
|
126 |
{
|
insilmaril@408
|
127 |
// Find smallest QRectF containing given rectangles
|
insilmaril@175
|
128 |
|
insilmaril@408
|
129 |
QRectF n;
|
insilmaril@0
|
130 |
// Set left border
|
insilmaril@0
|
131 |
if (r1.left() <= r2.left() )
|
insilmaril@0
|
132 |
n.setLeft(r1.left() );
|
insilmaril@0
|
133 |
else
|
insilmaril@0
|
134 |
n.setLeft(r2.left() );
|
insilmaril@0
|
135 |
|
insilmaril@0
|
136 |
// Set top border
|
insilmaril@0
|
137 |
if (r1.top() <= r2.top() )
|
insilmaril@0
|
138 |
n.setTop(r1.top() );
|
insilmaril@0
|
139 |
else
|
insilmaril@0
|
140 |
n.setTop(r2.top() );
|
insilmaril@0
|
141 |
|
insilmaril@0
|
142 |
// Set right border
|
insilmaril@0
|
143 |
if (r1.right() <= r2.right() )
|
insilmaril@0
|
144 |
n.setRight(r2.right() );
|
insilmaril@0
|
145 |
else
|
insilmaril@0
|
146 |
n.setRight(r1.right() );
|
insilmaril@0
|
147 |
|
insilmaril@0
|
148 |
// Set bottom
|
insilmaril@0
|
149 |
if (r1.bottom() <= r2.bottom() )
|
insilmaril@0
|
150 |
n.setBottom(r2.bottom() );
|
insilmaril@0
|
151 |
else
|
insilmaril@0
|
152 |
n.setBottom(r1.bottom() );
|
insilmaril@0
|
153 |
return n;
|
insilmaril@0
|
154 |
}
|
insilmaril@0
|
155 |
|
insilmaril@408
|
156 |
QSizeF MapObj::getSize()
|
insilmaril@0
|
157 |
{
|
insilmaril@0
|
158 |
return bbox.size();
|
insilmaril@0
|
159 |
}
|
insilmaril@0
|
160 |
|
insilmaril@0
|
161 |
|
insilmaril@0
|
162 |
bool MapObj::isVisibleObj()
|
insilmaril@0
|
163 |
{
|
insilmaril@0
|
164 |
return visible;
|
insilmaril@0
|
165 |
}
|
insilmaril@0
|
166 |
|
insilmaril@0
|
167 |
void MapObj::setVisibility(bool v)
|
insilmaril@0
|
168 |
{
|
insilmaril@0
|
169 |
visible=v;
|
insilmaril@0
|
170 |
}
|
insilmaril@93
|
171 |
|