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@388
|
68 |
// Move myself and childs
|
insilmaril@388
|
69 |
BranchObj::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@388
|
83 |
void MapCenterObj::updateRelPositions()
|
insilmaril@388
|
84 |
{
|
insilmaril@388
|
85 |
if (repositionRequest) unsetAllRepositionRequests();
|
insilmaril@388
|
86 |
|
insilmaril@388
|
87 |
// update relative Positions of branches and floats
|
insilmaril@388
|
88 |
BranchObj *b;
|
insilmaril@388
|
89 |
for (b=branch.first(); b; b=branch.next() )
|
insilmaril@388
|
90 |
{
|
insilmaril@388
|
91 |
b->setRelPos();
|
insilmaril@388
|
92 |
b->setOrientation();
|
insilmaril@388
|
93 |
}
|
insilmaril@388
|
94 |
|
insilmaril@388
|
95 |
FloatObj *fo;
|
insilmaril@388
|
96 |
for (fo=floatimage.first(); fo; fo=floatimage.next() ) fo->setRelPos();
|
insilmaril@388
|
97 |
|
insilmaril@388
|
98 |
if (repositionRequest) reposition();
|
insilmaril@388
|
99 |
}
|
insilmaril@388
|
100 |
|
insilmaril@0
|
101 |
LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
|
insilmaril@0
|
102 |
{
|
insilmaril@0
|
103 |
BranchObj *bo;
|
insilmaril@0
|
104 |
LinkableMapObj *lmo;
|
insilmaril@0
|
105 |
|
insilmaril@0
|
106 |
// Search through child branches
|
insilmaril@0
|
107 |
for (bo=branch.first(); bo; bo=branch.next() )
|
insilmaril@0
|
108 |
{
|
insilmaril@0
|
109 |
lmo = bo->findMapObj(p, excludeLMO);
|
insilmaril@169
|
110 |
if (lmo!= NULL) return lmo;
|
insilmaril@0
|
111 |
}
|
insilmaril@0
|
112 |
// is p in MapCenter?
|
insilmaril@169
|
113 |
if (inBox (p) && (this != excludeLMO) ) return this;
|
insilmaril@0
|
114 |
|
insilmaril@0
|
115 |
// Search float images
|
insilmaril@0
|
116 |
FloatImageObj *foi;
|
insilmaril@0
|
117 |
for (foi=floatimage.first(); foi; foi=floatimage.next() )
|
insilmaril@169
|
118 |
if (foi->inBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
|
insilmaril@0
|
119 |
|
insilmaril@0
|
120 |
// nothing found
|
insilmaril@0
|
121 |
return NULL;
|
insilmaril@0
|
122 |
}
|
insilmaril@0
|
123 |
|
insilmaril@0
|
124 |
QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
|
insilmaril@0
|
125 |
{
|
insilmaril@0
|
126 |
QString s,a;
|
insilmaril@0
|
127 |
|
insilmaril@0
|
128 |
// save area, if not scrolled
|
insilmaril@0
|
129 |
QString areaAttr=
|
insilmaril@0
|
130 |
attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
|
insilmaril@0
|
131 |
attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
|
insilmaril@0
|
132 |
attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
|
insilmaril@0
|
133 |
attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
|
insilmaril@0
|
134 |
|
insilmaril@169
|
135 |
// Providing an ID for a branch makes export to XHTML easier
|
insilmaril@169
|
136 |
QString idAttr;
|
insilmaril@169
|
137 |
if (countXLinks()>0)
|
insilmaril@169
|
138 |
idAttr=attribut ("id",getSelectString());
|
insilmaril@169
|
139 |
else
|
insilmaril@169
|
140 |
idAttr="";
|
insilmaril@169
|
141 |
|
insilmaril@169
|
142 |
QString linkAttr=getLinkAttr();
|
insilmaril@169
|
143 |
|
insilmaril@0
|
144 |
s=beginElement ("mapcenter"
|
insilmaril@239
|
145 |
+getOrnAttr()
|
insilmaril@0
|
146 |
+attribut("frameType",frame->getFrameTypeName())
|
insilmaril@0
|
147 |
+areaAttr
|
insilmaril@239
|
148 |
+idAttr
|
insilmaril@239
|
149 |
+getIncludeImageAttr() );
|
insilmaril@0
|
150 |
incIndent();
|
insilmaril@0
|
151 |
if (heading->getColor()!=QColor("black"))
|
insilmaril@0
|
152 |
a=attribut ("textColor",QColor(heading->getColor()).name() );
|
insilmaril@0
|
153 |
else
|
insilmaril@0
|
154 |
a="";
|
insilmaril@0
|
155 |
|
insilmaril@0
|
156 |
// Save flags. If verbose is set (export to xml dir), also write
|
insilmaril@0
|
157 |
// the flags as picture
|
insilmaril@0
|
158 |
s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
|
insilmaril@0
|
159 |
s=s+valueElement("heading", getHeading(),a);
|
insilmaril@0
|
160 |
|
insilmaril@0
|
161 |
// add link to file in s
|
insilmaril@0
|
162 |
if (!note.isEmpty() )
|
insilmaril@0
|
163 |
s+=note.saveToDir();
|
insilmaril@0
|
164 |
|
insilmaril@95
|
165 |
// Save branches
|
insilmaril@95
|
166 |
BranchObj *bo;
|
insilmaril@95
|
167 |
for (bo=branch.first(); bo; bo=branch.next() )
|
insilmaril@95
|
168 |
s+=bo->saveToDir(tmpdir,prefix, offset);
|
insilmaril@95
|
169 |
|
insilmaril@0
|
170 |
// Save FloatImages
|
insilmaril@0
|
171 |
FloatImageObj *fio;
|
insilmaril@0
|
172 |
for (fio=floatimage.first(); fio; fio=floatimage.next() )
|
insilmaril@377
|
173 |
s+=fio->saveToDir (tmpdir,prefix);
|
insilmaril@0
|
174 |
|
insilmaril@95
|
175 |
// Save XLinks
|
insilmaril@95
|
176 |
XLinkObj *xlo;
|
insilmaril@95
|
177 |
for (xlo=xlink.first(); xlo; xlo=xlink.next() )
|
insilmaril@95
|
178 |
s+=xlo->saveToDir();
|
insilmaril@0
|
179 |
|
insilmaril@0
|
180 |
decIndent();
|
insilmaril@0
|
181 |
s+=endElement ("mapcenter");
|
insilmaril@0
|
182 |
return s;
|
insilmaril@0
|
183 |
}
|
insilmaril@0
|
184 |
|
insilmaril@0
|
185 |
void MapCenterObj::setVersion (const QString &s)
|
insilmaril@0
|
186 |
{
|
insilmaril@0
|
187 |
version=s;
|
insilmaril@0
|
188 |
}
|
insilmaril@0
|
189 |
|
insilmaril@0
|
190 |
void MapCenterObj::setAuthor (const QString &s)
|
insilmaril@0
|
191 |
{
|
insilmaril@0
|
192 |
author=s;
|
insilmaril@0
|
193 |
}
|
insilmaril@0
|
194 |
|
insilmaril@0
|
195 |
QString MapCenterObj::getAuthor()
|
insilmaril@0
|
196 |
{
|
insilmaril@0
|
197 |
return author;
|
insilmaril@0
|
198 |
}
|
insilmaril@0
|
199 |
|
insilmaril@0
|
200 |
void MapCenterObj::setComment (const QString &s)
|
insilmaril@0
|
201 |
{
|
insilmaril@0
|
202 |
comment=s;
|
insilmaril@0
|
203 |
}
|
insilmaril@0
|
204 |
|
insilmaril@0
|
205 |
QString MapCenterObj::getComment ()
|
insilmaril@0
|
206 |
{
|
insilmaril@0
|
207 |
return comment;
|
insilmaril@0
|
208 |
}
|
insilmaril@0
|
209 |
|
insilmaril@0
|
210 |
QString MapCenterObj::getDate ()
|
insilmaril@0
|
211 |
{
|
insilmaril@0
|
212 |
return QDate::currentDate().toString ("yyyy-MM-dd");
|
insilmaril@0
|
213 |
}
|
insilmaril@83
|
214 |
|