branchobj.cpp
author insilmaril
Tue, 04 Dec 2007 12:32:56 +0000
changeset 626 96c8e6860e0c
parent 616 16d63fc9ae42
child 628 d7d0708b1c60
permissions -rw-r--r--
Fixed HideExport bug, changed pre- and postscript in XHTML export dialog
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@598
   743
	if (mode==HideExport && hasHiddenExportParent())
insilmaril@254
   744
	{
insilmaril@254
   745
		setVisibility (false);
insilmaril@254
   746
		hidden=true;
insilmaril@254
   747
	}else
insilmaril@254
   748
	{
insilmaril@301
   749
		if (hasScrolledParent(this))
insilmaril@301
   750
			setVisibility (false);
insilmaril@301
   751
		else
insilmaril@301
   752
			setVisibility (true);
insilmaril@254
   753
		hidden=false;
insilmaril@254
   754
	}	
insilmaril@254
   755
insilmaril@406
   756
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   757
		branch.at(i)->setHideTmp (mode);
insilmaril@254
   758
}
insilmaril@254
   759
insilmaril@598
   760
bool BranchObj::hasHiddenExportParent()
insilmaril@254
   761
{
insilmaril@254
   762
	// Calls parents recursivly to
insilmaril@254
   763
	// find out, if we are temp. hidden
insilmaril@254
   764
insilmaril@254
   765
	if (hideExport) return true;
insilmaril@254
   766
insilmaril@598
   767
	BranchObj* bo=(BranchObj*)parObj;
insilmaril@254
   768
	if (bo) 
insilmaril@598
   769
		return bo->hasHiddenExportParent();
insilmaril@254
   770
	else
insilmaril@254
   771
		return false;
insilmaril@254
   772
}
insilmaril@254
   773
insilmaril@408
   774
QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
insilmaril@0
   775
{
insilmaril@417
   776
	// Cloudy stuff can be hidden during exports
insilmaril@254
   777
	if (hidden) return "";
insilmaril@254
   778
insilmaril@417
   779
	// Update of note is usually done while unselecting a branch
insilmaril@417
   780
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
   781
	
insilmaril@0
   782
    QString s,a;
insilmaril@0
   783
	QString scrolledAttr;
insilmaril@0
   784
	if (scrolled) 
insilmaril@0
   785
		scrolledAttr=attribut ("scrolled","yes");
insilmaril@0
   786
	else
insilmaril@0
   787
		scrolledAttr="";
insilmaril@0
   788
insilmaril@0
   789
	// save area, if not scrolled
insilmaril@0
   790
	QString areaAttr;
insilmaril@0
   791
	if (!((BranchObj*)(parObj))->isScrolled() )
insilmaril@0
   792
	{
insilmaril@0
   793
		areaAttr=
insilmaril@408
   794
			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
insilmaril@408
   795
			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
insilmaril@408
   796
			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
insilmaril@408
   797
			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
insilmaril@0
   798
insilmaril@0
   799
	} else
insilmaril@0
   800
		areaAttr="";
insilmaril@0
   801
	
insilmaril@169
   802
	// Providing an ID for a branch makes export to XHTML easier
insilmaril@169
   803
	QString idAttr;
insilmaril@169
   804
	if (countXLinks()>0)
insilmaril@169
   805
		idAttr=attribut ("id",getSelectString());
insilmaril@169
   806
	else
insilmaril@169
   807
		idAttr="";
insilmaril@169
   808
insilmaril@239
   809
    s=beginElement ("branch" 
insilmaril@239
   810
		+getOrnAttr() 
insilmaril@239
   811
		+scrolledAttr 
insilmaril@239
   812
		+areaAttr 
insilmaril@239
   813
		+idAttr 
insilmaril@239
   814
		+getIncludeImageAttr() );
insilmaril@0
   815
    incIndent();
insilmaril@0
   816
insilmaril@0
   817
	// save heading
insilmaril@160
   818
    s+=valueElement("heading", getHeading(),
insilmaril@0
   819
		attribut ("textColor",QColor(heading->getColor()).name()));
insilmaril@0
   820
insilmaril@421
   821
	// Save frame
insilmaril@462
   822
	if (frame->getFrameType()!=FrameObj::NoFrame) 
insilmaril@421
   823
		s+=frame->saveToDir ();
insilmaril@421
   824
insilmaril@0
   825
	// save names of flags set
insilmaril@0
   826
	s+=standardFlags->saveToDir(tmpdir,prefix,0);
insilmaril@0
   827
	
insilmaril@364
   828
	// Save FloatImages
insilmaril@404
   829
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
   830
		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
insilmaril@364
   831
insilmaril@0
   832
	// save note
insilmaril@0
   833
	if (!note.isEmpty() )
insilmaril@0
   834
		s+=note.saveToDir();
insilmaril@0
   835
	
insilmaril@0
   836
	// Save branches
insilmaril@406
   837
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
   838
		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
insilmaril@0
   839
insilmaril@95
   840
	// Save XLinks
insilmaril@345
   841
	QString ol;	// old link
insilmaril@345
   842
	QString cl;	// current link
insilmaril@406
   843
	for (int i=0; i<xlink.size(); ++i)
insilmaril@345
   844
	{
insilmaril@406
   845
		cl=xlink.at(i)->saveToDir();
insilmaril@345
   846
		if (cl!=ol)
insilmaril@345
   847
		{
insilmaril@345
   848
			s+=cl;
insilmaril@345
   849
			ol=cl;
insilmaril@345
   850
		} else
insilmaril@345
   851
		{
insilmaril@345
   852
			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
insilmaril@345
   853
		}
insilmaril@345
   854
	}	
insilmaril@95
   855
insilmaril@95
   856
    decIndent();
insilmaril@0
   857
    s+=endElement   ("branch");
insilmaril@0
   858
    return s;
insilmaril@0
   859
}
insilmaril@0
   860
insilmaril@95
   861
void BranchObj::addXLink (XLinkObj *xlo)
insilmaril@83
   862
{
insilmaril@95
   863
	xlink.append (xlo);
insilmaril@83
   864
	
insilmaril@83
   865
}
insilmaril@83
   866
insilmaril@95
   867
void BranchObj::removeXLinkRef (XLinkObj *xlo)
insilmaril@83
   868
{
insilmaril@406
   869
	xlink.removeAt (xlink.indexOf(xlo));
insilmaril@83
   870
}
insilmaril@83
   871
insilmaril@95
   872
void BranchObj::deleteXLink(XLinkObj *xlo)
insilmaril@83
   873
{
insilmaril@95
   874
	xlo->deactivate();
insilmaril@95
   875
	if (!xlo->isUsed()) delete (xlo);
insilmaril@83
   876
}
insilmaril@83
   877
insilmaril@95
   878
void BranchObj::deleteXLinkAt (int i)
insilmaril@94
   879
{
insilmaril@95
   880
	XLinkObj *xlo=xlink.at(i);
insilmaril@95
   881
	xlo->deactivate();
insilmaril@95
   882
	if (!xlo->isUsed()) delete(xlo);
insilmaril@94
   883
}
insilmaril@94
   884
insilmaril@97
   885
XLinkObj* BranchObj::XLinkAt (int i)
insilmaril@97
   886
{
insilmaril@97
   887
	return xlink.at(i);
insilmaril@97
   888
}
insilmaril@97
   889
insilmaril@95
   890
int BranchObj::countXLink()
insilmaril@83
   891
{
insilmaril@95
   892
	return xlink.count();
insilmaril@83
   893
}
insilmaril@83
   894
insilmaril@223
   895
insilmaril@95
   896
BranchObj* BranchObj::XLinkTargetAt (int i)
insilmaril@89
   897
{
insilmaril@406
   898
	if (i>=0 && i<xlink.size())
insilmaril@406
   899
	{
insilmaril@406
   900
		if (xlink.at(i))
insilmaril@406
   901
			return xlink.at(i)->otherBranch (this);
insilmaril@406
   902
	}
insilmaril@406
   903
	return NULL;
insilmaril@89
   904
}
insilmaril@89
   905
insilmaril@169
   906
void BranchObj::setIncludeImagesVer(bool b)
insilmaril@169
   907
{
insilmaril@169
   908
	includeImagesVer=b;
insilmaril@169
   909
	calcBBoxSize();
insilmaril@169
   910
	positionBBox();
insilmaril@169
   911
	requestReposition();
insilmaril@169
   912
}
insilmaril@169
   913
insilmaril@169
   914
bool BranchObj::getIncludeImagesVer()
insilmaril@169
   915
{
insilmaril@169
   916
	return includeImagesVer;
insilmaril@169
   917
}
insilmaril@169
   918
insilmaril@169
   919
void BranchObj::setIncludeImagesHor(bool b)
insilmaril@169
   920
{
insilmaril@169
   921
	includeImagesHor=b;
insilmaril@169
   922
	calcBBoxSize();
insilmaril@169
   923
	positionBBox();
insilmaril@169
   924
	requestReposition();
insilmaril@169
   925
}
insilmaril@169
   926
insilmaril@169
   927
bool BranchObj::getIncludeImagesHor()
insilmaril@169
   928
{
insilmaril@169
   929
	return includeImagesHor;
insilmaril@169
   930
}
insilmaril@169
   931
insilmaril@169
   932
QString BranchObj::getIncludeImageAttr()
insilmaril@169
   933
{
insilmaril@169
   934
	QString a;
insilmaril@169
   935
	if (includeImagesVer)
insilmaril@169
   936
		a=attribut ("incImgV","true");
insilmaril@169
   937
	else
insilmaril@169
   938
		a=attribut ("incImgV","false");
insilmaril@169
   939
	if (includeImagesHor)
insilmaril@213
   940
		a+=attribut ("incImgH","true");
insilmaril@169
   941
	else
insilmaril@213
   942
		a+=attribut ("incImgH","false");
insilmaril@169
   943
	return a;	
insilmaril@169
   944
}
insilmaril@169
   945
insilmaril@395
   946
FloatImageObj* BranchObj::addFloatImage ()
insilmaril@0
   947
{
insilmaril@408
   948
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   949
	floatimage.append (newfi);
insilmaril@0
   950
	if (hasScrolledParent(this) )
insilmaril@0
   951
		newfi->setVisibility (false);
insilmaril@0
   952
	else	
insilmaril@0
   953
		newfi->setVisibility(visible);
insilmaril@395
   954
		/*
insilmaril@169
   955
	calcBBoxSize();
insilmaril@169
   956
	positionBBox();
insilmaril@395
   957
	*/
insilmaril@0
   958
	requestReposition();
insilmaril@0
   959
	return newfi;
insilmaril@0
   960
}
insilmaril@0
   961
insilmaril@395
   962
FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
insilmaril@0
   963
{
insilmaril@408
   964
	FloatImageObj *newfi=new FloatImageObj (scene,this);
insilmaril@0
   965
	floatimage.append (newfi);
insilmaril@0
   966
	newfi->copy (fio);
insilmaril@0
   967
	if (hasScrolledParent(this) )
insilmaril@0
   968
		newfi->setVisibility (false);
insilmaril@0
   969
	else	
insilmaril@0
   970
		newfi->setVisibility(visible);
insilmaril@395
   971
		/*
insilmaril@169
   972
	calcBBoxSize();
insilmaril@169
   973
	positionBBox();
insilmaril@395
   974
	*/
insilmaril@0
   975
	requestReposition();
insilmaril@0
   976
	return newfi;
insilmaril@0
   977
}
insilmaril@0
   978
insilmaril@0
   979
FloatImageObj* BranchObj::getFirstFloatImage ()
insilmaril@0
   980
{
insilmaril@0
   981
    return floatimage.first();
insilmaril@0
   982
}
insilmaril@0
   983
insilmaril@0
   984
FloatImageObj* BranchObj::getLastFloatImage ()
insilmaril@0
   985
{
insilmaril@0
   986
    return floatimage.last();
insilmaril@0
   987
}
insilmaril@0
   988
insilmaril@0
   989
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
insilmaril@0
   990
{
insilmaril@0
   991
    return floatimage.at(i);
insilmaril@0
   992
}
insilmaril@0
   993
insilmaril@0
   994
void BranchObj::removeFloatImage (FloatImageObj *fio)
insilmaril@0
   995
{
insilmaril@404
   996
	int i=floatimage.indexOf (fio);
insilmaril@411
   997
	if (i>-1) delete (floatimage.takeAt (i));
insilmaril@169
   998
	calcBBoxSize();
insilmaril@169
   999
	positionBBox();
insilmaril@0
  1000
	requestReposition();
insilmaril@0
  1001
}
insilmaril@0
  1002
insilmaril@0
  1003
void BranchObj::savePosInAngle ()
insilmaril@0
  1004
{
insilmaril@0
  1005
	// Save position in angle
insilmaril@406
  1006
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1007
		branch.at(i)->angle=i;
insilmaril@0
  1008
}
insilmaril@0
  1009
insilmaril@146
  1010
void BranchObj::setDefAttr (BranchModification mod)
insilmaril@146
  1011
{
insilmaril@146
  1012
	int fontsize;
insilmaril@146
  1013
	switch (depth)
insilmaril@146
  1014
	{
insilmaril@146
  1015
		case 0: fontsize=16; break;
insilmaril@146
  1016
		case 1: fontsize=12; break;
insilmaril@146
  1017
		default: fontsize=10; break;
insilmaril@146
  1018
	}	
insilmaril@146
  1019
insilmaril@146
  1020
	setLinkColor ();
insilmaril@146
  1021
	setLinkStyle(getDefLinkStyle());
insilmaril@146
  1022
	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@146
  1023
	font.setPointSize(fontsize);
insilmaril@146
  1024
	heading->setFont(font );
insilmaril@146
  1025
insilmaril@146
  1026
	if (mod==NewBranch)
insilmaril@239
  1027
		setColor (((BranchObj*)(parObj))->getColor());
insilmaril@146
  1028
	
insilmaril@146
  1029
	calcBBoxSize();
insilmaril@146
  1030
}
insilmaril@146
  1031
insilmaril@0
  1032
BranchObj* BranchObj::addBranch()
insilmaril@0
  1033
{
insilmaril@408
  1034
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1035
    branch.append (newbo);
insilmaril@0
  1036
    newbo->setParObj(this);
insilmaril@146
  1037
	newbo->setDefAttr(NewBranch);
insilmaril@0
  1038
    newbo->setHeading ("new");
insilmaril@0
  1039
	if (scrolled)
insilmaril@0
  1040
		newbo->setVisibility (false);
insilmaril@0
  1041
	else	
insilmaril@0
  1042
		newbo->setVisibility(visible);
insilmaril@93
  1043
	newbo->updateLink();	
insilmaril@0
  1044
	requestReposition();
insilmaril@0
  1045
	return newbo;
insilmaril@0
  1046
}
insilmaril@0
  1047
insilmaril@0
  1048
BranchObj* BranchObj::addBranch(BranchObj* bo)
insilmaril@0
  1049
{
insilmaril@408
  1050
    BranchObj* newbo=new BranchObj(scene,this);
insilmaril@0
  1051
    branch.append (newbo);
insilmaril@0
  1052
    newbo->copy(bo);
insilmaril@0
  1053
    newbo->setParObj(this);
insilmaril@162
  1054
	newbo->setDefAttr(MovedBranch);
insilmaril@0
  1055
	if (scrolled)
insilmaril@0
  1056
		newbo->setVisibility (false);
insilmaril@0
  1057
	else	
insilmaril@0
  1058
		newbo->setVisibility(bo->visible);
insilmaril@93
  1059
	newbo->updateLink();	
insilmaril@0
  1060
	requestReposition();
insilmaril@0
  1061
	return newbo;
insilmaril@0
  1062
}
insilmaril@0
  1063
insilmaril@83
  1064
BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
insilmaril@83
  1065
{
insilmaril@83
  1066
	branch.append (bo);
insilmaril@83
  1067
	bo->setParObj (this);
insilmaril@83
  1068
	bo->depth=depth+1;
insilmaril@146
  1069
	bo->setDefAttr(MovedBranch);
insilmaril@83
  1070
	if (scrolled) tmpUnscroll();
insilmaril@83
  1071
	setLastSelectedBranch (bo);
insilmaril@83
  1072
	return bo;
insilmaril@83
  1073
}
insilmaril@83
  1074
insilmaril@0
  1075
BranchObj* BranchObj::insertBranch(int pos)
insilmaril@0
  1076
{
insilmaril@0
  1077
	savePosInAngle();
insilmaril@0
  1078
	// Add new bo and resort branches
insilmaril@0
  1079
	BranchObj *newbo=addBranch ();
insilmaril@0
  1080
	newbo->angle=pos-0.5;
insilmaril@411
  1081
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1082
	return newbo;
insilmaril@0
  1083
}
insilmaril@0
  1084
insilmaril@0
  1085
BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
insilmaril@0
  1086
{
insilmaril@0
  1087
	savePosInAngle();
insilmaril@0
  1088
	// Add new bo and resort branches
insilmaril@0
  1089
	bo->angle=pos-0.5;
insilmaril@0
  1090
	BranchObj *newbo=addBranch (bo);
insilmaril@411
  1091
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@0
  1092
	return newbo;
insilmaril@0
  1093
}
insilmaril@0
  1094
insilmaril@83
  1095
BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
insilmaril@83
  1096
{
insilmaril@83
  1097
	savePosInAngle();
insilmaril@83
  1098
	// Add new bo and resort branches
insilmaril@83
  1099
	bo->angle=pos-0.5;
insilmaril@83
  1100
	branch.append (bo);
insilmaril@83
  1101
	bo->setParObj (this);
insilmaril@83
  1102
	bo->depth=depth+1;
insilmaril@146
  1103
	bo->setDefAttr (MovedBranch);
insilmaril@83
  1104
	if (scrolled) tmpUnscroll();
insilmaril@83
  1105
	setLastSelectedBranch (bo);
insilmaril@411
  1106
	qSort (branch.begin(),branch.end(), isAbove);
insilmaril@83
  1107
	return bo;
insilmaril@83
  1108
}
insilmaril@83
  1109
insilmaril@98
  1110
void BranchObj::removeBranchHere(BranchObj* borem)
insilmaril@98
  1111
{
insilmaril@98
  1112
	// This removes the branch bo from list, but 
insilmaril@98
  1113
	// inserts its childs at the place of bo
insilmaril@98
  1114
	BranchObj *bo;
insilmaril@98
  1115
	bo=borem->getLastBranch();
insilmaril@139
  1116
	int pos=borem->getNum();
insilmaril@98
  1117
	while (bo)
insilmaril@98
  1118
	{
insilmaril@421
  1119
		bo->linkTo (this,pos+1);
insilmaril@98
  1120
		bo=borem->getLastBranch();
insilmaril@98
  1121
	}	
insilmaril@98
  1122
	removeBranch (borem);
insilmaril@98
  1123
}
insilmaril@98
  1124
insilmaril@98
  1125
void BranchObj::removeChilds()
insilmaril@98
  1126
{
insilmaril@98
  1127
	clear();
insilmaril@98
  1128
}
insilmaril@98
  1129
insilmaril@0
  1130
void BranchObj::removeBranch(BranchObj* bo)
insilmaril@0
  1131
{
insilmaril@0
  1132
    // if bo is not in branch remove returns false, we
insilmaril@0
  1133
    // don't care...
insilmaril@83
  1134
	
insilmaril@406
  1135
	int i=branch.indexOf(bo);
insilmaril@406
  1136
    if (i>=0)
insilmaril@406
  1137
	{
insilmaril@83
  1138
		delete (bo);
insilmaril@406
  1139
		branch.removeAt (i);
insilmaril@406
  1140
	} else
insilmaril@83
  1141
		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
insilmaril@83
  1142
	requestReposition();
insilmaril@83
  1143
}
insilmaril@83
  1144
insilmaril@83
  1145
void BranchObj::removeBranchPtr(BranchObj* bo)
insilmaril@83
  1146
{
insilmaril@406
  1147
	int i=branch.indexOf(bo);
insilmaril@406
  1148
	
insilmaril@406
  1149
	if (i>=0)
insilmaril@406
  1150
		branch.removeAt (i);
insilmaril@406
  1151
	else	
insilmaril@406
  1152
		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
insilmaril@0
  1153
	requestReposition();
insilmaril@0
  1154
}
insilmaril@0
  1155
insilmaril@0
  1156
void BranchObj::setLastSelectedBranch (BranchObj* bo)
insilmaril@0
  1157
{
insilmaril@406
  1158
    lastSelectedBranch=branch.indexOf(bo);
insilmaril@0
  1159
}
insilmaril@0
  1160
insilmaril@0
  1161
BranchObj* BranchObj::getLastSelectedBranch ()
insilmaril@0
  1162
{
insilmaril@417
  1163
    if (lastSelectedBranch>=0)
insilmaril@417
  1164
	{
insilmaril@417
  1165
		if ( branch.size()>lastSelectedBranch) 
insilmaril@417
  1166
			return branch.at(lastSelectedBranch);
insilmaril@417
  1167
		if (branch.size()>0)
insilmaril@417
  1168
			return branch.last();
insilmaril@417
  1169
	}	
insilmaril@408
  1170
    return NULL;
insilmaril@0
  1171
}
insilmaril@0
  1172
insilmaril@0
  1173
BranchObj* BranchObj::getFirstBranch ()
insilmaril@0
  1174
{
insilmaril@408
  1175
	if (branch.size()>0)
insilmaril@408
  1176
		return branch.first();
insilmaril@408
  1177
	else
insilmaril@408
  1178
		return NULL;
insilmaril@0
  1179
}
insilmaril@0
  1180
insilmaril@0
  1181
BranchObj* BranchObj::getLastBranch ()
insilmaril@0
  1182
{
insilmaril@408
  1183
	if (branch.size()>0)
insilmaril@408
  1184
		return branch.last();
insilmaril@408
  1185
	else
insilmaril@408
  1186
		return NULL;
insilmaril@0
  1187
}
insilmaril@0
  1188
insilmaril@406
  1189
BranchObj* BranchObj::getBranchNum (int i)
insilmaril@0
  1190
{
insilmaril@406
  1191
	if (i>=0 && i<branch.size())
insilmaril@406
  1192
		return branch.at(i);
insilmaril@406
  1193
	else	
insilmaril@406
  1194
		return	NULL;
insilmaril@0
  1195
}
insilmaril@0
  1196
insilmaril@310
  1197
bool BranchObj::canMoveBranchUp() 
insilmaril@310
  1198
{
insilmaril@364
  1199
	if (!parObj || depth==1) return false;
insilmaril@310
  1200
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1201
	if (this==par->getFirstBranch())
insilmaril@310
  1202
		return false;
insilmaril@310
  1203
	else
insilmaril@310
  1204
		return true;
insilmaril@310
  1205
}
insilmaril@0
  1206
insilmaril@364
  1207
BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
insilmaril@0
  1208
{
insilmaril@0
  1209
	savePosInAngle();
insilmaril@406
  1210
    int i=branch.indexOf(bo1);
insilmaril@0
  1211
    if (i>0) 
insilmaril@0
  1212
	{	// -1 if bo1 not found 
insilmaril@0
  1213
		branch.at(i)->angle--;
insilmaril@0
  1214
		branch.at(i-1)->angle++;
insilmaril@411
  1215
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1216
		return branch.at(i);
insilmaril@0
  1217
	} else
insilmaril@364
  1218
		return NULL;
insilmaril@0
  1219
}
insilmaril@0
  1220
insilmaril@310
  1221
bool BranchObj::canMoveBranchDown() 
insilmaril@310
  1222
{
insilmaril@364
  1223
	if (!parObj|| depth==1) return false;
insilmaril@310
  1224
	BranchObj* par=(BranchObj*)parObj;
insilmaril@310
  1225
	if (this==par->getLastBranch())
insilmaril@310
  1226
		return false;
insilmaril@310
  1227
	else
insilmaril@310
  1228
		return true;
insilmaril@310
  1229
}
insilmaril@310
  1230
insilmaril@364
  1231
BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
insilmaril@0
  1232
{
insilmaril@0
  1233
	savePosInAngle();
insilmaril@406
  1234
    int i=branch.indexOf(bo1);
insilmaril@0
  1235
	int j;
insilmaril@406
  1236
	if (i <branch.size())
insilmaril@0
  1237
	{
insilmaril@406
  1238
		j = i+1;
insilmaril@0
  1239
		branch.at(i)->angle++;
insilmaril@0
  1240
		branch.at(j)->angle--;
insilmaril@411
  1241
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@364
  1242
		return branch.at(i);
insilmaril@0
  1243
	} else
insilmaril@364
  1244
		return NULL;
insilmaril@0
  1245
}
insilmaril@0
  1246
insilmaril@604
  1247
void BranchObj::sortChildren()
insilmaril@604
  1248
{
insilmaril@604
  1249
	int childCount=branch.count();
insilmaril@604
  1250
	int curChildIndex;
insilmaril@604
  1251
	bool madeChanges=false;
insilmaril@604
  1252
	do
insilmaril@604
  1253
	{
insilmaril@604
  1254
		madeChanges=false;
insilmaril@604
  1255
		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
insilmaril@604
  1256
			BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
insilmaril@604
  1257
			BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
insilmaril@604
  1258
			if(prevChild->heading->text().compare(curChild->heading->text())>0)
insilmaril@604
  1259
			{
insilmaril@604
  1260
				this->moveBranchUp(curChild);
insilmaril@604
  1261
				madeChanges=true;
insilmaril@604
  1262
			}
insilmaril@604
  1263
		}
insilmaril@604
  1264
	}while(madeChanges);
insilmaril@604
  1265
}
insilmaril@604
  1266
insilmaril@604
  1267
insilmaril@421
  1268
BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
insilmaril@83
  1269
{
insilmaril@83
  1270
	// Find current parent and 
insilmaril@83
  1271
	// remove pointer to myself there
insilmaril@94
  1272
	if (!dst) return NULL;
insilmaril@364
  1273
	BranchObj *par=(BranchObj*)parObj;
insilmaril@83
  1274
	if (par)
insilmaril@83
  1275
		par->removeBranchPtr (this);
insilmaril@83
  1276
	else
insilmaril@83
  1277
		return NULL;
insilmaril@83
  1278
insilmaril@129
  1279
	// Create new pointer to myself at dst
insilmaril@98
  1280
	if (pos<0||dst->getDepth()==0)
insilmaril@83
  1281
	{	
insilmaril@98
  1282
		// links myself as last branch at dst
insilmaril@83
  1283
		dst->addBranchPtr (this);
insilmaril@151
  1284
		updateLink();
insilmaril@83
  1285
		return this;
insilmaril@83
  1286
	} else
insilmaril@83
  1287
	{
insilmaril@83
  1288
		// inserts me at pos in parent of dst
insilmaril@83
  1289
		if (par)
insilmaril@139
  1290
		{
insilmaril@139
  1291
			BranchObj *bo=dst->insertBranchPtr (this,pos);
insilmaril@146
  1292
			bo->setDefAttr(MovedBranch);
insilmaril@151
  1293
			updateLink();
insilmaril@139
  1294
			return bo;
insilmaril@139
  1295
insilmaril@139
  1296
		} else
insilmaril@83
  1297
			return NULL;
insilmaril@83
  1298
	}	
insilmaril@83
  1299
}
insilmaril@83
  1300
insilmaril@408
  1301
void BranchObj::alignRelativeTo (QPointF ref)
insilmaril@0
  1302
{
insilmaril@408
  1303
	qreal th = bboxTotal.height();	
insilmaril@223
  1304
// TODO testing
insilmaril@223
  1305
/*
insilmaril@382
  1306
	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
insilmaril@169
  1307
	cout << "  d="<<depth<<
insilmaril@223
  1308
		"  ref="<<ref<<
insilmaril@254
  1309
//		"  bbox.topLeft="<<bboxTotal.topLeft()<<
insilmaril@223
  1310
		"  absPos="<<absPos<<
insilmaril@382
  1311
		"  relPos="<<relPos<<
insilmaril@382
  1312
		"  orient="<<orientation<<
insilmaril@254
  1313
//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
insilmaril@382
  1314
//		"  hidden="<<hidden<<
insilmaril@382
  1315
//		"  th="<<th<<
insilmaril@382
  1316
		endl;
insilmaril@394
  1317
*/
insilmaril@0
  1318
insilmaril@382
  1319
	setOrientation();
insilmaril@382
  1320
	//updateLink();
insilmaril@382
  1321
insilmaril@0
  1322
	if (depth<2)
insilmaril@364
  1323
	{
insilmaril@0
  1324
		if (depth==1)
insilmaril@382
  1325
		{
insilmaril@382
  1326
			// Position relatively, if needed
insilmaril@382
  1327
			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
insilmaril@382
  1328
insilmaril@0
  1329
			// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
  1330
			// needed for reordering the mainbranches clockwise 
insilmaril@0
  1331
			// around mapcenter 
insilmaril@408
  1332
			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@0
  1333
									(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@382
  1334
		}							
insilmaril@0
  1335
	} 
insilmaril@0
  1336
	else
insilmaril@0
  1337
    {
insilmaril@0
  1338
		// Align myself depending on orientation and parent, but
insilmaril@382
  1339
		// only if I am not a mainbranch or mapcenter itself
insilmaril@462
  1340
		LinkableMapObj::Orientation o;
insilmaril@382
  1341
		o=parObj->getOrientation();
insilmaril@0
  1342
		switch (orientation) 
insilmaril@0
  1343
		{
insilmaril@462
  1344
			case LinkableMapObj::LeftOfCenter:
insilmaril@223
  1345
				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@0
  1346
			break;
insilmaril@462
  1347
			case LinkableMapObj::RightOfCenter:	
insilmaril@223
  1348
				move (ref.x() , ref.y() + (th-bbox.height())/2  );
insilmaril@0
  1349
			break;
insilmaril@0
  1350
			default:
insilmaril@223
  1351
				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
insilmaril@0
  1352
			break;
insilmaril@0
  1353
		}		
insilmaril@0
  1354
    }		
insilmaril@0
  1355
insilmaril@0
  1356
	if (scrolled) return;
insilmaril@0
  1357
insilmaril@0
  1358
    // Set reference point for alignment of childs
insilmaril@408
  1359
    QPointF ref2;
insilmaril@462
  1360
    if (orientation==LinkableMapObj::LeftOfCenter)
insilmaril@223
  1361
		ref2.setX(bbox.topLeft().x() - linkwidth);
insilmaril@0
  1362
    else	
insilmaril@223
  1363
		ref2.setX(bbox.topRight().x() + linkwidth);
insilmaril@0
  1364
insilmaril@0
  1365
	if (depth==1)
insilmaril@0
  1366
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
  1367
	else	
insilmaril@0
  1368
		ref2.setY(ref.y() );	
insilmaril@0
  1369
insilmaril@0
  1370
    // Align the childs depending on reference point 
insilmaril@406
  1371
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1372
    {	
insilmaril@406
  1373
		if (!branch.at(i)->isHidden())
insilmaril@254
  1374
		{
insilmaril@406
  1375
			branch.at(i)->alignRelativeTo (ref2);
insilmaril@406
  1376
			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
insilmaril@254
  1377
		}
insilmaril@0
  1378
    }
insilmaril@0
  1379
}
insilmaril@0
  1380
insilmaril@0
  1381
insilmaril@0
  1382
void BranchObj::reposition()
insilmaril@0
  1383
{	
insilmaril@164
  1384
/* TODO testing only
insilmaril@0
  1385
	if (!getHeading().isEmpty())
insilmaril@382
  1386
		cout << "BO::reposition  "<<getHeading().ascii()<<endl;
insilmaril@0
  1387
	else	
insilmaril@0
  1388
		cout << "BO::reposition  ???"<<endl;
insilmaril@382
  1389
insilmaril@382
  1390
	cout << "  orient="<<orientation<<endl;
insilmaril@0
  1391
*/		
insilmaril@382
  1392
insilmaril@0
  1393
	if (depth==0)
insilmaril@0
  1394
	{
insilmaril@0
  1395
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
  1396
		// changes its height,
insilmaril@0
  1397
		// all upper LMOs have to change, too.
insilmaril@0
  1398
		calcBBoxSizeWithChilds();
insilmaril@408
  1399
		updateLink();	// This update is needed if the scene is resized 
insilmaril@333
  1400
						// due to excessive moving of a FIO
insilmaril@333
  1401
insilmaril@408
  1402
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1403
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@411
  1404
		qSort (branch.begin(),branch.end(), isAbove);
insilmaril@333
  1405
		positionBBox();	// Reposition bbox and contents
insilmaril@0
  1406
	} else
insilmaril@0
  1407
	{
insilmaril@0
  1408
		// This is only important for moving branches:
insilmaril@0
  1409
		// For editing a branch it isn't called...
insilmaril@408
  1410
	    alignRelativeTo ( QPointF (absPos.x(),
insilmaril@0
  1411
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
  1412
	}
insilmaril@0
  1413
}
insilmaril@0
  1414
insilmaril@382
  1415
void BranchObj::unsetAllRepositionRequests()
insilmaril@382
  1416
{
insilmaril@382
  1417
	repositionRequest=false;
insilmaril@406
  1418
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1419
		branch.at(i)->unsetAllRepositionRequests();
insilmaril@382
  1420
}
insilmaril@382
  1421
insilmaril@0
  1422
insilmaril@408
  1423
QRectF BranchObj::getTotalBBox()
insilmaril@0
  1424
{
insilmaril@408
  1425
	QRectF r=bbox;
insilmaril@0
  1426
insilmaril@0
  1427
	if (scrolled) return r;
insilmaril@0
  1428
insilmaril@406
  1429
	for (int i=0; i<branch.size(); ++i)
insilmaril@406
  1430
		if (!branch.at(i)->isHidden())
insilmaril@406
  1431
			r=addBBox(branch.at(i)->getTotalBBox(),r);
insilmaril@0
  1432
insilmaril@404
  1433
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@404
  1434
		if (!floatimage.at(i)->isHidden())
insilmaril@404
  1435
			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
insilmaril@0
  1436
		
insilmaril@0
  1437
	return r;
insilmaril@0
  1438
}
insilmaril@0
  1439
insilmaril@408
  1440
QRectF BranchObj::getBBoxSizeWithChilds()
insilmaril@0
  1441
{
insilmaril@0
  1442
	return bboxTotal;
insilmaril@0
  1443
}
insilmaril@0
  1444
insilmaril@0
  1445
void BranchObj::calcBBoxSizeWithChilds()
insilmaril@169
  1446
{	
insilmaril@169
  1447
	// This is initially called only from reposition and
insilmaril@0
  1448
	// and only for mapcenter. So it won't be
insilmaril@0
  1449
	// called more than once for a single user 
insilmaril@0
  1450
	// action
insilmaril@0
  1451
	
insilmaril@169
  1452
insilmaril@0
  1453
	// Calculate size of LMO including all childs (to align them later)
insilmaril@0
  1454
	bboxTotal.setX(bbox.x() );
insilmaril@0
  1455
	bboxTotal.setY(bbox.y() );
insilmaril@0
  1456
insilmaril@0
  1457
	// if branch is scrolled, ignore childs, but still consider floatimages
insilmaril@0
  1458
	if (scrolled)
insilmaril@0
  1459
	{
insilmaril@0
  1460
		bboxTotal.setWidth (bbox.width());
insilmaril@0
  1461
		bboxTotal.setHeight(bbox.height());
insilmaril@0
  1462
		return;
insilmaril@0
  1463
	}
insilmaril@0
  1464
	
insilmaril@254
  1465
	if (hidden)
insilmaril@254
  1466
	{
insilmaril@254
  1467
		bboxTotal.setWidth (0);
insilmaril@254
  1468
		bboxTotal.setHeight(0);
insilmaril@254
  1469
		if (parObj)
insilmaril@254
  1470
		{
insilmaril@254
  1471
			bboxTotal.setX (parObj->x());
insilmaril@254
  1472
			bboxTotal.setY (parObj->y());
insilmaril@254
  1473
		} else
insilmaril@254
  1474
		{
insilmaril@254
  1475
			bboxTotal.setX (bbox.x());
insilmaril@254
  1476
			bboxTotal.setY (bbox.y());
insilmaril@254
  1477
		}
insilmaril@254
  1478
		return;
insilmaril@254
  1479
	}
insilmaril@254
  1480
	
insilmaril@408
  1481
	QRectF r(0,0,0,0);
insilmaril@408
  1482
	QRectF br;
insilmaril@0
  1483
	// Now calculate recursivly
insilmaril@0
  1484
	// sum of heights 
insilmaril@0
  1485
	// maximum of widths 
insilmaril@0
  1486
	// minimum of y
insilmaril@406
  1487
	for (int i=0; i<branch.size(); ++i)
insilmaril@0
  1488
	{
insilmaril@406
  1489
		if (!branch.at(i)->isHidden())
insilmaril@254
  1490
		{
insilmaril@406
  1491
			branch.at(i)->calcBBoxSizeWithChilds();
insilmaril@406
  1492
			br=branch.at(i)->getBBoxSizeWithChilds();
insilmaril@254
  1493
			r.setWidth( max (br.width(), r.width() ));
insilmaril@254
  1494
			r.setHeight(br.height() + r.height() );
insilmaril@254
  1495
			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@254
  1496
		}
insilmaril@0
  1497
	}
insilmaril@0
  1498
	// Add myself and also
insilmaril@0
  1499
	// add width of link to sum if necessary
insilmaril@0
  1500
	if (branch.isEmpty())
insilmaril@0
  1501
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
  1502
	else	
insilmaril@0
  1503
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@169
  1504
	
insilmaril@169
  1505
	bboxTotal.setHeight(max (r.height(),  bbox.height()));
insilmaril@0
  1506
}
insilmaril@0
  1507
insilmaril@0
  1508
void BranchObj::select()
insilmaril@0
  1509
{
insilmaril@440
  1510
	// update NoteEditor
insilmaril@160
  1511
	textEditor->setText(note.getNote() );
insilmaril@160
  1512
	QString fnh=note.getFilenameHint();
insilmaril@160
  1513
	if (fnh!="")
insilmaril@160
  1514
		textEditor->setFilenameHint(note.getFilenameHint() );
insilmaril@160
  1515
	else	
insilmaril@160
  1516
		textEditor->setFilenameHint(getHeading() );
insilmaril@160
  1517
	textEditor->setFontHint (note.getFontHint() );
insilmaril@417
  1518
	isNoteInEditor=true;
insilmaril@160
  1519
insilmaril@440
  1520
	// set selected and visible
insilmaril@0
  1521
    LinkableMapObj::select();
insilmaril@440
  1522
insilmaril@0
  1523
	// Tell parent that I am selected now:
insilmaril@0
  1524
	BranchObj* po=(BranchObj*)(parObj);
insilmaril@0
  1525
    if (po)	// TODO	    Try to get rid of this cast...
insilmaril@0
  1526
        po->setLastSelectedBranch(this);
insilmaril@0
  1527
		
insilmaril@0
  1528
	// temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1529
	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
insilmaril@0
  1530
insilmaril@0
  1531
	// Show URL and link in statusbar
insilmaril@0
  1532
	QString status;
insilmaril@0
  1533
	if (!url.isEmpty()) status+="URL: "+url+"  ";
insilmaril@0
  1534
	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
insilmaril@0
  1535
	if (!status.isEmpty()) mainWindow->statusMessage (status);
insilmaril@0
  1536
insilmaril@0
  1537
	// Update Toolbar
insilmaril@364
  1538
	updateFlagsToolbar();
insilmaril@0
  1539
insilmaril@406
  1540
	// Update actions
insilmaril@0
  1541
	mapEditor->updateActions();
insilmaril@0
  1542
}
insilmaril@0
  1543
insilmaril@0
  1544
void BranchObj::unselect()
insilmaril@0
  1545
{
insilmaril@0
  1546
	LinkableMapObj::unselect();
insilmaril@0
  1547
	// Delete any messages like vymLink in StatusBar
insilmaril@0
  1548
	mainWindow->statusMessage ("");
insilmaril@0
  1549
insilmaril@417
  1550
	// Save current note
insilmaril@417
  1551
	if (isNoteInEditor) getNoteFromTextEditor();
insilmaril@417
  1552
	isNoteInEditor=false;
insilmaril@0
  1553
insilmaril@0
  1554
	// reset temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1555
	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
insilmaril@0
  1556
insilmaril@0
  1557
	// Erase content of editor 
insilmaril@0
  1558
	textEditor->setInactive();
insilmaril@0
  1559
insilmaril@0
  1560
	// unselect all buttons in toolbar
insilmaril@103
  1561
	standardFlagsDefault->updateToolbar();
insilmaril@0
  1562
}
insilmaril@0
  1563
insilmaril@0
  1564
QString BranchObj::getSelectString()
insilmaril@0
  1565
{
insilmaril@0
  1566
	QString s;
insilmaril@0
  1567
	if (parObj)
insilmaril@0
  1568
	{
insilmaril@95
  1569
		if (depth==1)
insilmaril@0
  1570
			s= "bo:" + QString("%1").arg(getNum());
insilmaril@0
  1571
		else	
insilmaril@0
  1572
			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
insilmaril@0
  1573
	} else
insilmaril@0
  1574
		s="mc:";
insilmaril@0
  1575
	return s;
insilmaril@0
  1576
}
insilmaril@0
  1577
insilmaril@462
  1578
insilmaril@462
  1579
void BranchObj::animate()
insilmaril@462
  1580
{
insilmaril@462
  1581
	//relPos.animate();
insilmaril@462
  1582
	cout << "BO::animate  x,y="<<relPos.x()<<","<<relPos.y()<<endl;
insilmaril@462
  1583
}
insilmaril@462
  1584