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@166
|
9 |
//qWarning ( "Const MapObj (): Please set canvas somehow!!!");
|
insilmaril@166
|
10 |
canvas=NULL;
|
insilmaril@0
|
11 |
init ();
|
insilmaril@0
|
12 |
}
|
insilmaril@0
|
13 |
|
insilmaril@0
|
14 |
MapObj::MapObj (QCanvas* c)
|
insilmaril@0
|
15 |
{
|
insilmaril@0
|
16 |
// cout << "Const MapObj\n";
|
insilmaril@0
|
17 |
canvas=c;
|
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@0
|
35 |
absPos=QPoint(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@0
|
41 |
// canvas=other->canvas; // 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@0
|
45 |
bbox.setSize (QSize(other->bbox.width(), other->bbox.height() ) );
|
insilmaril@0
|
46 |
}
|
insilmaril@0
|
47 |
|
insilmaril@0
|
48 |
QCanvas* MapObj::getCanvas()
|
insilmaril@0
|
49 |
{
|
insilmaril@0
|
50 |
return canvas;
|
insilmaril@0
|
51 |
}
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
int MapObj::x()
|
insilmaril@0
|
54 |
{
|
insilmaril@0
|
55 |
return absPos.x();
|
insilmaril@0
|
56 |
}
|
insilmaril@0
|
57 |
|
insilmaril@0
|
58 |
int MapObj::y()
|
insilmaril@0
|
59 |
{
|
insilmaril@0
|
60 |
return absPos.y();
|
insilmaril@0
|
61 |
}
|
insilmaril@0
|
62 |
|
insilmaril@0
|
63 |
int MapObj::width()
|
insilmaril@0
|
64 |
{
|
insilmaril@0
|
65 |
return bbox.width();
|
insilmaril@0
|
66 |
}
|
insilmaril@0
|
67 |
|
insilmaril@0
|
68 |
int MapObj::height()
|
insilmaril@0
|
69 |
{
|
insilmaril@0
|
70 |
return bbox.height();
|
insilmaril@0
|
71 |
}
|
insilmaril@0
|
72 |
|
insilmaril@227
|
73 |
QPoint 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@129
|
80 |
return qpointToString(absPos);
|
insilmaril@129
|
81 |
}
|
insilmaril@129
|
82 |
|
insilmaril@0
|
83 |
void MapObj::move (double x, double y)
|
insilmaril@0
|
84 |
{
|
insilmaril@0
|
85 |
int xi=static_cast <int> (x);
|
insilmaril@0
|
86 |
int yi=static_cast <int> (y);
|
insilmaril@0
|
87 |
absPos.setX( xi);
|
insilmaril@0
|
88 |
absPos.setY( yi);
|
insilmaril@0
|
89 |
bbox.moveTopLeft(QPoint(xi,yi));
|
insilmaril@175
|
90 |
clickBox.moveTopLeft(QPoint(xi,yi));
|
insilmaril@0
|
91 |
}
|
insilmaril@0
|
92 |
|
insilmaril@0
|
93 |
void MapObj::moveBy (double x, double y)
|
insilmaril@0
|
94 |
{
|
insilmaril@175
|
95 |
int ix=(int)x;
|
insilmaril@175
|
96 |
int iy=(int)y;
|
insilmaril@336
|
97 |
MapObj::move (x+absPos.x(),y+absPos.y() );
|
insilmaril@175
|
98 |
bbox.moveBy (ix,iy);
|
insilmaril@175
|
99 |
clickBox.moveBy (ix,iy);
|
insilmaril@0
|
100 |
}
|
insilmaril@0
|
101 |
|
insilmaril@175
|
102 |
bool MapObj::inBox(const QPoint &p)
|
insilmaril@0
|
103 |
{
|
insilmaril@175
|
104 |
if (p.x() >= clickBox.left() && p.x() <= clickBox.right()
|
insilmaril@175
|
105 |
&& p.y() <= clickBox.bottom() && p.y() >= clickBox.top() )
|
insilmaril@166
|
106 |
return true;
|
insilmaril@0
|
107 |
return false;
|
insilmaril@0
|
108 |
}
|
insilmaril@0
|
109 |
|
insilmaril@0
|
110 |
QRect MapObj::getBBox()
|
insilmaril@0
|
111 |
{
|
insilmaril@0
|
112 |
return bbox;
|
insilmaril@0
|
113 |
}
|
insilmaril@0
|
114 |
|
insilmaril@0
|
115 |
QRect MapObj::addBBox(QRect r1, QRect r2)
|
insilmaril@175
|
116 |
{
|
insilmaril@175
|
117 |
// Find smallest QRect containing given rectangles
|
insilmaril@175
|
118 |
|
insilmaril@0
|
119 |
QRect n;
|
insilmaril@0
|
120 |
// Set left border
|
insilmaril@0
|
121 |
if (r1.left() <= r2.left() )
|
insilmaril@0
|
122 |
n.setLeft(r1.left() );
|
insilmaril@0
|
123 |
else
|
insilmaril@0
|
124 |
n.setLeft(r2.left() );
|
insilmaril@0
|
125 |
|
insilmaril@0
|
126 |
// Set top border
|
insilmaril@0
|
127 |
if (r1.top() <= r2.top() )
|
insilmaril@0
|
128 |
n.setTop(r1.top() );
|
insilmaril@0
|
129 |
else
|
insilmaril@0
|
130 |
n.setTop(r2.top() );
|
insilmaril@0
|
131 |
|
insilmaril@0
|
132 |
// Set right border
|
insilmaril@0
|
133 |
if (r1.right() <= r2.right() )
|
insilmaril@0
|
134 |
n.setRight(r2.right() );
|
insilmaril@0
|
135 |
else
|
insilmaril@0
|
136 |
n.setRight(r1.right() );
|
insilmaril@0
|
137 |
|
insilmaril@0
|
138 |
// Set bottom
|
insilmaril@0
|
139 |
if (r1.bottom() <= r2.bottom() )
|
insilmaril@0
|
140 |
n.setBottom(r2.bottom() );
|
insilmaril@0
|
141 |
else
|
insilmaril@0
|
142 |
n.setBottom(r1.bottom() );
|
insilmaril@0
|
143 |
return n;
|
insilmaril@0
|
144 |
}
|
insilmaril@0
|
145 |
|
insilmaril@0
|
146 |
QSize MapObj::getSize()
|
insilmaril@0
|
147 |
{
|
insilmaril@0
|
148 |
return bbox.size();
|
insilmaril@0
|
149 |
}
|
insilmaril@0
|
150 |
|
insilmaril@0
|
151 |
|
insilmaril@0
|
152 |
bool MapObj::isVisibleObj()
|
insilmaril@0
|
153 |
{
|
insilmaril@0
|
154 |
return visible;
|
insilmaril@0
|
155 |
}
|
insilmaril@0
|
156 |
|
insilmaril@0
|
157 |
void MapObj::setVisibility(bool v)
|
insilmaril@0
|
158 |
{
|
insilmaril@0
|
159 |
visible=v;
|
insilmaril@0
|
160 |
}
|
insilmaril@93
|
161 |
|