branchobj.cpp
author insilmaril
Fri, 05 Jan 2007 11:17:32 +0000
changeset 417 1cc7bbf75f0b
parent 412 8059b6aa74d7
child 421 5522d1da7e37
permissions -rw-r--r--
1.8.64 various fixes
insilmaril@0
     1
#include "branchobj.h"
insilmaril@0
     2
#include "texteditor.h"
insilmaril@0
     3
#include "mapeditor.h"
insilmaril@0
     4
#include "mainwindow.h"
insilmaril@0
     5
insilmaril@0
     6
extern TextEditor *textEditor;
insilmaril@0
     7
extern Main *mainWindow;
insilmaril@0
     8
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
     9
insilmaril@0
    10
insilmaril@0
    11
/////////////////////////////////////////////////////////////////
insilmaril@0
    12
// BranchObj
insilmaril@0
    13
/////////////////////////////////////////////////////////////////
insilmaril@0
    14
insilmaril@0
    15
BranchObj* BranchObj::itLast=NULL;
insilmaril@364
    16
BranchObj* BranchObj::itFirst=NULL;
insilmaril@0
    17
insilmaril@0
    18
insilmaril@0
    19
BranchObj::BranchObj () :OrnamentedObj()
insilmaril@0
    20
{
insilmaril@0
    21
//    cout << "Const BranchObj ()\n";
insilmaril@0
    22
    setParObj (this);	
insilmaril@0
    23
    init();
insilmaril@0
    24
    depth=-1;
insilmaril@0
    25
}
insilmaril@0
    26
insilmaril@408
    27
BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
insilmaril@0
    28
{
insilmaril@408
    29
//    cout << "Const BranchObj (s)  called from MapCenterObj (s)\n";
insilmaril@83
    30
	parObj=NULL;
insilmaril@408
    31
    scene=s;
insilmaril@0
    32
}
insilmaril@0
    33
insilmaril@408
    34
BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
insilmaril@0
    35
{
insilmaril@408
    36
//    cout << "Const BranchObj (s,p)\n";
insilmaril@408
    37
    scene=s;
insilmaril@0
    38
    setParObj (p);	
insilmaril@0
    39
    depth=p->getDepth()+1;
insilmaril@0
    40
	if (depth==1)
insilmaril@0
    41
		// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
    42
		// needed for reordering the mainbranches clockwise 
insilmaril@0
    43
		// around mapcenter 
insilmaril@408
    44
		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
insilmaril@408
    45
								(y() - parObj->getChildPos().y() ) ) );
insilmaril@0
    46
    init();
insilmaril@0
    47
}
insilmaril@0
    48
insilmaril@0
    49
BranchObj::~BranchObj ()
insilmaril@0
    50
{
insilmaril@83
    51
//	cout << "Destr BranchObj of "<<this<<endl;
insilmaril@0
    52
	// Check, if this branch was the last child to be deleted
insilmaril@0
    53
	// If so, unset the scrolled flags
insilmaril@0
    54
insilmaril@0
    55
	BranchObj *po=(BranchObj*)(parObj);
insilmaril@83
    56
	BranchObj *bo;
insilmaril@0
    57
	if (po)
insilmaril@0
    58
	{
insilmaril@83
    59
		bo=((BranchObj*)(parObj))->getLastBranch();
insilmaril@0
    60
		if (!bo) po->unScroll();
insilmaril@0
    61
	}
insilmaril@83
    62
	clear();
insilmaril@0
    63
}
insilmaril@0
    64
insilmaril@0
    65
bool BranchObj::operator< ( const BranchObj & other )
insilmaril@0
    66
{
insilmaril@0
    67
    return  angle < other.angle;
insilmaril@0
    68
}
insilmaril@0
    69
insilmaril@0
    70
bool BranchObj::operator== ( const BranchObj & other )
insilmaril@0
    71
{
insilmaril@0
    72
    return angle == other.angle;
insilmaril@0
    73
}
insilmaril@0
    74
insilmaril@0
    75
void BranchObj::init () 
insilmaril@0
    76
{
insilmaril@83
    77
	if (parObj)
insilmaril@83
    78
	{
insilmaril@83
    79
		absPos=getRandPos();
insilmaril@83
    80
		absPos+=parObj->getChildPos();
insilmaril@83
    81
	}
insilmaril@0
    82
insilmaril@408
    83
    lastSelectedBranch=0;
insilmaril@0
    84
insilmaril@0
    85
    setChildObj(this);
insilmaril@0
    86
insilmaril@0
    87
	scrolled=false;
insilmaril@0
    88
	tmpUnscrolled=false;
insilmaril@0
    89
insilmaril@169
    90
	includeImagesVer=false;
insilmaril@169
    91
	includeImagesHor=false;
insilmaril@0
    92
}
insilmaril@0
    93
insilmaril@0
    94
void BranchObj::copy (BranchObj* other)
insilmaril@0
    95
{
insilmaril@0
    96
    OrnamentedObj::copy(other);
insilmaril@0
    97
insilmaril@0
    98
	branch.clear();
insilmaril@406
    99
	for (int i=0; i<other->branch.size(); ++i)
insilmaril@0
   100
		// Make deep copy of b
insilmaril@0
   101
		// Because addBranch again calls copy for the childs,
insilmaril@0
   102
		// Those will get a deep copy, too
insilmaril@406
   103
		addBranch(other->branch.at(i) );	
insilmaril@0
   104
insilmaril@404
   105
	for (int i=0; i<other->floatimage.size(); ++i)
insilmaril@404
   106
		addFloatImage  (other->floatimage.at(i));
insilmaril@0
   107
	scrolled=other->scrolled;
insilmaril@0
   108
	tmpUnscrolled=other->tmpUnscrolled;
insilmaril@0
   109
	setVisibility (other->visible);
insilmaril@0
   110
insilmaril@0
   111
	angle=other->angle;
insilmaril@0
   112
insilmaril@0
   113
    positionBBox();
insilmaril@0
   114
}
insilmaril@0
   115
insilmaril@0
   116
void BranchObj::clear() 
insilmaril@0
   117
{
insilmaril@404
   118
	while (!floatimage.isEmpty())
insilmaril@404
   119
		delete floatimage.takeFirst();
insilmaril@404
   120
insilmaril@95
   121
	while (!xlink.isEmpty())
insilmaril@406
   122
		delete xlink.takeFirst();
insilmaril@83
   123
insilmaril@83
   124
	while (!branch.isEmpty())
insilmaril@406
   125
		delete branch.takeFirst();
insilmaril@0
   126
}
insilmaril@0
   127
insilmaril@411
   128
bool isAbove (BranchObj* a, BranchObj *b)
insilmaril@411
   129
{
insilmaril@411
   130
	if (a->angle < b->angle)
insilmaril@411
   131
		return true;
insilmaril@411
   132
	else	
insilmaril@411
   133
		return false;
insilmaril@411
   134
}
insilmaril@411
   135
insilmaril@0
   136
int BranchObj::getNum()
insilmaril@0
   137
{
insilmaril@0
   138
	if (parObj)
insilmaril@364
   139
		return ((BranchObj*)parObj)->getNum (this);
insilmaril@0
   140
	else
insilmaril@0
   141
		return 0;
insilmaril@0
   142
}
insilmaril@0
   143
insilmaril@0
   144
int BranchObj::getNum(BranchObj *bo)
insilmaril@0
   145
{
insilmaril@406
   146
	return branch.indexOf (bo);
insilmaril@0
   147
}
insilmaril@0
   148
insilmaril@0
   149
int BranchObj::getFloatImageNum(FloatImageObj *fio)
insilmaril@0
   150
{
insilmaril@404
   151
	return floatimage.indexOf(fio);
insilmaril@0
   152
}
insilmaril@0
   153
insilmaril@0
   154
int BranchObj::countBranches()
insilmaril@0
   155
{
insilmaril@0
   156
	return branch.count();
insilmaril@0
   157
}
insilmaril@0
   158
insilmaril@0
   159
int BranchObj::countFloatImages()
insilmaril@0
   160
{
insilmaril@0
   161
	return floatimage.count();
insilmaril@0
   162
}
insilmaril@0
   163
insilmaril@95
   164
int BranchObj::countXLinks()
insilmaril@89
   165
{
insilmaril@95
   166
	return xlink.count();
insilmaril@89
   167
}
insilmaril@89
   168
insilmaril@408
   169
void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
insilmaril@0
   170
{
insilmaril@0
   171
	// Temporary link to lmo
insilmaril@0
   172
	// m is position of mouse pointer 
insilmaril@0
   173
	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
insilmaril@0
   174
insilmaril@0
   175
insilmaril@0
   176
	BranchObj* o=(BranchObj*)(lmo);
insilmaril@0
   177
	if (!parObjTmpBuf) 
insilmaril@0
   178
		parObjTmpBuf=parObj;
insilmaril@0
   179
insilmaril@0
   180
	// ignore mapcenter and mainbranch
insilmaril@0
   181
	if (lmo->getDepth()<2) off=0;
insilmaril@0
   182
	if (off==0)
insilmaril@0
   183
		link2ParPos=false;
insilmaril@0
   184
	else
insilmaril@0
   185
		link2ParPos=true;
insilmaril@93
   186
	parObj=o;
insilmaril@0
   187
insilmaril@0
   188
	depth=parObj->getDepth()+1;
insilmaril@0
   189
insilmaril@0
   190
	// setLinkStyle calls updateLink, only set it once
insilmaril@0
   191
	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
insilmaril@0
   192
insilmaril@0
   193
	// Move temporary to new position at destination
insilmaril@0
   194
	// Usually the positioning would be done by reposition(),
insilmaril@0
   195
	// but then also the destination branch would "Jump" around...
insilmaril@0
   196
	// Better just do it approximately
insilmaril@0
   197
	if (depth==1)
insilmaril@0
   198
	{	// new parent is the mapcenter itself
insilmaril@0
   199
insilmaril@408
   200
		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
insilmaril@0
   201
									  m.y() - o->getChildPos().y() ));
insilmaril@0
   202
		if (p.x()<0) p.setX( p.x()-bbox.width() );
insilmaril@0
   203
		move2RelPos (p);
insilmaril@0
   204
	} else
insilmaril@0
   205
	{	
insilmaril@408
   206
		qreal y;
insilmaril@0
   207
		if (off==0)
insilmaril@0
   208
		{
insilmaril@0
   209
			// new parent is just a branch, link to it
insilmaril@408
   210
			QRectF t=o->getBBoxSizeWithChilds();
insilmaril@0
   211
			if (o->getLastBranch())
insilmaril@0
   212
				y=t.y() + t.height() ;
insilmaril@0
   213
			else
insilmaril@0
   214
				y=t.y();
insilmaril@0
   215
insilmaril@0
   216
		} else
insilmaril@0
   217
		{
insilmaril@0
   218
			if (off<0)
insilmaril@0
   219
				// we want to link above lmo
insilmaril@0
   220
				y=o->y() - height() + 5;
insilmaril@0
   221
			else	
insilmaril@0
   222
				// we want to link below lmo
insilmaril@0
   223
				// Bottom of sel should be 5 pixels above
insilmaril@0
   224
				// the bottom of the branch _below_ the target:
insilmaril@0
   225
				// Don't try to find that branch, guess 12 pixels
insilmaril@0
   226
				y=o->getChildPos().y()  -height() + 12; 
insilmaril@0
   227
		}	
insilmaril@0
   228
		if (o->getOrientation()==OrientLeftOfCenter)
insilmaril@0
   229
			move ( o->getChildPos().x() - linkwidth, y );
insilmaril@0
   230
		else	
insilmaril@0
   231
			move (o->getChildPos().x() + linkwidth, y );
insilmaril@0
   232
	}	
insilmaril@0
   233
insilmaril@0
   234
	// updateLink is called implicitly in move
insilmaril@417
   235
	requestReposition();	
insilmaril@0
   236
}
insilmaril@0
   237
insilmaril@0
   238
void BranchObj::unsetParObjTmp()
insilmaril@0
   239
{
insilmaril@0
   240
	if (parObjTmpBuf) 
insilmaril@0
   241
	{
insilmaril@0
   242
		link2ParPos=false;
insilmaril@0
   243
		parObj=parObjTmpBuf;
insilmaril@0
   244
		parObjTmpBuf=NULL;
insilmaril@0
   245
		depth=parObj->getDepth()+1;
insilmaril@0
   246
		setLinkStyle (getDefLinkStyle() );
insilmaril@93
   247
		updateLink();
insilmaril@0
   248
	}		
insilmaril@0
   249
}
insilmaril@0
   250
insilmaril@0
   251
void BranchObj::unScroll()
insilmaril@0
   252
{
insilmaril@0
   253
	if (tmpUnscrolled) resetTmpUnscroll();
insilmaril@0
   254
	if (scrolled) toggleScroll();
insilmaril@0
   255
}
insilmaril@0
   256
insilmaril@0
   257
void BranchObj::toggleScroll()
insilmaril@0
   258
{
insilmaril@0
   259
	if (scrolled)
insilmaril@0
   260
	{
insilmaril@0
   261
		scrolled=false;
insilmaril@0
   262
		systemFlags->deactivate("scrolledright");
insilmaril@406
   263
		for (int i=0; i<branch.size(); ++i)
insilmaril@406
   264
			branch.at(i)->setVisibility(true);
insilmaril@0
   265
	} else
insilmaril@0
   266
	{
insilmaril@0
   267
		scrolled=true;
insilmaril@0
   268
		systemFlags->activate("scrolledright");
insilmaril@406
   269
		for (int i=0; i<branch.size(); ++i)
insilmaril@406
   270
			branch.at(i)->setVisibility(false);
insilmaril@0
   271
	}
insilmaril@0
   272
	calcBBoxSize();
insilmaril@0
   273
	positionBBox();	
insilmaril@0
   274
	move (absPos.x(), absPos.y() );
insilmaril@0
   275
	forceReposition();
insilmaril@0
   276
}
insilmaril@0
   277
insilmaril@0
   278
bool BranchObj::isScrolled()
insilmaril@0
   279
{
insilmaril@0
   280
	return scrolled;
insilmaril@0
   281
}
insilmaril@0
   282
insilmaril@0
   283
bool BranchObj::hasScrolledParent(BranchObj *start)
insilmaril@0
   284
{
insilmaril@0
   285
	// Calls parents recursivly to
insilmaril@0
   286
	// find out, if we are scrolled at all.
insilmaril@0
   287
	// But ignore myself, just look at parents.
insilmaril@0
   288
insilmaril@0
   289
	if (this !=start && scrolled) return true;
insilmaril@0
   290
insilmaril@0
   291
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   292
	if (bo) 
insilmaril@0
   293
		return bo->hasScrolledParent(start);
insilmaril@0
   294
	else
insilmaril@0
   295
		return false;
insilmaril@0
   296
}
insilmaril@0
   297
insilmaril@0
   298
void BranchObj::tmpUnscroll()
insilmaril@0
   299
{
insilmaril@0
   300
	// Unscroll parent (recursivly)
insilmaril@0
   301
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   302
	if (bo) bo->tmpUnscroll();
insilmaril@0
   303
		
insilmaril@0
   304
	// Unscroll myself
insilmaril@0
   305
	if (scrolled)
insilmaril@0
   306
	{
insilmaril@0
   307
		tmpUnscrolled=true;
insilmaril@0
   308
		systemFlags->activate("tmpUnscrolledright");
insilmaril@0
   309
		toggleScroll();
insilmaril@0
   310
	}	
insilmaril@0
   311
}
insilmaril@0
   312
insilmaril@0
   313
void BranchObj::resetTmpUnscroll()
insilmaril@0
   314
{
insilmaril@0
   315
	// Unscroll parent (recursivly)
insilmaril@0
   316
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   317
	if (bo)
insilmaril@0
   318
		bo->resetTmpUnscroll();
insilmaril@0
   319
		
insilmaril@0
   320
	// Unscroll myself
insilmaril@0
   321
	if (tmpUnscrolled)
insilmaril@0
   322
	{
insilmaril@0
   323
		tmpUnscrolled=false;
insilmaril@0
   324
		systemFlags->deactivate("tmpUnscrolledright");
insilmaril@0
   325
		toggleScroll();
insilmaril@0
   326
	}	
insilmaril@0
   327
}
insilmaril@0
   328
insilmaril@0
   329
void BranchObj::setVisibility(bool v, int toDepth)
insilmaril@0
   330
{
insilmaril@0
   331
    if (depth <= toDepth)
insilmaril@0
   332
    {
insilmaril@0
   333
		frame->setVisibility(v);
insilmaril@0
   334
		heading->setVisibility(v);
insilmaril@0
   335
		systemFlags->setVisibility(v);
insilmaril@0
   336
		standardFlags->setVisibility(v);
insilmaril@0
   337
		LinkableMapObj::setVisibility (v);
insilmaril@0
   338
		
insilmaril@254
   339
		// Only change childs, if I am not scrolled
insilmaril@0
   340
		if (!scrolled && (depth < toDepth))
insilmaril@0
   341
		{
insilmaril@0
   342
			// Now go recursivly through all childs
insilmaril@406
   343
			int i;
insilmaril@406
   344
			for (i=0; i<branch.size(); ++i)
insilmaril@406
   345
				branch.at(i)->setVisibility (v,toDepth);	
insilmaril@406
   346
			for (i=0; i<floatimage.size(); ++i)
insilmaril@404
   347
				floatimage.at(i)->setVisibility (v);
insilmaril@406
   348
			for (i=0; i<xlink.size(); ++i)	
insilmaril@406
   349
				xlink.at(i)->setVisibility ();	
insilmaril@0
   350
		}
insilmaril@0
   351
    } // depth <= toDepth	
insilmaril@0
   352
	requestReposition();
insilmaril@0
   353
}	
insilmaril@0
   354
insilmaril@0
   355
void BranchObj::setVisibility(bool v)
insilmaril@0
   356
{
insilmaril@0
   357
    setVisibility (v,MAX_DEPTH);
insilmaril@0
   358
}
insilmaril@0
   359
insilmaril@0
   360
insilmaril@0
   361
void BranchObj::setLinkColor ()
insilmaril@0
   362
{
insilmaril@0
   363
	// Overloaded from LinkableMapObj
insilmaril@0
   364
	// BranchObj can use color of heading
insilmaril@0
   365
insilmaril@164
   366
	if (mapEditor)
insilmaril@398
   367
		if (mapEditor->getMapLinkColorHint()==HeadingColor)
insilmaril@164
   368
			LinkableMapObj::setLinkColor (heading->getColor() );
insilmaril@164
   369
		else	
insilmaril@164
   370
			LinkableMapObj::setLinkColor ();
insilmaril@0
   371
}
insilmaril@0
   372
insilmaril@417
   373
void BranchObj::setColorSubtree(QColor col)
insilmaril@0
   374
{
insilmaril@239
   375
	OrnamentedObj::setColor (col);
insilmaril@406
   376
	for (int i=0; i<branch.size(); ++i)
insilmaril@417
   377
		branch.at(i)->setColorSubtree(col);
insilmaril@100
   378
}
insilmaril@0
   379
insilmaril@0
   380
BranchObj* BranchObj::first()
insilmaril@0
   381
{
insilmaril@0
   382
	itLast=NULL;	
insilmaril@364
   383
	itFirst=this;
insilmaril@0
   384
	return this; 
insilmaril@0
   385
}
insilmaril@0
   386
	
insilmaril@0
   387
BranchObj* BranchObj::next()
insilmaril@0
   388
{
insilmaril@406
   389
	BranchObj *bo;
insilmaril@0
   390
	BranchObj *lmo;
insilmaril@406
   391
	BranchObj *po=(BranchObj*)parObj;
insilmaril@406
   392
insilmaril@406
   393
	if (branch.isEmpty())
insilmaril@406
   394
		bo=NULL;
insilmaril@406
   395
	else
insilmaril@406
   396
		bo=branch.first();
insilmaril@0
   397
insilmaril@0
   398
	if (!itLast)
insilmaril@364
   399
	{
insilmaril@406
   400
		// no itLast, we are just beginning
insilmaril@0
   401
		if (bo) 
insilmaril@406
   402
		{
insilmaril@406
   403
			// we have childs, return first one
insilmaril@0
   404
			itLast=this;
insilmaril@0
   405
			return bo;
insilmaril@0
   406
		}	
insilmaril@0
   407
		else
insilmaril@0
   408
		{
insilmaril@406
   409
			// No childs, so there is no next
insilmaril@364
   410
			itLast=this;
insilmaril@0
   411
			return NULL;
insilmaril@0
   412
		}	
insilmaril@0
   413
	}
insilmaril@0
   414
insilmaril@406
   415
	// We have an itLast
insilmaril@406
   416
	if (itLast==po)
insilmaril@406
   417
	{	// We come from parent
insilmaril@0
   418
		if (bo)
insilmaril@0
   419
		{
insilmaril@0
   420
			// there are childs, go there
insilmaril@0
   421
			itLast=this;
insilmaril@0
   422
			return bo;
insilmaril@0
   423
		}	
insilmaril@0
   424
		else
insilmaril@0
   425
		{	// no childs, try to go up again
insilmaril@0
   426
			if (po)
insilmaril@0
   427
			{
insilmaril@406
   428
				// go back to parent and try to find next there
insilmaril@0
   429
				itLast=this;
insilmaril@0
   430
				lmo=po->next();
insilmaril@0
   431
				itLast=this;
insilmaril@0
   432
				return lmo;
insilmaril@0
   433
insilmaril@0
   434
			}	
insilmaril@0
   435
			else
insilmaril@0
   436
			{
insilmaril@406
   437
				// can't go up, I am mapCenter, no next
insilmaril@0
   438
				itLast=NULL;
insilmaril@0
   439
				return NULL;
insilmaril@0
   440
			}	
insilmaril@0
   441
		}
insilmaril@0
   442
	}
insilmaril@0
   443
insilmaril@406
   444
	// We don't come from parent, but from brother or childs
insilmaril@406
   445
insilmaril@364
   446
	// Try to find last child, where we came from, in my own childs
insilmaril@0
   447
	bool searching=true;
insilmaril@406
   448
	int i=0;
insilmaril@406
   449
	while (i<branch.size())
insilmaril@0
   450
	{
insilmaril@406
   451
		// Try to find itLast in my own childs
insilmaril@406
   452
		if (itLast==branch.at(i))
insilmaril@406
   453
		{
insilmaril@406
   454
			// ok, we come from my own childs
insilmaril@406
   455
			if (i<branch.size()-1)
insilmaril@406
   456
				bo=branch.at(i+1);
insilmaril@406
   457
			 else
insilmaril@406
   458
				bo=NULL;
insilmaril@406
   459
			searching=false;
insilmaril@406
   460
			i=branch.size();
insilmaril@406
   461
		} 	
insilmaril@406
   462
		++i;	
insilmaril@0
   463
	}
insilmaril@0
   464
	if (!searching)
insilmaril@406
   465
	{	// found itLast in my childs
insilmaril@0
   466
		if (bo)
insilmaril@0
   467
		{
insilmaril@0
   468
			// found a brother of lastLMO 
insilmaril@0
   469
			itLast=this;
insilmaril@0
   470
			return bo;
insilmaril@0
   471
		}	
insilmaril@0
   472
		else
insilmaril@0
   473
		{
insilmaril@0
   474
			if (po)
insilmaril@0
   475
			{
insilmaril@364
   476
				if (this==itFirst) return NULL;	// Stop at starting point
insilmaril@0
   477
				// go up
insilmaril@0
   478
				itLast=this;
insilmaril@0
   479
				lmo=po->next();
insilmaril@0
   480
				itLast=this;
insilmaril@0
   481
				return lmo;
insilmaril@0
   482
			}
insilmaril@0
   483
			else
insilmaril@0
   484
			{
insilmaril@0
   485
				// can't go up, I am mapCenter
insilmaril@0
   486
				itLast=NULL;
insilmaril@0
   487
				return NULL;
insilmaril@0
   488
			}	
insilmaril@0
   489
		}
insilmaril@0
   490
	}
insilmaril@0
   491
insilmaril@0
   492
	// couldn't find last child, it must be a nephew of mine
insilmaril@406
   493
	if (branch.size()>0)
insilmaril@0
   494
	{
insilmaril@0
   495
		// proceed with my first child
insilmaril@0
   496
		itLast=this;	
insilmaril@406
   497
		return branch.first();
insilmaril@0
   498
	}	
insilmaril@0
   499
	else
insilmaril@0
   500
	{
insilmaril@0
   501
		// or go back to my parents
insilmaril@0
   502
		if (po)
insilmaril@0
   503
		{
insilmaril@0
   504
			// go up
insilmaril@0
   505
			itLast=this;
insilmaril@0
   506
			lmo=po->next();
insilmaril@0
   507
			itLast=this;
insilmaril@0
   508
			return lmo;
insilmaril@0
   509
		}	
insilmaril@0
   510
		else
insilmaril@0
   511
		{
insilmaril@0
   512
			// can't go up, I am mapCenter
insilmaril@0
   513
			itLast=NULL;
insilmaril@0
   514
			return NULL;
insilmaril@0
   515
		}	
insilmaril@0
   516
	}	
insilmaril@0
   517
}
insilmaril@0
   518
insilmaril@0
   519
BranchObj* BranchObj::getLastIterator()
insilmaril@0
   520
{
insilmaril@0
   521
	return itLast;
insilmaril@0
   522
}
insilmaril@0
   523
insilmaril@0
   524
void BranchObj::setLastIterator(BranchObj* it)
insilmaril@0
   525
{
insilmaril@0
   526
	itLast=it;
insilmaril@0
   527
}
insilmaril@0
   528
insilmaril@333
   529
void BranchObj::positionContents()
insilmaril@333
   530
{
insilmaril@404
   531
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   532
		floatimage.at(i)->reposition();
insilmaril@333
   533
	OrnamentedObj::positionContents();
insilmaril@333
   534
}
insilmaril@0
   535
insilmaril@0
   536
void BranchObj::move (double x, double y)
insilmaril@0
   537
{
insilmaril@0
   538
	OrnamentedObj::move (x,y);
insilmaril@404
   539
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   540
		floatimage.at(i)->reposition();
insilmaril@0
   541
    positionBBox();
insilmaril@0
   542
}
insilmaril@0
   543
insilmaril@408
   544
void BranchObj::move (QPointF p)
insilmaril@0
   545
{
insilmaril@0
   546
	move (p.x(), p.y());
insilmaril@0
   547
}
insilmaril@0
   548
insilmaril@0
   549
void BranchObj::moveBy (double x, double y)
insilmaril@0
   550
{
insilmaril@0
   551
	OrnamentedObj::moveBy (x,y);
insilmaril@406
   552
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   553
		branch.at(i)->moveBy (x,y);
insilmaril@333
   554
    positionBBox();
insilmaril@0
   555
}
insilmaril@83
   556
	
insilmaril@408
   557
void BranchObj::moveBy (QPointF p)
insilmaril@0
   558
{
insilmaril@0
   559
	moveBy (p.x(), p.y());
insilmaril@0
   560
}
insilmaril@0
   561
insilmaril@0
   562
insilmaril@0
   563
void BranchObj::positionBBox()
insilmaril@0
   564
{
insilmaril@408
   565
	QPointF ap=getAbsPos();
insilmaril@223
   566
	bbox.moveTopLeft (ap);
insilmaril@169
   567
	positionContents();
insilmaril@0
   568
	setSelBox();
insilmaril@0
   569
insilmaril@0
   570
	// set the frame
insilmaril@408
   571
	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@83
   572
insilmaril@83
   573
	// Update links to other branches
insilmaril@406
   574
	for (int i=0; i<xlink.size(); ++i)
insilmaril@406
   575
		xlink.at(i)->updateXLink();
insilmaril@0
   576
}
insilmaril@0
   577
insilmaril@0
   578
void BranchObj::calcBBoxSize()
insilmaril@0
   579
{
insilmaril@408
   580
    QSizeF heading_r=heading->getSize();
insilmaril@408
   581
    qreal heading_w=(qreal) heading_r.width() ;
insilmaril@408
   582
    qreal heading_h=(qreal) heading_r.height() ;
insilmaril@408
   583
    QSizeF sysflags_r=systemFlags->getSize();
insilmaril@408
   584
	qreal sysflags_h=sysflags_r.height();
insilmaril@408
   585
	qreal sysflags_w=sysflags_r.width();
insilmaril@408
   586
    QSizeF stanflags_r=standardFlags->getSize();
insilmaril@408
   587
	qreal stanflags_h=stanflags_r.height();
insilmaril@408
   588
	qreal stanflags_w=stanflags_r.width();
insilmaril@408
   589
    qreal w;
insilmaril@408
   590
    qreal h;
insilmaril@0
   591
insilmaril@0
   592
	// set width to sum of all widths
insilmaril@0
   593
	w=heading_w + sysflags_w + stanflags_w;
insilmaril@0
   594
	// set height to maximum needed height
insilmaril@0
   595
	h=max (sysflags_h,stanflags_h);
insilmaril@0
   596
	h=max (h,heading_h);
insilmaril@0
   597
insilmaril@223
   598
	// Save the dimension of flags and heading
insilmaril@408
   599
	ornamentsBBox.setSize ( QSizeF(w,h));
insilmaril@223
   600
insilmaril@223
   601
	// clickBox includes Flags and Heading
insilmaril@223
   602
    clickBox.setSize (ornamentsBBox.size() );
insilmaril@169
   603
insilmaril@169
   604
	// Floatimages 
insilmaril@408
   605
	QPointF rp;
insilmaril@169
   606
insilmaril@169
   607
	topPad=botPad=leftPad=rightPad=0;
insilmaril@169
   608
	if (includeImagesVer || includeImagesHor)
insilmaril@169
   609
	{
insilmaril@169
   610
		if (countFloatImages()>0)
insilmaril@169
   611
		{
insilmaril@404
   612
			for (int i=0; i<floatimage.size(); ++i )
insilmaril@169
   613
			{
insilmaril@404
   614
				rp=floatimage.at(i)->getRelPos();
insilmaril@169
   615
				if (includeImagesVer)
insilmaril@169
   616
				{
insilmaril@169
   617
					if (rp.y() < 0) 
insilmaril@223
   618
						topPad=max (topPad,-rp.y()-h);
insilmaril@404
   619
					if (rp.y()+floatimage.at(i)->height() > 0)
insilmaril@404
   620
						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
insilmaril@169
   621
				}		
insilmaril@213
   622
				if (includeImagesHor)
insilmaril@213
   623
				{
insilmaril@223
   624
					if (orientation==OrientRightOfCenter)
insilmaril@223
   625
					{
insilmaril@223
   626
						if (-rp.x()-w > 0) 
insilmaril@223
   627
							leftPad=max (leftPad,-rp.x()-w);
insilmaril@404
   628
						if (rp.x()+floatimage.at(i)->width() > 0)
insilmaril@404
   629
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
insilmaril@223
   630
					} else
insilmaril@223
   631
					{
insilmaril@223
   632
						if (rp.x()< 0) 
insilmaril@223
   633
							leftPad=max (leftPad,-rp.x());
insilmaril@404
   634
						if (rp.x()+floatimage.at(i)->width() > w)
insilmaril@404
   635
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
insilmaril@223
   636
					}
insilmaril@213
   637
				}		
insilmaril@169
   638
			}	
insilmaril@169
   639
		}	
insilmaril@169
   640
		h+=topPad+botPad;
insilmaril@213
   641
		w+=leftPad+rightPad;
insilmaril@169
   642
	}
insilmaril@169
   643
insilmaril@169
   644
	// Frame thickness
insilmaril@0
   645
    w+=frame->getBorder();
insilmaril@0
   646
    h+=frame->getBorder();
insilmaril@169
   647
	
insilmaril@169
   648
	// Finally set size
insilmaril@408
   649
    bbox.setSize (QSizeF (w,h));
insilmaril@0
   650
}
insilmaril@0
   651
insilmaril@223
   652
void BranchObj::setDockPos()
insilmaril@223
   653
{
insilmaril@382
   654
	// Sets childpos and parpos depending on orientation
insilmaril@223
   655
	if (getOrientation()==OrientLeftOfCenter )
insilmaril@223
   656
    {
insilmaril@408
   657
		childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
insilmaril@408
   658
		parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
insilmaril@223
   659
    } else
insilmaril@223
   660
    {
insilmaril@408
   661
		childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
insilmaril@408
   662
		parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
insilmaril@223
   663
    }
insilmaril@223
   664
}
insilmaril@382
   665
insilmaril@408
   666
LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
insilmaril@0
   667
{
insilmaril@0
   668
	// Search branches
insilmaril@0
   669
    LinkableMapObj *lmo;
insilmaril@406
   670
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
   671
    {	
insilmaril@406
   672
		lmo=branch.at(i)->findMapObj(p, excludeLMO);
insilmaril@0
   673
		if (lmo != NULL) return lmo;
insilmaril@0
   674
    }
insilmaril@0
   675
	
insilmaril@0
   676
	// Search myself
insilmaril@169
   677
    if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) 
insilmaril@0
   678
		return this;
insilmaril@0
   679
insilmaril@0
   680
	// Search float images
insilmaril@404
   681
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   682
		if (floatimage.at(i)->inBox(p) && 
insilmaril@404
   683
			(floatimage.at(i) != excludeLMO) && 
insilmaril@404
   684
			floatimage.at(i)->getParObj()!= excludeLMO &&
insilmaril@404
   685
			floatimage.at(i)->isVisibleObj() 
insilmaril@404
   686
		) return floatimage.at(i);
insilmaril@0
   687
insilmaril@0
   688
    return NULL;
insilmaril@0
   689
}
insilmaril@0
   690
insilmaril@0
   691
void BranchObj::setHeading(QString s)
insilmaril@0
   692
{
insilmaril@0
   693
    heading->setText(s);	// set new heading
insilmaril@0
   694
	calcBBoxSize();			// recalculate bbox
insilmaril@0
   695
    positionBBox();			// rearrange contents
insilmaril@0
   696
	requestReposition();
insilmaril@0
   697
}
insilmaril@0
   698
insilmaril@254
   699
void BranchObj::setHideTmp (HideTmpMode mode)
insilmaril@254
   700
{
insilmaril@254
   701
	if (mode==HideExport && hasHiddenExportParent(this))
insilmaril@254
   702
	{
insilmaril@254
   703
		setVisibility (false);
insilmaril@254
   704
		hidden=true;
insilmaril@254
   705
	}else
insilmaril@254
   706
	{
insilmaril@301
   707
		if (hasScrolledParent(this))
insilmaril@301
   708
			setVisibility (false);
insilmaril@301
   709
		else
insilmaril@301
   710
			setVisibility (true);
insilmaril@254
   711
		hidden=false;
insilmaril@254
   712
	}	
insilmaril@254
   713
insilmaril@406
   714
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   715
		branch.at(i)->setHideTmp (mode);
insilmaril@254
   716
}
insilmaril@254
   717
insilmaril@254
   718
bool BranchObj::hasHiddenExportParent(BranchObj *start)
insilmaril@254
   719
{
insilmaril@254
   720
	// Calls parents recursivly to
insilmaril@254
   721
	// find out, if we are temp. hidden
insilmaril@254
   722
insilmaril@254
   723
	if (hideExport) return true;
insilmaril@254
   724
insilmaril@254
   725
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@254
   726
	if (bo) 
insilmaril@254
   727
		return bo->hasHiddenExportParent(start);
insilmaril@254
   728
	else
insilmaril@254
   729
		return false;
insilmaril@254
   730
}
insilmaril@254
   731
insilmaril@408
   732
QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
insilmaril@0
   733
{
insilmaril@417
   734
	// Cloudy stuff can be hidden during exports
insilmaril@254
   735
	if (hidden) return "";
insilmaril@254
   736
insilmaril@417
   737
	// Update of note is usually done while unselecting a branch
insilmaril@417
   738
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
   739
	
insilmaril@0
   740
    QString s,a;
insilmaril@0
   741
	QString scrolledAttr;
insilmaril@0
   742
	if (scrolled) 
insilmaril@0
   743
		scrolledAttr=attribut ("scrolled","yes");
insilmaril@0
   744
	else
insilmaril@0
   745
		scrolledAttr="";
insilmaril@0
   746
insilmaril@0
   747
	QString frameAttr;
insilmaril@0
   748
	if (frame->getFrameType()!=NoFrame)
insilmaril@0
   749
		frameAttr=attribut ("frameType",frame->getFrameTypeName());
insilmaril@0
   750
	else
insilmaril@0
   751
		frameAttr="";
insilmaril@0
   752
insilmaril@0
   753
	// save area, if not scrolled
insilmaril@0
   754
	QString areaAttr;
insilmaril@0
   755
	if (!((BranchObj*)(parObj))->isScrolled() )
insilmaril@0
   756
	{
insilmaril@0
   757
		areaAttr=
insilmaril@408
   758
			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
insilmaril@408
   759
			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
insilmaril@408
   760
			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
insilmaril@408
   761
			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
insilmaril@0
   762
insilmaril@0
   763
	} else
insilmaril@0
   764
		areaAttr="";
insilmaril@0
   765
	
insilmaril@169
   766
	// Providing an ID for a branch makes export to XHTML easier
insilmaril@169
   767
	QString idAttr;
insilmaril@169
   768
	if (countXLinks()>0)
insilmaril@169
   769
		idAttr=attribut ("id",getSelectString());
insilmaril@169
   770
	else
insilmaril@169
   771
		idAttr="";
insilmaril@169
   772
insilmaril@239
   773
    s=beginElement ("branch" 
insilmaril@239
   774
		+getOrnAttr() 
insilmaril@239
   775
		+scrolledAttr 
insilmaril@239
   776
		+frameAttr 
insilmaril@239
   777
		+areaAttr 
insilmaril@239
   778
		+idAttr 
insilmaril@239
   779
		+getIncludeImageAttr() );
insilmaril@0
   780
    incIndent();
insilmaril@0
   781
insilmaril@375
   782
	/* Testing
insilmaril@375
   783
	for (int i=1; i<depth;i++) cout << "  ";
insilmaril@375
   784
	cout <<getHeading().ascii()<<endl;
insilmaril@375
   785
	*/
insilmaril@375
   786
insilmaril@0
   787
	// save heading
insilmaril@160
   788
    s+=valueElement("heading", getHeading(),
insilmaril@0
   789
		attribut ("textColor",QColor(heading->getColor()).name()));
insilmaril@0
   790
insilmaril@0
   791
	// save names of flags set
insilmaril@0
   792
	s+=standardFlags->saveToDir(tmpdir,prefix,0);
insilmaril@0
   793
	
insilmaril@364
   794
	// Save FloatImages
insilmaril@404
   795
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
   796
		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
insilmaril@364
   797
insilmaril@0
   798
	// save note
insilmaril@0
   799
	if (!note.isEmpty() )
insilmaril@0
   800
		s+=note.saveToDir();
insilmaril@0
   801
	
insilmaril@0
   802
	// Save branches
insilmaril@406
   803
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   804
		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
insilmaril@0
   805
insilmaril@95
   806
	// Save XLinks
insilmaril@345
   807
	QString ol;	// old link
insilmaril@345
   808
	QString cl;	// current link
insilmaril@406
   809
	for (int i=0; i<xlink.size(); ++i)
insilmaril@345
   810
	{
insilmaril@406
   811
		cl=xlink.at(i)->saveToDir();
insilmaril@345
   812
		if (cl!=ol)
insilmaril@345
   813
		{
insilmaril@345
   814
			s+=cl;
insilmaril@345
   815
			ol=cl;
insilmaril@345
   816
		} else
insilmaril@345
   817
		{
insilmaril@345
   818
			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
insilmaril@345
   819
		}
insilmaril@345
   820
	}	
insilmaril@95
   821
insilmaril@95
   822
    decIndent();
insilmaril@0
   823
    s+=endElement   ("branch");
insilmaril@0
   824
    return s;
insilmaril@0
   825
}
insilmaril@0
   826
insilmaril@95
   827
void BranchObj::addXLink (XLinkObj *xlo)
insilmaril@83
   828
{
insilmaril@95
   829
	xlink.append (xlo);
insilmaril@83
   830
	
insilmaril@83
   831
}
insilmaril@83
   832
insilmaril@95
   833
void BranchObj::removeXLinkRef (XLinkObj *xlo)
insilmaril@83
   834
{
insilmaril@406
   835
	xlink.removeAt (xlink.indexOf(xlo));
insilmaril@83
   836
}
insilmaril@83
   837
insilmaril@95
   838
void BranchObj::deleteXLink(XLinkObj *xlo)
insilmaril@83
   839
{
insilmaril@95
   840
	xlo->deactivate();
insilmaril@95
   841
	if (!xlo->isUsed()) delete (xlo);
insilmaril@83
   842
}
insilmaril@83
   843
insilmaril@95
   844
void BranchObj::deleteXLinkAt (int i)
insilmaril@94
   845
{
insilmaril@95
   846
	XLinkObj *xlo=xlink.at(i);
insilmaril@95
   847
	xlo->deactivate();
insilmaril@95
   848
	if (!xlo->isUsed()) delete(xlo);
insilmaril@94
   849
}
insilmaril@94
   850
insilmaril@97
   851
XLinkObj* BranchObj::XLinkAt (int i)
insilmaril@97
   852
{
insilmaril@97
   853
	return xlink.at(i);
insilmaril@97
   854
}
insilmaril@97
   855
insilmaril@95
   856
int BranchObj::countXLink()
insilmaril@83
   857
{
insilmaril@95
   858
	return xlink.count();
insilmaril@83
   859
}
insilmaril@83
   860
insilmaril@223
   861
insilmaril@95
   862
BranchObj* BranchObj::XLinkTargetAt (int i)
insilmaril@89
   863
{
insilmaril@406
   864
	if (i>=0 && i<xlink.size())
insilmaril@406
   865
	{
insilmaril@406
   866
		if (xlink.at(i))
insilmaril@406
   867
			return xlink.at(i)->otherBranch (this);
insilmaril@406
   868
	}
insilmaril@406
   869
	return NULL;
insilmaril@89
   870
}
insilmaril@89
   871
insilmaril@169
   872
void BranchObj::setIncludeImagesVer(bool b)
insilmaril@169
   873
{
insilmaril@169
   874
	includeImagesVer=b;
insilmaril@169
   875
	calcBBoxSize();
insilmaril@169
   876
	positionBBox();
insilmaril@169
   877
	requestReposition();
insilmaril@169
   878
}
insilmaril@169
   879
insilmaril@169
   880
bool BranchObj::getIncludeImagesVer()
insilmaril@169
   881
{
insilmaril@169
   882
	return includeImagesVer;
insilmaril@169
   883
}
insilmaril@169
   884
insilmaril@169
   885
void BranchObj::setIncludeImagesHor(bool b)
insilmaril@169
   886
{
insilmaril@169
   887
	includeImagesHor=b;
insilmaril@169
   888
	calcBBoxSize();
insilmaril@169
   889
	positionBBox();
insilmaril@169
   890
	requestReposition();
insilmaril@169
   891
}
insilmaril@169
   892
insilmaril@169
   893
bool BranchObj::getIncludeImagesHor()
insilmaril@169
   894
{
insilmaril@169
   895
	return includeImagesHor;
insilmaril@169
   896
}
insilmaril@169
   897
insilmaril@169
   898
QString BranchObj::getIncludeImageAttr()
insilmaril@169
   899
{
insilmaril@169
   900
	QString a;
insilmaril@169
   901
	if (includeImagesVer)
insilmaril@169
   902
		a=attribut ("incImgV","true");
insilmaril@169
   903
	else
insilmaril@169
   904
		a=attribut ("incImgV","false");
insilmaril@169
   905
	if (includeImagesHor)
insilmaril@213
   906
		a+=attribut ("incImgH","true");
insilmaril@169
   907
	else
insilmaril@213
   908
		a+=attribut ("incImgH","false");
insilmaril@169
   909
	return a;	
insilmaril@169
   910
}
insilmaril@169
   911
insilmaril@395
   912
FloatImageObj* BranchObj::addFloatImage ()
insilmaril@0
   913
{
insilmaril@408
   914
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   915
	floatimage.append (newfi);
insilmaril@0
   916
	if (hasScrolledParent(this) )
insilmaril@0
   917
		newfi->setVisibility (false);
insilmaril@0
   918
	else	
insilmaril@0
   919
		newfi->setVisibility(visible);
insilmaril@395
   920
		/*
insilmaril@169
   921
	calcBBoxSize();
insilmaril@169
   922
	positionBBox();
insilmaril@395
   923
	*/
insilmaril@0
   924
	requestReposition();
insilmaril@0
   925
	return newfi;
insilmaril@0
   926
}
insilmaril@0
   927
insilmaril@395
   928
FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
insilmaril@0
   929
{
insilmaril@408
   930
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   931
	floatimage.append (newfi);
insilmaril@0
   932
	newfi->copy (fio);
insilmaril@0
   933
	if (hasScrolledParent(this) )
insilmaril@0
   934
		newfi->setVisibility (false);
insilmaril@0
   935
	else	
insilmaril@0
   936
		newfi->setVisibility(visible);
insilmaril@395
   937
		/*
insilmaril@169
   938
	calcBBoxSize();
insilmaril@169
   939
	positionBBox();
insilmaril@395
   940
	*/
insilmaril@0
   941
	requestReposition();
insilmaril@0
   942
	return newfi;
insilmaril@0
   943
}
insilmaril@0
   944
insilmaril@0
   945
FloatImageObj* BranchObj::getFirstFloatImage ()
insilmaril@0
   946
{
insilmaril@0
   947
    return floatimage.first();
insilmaril@0
   948
}
insilmaril@0
   949
insilmaril@0
   950
FloatImageObj* BranchObj::getLastFloatImage ()
insilmaril@0
   951
{
insilmaril@0
   952
    return floatimage.last();
insilmaril@0
   953
}
insilmaril@0
   954
insilmaril@0
   955
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
insilmaril@0
   956
{
insilmaril@0
   957
    return floatimage.at(i);
insilmaril@0
   958
}
insilmaril@0
   959
insilmaril@0
   960
void BranchObj::removeFloatImage (FloatImageObj *fio)
insilmaril@0
   961
{
insilmaril@404
   962
	int i=floatimage.indexOf (fio);
insilmaril@411
   963
	if (i>-1) delete (floatimage.takeAt (i));
insilmaril@169
   964
	calcBBoxSize();
insilmaril@169
   965
	positionBBox();
insilmaril@0
   966
	requestReposition();
insilmaril@0
   967
}
insilmaril@0
   968
insilmaril@0
   969
void BranchObj::savePosInAngle ()
insilmaril@0
   970
{
insilmaril@0
   971
	// Save position in angle
insilmaril@406
   972
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   973
		branch.at(i)->angle=i;
insilmaril@0
   974
}
insilmaril@0
   975
insilmaril@146
   976
void BranchObj::setDefAttr (BranchModification mod)
insilmaril@146
   977
{
insilmaril@146
   978
	int fontsize;
insilmaril@146
   979
	switch (depth)
insilmaril@146
   980
	{
insilmaril@146
   981
		case 0: fontsize=16; break;
insilmaril@146
   982
		case 1: fontsize=12; break;
insilmaril@146
   983
		default: fontsize=10; break;
insilmaril@146
   984
	}	
insilmaril@146
   985
insilmaril@146
   986
	setLinkColor ();
insilmaril@146
   987
	setLinkStyle(getDefLinkStyle());
insilmaril@146
   988
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
   989
	font.setPointSize(fontsize);
insilmaril@146
   990
	heading->setFont(font );
insilmaril@146
   991
insilmaril@146
   992
	if (mod==NewBranch)
insilmaril@239
   993
		setColor (((BranchObj*)(parObj))->getColor());
insilmaril@146
   994
	
insilmaril@146
   995
	calcBBoxSize();
insilmaril@146
   996
}
insilmaril@146
   997
insilmaril@0
   998
BranchObj* BranchObj::addBranch()
insilmaril@0
   999
{
insilmaril@408
  1000
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1001
    branch.append (newbo);
insilmaril@0
  1002
    newbo->setParObj(this);
insilmaril@146
  1003
	newbo->setDefAttr(NewBranch);
insilmaril@0
  1004
    newbo->setHeading ("new");
insilmaril@0
  1005
	if (scrolled)
insilmaril@0
  1006
		newbo->setVisibility (false);
insilmaril@0
  1007
	else	
insilmaril@0
  1008
		newbo->setVisibility(visible);
insilmaril@93
  1009
	newbo->updateLink();	
insilmaril@0
  1010
	requestReposition();
insilmaril@0
  1011
	return newbo;
insilmaril@0
  1012
}
insilmaril@0
  1013
insilmaril@0
  1014
BranchObj* BranchObj::addBranch(BranchObj* bo)
insilmaril@0
  1015
{
insilmaril@408
  1016
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1017
    branch.append (newbo);
insilmaril@0
  1018
    newbo->copy(bo);
insilmaril@0
  1019
    newbo->setParObj(this);
insilmaril@162
  1020
	newbo->setDefAttr(MovedBranch);
insilmaril@0
  1021
	if (scrolled)
insilmaril@0
  1022
		newbo->setVisibility (false);
insilmaril@0
  1023
	else	
insilmaril@0
  1024
		newbo->setVisibility(bo->visible);
insilmaril@93
  1025
	newbo->updateLink();	
insilmaril@0
  1026
	requestReposition();
insilmaril@0
  1027
	return newbo;
insilmaril@0
  1028
}
insilmaril@0
  1029
insilmaril@83
  1030
BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
insilmaril@83
  1031
{
insilmaril@83
  1032
	branch.append (bo);
insilmaril@83
  1033
	bo->setParObj (this);
insilmaril@83
  1034
	bo->depth=depth+1;
insilmaril@146
  1035
	bo->setDefAttr(MovedBranch);
insilmaril@83
  1036
	if (scrolled) tmpUnscroll();
insilmaril@83
  1037
	setLastSelectedBranch (bo);
insilmaril@83
  1038
	return bo;
insilmaril@83
  1039
}
insilmaril@83
  1040
insilmaril@0
  1041
BranchObj* BranchObj::insertBranch(int pos)
insilmaril@0
  1042
{
insilmaril@0
  1043
	savePosInAngle();
insilmaril@0
  1044
	// Add new bo and resort branches
insilmaril@0
  1045
	BranchObj *newbo=addBranch ();
insilmaril@0
  1046
	newbo->angle=pos-0.5;
insilmaril@411
  1047
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1048
	return newbo;
insilmaril@0
  1049
}
insilmaril@0
  1050
insilmaril@0
  1051
BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
insilmaril@0
  1052
{
insilmaril@0
  1053
	savePosInAngle();
insilmaril@0
  1054
	// Add new bo and resort branches
insilmaril@0
  1055
	bo->angle=pos-0.5;
insilmaril@0
  1056
	BranchObj *newbo=addBranch (bo);
insilmaril@411
  1057
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1058
	return newbo;
insilmaril@0
  1059
}
insilmaril@0
  1060
insilmaril@83
  1061
BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
insilmaril@83
  1062
{
insilmaril@83
  1063
	savePosInAngle();
insilmaril@83
  1064
	// Add new bo and resort branches
insilmaril@83
  1065
	bo->angle=pos-0.5;
insilmaril@83
  1066
	branch.append (bo);
insilmaril@83
  1067
	bo->setParObj (this);
insilmaril@83
  1068
	bo->depth=depth+1;
insilmaril@146
  1069
	bo->setDefAttr (MovedBranch);
insilmaril@83
  1070
	if (scrolled) tmpUnscroll();
insilmaril@83
  1071
	setLastSelectedBranch (bo);
insilmaril@411
  1072
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@83
  1073
	return bo;
insilmaril@83
  1074
}
insilmaril@83
  1075
insilmaril@98
  1076
void BranchObj::removeBranchHere(BranchObj* borem)
insilmaril@98
  1077
{
insilmaril@98
  1078
	// This removes the branch bo from list, but 
insilmaril@98
  1079
	// inserts its childs at the place of bo
insilmaril@98
  1080
	BranchObj *bo;
insilmaril@98
  1081
	bo=borem->getLastBranch();
insilmaril@139
  1082
	int pos=borem->getNum();
insilmaril@98
  1083
	while (bo)
insilmaril@98
  1084
	{
insilmaril@139
  1085
		bo->moveBranchTo (this,pos+1);
insilmaril@98
  1086
		bo=borem->getLastBranch();
insilmaril@98
  1087
	}	
insilmaril@98
  1088
	removeBranch (borem);
insilmaril@98
  1089
}
insilmaril@98
  1090
insilmaril@98
  1091
void BranchObj::removeChilds()
insilmaril@98
  1092
{
insilmaril@98
  1093
	clear();
insilmaril@98
  1094
}
insilmaril@98
  1095
insilmaril@0
  1096
void BranchObj::removeBranch(BranchObj* bo)
insilmaril@0
  1097
{
insilmaril@0
  1098
    // if bo is not in branch remove returns false, we
insilmaril@0
  1099
    // don't care...
insilmaril@83
  1100
	
insilmaril@406
  1101
	int i=branch.indexOf(bo);
insilmaril@406
  1102
    if (i>=0)
insilmaril@406
  1103
	{
insilmaril@83
  1104
		delete (bo);
insilmaril@406
  1105
		branch.removeAt (i);
insilmaril@406
  1106
	} else
insilmaril@83
  1107
		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
insilmaril@83
  1108
	requestReposition();
insilmaril@83
  1109
}
insilmaril@83
  1110
insilmaril@83
  1111
void BranchObj::removeBranchPtr(BranchObj* bo)
insilmaril@83
  1112
{
insilmaril@406
  1113
	int i=branch.indexOf(bo);
insilmaril@406
  1114
	
insilmaril@406
  1115
	if (i>=0)
insilmaril@406
  1116
		branch.removeAt (i);
insilmaril@406
  1117
	else	
insilmaril@406
  1118
		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
insilmaril@0
  1119
	requestReposition();
insilmaril@0
  1120
}
insilmaril@0
  1121
insilmaril@0
  1122
void BranchObj::setLastSelectedBranch (BranchObj* bo)
insilmaril@0
  1123
{
insilmaril@406
  1124
    lastSelectedBranch=branch.indexOf(bo);
insilmaril@0
  1125
}
insilmaril@0
  1126
insilmaril@0
  1127
BranchObj* BranchObj::getLastSelectedBranch ()
insilmaril@0
  1128
{
insilmaril@417
  1129
    if (lastSelectedBranch>=0)
insilmaril@417
  1130
	{
insilmaril@417
  1131
		if ( branch.size()>lastSelectedBranch) 
insilmaril@417
  1132
			return branch.at(lastSelectedBranch);
insilmaril@417
  1133
		if (branch.size()>0)
insilmaril@417
  1134
			return branch.last();
insilmaril@417
  1135
	}	
insilmaril@408
  1136
    return NULL;
insilmaril@0
  1137
}
insilmaril@0
  1138
insilmaril@0
  1139
BranchObj* BranchObj::getFirstBranch ()
insilmaril@0
  1140
{
insilmaril@408
  1141
	if (branch.size()>0)
insilmaril@408
  1142
		return branch.first();
insilmaril@408
  1143
	else
insilmaril@408
  1144
		return NULL;
insilmaril@0
  1145
}
insilmaril@0
  1146
insilmaril@0
  1147
BranchObj* BranchObj::getLastBranch ()
insilmaril@0
  1148
{
insilmaril@408
  1149
	if (branch.size()>0)
insilmaril@408
  1150
		return branch.last();
insilmaril@408
  1151
	else
insilmaril@408
  1152
		return NULL;
insilmaril@0
  1153
}
insilmaril@0
  1154
insilmaril@406
  1155
BranchObj* BranchObj::getBranchNum (int i)
insilmaril@0
  1156
{
insilmaril@406
  1157
	if (i>=0 && i<branch.size())
insilmaril@406
  1158
		return branch.at(i);
insilmaril@406
  1159
	else	
insilmaril@406
  1160
		return	NULL;
insilmaril@0
  1161
}
insilmaril@0
  1162
insilmaril@310
  1163
bool BranchObj::canMoveBranchUp() 
insilmaril@310
  1164
{
insilmaril@364
  1165
	if (!parObj || depth==1) return false;
insilmaril@310
  1166
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1167
	if (this==par->getFirstBranch())
insilmaril@310
  1168
		return false;
insilmaril@310
  1169
	else
insilmaril@310
  1170
		return true;
insilmaril@310
  1171
}
insilmaril@0
  1172
insilmaril@364
  1173
BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
insilmaril@0
  1174
{
insilmaril@0
  1175
	savePosInAngle();
insilmaril@406
  1176
    int i=branch.indexOf(bo1);
insilmaril@0
  1177
    if (i>0) 
insilmaril@0
  1178
	{	// -1 if bo1 not found 
insilmaril@0
  1179
		branch.at(i)->angle--;
insilmaril@0
  1180
		branch.at(i-1)->angle++;
insilmaril@411
  1181
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1182
		return branch.at(i);
insilmaril@0
  1183
	} else
insilmaril@364
  1184
		return NULL;
insilmaril@0
  1185
}
insilmaril@0
  1186
insilmaril@310
  1187
bool BranchObj::canMoveBranchDown() 
insilmaril@310
  1188
{
insilmaril@364
  1189
	if (!parObj|| depth==1) return false;
insilmaril@310
  1190
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1191
	if (this==par->getLastBranch())
insilmaril@310
  1192
		return false;
insilmaril@310
  1193
	else
insilmaril@310
  1194
		return true;
insilmaril@310
  1195
}
insilmaril@310
  1196
insilmaril@364
  1197
BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
insilmaril@0
  1198
{
insilmaril@0
  1199
	savePosInAngle();
insilmaril@406
  1200
    int i=branch.indexOf(bo1);
insilmaril@0
  1201
	int j;
insilmaril@406
  1202
	if (i <branch.size())
insilmaril@0
  1203
	{
insilmaril@406
  1204
		j = i+1;
insilmaril@0
  1205
		branch.at(i)->angle++;
insilmaril@0
  1206
		branch.at(j)->angle--;
insilmaril@411
  1207
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1208
		return branch.at(i);
insilmaril@0
  1209
	} else
insilmaril@364
  1210
		return NULL;
insilmaril@0
  1211
}
insilmaril@0
  1212
insilmaril@83
  1213
BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
insilmaril@83
  1214
{
insilmaril@83
  1215
	// Find current parent and 
insilmaril@83
  1216
	// remove pointer to myself there
insilmaril@94
  1217
	if (!dst) return NULL;
insilmaril@364
  1218
	BranchObj *par=(BranchObj*)parObj;
insilmaril@83
  1219
	if (par)
insilmaril@83
  1220
		par->removeBranchPtr (this);
insilmaril@83
  1221
	else
insilmaril@83
  1222
		return NULL;
insilmaril@83
  1223
insilmaril@129
  1224
	// Create new pointer to myself at dst
insilmaril@98
  1225
	if (pos<0||dst->getDepth()==0)
insilmaril@83
  1226
	{	
insilmaril@98
  1227
		// links myself as last branch at dst
insilmaril@83
  1228
		dst->addBranchPtr (this);
insilmaril@151
  1229
		updateLink();
insilmaril@83
  1230
		return this;
insilmaril@83
  1231
	} else
insilmaril@83
  1232
	{
insilmaril@83
  1233
		// inserts me at pos in parent of dst
insilmaril@83
  1234
		if (par)
insilmaril@139
  1235
		{
insilmaril@139
  1236
			BranchObj *bo=dst->insertBranchPtr (this,pos);
insilmaril@146
  1237
			bo->setDefAttr(MovedBranch);
insilmaril@151
  1238
			updateLink();
insilmaril@139
  1239
			return bo;
insilmaril@139
  1240
insilmaril@139
  1241
		} else
insilmaril@83
  1242
			return NULL;
insilmaril@83
  1243
	}	
insilmaril@83
  1244
}
insilmaril@83
  1245
insilmaril@408
  1246
void BranchObj::alignRelativeTo (QPointF ref)
insilmaril@0
  1247
{
insilmaril@408
  1248
	qreal th = bboxTotal.height();	
insilmaril@223
  1249
// TODO testing
insilmaril@223
  1250
/*
insilmaril@382
  1251
	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
insilmaril@169
  1252
	cout << "  d="<<depth<<
insilmaril@223
  1253
		"  ref="<<ref<<
insilmaril@254
  1254
//		"  bbox.topLeft="<<bboxTotal.topLeft()<<
insilmaril@223
  1255
		"  absPos="<<absPos<<
insilmaril@382
  1256
		"  relPos="<<relPos<<
insilmaril@382
  1257
		"  orient="<<orientation<<
insilmaril@254
  1258
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
  1259
//		"  hidden="<<hidden<<
insilmaril@382
  1260
//		"  th="<<th<<
insilmaril@382
  1261
		endl;
insilmaril@394
  1262
*/
insilmaril@0
  1263
insilmaril@382
  1264
	setOrientation();
insilmaril@382
  1265
	//updateLink();
insilmaril@382
  1266
insilmaril@0
  1267
	if (depth<2)
insilmaril@364
  1268
	{
insilmaril@0
  1269
		if (depth==1)
insilmaril@382
  1270
		{
insilmaril@382
  1271
			// Position relatively, if needed
insilmaril@382
  1272
			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
insilmaril@382
  1273
insilmaril@0
  1274
			// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
  1275
			// needed for reordering the mainbranches clockwise 
insilmaril@0
  1276
			// around mapcenter 
insilmaril@408
  1277
			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@0
  1278
									(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@382
  1279
		}							
insilmaril@0
  1280
	} 
insilmaril@0
  1281
	else
insilmaril@0
  1282
    {
insilmaril@0
  1283
		// Align myself depending on orientation and parent, but
insilmaril@382
  1284
		// only if I am not a mainbranch or mapcenter itself
insilmaril@382
  1285
		LinkOrient o;
insilmaril@382
  1286
		o=parObj->getOrientation();
insilmaril@0
  1287
		switch (orientation) 
insilmaril@0
  1288
		{
insilmaril@0
  1289
			case OrientLeftOfCenter:
insilmaril@223
  1290
				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@0
  1291
			break;
insilmaril@0
  1292
			case OrientRightOfCenter:	
insilmaril@223
  1293
				move (ref.x() , ref.y() + (th-bbox.height())/2  );
insilmaril@0
  1294
			break;
insilmaril@0
  1295
			default:
insilmaril@223
  1296
				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
insilmaril@0
  1297
			break;
insilmaril@0
  1298
		}		
insilmaril@0
  1299
    }		
insilmaril@0
  1300
insilmaril@0
  1301
	if (scrolled) return;
insilmaril@0
  1302
insilmaril@0
  1303
    // Set reference point for alignment of childs
insilmaril@408
  1304
    QPointF ref2;
insilmaril@0
  1305
    if (orientation==OrientLeftOfCenter)
insilmaril@223
  1306
		ref2.setX(bbox.topLeft().x() - linkwidth);
insilmaril@0
  1307
    else	
insilmaril@223
  1308
		ref2.setX(bbox.topRight().x() + linkwidth);
insilmaril@0
  1309
insilmaril@0
  1310
	if (depth==1)
insilmaril@0
  1311
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
  1312
	else	
insilmaril@0
  1313
		ref2.setY(ref.y() );	
insilmaril@0
  1314
insilmaril@0
  1315
    // Align the childs depending on reference point 
insilmaril@406
  1316
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1317
    {	
insilmaril@406
  1318
		if (!branch.at(i)->isHidden())
insilmaril@254
  1319
		{
insilmaril@406
  1320
			branch.at(i)->alignRelativeTo (ref2);
insilmaril@406
  1321
			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
insilmaril@254
  1322
		}
insilmaril@0
  1323
    }
insilmaril@0
  1324
}
insilmaril@0
  1325
insilmaril@0
  1326
insilmaril@0
  1327
void BranchObj::reposition()
insilmaril@0
  1328
{	
insilmaril@164
  1329
/* TODO testing only
insilmaril@0
  1330
	if (!getHeading().isEmpty())
insilmaril@382
  1331
		cout << "BO::reposition  "<<getHeading().ascii()<<endl;
insilmaril@0
  1332
	else	
insilmaril@0
  1333
		cout << "BO::reposition  ???"<<endl;
insilmaril@382
  1334
insilmaril@382
  1335
	cout << "  orient="<<orientation<<endl;
insilmaril@0
  1336
*/		
insilmaril@382
  1337
insilmaril@0
  1338
	if (depth==0)
insilmaril@0
  1339
	{
insilmaril@0
  1340
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
  1341
		// changes its height,
insilmaril@0
  1342
		// all upper LMOs have to change, too.
insilmaril@0
  1343
		calcBBoxSizeWithChilds();
insilmaril@408
  1344
		updateLink();	// This update is needed if the scene is resized 
insilmaril@333
  1345
						// due to excessive moving of a FIO
insilmaril@333
  1346
insilmaril@408
  1347
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1348
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@411
  1349
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@333
  1350
		positionBBox();	// Reposition bbox and contents
insilmaril@0
  1351
	} else
insilmaril@0
  1352
	{
insilmaril@0
  1353
		// This is only important for moving branches:
insilmaril@0
  1354
		// For editing a branch it isn't called...
insilmaril@408
  1355
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1356
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
  1357
	}
insilmaril@0
  1358
}
insilmaril@0
  1359
insilmaril@382
  1360
void BranchObj::unsetAllRepositionRequests()
insilmaril@382
  1361
{
insilmaril@382
  1362
	repositionRequest=false;
insilmaril@406
  1363
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1364
		branch.at(i)->unsetAllRepositionRequests();
insilmaril@382
  1365
}
insilmaril@382
  1366
insilmaril@0
  1367
insilmaril@408
  1368
QRectF BranchObj::getTotalBBox()
insilmaril@0
  1369
{
insilmaril@408
  1370
	QRectF r=bbox;
insilmaril@0
  1371
insilmaril@0
  1372
	if (scrolled) return r;
insilmaril@0
  1373
insilmaril@406
  1374
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1375
		if (!branch.at(i)->isHidden())
insilmaril@406
  1376
			r=addBBox(branch.at(i)->getTotalBBox(),r);
insilmaril@0
  1377
insilmaril@404
  1378
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
  1379
		if (!floatimage.at(i)->isHidden())
insilmaril@404
  1380
			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
insilmaril@0
  1381
		
insilmaril@0
  1382
	return r;
insilmaril@0
  1383
}
insilmaril@0
  1384
insilmaril@408
  1385
QRectF BranchObj::getBBoxSizeWithChilds()
insilmaril@0
  1386
{
insilmaril@0
  1387
	return bboxTotal;
insilmaril@0
  1388
}
insilmaril@0
  1389
insilmaril@0
  1390
void BranchObj::calcBBoxSizeWithChilds()
insilmaril@169
  1391
{	
insilmaril@169
  1392
	// This is initially called only from reposition and
insilmaril@0
  1393
	// and only for mapcenter. So it won't be
insilmaril@0
  1394
	// called more than once for a single user 
insilmaril@0
  1395
	// action
insilmaril@0
  1396
	
insilmaril@169
  1397
insilmaril@0
  1398
	// Calculate size of LMO including all childs (to align them later)
insilmaril@0
  1399
	bboxTotal.setX(bbox.x() );
insilmaril@0
  1400
	bboxTotal.setY(bbox.y() );
insilmaril@0
  1401
insilmaril@0
  1402
	// if branch is scrolled, ignore childs, but still consider floatimages
insilmaril@0
  1403
	if (scrolled)
insilmaril@0
  1404
	{
insilmaril@0
  1405
		bboxTotal.setWidth (bbox.width());
insilmaril@0
  1406
		bboxTotal.setHeight(bbox.height());
insilmaril@0
  1407
		return;
insilmaril@0
  1408
	}
insilmaril@0
  1409
	
insilmaril@254
  1410
	if (hidden)
insilmaril@254
  1411
	{
insilmaril@254
  1412
		bboxTotal.setWidth (0);
insilmaril@254
  1413
		bboxTotal.setHeight(0);
insilmaril@254
  1414
		if (parObj)
insilmaril@254
  1415
		{
insilmaril@254
  1416
			bboxTotal.setX (parObj->x());
insilmaril@254
  1417
			bboxTotal.setY (parObj->y());
insilmaril@254
  1418
		} else
insilmaril@254
  1419
		{
insilmaril@254
  1420
			bboxTotal.setX (bbox.x());
insilmaril@254
  1421
			bboxTotal.setY (bbox.y());
insilmaril@254
  1422
		}
insilmaril@254
  1423
		return;
insilmaril@254
  1424
	}
insilmaril@254
  1425
	
insilmaril@408
  1426
	QRectF r(0,0,0,0);
insilmaril@408
  1427
	QRectF br;
insilmaril@0
  1428
	// Now calculate recursivly
insilmaril@0
  1429
	// sum of heights 
insilmaril@0
  1430
	// maximum of widths 
insilmaril@0
  1431
	// minimum of y
insilmaril@406
  1432
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1433
	{
insilmaril@406
  1434
		if (!branch.at(i)->isHidden())
insilmaril@254
  1435
		{
insilmaril@406
  1436
			branch.at(i)->calcBBoxSizeWithChilds();
insilmaril@406
  1437
			br=branch.at(i)->getBBoxSizeWithChilds();
insilmaril@254
  1438
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
  1439
			r.setHeight(br.height() + r.height() );
insilmaril@254
  1440
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@254
  1441
		}
insilmaril@0
  1442
	}
insilmaril@0
  1443
	// Add myself and also
insilmaril@0
  1444
	// add width of link to sum if necessary
insilmaril@0
  1445
	if (branch.isEmpty())
insilmaril@0
  1446
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
  1447
	else	
insilmaril@0
  1448
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
  1449
	
insilmaril@169
  1450
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
  1451
}
insilmaril@0
  1452
insilmaril@0
  1453
void BranchObj::select()
insilmaril@0
  1454
{
insilmaril@160
  1455
	// set Text in Editor	
insilmaril@160
  1456
	textEditor->setText(note.getNote() );
insilmaril@160
  1457
	QString fnh=note.getFilenameHint();
insilmaril@160
  1458
	if (fnh!="")
insilmaril@160
  1459
		textEditor->setFilenameHint(note.getFilenameHint() );
insilmaril@160
  1460
	else	
insilmaril@160
  1461
		textEditor->setFilenameHint(getHeading() );
insilmaril@160
  1462
	textEditor->setFontHint (note.getFontHint() );
insilmaril@417
  1463
	isNoteInEditor=true;
insilmaril@160
  1464
insilmaril@0
  1465
    LinkableMapObj::select();
insilmaril@0
  1466
	// Tell parent that I am selected now:
insilmaril@0
  1467
	BranchObj* po=(BranchObj*)(parObj);
insilmaril@0
  1468
    if (po)	// TODO	    Try to get rid of this cast...
insilmaril@0
  1469
        po->setLastSelectedBranch(this);
insilmaril@0
  1470
		
insilmaril@0
  1471
	// temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1472
	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
insilmaril@0
  1473
insilmaril@0
  1474
	// Show URL and link in statusbar
insilmaril@0
  1475
	QString status;
insilmaril@0
  1476
	if (!url.isEmpty()) status+="URL: "+url+"  ";
insilmaril@0
  1477
	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
insilmaril@0
  1478
	if (!status.isEmpty()) mainWindow->statusMessage (status);
insilmaril@0
  1479
insilmaril@0
  1480
	// Update Toolbar
insilmaril@364
  1481
	updateFlagsToolbar();
insilmaril@0
  1482
insilmaril@406
  1483
	// Update actions
insilmaril@0
  1484
	mapEditor->updateActions();
insilmaril@0
  1485
}
insilmaril@0
  1486
insilmaril@0
  1487
void BranchObj::unselect()
insilmaril@0
  1488
{
insilmaril@0
  1489
	LinkableMapObj::unselect();
insilmaril@0
  1490
	// Delete any messages like vymLink in StatusBar
insilmaril@0
  1491
	mainWindow->statusMessage ("");
insilmaril@0
  1492
insilmaril@417
  1493
	// Save current note
insilmaril@417
  1494
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
  1495
	isNoteInEditor=false;
insilmaril@0
  1496
insilmaril@0
  1497
	// reset temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1498
	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
insilmaril@0
  1499
insilmaril@0
  1500
	// Erase content of editor 
insilmaril@0
  1501
	textEditor->setInactive();
insilmaril@0
  1502
insilmaril@0
  1503
	// unselect all buttons in toolbar
insilmaril@103
  1504
	standardFlagsDefault->updateToolbar();
insilmaril@0
  1505
}
insilmaril@0
  1506
insilmaril@0
  1507
QString BranchObj::getSelectString()
insilmaril@0
  1508
{
insilmaril@0
  1509
	QString s;
insilmaril@0
  1510
	if (parObj)
insilmaril@0
  1511
	{
insilmaril@95
  1512
		if (depth==1)
insilmaril@0
  1513
			s= "bo:" + QString("%1").arg(getNum());
insilmaril@0
  1514
		else	
insilmaril@0
  1515
			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
insilmaril@0
  1516
	} else
insilmaril@0
  1517
		s="mc:";
insilmaril@0
  1518
	return s;
insilmaril@0
  1519
}
insilmaril@0
  1520