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