mapobj.cpp
author insilmaril
Fri Aug 19 07:42:31 2005 +0000 (2005-08-19)
changeset 155 7f06b2e3afb5
parent 93 31c6ce8efbc7
child 166 325958acb69b
permissions -rw-r--r--
added license in new aboutwindow and debian subdir by Steffen Joeris
     1 #include "mapobj.h"
     2 #include "misc.h"
     3 
     4 /////////////////////////////////////////////////////////////////
     5 // MapObj
     6 /////////////////////////////////////////////////////////////////
     7 MapObj::MapObj ()
     8 {
     9 	// TODO not used any longer...
    10 	cout << "Const MapObj (): Please set canvas somehow!!!\n";
    11     // canvas=actMapEditor->getCanvas();
    12     init ();
    13 }
    14 
    15 MapObj::MapObj (QCanvas* c)
    16 {
    17 //  cout << "Const MapObj\n";
    18     canvas=c;
    19     init ();
    20 }
    21 
    22 
    23 MapObj::MapObj (MapObj* mo)
    24 {
    25 //    cout << "CopyConst MapObj\n";
    26     copy (mo);
    27 }
    28 
    29 MapObj::~MapObj ()
    30 {
    31 //    cout << "Destr MapObj\n";
    32 }
    33 
    34 void MapObj::init ()
    35 {
    36     absPos=QPoint(0,0);
    37     visible=true;
    38 }
    39 
    40 void MapObj::copy(MapObj* other)
    41 {
    42 //    canvas=other->canvas;	// already set in constr. of child, use that one...
    43     absPos=other->absPos;
    44 	bbox.setX (other->bbox.x() );
    45 	bbox.setY (other->bbox.y() );
    46 	bbox.setSize (QSize(other->bbox.width(), other->bbox.height() ) );
    47 }
    48 
    49 QCanvas* MapObj::getCanvas()
    50 {
    51 	return canvas;
    52 }
    53 
    54 int MapObj::x() 
    55 {
    56     return absPos.x();
    57 }
    58 
    59 int MapObj::y() 
    60 {
    61     return absPos.y();
    62 }
    63 
    64 int MapObj::width() 
    65 {
    66     return bbox.width();
    67 }
    68 
    69 int MapObj::height() 
    70 {
    71     return bbox.height();
    72 }
    73 
    74 QString MapObj::getPos()
    75 {
    76 	return qpointToString(absPos);
    77 }
    78 
    79 void MapObj::move (double x, double y) 
    80 {
    81     int xi=static_cast <int> (x);
    82     int yi=static_cast <int> (y);
    83     absPos.setX( xi);
    84     absPos.setY( yi);
    85     bbox.moveTopLeft(QPoint(xi,yi));
    86 }
    87 
    88 void MapObj::moveBy (double x, double y) 
    89 {
    90     move (x+absPos.x(),y+absPos.y() );
    91 }
    92 
    93 bool MapObj::inBBox(QPoint p)
    94 {
    95     if (p.x() >= bbox.left() && p.x() <= bbox.right()  
    96 	&& p.y() <= bbox.bottom() && p.y() >= bbox.top() )
    97 	return true;
    98     return false;	
    99 }
   100 
   101 QRect MapObj::getBBox()
   102 {
   103     return bbox;
   104 }
   105 
   106 QRect MapObj::addBBox(QRect r1, QRect r2)
   107 {
   108 	QRect n;
   109 	// Set left border
   110 	if (r1.left() <= r2.left() )
   111 		n.setLeft(r1.left() );
   112 	else
   113 		n.setLeft(r2.left() );
   114 		
   115 	// Set top border		
   116 	if (r1.top() <= r2.top() )
   117 		n.setTop(r1.top() );
   118 	else
   119 		n.setTop(r2.top() );
   120 		
   121 	// Set right border
   122 	if (r1.right() <= r2.right() )
   123 		n.setRight(r2.right() );
   124 	else
   125 		n.setRight(r1.right() );
   126 		
   127 	// Set bottom 
   128 	if (r1.bottom() <= r2.bottom() )
   129 		n.setBottom(r2.bottom() );
   130 	else
   131 		n.setBottom(r1.bottom() );
   132 	return n;
   133 }
   134 
   135 QSize MapObj::getSize()
   136 {
   137     return bbox.size();
   138 }
   139 
   140 
   141 bool MapObj::isVisibleObj()
   142 {
   143     return visible;
   144 }
   145 
   146 void MapObj::setVisibility(bool v)
   147 {
   148     visible=v;
   149 }
   150