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