File: ornamentedobj.cpp

package info (click to toggle)
vym 1.10.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,376 kB
  • ctags: 1,926
  • sloc: cpp: 18,468; xml: 277; sh: 211; perl: 89; makefile: 26
file content (489 lines) | stat: -rw-r--r-- 9,387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#include "ornamentedobj.h"
#include "texteditor.h"
#include "mapeditor.h"
#include "linkablemapobj.h"

extern TextEditor *textEditor;
extern FlagRowObj *systemFlagsDefault;
extern FlagRowObj *standardFlagsDefault;


/////////////////////////////////////////////////////////////////
// OrnamentedObj
/////////////////////////////////////////////////////////////////

OrnamentedObj::OrnamentedObj():LinkableMapObj()
{
  //  cout << "Const OrnamentedObj ()\n";
    init ();
}

OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
{
//    cout << "Const OrnamentedObj (s)\n";
    init ();
}

OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
{
    copy (lmo);
}

OrnamentedObj::~OrnamentedObj()
{
    delete heading;
	delete systemFlags;
	delete standardFlags;
	delete frame;
}


void OrnamentedObj::init ()
{
	heading = new HeadingObj(scene);
	heading->move (absPos.x(), absPos.y());

	note.setNote("");
	note.setFontHint (textEditor->getFontHintDefault() );
	isNoteInEditor=false;

	systemFlags=new FlagRowObj(scene);
	systemFlags->clone(systemFlagsDefault);
	systemFlags->setName ("systemFlags");
	
	standardFlags=new FlagRowObj(scene);
	standardFlags->clone(standardFlagsDefault);
	standardFlags->setName ("standardFlags");

	frame = new FrameObj (scene);

	hideExport=false;
	hidden=false;

	url="";
	vymLink="";
	
}

void OrnamentedObj::copy (OrnamentedObj* other)
{
    LinkableMapObj::copy(other);
	heading->copy(other->heading);
    setColor   (other->heading->getColor());	

	note.copy (other->note);
	systemFlags->copy (other->systemFlags);
	standardFlags->copy (other->standardFlags);

	ornamentsBBox=other->ornamentsBBox;

	hideExport=other->hideExport;
	url=other->url;
	vymLink=other->vymLink;
}

QString OrnamentedObj::getHeading()
{
    return heading->text();
}

void OrnamentedObj::setLinkColor()
{
	if (mapEditor->getMapLinkColorHint()==HeadingColor)
		LinkableMapObj::setLinkColor (heading->getColor());
	else	
		LinkableMapObj::setLinkColor (mapEditor->getMapDefLinkColor());
}

void OrnamentedObj::setColor (QColor col)
{
    heading->setColor(col);
	setLinkColor();
}

QColor OrnamentedObj::getColor ()
{
    return heading->getColor();
}

FrameObj::FrameType OrnamentedObj::getFrameType()
{
	return frame->getFrameType();
}

QString OrnamentedObj::getFrameTypeName()
{
	return frame->getFrameTypeName();
}

void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
{
	frame->setFrameType(t);
	if (t == FrameObj::NoFrame)
		linkpos=LinkableMapObj::Bottom;
	else	
		linkpos=LinkableMapObj::Middle;

	calcBBoxSize();
	positionBBox();
	requestReposition();
}

void OrnamentedObj::setFrameType(const QString &t)
{
	frame->setFrameType(t);
	if (frame->getFrameType() == FrameObj::NoFrame)
		linkpos=LinkableMapObj::Bottom;
	else	
		linkpos=LinkableMapObj::Middle;

	calcBBoxSize();
	positionBBox();
	requestReposition();
}

void OrnamentedObj::setFramePadding (const int &i)
{
	frame->setPadding (i);
	calcBBoxSize();
	positionBBox();
	requestReposition();
}

int OrnamentedObj::getFramePadding ()
{
	return frame->getPadding();
}

void OrnamentedObj::setFrameBorderWidth (const int &i)
{
	frame->setBorderWidth(i);
	calcBBoxSize();
	positionBBox();
	requestReposition();
}

int OrnamentedObj::getFrameBorderWidth()
{
	return frame->getBorderWidth();
}

void OrnamentedObj::setFramePenColor(QColor col)
{
	frame->setPenColor (col);
}

QColor OrnamentedObj::getFramePenColor()
{
	return frame->getPenColor ();
}

void OrnamentedObj::setFrameBrushColor(QColor col)
{
	frame->setBrushColor (col);
}

QColor OrnamentedObj::getFrameBrushColor()
{
	return frame->getBrushColor ();
}

void OrnamentedObj::positionContents()
{
	double d=frame->getPadding()/2;
	double x=absPos.x();
	double y=absPos.y();

	double ox,oy;	// Offset due to padding

	ox=leftPad + d;
	oy=topPad + d;
	
	systemFlags-> move (ox +x , oy + y );

	// vertical align heading to bottom
    heading->move (ox + x + systemFlags->getBBox().width(),
				   oy + y + ornamentsBBox.height() - heading->getHeight() 
					);
	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );

	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
}

void OrnamentedObj::move (double x, double y)
{
	MapObj::move (x,y);
	positionContents();
	updateLink();
	requestReposition();
}

void OrnamentedObj::move (QPointF p)
{
	move (p.x(), p.y());
}	

void OrnamentedObj::moveBy (double x, double y)
{

	MapObj::moveBy (x,y);
    frame->moveBy (x,y);
    systemFlags->moveBy (x,y);
    standardFlags->moveBy (x,y);
    heading->moveBy (x,y);
	updateLink();
	requestReposition();
}

void OrnamentedObj::moveBy (QPointF p)
{
	moveBy (p.x(), p.y());
}	

void OrnamentedObj::move2RelPos(double x, double y)
{
	setRelPos (QPointF((int)x,(int)y));
	if (parObj)
	{
		QPointF p=parObj->getChildPos();
		move (p.x()+x, p.y() +y);
	}
}

void OrnamentedObj::move2RelPos(QPointF p)
{
	move2RelPos (p.x(),p.y());
}

void OrnamentedObj::setNote(QString s)
{
	note.setNote(s);
	updateNoteFlag();
}

void OrnamentedObj::setNote(NoteObj n)
{
	note=n;
	updateNoteFlag();
}

QString OrnamentedObj::getNote()
{
    return note.getNote();
}

QString OrnamentedObj::getNoteASCII()
{
    return note.getNoteASCII();
}

QString OrnamentedObj::getNoteOpenDoc()
{
    return note.getNoteOpenDoc();
}

void OrnamentedObj::setURL(QString s)
{
	url=s;
	if (!url.isEmpty())
		systemFlags->activate("url");
	else	
		systemFlags->deactivate("url");
	calcBBoxSize();			// recalculate bbox
    positionBBox();			// rearrange contents
	forceReposition();
}

QString OrnamentedObj::getURL()
{
	return url;
}

void OrnamentedObj::setVymLink(QString s)
{
	if (!s.isEmpty())
	{
		// We need the relative (from loading) 
		// or absolute path (from User event)
		// and build the absolute path.
		// Note: If we have relative, use path of
		// current map to build absolute path
		QDir d(s);
		if (!d.path().startsWith ("/"))
		{
			QString p=mapEditor->getDestPath();
			int i=p.findRev("/",-1);
			d.setPath(p.left(i)+"/"+s);
			d.convertToAbs();
		}
		vymLink=d.path();
		systemFlags->activate("vymLink");
	}	
	else	
	{
		systemFlags->deactivate("vymLink");
		vymLink="";
	}	
	calcBBoxSize();			// recalculate bbox
    positionBBox();			// rearrange contents
	forceReposition();
}

QString OrnamentedObj::getVymLink()
{
	return vymLink;
}


void OrnamentedObj::clearStandardFlags()
{
	standardFlags->deactivateAll();
	calcBBoxSize();
	positionBBox();
	move (absPos.x(), absPos.y() );
	forceReposition();
}

void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
{
	standardFlags->toggle(f,exclusive);
	calcBBoxSize();
	positionBBox();
	move (absPos.x(), absPos.y() );
	forceReposition();
}

void OrnamentedObj::activateStandardFlag(QString f)
{
	standardFlags->activate(f);
	calcBBoxSize();
	positionBBox();
	move (absPos.x(), absPos.y() );
	forceReposition();
}

void OrnamentedObj::deactivateStandardFlag(QString f)
{
	standardFlags->deactivate(f);
	calcBBoxSize();
	positionBBox();
	move (absPos.x(), absPos.y() );
	forceReposition();
}

bool OrnamentedObj::isSetStandardFlag (QString f)
{
	return standardFlags->isActive(f);
}

QString OrnamentedObj::getSystemFlagName(const QPointF &p)
{
	return systemFlags->getFlagName(p);	
}

bool OrnamentedObj::isActiveFlag (const QString & fname)
{
	if (standardFlags->isActive (fname) ) return true;
	return false;
}

void OrnamentedObj::getNoteFromTextEditor ()
{
	note.setFilenameHint (textEditor->getFilename());
	note.setFontHint (textEditor->getFontHint() );
	setNote( textEditor->getText() );
}

void OrnamentedObj::updateNoteFlag()
{
	bool noteEmpty;
	if (isNoteInEditor)
		noteEmpty=textEditor->isEmpty();
	else	
		noteEmpty=note.isEmpty();

	if (!noteEmpty)
	{	
		if (systemFlags->isActive ("note")) return;
		systemFlags->activate("note");
	}	
	else		
	{	
		if (!systemFlags->isActive ("note")) return;
		systemFlags->deactivate("note");
	}	
	mapEditor->setChanged();
	calcBBoxSize();
	positionBBox();	
	move (absPos.x(), absPos.y() );
	forceReposition();
	
}	

void OrnamentedObj::updateFlagsToolbar()
{
	standardFlags->updateToolbar();
}

void OrnamentedObj::setHideInExport(bool b)
{
	if (parObj)
	{
		// Don't allow to MapCenter to be hidden
		hideExport=b;
		if (b)
			systemFlags->activate("hideInExport");
		else	
			systemFlags->deactivate("hideInExport");
		calcBBoxSize();
		positionBBox();
		requestReposition();	
	}
}	

bool OrnamentedObj::hideInExport()
{
	return hideExport;
}	

bool OrnamentedObj::isHidden()
{
	return hidden;
}	

QString OrnamentedObj::getOrnAttr()
{
	QString posAttr;

	if (depth==0)
		posAttr=		
			attribut("absPosX",QString().setNum(absPos.x())) +
			attribut("absPosY",QString().setNum(absPos.y())); 
	else
	{
		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
			posAttr=
				attribut("relPosX",QString().setNum(relPos.x())) +
				attribut("relPosY",QString().setNum(relPos.y())); 
		else
			posAttr="";
	}	

	QString urlAttr;
	if (!url.isEmpty())
		urlAttr=attribut ("url",url);

	QString vymLinkAttr;
	if (!vymLink.isEmpty())
		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );

	QString hideExpAttr;
	if (hideExport)
		hideExpAttr= attribut("hideInExport","true");
	else	
		hideExpAttr="";

	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
}