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