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