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