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