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