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