mapobj.cpp
author insilmaril
Wed, 18 May 2005 07:39:51 +0000
changeset 101 1d092be4fe33
parent 93 31c6ce8efbc7
child 129 9b9c7e8b9147
permissions -rw-r--r--
fixed some bugs in xlinks, more remove/insert functions
     1 #include "mapobj.h"
     2 
     3 /////////////////////////////////////////////////////////////////
     4 // MapObj
     5 /////////////////////////////////////////////////////////////////
     6 MapObj::MapObj ()
     7 {
     8 	// TODO not used any longer...
     9 	cout << "Const MapObj (): Please set canvas somehow!!!\n";
    10     // canvas=actMapEditor->getCanvas();
    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 void MapObj::move (double x, double y) 
    74 {
    75     int xi=static_cast <int> (x);
    76     int yi=static_cast <int> (y);
    77     absPos.setX( xi);
    78     absPos.setY( yi);
    79     bbox.moveTopLeft(QPoint(xi,yi));
    80 }
    81 
    82 void MapObj::moveBy (double x, double y) 
    83 {
    84     move (x+absPos.x(),y+absPos.y() );
    85 }
    86 
    87 bool MapObj::inBBox(QPoint p)
    88 {
    89     if (p.x() >= bbox.left() && p.x() <= bbox.right()  
    90 	&& p.y() <= bbox.bottom() && p.y() >= bbox.top() )
    91 	return true;
    92     return false;	
    93 }
    94 
    95 QRect MapObj::getBBox()
    96 {
    97     return bbox;
    98 }
    99 
   100 QRect MapObj::addBBox(QRect r1, QRect r2)
   101 {
   102 	QRect n;
   103 	// Set left border
   104 	if (r1.left() <= r2.left() )
   105 		n.setLeft(r1.left() );
   106 	else
   107 		n.setLeft(r2.left() );
   108 		
   109 	// Set top border		
   110 	if (r1.top() <= r2.top() )
   111 		n.setTop(r1.top() );
   112 	else
   113 		n.setTop(r2.top() );
   114 		
   115 	// Set right border
   116 	if (r1.right() <= r2.right() )
   117 		n.setRight(r2.right() );
   118 	else
   119 		n.setRight(r1.right() );
   120 		
   121 	// Set bottom 
   122 	if (r1.bottom() <= r2.bottom() )
   123 		n.setBottom(r2.bottom() );
   124 	else
   125 		n.setBottom(r1.bottom() );
   126 	return n;
   127 }
   128 
   129 QSize MapObj::getSize()
   130 {
   131     return bbox.size();
   132 }
   133 
   134 
   135 bool MapObj::isVisibleObj()
   136 {
   137     return visible;
   138 }
   139 
   140 void MapObj::setVisibility(bool v)
   141 {
   142     visible=v;
   143 }
   144