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@408
|
15 |
MapObj::MapObj (QGraphicsScene *s)
|
insilmaril@0
|
16 |
{
|
insilmaril@0
|
17 |
// cout << "Const MapObj\n";
|
insilmaril@408
|
18 |
scene=s;
|
insilmaril@0
|
19 |
init ();
|
insilmaril@0
|
20 |
}
|
insilmaril@0
|
21 |
|
insilmaril@0
|
22 |
|
insilmaril@0
|
23 |
MapObj::MapObj (MapObj* mo)
|
insilmaril@0
|
24 |
{
|
insilmaril@0
|
25 |
// cout << "CopyConst MapObj\n";
|
insilmaril@0
|
26 |
copy (mo);
|
insilmaril@0
|
27 |
}
|
insilmaril@0
|
28 |
|
insilmaril@0
|
29 |
MapObj::~MapObj ()
|
insilmaril@0
|
30 |
{
|
insilmaril@0
|
31 |
// cout << "Destr MapObj\n";
|
insilmaril@0
|
32 |
}
|
insilmaril@0
|
33 |
|
insilmaril@0
|
34 |
void MapObj::init ()
|
insilmaril@0
|
35 |
{
|
insilmaril@408
|
36 |
absPos=QPointF(0,0);
|
insilmaril@0
|
37 |
visible=true;
|
insilmaril@0
|
38 |
}
|
insilmaril@0
|
39 |
|
insilmaril@0
|
40 |
void MapObj::copy(MapObj* other)
|
insilmaril@0
|
41 |
{
|
insilmaril@408
|
42 |
// scene=other->scene; // already set in constr. of child, use that one...
|
insilmaril@0
|
43 |
absPos=other->absPos;
|
insilmaril@0
|
44 |
bbox.setX (other->bbox.x() );
|
insilmaril@0
|
45 |
bbox.setY (other->bbox.y() );
|
insilmaril@408
|
46 |
bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
|
insilmaril@0
|
47 |
}
|
insilmaril@0
|
48 |
|
insilmaril@408
|
49 |
QGraphicsScene* MapObj::getScene()
|
insilmaril@0
|
50 |
{
|
insilmaril@408
|
51 |
return scene;
|
insilmaril@0
|
52 |
}
|
insilmaril@0
|
53 |
|
insilmaril@408
|
54 |
qreal MapObj::x()
|
insilmaril@0
|
55 |
{
|
insilmaril@0
|
56 |
return absPos.x();
|
insilmaril@0
|
57 |
}
|
insilmaril@0
|
58 |
|
insilmaril@408
|
59 |
qreal MapObj::y()
|
insilmaril@0
|
60 |
{
|
insilmaril@0
|
61 |
return absPos.y();
|
insilmaril@0
|
62 |
}
|
insilmaril@0
|
63 |
|
insilmaril@408
|
64 |
qreal MapObj::width()
|
insilmaril@0
|
65 |
{
|
insilmaril@0
|
66 |
return bbox.width();
|
insilmaril@0
|
67 |
}
|
insilmaril@0
|
68 |
|
insilmaril@408
|
69 |
qreal MapObj::height()
|
insilmaril@0
|
70 |
{
|
insilmaril@0
|
71 |
return bbox.height();
|
insilmaril@0
|
72 |
}
|
insilmaril@0
|
73 |
|
insilmaril@408
|
74 |
QPointF MapObj::getAbsPos()
|
insilmaril@227
|
75 |
{
|
insilmaril@227
|
76 |
return absPos;
|
insilmaril@227
|
77 |
}
|
insilmaril@227
|
78 |
|
insilmaril@129
|
79 |
QString MapObj::getPos()
|
insilmaril@129
|
80 |
{
|
insilmaril@408
|
81 |
return qpointfToString(absPos);
|
insilmaril@129
|
82 |
}
|
insilmaril@129
|
83 |
|
insilmaril@0
|
84 |
void MapObj::move (double x, double y)
|
insilmaril@0
|
85 |
{
|
insilmaril@408
|
86 |
absPos.setX( x);
|
insilmaril@408
|
87 |
absPos.setY( y);
|
insilmaril@408
|
88 |
bbox.moveTo(QPointF(x,y));
|
insilmaril@408
|
89 |
clickBox.moveTo(QPointF(x,y));
|
insilmaril@408
|
90 |
}
|
insilmaril@408
|
91 |
|
insilmaril@408
|
92 |
void MapObj::move (QPointF p)
|
insilmaril@408
|
93 |
{
|
insilmaril@408
|
94 |
absPos=p;
|
insilmaril@408
|
95 |
bbox.moveTo (p);
|
insilmaril@408
|
96 |
clickBox.moveTo (p);
|
insilmaril@0
|
97 |
}
|
insilmaril@0
|
98 |
|
insilmaril@0
|
99 |
void MapObj::moveBy (double x, double y)
|
insilmaril@0
|
100 |
{
|
insilmaril@336
|
101 |
MapObj::move (x+absPos.x(),y+absPos.y() );
|
insilmaril@408
|
102 |
bbox.moveTo (bbox.x()+x,bbox.y()+y);
|
insilmaril@408
|
103 |
clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
|
insilmaril@0
|
104 |
}
|
insilmaril@0
|
105 |
|
insilmaril@408
|
106 |
QRectF MapObj::getBBox()
|
insilmaril@0
|
107 |
{
|
insilmaril@0
|
108 |
return bbox;
|
insilmaril@0
|
109 |
}
|
insilmaril@0
|
110 |
|
insilmaril@645
|
111 |
QRectF MapObj::getClickBox()
|
insilmaril@645
|
112 |
{
|
insilmaril@645
|
113 |
return clickBox;
|
insilmaril@645
|
114 |
}
|
insilmaril@175
|
115 |
|
insilmaril@754
|
116 |
bool MapObj::isInClickBox (const QPointF &p)
|
insilmaril@754
|
117 |
{
|
insilmaril@754
|
118 |
return isInBox (p,clickBox);
|
insilmaril@754
|
119 |
}
|
insilmaril@0
|
120 |
|
insilmaril@408
|
121 |
QSizeF MapObj::getSize()
|
insilmaril@0
|
122 |
{
|
insilmaril@0
|
123 |
return bbox.size();
|
insilmaril@0
|
124 |
}
|
insilmaril@0
|
125 |
|
insilmaril@0
|
126 |
|
insilmaril@0
|
127 |
bool MapObj::isVisibleObj()
|
insilmaril@0
|
128 |
{
|
insilmaril@0
|
129 |
return visible;
|
insilmaril@0
|
130 |
}
|
insilmaril@0
|
131 |
|
insilmaril@0
|
132 |
void MapObj::setVisibility(bool v)
|
insilmaril@0
|
133 |
{
|
insilmaril@0
|
134 |
visible=v;
|
insilmaril@0
|
135 |
}
|
insilmaril@93
|
136 |
|