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