branchobj.cpp
author insilmaril
Fri, 27 Nov 2009 15:00:51 +0000
changeset 812 62d4137bfb90
parent 804 14f2b1b15242
child 814 31de6677aa96
permissions -rw-r--r--
Select MapEditor after closing FindWidget
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@804
   118
void BranchObj::setParObjTmp(LinkableMapObj* dst, QPointF m, int off)	//FIXME-1 when moving a mainbranch to a branch it still has relPos, not moved as child
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@804
   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@804
   493
			fontsize=14; 
insilmaril@804
   494
			setFrameType (FrameObj::NoFrame);
insilmaril@804
   495
			break;
insilmaril@804
   496
		case 2: 
insilmaril@798
   497
			fontsize=12; 
insilmaril@798
   498
			setFrameType (FrameObj::NoFrame);
insilmaril@798
   499
			break;
insilmaril@798
   500
		default: 
insilmaril@798
   501
			fontsize=10; 
insilmaril@798
   502
			setFrameType (FrameObj::NoFrame);
insilmaril@798
   503
			break;
insilmaril@146
   504
	}	
insilmaril@786
   505
	setLinkStyle(getDefLinkStyle(treeItem->parent() ));
insilmaril@146
   506
	setLinkColor ();
insilmaril@146
   507
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
   508
	font.setPointSize(fontsize);
insilmaril@146
   509
	heading->setFont(font );
insilmaril@146
   510
insilmaril@146
   511
	if (mod==NewBranch)
insilmaril@760
   512
		setColor (treeItem->getHeadingColor() );
insilmaril@798
   513
	else
insilmaril@798
   514
		// Also set styles for children
insilmaril@798
   515
		for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@798
   516
			treeItem->getBranchObjNum(i)->setDefAttr(MovedBranch);
insilmaril@146
   517
	calcBBoxSize();
insilmaril@146
   518
}
insilmaril@146
   519
insilmaril@721
   520
void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
insilmaril@0
   521
{
insilmaril@408
   522
	qreal th = bboxTotal.height();	
insilmaril@773
   523
	int depth=treeItem->depth();	// FIXME-3 needed to recursively calc depth?
insilmaril@223
   524
// TODO testing
insilmaril@223
   525
/*
insilmaril@755
   526
insilmaril@755
   527
	QString h=QString (depth,' ');
insilmaril@753
   528
	h+=treeItem->getHeading();
insilmaril@753
   529
	h+=QString (15,' ');
insilmaril@753
   530
	h.truncate (15);
insilmaril@688
   531
	QPointF pp; if (parObj) pp=parObj->getChildPos();
insilmaril@753
   532
	cout << "BO::alignRelTo ";
insilmaril@753
   533
	cout<<h.toStdString();
insilmaril@755
   534
	cout << "    d="<<depth<<
insilmaril@755
   535
//cout<<  "  ref="<<ref<<
insilmaril@753
   536
      	"  bbox.tL="<<bboxTotal.topLeft()<<
insilmaril@223
   537
		"  absPos="<<absPos<<
insilmaril@795
   538
		"  relPos="<<relPos<<
insilmaril@721
   539
//		"  parPos="<<pp<<
insilmaril@795
   540
//		"  w="<<bbox.width()<<
insilmaril@795
   541
//		"  h="<<bbox.height()<<
insilmaril@753
   542
//		"  orient="<<orientation<<
insilmaril@753
   543
//		"  alignSelf="<<alignSelf<<
insilmaril@753
   544
//		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
insilmaril@254
   545
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
   546
//		"  hidden="<<hidden<<
insilmaril@753
   547
		"  th="<<th<<
insilmaril@382
   548
		endl;
insilmaril@394
   549
*/
insilmaril@0
   550
insilmaril@382
   551
	setOrientation();
insilmaril@779
   552
	//updateLinkGeometry();
insilmaril@382
   553
insilmaril@755
   554
	if (depth==1 && parObj)
insilmaril@364
   555
	{
insilmaril@753
   556
		// Position relatively, if needed
insilmaril@753
   557
		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
insilmaril@382
   558
insilmaril@753
   559
		// Calc angle to mapCenter if I am a mainbranch
insilmaril@753
   560
		// needed for reordering the mainbranches clockwise 
insilmaril@753
   561
		// around mapcenter 
insilmaril@753
   562
		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@753
   563
								(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@753
   564
	}							
insilmaril@796
   565
	if (depth==1)
insilmaril@796
   566
	{
insilmaril@796
   567
		move2RelPos (getRelPos() );
insilmaril@796
   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@408
   666
QRectF BranchObj::getTotalBBox()
insilmaril@0
   667
{
insilmaril@408
   668
	QRectF r=bbox;
insilmaril@0
   669
insilmaril@749
   670
	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
insilmaril@0
   671
insilmaril@750
   672
	for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@753
   673
		if (!treeItem->getBranchNum(i)->isHidden())
insilmaril@753
   674
			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
insilmaril@0
   675
insilmaril@755
   676
/* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
insilmaril@755
   677
            better check if they are not NULL and maybe simplify...
insilmaril@755
   678
			(have been NULL at least in calcBBoxSizeWithChilds...)
insilmaril@755
   679
*/			
insilmaril@755
   680
insilmaril@785
   681
	for (int i=0; i<treeItem->imageCount(); ++i)
insilmaril@785
   682
		if (!treeItem->isHidden())
insilmaril@785
   683
			r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
insilmaril@0
   684
	return r;
insilmaril@0
   685
}
insilmaril@0
   686
insilmaril@721
   687
QRectF BranchObj::getBBoxSizeWithChildren()
insilmaril@0
   688
{
insilmaril@0
   689
	return bboxTotal;
insilmaril@0
   690
}
insilmaril@0
   691
insilmaril@798
   692
ConvexPolygon BranchObj::getBoundingPolygon()	
insilmaril@793
   693
{
insilmaril@794
   694
/*
insilmaril@794
   695
	if (!pi)	//FIXME-3 Testing only
insilmaril@794
   696
	{
insilmaril@794
   697
		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
insilmaril@794
   698
		pi->setPen(Qt::NoPen);
insilmaril@794
   699
		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
insilmaril@794
   700
		pi->setZValue(Z_BBOX);
insilmaril@794
   701
	}
insilmaril@794
   702
	*/
insilmaril@798
   703
insilmaril@794
   704
	if (treeItem->branchCount()==0 || treeItem->depth()==0)
insilmaril@794
   705
	{
insilmaril@794
   706
		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
insilmaril@793
   707
		return MapObj::getBoundingPolygon();
insilmaril@794
   708
	}
insilmaril@793
   709
insilmaril@794
   710
	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
insilmaril@793
   711
	QPolygonF p;
insilmaril@793
   712
	p<<bboxTotal.topLeft();
insilmaril@793
   713
	p<<bboxTotal.topRight();
insilmaril@793
   714
	p<<bboxTotal.bottomRight();
insilmaril@793
   715
	p<<bboxTotal.bottomLeft();
insilmaril@798
   716
	//cout << "BO::getBP (total)  "<<treeItem->getHeadingStd()<<"  tL="<<bboxTotal.topLeft()<<"  bR="<<bboxTotal.bottomRight()<<endl;
insilmaril@798
   717
	//cout << "                   "<<"  tL="<<bbox.topLeft()<<"  bR="<<bbox.bottomRight()<<endl;
insilmaril@798
   718
	if (pi) pi->setPolygon (p );
insilmaril@793
   719
	return p;
insilmaril@793
   720
}
insilmaril@793
   721
insilmaril@721
   722
void BranchObj::calcBBoxSizeWithChildren()
insilmaril@169
   723
{	
insilmaril@169
   724
	// This is initially called only from reposition and
insilmaril@0
   725
	// and only for mapcenter. So it won't be
insilmaril@0
   726
	// called more than once for a single user 
insilmaril@0
   727
	// action
insilmaril@0
   728
	
insilmaril@169
   729
insilmaril@721
   730
	// Calculate size of LMO including all children (to align them later)
insilmaril@0
   731
	bboxTotal.setX(bbox.x() );
insilmaril@0
   732
	bboxTotal.setY(bbox.y() );
insilmaril@0
   733
insilmaril@721
   734
	// if branch is scrolled, ignore children, but still consider floatimages
insilmaril@753
   735
	BranchItem *bi=(BranchItem*)treeItem;
insilmaril@753
   736
	if ( bi->isScrolled() ) 
insilmaril@0
   737
	{
insilmaril@0
   738
		bboxTotal.setWidth (bbox.width());
insilmaril@0
   739
		bboxTotal.setHeight(bbox.height());
insilmaril@0
   740
		return;
insilmaril@0
   741
	}
insilmaril@0
   742
	
insilmaril@753
   743
	if (bi->isHidden())
insilmaril@254
   744
	{
insilmaril@254
   745
		bboxTotal.setWidth (0);
insilmaril@254
   746
		bboxTotal.setHeight(0);
insilmaril@254
   747
		if (parObj)
insilmaril@254
   748
		{
insilmaril@254
   749
			bboxTotal.setX (parObj->x());
insilmaril@254
   750
			bboxTotal.setY (parObj->y());
insilmaril@254
   751
		} else
insilmaril@254
   752
		{
insilmaril@254
   753
			bboxTotal.setX (bbox.x());
insilmaril@254
   754
			bboxTotal.setY (bbox.y());
insilmaril@254
   755
		}
insilmaril@254
   756
		return;
insilmaril@254
   757
	}
insilmaril@254
   758
	
insilmaril@408
   759
	QRectF r(0,0,0,0);
insilmaril@408
   760
	QRectF br;
insilmaril@0
   761
	// Now calculate recursivly
insilmaril@0
   762
	// sum of heights 
insilmaril@0
   763
	// maximum of widths 
insilmaril@0
   764
	// minimum of y
insilmaril@755
   765
	for (int i=0; i<treeItem->branchCount(); i++)
insilmaril@0
   766
	{
insilmaril@753
   767
		if (!bi->getBranchNum(i)->isHidden())
insilmaril@254
   768
		{
insilmaril@753
   769
			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
insilmaril@753
   770
			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
insilmaril@254
   771
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
   772
			r.setHeight(br.height() + r.height() );
insilmaril@254
   773
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@798
   774
			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
insilmaril@254
   775
		}
insilmaril@0
   776
	}
insilmaril@0
   777
	// Add myself and also
insilmaril@0
   778
	// add width of link to sum if necessary
insilmaril@753
   779
	if (bi->branchCount()<1)
insilmaril@0
   780
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
   781
	else	
insilmaril@0
   782
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
   783
	
insilmaril@169
   784
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
   785
}
insilmaril@0
   786
insilmaril@0
   787
QString BranchObj::getSelectString()
insilmaril@0
   788
{
insilmaril@773
   789
	VymModel *model=treeItem->getModel();
insilmaril@773
   790
	if (model)
insilmaril@773
   791
		return model->getSelectString (this);
insilmaril@773
   792
	else
insilmaril@773
   793
		return QString();
insilmaril@0
   794
}
insilmaril@0
   795
insilmaril@688
   796
void BranchObj::setAnimation(const AnimPoint &ap)
insilmaril@462
   797
{
insilmaril@688
   798
	anim=ap;
insilmaril@462
   799
}
insilmaril@462
   800
insilmaril@688
   801
bool BranchObj::animate()
insilmaril@688
   802
{
insilmaril@688
   803
	anim.animate ();
insilmaril@721
   804
	if ( anim.isAnimated() )
insilmaril@721
   805
	{
insilmaril@721
   806
		setRelPos (anim);
insilmaril@721
   807
		return true;
insilmaril@721
   808
	}
insilmaril@723
   809
	parObj->reposition();	// we might have been relinked meanwhile
insilmaril@721
   810
	return false;
insilmaril@688
   811
}
insilmaril@688
   812