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