ornamentedobj.cpp
author insilmaril
Thu, 02 Apr 2009 09:46:29 +0000
changeset 750 ff3b01ce0960
parent 746 ee6b0f3a4c2f
child 753 25a77484ec72
permissions -rw-r--r--
More moving from BranchObj to BranchItem
insilmaril@611
     1
#include <typeinfo> 
insilmaril@611
     2
insilmaril@0
     3
#include "ornamentedobj.h"
insilmaril@0
     4
#include "texteditor.h"
insilmaril@0
     5
#include "mapeditor.h"
insilmaril@0
     6
#include "linkablemapobj.h"
insilmaril@0
     7
insilmaril@0
     8
extern TextEditor *textEditor;
insilmaril@0
     9
extern FlagRowObj *systemFlagsDefault;
insilmaril@0
    10
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
    11
insilmaril@0
    12
insilmaril@0
    13
/////////////////////////////////////////////////////////////////
insilmaril@0
    14
// OrnamentedObj
insilmaril@0
    15
/////////////////////////////////////////////////////////////////
insilmaril@0
    16
insilmaril@0
    17
OrnamentedObj::OrnamentedObj():LinkableMapObj()
insilmaril@0
    18
{
insilmaril@0
    19
  //  cout << "Const OrnamentedObj ()\n";
insilmaril@0
    20
    init ();
insilmaril@0
    21
}
insilmaril@0
    22
insilmaril@408
    23
OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
insilmaril@0
    24
{
insilmaril@408
    25
//    cout << "Const OrnamentedObj (s)\n";
insilmaril@0
    26
    init ();
insilmaril@0
    27
}
insilmaril@0
    28
insilmaril@408
    29
OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
insilmaril@0
    30
{
insilmaril@0
    31
    copy (lmo);
insilmaril@0
    32
}
insilmaril@0
    33
insilmaril@0
    34
OrnamentedObj::~OrnamentedObj()
insilmaril@0
    35
{
insilmaril@442
    36
    delete heading;
insilmaril@442
    37
	delete systemFlags;
insilmaril@442
    38
	delete standardFlags;
insilmaril@442
    39
	delete frame;
insilmaril@0
    40
}
insilmaril@0
    41
insilmaril@0
    42
insilmaril@0
    43
void OrnamentedObj::init ()
insilmaril@0
    44
{
insilmaril@408
    45
	heading = new HeadingObj(scene);
insilmaril@0
    46
	heading->move (absPos.x(), absPos.y());
insilmaril@0
    47
insilmaril@408
    48
	systemFlags=new FlagRowObj(scene);
insilmaril@0
    49
	systemFlags->clone(systemFlagsDefault);
insilmaril@0
    50
	systemFlags->setName ("systemFlags");
insilmaril@0
    51
	
insilmaril@408
    52
	standardFlags=new FlagRowObj(scene);
insilmaril@0
    53
	standardFlags->clone(standardFlagsDefault);
insilmaril@0
    54
	standardFlags->setName ("standardFlags");
insilmaril@243
    55
insilmaril@628
    56
	attributes.clear();
insilmaril@628
    57
insilmaril@442
    58
	frame = new FrameObj (scene);
insilmaril@442
    59
insilmaril@243
    60
	hideExport=false;
insilmaril@260
    61
	hidden=false;
insilmaril@243
    62
insilmaril@243
    63
	url="";
insilmaril@243
    64
	vymLink="";
insilmaril@243
    65
	
insilmaril@0
    66
}
insilmaril@0
    67
insilmaril@0
    68
void OrnamentedObj::copy (OrnamentedObj* other)
insilmaril@0
    69
{
insilmaril@0
    70
    LinkableMapObj::copy(other);
insilmaril@0
    71
	heading->copy(other->heading);
insilmaril@243
    72
    setColor   (other->heading->getColor());	
insilmaril@0
    73
insilmaril@0
    74
	systemFlags->copy (other->systemFlags);
insilmaril@0
    75
	standardFlags->copy (other->standardFlags);
insilmaril@0
    76
insilmaril@227
    77
	ornamentsBBox=other->ornamentsBBox;
insilmaril@227
    78
insilmaril@243
    79
	hideExport=other->hideExport;
insilmaril@243
    80
	url=other->url;
insilmaril@243
    81
	vymLink=other->vymLink;
insilmaril@0
    82
}
insilmaril@0
    83
insilmaril@0
    84
QString OrnamentedObj::getHeading()
insilmaril@0
    85
{
insilmaril@0
    86
    return heading->text();
insilmaril@0
    87
}
insilmaril@0
    88
insilmaril@0
    89
void OrnamentedObj::setLinkColor()
insilmaril@0
    90
{
insilmaril@721
    91
	if (model->getMapLinkColorHint()==HeadingColor)
insilmaril@0
    92
		LinkableMapObj::setLinkColor (heading->getColor());
insilmaril@0
    93
	else	
insilmaril@721
    94
		LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
insilmaril@0
    95
}
insilmaril@0
    96
insilmaril@243
    97
void OrnamentedObj::setColor (QColor col)
insilmaril@243
    98
{
insilmaril@243
    99
    heading->setColor(col);
insilmaril@243
   100
	setLinkColor();
insilmaril@243
   101
}
insilmaril@243
   102
insilmaril@0
   103
QColor OrnamentedObj::getColor ()
insilmaril@0
   104
{
insilmaril@0
   105
    return heading->getColor();
insilmaril@0
   106
}
insilmaril@0
   107
insilmaril@476
   108
FrameObj::FrameType OrnamentedObj::getFrameType()
insilmaril@442
   109
{
insilmaril@442
   110
	return frame->getFrameType();
insilmaril@442
   111
}
insilmaril@442
   112
insilmaril@476
   113
QString OrnamentedObj::getFrameTypeName()
insilmaril@476
   114
{
insilmaril@476
   115
	return frame->getFrameTypeName();
insilmaril@476
   116
}
insilmaril@476
   117
insilmaril@476
   118
void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
insilmaril@442
   119
{
insilmaril@442
   120
	frame->setFrameType(t);
insilmaril@476
   121
	if (t == FrameObj::NoFrame)
insilmaril@476
   122
		linkpos=LinkableMapObj::Bottom;
insilmaril@442
   123
	else	
insilmaril@476
   124
		linkpos=LinkableMapObj::Middle;
insilmaril@442
   125
insilmaril@442
   126
	calcBBoxSize();
insilmaril@442
   127
	positionBBox();
insilmaril@442
   128
	requestReposition();
insilmaril@442
   129
}
insilmaril@442
   130
insilmaril@442
   131
void OrnamentedObj::setFrameType(const QString &t)
insilmaril@442
   132
{
insilmaril@442
   133
	frame->setFrameType(t);
insilmaril@476
   134
	if (frame->getFrameType() == FrameObj::NoFrame)
insilmaril@476
   135
		linkpos=LinkableMapObj::Bottom;
insilmaril@442
   136
	else	
insilmaril@476
   137
		linkpos=LinkableMapObj::Middle;
insilmaril@442
   138
insilmaril@442
   139
	calcBBoxSize();
insilmaril@442
   140
	positionBBox();
insilmaril@442
   141
	requestReposition();
insilmaril@442
   142
}
insilmaril@442
   143
insilmaril@476
   144
void OrnamentedObj::setFramePadding (const int &i)
insilmaril@476
   145
{
insilmaril@476
   146
	frame->setPadding (i);
insilmaril@476
   147
	calcBBoxSize();
insilmaril@476
   148
	positionBBox();
insilmaril@476
   149
	requestReposition();
insilmaril@476
   150
}
insilmaril@476
   151
insilmaril@476
   152
int OrnamentedObj::getFramePadding ()
insilmaril@476
   153
{
insilmaril@476
   154
	return frame->getPadding();
insilmaril@476
   155
}
insilmaril@476
   156
insilmaril@476
   157
void OrnamentedObj::setFrameBorderWidth (const int &i)
insilmaril@476
   158
{
insilmaril@476
   159
	frame->setBorderWidth(i);
insilmaril@476
   160
	calcBBoxSize();
insilmaril@476
   161
	positionBBox();
insilmaril@476
   162
	requestReposition();
insilmaril@476
   163
}
insilmaril@476
   164
insilmaril@476
   165
int OrnamentedObj::getFrameBorderWidth()
insilmaril@476
   166
{
insilmaril@476
   167
	return frame->getBorderWidth();
insilmaril@476
   168
}
insilmaril@476
   169
insilmaril@442
   170
void OrnamentedObj::setFramePenColor(QColor col)
insilmaril@442
   171
{
insilmaril@442
   172
	frame->setPenColor (col);
insilmaril@442
   173
}
insilmaril@442
   174
insilmaril@442
   175
QColor OrnamentedObj::getFramePenColor()
insilmaril@442
   176
{
insilmaril@442
   177
	return frame->getPenColor ();
insilmaril@442
   178
}
insilmaril@442
   179
insilmaril@442
   180
void OrnamentedObj::setFrameBrushColor(QColor col)
insilmaril@442
   181
{
insilmaril@442
   182
	frame->setBrushColor (col);
insilmaril@442
   183
}
insilmaril@442
   184
insilmaril@442
   185
QColor OrnamentedObj::getFrameBrushColor()
insilmaril@442
   186
{
insilmaril@442
   187
	return frame->getBrushColor ();
insilmaril@442
   188
}
insilmaril@0
   189
insilmaril@177
   190
void OrnamentedObj::positionContents()
insilmaril@0
   191
{
insilmaril@476
   192
	double d=frame->getPadding()/2;
insilmaril@177
   193
	double x=absPos.x();
insilmaril@177
   194
	double y=absPos.y();
insilmaril@227
   195
insilmaril@227
   196
	double ox,oy;	// Offset due to padding
insilmaril@227
   197
insilmaril@227
   198
	ox=leftPad + d;
insilmaril@227
   199
	oy=topPad + d;
insilmaril@227
   200
	
insilmaril@227
   201
	systemFlags-> move (ox +x , oy + y );
insilmaril@0
   202
insilmaril@0
   203
	// vertical align heading to bottom
insilmaril@227
   204
    heading->move (ox + x + systemFlags->getBBox().width(),
insilmaril@227
   205
				   oy + y + ornamentsBBox.height() - heading->getHeight() 
insilmaril@0
   206
					);
insilmaril@227
   207
	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
insilmaril@227
   208
insilmaril@408
   209
	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
insilmaril@408
   210
	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
insilmaril@177
   211
}
insilmaril@0
   212
insilmaril@177
   213
void OrnamentedObj::move (double x, double y)
insilmaril@177
   214
{
insilmaril@177
   215
	MapObj::move (x,y);
insilmaril@177
   216
	positionContents();
insilmaril@0
   217
	updateLink();
insilmaril@0
   218
	requestReposition();
insilmaril@0
   219
}
insilmaril@0
   220
insilmaril@408
   221
void OrnamentedObj::move (QPointF p)
insilmaril@0
   222
{
insilmaril@0
   223
	move (p.x(), p.y());
insilmaril@0
   224
}	
insilmaril@0
   225
insilmaril@0
   226
void OrnamentedObj::moveBy (double x, double y)
insilmaril@0
   227
{
insilmaril@0
   228
insilmaril@0
   229
	MapObj::moveBy (x,y);
insilmaril@0
   230
    frame->moveBy (x,y);
insilmaril@0
   231
    systemFlags->moveBy (x,y);
insilmaril@0
   232
    standardFlags->moveBy (x,y);
insilmaril@0
   233
    heading->moveBy (x,y);
insilmaril@0
   234
	updateLink();
insilmaril@0
   235
	requestReposition();
insilmaril@0
   236
}
insilmaril@0
   237
insilmaril@408
   238
void OrnamentedObj::moveBy (QPointF p)
insilmaril@0
   239
{
insilmaril@0
   240
	moveBy (p.x(), p.y());
insilmaril@0
   241
}	
insilmaril@0
   242
insilmaril@0
   243
void OrnamentedObj::move2RelPos(double x, double y)
insilmaril@0
   244
{
insilmaril@694
   245
	setRelPos (QPointF(x,y));
insilmaril@388
   246
	if (parObj)
insilmaril@388
   247
	{
insilmaril@408
   248
		QPointF p=parObj->getChildPos();
insilmaril@388
   249
		move (p.x()+x, p.y() +y);
insilmaril@388
   250
	}
insilmaril@0
   251
}
insilmaril@0
   252
insilmaril@408
   253
void OrnamentedObj::move2RelPos(QPointF p)
insilmaril@0
   254
{
insilmaril@218
   255
	move2RelPos (p.x(),p.y());
insilmaril@0
   256
}
insilmaril@0
   257
insilmaril@243
   258
void OrnamentedObj::setURL(QString s)
insilmaril@243
   259
{
insilmaril@243
   260
	url=s;
insilmaril@243
   261
	if (!url.isEmpty())
insilmaril@243
   262
		systemFlags->activate("url");
insilmaril@243
   263
	else	
insilmaril@243
   264
		systemFlags->deactivate("url");
insilmaril@243
   265
	calcBBoxSize();			// recalculate bbox
insilmaril@243
   266
    positionBBox();			// rearrange contents
insilmaril@243
   267
	forceReposition();
insilmaril@243
   268
}
insilmaril@243
   269
insilmaril@243
   270
QString OrnamentedObj::getURL()
insilmaril@243
   271
{
insilmaril@243
   272
	return url;
insilmaril@243
   273
}
insilmaril@243
   274
insilmaril@243
   275
void OrnamentedObj::setVymLink(QString s)
insilmaril@243
   276
{
insilmaril@243
   277
	if (!s.isEmpty())
insilmaril@243
   278
	{
insilmaril@243
   279
		// We need the relative (from loading) 
insilmaril@243
   280
		// or absolute path (from User event)
insilmaril@243
   281
		// and build the absolute path.
insilmaril@243
   282
		// Note: If we have relative, use path of
insilmaril@243
   283
		// current map to build absolute path
insilmaril@243
   284
		QDir d(s);
insilmaril@243
   285
		if (!d.path().startsWith ("/"))
insilmaril@243
   286
		{
insilmaril@721
   287
			QString p=model->getDestPath();
insilmaril@243
   288
			int i=p.findRev("/",-1);
insilmaril@243
   289
			d.setPath(p.left(i)+"/"+s);
insilmaril@243
   290
			d.convertToAbs();
insilmaril@243
   291
		}
insilmaril@243
   292
		vymLink=d.path();
insilmaril@243
   293
		systemFlags->activate("vymLink");
insilmaril@243
   294
	}	
insilmaril@243
   295
	else	
insilmaril@243
   296
	{
insilmaril@243
   297
		systemFlags->deactivate("vymLink");
insilmaril@243
   298
		vymLink="";
insilmaril@243
   299
	}	
insilmaril@243
   300
	calcBBoxSize();			// recalculate bbox
insilmaril@243
   301
    positionBBox();			// rearrange contents
insilmaril@243
   302
	forceReposition();
insilmaril@243
   303
}
insilmaril@243
   304
insilmaril@243
   305
QString OrnamentedObj::getVymLink()
insilmaril@243
   306
{
insilmaril@243
   307
	return vymLink;
insilmaril@243
   308
}
insilmaril@243
   309
insilmaril@628
   310
insilmaril@628
   311
void OrnamentedObj::setAttributes (const QList <Attribute> &al)
insilmaril@628
   312
{
insilmaril@628
   313
	attributes=al;
insilmaril@628
   314
}
insilmaril@243
   315
insilmaril@638
   316
QList <Attribute> OrnamentedObj::getAttributes()
insilmaril@638
   317
{
insilmaril@638
   318
	return attributes;
insilmaril@638
   319
}
insilmaril@638
   320
insilmaril@447
   321
void OrnamentedObj::clearStandardFlags()
insilmaril@447
   322
{
insilmaril@447
   323
	standardFlags->deactivateAll();
insilmaril@447
   324
	calcBBoxSize();
insilmaril@447
   325
	positionBBox();
insilmaril@447
   326
	move (absPos.x(), absPos.y() );
insilmaril@447
   327
	forceReposition();
insilmaril@447
   328
}
insilmaril@447
   329
insilmaril@103
   330
void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
insilmaril@0
   331
{
insilmaril@103
   332
	standardFlags->toggle(f,exclusive);
insilmaril@0
   333
	calcBBoxSize();
insilmaril@0
   334
	positionBBox();
insilmaril@0
   335
	move (absPos.x(), absPos.y() );
insilmaril@0
   336
	forceReposition();
insilmaril@0
   337
}
insilmaril@0
   338
insilmaril@0
   339
void OrnamentedObj::activateStandardFlag(QString f)
insilmaril@0
   340
{
insilmaril@0
   341
	standardFlags->activate(f);
insilmaril@0
   342
	calcBBoxSize();
insilmaril@0
   343
	positionBBox();
insilmaril@0
   344
	move (absPos.x(), absPos.y() );
insilmaril@0
   345
	forceReposition();
insilmaril@0
   346
}
insilmaril@0
   347
insilmaril@366
   348
void OrnamentedObj::deactivateStandardFlag(QString f)
insilmaril@366
   349
{
insilmaril@366
   350
	standardFlags->deactivate(f);
insilmaril@366
   351
	calcBBoxSize();
insilmaril@366
   352
	positionBBox();
insilmaril@366
   353
	move (absPos.x(), absPos.y() );
insilmaril@366
   354
	forceReposition();
insilmaril@366
   355
}
insilmaril@366
   356
insilmaril@296
   357
bool OrnamentedObj::isSetStandardFlag (QString f)
insilmaril@296
   358
{
insilmaril@296
   359
	return standardFlags->isActive(f);
insilmaril@296
   360
}
insilmaril@296
   361
insilmaril@408
   362
QString OrnamentedObj::getSystemFlagName(const QPointF &p)
insilmaril@0
   363
{
insilmaril@0
   364
	return systemFlags->getFlagName(p);	
insilmaril@0
   365
}
insilmaril@0
   366
insilmaril@236
   367
bool OrnamentedObj::isActiveFlag (const QString & fname)
insilmaril@236
   368
{
insilmaril@236
   369
	if (standardFlags->isActive (fname) ) return true;
insilmaril@236
   370
	return false;
insilmaril@236
   371
}
insilmaril@236
   372
insilmaril@746
   373
/* FIXME-3 should move to VymView ?!  void OrnamentedObj::getNoteFromTextEditor ()
insilmaril@417
   374
{
insilmaril@417
   375
	note.setFilenameHint (textEditor->getFilename());
insilmaril@417
   376
	note.setFontHint (textEditor->getFontHint() );
insilmaril@417
   377
	setNote( textEditor->getText() );
insilmaril@417
   378
}
insilmaril@746
   379
*/
insilmaril@417
   380
insilmaril@746
   381
void OrnamentedObj::updateSystemFlags()
insilmaril@0
   382
{
insilmaril@746
   383
	// FIXME-3 check if note here and text in editor are still in sync!!	
insilmaril@746
   384
	// Best would be to always have current text here...
insilmaril@746
   385
	bool noteEmpty=treeItem->getNoteObj().isEmpty();
insilmaril@746
   386
	/*
insilmaril@417
   387
	if (isNoteInEditor)
insilmaril@417
   388
		noteEmpty=textEditor->isEmpty();
insilmaril@417
   389
	else	
insilmaril@417
   390
		noteEmpty=note.isEmpty();
insilmaril@746
   391
	*/	
insilmaril@0
   392
insilmaril@417
   393
	if (!noteEmpty)
insilmaril@417
   394
	{	
insilmaril@417
   395
		if (systemFlags->isActive ("note")) return;
insilmaril@417
   396
		systemFlags->activate("note");
insilmaril@417
   397
	}	
insilmaril@417
   398
	else		
insilmaril@417
   399
	{	
insilmaril@417
   400
		if (!systemFlags->isActive ("note")) return;
insilmaril@417
   401
		systemFlags->deactivate("note");
insilmaril@417
   402
	}	
insilmaril@746
   403
	//model->setChanged();
insilmaril@417
   404
	calcBBoxSize();
insilmaril@417
   405
	positionBBox();	
insilmaril@417
   406
	move (absPos.x(), absPos.y() );
insilmaril@417
   407
	forceReposition();
insilmaril@417
   408
}	
insilmaril@0
   409
insilmaril@366
   410
void OrnamentedObj::updateFlagsToolbar()
insilmaril@366
   411
{
insilmaril@366
   412
	standardFlags->updateToolbar();
insilmaril@366
   413
}
insilmaril@366
   414
insilmaril@243
   415
void OrnamentedObj::setHideInExport(bool b)
insilmaril@243
   416
{
insilmaril@260
   417
	if (parObj)
insilmaril@260
   418
	{
insilmaril@260
   419
		// Don't allow to MapCenter to be hidden
insilmaril@260
   420
		hideExport=b;
insilmaril@260
   421
		if (b)
insilmaril@260
   422
			systemFlags->activate("hideInExport");
insilmaril@260
   423
		else	
insilmaril@260
   424
			systemFlags->deactivate("hideInExport");
insilmaril@260
   425
		calcBBoxSize();
insilmaril@260
   426
		positionBBox();
insilmaril@260
   427
		requestReposition();	
insilmaril@260
   428
	}
insilmaril@243
   429
}	
insilmaril@243
   430
insilmaril@243
   431
bool OrnamentedObj::hideInExport()
insilmaril@243
   432
{
insilmaril@243
   433
	return hideExport;
insilmaril@243
   434
}	
insilmaril@243
   435
insilmaril@260
   436
bool OrnamentedObj::isHidden()
insilmaril@260
   437
{
insilmaril@260
   438
	return hidden;
insilmaril@260
   439
}	
insilmaril@260
   440
insilmaril@628
   441
QString OrnamentedObj::getOrnXMLAttr()
insilmaril@243
   442
{
insilmaril@243
   443
	QString posAttr;
insilmaril@252
   444
insilmaril@388
   445
	if (depth==0)
insilmaril@388
   446
		posAttr=		
insilmaril@408
   447
			attribut("absPosX",QString().setNum(absPos.x())) +
insilmaril@408
   448
			attribut("absPosY",QString().setNum(absPos.y())); 
insilmaril@243
   449
	else
insilmaril@252
   450
	{
insilmaril@395
   451
		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
insilmaril@635
   452
		{
insilmaril@635
   453
			if (relPos.x()==0 && relPos.y()==0)
insilmaril@635
   454
				setRelPos();
insilmaril@388
   455
			posAttr=
insilmaril@408
   456
				attribut("relPosX",QString().setNum(relPos.x())) +
insilmaril@408
   457
				attribut("relPosY",QString().setNum(relPos.y())); 
insilmaril@635
   458
		} else
insilmaril@252
   459
			posAttr="";
insilmaril@252
   460
	}	
insilmaril@243
   461
insilmaril@243
   462
	QString urlAttr;
insilmaril@243
   463
	if (!url.isEmpty())
insilmaril@243
   464
		urlAttr=attribut ("url",url);
insilmaril@243
   465
insilmaril@243
   466
	QString vymLinkAttr;
insilmaril@243
   467
	if (!vymLink.isEmpty())
insilmaril@721
   468
		vymLinkAttr=attribut ("vymLink",convertToRel(model->getDestPath(),vymLink) );
insilmaril@243
   469
insilmaril@243
   470
	QString hideExpAttr;
insilmaril@243
   471
	if (hideExport)
insilmaril@243
   472
		hideExpAttr= attribut("hideInExport","true");
insilmaril@243
   473
	else	
insilmaril@243
   474
		hideExpAttr="";
insilmaril@243
   475
insilmaril@243
   476
	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
insilmaril@243
   477
}
insilmaril@243
   478