author | insilmaril |
Tue, 03 Jan 2006 09:44:41 +0000 | |
changeset 171 | a98a07994eed |
parent 166 | 325958acb69b |
child 175 | 728f51b71e71 |
permissions | -rw-r--r-- |
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@129 | 73 |
QString MapObj::getPos() |
insilmaril@129 | 74 |
{ |
insilmaril@129 | 75 |
return qpointToString(absPos); |
insilmaril@129 | 76 |
} |
insilmaril@129 | 77 |
|
insilmaril@0 | 78 |
void MapObj::move (double x, double y) |
insilmaril@0 | 79 |
{ |
insilmaril@0 | 80 |
int xi=static_cast <int> (x); |
insilmaril@0 | 81 |
int yi=static_cast <int> (y); |
insilmaril@0 | 82 |
absPos.setX( xi); |
insilmaril@0 | 83 |
absPos.setY( yi); |
insilmaril@0 | 84 |
bbox.moveTopLeft(QPoint(xi,yi)); |
insilmaril@0 | 85 |
} |
insilmaril@0 | 86 |
|
insilmaril@0 | 87 |
void MapObj::moveBy (double x, double y) |
insilmaril@0 | 88 |
{ |
insilmaril@0 | 89 |
move (x+absPos.x(),y+absPos.y() ); |
insilmaril@0 | 90 |
} |
insilmaril@0 | 91 |
|
insilmaril@0 | 92 |
bool MapObj::inBBox(QPoint p) |
insilmaril@0 | 93 |
{ |
insilmaril@0 | 94 |
if (p.x() >= bbox.left() && p.x() <= bbox.right() |
insilmaril@0 | 95 |
&& p.y() <= bbox.bottom() && p.y() >= bbox.top() ) |
insilmaril@166 | 96 |
return true; |
insilmaril@0 | 97 |
return false; |
insilmaril@0 | 98 |
} |
insilmaril@0 | 99 |
|
insilmaril@0 | 100 |
QRect MapObj::getBBox() |
insilmaril@0 | 101 |
{ |
insilmaril@0 | 102 |
return bbox; |
insilmaril@0 | 103 |
} |
insilmaril@0 | 104 |
|
insilmaril@0 | 105 |
QRect MapObj::addBBox(QRect r1, QRect r2) |
insilmaril@0 | 106 |
{ |
insilmaril@0 | 107 |
QRect n; |
insilmaril@0 | 108 |
// Set left border |
insilmaril@0 | 109 |
if (r1.left() <= r2.left() ) |
insilmaril@0 | 110 |
n.setLeft(r1.left() ); |
insilmaril@0 | 111 |
else |
insilmaril@0 | 112 |
n.setLeft(r2.left() ); |
insilmaril@0 | 113 |
|
insilmaril@0 | 114 |
// Set top border |
insilmaril@0 | 115 |
if (r1.top() <= r2.top() ) |
insilmaril@0 | 116 |
n.setTop(r1.top() ); |
insilmaril@0 | 117 |
else |
insilmaril@0 | 118 |
n.setTop(r2.top() ); |
insilmaril@0 | 119 |
|
insilmaril@0 | 120 |
// Set right border |
insilmaril@0 | 121 |
if (r1.right() <= r2.right() ) |
insilmaril@0 | 122 |
n.setRight(r2.right() ); |
insilmaril@0 | 123 |
else |
insilmaril@0 | 124 |
n.setRight(r1.right() ); |
insilmaril@0 | 125 |
|
insilmaril@0 | 126 |
// Set bottom |
insilmaril@0 | 127 |
if (r1.bottom() <= r2.bottom() ) |
insilmaril@0 | 128 |
n.setBottom(r2.bottom() ); |
insilmaril@0 | 129 |
else |
insilmaril@0 | 130 |
n.setBottom(r1.bottom() ); |
insilmaril@0 | 131 |
return n; |
insilmaril@0 | 132 |
} |
insilmaril@0 | 133 |
|
insilmaril@0 | 134 |
QSize MapObj::getSize() |
insilmaril@0 | 135 |
{ |
insilmaril@0 | 136 |
return bbox.size(); |
insilmaril@0 | 137 |
} |
insilmaril@0 | 138 |
|
insilmaril@0 | 139 |
|
insilmaril@0 | 140 |
bool MapObj::isVisibleObj() |
insilmaril@0 | 141 |
{ |
insilmaril@0 | 142 |
return visible; |
insilmaril@0 | 143 |
} |
insilmaril@0 | 144 |
|
insilmaril@0 | 145 |
void MapObj::setVisibility(bool v) |
insilmaril@0 | 146 |
{ |
insilmaril@0 | 147 |
visible=v; |
insilmaril@0 | 148 |
} |
insilmaril@93 | 149 |