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