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