mapobj.cpp
branchvendor
changeset 0 7a96bd401351
child 2 608f976aa7bb
child 93 31c6ce8efbc7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mapobj.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.3 @@ -0,0 +1,143 @@
     1.4 +#include "mapobj.h"
     1.5 +
     1.6 +/////////////////////////////////////////////////////////////////
     1.7 +// MapObj
     1.8 +/////////////////////////////////////////////////////////////////
     1.9 +MapObj::MapObj ()
    1.10 +{
    1.11 +	// TODO not used any longer...
    1.12 +	cout << "Const MapObj (): Please set canvas somehow!!!\n";
    1.13 +    // canvas=actMapEditor->getCanvas();
    1.14 +    init ();
    1.15 +}
    1.16 +
    1.17 +MapObj::MapObj (QCanvas* c)
    1.18 +{
    1.19 +//  cout << "Const MapObj\n";
    1.20 +    canvas=c;
    1.21 +    init ();
    1.22 +}
    1.23 +
    1.24 +
    1.25 +MapObj::MapObj (MapObj* mo)
    1.26 +{
    1.27 +//    cout << "CopyConst MapObj\n";
    1.28 +    copy (mo);
    1.29 +}
    1.30 +
    1.31 +MapObj::~MapObj ()
    1.32 +{
    1.33 +//    cout << "Destr MapObj\n";
    1.34 +}
    1.35 +
    1.36 +void MapObj::init ()
    1.37 +{
    1.38 +    absPos=QPoint(0,0);
    1.39 +    visible=true;
    1.40 +}
    1.41 +
    1.42 +void MapObj::copy(MapObj* other)
    1.43 +{
    1.44 +//    canvas=other->canvas;	// already set in constr. of child, use that one...
    1.45 +    absPos=other->absPos;
    1.46 +	bbox.setX (other->bbox.x() );
    1.47 +	bbox.setY (other->bbox.y() );
    1.48 +	bbox.setSize (QSize(other->bbox.width(), other->bbox.height() ) );
    1.49 +}
    1.50 +
    1.51 +QCanvas* MapObj::getCanvas()
    1.52 +{
    1.53 +	return canvas;
    1.54 +}
    1.55 +
    1.56 +int MapObj::x() 
    1.57 +{
    1.58 +    return absPos.x();
    1.59 +}
    1.60 +
    1.61 +int MapObj::y() 
    1.62 +{
    1.63 +    return absPos.y();
    1.64 +}
    1.65 +
    1.66 +int MapObj::width() 
    1.67 +{
    1.68 +    return bbox.width();
    1.69 +}
    1.70 +
    1.71 +int MapObj::height() 
    1.72 +{
    1.73 +    return bbox.height();
    1.74 +}
    1.75 +
    1.76 +void MapObj::move (double x, double y) 
    1.77 +{
    1.78 +    int xi=static_cast <int> (x);
    1.79 +    int yi=static_cast <int> (y);
    1.80 +    absPos.setX( xi);
    1.81 +    absPos.setY( yi);
    1.82 +    bbox.moveTopLeft(QPoint(xi,yi));
    1.83 +}
    1.84 +
    1.85 +void MapObj::moveBy (double x, double y) 
    1.86 +{
    1.87 +    move (x+absPos.x(),y+absPos.y() );
    1.88 +}
    1.89 +
    1.90 +bool MapObj::inBBox(QPoint p)
    1.91 +{
    1.92 +    if (p.x() >= bbox.left() && p.x() <= bbox.right()  
    1.93 +	&& p.y() <= bbox.bottom() && p.y() >= bbox.top() )
    1.94 +	return true;
    1.95 +    return false;	
    1.96 +}
    1.97 +
    1.98 +QRect MapObj::getBBox()
    1.99 +{
   1.100 +    return bbox;
   1.101 +}
   1.102 +
   1.103 +QRect MapObj::addBBox(QRect r1, QRect r2)
   1.104 +{
   1.105 +	QRect n;
   1.106 +	// Set left border
   1.107 +	if (r1.left() <= r2.left() )
   1.108 +		n.setLeft(r1.left() );
   1.109 +	else
   1.110 +		n.setLeft(r2.left() );
   1.111 +		
   1.112 +	// Set top border		
   1.113 +	if (r1.top() <= r2.top() )
   1.114 +		n.setTop(r1.top() );
   1.115 +	else
   1.116 +		n.setTop(r2.top() );
   1.117 +		
   1.118 +	// Set right border
   1.119 +	if (r1.right() <= r2.right() )
   1.120 +		n.setRight(r2.right() );
   1.121 +	else
   1.122 +		n.setRight(r1.right() );
   1.123 +		
   1.124 +	// Set bottom 
   1.125 +	if (r1.bottom() <= r2.bottom() )
   1.126 +		n.setBottom(r2.bottom() );
   1.127 +	else
   1.128 +		n.setBottom(r1.bottom() );
   1.129 +	return n;
   1.130 +}
   1.131 +
   1.132 +QSize MapObj::getSize()
   1.133 +{
   1.134 +    return bbox.size();
   1.135 +}
   1.136 +
   1.137 +
   1.138 +bool MapObj::isVisibleObj()
   1.139 +{
   1.140 +    return visible;
   1.141 +}
   1.142 +
   1.143 +void MapObj::setVisibility(bool v)
   1.144 +{
   1.145 +    visible=v;
   1.146 +}