mapobj.cpp
author insilmaril
Thu, 03 Sep 2009 08:52:00 +0000
changeset 790 133e2ed6b9c5
parent 754 db0ec4bcf416
child 792 7d67be709091
permissions -rw-r--r--
More work on xLinks
     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 }
    40 
    41 void MapObj::copy(MapObj* other)
    42 {
    43 //    scene=other->scene;	// already set in constr. of child, use that one...
    44     absPos=other->absPos;
    45 	bbox.setX (other->bbox.x() );
    46 	bbox.setY (other->bbox.y() );
    47 	bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
    48 }
    49 
    50 void MapObj::setTreeItem (TreeItem *ti)
    51 {
    52 	treeItem=ti;
    53 }
    54 
    55 TreeItem* MapObj::getTreeItem () const
    56 {
    57 	return treeItem;
    58 }
    59 
    60 
    61 QGraphicsScene* MapObj::getScene()
    62 {
    63 	return scene;
    64 }
    65 
    66 qreal MapObj::x() 
    67 {
    68     return absPos.x();
    69 }
    70 
    71 qreal MapObj::y() 
    72 {
    73     return absPos.y();
    74 }
    75 
    76 qreal MapObj::width() 
    77 {
    78     return bbox.width();
    79 }
    80 
    81 qreal MapObj::height() 
    82 {
    83     return bbox.height();
    84 }
    85 
    86 QPointF MapObj::getAbsPos() 
    87 {
    88     return absPos;
    89 }
    90 
    91 QString MapObj::getPos()
    92 {
    93 	return qpointfToString(absPos);
    94 }
    95 
    96 void MapObj::move (double x, double y) 
    97 {
    98     absPos.setX( x);
    99     absPos.setY( y);
   100     bbox.moveTo(QPointF(x,y));
   101     clickBox.moveTo(QPointF(x,y));
   102 }
   103 
   104 void MapObj::move (QPointF p)
   105 {
   106 	absPos=p;
   107 	bbox.moveTo (p);
   108 	clickBox.moveTo (p);
   109 }
   110 
   111 void MapObj::moveBy (double x, double y) 
   112 {
   113     MapObj::move (x+absPos.x(),y+absPos.y() );
   114 	bbox.moveTo (bbox.x()+x,bbox.y()+y);
   115 	clickBox.moveTo (clickBox.x()+x,clickBox.y()+y);
   116 }
   117 
   118 QRectF MapObj::getBBox()
   119 {
   120     return bbox;
   121 }
   122 
   123 QRectF MapObj::getClickBox()
   124 {
   125     return clickBox;
   126 }
   127 
   128 bool MapObj::isInClickBox (const QPointF &p)
   129 {
   130 	return isInBox (p,clickBox);
   131 }
   132 
   133 QSizeF MapObj::getSize()
   134 {
   135     return bbox.size();
   136 }
   137 
   138 
   139 bool MapObj::isVisibleObj()
   140 {
   141     return visible;
   142 }
   143 
   144 void MapObj::setVisibility(bool v)
   145 {
   146     visible=v;
   147 }
   148