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