mapobj.cpp
author insilmaril
Sat, 06 Mar 2010 20:05:02 +0000
changeset 826 e715694b0f47
parent 794 d922fb6ea482
permissions -rw-r--r--
Changed animTicks to uint
     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, TreeItem *ti)
    16 {
    17 //  cout << "Const MapObj\n";
    18     scene=s;
    19 	treeItem=ti;
    20     init ();
    21 }
    22 
    23 
    24 MapObj::MapObj (MapObj* mo)
    25 {
    26 //    cout << "CopyConst MapObj\n";
    27     copy (mo);
    28 }
    29 
    30 MapObj::~MapObj ()
    31 {
    32 //    cout << "Destr MapObj\n";
    33 }
    34 
    35 void MapObj::init ()
    36 {
    37     absPos=QPointF(0,0);
    38     visible=true;
    39 	pi=NULL;
    40 }
    41 
    42 void MapObj::copy(MapObj* other)
    43 {
    44 //    scene=other->scene;	// already set in constr. of child, use that one...
    45     absPos=other->absPos;
    46 	bbox.setX (other->bbox.x() );
    47 	bbox.setY (other->bbox.y() );
    48 	bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
    49 }
    50 
    51 void MapObj::setTreeItem (TreeItem *ti)
    52 {
    53 	treeItem=ti;
    54 }
    55 
    56 TreeItem* MapObj::getTreeItem () const
    57 {
    58 	return treeItem;
    59 }
    60 
    61 
    62 QGraphicsScene* MapObj::getScene()
    63 {
    64 	return scene;
    65 }
    66 
    67 qreal MapObj::x() 
    68 {
    69     return absPos.x();
    70 }
    71 
    72 qreal MapObj::y() 
    73 {
    74     return absPos.y();
    75 }
    76 
    77 qreal MapObj::width() 
    78 {
    79     return bbox.width();
    80 }
    81 
    82 qreal MapObj::height() 
    83 {
    84     return bbox.height();
    85 }
    86 
    87 QPointF MapObj::getAbsPos() 
    88 {
    89     return absPos;
    90 }
    91 
    92 QString MapObj::getPos()
    93 {
    94 	return qpointFToString(absPos);
    95 }
    96 
    97 void MapObj::move (double x, double y) 
    98 {
    99     absPos.setX( x);
   100     absPos.setY( y);
   101     bbox.moveTo(QPointF(x,y));
   102     clickBox.moveTo(QPointF(x,y));
   103 }
   104 
   105 void MapObj::move (QPointF p)
   106 {
   107 	absPos=p;
   108 	bbox.moveTo (p);
   109 	clickBox.moveTo (p);
   110 }
   111 
   112 void MapObj::moveBy (double x, double y) 
   113 {
   114     MapObj::move (x+absPos.x(),y+absPos.y() );
   115 	bbox.moveTo (bbox.x()+x,bbox.y()+y);
   116 	clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
   117 }
   118 
   119 QRectF MapObj::getBBox()
   120 {
   121     return bbox;
   122 }
   123 
   124 ConvexPolygon MapObj::getBoundingPolygon()
   125 {
   126 	QPolygonF p;
   127 	p<<bbox.topLeft()<<bbox.topRight()<<bbox.bottomRight()<<bbox.bottomLeft();
   128 	return p;
   129 }
   130 
   131 QRectF MapObj::getClickBox()
   132 {
   133     return clickBox;
   134 }
   135 
   136 bool MapObj::isInClickBox (const QPointF &p)
   137 {
   138 	return isInBox (p,clickBox);
   139 }
   140 
   141 QSizeF MapObj::getSize()
   142 {
   143     return bbox.size();
   144 }
   145 
   146 
   147 bool MapObj::isVisibleObj()
   148 {
   149     return visible;
   150 }
   151 
   152 void MapObj::setVisibility(bool v)
   153 {
   154     visible=v;
   155 }
   156