mapitem.cpp
author insilmaril
Wed, 25 Nov 2009 10:58:21 +0000
changeset 807 f9f7922989d8
parent 779 1fb50e79661c
child 819 8f987e376035
permissions -rw-r--r--
Added demos/vym-contribute.vym, fixes for selecting items
     1 #include "mapitem.h"
     2 
     3 #include "linkablemapobj.h"
     4 #include "ornamentedobj.h"
     5 
     6 MapItem::MapItem()
     7 {
     8 	init();
     9 }
    10 
    11 MapItem::MapItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
    12 {
    13 	init();
    14 }
    15 
    16 void MapItem::init()
    17 {
    18 	lmo=NULL;
    19 	posMode=Unused;
    20 	hideLinkUnselected=false;
    21 }
    22 
    23 void MapItem::appendChild (TreeItem *item)
    24 {
    25 	TreeItem::appendChild (item);
    26 
    27 	// FIXME-4 maybe access parent in MapObjs directly via treeItem
    28 	// and remove this here...
    29 
    30 	// If lmo exists, also set parObj there
    31 	if (lmo && (item->isBranchLikeType() || item->getType()==TreeItem::Image) )
    32 	{
    33 		LinkableMapObj *itemLMO=((MapItem*)item)->lmo;
    34 		if (itemLMO)
    35 			itemLMO->setParObj (lmo);
    36 	}
    37 }
    38 
    39 void MapItem::setRelPos (const QPointF &p)
    40 {
    41 	posMode=Relative;
    42 	pos=p;
    43 	if (lmo)
    44 	{
    45 		((OrnamentedObj*)lmo)->setUseRelPos (true);
    46 		((OrnamentedObj*)lmo)->move2RelPos(p);
    47 	}
    48 }
    49 
    50 void MapItem::setAbsPos (const QPointF &p)
    51 {
    52 	posMode=Absolute;
    53 	pos=p;
    54 	if (lmo) lmo->move (p);
    55 }
    56 
    57 void MapItem::setPositionMode (PositionMode mode)
    58 {
    59 	posMode=mode;
    60 }
    61 
    62 void MapItem::setHideLinkUnselected (bool b)
    63 {
    64 	hideLinkUnselected=b;
    65 	if (lmo) lmo->setHideLinkUnselected();
    66 }
    67 
    68 bool MapItem::getHideLinkUnselected()
    69 {
    70 	return hideLinkUnselected;
    71 }	
    72 
    73 QString MapItem::getMapAttr ()	
    74 {
    75 	QString s;
    76 
    77 	if (parentItem==rootItem)
    78 		posMode=Absolute;
    79 	else
    80 	{
    81 		if (type==TreeItem::Image ||depth()==1)
    82 			posMode=Relative;
    83 		else
    84 			posMode=Unused;
    85 	}
    86 	switch (posMode)
    87 	{
    88 		case Relative:	
    89 			if (lmo) pos=lmo->getRelPos();
    90 			s= attribut("relPosX",QString().setNum(pos.x())) +
    91 			   attribut("relPosY",QString().setNum(pos.y())); 
    92 			break;
    93 		case Absolute:	
    94 			if (lmo) pos=lmo->getAbsPos();
    95 			s=attribut("absPosX",QString().setNum(pos.x())) +
    96 			  attribut("absPosY",QString().setNum(pos.y())); 
    97 			break;
    98 		default: break;
    99 	}
   100 	if (hideLinkUnselected)
   101 		s+=attribut ("hideLink","true");
   102 	else
   103 		s+=attribut ("hideLink","false");
   104 	return s;
   105 }
   106 
   107 LinkableMapObj* MapItem::getLMO()
   108 {
   109 	return lmo;
   110 }
   111 
   112 void MapItem::setLMO(LinkableMapObj *l)
   113 {
   114 	lmo=l;
   115 }
   116 
   117 void MapItem::initLMO()
   118 {
   119 	if (!lmo) return;
   120 	switch (posMode)
   121 	{
   122 		case Relative:	
   123 			lmo->setRelPos (pos);
   124 			break;
   125 		case Absolute:	
   126 			lmo->move (pos);
   127 			break;
   128 		default:
   129 			break;
   130 	}
   131 }
   132