mapobj.cpp
author insilmaril
Tue, 06 Nov 2007 13:54:41 +0000
changeset 615 497f19b3c1fe
parent 474 d9add21ee9d3
child 645 2abfdb7e85f4
permissions -rw-r--r--
1.11.1 fixed undo/redo sorting of branches
     1 #include "mapobj.h"
     2 #include "misc.h"
     3 
     4 /////////////////////////////////////////////////////////////////
     5 // MapObj
     6 /////////////////////////////////////////////////////////////////
     7 MapObj::MapObj ()
     8 {
     9 	//qWarning ( "Const MapObj (): Please set scene somehow!!!");
    10 	scene=NULL;
    11     init ();
    12 }
    13 
    14 MapObj::MapObj (QGraphicsScene *s)
    15 {
    16 //  cout << "Const MapObj\n";
    17     scene=s;
    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=QPointF(0,0);
    36     visible=true;
    37 }
    38 
    39 void MapObj::copy(MapObj* other)
    40 {
    41 //    scene=other->scene;	// 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 (QSizeF(other->bbox.width(), other->bbox.height() ) );
    46 }
    47 
    48 QGraphicsScene* MapObj::getScene()
    49 {
    50 	return scene;
    51 }
    52 
    53 qreal MapObj::x() 
    54 {
    55     return absPos.x();
    56 }
    57 
    58 qreal MapObj::y() 
    59 {
    60     return absPos.y();
    61 }
    62 
    63 qreal MapObj::width() 
    64 {
    65     return bbox.width();
    66 }
    67 
    68 qreal MapObj::height() 
    69 {
    70     return bbox.height();
    71 }
    72 
    73 QPointF MapObj::getAbsPos() 
    74 {
    75     return absPos;
    76 }
    77 
    78 QString MapObj::getPos()
    79 {
    80 	return qpointfToString(absPos);
    81 }
    82 
    83 void MapObj::move (double x, double y) 
    84 {
    85     absPos.setX( x);
    86     absPos.setY( y);
    87     bbox.moveTo(QPointF(x,y));
    88     clickBox.moveTo(QPointF(x,y));
    89 }
    90 
    91 void MapObj::move (QPointF p)
    92 {
    93 	absPos=p;
    94 	bbox.moveTo (p);
    95 	clickBox.moveTo (p);
    96 }
    97 
    98 void MapObj::moveBy (double x, double y) 
    99 {
   100     MapObj::move (x+absPos.x(),y+absPos.y() );
   101 	bbox.moveTo (bbox.x()+x,bbox.y()+y);
   102 	clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
   103 }
   104 
   105 bool MapObj::inBox(const QPointF &p)
   106 {
   107     if (p.x() >= clickBox.left() && p.x() <= clickBox.right()  
   108 	&& p.y() <= clickBox.bottom() && p.y() >= clickBox.top() )
   109 		return true;
   110     return false;	
   111 }
   112 
   113 QRectF MapObj::getBBox()
   114 {
   115     return bbox;
   116 }
   117 
   118 QRectF MapObj::addBBox(QRectF r1, QRectF r2)
   119 {	
   120 	// Find smallest QRectF containing given rectangles
   121 
   122 	QRectF n;
   123 	// Set left border
   124 	if (r1.left() <= r2.left() )
   125 		n.setLeft(r1.left() );
   126 	else
   127 		n.setLeft(r2.left() );
   128 		
   129 	// Set top border		
   130 	if (r1.top() <= r2.top() )
   131 		n.setTop(r1.top() );
   132 	else
   133 		n.setTop(r2.top() );
   134 		
   135 	// Set right border
   136 	if (r1.right() <= r2.right() )
   137 		n.setRight(r2.right() );
   138 	else
   139 		n.setRight(r1.right() );
   140 		
   141 	// Set bottom 
   142 	if (r1.bottom() <= r2.bottom() )
   143 		n.setBottom(r2.bottom() );
   144 	else
   145 		n.setBottom(r1.bottom() );
   146 	return n;
   147 }
   148 
   149 QSizeF MapObj::getSize()
   150 {
   151     return bbox.size();
   152 }
   153 
   154 
   155 bool MapObj::isVisibleObj()
   156 {
   157     return visible;
   158 }
   159 
   160 void MapObj::setVisibility(bool v)
   161 {
   162     visible=v;
   163 }
   164 
   165 void MapObj::animate()
   166 {
   167 }