insilmaril@0
|
1 |
#include <qdatetime.h>
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include "mapcenterobj.h"
|
insilmaril@0
|
4 |
#include "floatimageobj.h"
|
insilmaril@0
|
5 |
#include "mapeditor.h"
|
insilmaril@0
|
6 |
|
insilmaril@0
|
7 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
8 |
// MapCenterObj
|
insilmaril@0
|
9 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
10 |
MapCenterObj::MapCenterObj() : BranchObj ()
|
insilmaril@0
|
11 |
{
|
insilmaril@0
|
12 |
// cout << "Const MapCenterObj\n";
|
insilmaril@0
|
13 |
init();
|
insilmaril@0
|
14 |
}
|
insilmaril@0
|
15 |
|
insilmaril@0
|
16 |
MapCenterObj::MapCenterObj(QCanvas* c) : BranchObj (c)
|
insilmaril@0
|
17 |
{
|
insilmaril@0
|
18 |
// cout << "Const MapCenterObj canvas="<<c<<"\n";
|
insilmaril@0
|
19 |
init();
|
insilmaril@0
|
20 |
}
|
insilmaril@0
|
21 |
|
insilmaril@0
|
22 |
MapCenterObj::~MapCenterObj()
|
insilmaril@0
|
23 |
{
|
insilmaril@0
|
24 |
// cout << "Destr MapCenterObj\n";
|
insilmaril@0
|
25 |
}
|
insilmaril@0
|
26 |
|
insilmaril@0
|
27 |
void MapCenterObj::clear()
|
insilmaril@0
|
28 |
{
|
insilmaril@0
|
29 |
BranchObj::clear();
|
insilmaril@0
|
30 |
init();
|
insilmaril@0
|
31 |
}
|
insilmaril@0
|
32 |
|
insilmaril@0
|
33 |
void MapCenterObj::init ()
|
insilmaril@0
|
34 |
{
|
insilmaril@83
|
35 |
BranchObj::init();
|
insilmaril@0
|
36 |
orientation=OrientUndef;
|
insilmaril@0
|
37 |
absPos=QPoint (canvas->width()/2, canvas->height()/2);
|
insilmaril@0
|
38 |
|
insilmaril@0
|
39 |
// FIXME this should be done in TextObj later...
|
insilmaril@0
|
40 |
QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");
|
insilmaril@0
|
41 |
heading->setFont(font);
|
insilmaril@0
|
42 |
|
insilmaril@0
|
43 |
depth=0;
|
insilmaril@0
|
44 |
|
insilmaril@0
|
45 |
frame->setFrameType (Rectangle);
|
insilmaril@91
|
46 |
move (absPos.x(), absPos.y() );
|
insilmaril@0
|
47 |
}
|
insilmaril@0
|
48 |
|
insilmaril@0
|
49 |
void MapCenterObj::move (double x, double y)
|
insilmaril@0
|
50 |
{
|
insilmaril@0
|
51 |
BranchObj::move(x,y);
|
insilmaril@0
|
52 |
positionBBox();
|
insilmaril@0
|
53 |
}
|
insilmaril@0
|
54 |
|
insilmaril@0
|
55 |
void MapCenterObj::moveBy (double x, double y)
|
insilmaril@0
|
56 |
{
|
insilmaril@0
|
57 |
BranchObj::moveBy(x,y);
|
insilmaril@0
|
58 |
positionBBox();
|
insilmaril@0
|
59 |
}
|
insilmaril@0
|
60 |
|
insilmaril@0
|
61 |
void MapCenterObj::moveAll (double x, double y)
|
insilmaril@0
|
62 |
{
|
insilmaril@0
|
63 |
// Get rel. position
|
insilmaril@0
|
64 |
double dx=x-absPos.x();
|
insilmaril@0
|
65 |
double dy=y-absPos.y();
|
insilmaril@0
|
66 |
|
insilmaril@0
|
67 |
// Move myself and branches
|
insilmaril@0
|
68 |
moveAllBy (dx,dy);
|
insilmaril@0
|
69 |
}
|
insilmaril@0
|
70 |
|
insilmaril@0
|
71 |
void MapCenterObj::moveAllBy (double dx, double dy)
|
insilmaril@0
|
72 |
{
|
insilmaril@0
|
73 |
// Move myself
|
insilmaril@0
|
74 |
moveBy(dx,dy);
|
insilmaril@0
|
75 |
|
insilmaril@0
|
76 |
positionBBox();
|
insilmaril@0
|
77 |
}
|
insilmaril@0
|
78 |
|
insilmaril@0
|
79 |
void MapCenterObj::updateLink()
|
insilmaril@0
|
80 |
{
|
insilmaril@0
|
81 |
// set childPos to middle of MapCenterObj
|
insilmaril@0
|
82 |
childPos=QPoint(
|
insilmaril@0
|
83 |
absPos.x() + QSize(getSize() ).width()/2,
|
insilmaril@0
|
84 |
absPos.y() + QSize(getSize() ).height()/2);
|
insilmaril@0
|
85 |
parPos=childPos;
|
insilmaril@0
|
86 |
BranchObj *b;
|
insilmaril@0
|
87 |
for (b=branch.first(); b; b=branch.next() )
|
insilmaril@0
|
88 |
b->updateLink();
|
insilmaril@0
|
89 |
}
|
insilmaril@0
|
90 |
|
insilmaril@0
|
91 |
LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
|
insilmaril@0
|
92 |
{
|
insilmaril@0
|
93 |
BranchObj *bo;
|
insilmaril@0
|
94 |
LinkableMapObj *lmo;
|
insilmaril@0
|
95 |
|
insilmaril@0
|
96 |
// Search through child branches
|
insilmaril@0
|
97 |
for (bo=branch.first(); bo; bo=branch.next() )
|
insilmaril@0
|
98 |
{
|
insilmaril@0
|
99 |
lmo = bo->findMapObj(p, excludeLMO);
|
insilmaril@0
|
100 |
|
insilmaril@0
|
101 |
if (lmo!= NULL)
|
insilmaril@0
|
102 |
{
|
insilmaril@0
|
103 |
return lmo;
|
insilmaril@0
|
104 |
}
|
insilmaril@0
|
105 |
}
|
insilmaril@0
|
106 |
// is p in MapCenter?
|
insilmaril@0
|
107 |
if (inBBox (p) && (this != excludeLMO) ) return this;
|
insilmaril@0
|
108 |
|
insilmaril@0
|
109 |
// Search float images
|
insilmaril@0
|
110 |
FloatImageObj *foi;
|
insilmaril@0
|
111 |
for (foi=floatimage.first(); foi; foi=floatimage.next() )
|
insilmaril@0
|
112 |
if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
|
insilmaril@0
|
113 |
|
insilmaril@0
|
114 |
// nothing found
|
insilmaril@0
|
115 |
return NULL;
|
insilmaril@0
|
116 |
}
|
insilmaril@0
|
117 |
|
insilmaril@0
|
118 |
QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
|
insilmaril@0
|
119 |
{
|
insilmaril@0
|
120 |
QString s,a;
|
insilmaril@0
|
121 |
|
insilmaril@0
|
122 |
// save area, if not scrolled
|
insilmaril@0
|
123 |
QString areaAttr=
|
insilmaril@0
|
124 |
attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
|
insilmaril@0
|
125 |
attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
|
insilmaril@0
|
126 |
attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
|
insilmaril@0
|
127 |
attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
|
insilmaril@0
|
128 |
|
insilmaril@0
|
129 |
s=beginElement ("mapcenter"
|
insilmaril@0
|
130 |
+attribut("absPosX",QString().setNum(absPos.x(),10))
|
insilmaril@0
|
131 |
+attribut("absPosY",QString().setNum(absPos.y(),10))
|
insilmaril@0
|
132 |
+attribut("frameType",frame->getFrameTypeName())
|
insilmaril@0
|
133 |
+areaAttr
|
insilmaril@0
|
134 |
);
|
insilmaril@0
|
135 |
|
insilmaril@0
|
136 |
incIndent();
|
insilmaril@0
|
137 |
if (heading->getColor()!=QColor("black"))
|
insilmaril@0
|
138 |
a=attribut ("textColor",QColor(heading->getColor()).name() );
|
insilmaril@0
|
139 |
else
|
insilmaril@0
|
140 |
a="";
|
insilmaril@0
|
141 |
|
insilmaril@0
|
142 |
// Save flags. If verbose is set (export to xml dir), also write
|
insilmaril@0
|
143 |
// the flags as picture
|
insilmaril@0
|
144 |
s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
|
insilmaril@0
|
145 |
s=s+valueElement("heading", getHeading(),a);
|
insilmaril@0
|
146 |
|
insilmaril@0
|
147 |
// Reset the counters before saving
|
insilmaril@0
|
148 |
FloatImageObj (canvas).resetSaveCounter();
|
insilmaril@0
|
149 |
|
insilmaril@0
|
150 |
// add link to file in s
|
insilmaril@0
|
151 |
if (!note.isEmpty() )
|
insilmaril@0
|
152 |
s+=note.saveToDir();
|
insilmaril@0
|
153 |
|
insilmaril@0
|
154 |
// Save FloatImages
|
insilmaril@0
|
155 |
FloatImageObj *fio;
|
insilmaril@0
|
156 |
for (fio=floatimage.first(); fio; fio=floatimage.next() )
|
insilmaril@0
|
157 |
s+=fio->saveToDir (tmpdir,prefix);
|
insilmaril@0
|
158 |
|
insilmaril@0
|
159 |
// Save branches
|
insilmaril@0
|
160 |
BranchObj *bo;
|
insilmaril@0
|
161 |
for (bo=branch.first(); bo; bo=branch.next() )
|
insilmaril@0
|
162 |
s+=bo->saveToDir(tmpdir,prefix, offset);
|
insilmaril@0
|
163 |
|
insilmaril@0
|
164 |
decIndent();
|
insilmaril@0
|
165 |
s+=endElement ("mapcenter");
|
insilmaril@0
|
166 |
return s;
|
insilmaril@0
|
167 |
}
|
insilmaril@0
|
168 |
|
insilmaril@0
|
169 |
void MapCenterObj::setVersion (const QString &s)
|
insilmaril@0
|
170 |
{
|
insilmaril@0
|
171 |
version=s;
|
insilmaril@0
|
172 |
}
|
insilmaril@0
|
173 |
|
insilmaril@0
|
174 |
bool MapCenterObj::checkVersion ()
|
insilmaril@0
|
175 |
{
|
insilmaril@0
|
176 |
// returns true, if vym is able to read file regarding
|
insilmaril@0
|
177 |
// the version set with setVersion
|
insilmaril@0
|
178 |
QString s1=version.section (".",0,0);
|
insilmaril@0
|
179 |
QString s2=version.section (".",1,1);
|
insilmaril@0
|
180 |
QString s3=version.section (".",2,2);
|
insilmaril@0
|
181 |
bool ok;
|
insilmaril@0
|
182 |
int vv1 =QString(__VYM_VERSION__).section (".",0,0).toInt(&ok,10);
|
insilmaril@0
|
183 |
int vv2 =QString(__VYM_VERSION__).section (".",1,1).toInt(&ok,10);
|
insilmaril@0
|
184 |
int vv3 =QString(__VYM_VERSION__).section (".",2,2).toInt(&ok,10);
|
insilmaril@0
|
185 |
int mv1=0;
|
insilmaril@0
|
186 |
int mv2=0;
|
insilmaril@0
|
187 |
int mv3=0;
|
insilmaril@0
|
188 |
if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
|
insilmaril@0
|
189 |
if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
|
insilmaril@0
|
190 |
if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
|
insilmaril@0
|
191 |
|
insilmaril@0
|
192 |
if (vv1 > mv1)
|
insilmaril@0
|
193 |
return true;
|
insilmaril@0
|
194 |
if (vv1 < mv1)
|
insilmaril@0
|
195 |
return false;
|
insilmaril@0
|
196 |
if (vv2 > mv2)
|
insilmaril@0
|
197 |
return true;
|
insilmaril@0
|
198 |
if (vv2 < mv2)
|
insilmaril@0
|
199 |
return false;
|
insilmaril@0
|
200 |
if (vv3 > mv3)
|
insilmaril@0
|
201 |
return true;
|
insilmaril@0
|
202 |
if (vv3 < mv3)
|
insilmaril@0
|
203 |
return false;
|
insilmaril@0
|
204 |
return true;
|
insilmaril@0
|
205 |
}
|
insilmaril@0
|
206 |
|
insilmaril@0
|
207 |
void MapCenterObj::setAuthor (const QString &s)
|
insilmaril@0
|
208 |
{
|
insilmaril@0
|
209 |
author=s;
|
insilmaril@0
|
210 |
}
|
insilmaril@0
|
211 |
|
insilmaril@0
|
212 |
QString MapCenterObj::getAuthor()
|
insilmaril@0
|
213 |
{
|
insilmaril@0
|
214 |
return author;
|
insilmaril@0
|
215 |
}
|
insilmaril@0
|
216 |
|
insilmaril@0
|
217 |
void MapCenterObj::setComment (const QString &s)
|
insilmaril@0
|
218 |
{
|
insilmaril@0
|
219 |
comment=s;
|
insilmaril@0
|
220 |
}
|
insilmaril@0
|
221 |
|
insilmaril@0
|
222 |
QString MapCenterObj::getComment ()
|
insilmaril@0
|
223 |
{
|
insilmaril@0
|
224 |
return comment;
|
insilmaril@0
|
225 |
}
|
insilmaril@0
|
226 |
|
insilmaril@0
|
227 |
QString MapCenterObj::getDate ()
|
insilmaril@0
|
228 |
{
|
insilmaril@0
|
229 |
return QDate::currentDate().toString ("yyyy-MM-dd");
|
insilmaril@0
|
230 |
}
|
insilmaril@83
|
231 |
|