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