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