mapobj.cpp
author insilmaril
Mon, 29 Jun 2009 10:28:28 +0000
changeset 778 7b4e73ac247e
parent 754 db0ec4bcf416
child 790 133e2ed6b9c5
permissions -rw-r--r--
added imageitem.*
     1 #include "geometry.h"
     2 #include "mapobj.h"
     3 #include "misc.h"
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // MapObj
     7 /////////////////////////////////////////////////////////////////
     8 MapObj::MapObj ()
     9 {
    10 	//qWarning ( "Const MapObj (): Please set scene somehow!!!");
    11 	scene=NULL;
    12     init ();
    13 }
    14 
    15 MapObj::MapObj (QGraphicsScene *s)
    16 {
    17 //  cout << "Const MapObj\n";
    18     scene=s;
    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=QPointF(0,0);
    37     visible=true;
    38 }
    39 
    40 void MapObj::copy(MapObj* other)
    41 {
    42 //    scene=other->scene;	// 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 (QSizeF(other->bbox.width(), other->bbox.height() ) );
    47 }
    48 
    49 QGraphicsScene* MapObj::getScene()
    50 {
    51 	return scene;
    52 }
    53 
    54 qreal MapObj::x() 
    55 {
    56     return absPos.x();
    57 }
    58 
    59 qreal MapObj::y() 
    60 {
    61     return absPos.y();
    62 }
    63 
    64 qreal MapObj::width() 
    65 {
    66     return bbox.width();
    67 }
    68 
    69 qreal MapObj::height() 
    70 {
    71     return bbox.height();
    72 }
    73 
    74 QPointF MapObj::getAbsPos() 
    75 {
    76     return absPos;
    77 }
    78 
    79 QString MapObj::getPos()
    80 {
    81 	return qpointfToString(absPos);
    82 }
    83 
    84 void MapObj::move (double x, double y) 
    85 {
    86     absPos.setX( x);
    87     absPos.setY( y);
    88     bbox.moveTo(QPointF(x,y));
    89     clickBox.moveTo(QPointF(x,y));
    90 }
    91 
    92 void MapObj::move (QPointF p)
    93 {
    94 	absPos=p;
    95 	bbox.moveTo (p);
    96 	clickBox.moveTo (p);
    97 }
    98 
    99 void MapObj::moveBy (double x, double y) 
   100 {
   101     MapObj::move (x+absPos.x(),y+absPos.y() );
   102 	bbox.moveTo (bbox.x()+x,bbox.y()+y);
   103 	clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
   104 }
   105 
   106 QRectF MapObj::getBBox()
   107 {
   108     return bbox;
   109 }
   110 
   111 QRectF MapObj::getClickBox()
   112 {
   113     return clickBox;
   114 }
   115 
   116 bool MapObj::isInClickBox (const QPointF &p)
   117 {
   118 	return isInBox (p,clickBox);
   119 }
   120 
   121 QSizeF MapObj::getSize()
   122 {
   123     return bbox.size();
   124 }
   125 
   126 
   127 bool MapObj::isVisibleObj()
   128 {
   129     return visible;
   130 }
   131 
   132 void MapObj::setVisibility(bool v)
   133 {
   134     visible=v;
   135 }
   136