mapitem.cpp
author insilmaril
Tue, 09 Mar 2010 13:09:05 +0000
changeset 833 bfacef6f29c1
parent 823 0bba81dde1bc
child 835 31841b366d5e
permissions -rw-r--r--
Bugfix: Previous checkin caused toggleScroll to fail
     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 void MapItem::setHideLinkUnselected (bool b)
    65 {
    66 	hideLinkUnselected=b;
    67 	if (lmo) 
    68 	{
    69 		//lmo->setHideLinkUnselected();
    70 		lmo->setVisibility (lmo->isVisibleObj());
    71 		lmo->updateLinkGeometry();
    72 	}	
    73 }
    74 
    75 bool MapItem::getHideLinkUnselected()
    76 {
    77 	return hideLinkUnselected;
    78 }	
    79 
    80 QString MapItem::getMapAttr ()	
    81 {
    82 	QString s;
    83 
    84 	if (parentItem==rootItem)
    85 		posMode=Absolute;
    86 	else
    87 	{
    88 		if (type==TreeItem::Image ||depth()==1)
    89 			posMode=Relative;
    90 		else
    91 			posMode=Unused;
    92 	}
    93 	switch (posMode)
    94 	{
    95 		case Relative:	
    96 			if (lmo) pos=lmo->getRelPos();
    97 			s= attribut("relPosX",QString().setNum(pos.x())) +
    98 			   attribut("relPosY",QString().setNum(pos.y())); 
    99 			break;
   100 		case Absolute:	
   101 			if (lmo) pos=lmo->getAbsPos();
   102 			s=attribut("absPosX",QString().setNum(pos.x())) +
   103 			  attribut("absPosY",QString().setNum(pos.y())); 
   104 			break;
   105 		default: break;
   106 	}
   107 	if (hideLinkUnselected)
   108 		s+=attribut ("hideLink","true");
   109 	else
   110 		s+=attribut ("hideLink","false");
   111 	return s;
   112 }
   113 
   114 QRectF MapItem::getBBoxURLFlag ()
   115 {
   116 	QStringList list=systemFlags.activeFlagNames().filter ("system-url");
   117 	if (list.count()>1)
   118 	{
   119 		qWarning()<<"MapItem::getBBoxURLFlag found more than one system-url*";
   120 		return QRectF ();
   121 	}	
   122 	return getBBoxFlag (list.first());
   123 }
   124 
   125 QRectF MapItem::getBBoxFlag (const QString &fname)
   126 {
   127 	if (lmo)
   128 		return ((OrnamentedObj*)lmo)->getBBoxFlag (fname);
   129 	else	
   130 		return QRectF ();
   131 }
   132 
   133 LinkableMapObj* MapItem::getLMO()
   134 {
   135 	return lmo;
   136 }
   137 
   138 void MapItem::setLMO(LinkableMapObj *l)
   139 {
   140 	lmo=l;
   141 }
   142 
   143 void MapItem::initLMO()
   144 {
   145 	if (!lmo) return;
   146 	switch (posMode)
   147 	{
   148 		case Relative:	
   149 			lmo->setRelPos (pos);
   150 			break;
   151 		case Absolute:	
   152 			lmo->move (pos);
   153 			break;
   154 		default:
   155 			break;
   156 	}
   157 }
   158