branchobj.cpp
author insilmaril
Wed, 09 Jun 2010 13:14:08 +0000
changeset 847 43268373032d
parent 836 62d621e3e550
child 848 e265f07f2173
permissions -rw-r--r--
1.13.4 Various fixes
insilmaril@0
     1
#include "branchobj.h"
insilmaril@616
     2
insilmaril@822
     3
#include "attributeitem.h"
insilmaril@749
     4
#include "branchitem.h"
insilmaril@643
     5
#include "geometry.h"
insilmaril@0
     6
#include "mapeditor.h"
insilmaril@794
     7
#include "mainwindow.h"   
insilmaril@616
     8
#include "misc.h"
insilmaril@616
     9
insilmaril@767
    10
extern FlagRow *standardFlagsMaster;
insilmaril@767
    11
extern FlagRow *systemFlagsMaster;
insilmaril@0
    12
insilmaril@0
    13
/////////////////////////////////////////////////////////////////
insilmaril@0
    14
// BranchObj
insilmaril@0
    15
/////////////////////////////////////////////////////////////////
insilmaril@0
    16
insilmaril@790
    17
BranchObj::BranchObj (QGraphicsScene* s,TreeItem *ti):OrnamentedObj (s)
insilmaril@0
    18
{
insilmaril@755
    19
//    cout << "Const BranchObj (s)  \n";
insilmaril@408
    20
    scene=s;
insilmaril@790
    21
	treeItem=ti;
insilmaril@794
    22
	BranchItem *pi=(BranchItem*)(ti->parent());
insilmaril@794
    23
	if (pi && pi!=ti->getModel()->getRootItem() )
insilmaril@794
    24
		parObj=pi->getLMO();
insilmaril@794
    25
	else
insilmaril@794
    26
		parObj=NULL;
insilmaril@755
    27
	init();
insilmaril@0
    28
}
insilmaril@0
    29
insilmaril@0
    30
BranchObj::~BranchObj ()
insilmaril@0
    31
{
insilmaril@847
    32
	//qDebug()<< "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading()<<")";
insilmaril@757
    33
insilmaril@722
    34
	// If I'm animated, I need to un-animate myself first
insilmaril@722
    35
	if (anim.isAnimated() )
insilmaril@722
    36
	{
insilmaril@722
    37
		anim.setAnimated (false);
insilmaril@773
    38
		VymModel *model=treeItem->getModel();
insilmaril@722
    39
		model->stopAnimation (this);
insilmaril@722
    40
	}
insilmaril@722
    41
insilmaril@83
    42
	clear();
insilmaril@0
    43
}
insilmaril@0
    44
insilmaril@0
    45
void BranchObj::init () 
insilmaril@0
    46
{
insilmaril@83
    47
	if (parObj)
insilmaril@83
    48
	{
insilmaril@83
    49
		absPos=getRandPos();
insilmaril@83
    50
		absPos+=parObj->getChildPos();
insilmaril@83
    51
	}
insilmaril@0
    52
}
insilmaril@0
    53
insilmaril@0
    54
void BranchObj::copy (BranchObj* other)
insilmaril@0
    55
{
insilmaril@0
    56
    OrnamentedObj::copy(other);
insilmaril@0
    57
insilmaril@0
    58
	setVisibility (other->visible);
insilmaril@0
    59
insilmaril@0
    60
    positionBBox();
insilmaril@0
    61
}
insilmaril@0
    62
insilmaril@0
    63
void BranchObj::clear() 
insilmaril@0
    64
{
insilmaril@755
    65
	//setVisibility (true); //FIXME-4 needed?
insilmaril@0
    66
}
insilmaril@0
    67
insilmaril@819
    68
void BranchObj::setParObjTmp(LinkableMapObj* dst, QPointF m, int off)	
insilmaril@0
    69
{
insilmaril@796
    70
	// Temporary link to dst
insilmaril@0
    71
	// m is position of mouse pointer 
insilmaril@796
    72
	// offset 0: default 1: below dst   -1 above dst  (if possible)
insilmaril@0
    73
insilmaril@796
    74
	BranchItem *dsti=(BranchItem*)(dst->getTreeItem());
insilmaril@796
    75
insilmaril@796
    76
	BranchItem *pi=(BranchItem*)(dsti->parent());
insilmaril@775
    77
	int pi_depth=pi->depth();
insilmaril@815
    78
	BranchObj* bodst=(BranchObj*)dst;
insilmaril@0
    79
insilmaril@798
    80
	if (!tmpParent) 
insilmaril@798
    81
	{
insilmaril@798
    82
		tmpParent=true;
insilmaril@798
    83
		parObjTmpBuf=parObj;
insilmaril@798
    84
	}
insilmaril@796
    85
insilmaril@775
    86
	if (pi_depth<2) off=0;
insilmaril@0
    87
	if (off==0)
insilmaril@0
    88
		link2ParPos=false;
insilmaril@0
    89
	else
insilmaril@0
    90
		link2ParPos=true;
insilmaril@815
    91
	parObj=bodst;
insilmaril@0
    92
insilmaril@796
    93
	setLinkStyle (dst->getDefLinkStyle (dsti));
insilmaril@814
    94
 
insilmaril@0
    95
	// Move temporary to new position at destination
insilmaril@0
    96
	// Usually the positioning would be done by reposition(),
insilmaril@0
    97
	// but then also the destination branch would "Jump" around...
insilmaril@0
    98
	// Better just do it approximately
insilmaril@814
    99
	if (dsti->depth()==0)	
insilmaril@786
   100
	{	// new parent is a mapcenter
insilmaril@815
   101
		Vector v= ( m - bodst->getChildPos());
insilmaril@798
   102
		if (v.x()<0) v.setX( v.x()-bbox.width() );
insilmaril@798
   103
		v.normalize();
insilmaril@798
   104
		v.scale (100);
insilmaril@798
   105
		move2RelPos (v.toQPointF());
insilmaril@0
   106
	} else
insilmaril@0
   107
	{	
insilmaril@408
   108
		qreal y;
insilmaril@0
   109
		if (off==0)
insilmaril@0
   110
		{
insilmaril@0
   111
			// new parent is just a branch, link to it
insilmaril@815
   112
			QRectF t=bodst->getBBoxSizeWithChildren();
insilmaril@796
   113
			if (dsti->getLastBranch())
insilmaril@0
   114
				y=t.y() + t.height() ;
insilmaril@0
   115
			else
insilmaril@0
   116
				y=t.y();
insilmaril@0
   117
insilmaril@815
   118
			y=t.bottom();
insilmaril@815
   119
insilmaril@0
   120
		} else
insilmaril@0
   121
		{
insilmaril@0
   122
			if (off<0)
insilmaril@796
   123
				// we want to link above dst
insilmaril@815
   124
				y=bodst->y() - height() + 5;
insilmaril@0
   125
			else	
insilmaril@796
   126
				// we want to link below dst
insilmaril@0
   127
				// Bottom of sel should be 5 pixels above
insilmaril@0
   128
				// the bottom of the branch _below_ the target:
insilmaril@0
   129
				// Don't try to find that branch, guess 12 pixels
insilmaril@815
   130
				y=bodst->getChildPos().y()  -height() + 12; 
insilmaril@0
   131
		}	
insilmaril@815
   132
		if (bodst->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@815
   133
			move ( bodst->getChildPos().x() - linkwidth, y );
insilmaril@0
   134
		else	
insilmaril@815
   135
			move (bodst->getChildPos().x() + linkwidth, y );
insilmaril@0
   136
	}	
insilmaril@0
   137
insilmaril@779
   138
	// updateLinkGeometry is called implicitly in move
insilmaril@417
   139
	requestReposition();	
insilmaril@0
   140
}
insilmaril@0
   141
insilmaril@0
   142
void BranchObj::unsetParObjTmp()
insilmaril@0
   143
{
insilmaril@798
   144
	if (tmpParent) 
insilmaril@0
   145
	{
insilmaril@798
   146
		tmpParent=false;
insilmaril@0
   147
		link2ParPos=false;
insilmaril@0
   148
		parObj=parObjTmpBuf;
insilmaril@0
   149
		parObjTmpBuf=NULL;
insilmaril@786
   150
		setLinkStyle (getDefLinkStyle(treeItem->parent() ) );
insilmaril@779
   151
		updateLinkGeometry();
insilmaril@0
   152
	}		
insilmaril@0
   153
}
insilmaril@0
   154
insilmaril@0
   155
void BranchObj::setVisibility(bool v, int toDepth)
insilmaril@0
   156
{
insilmaril@749
   157
	BranchItem *bi=(BranchItem*)treeItem;
insilmaril@755
   158
    if (bi->depth() <= toDepth)
insilmaril@0
   159
    {
insilmaril@0
   160
		frame->setVisibility(v);
insilmaril@0
   161
		heading->setVisibility(v);
insilmaril@0
   162
		systemFlags->setVisibility(v);
insilmaril@0
   163
		standardFlags->setVisibility(v);
insilmaril@0
   164
		LinkableMapObj::setVisibility (v);
insilmaril@730
   165
		int i;
insilmaril@785
   166
		for (i=0; i<treeItem->imageCount(); ++i)
insilmaril@785
   167
			treeItem->getImageObjNum(i)->setVisibility (v);
insilmaril@790
   168
		for (i=0; i<treeItem->xlinkCount(); ++i)	
insilmaril@790
   169
			treeItem->getXLinkObjNum(i)->setVisibility ();	
insilmaril@730
   170
insilmaril@721
   171
		// Only change children, if I am not scrolled
insilmaril@749
   172
		if (! bi->isScrolled() && (bi->depth() < toDepth))
insilmaril@0
   173
		{
insilmaril@785
   174
			// Now go recursivly through all children //FIXME-3 are there multiple calls for lower level items???
insilmaril@750
   175
			for (i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   176
				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
insilmaril@0
   177
		}
insilmaril@0
   178
    } // depth <= toDepth	
insilmaril@0
   179
	requestReposition();
insilmaril@0
   180
}	
insilmaril@0
   181
insilmaril@0
   182
void BranchObj::setVisibility(bool v)
insilmaril@0
   183
{
insilmaril@0
   184
    setVisibility (v,MAX_DEPTH);
insilmaril@0
   185
}
insilmaril@0
   186
insilmaril@0
   187
insilmaril@0
   188
void BranchObj::setLinkColor ()
insilmaril@0
   189
{
insilmaril@0
   190
	// Overloaded from LinkableMapObj
insilmaril@0
   191
	// BranchObj can use color of heading
insilmaril@0
   192
insilmaril@773
   193
	VymModel *model=treeItem->getModel();
insilmaril@721
   194
	if (model)
insilmaril@611
   195
	{
insilmaril@721
   196
		if (model->getMapLinkColorHint()==HeadingColor)
insilmaril@164
   197
			LinkableMapObj::setLinkColor (heading->getColor() );
insilmaril@164
   198
		else	
insilmaril@164
   199
			LinkableMapObj::setLinkColor ();
insilmaril@611
   200
	}		
insilmaril@0
   201
}
insilmaril@0
   202
insilmaril@753
   203
void BranchObj::updateContentSize()
insilmaril@753
   204
{
insilmaril@753
   205
	calcBBoxSize();
insilmaril@753
   206
	positionBBox();
insilmaril@753
   207
	requestReposition();
insilmaril@100
   208
}
insilmaril@0
   209
insilmaril@333
   210
void BranchObj::positionContents()
insilmaril@333
   211
{
insilmaril@785
   212
	for (int i=0; i<treeItem->imageCount(); ++i)
insilmaril@785
   213
		treeItem->getImageObjNum(i)->reposition();
insilmaril@333
   214
	OrnamentedObj::positionContents();
insilmaril@333
   215
}
insilmaril@0
   216
insilmaril@0
   217
void BranchObj::move (double x, double y)
insilmaril@0
   218
{
insilmaril@0
   219
	OrnamentedObj::move (x,y);
insilmaril@0
   220
    positionBBox();
insilmaril@0
   221
}
insilmaril@0
   222
insilmaril@408
   223
void BranchObj::move (QPointF p)
insilmaril@0
   224
{
insilmaril@0
   225
	move (p.x(), p.y());
insilmaril@0
   226
}
insilmaril@0
   227
insilmaril@0
   228
void BranchObj::moveBy (double x, double y)
insilmaril@0
   229
{
insilmaril@0
   230
	OrnamentedObj::moveBy (x,y);
insilmaril@750
   231
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   232
		treeItem->getBranchObjNum(i)->moveBy (x,y);
insilmaril@333
   233
    positionBBox();
insilmaril@0
   234
}
insilmaril@83
   235
	
insilmaril@408
   236
void BranchObj::moveBy (QPointF p)
insilmaril@0
   237
{
insilmaril@0
   238
	moveBy (p.x(), p.y());
insilmaril@0
   239
}
insilmaril@0
   240
insilmaril@0
   241
insilmaril@0
   242
void BranchObj::positionBBox()
insilmaril@0
   243
{
insilmaril@408
   244
	QPointF ap=getAbsPos();
insilmaril@223
   245
	bbox.moveTopLeft (ap);
insilmaril@169
   246
	positionContents();
insilmaril@0
   247
insilmaril@0
   248
	// set the frame
insilmaril@408
   249
	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@83
   250
insilmaril@847
   251
	//Update links to other branches	
insilmaril@790
   252
	XLinkObj *xlo;
insilmaril@790
   253
	for (int i=0; i<treeItem->xlinkCount(); ++i)	
insilmaril@790
   254
	{
insilmaril@790
   255
		xlo=treeItem->getXLinkObjNum(i);
insilmaril@790
   256
		if (xlo) xlo->updateXLink();
insilmaril@790
   257
	}	
insilmaril@0
   258
}
insilmaril@0
   259
insilmaril@0
   260
void BranchObj::calcBBoxSize()
insilmaril@0
   261
{
insilmaril@408
   262
    QSizeF heading_r=heading->getSize();
insilmaril@408
   263
    qreal heading_w=(qreal) heading_r.width() ;
insilmaril@408
   264
    qreal heading_h=(qreal) heading_r.height() ;
insilmaril@767
   265
    QSizeF sysflags_r=systemFlags->getSize();
insilmaril@767
   266
	qreal sysflags_h=sysflags_r.height();
insilmaril@767
   267
	qreal sysflags_w=sysflags_r.width();
insilmaril@767
   268
    QSizeF stanflags_r=standardFlags->getSize();
insilmaril@767
   269
	qreal stanflags_h=stanflags_r.height();
insilmaril@767
   270
	qreal stanflags_w=stanflags_r.width();
insilmaril@408
   271
    qreal w;
insilmaril@408
   272
    qreal h;
insilmaril@0
   273
insilmaril@0
   274
	// set width to sum of all widths
insilmaril@0
   275
	w=heading_w + sysflags_w + stanflags_w;
insilmaril@0
   276
	// set height to maximum needed height
insilmaril@0
   277
	h=max (sysflags_h,stanflags_h);
insilmaril@0
   278
	h=max (h,heading_h);
insilmaril@0
   279
insilmaril@223
   280
	// Save the dimension of flags and heading
insilmaril@408
   281
	ornamentsBBox.setSize ( QSizeF(w,h));
insilmaril@223
   282
insilmaril@223
   283
	// clickBox includes Flags and Heading
insilmaril@223
   284
    clickBox.setSize (ornamentsBBox.size() );
insilmaril@169
   285
insilmaril@169
   286
	// Floatimages 
insilmaril@408
   287
	QPointF rp;
insilmaril@169
   288
insilmaril@169
   289
	topPad=botPad=leftPad=rightPad=0;
insilmaril@785
   290
	bool incV=((BranchItem*)treeItem)->getIncludeImagesVer();
insilmaril@785
   291
	bool incH=((BranchItem*)treeItem)->getIncludeImagesHor();
insilmaril@785
   292
	if (incH || incV)
insilmaril@169
   293
	{
insilmaril@785
   294
		FloatImageObj *fio;
insilmaril@785
   295
		for (int i=0; i<treeItem->imageCount(); ++i )	
insilmaril@169
   296
		{
insilmaril@785
   297
			fio=treeItem->getImageObjNum(i);
insilmaril@785
   298
			rp=fio->getRelPos();
insilmaril@785
   299
			if (incV)
insilmaril@169
   300
			{
insilmaril@785
   301
				if (rp.y() < 0) 
insilmaril@785
   302
					topPad=max (topPad,-rp.y()-h);
insilmaril@785
   303
				if (rp.y()+fio->height() > 0)
insilmaril@785
   304
					botPad=max (botPad,rp.y()+fio->height());
insilmaril@785
   305
			}		
insilmaril@785
   306
			if (incH)
insilmaril@785
   307
			{
insilmaril@785
   308
				if (orientation==LinkableMapObj::RightOfCenter)
insilmaril@169
   309
				{
insilmaril@785
   310
					if (-rp.x()-w > 0) 
insilmaril@785
   311
						leftPad=max (leftPad,-rp.x()-w);
insilmaril@785
   312
					if (rp.x()+fio->width() > 0)
insilmaril@785
   313
						rightPad=max (rightPad,rp.x()+fio->width());
insilmaril@785
   314
				} else
insilmaril@213
   315
				{
insilmaril@785
   316
					if (rp.x()< 0) 
insilmaril@785
   317
						leftPad=max (leftPad,-rp.x());
insilmaril@785
   318
					if (rp.x()+fio->width() > w)
insilmaril@785
   319
						rightPad=max (rightPad,rp.x()+fio->width()-w);
insilmaril@785
   320
				}
insilmaril@785
   321
			}		
insilmaril@169
   322
		}	
insilmaril@169
   323
		h+=topPad+botPad;
insilmaril@213
   324
		w+=leftPad+rightPad;
insilmaril@169
   325
	}
insilmaril@169
   326
insilmaril@169
   327
	// Frame thickness
insilmaril@462
   328
    w+=frame->getPadding();
insilmaril@462
   329
    h+=frame->getPadding();
insilmaril@169
   330
	
insilmaril@169
   331
	// Finally set size
insilmaril@408
   332
    bbox.setSize (QSizeF (w,h));
insilmaril@0
   333
}
insilmaril@0
   334
insilmaril@223
   335
void BranchObj::setDockPos()
insilmaril@223
   336
{
insilmaril@775
   337
	if (treeItem->getType()==TreeItem::MapCenter)
insilmaril@775
   338
	{
insilmaril@775
   339
		// set childPos to middle of MapCenterObj
insilmaril@775
   340
		childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
insilmaril@775
   341
		childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
insilmaril@775
   342
		parPos=childPos;		
insilmaril@775
   343
		for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@779
   344
			treeItem->getBranchObjNum(i)->updateLinkGeometry();
insilmaril@775
   345
insilmaril@775
   346
	} else
insilmaril@775
   347
	{
insilmaril@775
   348
		// Sets childpos and parpos depending on orientation
insilmaril@775
   349
		if (getOrientation()==LinkableMapObj::LeftOfCenter )
insilmaril@775
   350
		{
insilmaril@775
   351
			childPos=QPointF (
insilmaril@775
   352
				ornamentsBBox.bottomLeft().x(), 
insilmaril@775
   353
				bottomlineY);
insilmaril@775
   354
			parPos=QPointF (
insilmaril@775
   355
				ornamentsBBox.bottomRight().x(),
insilmaril@775
   356
				bottomlineY);
insilmaril@775
   357
		} else
insilmaril@775
   358
		{
insilmaril@775
   359
			childPos=QPointF (
insilmaril@775
   360
				ornamentsBBox.bottomRight().x(), 
insilmaril@775
   361
				bottomlineY);
insilmaril@775
   362
			parPos=QPointF (
insilmaril@775
   363
				ornamentsBBox.bottomLeft().x(),
insilmaril@775
   364
				bottomlineY);
insilmaril@775
   365
		}
insilmaril@775
   366
	}
insilmaril@223
   367
}
insilmaril@382
   368
insilmaril@767
   369
void BranchObj::updateData()
insilmaril@0
   370
{
insilmaril@767
   371
	bool changed=false;
insilmaril@753
   372
	if (!treeItem)
insilmaril@254
   373
	{
insilmaril@753
   374
		qWarning ("BranchObj::udpateHeading treeItem==NULL");
insilmaril@753
   375
		return;
insilmaril@753
   376
	}
insilmaril@767
   377
	QString s=treeItem->getHeading();
insilmaril@767
   378
	if (s!=heading->text())
insilmaril@767
   379
	{
insilmaril@767
   380
		heading->setText (s);
insilmaril@767
   381
		changed=true;
insilmaril@767
   382
	}
insilmaril@767
   383
	QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
insilmaril@767
   384
insilmaril@767
   385
	// Add missing standard flags active in TreeItem
insilmaril@767
   386
	for (int i=0;i<=TIactiveFlags.size()-1;i++)
insilmaril@767
   387
	{	
insilmaril@767
   388
		if (!standardFlags->isActive (TIactiveFlags.at(i) ))
insilmaril@767
   389
		{
insilmaril@767
   390
			Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
insilmaril@767
   391
			if (f) standardFlags->activate (f);
insilmaril@767
   392
			changed=true;
insilmaril@767
   393
		}
insilmaril@767
   394
	}
insilmaril@767
   395
	// Remove standard flags no longer active in TreeItem
insilmaril@767
   396
	QStringList BOactiveFlags=standardFlags->activeFlagNames();
insilmaril@767
   397
	for (int i=0;i<BOactiveFlags.size();++i)
insilmaril@767
   398
		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
insilmaril@767
   399
		{
insilmaril@767
   400
			standardFlags->deactivate (BOactiveFlags.at(i));
insilmaril@767
   401
			changed=true;
insilmaril@767
   402
		}	
insilmaril@767
   403
insilmaril@767
   404
	// Add missing system flags active in TreeItem
insilmaril@767
   405
	TIactiveFlags=treeItem->activeSystemFlagNames();
insilmaril@767
   406
	for (int i=0;i<TIactiveFlags.size();++i)
insilmaril@767
   407
	{	
insilmaril@767
   408
		if (!systemFlags->isActive (TIactiveFlags.at(i) ))
insilmaril@767
   409
		{
insilmaril@767
   410
			Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
insilmaril@767
   411
			if (f) systemFlags->activate (f);
insilmaril@767
   412
			changed=true;
insilmaril@767
   413
		}
insilmaril@767
   414
	}
insilmaril@767
   415
	// Remove system flags no longer active in TreeItem
insilmaril@767
   416
	BOactiveFlags=systemFlags->activeFlagNames();
insilmaril@767
   417
	for (int i=0;i<BOactiveFlags.size();++i)
insilmaril@767
   418
	{
insilmaril@767
   419
		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
insilmaril@767
   420
		{
insilmaril@767
   421
			systemFlags->deactivate (BOactiveFlags.at(i));
insilmaril@767
   422
			changed=true;
insilmaril@767
   423
		}	
insilmaril@767
   424
	}
insilmaril@819
   425
	if (changed) updateContentSize(); 
insilmaril@254
   426
}
insilmaril@254
   427
insilmaril@822
   428
void BranchObj::setDefAttr (BranchModification mod, bool keepFrame)
insilmaril@146
   429
{
insilmaril@146
   430
	int fontsize;
insilmaril@755
   431
	switch (treeItem->depth())
insilmaril@146
   432
	{
insilmaril@798
   433
		case 0: 
insilmaril@798
   434
			fontsize=16; 
insilmaril@798
   435
			break;
insilmaril@798
   436
		case 1: 
insilmaril@804
   437
			fontsize=14; 
insilmaril@804
   438
			break;
insilmaril@804
   439
		case 2: 
insilmaril@798
   440
			fontsize=12; 
insilmaril@798
   441
			break;
insilmaril@798
   442
		default: 
insilmaril@798
   443
			fontsize=10; 
insilmaril@798
   444
			break;
insilmaril@146
   445
	}	
insilmaril@786
   446
	setLinkStyle(getDefLinkStyle(treeItem->parent() ));
insilmaril@146
   447
	setLinkColor ();
insilmaril@146
   448
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
   449
	font.setPointSize(fontsize);
insilmaril@146
   450
	heading->setFont(font );
insilmaril@146
   451
insilmaril@822
   452
	if (mod==NewBranch && !keepFrame)
insilmaril@823
   453
	{
insilmaril@823
   454
		if (treeItem->depth()==0)
insilmaril@823
   455
			setFrameType (FrameObj::Rectangle);
insilmaril@823
   456
		else	
insilmaril@823
   457
			setFrameType (FrameObj::NoFrame);
insilmaril@823
   458
	}
insilmaril@146
   459
	if (mod==NewBranch)
insilmaril@760
   460
		setColor (treeItem->getHeadingColor() );
insilmaril@798
   461
	else
insilmaril@822
   462
	{
insilmaril@798
   463
		// Also set styles for children
insilmaril@798
   464
		for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@798
   465
			treeItem->getBranchObjNum(i)->setDefAttr(MovedBranch);
insilmaril@822
   466
	}		
insilmaril@146
   467
	calcBBoxSize();
insilmaril@146
   468
}
insilmaril@146
   469
insilmaril@721
   470
void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
insilmaril@0
   471
{
insilmaril@408
   472
	qreal th = bboxTotal.height();	
insilmaril@817
   473
	int depth=0;
insilmaril@817
   474
	if (parObj)	depth=1 + parObj->getTreeItem()->depth();
insilmaril@223
   475
// TODO testing
insilmaril@223
   476
/*
insilmaril@817
   477
	QString h=QString (depth+1,' ');
insilmaril@753
   478
	h+=treeItem->getHeading();
insilmaril@753
   479
	h+=QString (15,' ');
insilmaril@753
   480
	h.truncate (15);
insilmaril@817
   481
	QPointF pp; 
insilmaril@817
   482
	if (parObj) pp=parObj->getChildPos();
insilmaril@753
   483
	cout << "BO::alignRelTo ";
insilmaril@753
   484
	cout<<h.toStdString();
insilmaril@817
   485
	cout << "    d="<<depth;
insilmaril@817
   486
	cout <<"  parO="<<parObj;
insilmaril@755
   487
//cout<<  "  ref="<<ref<<
insilmaril@817
   488
//cout <<	"  bbox.tL="<<bboxTotal.topLeft();
insilmaril@817
   489
cout<<	"  absPos="<<absPos<<
insilmaril@795
   490
		"  relPos="<<relPos<<
insilmaril@721
   491
//		"  parPos="<<pp<<
insilmaril@795
   492
//		"  w="<<bbox.width()<<
insilmaril@795
   493
//		"  h="<<bbox.height()<<
insilmaril@753
   494
//		"  orient="<<orientation<<
insilmaril@753
   495
//		"  alignSelf="<<alignSelf<<
insilmaril@753
   496
//		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
insilmaril@254
   497
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
   498
//		"  hidden="<<hidden<<
insilmaril@817
   499
//		"  th="<<th<<
insilmaril@382
   500
		endl;
insilmaril@394
   501
*/
insilmaril@0
   502
insilmaril@382
   503
	setOrientation();
insilmaril@779
   504
	//updateLinkGeometry();
insilmaril@382
   505
insilmaril@796
   506
	if (depth==1)
insilmaril@796
   507
	{
insilmaril@796
   508
		move2RelPos (getRelPos() );
insilmaril@796
   509
	}
insilmaril@753
   510
	if (depth>1)
insilmaril@0
   511
    {
insilmaril@0
   512
		// Align myself depending on orientation and parent, but
insilmaril@382
   513
		// only if I am not a mainbranch or mapcenter itself
insilmaril@688
   514
insilmaril@688
   515
		if (anim.isAnimated())
insilmaril@0
   516
		{
insilmaril@688
   517
			move2RelPos(anim);
insilmaril@688
   518
		} else
insilmaril@688
   519
		{
insilmaril@688
   520
			LinkableMapObj::Orientation o;
insilmaril@688
   521
			o=parObj->getOrientation();
insilmaril@721
   522
			if (alignSelf)
insilmaril@721
   523
				switch (orientation) 
insilmaril@721
   524
				{
insilmaril@721
   525
					case LinkableMapObj::LeftOfCenter:
insilmaril@721
   526
						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@721
   527
						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
insilmaril@721
   528
					break;
insilmaril@721
   529
					case LinkableMapObj::RightOfCenter:	
insilmaril@721
   530
						move (ref.x() , ref.y() + (th-bbox.height())/2  );
insilmaril@721
   531
					break;
insilmaril@721
   532
					default:
insilmaril@721
   533
						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
insilmaril@721
   534
					break;
insilmaril@753
   535
			}
insilmaril@688
   536
		}
insilmaril@0
   537
    }		
insilmaril@0
   538
insilmaril@749
   539
	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
insilmaril@0
   540
insilmaril@721
   541
    // Set reference point for alignment of children
insilmaril@408
   542
    QPointF ref2;
insilmaril@462
   543
    if (orientation==LinkableMapObj::LeftOfCenter)
insilmaril@223
   544
		ref2.setX(bbox.topLeft().x() - linkwidth);
insilmaril@0
   545
    else	
insilmaril@223
   546
		ref2.setX(bbox.topRight().x() + linkwidth);
insilmaril@0
   547
insilmaril@0
   548
	if (depth==1)
insilmaril@0
   549
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
   550
	else	
insilmaril@0
   551
		ref2.setY(ref.y() );	
insilmaril@0
   552
insilmaril@822
   553
    // Align the attribute children depending on reference point 
insilmaril@822
   554
	// on top like in TreeEditor
insilmaril@822
   555
	for (int i=0; i<treeItem->attributeCount(); ++i)
insilmaril@822
   556
    {	
insilmaril@822
   557
		if (!treeItem->getAttributeNum(i)->isHidden())
insilmaril@822
   558
		{
insilmaril@822
   559
			BranchObj *bo=(BranchObj*)(treeItem->getAttributeNum(i)->getBranchObj());
insilmaril@822
   560
			if (!bo) break;
insilmaril@822
   561
			bo->alignRelativeTo (ref2,true);
insilmaril@822
   562
insilmaril@822
   563
			// append next branch below current one
insilmaril@822
   564
			ref2.setY(ref2.y() + bo->getBBoxSizeWithChildren().height() );
insilmaril@822
   565
		}
insilmaril@822
   566
    }
insilmaril@822
   567
    // Align the branch children depending on reference point 
insilmaril@750
   568
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@0
   569
    {	
insilmaril@753
   570
		if (!treeItem->getBranchNum(i)->isHidden())
insilmaril@254
   571
		{
insilmaril@753
   572
			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
insilmaril@721
   573
insilmaril@721
   574
			// append next branch below current one
insilmaril@753
   575
			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
insilmaril@254
   576
		}
insilmaril@0
   577
    }
insilmaril@0
   578
}
insilmaril@0
   579
insilmaril@0
   580
insilmaril@0
   581
void BranchObj::reposition()
insilmaril@0
   582
{	
insilmaril@164
   583
/* TODO testing only
insilmaril@753
   584
	if (!treeItem->getHeading().isEmpty())
insilmaril@753
   585
		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
insilmaril@0
   586
	else	
insilmaril@0
   587
		cout << "BO::reposition  ???"<<endl;
insilmaril@753
   588
//	cout << "  orient="<<orientation<<endl;
insilmaril@0
   589
*/		
insilmaril@382
   590
insilmaril@755
   591
	if (treeItem->depth()==0)
insilmaril@0
   592
	{
insilmaril@0
   593
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
   594
		// changes its height,
insilmaril@0
   595
		// all upper LMOs have to change, too.
insilmaril@721
   596
		calcBBoxSizeWithChildren();
insilmaril@779
   597
		updateLinkGeometry();	// This update is needed if the scene is resized 
insilmaril@333
   598
						// due to excessive moving of a FIO
insilmaril@333
   599
insilmaril@408
   600
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
   601
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@333
   602
		positionBBox();	// Reposition bbox and contents
insilmaril@0
   603
	} else
insilmaril@0
   604
	{
insilmaril@0
   605
		// This is only important for moving branches:
insilmaril@0
   606
		// For editing a branch it isn't called...
insilmaril@408
   607
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
   608
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   609
	}
insilmaril@0
   610
}
insilmaril@0
   611
insilmaril@382
   612
void BranchObj::unsetAllRepositionRequests()
insilmaril@382
   613
{
insilmaril@382
   614
	repositionRequest=false;
insilmaril@750
   615
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   616
		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
insilmaril@382
   617
}
insilmaril@382
   618
insilmaril@721
   619
QRectF BranchObj::getBBoxSizeWithChildren()
insilmaril@0
   620
{
insilmaril@0
   621
	return bboxTotal;
insilmaril@0
   622
}
insilmaril@0
   623
insilmaril@798
   624
ConvexPolygon BranchObj::getBoundingPolygon()	
insilmaril@793
   625
{
insilmaril@794
   626
/*
insilmaril@794
   627
	if (!pi)	//FIXME-3 Testing only
insilmaril@794
   628
	{
insilmaril@794
   629
		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
insilmaril@794
   630
		pi->setPen(Qt::NoPen);
insilmaril@794
   631
		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
insilmaril@794
   632
		pi->setZValue(Z_BBOX);
insilmaril@794
   633
	}
insilmaril@794
   634
	*/
insilmaril@798
   635
insilmaril@794
   636
	if (treeItem->branchCount()==0 || treeItem->depth()==0)
insilmaril@794
   637
	{
insilmaril@794
   638
		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
insilmaril@793
   639
		return MapObj::getBoundingPolygon();
insilmaril@794
   640
	}
insilmaril@793
   641
insilmaril@823
   642
	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
insilmaril@793
   643
	QPolygonF p;
insilmaril@793
   644
	p<<bboxTotal.topLeft();
insilmaril@793
   645
	p<<bboxTotal.topRight();
insilmaril@793
   646
	p<<bboxTotal.bottomRight();
insilmaril@793
   647
	p<<bboxTotal.bottomLeft();
insilmaril@798
   648
	//cout << "BO::getBP (total)  "<<treeItem->getHeadingStd()<<"  tL="<<bboxTotal.topLeft()<<"  bR="<<bboxTotal.bottomRight()<<endl;
insilmaril@798
   649
	//cout << "                   "<<"  tL="<<bbox.topLeft()<<"  bR="<<bbox.bottomRight()<<endl;
insilmaril@798
   650
	if (pi) pi->setPolygon (p );
insilmaril@793
   651
	return p;
insilmaril@793
   652
}
insilmaril@793
   653
insilmaril@721
   654
void BranchObj::calcBBoxSizeWithChildren()
insilmaril@169
   655
{	
insilmaril@169
   656
	// This is initially called only from reposition and
insilmaril@0
   657
	// and only for mapcenter. So it won't be
insilmaril@0
   658
	// called more than once for a single user 
insilmaril@0
   659
	// action
insilmaril@0
   660
	
insilmaril@169
   661
insilmaril@721
   662
	// Calculate size of LMO including all children (to align them later)
insilmaril@0
   663
	bboxTotal.setX(bbox.x() );
insilmaril@0
   664
	bboxTotal.setY(bbox.y() );
insilmaril@0
   665
insilmaril@721
   666
	// if branch is scrolled, ignore children, but still consider floatimages
insilmaril@753
   667
	BranchItem *bi=(BranchItem*)treeItem;
insilmaril@753
   668
	if ( bi->isScrolled() ) 
insilmaril@0
   669
	{
insilmaril@0
   670
		bboxTotal.setWidth (bbox.width());
insilmaril@0
   671
		bboxTotal.setHeight(bbox.height());
insilmaril@0
   672
		return;
insilmaril@0
   673
	}
insilmaril@0
   674
	
insilmaril@753
   675
	if (bi->isHidden())
insilmaril@254
   676
	{
insilmaril@254
   677
		bboxTotal.setWidth (0);
insilmaril@254
   678
		bboxTotal.setHeight(0);
insilmaril@254
   679
		if (parObj)
insilmaril@254
   680
		{
insilmaril@254
   681
			bboxTotal.setX (parObj->x());
insilmaril@254
   682
			bboxTotal.setY (parObj->y());
insilmaril@254
   683
		} else
insilmaril@254
   684
		{
insilmaril@254
   685
			bboxTotal.setX (bbox.x());
insilmaril@254
   686
			bboxTotal.setY (bbox.y());
insilmaril@254
   687
		}
insilmaril@254
   688
		return;
insilmaril@254
   689
	}
insilmaril@254
   690
	
insilmaril@408
   691
	QRectF r(0,0,0,0);
insilmaril@408
   692
	QRectF br;
insilmaril@0
   693
	// Now calculate recursivly
insilmaril@0
   694
	// sum of heights 
insilmaril@0
   695
	// maximum of widths 
insilmaril@0
   696
	// minimum of y
insilmaril@755
   697
	for (int i=0; i<treeItem->branchCount(); i++)
insilmaril@0
   698
	{
insilmaril@753
   699
		if (!bi->getBranchNum(i)->isHidden())
insilmaril@254
   700
		{
insilmaril@822
   701
			BranchObj *bo=bi->getBranchObjNum(i);
insilmaril@822
   702
			bo->calcBBoxSizeWithChildren();
insilmaril@822
   703
			br=bo->getBBoxSizeWithChildren();
insilmaril@822
   704
			r.setWidth( max (br.width(), r.width() ));
insilmaril@822
   705
			r.setHeight(br.height() + r.height() );
insilmaril@822
   706
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@822
   707
			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
insilmaril@822
   708
		}
insilmaril@822
   709
	}
insilmaril@822
   710
	for (int i=0; i<treeItem->attributeCount(); i++)
insilmaril@822
   711
	{
insilmaril@822
   712
		if (!bi->getAttributeNum(i)->isHidden())
insilmaril@822
   713
		{
insilmaril@822
   714
			BranchObj *bo=bi->getAttributeNum(i)->getBranchObj();
insilmaril@822
   715
			bo->calcBBoxSizeWithChildren();
insilmaril@822
   716
			br=bo->getBBoxSizeWithChildren();
insilmaril@254
   717
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
   718
			r.setHeight(br.height() + r.height() );
insilmaril@254
   719
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@798
   720
			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
insilmaril@254
   721
		}
insilmaril@0
   722
	}
insilmaril@0
   723
	// Add myself and also
insilmaril@0
   724
	// add width of link to sum if necessary
insilmaril@753
   725
	if (bi->branchCount()<1)
insilmaril@0
   726
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
   727
	else	
insilmaril@0
   728
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
   729
	
insilmaril@169
   730
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
   731
}
insilmaril@0
   732
insilmaril@688
   733
void BranchObj::setAnimation(const AnimPoint &ap)
insilmaril@462
   734
{
insilmaril@688
   735
	anim=ap;
insilmaril@462
   736
}
insilmaril@462
   737
insilmaril@847
   738
void BranchObj::stopAnimation()
insilmaril@847
   739
{
insilmaril@847
   740
	anim.stop();
insilmaril@847
   741
	if (useRelPos)
insilmaril@847
   742
		setRelPos (anim);
insilmaril@847
   743
	else
insilmaril@847
   744
		move (anim);
insilmaril@847
   745
}
insilmaril@847
   746
insilmaril@688
   747
bool BranchObj::animate()
insilmaril@688
   748
{
insilmaril@688
   749
	anim.animate ();
insilmaril@721
   750
	if ( anim.isAnimated() )
insilmaril@721
   751
	{
insilmaril@835
   752
		if (useRelPos)
insilmaril@835
   753
			setRelPos (anim);
insilmaril@835
   754
		else
insilmaril@835
   755
			move (anim);
insilmaril@721
   756
		return true;
insilmaril@721
   757
	}
insilmaril@835
   758
	/*FIXME-3 reposition in BO:animate nearly never reached? needed?	
insilmaril@835
   759
	if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative)
insilmaril@835
   760
		parObj->reposition();	// we might have been relinked meanwhile
insilmaril@835
   761
	*/	
insilmaril@721
   762
	return false;
insilmaril@688
   763
}
insilmaril@688
   764