mapitem.cpp
author insilmaril
Wed, 13 May 2009 08:26:27 +0000
changeset 767 6d2b32f305f9
parent 762 ffb95cd03156
child 775 6e4b586aa88a
permissions -rw-r--r--
Started to use QtKinetic for Animation
     1 #include "mapitem.h"
     2 
     3 #include "linkablemapobj.h"
     4 #include "ornamentedobj.h"
     5 
     6 #include <iostream>
     7 using namespace std;
     8 
     9 MapItem::MapItem()
    10 {
    11 	lmo=NULL;
    12 	posMode=Unused;
    13 }
    14 
    15 void MapItem::setRelPos (const QPointF &p)
    16 {
    17 	posMode=Relative;
    18 	pos=p;
    19 	if (lmo)
    20 	{
    21 		((OrnamentedObj*)lmo)->setUseRelPos (true);
    22 		((OrnamentedObj*)lmo)->move2RelPos(p);
    23 	}
    24 }
    25 
    26 void MapItem::setAbsPos (const QPointF &p)
    27 {
    28 	posMode=Absolute;
    29 	pos=p;
    30 	if (lmo) lmo->move (p);
    31 }
    32 
    33 LinkableMapObj* MapItem::getLMO()
    34 {
    35 	return lmo;
    36 }
    37 
    38 void MapItem::setLMO(LinkableMapObj *l)
    39 {
    40 	lmo=l;
    41 }
    42 
    43 void MapItem::initLMO()
    44 {
    45 	if (!lmo) return;
    46 	switch (posMode)
    47 	{
    48 		case Relative:	
    49 			lmo->setRelPos (pos);
    50 			break;
    51 		case Absolute:	
    52 			lmo->move (pos);
    53 			break;
    54 		default:
    55 			break;
    56 	}
    57 }
    58 
    59 QString MapItem::getAttr()
    60 {
    61 	switch (posMode)
    62 	{
    63 		case Relative:	
    64 			if (lmo) pos=lmo->getRelPos();
    65 			return
    66 				attribut("relPosX",QString().setNum(pos.x())) +
    67 				attribut("relPosY",QString().setNum(pos.y())); 
    68 			break;
    69 		case Absolute:	
    70 			if (lmo) pos=lmo->getAbsPos();
    71 			return
    72 				attribut("absPosX",QString().setNum(pos.x())) +
    73 				attribut("absPosY",QString().setNum(pos.y())); 
    74 			break;
    75 		default:
    76 			return QString();
    77 			break;
    78 	}
    79 }
    80