branchobj.cpp
author insilmaril
Sun, 30 Jan 2005 12:59:10 +0000
changeset 82 920e6ed5889b
parent 0 7a96bd401351
child 2 608f976aa7bb
child 40 394b2f297e1d
child 83 e90f5bef70c8
permissions -rw-r--r--
Initial revision
insilmaril@0
     1
#include "branchobj.h"
insilmaril@0
     2
#include "texteditor.h"
insilmaril@0
     3
#include "mapeditor.h"
insilmaril@0
     4
#include "mainwindow.h"
insilmaril@0
     5
insilmaril@0
     6
extern TextEditor *textEditor;
insilmaril@0
     7
extern Main *mainWindow;
insilmaril@0
     8
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
     9
extern QAction *actionEditOpenURL;
insilmaril@0
    10
insilmaril@0
    11
insilmaril@0
    12
/////////////////////////////////////////////////////////////////
insilmaril@0
    13
// BranchObj
insilmaril@0
    14
/////////////////////////////////////////////////////////////////
insilmaril@0
    15
insilmaril@0
    16
BranchObj* BranchObj::itLast=NULL;
insilmaril@0
    17
insilmaril@0
    18
insilmaril@0
    19
BranchObj::BranchObj () :OrnamentedObj()
insilmaril@0
    20
{
insilmaril@0
    21
//    cout << "Const BranchObj ()\n";
insilmaril@0
    22
    setParObj (this);	
insilmaril@0
    23
    init();
insilmaril@0
    24
    depth=-1;
insilmaril@0
    25
}
insilmaril@0
    26
insilmaril@0
    27
BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
insilmaril@0
    28
{
insilmaril@0
    29
//    cout << "Const BranchObj (c)  called from MapCenterObj (c)\n";
insilmaril@0
    30
    canvas=c;
insilmaril@0
    31
}
insilmaril@0
    32
insilmaril@0
    33
BranchObj::BranchObj (QCanvas* c, LinkableMapObj* p):OrnamentedObj (c)
insilmaril@0
    34
{
insilmaril@0
    35
//    cout << "Const BranchObj (c,p)\n";
insilmaril@0
    36
    canvas=c;
insilmaril@0
    37
    setParObj (p);	
insilmaril@0
    38
    depth=p->getDepth()+1;
insilmaril@0
    39
	if (depth==1)
insilmaril@0
    40
		// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
    41
		// needed for reordering the mainbranches clockwise 
insilmaril@0
    42
		// around mapcenter 
insilmaril@0
    43
		angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@0
    44
								(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@0
    45
    init();
insilmaril@0
    46
}
insilmaril@0
    47
insilmaril@0
    48
BranchObj::~BranchObj ()
insilmaril@0
    49
{
insilmaril@0
    50
    //cout << "Destr BranchObj\n";
insilmaril@0
    51
	// Check, if this branch was the last child to be deleted
insilmaril@0
    52
	// If so, unset the scrolled flags
insilmaril@0
    53
insilmaril@0
    54
	BranchObj *po=(BranchObj*)(parObj);
insilmaril@0
    55
	if (po)
insilmaril@0
    56
	{
insilmaril@0
    57
		BranchObj *bo=((BranchObj*)(parObj))->getLastBranch();
insilmaril@0
    58
		if (!bo) po->unScroll();
insilmaril@0
    59
	}
insilmaril@0
    60
}
insilmaril@0
    61
insilmaril@0
    62
bool BranchObj::operator< ( const BranchObj & other )
insilmaril@0
    63
{
insilmaril@0
    64
    return  angle < other.angle;
insilmaril@0
    65
}
insilmaril@0
    66
insilmaril@0
    67
bool BranchObj::operator== ( const BranchObj & other )
insilmaril@0
    68
{
insilmaril@0
    69
    return angle == other.angle;
insilmaril@0
    70
}
insilmaril@0
    71
insilmaril@0
    72
int BranchObjPtrList::compareItems ( QPtrCollection::Item i, QPtrCollection::Item j)
insilmaril@0
    73
{
insilmaril@0
    74
	// Make sure PtrList::find works
insilmaril@0
    75
	if (i==j) return 0;
insilmaril@0
    76
insilmaril@0
    77
	if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
insilmaril@0
    78
		return 1;
insilmaril@0
    79
	else
insilmaril@0
    80
		return -1;
insilmaril@0
    81
}
insilmaril@0
    82
insilmaril@0
    83
void BranchObj::init () 
insilmaril@0
    84
{
insilmaril@0
    85
    branch.setAutoDelete (true);
insilmaril@0
    86
    floatimage.setAutoDelete (true);
insilmaril@0
    87
insilmaril@0
    88
	absPos=getRandPos();
insilmaril@0
    89
	absPos+=parObj->getChildPos();
insilmaril@0
    90
insilmaril@0
    91
    // TODO This should be done in TextObj later
insilmaril@0
    92
    QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
insilmaril@0
    93
//    font.setPointSize(12);
insilmaril@0
    94
   heading->setFont(font );
insilmaril@0
    95
//    heading->setText(QObject::tr("new branch"));
insilmaril@0
    96
insilmaril@0
    97
    lastSelectedBranch=-1;
insilmaril@0
    98
insilmaril@0
    99
    setChildObj(this);
insilmaril@0
   100
insilmaril@0
   101
	scrolled=false;
insilmaril@0
   102
	tmpUnscrolled=false;
insilmaril@0
   103
insilmaril@0
   104
	url="";
insilmaril@0
   105
	vymLink="";
insilmaril@0
   106
}
insilmaril@0
   107
insilmaril@0
   108
void BranchObj::copy (BranchObj* other)
insilmaril@0
   109
{
insilmaril@0
   110
    OrnamentedObj::copy(other);
insilmaril@0
   111
insilmaril@0
   112
	branch.clear();
insilmaril@0
   113
    BranchObj* b;
insilmaril@0
   114
    for (b=other->branch.first(); b;b=other->branch.next() ) 
insilmaril@0
   115
		// Make deep copy of b
insilmaril@0
   116
		// Because addBranch again calls copy for the childs,
insilmaril@0
   117
		// Those will get a deep copy, too
insilmaril@0
   118
		addBranch(b);	
insilmaril@0
   119
insilmaril@0
   120
	FloatImageObj *fi;
insilmaril@0
   121
	for (fi=other->floatimage.first(); fi;fi=other->floatimage.next() )
insilmaril@0
   122
		addFloatImage (fi);
insilmaril@0
   123
insilmaril@0
   124
	scrolled=other->scrolled;
insilmaril@0
   125
	tmpUnscrolled=other->tmpUnscrolled;
insilmaril@0
   126
	setVisibility (other->visible);
insilmaril@0
   127
insilmaril@0
   128
	url=other->url;
insilmaril@0
   129
	vymLink=other->vymLink;
insilmaril@0
   130
insilmaril@0
   131
	angle=other->angle;
insilmaril@0
   132
insilmaril@0
   133
    positionBBox();
insilmaril@0
   134
}
insilmaril@0
   135
insilmaril@0
   136
void BranchObj::clear() 
insilmaril@0
   137
{
insilmaril@0
   138
	branch.clear();
insilmaril@0
   139
	floatimage.clear();
insilmaril@0
   140
}
insilmaril@0
   141
insilmaril@0
   142
int BranchObj::getNum()
insilmaril@0
   143
{
insilmaril@0
   144
	if (parObj)
insilmaril@0
   145
		return ((BranchObj*)(parObj))->getNum ((BranchObj*)(this));
insilmaril@0
   146
	else
insilmaril@0
   147
		return 0;
insilmaril@0
   148
}
insilmaril@0
   149
insilmaril@0
   150
int BranchObj::getNum(BranchObj *bo)
insilmaril@0
   151
{
insilmaril@0
   152
	return branch.findRef (bo);
insilmaril@0
   153
}
insilmaril@0
   154
insilmaril@0
   155
int BranchObj::getFloatImageNum(FloatImageObj *fio)
insilmaril@0
   156
{
insilmaril@0
   157
	return floatimage.findRef (fio);
insilmaril@0
   158
}
insilmaril@0
   159
insilmaril@0
   160
int BranchObj::countBranches()
insilmaril@0
   161
{
insilmaril@0
   162
	return branch.count();
insilmaril@0
   163
}
insilmaril@0
   164
insilmaril@0
   165
int BranchObj::countFloatImages()
insilmaril@0
   166
{
insilmaril@0
   167
	return floatimage.count();
insilmaril@0
   168
}
insilmaril@0
   169
insilmaril@0
   170
void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPoint m, int off)
insilmaril@0
   171
{
insilmaril@0
   172
	// Temporary link to lmo
insilmaril@0
   173
	// m is position of mouse pointer 
insilmaril@0
   174
	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
insilmaril@0
   175
insilmaril@0
   176
insilmaril@0
   177
	BranchObj* o=(BranchObj*)(lmo);
insilmaril@0
   178
	if (!parObjTmpBuf) 
insilmaril@0
   179
		parObjTmpBuf=parObj;
insilmaril@0
   180
insilmaril@0
   181
	// ignore mapcenter and mainbranch
insilmaril@0
   182
	if (lmo->getDepth()<2) off=0;
insilmaril@0
   183
	if (off==0)
insilmaril@0
   184
	{
insilmaril@0
   185
		link2ParPos=false;
insilmaril@0
   186
		parObj=o;
insilmaril@0
   187
	}	
insilmaril@0
   188
	else
insilmaril@0
   189
	{	
insilmaril@0
   190
		link2ParPos=true;
insilmaril@0
   191
		if (off>0)
insilmaril@0
   192
			parObj=o->getParObj();
insilmaril@0
   193
		else	
insilmaril@0
   194
			parObj=o->getParObj();
insilmaril@0
   195
		parObj=o;
insilmaril@0
   196
	}		
insilmaril@0
   197
insilmaril@0
   198
	depth=parObj->getDepth()+1;
insilmaril@0
   199
insilmaril@0
   200
	// setLinkStyle calls updateLink, only set it once
insilmaril@0
   201
	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
insilmaril@0
   202
insilmaril@0
   203
	// Move temporary to new position at destination
insilmaril@0
   204
	// Usually the positioning would be done by reposition(),
insilmaril@0
   205
	// but then also the destination branch would "Jump" around...
insilmaril@0
   206
	// Better just do it approximately
insilmaril@0
   207
	if (depth==1)
insilmaril@0
   208
	{	// new parent is the mapcenter itself
insilmaril@0
   209
insilmaril@0
   210
		QPoint p= normalise ( QPoint (m.x() - o->getChildPos().x(),
insilmaril@0
   211
									  m.y() - o->getChildPos().y() ));
insilmaril@0
   212
		if (p.x()<0) p.setX( p.x()-bbox.width() );
insilmaril@0
   213
		move2RelPos (p);
insilmaril@0
   214
	} else
insilmaril@0
   215
	{	
insilmaril@0
   216
		int y;
insilmaril@0
   217
		if (off==0)
insilmaril@0
   218
		{
insilmaril@0
   219
			// new parent is just a branch, link to it
insilmaril@0
   220
			QRect t=o->getBBoxSizeWithChilds();
insilmaril@0
   221
			if (o->getLastBranch())
insilmaril@0
   222
				y=t.y() + t.height() ;
insilmaril@0
   223
			else
insilmaril@0
   224
				y=t.y();
insilmaril@0
   225
insilmaril@0
   226
		} else
insilmaril@0
   227
		{
insilmaril@0
   228
			if (off<0)
insilmaril@0
   229
				// we want to link above lmo
insilmaril@0
   230
				y=o->y() - height() + 5;
insilmaril@0
   231
			else	
insilmaril@0
   232
				// we want to link below lmo
insilmaril@0
   233
				// Bottom of sel should be 5 pixels above
insilmaril@0
   234
				// the bottom of the branch _below_ the target:
insilmaril@0
   235
				// Don't try to find that branch, guess 12 pixels
insilmaril@0
   236
				y=o->getChildPos().y()  -height() + 12; 
insilmaril@0
   237
		}	
insilmaril@0
   238
		if (o->getOrientation()==OrientLeftOfCenter)
insilmaril@0
   239
			move ( o->getChildPos().x() - linkwidth, y );
insilmaril@0
   240
		else	
insilmaril@0
   241
			move (o->getChildPos().x() + linkwidth, y );
insilmaril@0
   242
	}	
insilmaril@0
   243
insilmaril@0
   244
	// updateLink is called implicitly in move
insilmaril@0
   245
	reposition();	// FIXME shouldn't be this a request?
insilmaril@0
   246
}
insilmaril@0
   247
insilmaril@0
   248
void BranchObj::unsetParObjTmp()
insilmaril@0
   249
{
insilmaril@0
   250
	if (parObjTmpBuf) 
insilmaril@0
   251
	{
insilmaril@0
   252
		link2ParPos=false;
insilmaril@0
   253
		parObj=parObjTmpBuf;
insilmaril@0
   254
		parObjTmpBuf=NULL;
insilmaril@0
   255
		depth=parObj->getDepth()+1;
insilmaril@0
   256
		setLinkStyle (getDefLinkStyle() );
insilmaril@0
   257
	}		
insilmaril@0
   258
}
insilmaril@0
   259
insilmaril@0
   260
void BranchObj::unScroll()
insilmaril@0
   261
{
insilmaril@0
   262
	if (tmpUnscrolled) resetTmpUnscroll();
insilmaril@0
   263
	if (scrolled) toggleScroll();
insilmaril@0
   264
}
insilmaril@0
   265
insilmaril@0
   266
void BranchObj::toggleScroll()
insilmaril@0
   267
{
insilmaril@0
   268
	BranchObj *bo;
insilmaril@0
   269
	if (scrolled)
insilmaril@0
   270
	{
insilmaril@0
   271
		scrolled=false;
insilmaril@0
   272
		systemFlags->deactivate("scrolledright");
insilmaril@0
   273
		for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@0
   274
		{
insilmaril@0
   275
			bo->setVisibility(true);
insilmaril@0
   276
		}
insilmaril@0
   277
	} else
insilmaril@0
   278
	{
insilmaril@0
   279
		scrolled=true;
insilmaril@0
   280
		systemFlags->activate("scrolledright");
insilmaril@0
   281
		for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@0
   282
		{
insilmaril@0
   283
			bo->setVisibility(false);
insilmaril@0
   284
		}
insilmaril@0
   285
	}
insilmaril@0
   286
	calcBBoxSize();
insilmaril@0
   287
	positionBBox();	
insilmaril@0
   288
	move (absPos.x(), absPos.y() );
insilmaril@0
   289
	forceReposition();
insilmaril@0
   290
}
insilmaril@0
   291
insilmaril@0
   292
bool BranchObj::isScrolled()
insilmaril@0
   293
{
insilmaril@0
   294
	return scrolled;
insilmaril@0
   295
}
insilmaril@0
   296
insilmaril@0
   297
bool BranchObj::hasScrolledParent(BranchObj *start)
insilmaril@0
   298
{
insilmaril@0
   299
	// Calls parents recursivly to
insilmaril@0
   300
	// find out, if we are scrolled at all.
insilmaril@0
   301
	// But ignore myself, just look at parents.
insilmaril@0
   302
insilmaril@0
   303
	if (this !=start && scrolled) return true;
insilmaril@0
   304
insilmaril@0
   305
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   306
	if (bo) 
insilmaril@0
   307
		return bo->hasScrolledParent(start);
insilmaril@0
   308
	else
insilmaril@0
   309
		return false;
insilmaril@0
   310
}
insilmaril@0
   311
insilmaril@0
   312
void BranchObj::tmpUnscroll()
insilmaril@0
   313
{
insilmaril@0
   314
	// Unscroll parent (recursivly)
insilmaril@0
   315
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   316
	if (bo) bo->tmpUnscroll();
insilmaril@0
   317
		
insilmaril@0
   318
	// Unscroll myself
insilmaril@0
   319
	if (scrolled)
insilmaril@0
   320
	{
insilmaril@0
   321
		tmpUnscrolled=true;
insilmaril@0
   322
		systemFlags->activate("tmpUnscrolledright");
insilmaril@0
   323
		toggleScroll();
insilmaril@0
   324
	}	
insilmaril@0
   325
}
insilmaril@0
   326
insilmaril@0
   327
void BranchObj::resetTmpUnscroll()
insilmaril@0
   328
{
insilmaril@0
   329
	// Unscroll parent (recursivly)
insilmaril@0
   330
	BranchObj* bo=(BranchObj*)(parObj);
insilmaril@0
   331
	if (bo)
insilmaril@0
   332
		bo->resetTmpUnscroll();
insilmaril@0
   333
		
insilmaril@0
   334
	// Unscroll myself
insilmaril@0
   335
	if (tmpUnscrolled)
insilmaril@0
   336
	{
insilmaril@0
   337
		tmpUnscrolled=false;
insilmaril@0
   338
		systemFlags->deactivate("tmpUnscrolledright");
insilmaril@0
   339
		toggleScroll();
insilmaril@0
   340
	}	
insilmaril@0
   341
}
insilmaril@0
   342
insilmaril@0
   343
void BranchObj::setVisibility(bool v, int toDepth)
insilmaril@0
   344
{
insilmaril@0
   345
    if (depth <= toDepth)
insilmaril@0
   346
    {
insilmaril@0
   347
		frame->setVisibility(v);
insilmaril@0
   348
		heading->setVisibility(v);
insilmaril@0
   349
		systemFlags->setVisibility(v);
insilmaril@0
   350
		standardFlags->setVisibility(v);
insilmaril@0
   351
		LinkableMapObj::setVisibility (v);
insilmaril@0
   352
		
insilmaril@0
   353
		if (!scrolled && (depth < toDepth))
insilmaril@0
   354
		{
insilmaril@0
   355
			// Now go recursivly through all childs
insilmaril@0
   356
			BranchObj* b;
insilmaril@0
   357
			for (b=branch.first(); b;b=branch.next() ) 
insilmaril@0
   358
				b->setVisibility (v,toDepth);	
insilmaril@0
   359
			FloatImageObj *fio;
insilmaril@0
   360
			for (fio=floatimage.first(); fio; fio=floatimage.next())
insilmaril@0
   361
				fio->setVisibility (v);
insilmaril@0
   362
		}
insilmaril@0
   363
    } // depth <= toDepth	
insilmaril@0
   364
	move (absPos.x(), absPos.y() );
insilmaril@0
   365
	requestReposition();
insilmaril@0
   366
}	
insilmaril@0
   367
insilmaril@0
   368
void BranchObj::setVisibility(bool v)
insilmaril@0
   369
{
insilmaril@0
   370
    setVisibility (v,MAX_DEPTH);
insilmaril@0
   371
}
insilmaril@0
   372
insilmaril@0
   373
insilmaril@0
   374
void BranchObj::setLinkColor ()
insilmaril@0
   375
{
insilmaril@0
   376
	// Overloaded from LinkableMapObj
insilmaril@0
   377
	// BranchObj can use color of heading
insilmaril@0
   378
insilmaril@0
   379
	if (mapEditor->getLinkColorHint()==HeadingColor)
insilmaril@0
   380
		LinkableMapObj::setLinkColor (heading->getColor() );
insilmaril@0
   381
	else	
insilmaril@0
   382
		LinkableMapObj::setLinkColor ();
insilmaril@0
   383
}
insilmaril@0
   384
insilmaril@0
   385
void BranchObj::setColor (QColor col, bool colorChilds)
insilmaril@0
   386
{
insilmaril@0
   387
    heading->setColor(col);
insilmaril@0
   388
	setLinkColor();
insilmaril@0
   389
    if (colorChilds) 
insilmaril@0
   390
    {
insilmaril@0
   391
		BranchObj *bo;
insilmaril@0
   392
		for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@0
   393
			bo->setColor(col,colorChilds);
insilmaril@0
   394
    }	
insilmaril@0
   395
}
insilmaril@0
   396
insilmaril@0
   397
insilmaril@0
   398
BranchObj* BranchObj::first()
insilmaril@0
   399
{
insilmaril@0
   400
	itLast=NULL;	
insilmaril@0
   401
	return this; 
insilmaril@0
   402
}
insilmaril@0
   403
	
insilmaril@0
   404
BranchObj* BranchObj::next()
insilmaril@0
   405
{
insilmaril@0
   406
	BranchObj *lmo;
insilmaril@0
   407
	BranchObj *bo=branch.first();
insilmaril@0
   408
	BranchObj *po=(BranchObj*)(parObj);
insilmaril@0
   409
insilmaril@0
   410
	if (!itLast)
insilmaril@0
   411
	{	// We are just beginning at the mapCenter
insilmaril@0
   412
		if (bo) 
insilmaril@0
   413
		{
insilmaril@0
   414
			itLast=this;
insilmaril@0
   415
			return bo;
insilmaril@0
   416
		}	
insilmaril@0
   417
		else
insilmaril@0
   418
		{
insilmaril@0
   419
			itLast=NULL;
insilmaril@0
   420
			return NULL;
insilmaril@0
   421
		}	
insilmaril@0
   422
	}
insilmaril@0
   423
insilmaril@0
   424
	if (itLast==parObj)
insilmaril@0
   425
	{	// We come from above
insilmaril@0
   426
		if (bo)
insilmaril@0
   427
		{
insilmaril@0
   428
			// there are childs, go there
insilmaril@0
   429
			itLast=this;
insilmaril@0
   430
			return bo;
insilmaril@0
   431
		}	
insilmaril@0
   432
		else
insilmaril@0
   433
		{	// no childs, try to go up again
insilmaril@0
   434
			if (po)
insilmaril@0
   435
			{
insilmaril@0
   436
				// go up
insilmaril@0
   437
				itLast=this;
insilmaril@0
   438
				lmo=po->next();
insilmaril@0
   439
				itLast=this;
insilmaril@0
   440
				return lmo;
insilmaril@0
   441
insilmaril@0
   442
			}	
insilmaril@0
   443
			else
insilmaril@0
   444
			{
insilmaril@0
   445
				// can't go up, I am mapCenter
insilmaril@0
   446
				itLast=NULL;
insilmaril@0
   447
				return NULL;
insilmaril@0
   448
			}	
insilmaril@0
   449
		}
insilmaril@0
   450
	}
insilmaril@0
   451
insilmaril@0
   452
	// Try to find last child, we came from, in my own childs
insilmaril@0
   453
	bool searching=true;
insilmaril@0
   454
	while (bo && searching)
insilmaril@0
   455
	{
insilmaril@0
   456
		if (itLast==bo) searching=false;
insilmaril@0
   457
		bo=branch.next();
insilmaril@0
   458
	}
insilmaril@0
   459
	if (!searching)
insilmaril@0
   460
	{	// found lastLMO in my childs
insilmaril@0
   461
		if (bo)
insilmaril@0
   462
		{
insilmaril@0
   463
			// found a brother of lastLMO 
insilmaril@0
   464
			itLast=this;
insilmaril@0
   465
			return bo;
insilmaril@0
   466
		}	
insilmaril@0
   467
		else
insilmaril@0
   468
		{
insilmaril@0
   469
			if (po)
insilmaril@0
   470
			{
insilmaril@0
   471
				// go up
insilmaril@0
   472
				itLast=this;
insilmaril@0
   473
				lmo=po->next();
insilmaril@0
   474
				itLast=this;
insilmaril@0
   475
				return lmo;
insilmaril@0
   476
			}
insilmaril@0
   477
			else
insilmaril@0
   478
			{
insilmaril@0
   479
				// can't go up, I am mapCenter
insilmaril@0
   480
				itLast=NULL;
insilmaril@0
   481
				return NULL;
insilmaril@0
   482
			}	
insilmaril@0
   483
		}
insilmaril@0
   484
	}
insilmaril@0
   485
insilmaril@0
   486
	// couldn't find last child, it must be a nephew of mine
insilmaril@0
   487
	bo=branch.first();
insilmaril@0
   488
	if (bo)
insilmaril@0
   489
	{
insilmaril@0
   490
		// proceed with my first child
insilmaril@0
   491
		itLast=this;	
insilmaril@0
   492
		return bo;
insilmaril@0
   493
	}	
insilmaril@0
   494
	else
insilmaril@0
   495
	{
insilmaril@0
   496
		// or go back to my parents
insilmaril@0
   497
		if (po)
insilmaril@0
   498
		{
insilmaril@0
   499
			// go up
insilmaril@0
   500
			itLast=this;
insilmaril@0
   501
			lmo=po->next();
insilmaril@0
   502
			itLast=this;
insilmaril@0
   503
			return lmo;
insilmaril@0
   504
		}	
insilmaril@0
   505
		else
insilmaril@0
   506
		{
insilmaril@0
   507
			// can't go up, I am mapCenter
insilmaril@0
   508
			itLast=NULL;
insilmaril@0
   509
			return NULL;
insilmaril@0
   510
		}	
insilmaril@0
   511
	}	
insilmaril@0
   512
}
insilmaril@0
   513
insilmaril@0
   514
BranchObj* BranchObj::getLastIterator()
insilmaril@0
   515
{
insilmaril@0
   516
	return itLast;
insilmaril@0
   517
}
insilmaril@0
   518
insilmaril@0
   519
void BranchObj::setLastIterator(BranchObj* it)
insilmaril@0
   520
{
insilmaril@0
   521
	itLast=it;
insilmaril@0
   522
}
insilmaril@0
   523
insilmaril@0
   524
insilmaril@0
   525
void BranchObj::move (double x, double y)
insilmaril@0
   526
{
insilmaril@0
   527
	OrnamentedObj::move (x,y);
insilmaril@0
   528
    positionBBox();
insilmaril@0
   529
}
insilmaril@0
   530
insilmaril@0
   531
void BranchObj::move (QPoint p)
insilmaril@0
   532
{
insilmaril@0
   533
	move (p.x(), p.y());
insilmaril@0
   534
}
insilmaril@0
   535
insilmaril@0
   536
void BranchObj::moveBy (double x, double y)
insilmaril@0
   537
{
insilmaril@0
   538
	OrnamentedObj::moveBy (x,y);
insilmaril@0
   539
    positionBBox();
insilmaril@0
   540
    BranchObj* b;
insilmaril@0
   541
    for (b=branch.first(); b;b=branch.next() ) 
insilmaril@0
   542
		b->moveBy (x,y);
insilmaril@0
   543
}
insilmaril@0
   544
insilmaril@0
   545
void BranchObj::moveBy (QPoint p)
insilmaril@0
   546
{
insilmaril@0
   547
	moveBy (p.x(), p.y());
insilmaril@0
   548
}
insilmaril@0
   549
insilmaril@0
   550
insilmaril@0
   551
void BranchObj::positionBBox()
insilmaril@0
   552
{
insilmaril@0
   553
insilmaril@0
   554
    heading->positionBBox();
insilmaril@0
   555
	systemFlags->positionBBox();
insilmaril@0
   556
	standardFlags->positionBBox();
insilmaril@0
   557
	// It seems that setting x,y also affects width,height
insilmaril@0
   558
	int w_old=bbox.width();
insilmaril@0
   559
	int h_old=bbox.height();
insilmaril@0
   560
    bbox.setX (absPos.x() );
insilmaril@0
   561
	bbox.setY (absPos.y() );
insilmaril@0
   562
	bbox.setWidth(w_old);
insilmaril@0
   563
	bbox.setHeight(h_old);
insilmaril@0
   564
insilmaril@0
   565
insilmaril@0
   566
	setSelBox();
insilmaril@0
   567
insilmaril@0
   568
	// set the frame
insilmaril@0
   569
	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@0
   570
}
insilmaril@0
   571
insilmaril@0
   572
void BranchObj::calcBBoxSize()
insilmaril@0
   573
{
insilmaril@0
   574
    QSize heading_r=heading->getSize();
insilmaril@0
   575
    int heading_w=static_cast <int> (heading_r.width() );
insilmaril@0
   576
    int heading_h=static_cast <int> (heading_r.height() );
insilmaril@0
   577
    QSize sysflags_r=systemFlags->getSize();
insilmaril@0
   578
	int sysflags_h=sysflags_r.height();
insilmaril@0
   579
	int sysflags_w=sysflags_r.width();
insilmaril@0
   580
    QSize stanflags_r=standardFlags->getSize();
insilmaril@0
   581
	int stanflags_h=stanflags_r.height();
insilmaril@0
   582
	int stanflags_w=stanflags_r.width();
insilmaril@0
   583
    int w;
insilmaril@0
   584
    int h;
insilmaril@0
   585
insilmaril@0
   586
	// set width to sum of all widths
insilmaril@0
   587
	w=heading_w + sysflags_w + stanflags_w;
insilmaril@0
   588
	// set height to maximum needed height
insilmaril@0
   589
	h=max (sysflags_h,stanflags_h);
insilmaril@0
   590
	h=max (h,heading_h);
insilmaril@0
   591
insilmaril@0
   592
    w+=frame->getBorder();
insilmaril@0
   593
    h+=frame->getBorder();
insilmaril@0
   594
    bbox.setSize (QSize (w,h));
insilmaril@0
   595
}
insilmaril@0
   596
insilmaril@0
   597
LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
insilmaril@0
   598
{
insilmaril@0
   599
	// Search branches
insilmaril@0
   600
    BranchObj *b;
insilmaril@0
   601
    LinkableMapObj *lmo;
insilmaril@0
   602
    for (b=branch.first(); b; b=branch.next() )
insilmaril@0
   603
    {	
insilmaril@0
   604
		lmo=b->findMapObj(p, excludeLMO);
insilmaril@0
   605
		if (lmo != NULL) return lmo;
insilmaril@0
   606
    }
insilmaril@0
   607
	
insilmaril@0
   608
	// Search myself
insilmaril@0
   609
    if (inBBox (p) && (this != excludeLMO) && isVisibleObj() ) 
insilmaril@0
   610
		return this;
insilmaril@0
   611
insilmaril@0
   612
	// Search float images
insilmaril@0
   613
	FloatImageObj *foi;
insilmaril@0
   614
    for (foi=floatimage.first(); foi; foi=floatimage.next() )
insilmaril@0
   615
		if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
insilmaril@0
   616
insilmaril@0
   617
    return NULL;
insilmaril@0
   618
}
insilmaril@0
   619
insilmaril@0
   620
void BranchObj::setHeading(QString s)
insilmaril@0
   621
{
insilmaril@0
   622
    // Adjusting font size
insilmaril@0
   623
    QFont font=heading->getFont();
insilmaril@0
   624
	if (depth==0)
insilmaril@0
   625
		font.setPointSize(16);
insilmaril@0
   626
	else	
insilmaril@0
   627
		if (depth>1) 
insilmaril@0
   628
			font.setPointSize(10);
insilmaril@0
   629
		else
insilmaril@0
   630
			font.setPointSize(12);
insilmaril@0
   631
    heading->setFont(font);
insilmaril@0
   632
    heading->setText(s);	// set new heading
insilmaril@0
   633
	calcBBoxSize();			// recalculate bbox
insilmaril@0
   634
    positionBBox();			// rearrange contents
insilmaril@0
   635
	requestReposition();
insilmaril@0
   636
}
insilmaril@0
   637
insilmaril@0
   638
void BranchObj::setURL(QString s)
insilmaril@0
   639
{
insilmaril@0
   640
	url=s;
insilmaril@0
   641
	if (!url.isEmpty())
insilmaril@0
   642
		systemFlags->activate("url");
insilmaril@0
   643
	else	
insilmaril@0
   644
		systemFlags->deactivate("url");
insilmaril@0
   645
	calcBBoxSize();			// recalculate bbox
insilmaril@0
   646
    positionBBox();			// rearrange contents
insilmaril@0
   647
	forceReposition();
insilmaril@0
   648
}
insilmaril@0
   649
insilmaril@0
   650
QString BranchObj::getURL()
insilmaril@0
   651
{
insilmaril@0
   652
	return url;
insilmaril@0
   653
}
insilmaril@0
   654
insilmaril@0
   655
void BranchObj::setVymLink(QString s)
insilmaril@0
   656
{
insilmaril@0
   657
	if (!s.isEmpty())
insilmaril@0
   658
	{
insilmaril@0
   659
		// We need the relative (from loading) 
insilmaril@0
   660
		// or absolute path (from User event)
insilmaril@0
   661
		// and build the absolute path.
insilmaril@0
   662
		// Note: If we have relative, use path of
insilmaril@0
   663
		// current map to build absolute path
insilmaril@0
   664
		QDir d(s);
insilmaril@0
   665
		if (!d.path().startsWith ("/"))
insilmaril@0
   666
		{
insilmaril@0
   667
			QString p=mapEditor->getDestPath();
insilmaril@0
   668
			int i=p.findRev("/",-1);
insilmaril@0
   669
			d.setPath(p.left(i)+"/"+s);
insilmaril@0
   670
			d.convertToAbs();
insilmaril@0
   671
		}
insilmaril@0
   672
		vymLink=d.path();
insilmaril@0
   673
		systemFlags->activate("vymLink");
insilmaril@0
   674
	}	
insilmaril@0
   675
	else	
insilmaril@0
   676
	{
insilmaril@0
   677
		systemFlags->deactivate("vymLink");
insilmaril@0
   678
		vymLink="";
insilmaril@0
   679
	}	
insilmaril@0
   680
	calcBBoxSize();			// recalculate bbox
insilmaril@0
   681
    positionBBox();			// rearrange contents
insilmaril@0
   682
	forceReposition();
insilmaril@0
   683
}
insilmaril@0
   684
insilmaril@0
   685
QString BranchObj::getVymLink()
insilmaril@0
   686
{
insilmaril@0
   687
	return vymLink;
insilmaril@0
   688
}
insilmaril@0
   689
insilmaril@0
   690
QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint& offset)
insilmaril@0
   691
{
insilmaril@0
   692
    QString s,a;
insilmaril@0
   693
	QString scrolledAttr;
insilmaril@0
   694
	if (scrolled) 
insilmaril@0
   695
		scrolledAttr=attribut ("scrolled","yes");
insilmaril@0
   696
	else
insilmaril@0
   697
		scrolledAttr="";
insilmaril@0
   698
insilmaril@0
   699
	QString posAttr;
insilmaril@0
   700
	if (depth<2) posAttr=
insilmaril@0
   701
		attribut("absPosX",QString().setNum(absPos.x(),10)) +
insilmaril@0
   702
		attribut("absPosY",QString().setNum(absPos.y(),10)); 
insilmaril@0
   703
	else
insilmaril@0
   704
		posAttr="";
insilmaril@0
   705
insilmaril@0
   706
	QString urlAttr;
insilmaril@0
   707
	if (!url.isEmpty())
insilmaril@0
   708
		urlAttr=attribut ("url",url);
insilmaril@0
   709
insilmaril@0
   710
	QString vymLinkAttr;
insilmaril@0
   711
	if (!vymLink.isEmpty())
insilmaril@0
   712
		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
insilmaril@0
   713
insilmaril@0
   714
	QString frameAttr;
insilmaril@0
   715
	if (frame->getFrameType()!=NoFrame)
insilmaril@0
   716
		frameAttr=attribut ("frameType",frame->getFrameTypeName());
insilmaril@0
   717
	else
insilmaril@0
   718
		frameAttr="";
insilmaril@0
   719
insilmaril@0
   720
	// save area, if not scrolled
insilmaril@0
   721
	QString areaAttr;
insilmaril@0
   722
	if (!((BranchObj*)(parObj))->isScrolled() )
insilmaril@0
   723
	{
insilmaril@0
   724
		areaAttr=
insilmaril@0
   725
			attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
insilmaril@0
   726
			attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
insilmaril@0
   727
			attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
insilmaril@0
   728
			attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
insilmaril@0
   729
insilmaril@0
   730
	} else
insilmaril@0
   731
		areaAttr="";
insilmaril@0
   732
	
insilmaril@0
   733
    s=beginElement ("branch" +scrolledAttr +posAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr);
insilmaril@0
   734
    incIndent();
insilmaril@0
   735
insilmaril@0
   736
	// save heading
insilmaril@0
   737
    s=s+valueElement("heading", getHeading(),
insilmaril@0
   738
		attribut ("textColor",QColor(heading->getColor()).name()));
insilmaril@0
   739
insilmaril@0
   740
	// save names of flags set
insilmaril@0
   741
	s+=standardFlags->saveToDir(tmpdir,prefix,0);
insilmaril@0
   742
	
insilmaril@0
   743
	// save note
insilmaril@0
   744
	if (!note.isEmpty() )
insilmaril@0
   745
		s+=note.saveToDir();
insilmaril@0
   746
	
insilmaril@0
   747
	// Save branches
insilmaril@0
   748
    BranchObj *bo;
insilmaril@0
   749
    for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@0
   750
		s+=bo->saveToDir(tmpdir,prefix,offset);
insilmaril@0
   751
    decIndent();
insilmaril@0
   752
insilmaril@0
   753
	// Save FloatImages
insilmaril@0
   754
	FloatImageObj *fio;
insilmaril@0
   755
	for (fio=floatimage.first(); fio; fio=floatimage.next() )
insilmaril@0
   756
		s+=fio->saveToDir (tmpdir,prefix);
insilmaril@0
   757
insilmaril@0
   758
    s+=endElement   ("branch");
insilmaril@0
   759
    return s;
insilmaril@0
   760
}
insilmaril@0
   761
insilmaril@0
   762
LinkableMapObj* BranchObj::addFloatImage ()
insilmaril@0
   763
{
insilmaril@0
   764
	FloatImageObj *newfi=new FloatImageObj (canvas,this);
insilmaril@0
   765
	floatimage.append (newfi);
insilmaril@0
   766
	if (hasScrolledParent(this) )
insilmaril@0
   767
		newfi->setVisibility (false);
insilmaril@0
   768
	else	
insilmaril@0
   769
		newfi->setVisibility(visible);
insilmaril@0
   770
	requestReposition();
insilmaril@0
   771
	return newfi;
insilmaril@0
   772
}
insilmaril@0
   773
insilmaril@0
   774
LinkableMapObj* BranchObj::addFloatImage (FloatImageObj *fio)
insilmaril@0
   775
{
insilmaril@0
   776
	FloatImageObj *newfi=new FloatImageObj (canvas,this);
insilmaril@0
   777
	floatimage.append (newfi);
insilmaril@0
   778
	newfi->copy (fio);
insilmaril@0
   779
	if (hasScrolledParent(this) )
insilmaril@0
   780
		newfi->setVisibility (false);
insilmaril@0
   781
	else	
insilmaril@0
   782
		newfi->setVisibility(visible);
insilmaril@0
   783
	requestReposition();
insilmaril@0
   784
	return newfi;
insilmaril@0
   785
}
insilmaril@0
   786
insilmaril@0
   787
FloatImageObj* BranchObj::getFirstFloatImage ()
insilmaril@0
   788
{
insilmaril@0
   789
    return floatimage.first();
insilmaril@0
   790
}
insilmaril@0
   791
insilmaril@0
   792
FloatImageObj* BranchObj::getLastFloatImage ()
insilmaril@0
   793
{
insilmaril@0
   794
    return floatimage.last();
insilmaril@0
   795
}
insilmaril@0
   796
insilmaril@0
   797
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
insilmaril@0
   798
{
insilmaril@0
   799
    return floatimage.at(i);
insilmaril@0
   800
}
insilmaril@0
   801
insilmaril@0
   802
void BranchObj::removeFloatImage (FloatImageObj *fio)
insilmaril@0
   803
{
insilmaril@0
   804
	floatimage.remove (fio);
insilmaril@0
   805
	requestReposition();
insilmaril@0
   806
}
insilmaril@0
   807
insilmaril@0
   808
void BranchObj::savePosInAngle ()
insilmaril@0
   809
{
insilmaril@0
   810
	// Save position in angle
insilmaril@0
   811
    BranchObj *b;
insilmaril@0
   812
	int i=0;
insilmaril@0
   813
    for (b=branch.first(); b; b=branch.next() )
insilmaril@0
   814
	{
insilmaril@0
   815
		b->angle=i;
insilmaril@0
   816
		i++;
insilmaril@0
   817
	}
insilmaril@0
   818
}
insilmaril@0
   819
insilmaril@0
   820
BranchObj* BranchObj::addBranch()
insilmaril@0
   821
{
insilmaril@0
   822
    BranchObj* newbo=new BranchObj(canvas,this);
insilmaril@0
   823
    branch.append (newbo);
insilmaril@0
   824
    newbo->setParObj(this);
insilmaril@0
   825
    newbo->setColor(getColor(),false);	
insilmaril@0
   826
    newbo->setLinkColor();	
insilmaril@0
   827
    newbo->setHeading ("new");
insilmaril@0
   828
	newbo->setLinkStyle (newbo->getDefLinkStyle());
insilmaril@0
   829
	if (scrolled)
insilmaril@0
   830
		newbo->setVisibility (false);
insilmaril@0
   831
	else	
insilmaril@0
   832
		newbo->setVisibility(visible);
insilmaril@0
   833
	requestReposition();
insilmaril@0
   834
	return newbo;
insilmaril@0
   835
}
insilmaril@0
   836
insilmaril@0
   837
BranchObj* BranchObj::addBranch(BranchObj* bo)
insilmaril@0
   838
{
insilmaril@0
   839
    BranchObj* newbo=new BranchObj(canvas,this);
insilmaril@0
   840
    branch.append (newbo);
insilmaril@0
   841
    newbo->copy(bo);
insilmaril@0
   842
    newbo->setParObj(this);
insilmaril@0
   843
	newbo->setHeading (newbo->getHeading());	// adjust fontsize to depth
insilmaril@0
   844
	newbo->setLinkStyle (newbo->getDefLinkStyle());
insilmaril@0
   845
	if (scrolled)
insilmaril@0
   846
		newbo->setVisibility (false);
insilmaril@0
   847
	else	
insilmaril@0
   848
		newbo->setVisibility(bo->visible);
insilmaril@0
   849
	requestReposition();
insilmaril@0
   850
	return newbo;
insilmaril@0
   851
}
insilmaril@0
   852
insilmaril@0
   853
BranchObj* BranchObj::insertBranch(int pos)
insilmaril@0
   854
{
insilmaril@0
   855
	savePosInAngle();
insilmaril@0
   856
	// Add new bo and resort branches
insilmaril@0
   857
	BranchObj *newbo=addBranch ();
insilmaril@0
   858
	newbo->angle=pos-0.5;
insilmaril@0
   859
	branch.sort();
insilmaril@0
   860
	return newbo;
insilmaril@0
   861
}
insilmaril@0
   862
insilmaril@0
   863
BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
insilmaril@0
   864
{
insilmaril@0
   865
	savePosInAngle();
insilmaril@0
   866
	// Add new bo and resort branches
insilmaril@0
   867
	bo->angle=pos-0.5;
insilmaril@0
   868
	BranchObj *newbo=addBranch (bo);
insilmaril@0
   869
	branch.sort();
insilmaril@0
   870
	return newbo;
insilmaril@0
   871
}
insilmaril@0
   872
insilmaril@0
   873
void BranchObj::removeBranch(BranchObj* bo)
insilmaril@0
   874
{
insilmaril@0
   875
    // if bo is not in branch remove returns false, we
insilmaril@0
   876
    // don't care...
insilmaril@0
   877
    branch.remove (bo);
insilmaril@0
   878
	requestReposition();
insilmaril@0
   879
}
insilmaril@0
   880
insilmaril@0
   881
void BranchObj::setLastSelectedBranch (BranchObj* bo)
insilmaril@0
   882
{
insilmaril@0
   883
    lastSelectedBranch=branch.find(bo);
insilmaril@0
   884
}
insilmaril@0
   885
insilmaril@0
   886
BranchObj* BranchObj::getLastSelectedBranch ()
insilmaril@0
   887
{
insilmaril@0
   888
    if (lastSelectedBranch>=0) 
insilmaril@0
   889
	{
insilmaril@0
   890
		BranchObj* bo=branch.at(lastSelectedBranch);
insilmaril@0
   891
		if (bo) return bo;
insilmaril@0
   892
    }	
insilmaril@0
   893
    return branch.first();
insilmaril@0
   894
}
insilmaril@0
   895
insilmaril@0
   896
BranchObj* BranchObj::getFirstBranch ()
insilmaril@0
   897
{
insilmaril@0
   898
    return branch.first();
insilmaril@0
   899
}
insilmaril@0
   900
insilmaril@0
   901
BranchObj* BranchObj::getLastBranch ()
insilmaril@0
   902
{
insilmaril@0
   903
    return branch.last();
insilmaril@0
   904
}
insilmaril@0
   905
insilmaril@0
   906
BranchObj* BranchObj::getBranchNum (const uint &i)
insilmaril@0
   907
{
insilmaril@0
   908
    return branch.at(i);
insilmaril@0
   909
}
insilmaril@0
   910
insilmaril@0
   911
insilmaril@0
   912
BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // move a branch up (modify myself)
insilmaril@0
   913
{
insilmaril@0
   914
	savePosInAngle();
insilmaril@0
   915
    int i=branch.find(bo1);
insilmaril@0
   916
    if (i>0) 
insilmaril@0
   917
	{	// -1 if bo1 not found 
insilmaril@0
   918
		branch.at(i)->angle--;
insilmaril@0
   919
		branch.at(i-1)->angle++;
insilmaril@0
   920
		branch.sort();
insilmaril@0
   921
		return branch.at(i-1);
insilmaril@0
   922
	} else
insilmaril@0
   923
		return branch.at(i);
insilmaril@0
   924
}
insilmaril@0
   925
insilmaril@0
   926
BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)
insilmaril@0
   927
{
insilmaril@0
   928
	savePosInAngle();
insilmaril@0
   929
    int i=branch.find(bo1);
insilmaril@0
   930
	int j;
insilmaril@0
   931
	if (branch.next())
insilmaril@0
   932
	{
insilmaril@0
   933
		j = branch.at();
insilmaril@0
   934
		branch.at(i)->angle++;
insilmaril@0
   935
		branch.at(j)->angle--;
insilmaril@0
   936
		branch.sort();
insilmaril@0
   937
		return branch.at(j);
insilmaril@0
   938
	} else
insilmaril@0
   939
		return branch.at(i);
insilmaril@0
   940
}
insilmaril@0
   941
insilmaril@0
   942
void BranchObj::alignRelativeTo (QPoint ref)
insilmaril@0
   943
{
insilmaril@0
   944
/* FIXME testing
insilmaril@0
   945
	if (!getHeading().isEmpty())
insilmaril@0
   946
		cout << "BO::alignRelTo "<<getHeading()<<endl;
insilmaril@0
   947
	else	
insilmaril@0
   948
		cout << "BO::alignRelTo  ???"<<endl;
insilmaril@0
   949
	cout << "  d="<<depth<<endl;
insilmaril@0
   950
*/	
insilmaril@0
   951
	int th = bboxTotal.height();	
insilmaril@0
   952
insilmaril@0
   953
	// If I am the mapcenter or a mainbranch, reposition heading
insilmaril@0
   954
	if (depth<2)
insilmaril@0
   955
	{
insilmaril@0
   956
		move (absPos.x(),absPos.y());
insilmaril@0
   957
		if (depth==1)
insilmaril@0
   958
		{
insilmaril@0
   959
			// Calc angle to mapCenter if I am a mainbranch
insilmaril@0
   960
			// needed for reordering the mainbranches clockwise 
insilmaril@0
   961
			// around mapcenter 
insilmaril@0
   962
			angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
insilmaril@0
   963
									(int)(y() - parObj->getChildPos().y() ) ) );
insilmaril@0
   964
		}	
insilmaril@0
   965
	} 
insilmaril@0
   966
	else
insilmaril@0
   967
    {
insilmaril@0
   968
		// Align myself depending on orientation and parent, but
insilmaril@0
   969
		// only if I am not the mainbranch or mapcenter itself
insilmaril@0
   970
		switch (orientation) 
insilmaril@0
   971
		{
insilmaril@0
   972
			case OrientLeftOfCenter:
insilmaril@0
   973
				move (ref.x()-bbox.width(), ref.y() + (th-bbox.height())/2 );
insilmaril@0
   974
			break;
insilmaril@0
   975
			case OrientRightOfCenter:	
insilmaril@0
   976
				move (ref.x(), ref.y() + (th-bbox.height())/2 );
insilmaril@0
   977
			break;
insilmaril@0
   978
			default:
insilmaril@0
   979
				cout <<"LMO::alignRelativeTo: oops, no orientation given...\n";
insilmaril@0
   980
			break;
insilmaril@0
   981
		}		
insilmaril@0
   982
    }		
insilmaril@0
   983
insilmaril@0
   984
	FloatImageObj *fio;
insilmaril@0
   985
    for (fio=floatimage.first(); fio; fio=floatimage.next() )
insilmaril@0
   986
		fio->reposition();
insilmaril@0
   987
insilmaril@0
   988
	if (scrolled) return;
insilmaril@0
   989
insilmaril@0
   990
    // Set reference point for alignment of childs
insilmaril@0
   991
    QPoint ref2;
insilmaril@0
   992
    if (orientation==OrientLeftOfCenter)
insilmaril@0
   993
		ref2.setX(childPos.x() - linkwidth);
insilmaril@0
   994
    else	
insilmaril@0
   995
		ref2.setX(childPos.x() + linkwidth);
insilmaril@0
   996
insilmaril@0
   997
	if (depth==1)
insilmaril@0
   998
		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
insilmaril@0
   999
	else	
insilmaril@0
  1000
		ref2.setY(ref.y() );	
insilmaril@0
  1001
insilmaril@0
  1002
    // Align the childs depending on reference point 
insilmaril@0
  1003
    BranchObj *b;
insilmaril@0
  1004
    for (b=branch.first(); b; b=branch.next() )
insilmaril@0
  1005
    {	
insilmaril@0
  1006
		b->alignRelativeTo (ref2);
insilmaril@0
  1007
		ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
insilmaril@0
  1008
    }
insilmaril@0
  1009
}
insilmaril@0
  1010
insilmaril@0
  1011
insilmaril@0
  1012
void BranchObj::reposition()
insilmaril@0
  1013
{	
insilmaril@0
  1014
/* FIXME testing
insilmaril@0
  1015
	if (!getHeading().isEmpty())
insilmaril@0
  1016
		cout << "BO::reposition  "<<getHeading()<<endl;
insilmaril@0
  1017
	else	
insilmaril@0
  1018
		cout << "BO::reposition  ???"<<endl;
insilmaril@0
  1019
*/		
insilmaril@0
  1020
	if (depth==0)
insilmaril@0
  1021
	{
insilmaril@0
  1022
		// only calculate the sizes once. If the deepest LMO 
insilmaril@0
  1023
		// changes its height,
insilmaril@0
  1024
		// all upper LMOs have to change, too.
insilmaril@0
  1025
		calcBBoxSizeWithChilds();
insilmaril@0
  1026
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
  1027
			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
  1028
		branch.sort();	
insilmaril@0
  1029
	} else
insilmaril@0
  1030
	{
insilmaril@0
  1031
		// This is only important for moving branches:
insilmaril@0
  1032
		// For editing a branch it isn't called...
insilmaril@0
  1033
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
  1034
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
  1035
	}
insilmaril@0
  1036
}
insilmaril@0
  1037
insilmaril@0
  1038
insilmaril@0
  1039
QRect BranchObj::getTotalBBox()
insilmaril@0
  1040
{
insilmaril@0
  1041
	QRect r=bbox;
insilmaril@0
  1042
insilmaril@0
  1043
	if (scrolled) return r;
insilmaril@0
  1044
insilmaril@0
  1045
	BranchObj* b;
insilmaril@0
  1046
	for (b=branch.first();b ;b=branch.next() )
insilmaril@0
  1047
		r=addBBox(b->getTotalBBox(),r);
insilmaril@0
  1048
insilmaril@0
  1049
	FloatImageObj* fio;
insilmaril@0
  1050
	for (fio=floatimage.first();fio ;fio=floatimage.next() )
insilmaril@0
  1051
		r=addBBox(fio->getTotalBBox(),r);
insilmaril@0
  1052
		
insilmaril@0
  1053
	return r;
insilmaril@0
  1054
}
insilmaril@0
  1055
insilmaril@0
  1056
QRect BranchObj::getBBoxSizeWithChilds()
insilmaril@0
  1057
{
insilmaril@0
  1058
	return bboxTotal;
insilmaril@0
  1059
}
insilmaril@0
  1060
insilmaril@0
  1061
void BranchObj::calcBBoxSizeWithChilds()
insilmaril@0
  1062
{
insilmaril@0
  1063
	// This is called only from reposition and
insilmaril@0
  1064
	// and only for mapcenter. So it won't be
insilmaril@0
  1065
	// called more than once for a single user 
insilmaril@0
  1066
	// action
insilmaril@0
  1067
	
insilmaril@0
  1068
	// Calculate size of LMO including all childs (to align them later)
insilmaril@0
  1069
insilmaril@0
  1070
	bboxTotal.setX(bbox.x() );
insilmaril@0
  1071
	bboxTotal.setY(bbox.y() );
insilmaril@0
  1072
insilmaril@0
  1073
	// if branch is scrolled, ignore childs, but still consider floatimages
insilmaril@0
  1074
	if (scrolled)
insilmaril@0
  1075
	{
insilmaril@0
  1076
		bboxTotal.setWidth (bbox.width());
insilmaril@0
  1077
		bboxTotal.setHeight(bbox.height());
insilmaril@0
  1078
		return;
insilmaril@0
  1079
	}
insilmaril@0
  1080
	
insilmaril@0
  1081
	QRect r(0,0,0,0);
insilmaril@0
  1082
	QRect br;
insilmaril@0
  1083
	// Now calculate recursivly
insilmaril@0
  1084
	// sum of heights 
insilmaril@0
  1085
	// maximum of widths 
insilmaril@0
  1086
	// minimum of y
insilmaril@0
  1087
	BranchObj* b;
insilmaril@0
  1088
	for (b=branch.first();b ;b=branch.next() )
insilmaril@0
  1089
	{
insilmaril@0
  1090
		b->calcBBoxSizeWithChilds();
insilmaril@0
  1091
		br=b->getBBoxSizeWithChilds();
insilmaril@0
  1092
		r.setWidth( max (br.width(), r.width() ));
insilmaril@0
  1093
		r.setHeight(br.height() + r.height() );
insilmaril@0
  1094
		if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
insilmaril@0
  1095
	}
insilmaril@0
  1096
	// Add myself and also
insilmaril@0
  1097
	// add width of link to sum if necessary
insilmaril@0
  1098
	if (branch.isEmpty())
insilmaril@0
  1099
		bboxTotal.setWidth (bbox.width() + r.width() );
insilmaril@0
  1100
	else	
insilmaril@0
  1101
		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
insilmaril@0
  1102
	bboxTotal.setHeight(max (r.height(),  bbox.height() ) );
insilmaril@0
  1103
//	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
insilmaril@0
  1104
}
insilmaril@0
  1105
insilmaril@0
  1106
void BranchObj::select()
insilmaril@0
  1107
{
insilmaril@0
  1108
    LinkableMapObj::select();
insilmaril@0
  1109
	// Tell parent that I am selected now:
insilmaril@0
  1110
	BranchObj* po=(BranchObj*)(parObj);
insilmaril@0
  1111
    if (po)	// TODO	    Try to get rid of this cast...
insilmaril@0
  1112
        po->setLastSelectedBranch(this);
insilmaril@0
  1113
		
insilmaril@0
  1114
	// temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1115
	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
insilmaril@0
  1116
insilmaril@0
  1117
	// set Text in Editor	
insilmaril@0
  1118
	textEditor->setText(note.getNote() );
insilmaril@0
  1119
	textEditor->setFilename(note.getFilenameHint() );
insilmaril@0
  1120
	textEditor->setFontHint (note.getFontHint() );
insilmaril@0
  1121
	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag() ) ); 
insilmaril@0
  1122
	connect (textEditor, SIGNAL (fontSizeHasChanged() ), this, SLOT (updateNoteFlag() ) ); 
insilmaril@0
  1123
insilmaril@0
  1124
	// Show URL and link in statusbar
insilmaril@0
  1125
	QString status;
insilmaril@0
  1126
	if (!url.isEmpty()) status+="URL: "+url+"  ";
insilmaril@0
  1127
	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
insilmaril@0
  1128
	if (!status.isEmpty()) mainWindow->statusMessage (status);
insilmaril@0
  1129
insilmaril@0
  1130
	// Update Toolbar
insilmaril@0
  1131
	standardFlags->updateToolBar();
insilmaril@0
  1132
insilmaril@0
  1133
	// Update Browserbutton
insilmaril@0
  1134
	if (!url.isEmpty())
insilmaril@0
  1135
		actionEditOpenURL->setEnabled (true);
insilmaril@0
  1136
	else	
insilmaril@0
  1137
		actionEditOpenURL->setEnabled (false);
insilmaril@0
  1138
insilmaril@0
  1139
	// Update actions in mapeditor
insilmaril@0
  1140
	mapEditor->updateActions();
insilmaril@0
  1141
}
insilmaril@0
  1142
insilmaril@0
  1143
void BranchObj::unselect()
insilmaril@0
  1144
{
insilmaril@0
  1145
	LinkableMapObj::unselect();
insilmaril@0
  1146
	// Delete any messages like vymLink in StatusBar
insilmaril@0
  1147
	mainWindow->statusMessage ("");
insilmaril@0
  1148
insilmaril@0
  1149
	// save note from editor and set flag
insilmaril@0
  1150
	// text is done by updateNoteFlag(), just save
insilmaril@0
  1151
	// filename here
insilmaril@0
  1152
	note.setFilenameHint (textEditor->getFilename());
insilmaril@0
  1153
insilmaril@0
  1154
	// reset temporary unscroll, if we have scrolled parents somewhere
insilmaril@0
  1155
	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
insilmaril@0
  1156
insilmaril@0
  1157
	// Disconnect textEditor from this LMO
insilmaril@0
  1158
	disconnect( textEditor, SIGNAL(textHasChanged()), 0, 0 );
insilmaril@0
  1159
	disconnect( textEditor, SIGNAL (fontSizeHasChanged()),0,0 ); 
insilmaril@0
  1160
insilmaril@0
  1161
	// Erase content of editor 
insilmaril@0
  1162
	textEditor->setInactive();
insilmaril@0
  1163
insilmaril@0
  1164
	// unselect all buttons in toolbar
insilmaril@0
  1165
	standardFlagsDefault->updateToolBar();
insilmaril@0
  1166
}
insilmaril@0
  1167
insilmaril@0
  1168
QString BranchObj::getSelectString()
insilmaril@0
  1169
{
insilmaril@0
  1170
	QString s;
insilmaril@0
  1171
	if (parObj)
insilmaril@0
  1172
	{
insilmaril@0
  1173
		if (parObj->getDepth()==0)
insilmaril@0
  1174
			s= "bo:" + QString("%1").arg(getNum());
insilmaril@0
  1175
		else	
insilmaril@0
  1176
			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
insilmaril@0
  1177
	} else
insilmaril@0
  1178
	{
insilmaril@0
  1179
		s="mc:";
insilmaril@0
  1180
	}
insilmaril@0
  1181
	
insilmaril@0
  1182
	return s;
insilmaril@0
  1183
}
insilmaril@0
  1184