mapitem.cpp
author insilmaril
Wed, 09 Jun 2010 13:14:08 +0000
changeset 847 43268373032d
parent 835 31841b366d5e
permissions -rw-r--r--
1.13.4 Various fixes
     1 #include "mapitem.h"
     2 
     3 #include "linkablemapobj.h"
     4 #include "ornamentedobj.h"
     5 
     6 #include <QDebug>
     7 
     8 MapItem::MapItem()
     9 {
    10 	init();
    11 }
    12 
    13 MapItem::MapItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
    14 {
    15 	init();
    16 }
    17 
    18 void MapItem::init()
    19 {
    20 	lmo=NULL;
    21 	posMode=Unused;
    22 	hideLinkUnselected=false;
    23 }
    24 
    25 void MapItem::appendChild (TreeItem *item)
    26 {
    27 	TreeItem::appendChild (item);
    28 
    29 	// FIXME-4 maybe access parent in MapObjs directly via treeItem
    30 	// and remove this here...
    31 
    32 	// If lmo exists, also set parObj there
    33 	if (lmo && (item->isBranchLikeType() || item->getType()==TreeItem::Image) )
    34 	{
    35 		LinkableMapObj *itemLMO=((MapItem*)item)->lmo;
    36 		if (itemLMO)
    37 			itemLMO->setParObj (lmo);
    38 	}
    39 }
    40 
    41 void MapItem::setRelPos (const QPointF &p)
    42 {
    43 	posMode=Relative;
    44 	pos=p;
    45 	if (lmo)
    46 	{
    47 		((OrnamentedObj*)lmo)->setUseRelPos (true);
    48 		((OrnamentedObj*)lmo)->move2RelPos(p);
    49 	}
    50 }
    51 
    52 void MapItem::setAbsPos (const QPointF &p)
    53 {
    54 	posMode=Absolute;
    55 	pos=p;
    56 	if (lmo) lmo->move (p);
    57 }
    58 
    59 void MapItem::setPositionMode (PositionMode mode)
    60 {
    61 	posMode=mode;
    62 }
    63 
    64 MapItem::PositionMode MapItem::getPositionMode ()
    65 {
    66 	return posMode;
    67 }
    68 
    69 void MapItem::setHideLinkUnselected (bool b)
    70 {
    71 	hideLinkUnselected=b;
    72 	if (lmo) 
    73 	{
    74 		//lmo->setHideLinkUnselected();
    75 		lmo->setVisibility (lmo->isVisibleObj());
    76 		lmo->updateLinkGeometry();
    77 	}	
    78 }
    79 
    80 bool MapItem::getHideLinkUnselected()
    81 {
    82 	return hideLinkUnselected;
    83 }	
    84 
    85 QString MapItem::getMapAttr ()	
    86 {
    87 	QString s;
    88 
    89 	if (parentItem==rootItem)
    90 		posMode=Absolute;
    91 	else
    92 	{
    93 		if (type==TreeItem::Image ||depth()==1)
    94 			posMode=Relative;
    95 		else
    96 			posMode=Unused;
    97 	}
    98 	switch (posMode)
    99 	{
   100 		case Relative:	
   101 			if (lmo) pos=lmo->getRelPos();
   102 			s= attribut("relPosX",QString().setNum(pos.x())) +
   103 			   attribut("relPosY",QString().setNum(pos.y())); 
   104 			break;
   105 		case Absolute:	
   106 			if (lmo) pos=lmo->getAbsPos();
   107 			s=attribut("absPosX",QString().setNum(pos.x())) +
   108 			  attribut("absPosY",QString().setNum(pos.y())); 
   109 			break;
   110 		default: break;
   111 	}
   112 	if (hideLinkUnselected)
   113 		s+=attribut ("hideLink","true");
   114 	else
   115 		s+=attribut ("hideLink","false");
   116 	return s;
   117 }
   118 
   119 QRectF MapItem::getBBoxURLFlag ()
   120 {
   121 	QStringList list=systemFlags.activeFlagNames().filter ("system-url");
   122 	if (list.count()>1)
   123 	{
   124 		qWarning()<<"MapItem::getBBoxURLFlag found more than one system-url*";
   125 		return QRectF ();
   126 	}	
   127 	return getBBoxFlag (list.first());
   128 }
   129 
   130 QRectF MapItem::getBBoxFlag (const QString &fname)
   131 {
   132 	if (lmo)
   133 		return ((OrnamentedObj*)lmo)->getBBoxFlag (fname);
   134 	else	
   135 		return QRectF ();
   136 }
   137 
   138 LinkableMapObj* MapItem::getLMO()
   139 {
   140 	return lmo;
   141 }
   142 
   143 void MapItem::setLMO(LinkableMapObj *l)
   144 {
   145 	lmo=l;
   146 }
   147 
   148 void MapItem::initLMO()
   149 {
   150 	if (!lmo) return;
   151 	switch (posMode)
   152 	{
   153 		case Relative:	
   154 			lmo->setRelPos (pos);
   155 			break;
   156 		case Absolute:	
   157 			lmo->move (pos);
   158 			break;
   159 		default:
   160 			break;
   161 	}
   162 }
   163