insilmaril@0
|
1 |
#include "ornamentedobj.h"
|
insilmaril@0
|
2 |
#include "texteditor.h"
|
insilmaril@0
|
3 |
#include "mapeditor.h"
|
insilmaril@0
|
4 |
#include "linkablemapobj.h"
|
insilmaril@0
|
5 |
|
insilmaril@0
|
6 |
extern TextEditor *textEditor;
|
insilmaril@0
|
7 |
extern FlagRowObj *systemFlagsDefault;
|
insilmaril@0
|
8 |
extern FlagRowObj *standardFlagsDefault;
|
insilmaril@0
|
9 |
|
insilmaril@0
|
10 |
|
insilmaril@0
|
11 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
12 |
// OrnamentedObj
|
insilmaril@0
|
13 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
14 |
|
insilmaril@0
|
15 |
OrnamentedObj::OrnamentedObj():LinkableMapObj()
|
insilmaril@0
|
16 |
{
|
insilmaril@0
|
17 |
// cout << "Const OrnamentedObj ()\n";
|
insilmaril@0
|
18 |
init ();
|
insilmaril@0
|
19 |
}
|
insilmaril@0
|
20 |
|
insilmaril@2
|
21 |
OrnamentedObj::OrnamentedObj(Q3Canvas* c) :LinkableMapObj(c)
|
insilmaril@0
|
22 |
{
|
insilmaril@0
|
23 |
// cout << "Const OrnamentedObj\n";
|
insilmaril@0
|
24 |
init ();
|
insilmaril@0
|
25 |
}
|
insilmaril@0
|
26 |
|
insilmaril@0
|
27 |
OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->canvas)
|
insilmaril@0
|
28 |
{
|
insilmaril@0
|
29 |
copy (lmo);
|
insilmaril@0
|
30 |
}
|
insilmaril@0
|
31 |
|
insilmaril@0
|
32 |
OrnamentedObj::~OrnamentedObj()
|
insilmaril@0
|
33 |
{
|
insilmaril@0
|
34 |
delete (heading);
|
insilmaril@0
|
35 |
delete (systemFlags);
|
insilmaril@0
|
36 |
delete (standardFlags);
|
insilmaril@0
|
37 |
|
insilmaril@0
|
38 |
}
|
insilmaril@0
|
39 |
|
insilmaril@0
|
40 |
|
insilmaril@0
|
41 |
void OrnamentedObj::init ()
|
insilmaril@0
|
42 |
{
|
insilmaril@0
|
43 |
heading = new HeadingObj(canvas);
|
insilmaril@0
|
44 |
heading->move (absPos.x(), absPos.y());
|
insilmaril@0
|
45 |
|
insilmaril@0
|
46 |
note.setNote("");
|
insilmaril@0
|
47 |
note.setFontHint (textEditor->getFontHintDefault() );
|
insilmaril@0
|
48 |
|
insilmaril@0
|
49 |
systemFlags=new FlagRowObj(canvas);
|
insilmaril@0
|
50 |
systemFlags->clone(systemFlagsDefault);
|
insilmaril@0
|
51 |
systemFlags->setName ("systemFlags");
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
standardFlags=new FlagRowObj(canvas);
|
insilmaril@0
|
54 |
standardFlags->clone(standardFlagsDefault);
|
insilmaril@0
|
55 |
standardFlags->setName ("standardFlags");
|
insilmaril@0
|
56 |
|
insilmaril@2
|
57 |
hideExport=false;
|
insilmaril@2
|
58 |
hidden=false;
|
insilmaril@0
|
59 |
|
insilmaril@2
|
60 |
url="";
|
insilmaril@2
|
61 |
vymLink="";
|
insilmaril@2
|
62 |
|
insilmaril@0
|
63 |
}
|
insilmaril@0
|
64 |
|
insilmaril@0
|
65 |
void OrnamentedObj::copy (OrnamentedObj* other)
|
insilmaril@0
|
66 |
{
|
insilmaril@0
|
67 |
LinkableMapObj::copy(other);
|
insilmaril@0
|
68 |
heading->copy(other->heading);
|
insilmaril@2
|
69 |
setColor (other->heading->getColor());
|
insilmaril@0
|
70 |
|
insilmaril@0
|
71 |
note.copy (other->note);
|
insilmaril@0
|
72 |
systemFlags->copy (other->systemFlags);
|
insilmaril@0
|
73 |
standardFlags->copy (other->standardFlags);
|
insilmaril@0
|
74 |
|
insilmaril@2
|
75 |
ornamentsBBox=other->ornamentsBBox;
|
insilmaril@2
|
76 |
|
insilmaril@2
|
77 |
hideExport=other->hideExport;
|
insilmaril@2
|
78 |
url=other->url;
|
insilmaril@2
|
79 |
vymLink=other->vymLink;
|
insilmaril@0
|
80 |
}
|
insilmaril@0
|
81 |
|
insilmaril@0
|
82 |
QString OrnamentedObj::getHeading()
|
insilmaril@0
|
83 |
{
|
insilmaril@0
|
84 |
return heading->text();
|
insilmaril@0
|
85 |
}
|
insilmaril@0
|
86 |
|
insilmaril@0
|
87 |
void OrnamentedObj::setLinkColor()
|
insilmaril@0
|
88 |
{
|
insilmaril@0
|
89 |
if (mapEditor->getLinkColorHint()==HeadingColor)
|
insilmaril@0
|
90 |
LinkableMapObj::setLinkColor (heading->getColor());
|
insilmaril@0
|
91 |
else
|
insilmaril@0
|
92 |
LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
|
insilmaril@0
|
93 |
}
|
insilmaril@0
|
94 |
|
insilmaril@2
|
95 |
void OrnamentedObj::setColor (QColor col)
|
insilmaril@2
|
96 |
{
|
insilmaril@2
|
97 |
heading->setColor(col);
|
insilmaril@2
|
98 |
setLinkColor();
|
insilmaril@2
|
99 |
}
|
insilmaril@2
|
100 |
|
insilmaril@0
|
101 |
QColor OrnamentedObj::getColor ()
|
insilmaril@0
|
102 |
{
|
insilmaril@0
|
103 |
return heading->getColor();
|
insilmaril@0
|
104 |
}
|
insilmaril@0
|
105 |
|
insilmaril@0
|
106 |
|
insilmaril@2
|
107 |
void OrnamentedObj::positionContents()
|
insilmaril@2
|
108 |
{
|
insilmaril@2
|
109 |
double d=frame->getBorder()/2;
|
insilmaril@2
|
110 |
double x=absPos.x();
|
insilmaril@2
|
111 |
double y=absPos.y();
|
insilmaril@2
|
112 |
|
insilmaril@2
|
113 |
double ox,oy; // Offset due to padding
|
insilmaril@2
|
114 |
|
insilmaril@2
|
115 |
ox=leftPad + d;
|
insilmaril@2
|
116 |
oy=topPad + d;
|
insilmaril@2
|
117 |
|
insilmaril@2
|
118 |
systemFlags-> move (ox +x , oy + y );
|
insilmaril@2
|
119 |
|
insilmaril@2
|
120 |
// vertical align heading to bottom
|
insilmaril@2
|
121 |
heading->move (ox + x + systemFlags->getBBox().width(),
|
insilmaril@2
|
122 |
oy + y + ornamentsBBox.height() - heading->getHeight()
|
insilmaril@2
|
123 |
);
|
insilmaril@2
|
124 |
standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
|
insilmaril@2
|
125 |
|
insilmaril@2
|
126 |
ornamentsBBox.moveTopLeft ( QPoint ((int)(ox+x),(int)(oy+y)));
|
insilmaril@2
|
127 |
clickBox.moveTopLeft (QPoint ((int)(ox + x), (int)(oy + y)));
|
insilmaril@2
|
128 |
}
|
insilmaril@2
|
129 |
|
insilmaril@0
|
130 |
void OrnamentedObj::move (double x, double y)
|
insilmaril@0
|
131 |
{
|
insilmaril@0
|
132 |
MapObj::move (x,y);
|
insilmaril@2
|
133 |
positionContents();
|
insilmaril@0
|
134 |
updateLink();
|
insilmaril@0
|
135 |
requestReposition();
|
insilmaril@0
|
136 |
}
|
insilmaril@0
|
137 |
|
insilmaril@0
|
138 |
void OrnamentedObj::move (QPoint p)
|
insilmaril@0
|
139 |
{
|
insilmaril@0
|
140 |
move (p.x(), p.y());
|
insilmaril@0
|
141 |
}
|
insilmaril@0
|
142 |
|
insilmaril@0
|
143 |
void OrnamentedObj::moveBy (double x, double y)
|
insilmaril@0
|
144 |
{
|
insilmaril@0
|
145 |
|
insilmaril@0
|
146 |
MapObj::moveBy (x,y);
|
insilmaril@0
|
147 |
frame->moveBy (x,y);
|
insilmaril@0
|
148 |
systemFlags->moveBy (x,y);
|
insilmaril@0
|
149 |
standardFlags->moveBy (x,y);
|
insilmaril@0
|
150 |
heading->moveBy (x,y);
|
insilmaril@0
|
151 |
updateLink();
|
insilmaril@0
|
152 |
requestReposition();
|
insilmaril@0
|
153 |
}
|
insilmaril@0
|
154 |
|
insilmaril@0
|
155 |
void OrnamentedObj::moveBy (QPoint p)
|
insilmaril@0
|
156 |
{
|
insilmaril@0
|
157 |
moveBy (p.x(), p.y());
|
insilmaril@0
|
158 |
}
|
insilmaril@0
|
159 |
|
insilmaril@0
|
160 |
void OrnamentedObj::move2RelPos(double x, double y)
|
insilmaril@0
|
161 |
{
|
insilmaril@0
|
162 |
if (!parObj) return;
|
insilmaril@0
|
163 |
move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
|
insilmaril@0
|
164 |
}
|
insilmaril@0
|
165 |
|
insilmaril@0
|
166 |
void OrnamentedObj::move2RelPos(QPoint p)
|
insilmaril@0
|
167 |
{
|
insilmaril@2
|
168 |
move2RelPos (p.x(),p.y());
|
insilmaril@0
|
169 |
}
|
insilmaril@0
|
170 |
|
insilmaril@0
|
171 |
void OrnamentedObj::setNote(QString s)
|
insilmaril@0
|
172 |
{
|
insilmaril@0
|
173 |
note.setNote(s);
|
insilmaril@0
|
174 |
if (!note.isEmpty())
|
insilmaril@0
|
175 |
systemFlags->activate("note");
|
insilmaril@0
|
176 |
else
|
insilmaril@0
|
177 |
systemFlags->deactivate("note");
|
insilmaril@0
|
178 |
calcBBoxSize();
|
insilmaril@0
|
179 |
positionBBox();
|
insilmaril@0
|
180 |
move (absPos.x(), absPos.y() );
|
insilmaril@0
|
181 |
forceReposition();
|
insilmaril@0
|
182 |
}
|
insilmaril@0
|
183 |
|
insilmaril@0
|
184 |
void OrnamentedObj::setNote(NoteObj n)
|
insilmaril@0
|
185 |
{
|
insilmaril@0
|
186 |
note=n;
|
insilmaril@0
|
187 |
if (!note.isEmpty())
|
insilmaril@0
|
188 |
systemFlags->activate("note");
|
insilmaril@0
|
189 |
else
|
insilmaril@0
|
190 |
systemFlags->deactivate("note");
|
insilmaril@0
|
191 |
calcBBoxSize();
|
insilmaril@0
|
192 |
positionBBox();
|
insilmaril@0
|
193 |
move (absPos.x(), absPos.y() );
|
insilmaril@0
|
194 |
forceReposition();
|
insilmaril@0
|
195 |
|
insilmaril@0
|
196 |
}
|
insilmaril@0
|
197 |
|
insilmaril@0
|
198 |
QString OrnamentedObj::getNote()
|
insilmaril@0
|
199 |
{
|
insilmaril@0
|
200 |
return note.getNote();
|
insilmaril@0
|
201 |
}
|
insilmaril@0
|
202 |
|
insilmaril@2
|
203 |
QString OrnamentedObj::getNoteASCII()
|
insilmaril@0
|
204 |
{
|
insilmaril@2
|
205 |
return note.getNoteASCII();
|
insilmaril@2
|
206 |
}
|
insilmaril@2
|
207 |
|
insilmaril@2
|
208 |
QString OrnamentedObj::getNoteOpenDoc()
|
insilmaril@2
|
209 |
{
|
insilmaril@2
|
210 |
return note.getNoteOpenDoc();
|
insilmaril@2
|
211 |
}
|
insilmaril@2
|
212 |
|
insilmaril@2
|
213 |
void OrnamentedObj::setURL(QString s)
|
insilmaril@2
|
214 |
{
|
insilmaril@2
|
215 |
url=s;
|
insilmaril@2
|
216 |
if (!url.isEmpty())
|
insilmaril@2
|
217 |
systemFlags->activate("url");
|
insilmaril@2
|
218 |
else
|
insilmaril@2
|
219 |
systemFlags->deactivate("url");
|
insilmaril@2
|
220 |
calcBBoxSize(); // recalculate bbox
|
insilmaril@2
|
221 |
positionBBox(); // rearrange contents
|
insilmaril@2
|
222 |
forceReposition();
|
insilmaril@2
|
223 |
}
|
insilmaril@2
|
224 |
|
insilmaril@2
|
225 |
QString OrnamentedObj::getURL()
|
insilmaril@2
|
226 |
{
|
insilmaril@2
|
227 |
return url;
|
insilmaril@2
|
228 |
}
|
insilmaril@2
|
229 |
|
insilmaril@2
|
230 |
void OrnamentedObj::setVymLink(QString s)
|
insilmaril@2
|
231 |
{
|
insilmaril@2
|
232 |
if (!s.isEmpty())
|
insilmaril@2
|
233 |
{
|
insilmaril@2
|
234 |
// We need the relative (from loading)
|
insilmaril@2
|
235 |
// or absolute path (from User event)
|
insilmaril@2
|
236 |
// and build the absolute path.
|
insilmaril@2
|
237 |
// Note: If we have relative, use path of
|
insilmaril@2
|
238 |
// current map to build absolute path
|
insilmaril@2
|
239 |
QDir d(s);
|
insilmaril@2
|
240 |
if (!d.path().startsWith ("/"))
|
insilmaril@2
|
241 |
{
|
insilmaril@2
|
242 |
QString p=mapEditor->getDestPath();
|
insilmaril@2
|
243 |
int i=p.findRev("/",-1);
|
insilmaril@2
|
244 |
d.setPath(p.left(i)+"/"+s);
|
insilmaril@2
|
245 |
d.convertToAbs();
|
insilmaril@2
|
246 |
}
|
insilmaril@2
|
247 |
vymLink=d.path();
|
insilmaril@2
|
248 |
systemFlags->activate("vymLink");
|
insilmaril@2
|
249 |
}
|
insilmaril@2
|
250 |
else
|
insilmaril@2
|
251 |
{
|
insilmaril@2
|
252 |
systemFlags->deactivate("vymLink");
|
insilmaril@2
|
253 |
vymLink="";
|
insilmaril@2
|
254 |
}
|
insilmaril@2
|
255 |
calcBBoxSize(); // recalculate bbox
|
insilmaril@2
|
256 |
positionBBox(); // rearrange contents
|
insilmaril@2
|
257 |
forceReposition();
|
insilmaril@2
|
258 |
}
|
insilmaril@2
|
259 |
|
insilmaril@2
|
260 |
QString OrnamentedObj::getVymLink()
|
insilmaril@2
|
261 |
{
|
insilmaril@2
|
262 |
return vymLink;
|
insilmaril@2
|
263 |
}
|
insilmaril@2
|
264 |
|
insilmaril@2
|
265 |
|
insilmaril@2
|
266 |
void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
|
insilmaril@2
|
267 |
{
|
insilmaril@2
|
268 |
standardFlags->toggle(f,exclusive);
|
insilmaril@0
|
269 |
calcBBoxSize();
|
insilmaril@0
|
270 |
positionBBox();
|
insilmaril@0
|
271 |
move (absPos.x(), absPos.y() );
|
insilmaril@0
|
272 |
forceReposition();
|
insilmaril@0
|
273 |
}
|
insilmaril@0
|
274 |
|
insilmaril@0
|
275 |
void OrnamentedObj::activateStandardFlag(QString f)
|
insilmaril@0
|
276 |
{
|
insilmaril@0
|
277 |
standardFlags->activate(f);
|
insilmaril@0
|
278 |
calcBBoxSize();
|
insilmaril@0
|
279 |
positionBBox();
|
insilmaril@0
|
280 |
move (absPos.x(), absPos.y() );
|
insilmaril@0
|
281 |
forceReposition();
|
insilmaril@0
|
282 |
}
|
insilmaril@0
|
283 |
|
insilmaril@2
|
284 |
bool OrnamentedObj::isSetStandardFlag (QString f)
|
insilmaril@2
|
285 |
{
|
insilmaril@2
|
286 |
return standardFlags->isActive(f);
|
insilmaril@2
|
287 |
}
|
insilmaril@2
|
288 |
|
insilmaril@0
|
289 |
QString OrnamentedObj::getSystemFlagName(const QPoint &p)
|
insilmaril@0
|
290 |
{
|
insilmaril@0
|
291 |
return systemFlags->getFlagName(p);
|
insilmaril@0
|
292 |
}
|
insilmaril@0
|
293 |
|
insilmaril@2
|
294 |
bool OrnamentedObj::isActiveFlag (const QString & fname)
|
insilmaril@2
|
295 |
{
|
insilmaril@2
|
296 |
if (standardFlags->isActive (fname) ) return true;
|
insilmaril@2
|
297 |
return false;
|
insilmaril@2
|
298 |
}
|
insilmaril@2
|
299 |
|
insilmaril@0
|
300 |
void OrnamentedObj::updateNoteFlag()
|
insilmaril@0
|
301 |
{
|
insilmaril@2
|
302 |
if (selected)
|
insilmaril@2
|
303 |
{
|
insilmaril@2
|
304 |
// text in NoteEditor has changed, notify MapEditor
|
insilmaril@2
|
305 |
mapEditor->setChanged();
|
insilmaril@0
|
306 |
|
insilmaril@2
|
307 |
// save text
|
insilmaril@2
|
308 |
setNote( textEditor->getText() );
|
insilmaril@0
|
309 |
|
insilmaril@2
|
310 |
// save font
|
insilmaril@2
|
311 |
note.setFontHint (textEditor->getFontHint() );
|
insilmaril@2
|
312 |
}
|
insilmaril@0
|
313 |
}
|
insilmaril@0
|
314 |
|
insilmaril@2
|
315 |
void OrnamentedObj::setHideInExport(bool b)
|
insilmaril@2
|
316 |
{
|
insilmaril@2
|
317 |
if (parObj)
|
insilmaril@2
|
318 |
{
|
insilmaril@2
|
319 |
// Don't allow to MapCenter to be hidden
|
insilmaril@2
|
320 |
hideExport=b;
|
insilmaril@2
|
321 |
if (b)
|
insilmaril@2
|
322 |
systemFlags->activate("hideInExport");
|
insilmaril@2
|
323 |
else
|
insilmaril@2
|
324 |
systemFlags->deactivate("hideInExport");
|
insilmaril@2
|
325 |
calcBBoxSize();
|
insilmaril@2
|
326 |
positionBBox();
|
insilmaril@2
|
327 |
requestReposition();
|
insilmaril@2
|
328 |
}
|
insilmaril@2
|
329 |
}
|
insilmaril@2
|
330 |
|
insilmaril@2
|
331 |
bool OrnamentedObj::hideInExport()
|
insilmaril@2
|
332 |
{
|
insilmaril@2
|
333 |
return hideExport;
|
insilmaril@2
|
334 |
}
|
insilmaril@2
|
335 |
|
insilmaril@2
|
336 |
bool OrnamentedObj::isHidden()
|
insilmaril@2
|
337 |
{
|
insilmaril@2
|
338 |
return hidden;
|
insilmaril@2
|
339 |
}
|
insilmaril@2
|
340 |
|
insilmaril@2
|
341 |
QString OrnamentedObj::getOrnAttr()
|
insilmaril@2
|
342 |
{
|
insilmaril@2
|
343 |
QString posAttr;
|
insilmaril@2
|
344 |
|
insilmaril@2
|
345 |
if (useRelPos)
|
insilmaril@2
|
346 |
posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
|
insilmaril@2
|
347 |
attribut("relPosY",QString().setNum(relPos.y(),10));
|
insilmaril@2
|
348 |
else
|
insilmaril@2
|
349 |
{
|
insilmaril@2
|
350 |
if (depth==0 || depth==1) posAttr=
|
insilmaril@2
|
351 |
attribut("absPosX",QString().setNum(absPos.x(),10)) +
|
insilmaril@2
|
352 |
attribut("absPosY",QString().setNum(absPos.y(),10));
|
insilmaril@2
|
353 |
else
|
insilmaril@2
|
354 |
posAttr="";
|
insilmaril@2
|
355 |
}
|
insilmaril@2
|
356 |
|
insilmaril@2
|
357 |
QString urlAttr;
|
insilmaril@2
|
358 |
if (!url.isEmpty())
|
insilmaril@2
|
359 |
urlAttr=attribut ("url",url);
|
insilmaril@2
|
360 |
|
insilmaril@2
|
361 |
QString vymLinkAttr;
|
insilmaril@2
|
362 |
if (!vymLink.isEmpty())
|
insilmaril@2
|
363 |
vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
|
insilmaril@2
|
364 |
|
insilmaril@2
|
365 |
QString hideExpAttr;
|
insilmaril@2
|
366 |
if (hideExport)
|
insilmaril@2
|
367 |
hideExpAttr= attribut("hideInExport","true");
|
insilmaril@2
|
368 |
else
|
insilmaril@2
|
369 |
hideExpAttr="";
|
insilmaril@2
|
370 |
|
insilmaril@2
|
371 |
return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
|
insilmaril@2
|
372 |
}
|
insilmaril@2
|
373 |
|