branchobj.cpp
author insilmaril
Wed, 21 Mar 2007 11:51:38 +0000
changeset 438 eae9abe70d7c
parent 425 7014be3ac7d0
child 440 c6a8651e6bbc
permissions -rw-r--r--
Slightly improved scripting abilities
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
	setSelBox();
insilmaril@0
   576
insilmaril@0
   577
	// set the frame
insilmaril@408
   578
	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@83
   579
insilmaril@83
   580
	// Update links to other branches
insilmaril@406
   581
	for (int i=0; i<xlink.size(); ++i)
insilmaril@406
   582
		xlink.at(i)->updateXLink();
insilmaril@0
   583
}
insilmaril@0
   584
insilmaril@0
   585
void BranchObj::calcBBoxSize()
insilmaril@0
   586
{
insilmaril@408
   587
    QSizeF heading_r=heading->getSize();
insilmaril@408
   588
    qreal heading_w=(qreal) heading_r.width() ;
insilmaril@408
   589
    qreal heading_h=(qreal) heading_r.height() ;
insilmaril@408
   590
    QSizeF sysflags_r=systemFlags->getSize();
insilmaril@408
   591
	qreal sysflags_h=sysflags_r.height();
insilmaril@408
   592
	qreal sysflags_w=sysflags_r.width();
insilmaril@408
   593
    QSizeF stanflags_r=standardFlags->getSize();
insilmaril@408
   594
	qreal stanflags_h=stanflags_r.height();
insilmaril@408
   595
	qreal stanflags_w=stanflags_r.width();
insilmaril@408
   596
    qreal w;
insilmaril@408
   597
    qreal h;
insilmaril@0
   598
insilmaril@0
   599
	// set width to sum of all widths
insilmaril@0
   600
	w=heading_w + sysflags_w + stanflags_w;
insilmaril@0
   601
	// set height to maximum needed height
insilmaril@0
   602
	h=max (sysflags_h,stanflags_h);
insilmaril@0
   603
	h=max (h,heading_h);
insilmaril@0
   604
insilmaril@223
   605
	// Save the dimension of flags and heading
insilmaril@408
   606
	ornamentsBBox.setSize ( QSizeF(w,h));
insilmaril@223
   607
insilmaril@223
   608
	// clickBox includes Flags and Heading
insilmaril@223
   609
    clickBox.setSize (ornamentsBBox.size() );
insilmaril@169
   610
insilmaril@169
   611
	// Floatimages 
insilmaril@408
   612
	QPointF rp;
insilmaril@169
   613
insilmaril@169
   614
	topPad=botPad=leftPad=rightPad=0;
insilmaril@169
   615
	if (includeImagesVer || includeImagesHor)
insilmaril@169
   616
	{
insilmaril@169
   617
		if (countFloatImages()>0)
insilmaril@169
   618
		{
insilmaril@404
   619
			for (int i=0; i<floatimage.size(); ++i )
insilmaril@169
   620
			{
insilmaril@404
   621
				rp=floatimage.at(i)->getRelPos();
insilmaril@169
   622
				if (includeImagesVer)
insilmaril@169
   623
				{
insilmaril@169
   624
					if (rp.y() < 0) 
insilmaril@223
   625
						topPad=max (topPad,-rp.y()-h);
insilmaril@404
   626
					if (rp.y()+floatimage.at(i)->height() > 0)
insilmaril@404
   627
						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
insilmaril@169
   628
				}		
insilmaril@213
   629
				if (includeImagesHor)
insilmaril@213
   630
				{
insilmaril@223
   631
					if (orientation==OrientRightOfCenter)
insilmaril@223
   632
					{
insilmaril@223
   633
						if (-rp.x()-w > 0) 
insilmaril@223
   634
							leftPad=max (leftPad,-rp.x()-w);
insilmaril@404
   635
						if (rp.x()+floatimage.at(i)->width() > 0)
insilmaril@404
   636
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
insilmaril@223
   637
					} else
insilmaril@223
   638
					{
insilmaril@223
   639
						if (rp.x()< 0) 
insilmaril@223
   640
							leftPad=max (leftPad,-rp.x());
insilmaril@404
   641
						if (rp.x()+floatimage.at(i)->width() > w)
insilmaril@404
   642
							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
insilmaril@223
   643
					}
insilmaril@213
   644
				}		
insilmaril@169
   645
			}	
insilmaril@169
   646
		}	
insilmaril@169
   647
		h+=topPad+botPad;
insilmaril@213
   648
		w+=leftPad+rightPad;
insilmaril@169
   649
	}
insilmaril@169
   650
insilmaril@169
   651
	// Frame thickness
insilmaril@0
   652
    w+=frame->getBorder();
insilmaril@0
   653
    h+=frame->getBorder();
insilmaril@169
   654
	
insilmaril@169
   655
	// Finally set size
insilmaril@408
   656
    bbox.setSize (QSizeF (w,h));
insilmaril@0
   657
}
insilmaril@0
   658
insilmaril@223
   659
void BranchObj::setDockPos()
insilmaril@223
   660
{
insilmaril@382
   661
	// Sets childpos and parpos depending on orientation
insilmaril@223
   662
	if (getOrientation()==OrientLeftOfCenter )
insilmaril@223
   663
    {
insilmaril@408
   664
		childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
insilmaril@408
   665
		parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
insilmaril@223
   666
    } else
insilmaril@223
   667
    {
insilmaril@408
   668
		childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
insilmaril@408
   669
		parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
insilmaril@223
   670
    }
insilmaril@223
   671
}
insilmaril@382
   672
insilmaril@408
   673
LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
insilmaril@0
   674
{
insilmaril@0
   675
	// Search branches
insilmaril@0
   676
    LinkableMapObj *lmo;
insilmaril@406
   677
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
   678
    {	
insilmaril@406
   679
		lmo=branch.at(i)->findMapObj(p, excludeLMO);
insilmaril@0
   680
		if (lmo != NULL) return lmo;
insilmaril@0
   681
    }
insilmaril@0
   682
	
insilmaril@0
   683
	// Search myself
insilmaril@169
   684
    if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) 
insilmaril@0
   685
		return this;
insilmaril@0
   686
insilmaril@0
   687
	// Search float images
insilmaril@404
   688
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@404
   689
		if (floatimage.at(i)->inBox(p) && 
insilmaril@404
   690
			(floatimage.at(i) != excludeLMO) && 
insilmaril@404
   691
			floatimage.at(i)->getParObj()!= excludeLMO &&
insilmaril@404
   692
			floatimage.at(i)->isVisibleObj() 
insilmaril@404
   693
		) return floatimage.at(i);
insilmaril@0
   694
insilmaril@0
   695
    return NULL;
insilmaril@0
   696
}
insilmaril@0
   697
insilmaril@0
   698
void BranchObj::setHeading(QString s)
insilmaril@0
   699
{
insilmaril@0
   700
    heading->setText(s);	// set new heading
insilmaril@0
   701
	calcBBoxSize();			// recalculate bbox
insilmaril@0
   702
    positionBBox();			// rearrange contents
insilmaril@0
   703
	requestReposition();
insilmaril@0
   704
}
insilmaril@0
   705
insilmaril@254
   706
void BranchObj::setHideTmp (HideTmpMode mode)
insilmaril@254
   707
{
insilmaril@254
   708
	if (mode==HideExport && hasHiddenExportParent(this))
insilmaril@254
   709
	{
insilmaril@254
   710
		setVisibility (false);
insilmaril@254
   711
		hidden=true;
insilmaril@254
   712
	}else
insilmaril@254
   713
	{
insilmaril@301
   714
		if (hasScrolledParent(this))
insilmaril@301
   715
			setVisibility (false);
insilmaril@301
   716
		else
insilmaril@301
   717
			setVisibility (true);
insilmaril@254
   718
		hidden=false;
insilmaril@254
   719
	}	
insilmaril@254
   720
insilmaril@406
   721
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   722
		branch.at(i)->setHideTmp (mode);
insilmaril@254
   723
}
insilmaril@254
   724
insilmaril@254
   725
bool BranchObj::hasHiddenExportParent(BranchObj *start)
insilmaril@254
   726
{
insilmaril@254
   727
	// Calls parents recursivly to
insilmaril@254
   728
	// find out, if we are temp. hidden
insilmaril@254
   729
insilmaril@254
   730
	if (hideExport) return true;
insilmaril@254
   731
insilmaril@254
   732
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@254
   733
	if (bo) 
insilmaril@254
   734
		return bo->hasHiddenExportParent(start);
insilmaril@254
   735
	else
insilmaril@254
   736
		return false;
insilmaril@254
   737
}
insilmaril@254
   738
insilmaril@408
   739
QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
insilmaril@0
   740
{
insilmaril@417
   741
	// Cloudy stuff can be hidden during exports
insilmaril@254
   742
	if (hidden) return "";
insilmaril@254
   743
insilmaril@417
   744
	// Update of note is usually done while unselecting a branch
insilmaril@417
   745
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
   746
	
insilmaril@0
   747
    QString s,a;
insilmaril@0
   748
	QString scrolledAttr;
insilmaril@0
   749
	if (scrolled) 
insilmaril@0
   750
		scrolledAttr=attribut ("scrolled","yes");
insilmaril@0
   751
	else
insilmaril@0
   752
		scrolledAttr="";
insilmaril@0
   753
insilmaril@0
   754
	// save area, if not scrolled
insilmaril@0
   755
	QString areaAttr;
insilmaril@0
   756
	if (!((BranchObj*)(parObj))->isScrolled() )
insilmaril@0
   757
	{
insilmaril@0
   758
		areaAttr=
insilmaril@408
   759
			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
insilmaril@408
   760
			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
insilmaril@408
   761
			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
insilmaril@408
   762
			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
insilmaril@0
   763
insilmaril@0
   764
	} else
insilmaril@0
   765
		areaAttr="";
insilmaril@0
   766
	
insilmaril@169
   767
	// Providing an ID for a branch makes export to XHTML easier
insilmaril@169
   768
	QString idAttr;
insilmaril@169
   769
	if (countXLinks()>0)
insilmaril@169
   770
		idAttr=attribut ("id",getSelectString());
insilmaril@169
   771
	else
insilmaril@169
   772
		idAttr="";
insilmaril@169
   773
insilmaril@239
   774
    s=beginElement ("branch" 
insilmaril@239
   775
		+getOrnAttr() 
insilmaril@239
   776
		+scrolledAttr 
insilmaril@239
   777
		+areaAttr 
insilmaril@239
   778
		+idAttr 
insilmaril@239
   779
		+getIncludeImageAttr() );
insilmaril@0
   780
    incIndent();
insilmaril@0
   781
insilmaril@0
   782
	// save heading
insilmaril@160
   783
    s+=valueElement("heading", getHeading(),
insilmaril@0
   784
		attribut ("textColor",QColor(heading->getColor()).name()));
insilmaril@0
   785
insilmaril@421
   786
	// Save frame
insilmaril@421
   787
	if (frame->getFrameType()!=NoFrame) 
insilmaril@421
   788
		s+=frame->saveToDir ();
insilmaril@421
   789
insilmaril@0
   790
	// save names of flags set
insilmaril@0
   791
	s+=standardFlags->saveToDir(tmpdir,prefix,0);
insilmaril@0
   792
	
insilmaril@364
   793
	// Save FloatImages
insilmaril@404
   794
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
   795
		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
insilmaril@364
   796
insilmaril@0
   797
	// save note
insilmaril@0
   798
	if (!note.isEmpty() )
insilmaril@0
   799
		s+=note.saveToDir();
insilmaril@0
   800
	
insilmaril@0
   801
	// Save branches
insilmaril@406
   802
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   803
		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
insilmaril@0
   804
insilmaril@95
   805
	// Save XLinks
insilmaril@345
   806
	QString ol;	// old link
insilmaril@345
   807
	QString cl;	// current link
insilmaril@406
   808
	for (int i=0; i<xlink.size(); ++i)
insilmaril@345
   809
	{
insilmaril@406
   810
		cl=xlink.at(i)->saveToDir();
insilmaril@345
   811
		if (cl!=ol)
insilmaril@345
   812
		{
insilmaril@345
   813
			s+=cl;
insilmaril@345
   814
			ol=cl;
insilmaril@345
   815
		} else
insilmaril@345
   816
		{
insilmaril@345
   817
			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
insilmaril@345
   818
		}
insilmaril@345
   819
	}	
insilmaril@95
   820
insilmaril@95
   821
    decIndent();
insilmaril@0
   822
    s+=endElement   ("branch");
insilmaril@0
   823
    return s;
insilmaril@0
   824
}
insilmaril@0
   825
insilmaril@95
   826
void BranchObj::addXLink (XLinkObj *xlo)
insilmaril@83
   827
{
insilmaril@95
   828
	xlink.append (xlo);
insilmaril@83
   829
	
insilmaril@83
   830
}
insilmaril@83
   831
insilmaril@95
   832
void BranchObj::removeXLinkRef (XLinkObj *xlo)
insilmaril@83
   833
{
insilmaril@406
   834
	xlink.removeAt (xlink.indexOf(xlo));
insilmaril@83
   835
}
insilmaril@83
   836
insilmaril@95
   837
void BranchObj::deleteXLink(XLinkObj *xlo)
insilmaril@83
   838
{
insilmaril@95
   839
	xlo->deactivate();
insilmaril@95
   840
	if (!xlo->isUsed()) delete (xlo);
insilmaril@83
   841
}
insilmaril@83
   842
insilmaril@95
   843
void BranchObj::deleteXLinkAt (int i)
insilmaril@94
   844
{
insilmaril@95
   845
	XLinkObj *xlo=xlink.at(i);
insilmaril@95
   846
	xlo->deactivate();
insilmaril@95
   847
	if (!xlo->isUsed()) delete(xlo);
insilmaril@94
   848
}
insilmaril@94
   849
insilmaril@97
   850
XLinkObj* BranchObj::XLinkAt (int i)
insilmaril@97
   851
{
insilmaril@97
   852
	return xlink.at(i);
insilmaril@97
   853
}
insilmaril@97
   854
insilmaril@95
   855
int BranchObj::countXLink()
insilmaril@83
   856
{
insilmaril@95
   857
	return xlink.count();
insilmaril@83
   858
}
insilmaril@83
   859
insilmaril@223
   860
insilmaril@95
   861
BranchObj* BranchObj::XLinkTargetAt (int i)
insilmaril@89
   862
{
insilmaril@406
   863
	if (i>=0 && i<xlink.size())
insilmaril@406
   864
	{
insilmaril@406
   865
		if (xlink.at(i))
insilmaril@406
   866
			return xlink.at(i)->otherBranch (this);
insilmaril@406
   867
	}
insilmaril@406
   868
	return NULL;
insilmaril@89
   869
}
insilmaril@89
   870
insilmaril@169
   871
void BranchObj::setIncludeImagesVer(bool b)
insilmaril@169
   872
{
insilmaril@169
   873
	includeImagesVer=b;
insilmaril@169
   874
	calcBBoxSize();
insilmaril@169
   875
	positionBBox();
insilmaril@169
   876
	requestReposition();
insilmaril@169
   877
}
insilmaril@169
   878
insilmaril@169
   879
bool BranchObj::getIncludeImagesVer()
insilmaril@169
   880
{
insilmaril@169
   881
	return includeImagesVer;
insilmaril@169
   882
}
insilmaril@169
   883
insilmaril@169
   884
void BranchObj::setIncludeImagesHor(bool b)
insilmaril@169
   885
{
insilmaril@169
   886
	includeImagesHor=b;
insilmaril@169
   887
	calcBBoxSize();
insilmaril@169
   888
	positionBBox();
insilmaril@169
   889
	requestReposition();
insilmaril@169
   890
}
insilmaril@169
   891
insilmaril@169
   892
bool BranchObj::getIncludeImagesHor()
insilmaril@169
   893
{
insilmaril@169
   894
	return includeImagesHor;
insilmaril@169
   895
}
insilmaril@169
   896
insilmaril@169
   897
QString BranchObj::getIncludeImageAttr()
insilmaril@169
   898
{
insilmaril@169
   899
	QString a;
insilmaril@169
   900
	if (includeImagesVer)
insilmaril@169
   901
		a=attribut ("incImgV","true");
insilmaril@169
   902
	else
insilmaril@169
   903
		a=attribut ("incImgV","false");
insilmaril@169
   904
	if (includeImagesHor)
insilmaril@213
   905
		a+=attribut ("incImgH","true");
insilmaril@169
   906
	else
insilmaril@213
   907
		a+=attribut ("incImgH","false");
insilmaril@169
   908
	return a;	
insilmaril@169
   909
}
insilmaril@169
   910
insilmaril@395
   911
FloatImageObj* BranchObj::addFloatImage ()
insilmaril@0
   912
{
insilmaril@408
   913
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   914
	floatimage.append (newfi);
insilmaril@0
   915
	if (hasScrolledParent(this) )
insilmaril@0
   916
		newfi->setVisibility (false);
insilmaril@0
   917
	else	
insilmaril@0
   918
		newfi->setVisibility(visible);
insilmaril@395
   919
		/*
insilmaril@169
   920
	calcBBoxSize();
insilmaril@169
   921
	positionBBox();
insilmaril@395
   922
	*/
insilmaril@0
   923
	requestReposition();
insilmaril@0
   924
	return newfi;
insilmaril@0
   925
}
insilmaril@0
   926
insilmaril@395
   927
FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
insilmaril@0
   928
{
insilmaril@408
   929
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   930
	floatimage.append (newfi);
insilmaril@0
   931
	newfi->copy (fio);
insilmaril@0
   932
	if (hasScrolledParent(this) )
insilmaril@0
   933
		newfi->setVisibility (false);
insilmaril@0
   934
	else	
insilmaril@0
   935
		newfi->setVisibility(visible);
insilmaril@395
   936
		/*
insilmaril@169
   937
	calcBBoxSize();
insilmaril@169
   938
	positionBBox();
insilmaril@395
   939
	*/
insilmaril@0
   940
	requestReposition();
insilmaril@0
   941
	return newfi;
insilmaril@0
   942
}
insilmaril@0
   943
insilmaril@0
   944
FloatImageObj* BranchObj::getFirstFloatImage ()
insilmaril@0
   945
{
insilmaril@0
   946
    return floatimage.first();
insilmaril@0
   947
}
insilmaril@0
   948
insilmaril@0
   949
FloatImageObj* BranchObj::getLastFloatImage ()
insilmaril@0
   950
{
insilmaril@0
   951
    return floatimage.last();
insilmaril@0
   952
}
insilmaril@0
   953
insilmaril@0
   954
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
insilmaril@0
   955
{
insilmaril@0
   956
    return floatimage.at(i);
insilmaril@0
   957
}
insilmaril@0
   958
insilmaril@0
   959
void BranchObj::removeFloatImage (FloatImageObj *fio)
insilmaril@0
   960
{
insilmaril@404
   961
	int i=floatimage.indexOf (fio);
insilmaril@411
   962
	if (i>-1) delete (floatimage.takeAt (i));
insilmaril@169
   963
	calcBBoxSize();
insilmaril@169
   964
	positionBBox();
insilmaril@0
   965
	requestReposition();
insilmaril@0
   966
}
insilmaril@0
   967
insilmaril@0
   968
void BranchObj::savePosInAngle ()
insilmaril@0
   969
{
insilmaril@0
   970
	// Save position in angle
insilmaril@406
   971
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   972
		branch.at(i)->angle=i;
insilmaril@0
   973
}
insilmaril@0
   974
insilmaril@146
   975
void BranchObj::setDefAttr (BranchModification mod)
insilmaril@146
   976
{
insilmaril@146
   977
	int fontsize;
insilmaril@146
   978
	switch (depth)
insilmaril@146
   979
	{
insilmaril@146
   980
		case 0: fontsize=16; break;
insilmaril@146
   981
		case 1: fontsize=12; break;
insilmaril@146
   982
		default: fontsize=10; break;
insilmaril@146
   983
	}	
insilmaril@146
   984
insilmaril@146
   985
	setLinkColor ();
insilmaril@146
   986
	setLinkStyle(getDefLinkStyle());
insilmaril@146
   987
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
   988
	font.setPointSize(fontsize);
insilmaril@146
   989
	heading->setFont(font );
insilmaril@146
   990
insilmaril@146
   991
	if (mod==NewBranch)
insilmaril@239
   992
		setColor (((BranchObj*)(parObj))->getColor());
insilmaril@146
   993
	
insilmaril@146
   994
	calcBBoxSize();
insilmaril@146
   995
}
insilmaril@146
   996
insilmaril@0
   997
BranchObj* BranchObj::addBranch()
insilmaril@0
   998
{
insilmaril@408
   999
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1000
    branch.append (newbo);
insilmaril@0
  1001
    newbo->setParObj(this);
insilmaril@146
  1002
	newbo->setDefAttr(NewBranch);
insilmaril@0
  1003
    newbo->setHeading ("new");
insilmaril@0
  1004
	if (scrolled)
insilmaril@0
  1005
		newbo->setVisibility (false);
insilmaril@0
  1006
	else	
insilmaril@0
  1007
		newbo->setVisibility(visible);
insilmaril@93
  1008
	newbo->updateLink();	
insilmaril@0
  1009
	requestReposition();
insilmaril@0
  1010
	return newbo;
insilmaril@0
  1011
}
insilmaril@0
  1012
insilmaril@0
  1013
BranchObj* BranchObj::addBranch(BranchObj* bo)
insilmaril@0
  1014
{
insilmaril@408
  1015
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1016
    branch.append (newbo);
insilmaril@0
  1017
    newbo->copy(bo);
insilmaril@0
  1018
    newbo->setParObj(this);
insilmaril@162
  1019
	newbo->setDefAttr(MovedBranch);
insilmaril@0
  1020
	if (scrolled)
insilmaril@0
  1021
		newbo->setVisibility (false);
insilmaril@0
  1022
	else	
insilmaril@0
  1023
		newbo->setVisibility(bo->visible);
insilmaril@93
  1024
	newbo->updateLink();	
insilmaril@0
  1025
	requestReposition();
insilmaril@0
  1026
	return newbo;
insilmaril@0
  1027
}
insilmaril@0
  1028
insilmaril@83
  1029
BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
insilmaril@83
  1030
{
insilmaril@83
  1031
	branch.append (bo);
insilmaril@83
  1032
	bo->setParObj (this);
insilmaril@83
  1033
	bo->depth=depth+1;
insilmaril@146
  1034
	bo->setDefAttr(MovedBranch);
insilmaril@83
  1035
	if (scrolled) tmpUnscroll();
insilmaril@83
  1036
	setLastSelectedBranch (bo);
insilmaril@83
  1037
	return bo;
insilmaril@83
  1038
}
insilmaril@83
  1039
insilmaril@0
  1040
BranchObj* BranchObj::insertBranch(int pos)
insilmaril@0
  1041
{
insilmaril@0
  1042
	savePosInAngle();
insilmaril@0
  1043
	// Add new bo and resort branches
insilmaril@0
  1044
	BranchObj *newbo=addBranch ();
insilmaril@0
  1045
	newbo->angle=pos-0.5;
insilmaril@411
  1046
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1047
	return newbo;
insilmaril@0
  1048
}
insilmaril@0
  1049
insilmaril@0
  1050
BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
insilmaril@0
  1051
{
insilmaril@0
  1052
	savePosInAngle();
insilmaril@0
  1053
	// Add new bo and resort branches
insilmaril@0
  1054
	bo->angle=pos-0.5;
insilmaril@0
  1055
	BranchObj *newbo=addBranch (bo);
insilmaril@411
  1056
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1057
	return newbo;
insilmaril@0
  1058
}
insilmaril@0
  1059
insilmaril@83
  1060
BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
insilmaril@83
  1061
{
insilmaril@83
  1062
	savePosInAngle();
insilmaril@83
  1063
	// Add new bo and resort branches
insilmaril@83
  1064
	bo->angle=pos-0.5;
insilmaril@83
  1065
	branch.append (bo);
insilmaril@83
  1066
	bo->setParObj (this);
insilmaril@83
  1067
	bo->depth=depth+1;
insilmaril@146
  1068
	bo->setDefAttr (MovedBranch);
insilmaril@83
  1069
	if (scrolled) tmpUnscroll();
insilmaril@83
  1070
	setLastSelectedBranch (bo);
insilmaril@411
  1071
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@83
  1072
	return bo;
insilmaril@83
  1073
}
insilmaril@83
  1074
insilmaril@98
  1075
void BranchObj::removeBranchHere(BranchObj* borem)
insilmaril@98
  1076
{
insilmaril@98
  1077
	// This removes the branch bo from list, but 
insilmaril@98
  1078
	// inserts its childs at the place of bo
insilmaril@98
  1079
	BranchObj *bo;
insilmaril@98
  1080
	bo=borem->getLastBranch();
insilmaril@139
  1081
	int pos=borem->getNum();
insilmaril@98
  1082
	while (bo)
insilmaril@98
  1083
	{
insilmaril@421
  1084
		bo->linkTo (this,pos+1);
insilmaril@98
  1085
		bo=borem->getLastBranch();
insilmaril@98
  1086
	}	
insilmaril@98
  1087
	removeBranch (borem);
insilmaril@98
  1088
}
insilmaril@98
  1089
insilmaril@98
  1090
void BranchObj::removeChilds()
insilmaril@98
  1091
{
insilmaril@98
  1092
	clear();
insilmaril@98
  1093
}
insilmaril@98
  1094
insilmaril@0
  1095
void BranchObj::removeBranch(BranchObj* bo)
insilmaril@0
  1096
{
insilmaril@0
  1097
    // if bo is not in branch remove returns false, we
insilmaril@0
  1098
    // don't care...
insilmaril@83
  1099
	
insilmaril@406
  1100
	int i=branch.indexOf(bo);
insilmaril@406
  1101
    if (i>=0)
insilmaril@406
  1102
	{
insilmaril@83
  1103
		delete (bo);
insilmaril@406
  1104
		branch.removeAt (i);
insilmaril@406
  1105
	} else
insilmaril@83
  1106
		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
insilmaril@83
  1107
	requestReposition();
insilmaril@83
  1108
}
insilmaril@83
  1109
insilmaril@83
  1110
void BranchObj::removeBranchPtr(BranchObj* bo)
insilmaril@83
  1111
{
insilmaril@406
  1112
	int i=branch.indexOf(bo);
insilmaril@406
  1113
	
insilmaril@406
  1114
	if (i>=0)
insilmaril@406
  1115
		branch.removeAt (i);
insilmaril@406
  1116
	else	
insilmaril@406
  1117
		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
insilmaril@0
  1118
	requestReposition();
insilmaril@0
  1119
}
insilmaril@0
  1120
insilmaril@0
  1121
void BranchObj::setLastSelectedBranch (BranchObj* bo)
insilmaril@0
  1122
{
insilmaril@406
  1123
    lastSelectedBranch=branch.indexOf(bo);
insilmaril@0
  1124
}
insilmaril@0
  1125
insilmaril@0
  1126
BranchObj* BranchObj::getLastSelectedBranch ()
insilmaril@0
  1127
{
insilmaril@417
  1128
    if (lastSelectedBranch>=0)
insilmaril@417
  1129
	{
insilmaril@417
  1130
		if ( branch.size()>lastSelectedBranch) 
insilmaril@417
  1131
			return branch.at(lastSelectedBranch);
insilmaril@417
  1132
		if (branch.size()>0)
insilmaril@417
  1133
			return branch.last();
insilmaril@417
  1134
	}	
insilmaril@408
  1135
    return NULL;
insilmaril@0
  1136
}
insilmaril@0
  1137
insilmaril@0
  1138
BranchObj* BranchObj::getFirstBranch ()
insilmaril@0
  1139
{
insilmaril@408
  1140
	if (branch.size()>0)
insilmaril@408
  1141
		return branch.first();
insilmaril@408
  1142
	else
insilmaril@408
  1143
		return NULL;
insilmaril@0
  1144
}
insilmaril@0
  1145
insilmaril@0
  1146
BranchObj* BranchObj::getLastBranch ()
insilmaril@0
  1147
{
insilmaril@408
  1148
	if (branch.size()>0)
insilmaril@408
  1149
		return branch.last();
insilmaril@408
  1150
	else
insilmaril@408
  1151
		return NULL;
insilmaril@0
  1152
}
insilmaril@0
  1153
insilmaril@406
  1154
BranchObj* BranchObj::getBranchNum (int i)
insilmaril@0
  1155
{
insilmaril@406
  1156
	if (i>=0 && i<branch.size())
insilmaril@406
  1157
		return branch.at(i);
insilmaril@406
  1158
	else	
insilmaril@406
  1159
		return	NULL;
insilmaril@0
  1160
}
insilmaril@0
  1161
insilmaril@310
  1162
bool BranchObj::canMoveBranchUp() 
insilmaril@310
  1163
{
insilmaril@364
  1164
	if (!parObj || depth==1) return false;
insilmaril@310
  1165
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1166
	if (this==par->getFirstBranch())
insilmaril@310
  1167
		return false;
insilmaril@310
  1168
	else
insilmaril@310
  1169
		return true;
insilmaril@310
  1170
}
insilmaril@0
  1171
insilmaril@364
  1172
BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
insilmaril@0
  1173
{
insilmaril@0
  1174
	savePosInAngle();
insilmaril@406
  1175
    int i=branch.indexOf(bo1);
insilmaril@0
  1176
    if (i>0) 
insilmaril@0
  1177
	{	// -1 if bo1 not found 
insilmaril@0
  1178
		branch.at(i)->angle--;
insilmaril@0
  1179
		branch.at(i-1)->angle++;
insilmaril@411
  1180
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1181
		return branch.at(i);
insilmaril@0
  1182
	} else
insilmaril@364
  1183
		return NULL;
insilmaril@0
  1184
}
insilmaril@0
  1185
insilmaril@310
  1186
bool BranchObj::canMoveBranchDown() 
insilmaril@310
  1187
{
insilmaril@364
  1188
	if (!parObj|| depth==1) return false;
insilmaril@310
  1189
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1190
	if (this==par->getLastBranch())
insilmaril@310
  1191
		return false;
insilmaril@310
  1192
	else
insilmaril@310
  1193
		return true;
insilmaril@310
  1194
}
insilmaril@310
  1195
insilmaril@364
  1196
BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
insilmaril@0
  1197
{
insilmaril@0
  1198
	savePosInAngle();
insilmaril@406
  1199
    int i=branch.indexOf(bo1);
insilmaril@0
  1200
	int j;
insilmaril@406
  1201
	if (i <branch.size())
insilmaril@0
  1202
	{
insilmaril@406
  1203
		j = i+1;
insilmaril@0
  1204
		branch.at(i)->angle++;
insilmaril@0
  1205
		branch.at(j)->angle--;
insilmaril@411
  1206
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1207
		return branch.at(i);
insilmaril@0
  1208
	} else
insilmaril@364
  1209
		return NULL;
insilmaril@0
  1210
}
insilmaril@0
  1211
insilmaril@421
  1212
BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
insilmaril@83
  1213
{
insilmaril@83
  1214
	// Find current parent and 
insilmaril@83
  1215
	// remove pointer to myself there
insilmaril@94
  1216
	if (!dst) return NULL;
insilmaril@364
  1217
	BranchObj *par=(BranchObj*)parObj;
insilmaril@83
  1218
	if (par)
insilmaril@83
  1219
		par->removeBranchPtr (this);
insilmaril@83
  1220
	else
insilmaril@83
  1221
		return NULL;
insilmaril@83
  1222
insilmaril@129
  1223
	// Create new pointer to myself at dst
insilmaril@98
  1224
	if (pos<0||dst->getDepth()==0)
insilmaril@83
  1225
	{	
insilmaril@98
  1226
		// links myself as last branch at dst
insilmaril@83
  1227
		dst->addBranchPtr (this);
insilmaril@151
  1228
		updateLink();
insilmaril@83
  1229
		return this;
insilmaril@83
  1230
	} else
insilmaril@83
  1231
	{
insilmaril@83
  1232
		// inserts me at pos in parent of dst
insilmaril@83
  1233
		if (par)
insilmaril@139
  1234
		{
insilmaril@139
  1235
			BranchObj *bo=dst->insertBranchPtr (this,pos);
insilmaril@146
  1236
			bo->setDefAttr(MovedBranch);
insilmaril@151
  1237
			updateLink();
insilmaril@139
  1238
			return bo;
insilmaril@139
  1239
insilmaril@139
  1240
		} else
insilmaril@83
  1241
			return NULL;
insilmaril@83
  1242
	}	
insilmaril@83
  1243
}
insilmaril@83
  1244
insilmaril@408
  1245
void BranchObj::alignRelativeTo (QPointF ref)
insilmaril@0
  1246
{
insilmaril@408
  1247
	qreal th = bboxTotal.height();	
insilmaril@223
  1248
// TODO testing
insilmaril@223
  1249
/*
insilmaril@382
  1250
	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
insilmaril@169
  1251
	cout << "  d="<<depth<<
insilmaril@223
  1252
		"  ref="<<ref<<
insilmaril@254
  1253
//		"  bbox.topLeft="<<bboxTotal.topLeft()<<
insilmaril@223
  1254
		"  absPos="<<absPos<<
insilmaril@382
  1255
		"  relPos="<<relPos<<
insilmaril@382
  1256
		"  orient="<<orientation<<
insilmaril@254
  1257
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
  1258
//		"  hidden="<<hidden<<
insilmaril@382
  1259
//		"  th="<<th<<
insilmaril@382
  1260
		endl;
insilmaril@394
  1261
*/
insilmaril@0
  1262
insilmaril@382
  1263
	setOrientation();
insilmaril@382
  1264
	//updateLink();
insilmaril@382
  1265
insilmaril@0
  1266
	if (depth<2)
insilmaril@364
  1267
	{
insilmaril@0
  1268
		if (depth==1)
insilmaril@382
  1269
		{
insilmaril@382
  1270
			// Position relatively, if needed
insilmaril@382
  1271
			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
insilmaril@382
  1272
insilmaril@0
  1273
			// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
  1274
			// needed for reordering the mainbranches clockwise 
insilmaril@0
  1275
			// around mapcenter 
insilmaril@408
  1276
			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@0
  1277
									(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@382
  1278
		}							
insilmaril@0
  1279
	} 
insilmaril@0
  1280
	else
insilmaril@0
  1281
    {
insilmaril@0
  1282
		// Align myself depending on orientation and parent, but
insilmaril@382
  1283
		// only if I am not a mainbranch or mapcenter itself
insilmaril@382
  1284
		LinkOrient o;
insilmaril@382
  1285
		o=parObj->getOrientation();
insilmaril@0
  1286
		switch (orientation) 
insilmaril@0
  1287
		{
insilmaril@0
  1288
			case OrientLeftOfCenter:
insilmaril@223
  1289
				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@0
  1290
			break;
insilmaril@0
  1291
			case OrientRightOfCenter:	
insilmaril@223
  1292
				move (ref.x() , ref.y() + (th-bbox.height())/2  );
insilmaril@0
  1293
			break;
insilmaril@0
  1294
			default:
insilmaril@223
  1295
				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
insilmaril@0
  1296
			break;
insilmaril@0
  1297
		}		
insilmaril@0
  1298
    }		
insilmaril@0
  1299
insilmaril@0
  1300
	if (scrolled) return;
insilmaril@0
  1301
insilmaril@0
  1302
    // Set reference point for alignment of childs
insilmaril@408
  1303
    QPointF ref2;
insilmaril@0
  1304
    if (orientation==OrientLeftOfCenter)
insilmaril@223
  1305
		ref2.setX(bbox.topLeft().x() - linkwidth);
insilmaril@0
  1306
    else	
insilmaril@223
  1307
		ref2.setX(bbox.topRight().x() + linkwidth);
insilmaril@0
  1308
insilmaril@0
  1309
	if (depth==1)
insilmaril@0
  1310
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
  1311
	else	
insilmaril@0
  1312
		ref2.setY(ref.y() );	
insilmaril@0
  1313
insilmaril@0
  1314
    // Align the childs depending on reference point 
insilmaril@406
  1315
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1316
    {	
insilmaril@406
  1317
		if (!branch.at(i)->isHidden())
insilmaril@254
  1318
		{
insilmaril@406
  1319
			branch.at(i)->alignRelativeTo (ref2);
insilmaril@406
  1320
			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
insilmaril@254
  1321
		}
insilmaril@0
  1322
    }
insilmaril@0
  1323
}
insilmaril@0
  1324
insilmaril@0
  1325
insilmaril@0
  1326
void BranchObj::reposition()
insilmaril@0
  1327
{	
insilmaril@164
  1328
/* TODO testing only
insilmaril@0
  1329
	if (!getHeading().isEmpty())
insilmaril@382
  1330
		cout << "BO::reposition  "<<getHeading().ascii()<<endl;
insilmaril@0
  1331
	else	
insilmaril@0
  1332
		cout << "BO::reposition  ???"<<endl;
insilmaril@382
  1333
insilmaril@382
  1334
	cout << "  orient="<<orientation<<endl;
insilmaril@0
  1335
*/		
insilmaril@382
  1336
insilmaril@0
  1337
	if (depth==0)
insilmaril@0
  1338
	{
insilmaril@0
  1339
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
  1340
		// changes its height,
insilmaril@0
  1341
		// all upper LMOs have to change, too.
insilmaril@0
  1342
		calcBBoxSizeWithChilds();
insilmaril@408
  1343
		updateLink();	// This update is needed if the scene is resized 
insilmaril@333
  1344
						// due to excessive moving of a FIO
insilmaril@333
  1345
insilmaril@408
  1346
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1347
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@411
  1348
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@333
  1349
		positionBBox();	// Reposition bbox and contents
insilmaril@0
  1350
	} else
insilmaril@0
  1351
	{
insilmaril@0
  1352
		// This is only important for moving branches:
insilmaril@0
  1353
		// For editing a branch it isn't called...
insilmaril@408
  1354
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1355
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
  1356
	}
insilmaril@0
  1357
}
insilmaril@0
  1358
insilmaril@382
  1359
void BranchObj::unsetAllRepositionRequests()
insilmaril@382
  1360
{
insilmaril@382
  1361
	repositionRequest=false;
insilmaril@406
  1362
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1363
		branch.at(i)->unsetAllRepositionRequests();
insilmaril@382
  1364
}
insilmaril@382
  1365
insilmaril@0
  1366
insilmaril@408
  1367
QRectF BranchObj::getTotalBBox()
insilmaril@0
  1368
{
insilmaril@408
  1369
	QRectF r=bbox;
insilmaril@0
  1370
insilmaril@0
  1371
	if (scrolled) return r;
insilmaril@0
  1372
insilmaril@406
  1373
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1374
		if (!branch.at(i)->isHidden())
insilmaril@406
  1375
			r=addBBox(branch.at(i)->getTotalBBox(),r);
insilmaril@0
  1376
insilmaril@404
  1377
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
  1378
		if (!floatimage.at(i)->isHidden())
insilmaril@404
  1379
			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
insilmaril@0
  1380
		
insilmaril@0
  1381
	return r;
insilmaril@0
  1382
}
insilmaril@0
  1383
insilmaril@408
  1384
QRectF BranchObj::getBBoxSizeWithChilds()
insilmaril@0
  1385
{
insilmaril@0
  1386
	return bboxTotal;
insilmaril@0
  1387
}
insilmaril@0
  1388
insilmaril@0
  1389
void BranchObj::calcBBoxSizeWithChilds()
insilmaril@169
  1390
{	
insilmaril@169
  1391
	// This is initially called only from reposition and
insilmaril@0
  1392
	// and only for mapcenter. So it won't be
insilmaril@0
  1393
	// called more than once for a single user 
insilmaril@0
  1394
	// action
insilmaril@0
  1395
	
insilmaril@169
  1396
insilmaril@0
  1397
	// Calculate size of LMO including all childs (to align them later)
insilmaril@0
  1398
	bboxTotal.setX(bbox.x() );
insilmaril@0
  1399
	bboxTotal.setY(bbox.y() );
insilmaril@0
  1400
insilmaril@0
  1401
	// if branch is scrolled, ignore childs, but still consider floatimages
insilmaril@0
  1402
	if (scrolled)
insilmaril@0
  1403
	{
insilmaril@0
  1404
		bboxTotal.setWidth (bbox.width());
insilmaril@0
  1405
		bboxTotal.setHeight(bbox.height());
insilmaril@0
  1406
		return;
insilmaril@0
  1407
	}
insilmaril@0
  1408
	
insilmaril@254
  1409
	if (hidden)
insilmaril@254
  1410
	{
insilmaril@254
  1411
		bboxTotal.setWidth (0);
insilmaril@254
  1412
		bboxTotal.setHeight(0);
insilmaril@254
  1413
		if (parObj)
insilmaril@254
  1414
		{
insilmaril@254
  1415
			bboxTotal.setX (parObj->x());
insilmaril@254
  1416
			bboxTotal.setY (parObj->y());
insilmaril@254
  1417
		} else
insilmaril@254
  1418
		{
insilmaril@254
  1419
			bboxTotal.setX (bbox.x());
insilmaril@254
  1420
			bboxTotal.setY (bbox.y());
insilmaril@254
  1421
		}
insilmaril@254
  1422
		return;
insilmaril@254
  1423
	}
insilmaril@254
  1424
	
insilmaril@408
  1425
	QRectF r(0,0,0,0);
insilmaril@408
  1426
	QRectF br;
insilmaril@0
  1427
	// Now calculate recursivly
insilmaril@0
  1428
	// sum of heights 
insilmaril@0
  1429
	// maximum of widths 
insilmaril@0
  1430
	// minimum of y
insilmaril@406
  1431
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1432
	{
insilmaril@406
  1433
		if (!branch.at(i)->isHidden())
insilmaril@254
  1434
		{
insilmaril@406
  1435
			branch.at(i)->calcBBoxSizeWithChilds();
insilmaril@406
  1436
			br=branch.at(i)->getBBoxSizeWithChilds();
insilmaril@254
  1437
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
  1438
			r.setHeight(br.height() + r.height() );
insilmaril@254
  1439
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@254
  1440
		}
insilmaril@0
  1441
	}
insilmaril@0
  1442
	// Add myself and also
insilmaril@0
  1443
	// add width of link to sum if necessary
insilmaril@0
  1444
	if (branch.isEmpty())
insilmaril@0
  1445
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
  1446
	else	
insilmaril@0
  1447
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
  1448
	
insilmaril@169
  1449
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
  1450
}
insilmaril@0
  1451
insilmaril@0
  1452
void BranchObj::select()
insilmaril@0
  1453
{
insilmaril@160
  1454
	// set Text in Editor	
insilmaril@160
  1455
	textEditor->setText(note.getNote() );
insilmaril@160
  1456
	QString fnh=note.getFilenameHint();
insilmaril@160
  1457
	if (fnh!="")
insilmaril@160
  1458
		textEditor->setFilenameHint(note.getFilenameHint() );
insilmaril@160
  1459
	else	
insilmaril@160
  1460
		textEditor->setFilenameHint(getHeading() );
insilmaril@160
  1461
	textEditor->setFontHint (note.getFontHint() );
insilmaril@417
  1462
	isNoteInEditor=true;
insilmaril@160
  1463
insilmaril@0
  1464
    LinkableMapObj::select();
insilmaril@0
  1465
	// Tell parent that I am selected now:
insilmaril@0
  1466
	BranchObj* po=(BranchObj*)(parObj);
insilmaril@0
  1467
    if (po)	// TODO	    Try to get rid of this cast...
insilmaril@0
  1468
        po->setLastSelectedBranch(this);
insilmaril@0
  1469
		
insilmaril@0
  1470
	// temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1471
	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
insilmaril@0
  1472
insilmaril@0
  1473
	// Show URL and link in statusbar
insilmaril@0
  1474
	QString status;
insilmaril@0
  1475
	if (!url.isEmpty()) status+="URL: "+url+"  ";
insilmaril@0
  1476
	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
insilmaril@0
  1477
	if (!status.isEmpty()) mainWindow->statusMessage (status);
insilmaril@0
  1478
insilmaril@0
  1479
	// Update Toolbar
insilmaril@364
  1480
	updateFlagsToolbar();
insilmaril@0
  1481
insilmaril@406
  1482
	// Update actions
insilmaril@0
  1483
	mapEditor->updateActions();
insilmaril@0
  1484
}
insilmaril@0
  1485
insilmaril@0
  1486
void BranchObj::unselect()
insilmaril@0
  1487
{
insilmaril@0
  1488
	LinkableMapObj::unselect();
insilmaril@0
  1489
	// Delete any messages like vymLink in StatusBar
insilmaril@0
  1490
	mainWindow->statusMessage ("");
insilmaril@0
  1491
insilmaril@417
  1492
	// Save current note
insilmaril@417
  1493
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
  1494
	isNoteInEditor=false;
insilmaril@0
  1495
insilmaril@0
  1496
	// reset temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1497
	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
insilmaril@0
  1498
insilmaril@0
  1499
	// Erase content of editor 
insilmaril@0
  1500
	textEditor->setInactive();
insilmaril@0
  1501
insilmaril@0
  1502
	// unselect all buttons in toolbar
insilmaril@103
  1503
	standardFlagsDefault->updateToolbar();
insilmaril@0
  1504
}
insilmaril@0
  1505
insilmaril@0
  1506
QString BranchObj::getSelectString()
insilmaril@0
  1507
{
insilmaril@0
  1508
	QString s;
insilmaril@0
  1509
	if (parObj)
insilmaril@0
  1510
	{
insilmaril@95
  1511
		if (depth==1)
insilmaril@0
  1512
			s= "bo:" + QString("%1").arg(getNum());
insilmaril@0
  1513
		else	
insilmaril@0
  1514
			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
insilmaril@0
  1515
	} else
insilmaril@0
  1516
		s="mc:";
insilmaril@0
  1517
	return s;
insilmaril@0
  1518
}
insilmaril@0
  1519