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