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