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