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