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