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