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