branchobj.cpp
author insilmaril
Mon, 18 May 2009 09:41:31 +0000
changeset 770 57ce1ba6d1cb
parent 767 6d2b32f305f9
child 771 01f2f6d6789d
permissions -rw-r--r--
Fixed Standard Flags finally
insilmaril@0
     1
#include "branchobj.h"
insilmaril@616
     2
insilmaril@749
     3
#include "branchitem.h"
insilmaril@643
     4
#include "geometry.h"
insilmaril@0
     5
#include "mapeditor.h"
insilmaril@0
     6
#include "mainwindow.h"
insilmaril@616
     7
#include "misc.h"
insilmaril@616
     8
insilmaril@767
     9
extern FlagRow *standardFlagsMaster;
insilmaril@767
    10
extern FlagRow *systemFlagsMaster;
insilmaril@0
    11
insilmaril@0
    12
/////////////////////////////////////////////////////////////////
insilmaril@0
    13
// BranchObj
insilmaril@0
    14
/////////////////////////////////////////////////////////////////
insilmaril@0
    15
insilmaril@746
    16
BranchObj::BranchObj () :OrnamentedObj()	// FIXME-3 needed at all?
insilmaril@0
    17
{
insilmaril@0
    18
//    cout << "Const BranchObj ()\n";
insilmaril@0
    19
    setParObj (this);	
insilmaril@0
    20
    init();
insilmaril@0
    21
}
insilmaril@0
    22
insilmaril@755
    23
BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
insilmaril@0
    24
{
insilmaril@755
    25
//    cout << "Const BranchObj (s)  \n";
insilmaril@83
    26
	parObj=NULL;
insilmaril@408
    27
    scene=s;
insilmaril@755
    28
	init();
insilmaril@0
    29
}
insilmaril@0
    30
insilmaril@755
    31
BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
insilmaril@0
    32
{
insilmaril@408
    33
//    cout << "Const BranchObj (s,p)\n";
insilmaril@408
    34
    scene=s;
insilmaril@0
    35
    setParObj (p);	
insilmaril@755
    36
	if (treeItem->depth()==1)
insilmaril@0
    37
		// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
    38
		// needed for reordering the mainbranches clockwise 
insilmaril@0
    39
		// around mapcenter 
insilmaril@408
    40
		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
insilmaril@408
    41
								(y() - parObj->getChildPos().y() ) ) );
insilmaril@0
    42
    init();
insilmaril@0
    43
}
insilmaril@0
    44
insilmaril@0
    45
BranchObj::~BranchObj ()
insilmaril@0
    46
{
insilmaril@757
    47
//	cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
insilmaril@757
    48
insilmaril@722
    49
	// If I'm animated, I need to un-animate myself first
insilmaril@722
    50
	if (anim.isAnimated() )
insilmaril@722
    51
	{
insilmaril@722
    52
		anim.setAnimated (false);
insilmaril@722
    53
		model->stopAnimation (this);
insilmaril@722
    54
	}
insilmaril@722
    55
insilmaril@0
    56
	// Check, if this branch was the last child to be deleted
insilmaril@749
    57
	// If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
insilmaril@0
    58
insilmaril@749
    59
	/*
insilmaril@425
    60
	BranchObj *po=(BranchObj*)parObj;
insilmaril@83
    61
	BranchObj *bo;
insilmaril@0
    62
	if (po)
insilmaril@0
    63
	{
insilmaril@425
    64
		bo=((BranchObj*)parObj)->getLastBranch();
insilmaril@425
    65
		if (bo) po->unScroll();
insilmaril@0
    66
	}
insilmaril@749
    67
	*/
insilmaril@83
    68
	clear();
insilmaril@0
    69
}
insilmaril@0
    70
insilmaril@0
    71
bool BranchObj::operator< ( const BranchObj & other )
insilmaril@0
    72
{
insilmaril@0
    73
    return  angle < other.angle;
insilmaril@0
    74
}
insilmaril@0
    75
insilmaril@0
    76
bool BranchObj::operator== ( const BranchObj & other )
insilmaril@0
    77
{
insilmaril@0
    78
    return angle == other.angle;
insilmaril@0
    79
}
insilmaril@0
    80
insilmaril@0
    81
void BranchObj::init () 
insilmaril@0
    82
{
insilmaril@83
    83
	if (parObj)
insilmaril@83
    84
	{
insilmaril@83
    85
		absPos=getRandPos();
insilmaril@83
    86
		absPos+=parObj->getChildPos();
insilmaril@83
    87
	}
insilmaril@0
    88
insilmaril@0
    89
    setChildObj(this);
insilmaril@0
    90
insilmaril@169
    91
	includeImagesVer=false;
insilmaril@169
    92
	includeImagesHor=false;
insilmaril@0
    93
}
insilmaril@0
    94
insilmaril@0
    95
void BranchObj::copy (BranchObj* other)
insilmaril@0
    96
{
insilmaril@0
    97
    OrnamentedObj::copy(other);
insilmaril@0
    98
insilmaril@404
    99
	for (int i=0; i<other->floatimage.size(); ++i)
insilmaril@404
   100
		addFloatImage  (other->floatimage.at(i));
insilmaril@749
   101
	
insilmaril@0
   102
	setVisibility (other->visible);
insilmaril@0
   103
insilmaril@0
   104
	angle=other->angle;
insilmaril@0
   105
insilmaril@0
   106
    positionBBox();
insilmaril@0
   107
}
insilmaril@0
   108
insilmaril@0
   109
void BranchObj::clear() 
insilmaril@0
   110
{
insilmaril@755
   111
	//setVisibility (true); //FIXME-4 needed?
insilmaril@425
   112
insilmaril@404
   113
	while (!floatimage.isEmpty())
insilmaril@404
   114
		delete floatimage.takeFirst();
insilmaril@404
   115
insilmaril@95
   116
	while (!xlink.isEmpty())
insilmaril@406
   117
		delete xlink.takeFirst();
insilmaril@0
   118
}
insilmaril@0
   119
insilmaril@411
   120
bool isAbove (BranchObj* a, BranchObj *b)
insilmaril@411
   121
{
insilmaril@411
   122
	if (a->angle < b->angle)
insilmaril@411
   123
		return true;
insilmaril@411
   124
	else	
insilmaril@411
   125
		return false;
insilmaril@411
   126
}
insilmaril@411
   127
insilmaril@408
   128
void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
insilmaril@0
   129
{
insilmaril@0
   130
	// Temporary link to lmo
insilmaril@0
   131
	// m is position of mouse pointer 
insilmaril@0
   132
	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
insilmaril@0
   133
insilmaril@0
   134
insilmaril@0
   135
	BranchObj* o=(BranchObj*)(lmo);
insilmaril@0
   136
	if (!parObjTmpBuf) 
insilmaril@0
   137
		parObjTmpBuf=parObj;
insilmaril@0
   138
insilmaril@0
   139
	// ignore mapcenter and mainbranch
insilmaril@755
   140
	if (treeItem->depth()<2) off=0;
insilmaril@0
   141
	if (off==0)
insilmaril@0
   142
		link2ParPos=false;
insilmaril@0
   143
	else
insilmaril@0
   144
		link2ParPos=true;
insilmaril@93
   145
	parObj=o;
insilmaril@0
   146
insilmaril@755
   147
	// FIXME-2 depth=parObj->getDepth()+1;
insilmaril@0
   148
insilmaril@0
   149
	// setLinkStyle calls updateLink, only set it once
insilmaril@0
   150
	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
insilmaril@0
   151
insilmaril@0
   152
	// Move temporary to new position at destination
insilmaril@0
   153
	// Usually the positioning would be done by reposition(),
insilmaril@0
   154
	// but then also the destination branch would "Jump" around...
insilmaril@0
   155
	// Better just do it approximately
insilmaril@755
   156
	if (treeItem->depth()==1)
insilmaril@0
   157
	{	// new parent is the mapcenter itself
insilmaril@0
   158
insilmaril@408
   159
		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
insilmaril@0
   160
									  m.y() - o->getChildPos().y() ));
insilmaril@0
   161
		if (p.x()<0) p.setX( p.x()-bbox.width() );
insilmaril@0
   162
		move2RelPos (p);
insilmaril@0
   163
	} else
insilmaril@0
   164
	{	
insilmaril@408
   165
		qreal y;
insilmaril@0
   166
		if (off==0)
insilmaril@0
   167
		{
insilmaril@0
   168
			// new parent is just a branch, link to it
insilmaril@721
   169
			QRectF t=o->getBBoxSizeWithChildren();
insilmaril@750
   170
			if (o->getTreeItem()->getLastBranch())
insilmaril@0
   171
				y=t.y() + t.height() ;
insilmaril@0
   172
			else
insilmaril@0
   173
				y=t.y();
insilmaril@0
   174
insilmaril@0
   175
		} else
insilmaril@0
   176
		{
insilmaril@0
   177
			if (off<0)
insilmaril@0
   178
				// we want to link above lmo
insilmaril@0
   179
				y=o->y() - height() + 5;
insilmaril@0
   180
			else	
insilmaril@0
   181
				// we want to link below lmo
insilmaril@0
   182
				// Bottom of sel should be 5 pixels above
insilmaril@0
   183
				// the bottom of the branch _below_ the target:
insilmaril@0
   184
				// Don't try to find that branch, guess 12 pixels
insilmaril@0
   185
				y=o->getChildPos().y()  -height() + 12; 
insilmaril@0
   186
		}	
insilmaril@462
   187
		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
   188
			move ( o->getChildPos().x() - linkwidth, y );
insilmaril@0
   189
		else	
insilmaril@0
   190
			move (o->getChildPos().x() + linkwidth, y );
insilmaril@0
   191
	}	
insilmaril@0
   192
insilmaril@0
   193
	// updateLink is called implicitly in move
insilmaril@417
   194
	requestReposition();	
insilmaril@0
   195
}
insilmaril@0
   196
insilmaril@0
   197
void BranchObj::unsetParObjTmp()
insilmaril@0
   198
{
insilmaril@0
   199
	if (parObjTmpBuf) 
insilmaril@0
   200
	{
insilmaril@0
   201
		link2ParPos=false;
insilmaril@0
   202
		parObj=parObjTmpBuf;
insilmaril@0
   203
		parObjTmpBuf=NULL;
insilmaril@755
   204
		//FIXME-2 depth=parObj->getDepth()+1;
insilmaril@0
   205
		setLinkStyle (getDefLinkStyle() );
insilmaril@93
   206
		updateLink();
insilmaril@0
   207
	}		
insilmaril@0
   208
}
insilmaril@0
   209
insilmaril@0
   210
void BranchObj::setVisibility(bool v, int toDepth)
insilmaril@0
   211
{
insilmaril@749
   212
	BranchItem *bi=(BranchItem*)treeItem;
insilmaril@755
   213
    if (bi->depth() <= toDepth)
insilmaril@0
   214
    {
insilmaril@0
   215
		frame->setVisibility(v);
insilmaril@0
   216
		heading->setVisibility(v);
insilmaril@0
   217
		systemFlags->setVisibility(v);
insilmaril@0
   218
		standardFlags->setVisibility(v);
insilmaril@0
   219
		LinkableMapObj::setVisibility (v);
insilmaril@730
   220
		int i;
insilmaril@730
   221
		for (i=0; i<floatimage.size(); ++i)
insilmaril@730
   222
			floatimage.at(i)->setVisibility (v);
insilmaril@730
   223
		for (i=0; i<xlink.size(); ++i)	
insilmaril@730
   224
			xlink.at(i)->setVisibility ();	
insilmaril@730
   225
insilmaril@721
   226
		// Only change children, if I am not scrolled
insilmaril@749
   227
		if (! bi->isScrolled() && (bi->depth() < toDepth))
insilmaril@0
   228
		{
insilmaril@721
   229
			// Now go recursivly through all children
insilmaril@750
   230
			for (i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   231
				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
insilmaril@0
   232
		}
insilmaril@0
   233
    } // depth <= toDepth	
insilmaril@0
   234
	requestReposition();
insilmaril@0
   235
}	
insilmaril@0
   236
insilmaril@0
   237
void BranchObj::setVisibility(bool v)
insilmaril@0
   238
{
insilmaril@0
   239
    setVisibility (v,MAX_DEPTH);
insilmaril@0
   240
}
insilmaril@0
   241
insilmaril@0
   242
insilmaril@0
   243
void BranchObj::setLinkColor ()
insilmaril@0
   244
{
insilmaril@0
   245
	// Overloaded from LinkableMapObj
insilmaril@0
   246
	// BranchObj can use color of heading
insilmaril@0
   247
insilmaril@721
   248
	if (model)
insilmaril@611
   249
	{
insilmaril@721
   250
		if (model->getMapLinkColorHint()==HeadingColor)
insilmaril@164
   251
			LinkableMapObj::setLinkColor (heading->getColor() );
insilmaril@164
   252
		else	
insilmaril@164
   253
			LinkableMapObj::setLinkColor ();
insilmaril@611
   254
	}		
insilmaril@0
   255
}
insilmaril@0
   256
insilmaril@417
   257
void BranchObj::setColorSubtree(QColor col)
insilmaril@0
   258
{
insilmaril@638
   259
	setColor (col);
insilmaril@750
   260
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   261
		treeItem->getBranchObjNum(i)->setColorSubtree(col);
insilmaril@753
   262
}
insilmaril@753
   263
insilmaril@753
   264
void BranchObj::updateContentSize()
insilmaril@753
   265
{
insilmaril@753
   266
	calcBBoxSize();
insilmaril@753
   267
	positionBBox();
insilmaril@753
   268
	requestReposition();
insilmaril@100
   269
}
insilmaril@0
   270
insilmaril@333
   271
void BranchObj::positionContents()
insilmaril@333
   272
{
insilmaril@404
   273
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   274
		floatimage.at(i)->reposition();
insilmaril@333
   275
	OrnamentedObj::positionContents();
insilmaril@333
   276
}
insilmaril@0
   277
insilmaril@0
   278
void BranchObj::move (double x, double y)
insilmaril@0
   279
{
insilmaril@0
   280
	OrnamentedObj::move (x,y);
insilmaril@404
   281
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   282
		floatimage.at(i)->reposition();
insilmaril@0
   283
    positionBBox();
insilmaril@0
   284
}
insilmaril@0
   285
insilmaril@408
   286
void BranchObj::move (QPointF p)
insilmaril@0
   287
{
insilmaril@0
   288
	move (p.x(), p.y());
insilmaril@0
   289
}
insilmaril@0
   290
insilmaril@0
   291
void BranchObj::moveBy (double x, double y)
insilmaril@0
   292
{
insilmaril@0
   293
	OrnamentedObj::moveBy (x,y);
insilmaril@750
   294
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   295
		treeItem->getBranchObjNum(i)->moveBy (x,y);
insilmaril@333
   296
    positionBBox();
insilmaril@0
   297
}
insilmaril@83
   298
	
insilmaril@408
   299
void BranchObj::moveBy (QPointF p)
insilmaril@0
   300
{
insilmaril@0
   301
	moveBy (p.x(), p.y());
insilmaril@0
   302
}
insilmaril@0
   303
insilmaril@0
   304
insilmaril@0
   305
void BranchObj::positionBBox()
insilmaril@0
   306
{
insilmaril@408
   307
	QPointF ap=getAbsPos();
insilmaril@223
   308
	bbox.moveTopLeft (ap);
insilmaril@169
   309
	positionContents();
insilmaril@0
   310
insilmaril@0
   311
	// set the frame
insilmaril@408
   312
	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@83
   313
insilmaril@83
   314
	// Update links to other branches
insilmaril@406
   315
	for (int i=0; i<xlink.size(); ++i)
insilmaril@406
   316
		xlink.at(i)->updateXLink();
insilmaril@0
   317
}
insilmaril@0
   318
insilmaril@0
   319
void BranchObj::calcBBoxSize()
insilmaril@0
   320
{
insilmaril@408
   321
    QSizeF heading_r=heading->getSize();
insilmaril@408
   322
    qreal heading_w=(qreal) heading_r.width() ;
insilmaril@408
   323
    qreal heading_h=(qreal) heading_r.height() ;
insilmaril@767
   324
    QSizeF sysflags_r=systemFlags->getSize();
insilmaril@767
   325
	qreal sysflags_h=sysflags_r.height();
insilmaril@767
   326
	qreal sysflags_w=sysflags_r.width();
insilmaril@767
   327
    QSizeF stanflags_r=standardFlags->getSize();
insilmaril@767
   328
	qreal stanflags_h=stanflags_r.height();
insilmaril@767
   329
	qreal stanflags_w=stanflags_r.width();
insilmaril@408
   330
    qreal w;
insilmaril@408
   331
    qreal h;
insilmaril@0
   332
insilmaril@0
   333
	// set width to sum of all widths
insilmaril@0
   334
	w=heading_w + sysflags_w + stanflags_w;
insilmaril@0
   335
	// set height to maximum needed height
insilmaril@0
   336
	h=max (sysflags_h,stanflags_h);
insilmaril@0
   337
	h=max (h,heading_h);
insilmaril@0
   338
insilmaril@223
   339
	// Save the dimension of flags and heading
insilmaril@408
   340
	ornamentsBBox.setSize ( QSizeF(w,h));
insilmaril@223
   341
insilmaril@223
   342
	// clickBox includes Flags and Heading
insilmaril@223
   343
    clickBox.setSize (ornamentsBBox.size() );
insilmaril@169
   344
insilmaril@169
   345
	// Floatimages 
insilmaril@408
   346
	QPointF rp;
insilmaril@169
   347
insilmaril@169
   348
	topPad=botPad=leftPad=rightPad=0;
insilmaril@169
   349
	if (includeImagesVer || includeImagesHor)
insilmaril@169
   350
	{
insilmaril@749
   351
		if (treeItem->imageCount()>0)
insilmaril@169
   352
		{
insilmaril@404
   353
			for (int i=0; i<floatimage.size(); ++i )
insilmaril@169
   354
			{
insilmaril@404
   355
				rp=floatimage.at(i)->getRelPos();
insilmaril@169
   356
				if (includeImagesVer)
insilmaril@169
   357
				{
insilmaril@169
   358
					if (rp.y() < 0) 
insilmaril@223
   359
						topPad=max (topPad,-rp.y()-h);
insilmaril@404
   360
					if (rp.y()+floatimage.at(i)->height() > 0)
insilmaril@404
   361
						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
insilmaril@169
   362
				}		
insilmaril@213
   363
				if (includeImagesHor)
insilmaril@213
   364
				{
insilmaril@462
   365
					if (orientation==LinkableMapObj::RightOfCenter)
insilmaril@223
   366
					{
insilmaril@223
   367
						if (-rp.x()-w > 0) 
insilmaril@223
   368
							leftPad=max (leftPad,-rp.x()-w);
insilmaril@404
   369
						if (rp.x()+floatimage.at(i)->width() > 0)
insilmaril@404
   370
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
insilmaril@223
   371
					} else
insilmaril@223
   372
					{
insilmaril@223
   373
						if (rp.x()< 0) 
insilmaril@223
   374
							leftPad=max (leftPad,-rp.x());
insilmaril@404
   375
						if (rp.x()+floatimage.at(i)->width() > w)
insilmaril@404
   376
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
insilmaril@223
   377
					}
insilmaril@213
   378
				}		
insilmaril@169
   379
			}	
insilmaril@169
   380
		}	
insilmaril@169
   381
		h+=topPad+botPad;
insilmaril@213
   382
		w+=leftPad+rightPad;
insilmaril@169
   383
	}
insilmaril@169
   384
insilmaril@169
   385
	// Frame thickness
insilmaril@462
   386
    w+=frame->getPadding();
insilmaril@462
   387
    h+=frame->getPadding();
insilmaril@169
   388
	
insilmaril@169
   389
	// Finally set size
insilmaril@408
   390
    bbox.setSize (QSizeF (w,h));
insilmaril@0
   391
}
insilmaril@0
   392
insilmaril@223
   393
void BranchObj::setDockPos()
insilmaril@223
   394
{
insilmaril@382
   395
	// Sets childpos and parpos depending on orientation
insilmaril@462
   396
	if (getOrientation()==LinkableMapObj::LeftOfCenter )
insilmaril@223
   397
    {
insilmaril@440
   398
		childPos=QPointF (
insilmaril@440
   399
			ornamentsBBox.bottomLeft().x(), 
insilmaril@440
   400
			bottomlineY);
insilmaril@440
   401
		parPos=QPointF (
insilmaril@440
   402
			ornamentsBBox.bottomRight().x(),
insilmaril@440
   403
			bottomlineY);
insilmaril@223
   404
    } else
insilmaril@223
   405
    {
insilmaril@440
   406
		childPos=QPointF (
insilmaril@440
   407
			ornamentsBBox.bottomRight().x(), 
insilmaril@440
   408
			bottomlineY);
insilmaril@440
   409
		parPos=QPointF (
insilmaril@440
   410
			ornamentsBBox.bottomLeft().x(),
insilmaril@440
   411
			bottomlineY);
insilmaril@223
   412
    }
insilmaril@223
   413
}
insilmaril@382
   414
insilmaril@767
   415
void BranchObj::updateData()
insilmaril@0
   416
{
insilmaril@767
   417
	bool changed=false;
insilmaril@753
   418
	if (!treeItem)
insilmaril@254
   419
	{
insilmaril@753
   420
		qWarning ("BranchObj::udpateHeading treeItem==NULL");
insilmaril@753
   421
		return;
insilmaril@753
   422
	}
insilmaril@767
   423
	QString s=treeItem->getHeading();
insilmaril@767
   424
	if (s!=heading->text())
insilmaril@767
   425
	{
insilmaril@767
   426
		heading->setText (s);
insilmaril@767
   427
		changed=true;
insilmaril@767
   428
	}
insilmaril@767
   429
	QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
insilmaril@767
   430
insilmaril@767
   431
	// Add missing standard flags active in TreeItem
insilmaril@767
   432
	for (int i=0;i<=TIactiveFlags.size()-1;i++)
insilmaril@767
   433
	{	
insilmaril@767
   434
		if (!standardFlags->isActive (TIactiveFlags.at(i) ))
insilmaril@767
   435
		{
insilmaril@767
   436
			Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
insilmaril@767
   437
			if (f) standardFlags->activate (f);
insilmaril@767
   438
			changed=true;
insilmaril@767
   439
		}
insilmaril@767
   440
	}
insilmaril@767
   441
	// Remove standard flags no longer active in TreeItem
insilmaril@767
   442
	QStringList BOactiveFlags=standardFlags->activeFlagNames();
insilmaril@767
   443
	for (int i=0;i<BOactiveFlags.size();++i)
insilmaril@767
   444
		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
insilmaril@767
   445
		{
insilmaril@767
   446
			standardFlags->deactivate (BOactiveFlags.at(i));
insilmaril@767
   447
			changed=true;
insilmaril@767
   448
		}	
insilmaril@767
   449
insilmaril@767
   450
	// Add missing system flags active in TreeItem
insilmaril@767
   451
	TIactiveFlags=treeItem->activeSystemFlagNames();
insilmaril@767
   452
	for (int i=0;i<TIactiveFlags.size();++i)
insilmaril@767
   453
	{	
insilmaril@767
   454
		if (!systemFlags->isActive (TIactiveFlags.at(i) ))
insilmaril@767
   455
		{
insilmaril@767
   456
			Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
insilmaril@767
   457
			if (f) systemFlags->activate (f);
insilmaril@767
   458
			changed=true;
insilmaril@767
   459
		}
insilmaril@767
   460
	}
insilmaril@767
   461
	// Remove system flags no longer active in TreeItem
insilmaril@767
   462
	BOactiveFlags=systemFlags->activeFlagNames();
insilmaril@767
   463
	for (int i=0;i<BOactiveFlags.size();++i)
insilmaril@767
   464
	{
insilmaril@767
   465
		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
insilmaril@767
   466
		{
insilmaril@767
   467
			systemFlags->deactivate (BOactiveFlags.at(i));
insilmaril@767
   468
			changed=true;
insilmaril@767
   469
		}	
insilmaril@767
   470
	}
insilmaril@767
   471
insilmaril@767
   472
	if (changed)
insilmaril@767
   473
		updateContentSize();
insilmaril@254
   474
}
insilmaril@254
   475
insilmaril@0
   476
insilmaril@95
   477
void BranchObj::addXLink (XLinkObj *xlo)
insilmaril@83
   478
{
insilmaril@95
   479
	xlink.append (xlo);
insilmaril@83
   480
	
insilmaril@83
   481
}
insilmaril@83
   482
insilmaril@95
   483
void BranchObj::removeXLinkRef (XLinkObj *xlo)
insilmaril@83
   484
{
insilmaril@406
   485
	xlink.removeAt (xlink.indexOf(xlo));
insilmaril@83
   486
}
insilmaril@83
   487
insilmaril@95
   488
void BranchObj::deleteXLink(XLinkObj *xlo)
insilmaril@83
   489
{
insilmaril@95
   490
	xlo->deactivate();
insilmaril@95
   491
	if (!xlo->isUsed()) delete (xlo);
insilmaril@83
   492
}
insilmaril@83
   493
insilmaril@95
   494
void BranchObj::deleteXLinkAt (int i)
insilmaril@94
   495
{
insilmaril@95
   496
	XLinkObj *xlo=xlink.at(i);
insilmaril@95
   497
	xlo->deactivate();
insilmaril@95
   498
	if (!xlo->isUsed()) delete(xlo);
insilmaril@94
   499
}
insilmaril@94
   500
insilmaril@97
   501
XLinkObj* BranchObj::XLinkAt (int i)
insilmaril@97
   502
{
insilmaril@97
   503
	return xlink.at(i);
insilmaril@97
   504
}
insilmaril@97
   505
insilmaril@95
   506
BranchObj* BranchObj::XLinkTargetAt (int i)
insilmaril@89
   507
{
insilmaril@406
   508
	if (i>=0 && i<xlink.size())
insilmaril@406
   509
	{
insilmaril@406
   510
		if (xlink.at(i))
insilmaril@406
   511
			return xlink.at(i)->otherBranch (this);
insilmaril@406
   512
	}
insilmaril@406
   513
	return NULL;
insilmaril@89
   514
}
insilmaril@89
   515
insilmaril@169
   516
void BranchObj::setIncludeImagesVer(bool b)
insilmaril@169
   517
{
insilmaril@169
   518
	includeImagesVer=b;
insilmaril@169
   519
	calcBBoxSize();
insilmaril@169
   520
	positionBBox();
insilmaril@169
   521
	requestReposition();
insilmaril@169
   522
}
insilmaril@169
   523
insilmaril@169
   524
bool BranchObj::getIncludeImagesVer()
insilmaril@169
   525
{
insilmaril@169
   526
	return includeImagesVer;
insilmaril@169
   527
}
insilmaril@169
   528
insilmaril@169
   529
void BranchObj::setIncludeImagesHor(bool b)
insilmaril@169
   530
{
insilmaril@169
   531
	includeImagesHor=b;
insilmaril@169
   532
	calcBBoxSize();
insilmaril@169
   533
	positionBBox();
insilmaril@169
   534
	requestReposition();
insilmaril@169
   535
}
insilmaril@169
   536
insilmaril@169
   537
bool BranchObj::getIncludeImagesHor()
insilmaril@169
   538
{
insilmaril@169
   539
	return includeImagesHor;
insilmaril@169
   540
}
insilmaril@169
   541
insilmaril@169
   542
QString BranchObj::getIncludeImageAttr()
insilmaril@169
   543
{
insilmaril@169
   544
	QString a;
insilmaril@169
   545
	if (includeImagesVer)
insilmaril@169
   546
		a=attribut ("incImgV","true");
insilmaril@169
   547
	else
insilmaril@169
   548
		a=attribut ("incImgV","false");
insilmaril@169
   549
	if (includeImagesHor)
insilmaril@213
   550
		a+=attribut ("incImgH","true");
insilmaril@169
   551
	else
insilmaril@213
   552
		a+=attribut ("incImgH","false");
insilmaril@169
   553
	return a;	
insilmaril@169
   554
}
insilmaril@169
   555
insilmaril@395
   556
FloatImageObj* BranchObj::addFloatImage ()
insilmaril@0
   557
{
insilmaril@408
   558
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   559
	floatimage.append (newfi);
insilmaril@749
   560
	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
insilmaril@0
   561
		newfi->setVisibility (false);
insilmaril@0
   562
	else	
insilmaril@0
   563
		newfi->setVisibility(visible);
insilmaril@395
   564
		/*
insilmaril@169
   565
	calcBBoxSize();
insilmaril@169
   566
	positionBBox();
insilmaril@395
   567
	*/
insilmaril@0
   568
	requestReposition();
insilmaril@0
   569
	return newfi;
insilmaril@0
   570
}
insilmaril@0
   571
insilmaril@395
   572
FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
insilmaril@0
   573
{
insilmaril@408
   574
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   575
	floatimage.append (newfi);
insilmaril@0
   576
	newfi->copy (fio);
insilmaril@749
   577
	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
insilmaril@0
   578
		newfi->setVisibility (false);
insilmaril@0
   579
	else	
insilmaril@0
   580
		newfi->setVisibility(visible);
insilmaril@395
   581
		/*
insilmaril@169
   582
	calcBBoxSize();
insilmaril@169
   583
	positionBBox();
insilmaril@395
   584
	*/
insilmaril@0
   585
	requestReposition();
insilmaril@0
   586
	return newfi;
insilmaril@0
   587
}
insilmaril@0
   588
insilmaril@0
   589
FloatImageObj* BranchObj::getFirstFloatImage ()
insilmaril@0
   590
{
insilmaril@0
   591
    return floatimage.first();
insilmaril@0
   592
}
insilmaril@0
   593
insilmaril@0
   594
FloatImageObj* BranchObj::getLastFloatImage ()
insilmaril@0
   595
{
insilmaril@0
   596
    return floatimage.last();
insilmaril@0
   597
}
insilmaril@0
   598
insilmaril@0
   599
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
insilmaril@0
   600
{
insilmaril@0
   601
    return floatimage.at(i);
insilmaril@0
   602
}
insilmaril@0
   603
insilmaril@0
   604
void BranchObj::removeFloatImage (FloatImageObj *fio)
insilmaril@0
   605
{
insilmaril@404
   606
	int i=floatimage.indexOf (fio);
insilmaril@411
   607
	if (i>-1) delete (floatimage.takeAt (i));
insilmaril@169
   608
	calcBBoxSize();
insilmaril@169
   609
	positionBBox();
insilmaril@0
   610
	requestReposition();
insilmaril@0
   611
}
insilmaril@0
   612
insilmaril@0
   613
void BranchObj::savePosInAngle ()
insilmaril@0
   614
{
insilmaril@0
   615
	// Save position in angle
insilmaril@750
   616
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   617
		treeItem->getBranchObjNum(i)->angle=i;
insilmaril@0
   618
}
insilmaril@0
   619
insilmaril@146
   620
void BranchObj::setDefAttr (BranchModification mod)
insilmaril@146
   621
{
insilmaril@146
   622
	int fontsize;
insilmaril@755
   623
	switch (treeItem->depth())
insilmaril@146
   624
	{
insilmaril@146
   625
		case 0: fontsize=16; break;
insilmaril@146
   626
		case 1: fontsize=12; break;
insilmaril@146
   627
		default: fontsize=10; break;
insilmaril@146
   628
	}	
insilmaril@146
   629
insilmaril@146
   630
	setLinkColor ();
insilmaril@146
   631
	setLinkStyle(getDefLinkStyle());
insilmaril@146
   632
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
   633
	font.setPointSize(fontsize);
insilmaril@146
   634
	heading->setFont(font );
insilmaril@146
   635
insilmaril@146
   636
	if (mod==NewBranch)
insilmaril@760
   637
		setColor (treeItem->getHeadingColor() );
insilmaril@146
   638
	calcBBoxSize();
insilmaril@146
   639
}
insilmaril@146
   640
insilmaril@760
   641
void BranchObj::removeBranchHere(BranchObj* borem)	// FIXME-2 getNum no longer available
insilmaril@98
   642
{
insilmaril@749
   643
/*
insilmaril@98
   644
	// This removes the branch bo from list, but 
insilmaril@721
   645
	// inserts its children at the place of bo
insilmaril@98
   646
	BranchObj *bo;
insilmaril@98
   647
	bo=borem->getLastBranch();
insilmaril@139
   648
	int pos=borem->getNum();
insilmaril@98
   649
	while (bo)
insilmaril@98
   650
	{
insilmaril@421
   651
		bo->linkTo (this,pos+1);
insilmaril@98
   652
		bo=borem->getLastBranch();
insilmaril@98
   653
	}	
insilmaril@98
   654
	removeBranch (borem);
insilmaril@749
   655
	*/
insilmaril@98
   656
}
insilmaril@98
   657
insilmaril@755
   658
void BranchObj::removeChildren()	// FIXME-3 not needed here
insilmaril@98
   659
{
insilmaril@98
   660
	clear();
insilmaril@98
   661
}
insilmaril@98
   662
insilmaril@760
   663
void BranchObj::removeBranch(BranchObj* bo)	// FIXME-2 not needed here
insilmaril@0
   664
{
insilmaril@753
   665
/*
insilmaril@0
   666
    // if bo is not in branch remove returns false, we
insilmaril@0
   667
    // don't care...
insilmaril@83
   668
	
insilmaril@406
   669
	int i=branch.indexOf(bo);
insilmaril@406
   670
    if (i>=0)
insilmaril@406
   671
	{
insilmaril@83
   672
		delete (bo);
insilmaril@406
   673
		branch.removeAt (i);
insilmaril@406
   674
	} else
insilmaril@83
   675
		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
insilmaril@83
   676
	requestReposition();
insilmaril@753
   677
	*/
insilmaril@83
   678
}
insilmaril@83
   679
insilmaril@760
   680
void BranchObj::removeBranchPtr(BranchObj* bo)	// FIXME-3 not needed here
insilmaril@83
   681
{
insilmaril@753
   682
/*
insilmaril@406
   683
	int i=branch.indexOf(bo);
insilmaril@406
   684
	
insilmaril@406
   685
	if (i>=0)
insilmaril@406
   686
		branch.removeAt (i);
insilmaril@406
   687
	else	
insilmaril@406
   688
		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
insilmaril@0
   689
	requestReposition();
insilmaril@753
   690
*/	
insilmaril@0
   691
}
insilmaril@0
   692
insilmaril@760
   693
void BranchObj::sortChildren() //FIXME-2  
insilmaril@604
   694
{
insilmaril@749
   695
/*
insilmaril@749
   696
	int childCount=branch.count(); 
insilmaril@604
   697
	int curChildIndex;
insilmaril@604
   698
	bool madeChanges=false;
insilmaril@604
   699
	do
insilmaril@604
   700
	{
insilmaril@604
   701
		madeChanges=false;
insilmaril@604
   702
		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
insilmaril@753
   703
			BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
insilmaril@753
   704
			BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
insilmaril@604
   705
			if(prevChild->heading->text().compare(curChild->heading->text())>0)
insilmaril@604
   706
			{
insilmaril@604
   707
				this->moveBranchUp(curChild);
insilmaril@604
   708
				madeChanges=true;
insilmaril@604
   709
			}
insilmaril@604
   710
		}
insilmaril@604
   711
	}while(madeChanges);
insilmaril@749
   712
*/
insilmaril@604
   713
}
insilmaril@604
   714
insilmaril@721
   715
void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
insilmaril@0
   716
{
insilmaril@408
   717
	qreal th = bboxTotal.height();	
insilmaril@755
   718
	int depth=treeItem->depth();
insilmaril@223
   719
// TODO testing
insilmaril@223
   720
/*
insilmaril@755
   721
insilmaril@755
   722
	QString h=QString (depth,' ');
insilmaril@753
   723
	h+=treeItem->getHeading();
insilmaril@753
   724
	h+=QString (15,' ');
insilmaril@753
   725
	h.truncate (15);
insilmaril@688
   726
	QPointF pp; if (parObj) pp=parObj->getChildPos();
insilmaril@753
   727
	cout << "BO::alignRelTo ";
insilmaril@753
   728
	cout<<h.toStdString();
insilmaril@755
   729
	cout << "    d="<<depth<<
insilmaril@755
   730
//cout<<  "  ref="<<ref<<
insilmaril@753
   731
      	"  bbox.tL="<<bboxTotal.topLeft()<<
insilmaril@223
   732
		"  absPos="<<absPos<<
insilmaril@721
   733
//		"  relPos="<<relPos<<
insilmaril@721
   734
//		"  parPos="<<pp<<
insilmaril@753
   735
		"  w="<<bbox.width()<<
insilmaril@753
   736
		"  h="<<bbox.height()<<
insilmaril@753
   737
//		"  orient="<<orientation<<
insilmaril@753
   738
//		"  alignSelf="<<alignSelf<<
insilmaril@753
   739
//		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
insilmaril@254
   740
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
   741
//		"  hidden="<<hidden<<
insilmaril@753
   742
		"  th="<<th<<
insilmaril@382
   743
		endl;
insilmaril@394
   744
*/
insilmaril@0
   745
insilmaril@382
   746
	setOrientation();
insilmaril@382
   747
	//updateLink();
insilmaril@382
   748
insilmaril@755
   749
	if (depth==1 && parObj)
insilmaril@364
   750
	{
insilmaril@753
   751
		// Position relatively, if needed
insilmaril@753
   752
		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
insilmaril@382
   753
insilmaril@753
   754
		// Calc angle to mapCenter if I am a mainbranch
insilmaril@753
   755
		// needed for reordering the mainbranches clockwise 
insilmaril@753
   756
		// around mapcenter 
insilmaril@753
   757
		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@753
   758
								(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@753
   759
	}							
insilmaril@753
   760
	if (depth>1)
insilmaril@0
   761
    {
insilmaril@0
   762
		// Align myself depending on orientation and parent, but
insilmaril@382
   763
		// only if I am not a mainbranch or mapcenter itself
insilmaril@688
   764
insilmaril@688
   765
		if (anim.isAnimated())
insilmaril@0
   766
		{
insilmaril@688
   767
			move2RelPos(anim);
insilmaril@688
   768
		} else
insilmaril@688
   769
		{
insilmaril@688
   770
			LinkableMapObj::Orientation o;
insilmaril@688
   771
			o=parObj->getOrientation();
insilmaril@721
   772
			if (alignSelf)
insilmaril@721
   773
				switch (orientation) 
insilmaril@721
   774
				{
insilmaril@721
   775
					case LinkableMapObj::LeftOfCenter:
insilmaril@721
   776
						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@721
   777
						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
insilmaril@721
   778
					break;
insilmaril@721
   779
					case LinkableMapObj::RightOfCenter:	
insilmaril@721
   780
						move (ref.x() , ref.y() + (th-bbox.height())/2  );
insilmaril@721
   781
					break;
insilmaril@721
   782
					default:
insilmaril@721
   783
						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
insilmaril@721
   784
					break;
insilmaril@753
   785
			}
insilmaril@688
   786
		}
insilmaril@0
   787
    }		
insilmaril@0
   788
insilmaril@749
   789
	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
insilmaril@0
   790
insilmaril@721
   791
    // Set reference point for alignment of children
insilmaril@408
   792
    QPointF ref2;
insilmaril@462
   793
    if (orientation==LinkableMapObj::LeftOfCenter)
insilmaril@223
   794
		ref2.setX(bbox.topLeft().x() - linkwidth);
insilmaril@0
   795
    else	
insilmaril@223
   796
		ref2.setX(bbox.topRight().x() + linkwidth);
insilmaril@0
   797
insilmaril@0
   798
	if (depth==1)
insilmaril@0
   799
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
   800
	else	
insilmaril@0
   801
		ref2.setY(ref.y() );	
insilmaril@0
   802
insilmaril@721
   803
    // Align the children depending on reference point 
insilmaril@750
   804
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@0
   805
    {	
insilmaril@753
   806
		if (!treeItem->getBranchNum(i)->isHidden())
insilmaril@254
   807
		{
insilmaril@753
   808
			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
insilmaril@721
   809
insilmaril@721
   810
			// append next branch below current one
insilmaril@753
   811
			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
insilmaril@254
   812
		}
insilmaril@0
   813
    }
insilmaril@0
   814
}
insilmaril@0
   815
insilmaril@0
   816
insilmaril@0
   817
void BranchObj::reposition()
insilmaril@0
   818
{	
insilmaril@164
   819
/* TODO testing only
insilmaril@753
   820
	if (!treeItem->getHeading().isEmpty())
insilmaril@753
   821
		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
insilmaril@0
   822
	else	
insilmaril@0
   823
		cout << "BO::reposition  ???"<<endl;
insilmaril@753
   824
//	cout << "  orient="<<orientation<<endl;
insilmaril@0
   825
*/		
insilmaril@382
   826
insilmaril@755
   827
	if (treeItem->depth()==0)
insilmaril@0
   828
	{
insilmaril@0
   829
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
   830
		// changes its height,
insilmaril@0
   831
		// all upper LMOs have to change, too.
insilmaril@721
   832
		calcBBoxSizeWithChildren();
insilmaril@408
   833
		updateLink();	// This update is needed if the scene is resized 
insilmaril@333
   834
						// due to excessive moving of a FIO
insilmaril@333
   835
insilmaril@408
   836
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
   837
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@753
   838
		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
insilmaril@333
   839
		positionBBox();	// Reposition bbox and contents
insilmaril@0
   840
	} else
insilmaril@0
   841
	{
insilmaril@0
   842
		// This is only important for moving branches:
insilmaril@0
   843
		// For editing a branch it isn't called...
insilmaril@408
   844
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
   845
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   846
	}
insilmaril@0
   847
}
insilmaril@0
   848
insilmaril@382
   849
void BranchObj::unsetAllRepositionRequests()
insilmaril@382
   850
{
insilmaril@382
   851
	repositionRequest=false;
insilmaril@750
   852
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   853
		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
insilmaril@382
   854
}
insilmaril@382
   855
insilmaril@0
   856
insilmaril@661
   857
QPolygonF BranchObj::shape()
insilmaril@661
   858
{
insilmaril@661
   859
	QPolygonF p;
insilmaril@661
   860
insilmaril@661
   861
	QRectF r=getTotalBBox();
insilmaril@661
   862
	if (orientation==LinkableMapObj::LeftOfCenter)
insilmaril@661
   863
		p   <<r.bottomLeft()
insilmaril@661
   864
			<<r.topLeft()
insilmaril@661
   865
			<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
insilmaril@661
   866
			<<bbox.topRight()
insilmaril@661
   867
			<<bbox.bottomRight()
insilmaril@661
   868
			<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
insilmaril@661
   869
	else		
insilmaril@661
   870
		p   <<r.bottomRight()
insilmaril@661
   871
			<<r.topRight()
insilmaril@661
   872
			<<QPointF (bbox.topRight().x(), r.topRight().y() )
insilmaril@661
   873
			<<bbox.topLeft()
insilmaril@661
   874
			<<bbox.bottomLeft()
insilmaril@661
   875
			<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
insilmaril@661
   876
	return p;
insilmaril@661
   877
}
insilmaril@661
   878
insilmaril@408
   879
QRectF BranchObj::getTotalBBox()
insilmaril@0
   880
{
insilmaril@408
   881
	QRectF r=bbox;
insilmaril@0
   882
insilmaril@749
   883
	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
insilmaril@0
   884
insilmaril@750
   885
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   886
		if (!treeItem->getBranchNum(i)->isHidden())
insilmaril@753
   887
			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
insilmaril@0
   888
insilmaril@755
   889
/* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
insilmaril@755
   890
            better check if they are not NULL and maybe simplify...
insilmaril@755
   891
			(have been NULL at least in calcBBoxSizeWithChilds...)
insilmaril@755
   892
*/			
insilmaril@755
   893
insilmaril@753
   894
/*
insilmaril@753
   895
	FIXME-1 for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
   896
		if (!floatimage.at(i)->isHidden())
insilmaril@404
   897
			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
insilmaril@753
   898
	*/	
insilmaril@0
   899
	return r;
insilmaril@0
   900
}
insilmaril@0
   901
insilmaril@721
   902
QRectF BranchObj::getBBoxSizeWithChildren()
insilmaril@0
   903
{
insilmaril@0
   904
	return bboxTotal;
insilmaril@0
   905
}
insilmaril@0
   906
insilmaril@721
   907
void BranchObj::calcBBoxSizeWithChildren()
insilmaril@169
   908
{	
insilmaril@169
   909
	// This is initially called only from reposition and
insilmaril@0
   910
	// and only for mapcenter. So it won't be
insilmaril@0
   911
	// called more than once for a single user 
insilmaril@0
   912
	// action
insilmaril@0
   913
	
insilmaril@169
   914
insilmaril@721
   915
	// Calculate size of LMO including all children (to align them later)
insilmaril@0
   916
	bboxTotal.setX(bbox.x() );
insilmaril@0
   917
	bboxTotal.setY(bbox.y() );
insilmaril@0
   918
insilmaril@721
   919
	// if branch is scrolled, ignore children, but still consider floatimages
insilmaril@753
   920
	BranchItem *bi=(BranchItem*)treeItem;
insilmaril@753
   921
	if ( bi->isScrolled() ) 
insilmaril@0
   922
	{
insilmaril@0
   923
		bboxTotal.setWidth (bbox.width());
insilmaril@0
   924
		bboxTotal.setHeight(bbox.height());
insilmaril@0
   925
		return;
insilmaril@0
   926
	}
insilmaril@0
   927
	
insilmaril@753
   928
	if (bi->isHidden())
insilmaril@254
   929
	{
insilmaril@254
   930
		bboxTotal.setWidth (0);
insilmaril@254
   931
		bboxTotal.setHeight(0);
insilmaril@254
   932
		if (parObj)
insilmaril@254
   933
		{
insilmaril@254
   934
			bboxTotal.setX (parObj->x());
insilmaril@254
   935
			bboxTotal.setY (parObj->y());
insilmaril@254
   936
		} else
insilmaril@254
   937
		{
insilmaril@254
   938
			bboxTotal.setX (bbox.x());
insilmaril@254
   939
			bboxTotal.setY (bbox.y());
insilmaril@254
   940
		}
insilmaril@254
   941
		return;
insilmaril@254
   942
	}
insilmaril@254
   943
	
insilmaril@408
   944
	QRectF r(0,0,0,0);
insilmaril@408
   945
	QRectF br;
insilmaril@0
   946
	// Now calculate recursivly
insilmaril@0
   947
	// sum of heights 
insilmaril@0
   948
	// maximum of widths 
insilmaril@0
   949
	// minimum of y
insilmaril@755
   950
	for (int i=0; i<treeItem->branchCount(); i++)
insilmaril@0
   951
	{
insilmaril@753
   952
		if (!bi->getBranchNum(i)->isHidden())
insilmaril@254
   953
		{
insilmaril@753
   954
			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
insilmaril@753
   955
			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
insilmaril@254
   956
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
   957
			r.setHeight(br.height() + r.height() );
insilmaril@254
   958
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@254
   959
		}
insilmaril@0
   960
	}
insilmaril@0
   961
	// Add myself and also
insilmaril@0
   962
	// add width of link to sum if necessary
insilmaril@753
   963
	if (bi->branchCount()<1)
insilmaril@0
   964
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
   965
	else	
insilmaril@0
   966
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
   967
	
insilmaril@169
   968
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
   969
}
insilmaril@0
   970
insilmaril@0
   971
QString BranchObj::getSelectString()
insilmaril@0
   972
{
insilmaril@723
   973
	return model->getSelectString (this);
insilmaril@0
   974
}
insilmaril@0
   975
insilmaril@688
   976
void BranchObj::setAnimation(const AnimPoint &ap)
insilmaril@462
   977
{
insilmaril@688
   978
	anim=ap;
insilmaril@462
   979
}
insilmaril@462
   980
insilmaril@688
   981
bool BranchObj::animate()
insilmaril@688
   982
{
insilmaril@688
   983
	anim.animate ();
insilmaril@721
   984
	if ( anim.isAnimated() )
insilmaril@721
   985
	{
insilmaril@721
   986
		setRelPos (anim);
insilmaril@721
   987
		return true;
insilmaril@721
   988
	}
insilmaril@723
   989
	parObj->reposition();	// we might have been relinked meanwhile
insilmaril@721
   990
	return false;
insilmaril@688
   991
}
insilmaril@688
   992