]> git.sven.stormbind.net Git - sven/vym.git/blob - src/mapitem.cpp
New upstream version 2.9.22
[sven/vym.git] / src / mapitem.cpp
1 #include "mapitem.h"
2
3 #include "linkablemapobj.h"
4 #include "ornamentedobj.h"
5
6 #include <QDebug>
7
8 extern FlagRowMaster *systemFlagsMaster;
9
10 MapItem::MapItem(TreeItem *parent)
11     : TreeItem(parent)
12 {
13     // qDebug() << "Constr. MapItem(" << parent << ")";
14     init();
15 }
16
17 void MapItem::init()
18 {
19     mo = NULL;
20     posMode = Unused;
21     hideLinkUnselected = false;
22 }
23
24 void MapItem::appendChild(TreeItem *item)
25 {
26     TreeItem::appendChild(item);
27
28     // FIXME-4 maybe access parent in MapObjs directly via treeItem
29     // and remove this here...
30
31     // If lmo exists, also set parObj there
32     LinkableMapObj *lmo = getLMO();
33     if (lmo) {
34         LinkableMapObj *itemLMO = ((MapItem *)item)->getLMO();
35         if (itemLMO)
36             itemLMO->setParObj(lmo);
37     }
38 }
39
40 void MapItem::setRelPos(const QPointF &p)
41 {
42     posMode = Relative;
43     pos = p;
44     LinkableMapObj *lmo = getLMO();
45     if (lmo) {
46         ((OrnamentedObj *)lmo)->setUseRelPos(true);
47         ((OrnamentedObj *)lmo)->move2RelPos(p);
48     }
49 }
50
51 void MapItem::setAbsPos(const QPointF &p)
52 {
53     posMode = Absolute;
54     pos = p;
55     if (mo)
56         mo->move(p);
57 }
58
59 void MapItem::setPositionMode(PositionMode mode) { posMode = mode; }
60
61 MapItem::PositionMode MapItem::getPositionMode() { return posMode; }
62
63 void MapItem::setHideLinkUnselected(bool b)
64 {
65     hideLinkUnselected = b;
66     LinkableMapObj *lmo = getLMO();
67     if (lmo) {
68         // lmo->setHideLinkUnselected();
69         lmo->setVisibility(lmo->isVisibleObj());
70         lmo->updateLinkGeometry();
71     }
72 }
73
74 bool MapItem::getHideLinkUnselected() { return hideLinkUnselected; }
75
76 QString MapItem::getMapAttr()
77 {
78     QString s;
79     LinkableMapObj *lmo = getLMO();
80
81     if (parentItem == rootItem)
82         posMode = Absolute;
83     else {
84         if (type == TreeItem::Image || depth() == 1 || lmo->getUseRelPos())
85             posMode = Relative; // FiXME-2 shouldn't this be replaced by relPos?
86         else
87             posMode = Unused;
88     }
89     switch (posMode) {
90     case Relative:
91         if (lmo)
92             pos = lmo->getRelPos();
93         s = attribut("relPosX", QString().setNum(pos.x())) +
94             attribut("relPosY", QString().setNum(pos.y()));
95         break;
96     case Absolute:
97         if (mo)
98             pos = mo->getAbsPos();
99         s = attribut("absPosX", QString().setNum(pos.x())) +
100             attribut("absPosY", QString().setNum(pos.y()));
101         break;
102     default:
103         break;
104     }
105     if (hideLinkUnselected)
106         s += attribut("hideLink", "true");
107
108     // Rotation angle
109     MapObj *mo = getMO();
110     if (mo)
111         angle = mo->getRotation();
112     if (angle != 0)
113         s += attribut("rotation", QString().setNum(angle));
114
115     return s;
116 }
117
118 QRectF MapItem::getBBoxURLFlag()
119 {
120     QString s = "system-url";
121     QStringList list = systemFlags.activeFlagNames().filter(s);
122     if (list.count() > 1) {
123         qWarning() << "MapItem::getBBoxURLFlag found more than one system-url*";
124         return QRectF();
125     }
126
127     Flag *f = systemFlagsMaster->findFlagByName(s);
128     if (f) {
129         QUuid u = f->getUuid();
130         LinkableMapObj *lmo = getLMO();
131         if (lmo)
132             return ((OrnamentedObj *)lmo)->getBBoxSystemFlagByUid(u);
133     }
134     return QRectF();
135 }
136
137 void MapItem::setRotation(const qreal &a)
138 {
139     angle = a;
140     MapObj *mo = getMO();
141     if (mo)
142         mo->setRotation(a);
143 }
144
145 MapObj *MapItem::getMO() { return mo; }
146
147 LinkableMapObj *MapItem::getLMO()
148 {
149     if (isBranchLikeType() || type == Image)
150         return (LinkableMapObj *)mo;
151     else
152         return NULL;
153 }
154
155 void MapItem::initLMO()
156 {
157     LinkableMapObj *lmo = getLMO();
158     if (!lmo)
159         return;
160     switch (posMode) {
161     case Relative:
162         lmo->setRelPos(pos);
163         break;
164     case Absolute:
165         lmo->move(pos);
166         break;
167     default:
168         break;
169     }
170 }