branchitem.cpp
author insilmaril
Tue, 05 Jan 2010 11:23:12 +0000
changeset 820 735c7ea1d2a9
parent 819 8f987e376035
child 822 c2ce9944148c
permissions -rw-r--r--
Fixed dropping of URLs
insilmaril@747
     1
#include "branchitem.h"
insilmaril@747
     2
#include "branchobj.h"
insilmaril@753
     3
#include "vymmodel.h"
insilmaril@790
     4
#include "xlinkitem.h"
insilmaril@747
     5
insilmaril@747
     6
#include <iostream>
insilmaril@753
     7
#include <QDir>
insilmaril@753
     8
insilmaril@747
     9
using namespace std;
insilmaril@747
    10
insilmaril@779
    11
BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
insilmaril@747
    12
{
insilmaril@749
    13
	//cout << "Constr. BranchItem\n";
insilmaril@749
    14
insilmaril@791
    15
	// Set type if parent is known yet 
insilmaril@791
    16
	// if not, type is set in insertBranch or TreeItem::appendChild
insilmaril@788
    17
	if (parent==rootItem)
insilmaril@788
    18
		setType (MapCenter);
insilmaril@788
    19
	else
insilmaril@788
    20
		setType (Branch);
insilmaril@788
    21
insilmaril@749
    22
	scrolled=false;
insilmaril@749
    23
	tmpUnscrolled=false;
insilmaril@785
    24
insilmaril@785
    25
	includeImagesVer=false;
insilmaril@785
    26
	includeImagesHor=false;
insilmaril@787
    27
	 
insilmaril@787
    28
	lastSelectedBranchNum=-1;
insilmaril@787
    29
	lastSelectedBranchNumAlt=-1;
insilmaril@747
    30
}
insilmaril@747
    31
insilmaril@747
    32
BranchItem::~BranchItem()
insilmaril@747
    33
{
insilmaril@788
    34
	//cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
insilmaril@756
    35
	if (lmo) 
insilmaril@756
    36
	{
insilmaril@756
    37
		delete lmo;
insilmaril@756
    38
		lmo=NULL;
insilmaril@756
    39
	}
insilmaril@747
    40
}
insilmaril@747
    41
insilmaril@749
    42
void BranchItem::copy (BranchItem *other)
insilmaril@749
    43
{
insilmaril@749
    44
	scrolled=other->scrolled;
insilmaril@749
    45
	tmpUnscrolled=other->tmpUnscrolled;
insilmaril@749
    46
}
insilmaril@749
    47
insilmaril@795
    48
BranchItem* BranchItem::parentBranch ()
insilmaril@795
    49
{
insilmaril@795
    50
	return (BranchItem*) parentItem;
insilmaril@795
    51
}
insilmaril@795
    52
insilmaril@756
    53
void BranchItem::insertBranch (int pos, BranchItem *branch)
insilmaril@756
    54
{
insilmaril@756
    55
	if (pos<0) pos=0;
insilmaril@756
    56
	if (pos>branchCounter) pos=branchCounter;
insilmaril@756
    57
    childItems.insert(pos+branchOffset,branch);
insilmaril@756
    58
	branch->parentItem=this;
insilmaril@791
    59
	branch->rootItem=rootItem;
insilmaril@756
    60
	branch->setModel (model);
insilmaril@791
    61
	if (parentItem==rootItem)
insilmaril@791
    62
		setType (MapCenter);
insilmaril@791
    63
	else
insilmaril@791
    64
		setType (Branch);
insilmaril@791
    65
insilmaril@756
    66
insilmaril@756
    67
	if (branchCounter==0)
insilmaril@756
    68
		branchOffset=childItems.count()-1;
insilmaril@756
    69
	branchCounter++;
insilmaril@756
    70
}
insilmaril@756
    71
insilmaril@771
    72
QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
insilmaril@747
    73
{
insilmaril@747
    74
	// Cloudy stuff can be hidden during exports
insilmaril@748
    75
	if (hidden) return QString();
insilmaril@747
    76
insilmaril@747
    77
    QString s,a;
insilmaril@747
    78
	BranchObj *bo=(BranchObj*)lmo;
insilmaril@747
    79
insilmaril@747
    80
	// Update of note is usually done while unselecting a branch
insilmaril@747
    81
	
insilmaril@747
    82
	QString scrolledAttr;
insilmaril@747
    83
	if (scrolled) 
insilmaril@747
    84
		scrolledAttr=attribut ("scrolled","yes");
insilmaril@747
    85
	else
insilmaril@747
    86
		scrolledAttr="";
insilmaril@747
    87
insilmaril@775
    88
	// save area, if not scrolled	// FIXME-5 not needed if HTML is rewritten...
insilmaril@768
    89
									// also we should check if _any_ of parents is scrolled
insilmaril@747
    90
	QString areaAttr;
insilmaril@775
    91
	if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
insilmaril@747
    92
	{
insilmaril@775
    93
		qreal x=lmo->getAbsPos().x();
insilmaril@775
    94
		qreal y=lmo->getAbsPos().y();
insilmaril@747
    95
		areaAttr=
insilmaril@775
    96
			attribut("x1",QString().setNum(x-offset.x())) +
insilmaril@775
    97
			attribut("y1",QString().setNum(y-offset.y())) +
insilmaril@775
    98
			attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
insilmaril@775
    99
			attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
insilmaril@747
   100
insilmaril@747
   101
	} else
insilmaril@747
   102
		areaAttr="";
insilmaril@747
   103
	
insilmaril@790
   104
	// Provide an ID for a branch makes export to XHTML easier
insilmaril@747
   105
	QString idAttr;
insilmaril@790
   106
	if (xlinkCount()>0)
insilmaril@790
   107
		idAttr=attribut ("id",model->getSelectString(this)); 
insilmaril@747
   108
	else
insilmaril@747
   109
		idAttr="";
insilmaril@747
   110
insilmaril@773
   111
	QString elementName;
insilmaril@773
   112
	if (parentItem==rootItem)
insilmaril@773
   113
		elementName="mapcenter";
insilmaril@773
   114
	else	
insilmaril@773
   115
		elementName="branch";
insilmaril@773
   116
insilmaril@773
   117
    s=beginElement (elementName
insilmaril@779
   118
		+getMapAttr()
insilmaril@779
   119
		+getGeneralAttr()
insilmaril@768
   120
		+scrolledAttr 
insilmaril@790
   121
	//	+areaAttr	// FIXME-2
insilmaril@790
   122
		+idAttr 
insilmaril@785
   123
		+getIncludeImageAttr() 
insilmaril@747
   124
		);
insilmaril@747
   125
    incIndent();
insilmaril@747
   126
insilmaril@747
   127
	// save heading
insilmaril@747
   128
    s+=valueElement("heading", getHeading(),
insilmaril@747
   129
		attribut ("textColor",QColor( bo->getColor()).name()));
insilmaril@747
   130
insilmaril@777
   131
	// Save frame  //FIXME-4 not saved if there is no LMO
insilmaril@777
   132
	if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame) 
insilmaril@777
   133
		s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
insilmaril@747
   134
insilmaril@747
   135
	// save names of flags set
insilmaril@768
   136
	s+=standardFlags.saveToDir(tmpdir,prefix,0);
insilmaril@747
   137
	
insilmaril@776
   138
	// Save Images
insilmaril@776
   139
	for (int i=0; i<imageCount(); ++i)
insilmaril@776
   140
		s+=getImageNum(i)->saveToDir (tmpdir,prefix);
insilmaril@747
   141
insilmaril@747
   142
	// save note
insilmaril@747
   143
	if (!note.isEmpty() )
insilmaril@747
   144
		s+=note.saveToDir();
insilmaril@747
   145
	
insilmaril@747
   146
	// Save branches
insilmaril@760
   147
	int i=0;
insilmaril@760
   148
	TreeItem *ti=getBranchNum(i);
insilmaril@760
   149
	while (ti)
insilmaril@760
   150
	{
insilmaril@760
   151
		s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
insilmaril@760
   152
		i++;
insilmaril@760
   153
		ti=getBranchNum(i);
insilmaril@760
   154
	}	
insilmaril@747
   155
insilmaril@790
   156
	// Save XLinks 
insilmaril@747
   157
	QString ol;	// old link
insilmaril@747
   158
	QString cl;	// current link
insilmaril@790
   159
	for (int i=0; i<xlinkCount(); ++i)
insilmaril@747
   160
	{
insilmaril@790
   161
		cl=getXLinkNum(i)->saveToDir();
insilmaril@747
   162
		if (cl!=ol)
insilmaril@747
   163
		{
insilmaril@747
   164
			s+=cl;
insilmaril@747
   165
			ol=cl;
insilmaril@747
   166
		} else
insilmaril@747
   167
		{
insilmaril@747
   168
			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
insilmaril@747
   169
		}
insilmaril@747
   170
	}	
insilmaril@747
   171
insilmaril@747
   172
    decIndent();
insilmaril@773
   173
    s+=endElement   (elementName);
insilmaril@747
   174
    return s;
insilmaril@747
   175
}
insilmaril@747
   176
insilmaril@781
   177
void BranchItem::updateVisibility()	
insilmaril@753
   178
{
insilmaril@781
   179
	// Needed to hide relinked branch, if parent is scrolled
insilmaril@781
   180
	if (lmo)
insilmaril@819
   181
	{
insilmaril@819
   182
		if (hasScrolledParent(this) || hidden)
insilmaril@819
   183
			lmo->setVisibility (false);
insilmaril@819
   184
		else	
insilmaril@819
   185
			lmo->setVisibility (true);
insilmaril@819
   186
	}
insilmaril@753
   187
}
insilmaril@753
   188
insilmaril@758
   189
void BranchItem::setHeadingColor (QColor color)
insilmaril@758
   190
{
insilmaril@758
   191
	TreeItem::setHeadingColor (color);
insilmaril@758
   192
	if (lmo) ((BranchObj*)lmo)->setColor (color);
insilmaril@758
   193
}
insilmaril@758
   194
insilmaril@749
   195
void BranchItem::unScroll()
insilmaril@749
   196
{
insilmaril@749
   197
	if (tmpUnscrolled) resetTmpUnscroll();
insilmaril@749
   198
	if (scrolled) toggleScroll();
insilmaril@749
   199
}
insilmaril@747
   200
insilmaril@767
   201
bool BranchItem::toggleScroll()	
insilmaril@749
   202
{
insilmaril@763
   203
	BranchObj *bo=NULL;
insilmaril@749
   204
	if (scrolled)
insilmaril@749
   205
	{
insilmaril@749
   206
		scrolled=false;
insilmaril@767
   207
		systemFlags.deactivate("system-scrolledright");
insilmaril@767
   208
		if (branchCounter>0)
insilmaril@763
   209
		{
insilmaril@767
   210
			for (int i=0;i<branchCounter;++i)
insilmaril@767
   211
			{
insilmaril@767
   212
				bo=(BranchObj*)(getBranchNum(i)->getLMO());
insilmaril@767
   213
				if (bo) bo->setVisibility(true);
insilmaril@767
   214
			}
insilmaril@763
   215
		}
insilmaril@749
   216
	} else
insilmaril@749
   217
	{
insilmaril@749
   218
		scrolled=true;
insilmaril@767
   219
		systemFlags.activate("system-scrolledright");
insilmaril@767
   220
		if (branchCounter>0)
insilmaril@763
   221
		{
insilmaril@767
   222
			for (int i=0;i<branchCounter;++i)
insilmaril@767
   223
			{
insilmaril@767
   224
				bo=(BranchObj*)(getBranchNum(i)->getLMO());
insilmaril@767
   225
				if (bo) bo->setVisibility(false);
insilmaril@767
   226
			}
insilmaril@763
   227
		}
insilmaril@749
   228
	}
insilmaril@795
   229
	//model->reposition();	// FIXME-3 we don't really want to update view from here...
insilmaril@767
   230
	return true;
insilmaril@749
   231
}
insilmaril@749
   232
insilmaril@749
   233
bool BranchItem::isScrolled()
insilmaril@749
   234
{
insilmaril@749
   235
	return scrolled;
insilmaril@749
   236
}
insilmaril@749
   237
insilmaril@749
   238
bool BranchItem::hasScrolledParent(BranchItem *start)
insilmaril@749
   239
{
insilmaril@749
   240
	// Calls parents recursivly to
insilmaril@749
   241
	// find out, if we are scrolled at all.
insilmaril@749
   242
	// But ignore myself, just look at parents.
insilmaril@749
   243
insilmaril@749
   244
	if (this !=start && scrolled) return true;
insilmaril@749
   245
insilmaril@749
   246
	BranchItem* bi=(BranchItem*)parentItem;
insilmaril@796
   247
	if (bi && bi!=rootItem ) 
insilmaril@749
   248
		return bi->hasScrolledParent(start);
insilmaril@749
   249
	else
insilmaril@749
   250
		return false;
insilmaril@749
   251
}
insilmaril@749
   252
insilmaril@796
   253
bool BranchItem::tmpUnscroll()
insilmaril@749
   254
{
insilmaril@796
   255
	bool result=false;
insilmaril@796
   256
insilmaril@749
   257
	// Unscroll parent (recursivly)
insilmaril@775
   258
	BranchItem * pi=(BranchItem*)parentItem;
insilmaril@796
   259
	if (pi && pi->isBranchLikeType() ) result=pi->tmpUnscroll();
insilmaril@749
   260
		
insilmaril@749
   261
	// Unscroll myself
insilmaril@749
   262
	if (scrolled)
insilmaril@749
   263
	{
insilmaril@749
   264
		tmpUnscrolled=true;
insilmaril@775
   265
		systemFlags.activate("system-tmpUnscrolledRight");
insilmaril@749
   266
		toggleScroll();
insilmaril@775
   267
		model->emitDataHasChanged (this);
insilmaril@796
   268
		result=true;
insilmaril@749
   269
	}	
insilmaril@796
   270
	return result;
insilmaril@749
   271
}
insilmaril@749
   272
insilmaril@796
   273
bool BranchItem::resetTmpUnscroll()
insilmaril@749
   274
{
insilmaril@796
   275
	bool result=false;
insilmaril@796
   276
insilmaril@749
   277
	// Unscroll parent (recursivly)
insilmaril@775
   278
	BranchItem * pi=(BranchItem*)parentItem;
insilmaril@796
   279
	if (pi && pi->isBranchLikeType() ) result=pi->resetTmpUnscroll();
insilmaril@749
   280
		
insilmaril@749
   281
	// Unscroll myself
insilmaril@749
   282
	if (tmpUnscrolled)
insilmaril@749
   283
	{
insilmaril@749
   284
		tmpUnscrolled=false;
insilmaril@775
   285
		systemFlags.deactivate("system-tmpUnscrolledRight");
insilmaril@749
   286
		toggleScroll();
insilmaril@775
   287
		model->emitDataHasChanged (this);
insilmaril@796
   288
		result=true;
insilmaril@749
   289
	}	
insilmaril@796
   290
	return result;
insilmaril@749
   291
}
insilmaril@749
   292
insilmaril@795
   293
void BranchItem::sortChildren()
insilmaril@795
   294
{
insilmaril@795
   295
	int childCount=branchCounter; 
insilmaril@795
   296
	int curChildIndex;
insilmaril@795
   297
	bool madeChanges=false;
insilmaril@795
   298
	do
insilmaril@795
   299
	{
insilmaril@795
   300
		madeChanges=false;
insilmaril@795
   301
		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
insilmaril@795
   302
			BranchItem* curChild =getBranchNum(curChildIndex);
insilmaril@795
   303
			BranchItem* prevChild=getBranchNum(curChildIndex-1);
insilmaril@795
   304
			if(prevChild->getHeading().compare(curChild->getHeading())>0)
insilmaril@795
   305
			{
insilmaril@795
   306
				model->moveUp(curChild);
insilmaril@795
   307
				madeChanges=true;
insilmaril@795
   308
			}
insilmaril@795
   309
		}
insilmaril@795
   310
	}while(madeChanges);
insilmaril@795
   311
}
insilmaril@795
   312
insilmaril@785
   313
void BranchItem::setIncludeImagesVer(bool b)
insilmaril@785
   314
{
insilmaril@785
   315
	includeImagesVer=b;
insilmaril@795
   316
	/* calcBBoxSize(); FIXME-3
insilmaril@785
   317
	positionBBox();
insilmaril@785
   318
	requestReposition();
insilmaril@785
   319
	*/
insilmaril@785
   320
}
insilmaril@785
   321
insilmaril@785
   322
bool BranchItem::getIncludeImagesVer()
insilmaril@785
   323
{
insilmaril@785
   324
	return includeImagesVer;
insilmaril@785
   325
}
insilmaril@785
   326
insilmaril@785
   327
void BranchItem::setIncludeImagesHor(bool b)
insilmaril@785
   328
{
insilmaril@785
   329
	includeImagesHor=b;
insilmaril@795
   330
	/* calcBBoxSize(); FIXME-3
insilmaril@785
   331
	positionBBox();
insilmaril@785
   332
	requestReposition();
insilmaril@785
   333
	*/
insilmaril@785
   334
}
insilmaril@785
   335
insilmaril@785
   336
bool BranchItem::getIncludeImagesHor()
insilmaril@785
   337
{
insilmaril@785
   338
	return includeImagesHor;
insilmaril@785
   339
}
insilmaril@785
   340
insilmaril@785
   341
QString BranchItem::getIncludeImageAttr()
insilmaril@785
   342
{
insilmaril@785
   343
	QString a;
insilmaril@785
   344
	if (includeImagesVer)
insilmaril@785
   345
		a=attribut ("incImgV","true");
insilmaril@785
   346
	if (includeImagesHor)
insilmaril@785
   347
		a+=attribut ("incImgH","true");
insilmaril@785
   348
	return a;	
insilmaril@785
   349
}
insilmaril@785
   350
insilmaril@787
   351
void BranchItem::setLastSelectedBranch()
insilmaril@787
   352
{
insilmaril@787
   353
	int d=depth();
insilmaril@787
   354
	if (d>=0)
insilmaril@787
   355
	{
insilmaril@787
   356
		if (d==1)
insilmaril@787
   357
			// Hack to save an additional lastSelected for mapcenters in MapEditor
insilmaril@787
   358
			// depending on orientation
insilmaril@787
   359
			// this allows to go both left and right from there
insilmaril@787
   360
			if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@787
   361
			{
insilmaril@787
   362
				((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
insilmaril@787
   363
				return;
insilmaril@787
   364
			}
insilmaril@787
   365
		((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
insilmaril@787
   366
	}
insilmaril@787
   367
}
insilmaril@787
   368
insilmaril@787
   369
void BranchItem::setLastSelectedBranch(int i)
insilmaril@787
   370
{
insilmaril@787
   371
		lastSelectedBranchNum=i;
insilmaril@787
   372
}
insilmaril@787
   373
insilmaril@787
   374
BranchItem* BranchItem::getLastSelectedBranch()
insilmaril@787
   375
{
insilmaril@804
   376
	if (lastSelectedBranchNum>=branchCounter)
insilmaril@804
   377
		return getBranchNum (branchCounter-1);
insilmaril@804
   378
	else	
insilmaril@804
   379
		return getBranchNum (lastSelectedBranchNum);
insilmaril@787
   380
}
insilmaril@787
   381
insilmaril@787
   382
BranchItem* BranchItem::getLastSelectedBranchAlt()
insilmaril@787
   383
{
insilmaril@787
   384
	return getBranchNum (lastSelectedBranchNumAlt);
insilmaril@787
   385
}
insilmaril@787
   386
insilmaril@787
   387
insilmaril@787
   388
insilmaril@785
   389
insilmaril@785
   390
insilmaril@758
   391
TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
insilmaril@754
   392
{
insilmaril@754
   393
	// Search branches
insilmaril@754
   394
	TreeItem *ti;
insilmaril@754
   395
	for (int i=0; i<branchCount(); ++i)
insilmaril@754
   396
    {	
insilmaril@758
   397
		ti=getBranchNum(i)->findMapItem(p, excludeTI);
insilmaril@754
   398
		if (ti != NULL) return ti;
insilmaril@754
   399
    }
insilmaril@754
   400
	
insilmaril@754
   401
insilmaril@754
   402
	// Search myself
insilmaril@758
   403
    if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() ) 
insilmaril@754
   404
		return this;
insilmaril@754
   405
insilmaril@776
   406
	// Search images
insilmaril@776
   407
	ImageItem *ii;
insilmaril@776
   408
    for (int i=0; i<imageCount(); ++i )
insilmaril@776
   409
	{
insilmaril@776
   410
		ii=getImageNum (i);
insilmaril@776
   411
		LinkableMapObj *mo=ii->getLMO();
insilmaril@776
   412
		if (mo && mo->isInClickBox(p) && 
insilmaril@776
   413
			(ii != excludeTI) && 
insilmaril@776
   414
			this!= excludeTI &&
insilmaril@776
   415
			mo->isVisibleObj() 
insilmaril@776
   416
		) return ii;
insilmaril@776
   417
	}
insilmaril@776
   418
	return NULL;
insilmaril@754
   419
}
insilmaril@795
   420
/*
insilmaril@790
   421
TreeItem* BranchItem::findID (QString sid)	//FIXME-3 move to TreeItem	//FIXME-4 search images
insilmaril@754
   422
{
insilmaril@754
   423
	// Search branches
insilmaril@754
   424
    TreeItem *ti;
insilmaril@754
   425
	for (int i=0; i<branchCount(); ++i)
insilmaril@754
   426
    {	
insilmaril@754
   427
		ti=getBranchNum(i)->findID (sid);
insilmaril@754
   428
		if (ti != NULL) return ti;
insilmaril@754
   429
    }
insilmaril@754
   430
	
insilmaril@754
   431
	// Search myself
insilmaril@754
   432
	if (sid==objID) return this;
insilmaril@754
   433
insilmaril@754
   434
insilmaril@790
   435
	// Search float images 
insilmaril@754
   436
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@754
   437
		if (floatimage.at(i)->inBox(p) && 
insilmaril@754
   438
			(floatimage.at(i) != excludeLMO) && 
insilmaril@754
   439
			floatimage.at(i)->getParObj()!= excludeLMO &&
insilmaril@754
   440
			floatimage.at(i)->isVisibleObj() 
insilmaril@754
   441
		) return floatimage.at(i);
insilmaril@754
   442
    return NULL;
insilmaril@754
   443
}
insilmaril@795
   444
*/
insilmaril@773
   445
void BranchItem::updateStyles()
insilmaril@773
   446
{
insilmaril@773
   447
	// FIXME-5 compare also MapItem::initLMO...
insilmaril@773
   448
insilmaril@798
   449
	if (lmo)
insilmaril@798
   450
	{ 
insilmaril@798
   451
		if ( parentItem != rootItem)
insilmaril@798
   452
			lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
insilmaril@798
   453
		else
insilmaril@798
   454
			lmo->setParObj (NULL);
insilmaril@798
   455
		((BranchObj*)lmo)->setDefAttr(BranchObj::MovedBranch);
insilmaril@773
   456
	}
insilmaril@773
   457
}
insilmaril@754
   458
insilmaril@750
   459
BranchObj* BranchItem::getBranchObj()	// FIXME-3 only for transition BO->BI
insilmaril@750
   460
{
insilmaril@750
   461
	return (BranchObj*)lmo;
insilmaril@750
   462
}
insilmaril@749
   463
insilmaril@786
   464
BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)	// FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
insilmaril@755
   465
{
insilmaril@773
   466
	BranchObj *newbo;
insilmaril@790
   467
	newbo=new BranchObj(scene,this);
insilmaril@775
   468
	lmo=newbo;
insilmaril@775
   469
insilmaril@773
   470
	if (parentItem==rootItem)
insilmaril@773
   471
	{
insilmaril@773
   472
		newbo->setParObj(NULL);
insilmaril@798
   473
		//newbo->setFrameType (FrameObj::Rectangle);	//FIXME-4 maybe call updateStyles?
insilmaril@773
   474
	} else
insilmaril@773
   475
	{
insilmaril@779
   476
		newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
insilmaril@775
   477
		// Set visibility depending on parents
insilmaril@791
   478
		if (parentItem!=rootItem && 
insilmaril@791
   479
			( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
insilmaril@775
   480
			newbo->setVisibility (false);
insilmaril@773
   481
	}
insilmaril@775
   482
	newbo->setDefAttr(BranchObj::NewBranch);
insilmaril@760
   483
	initLMO();
insilmaril@758
   484
insilmaril@758
   485
	if (!getHeading().isEmpty() ) 
insilmaril@758
   486
	{
insilmaril@775
   487
		newbo->updateData();	//FIXME-3 maybe better model->emitDataHasChanged()?
insilmaril@775
   488
		newbo->setColor (headingColor);
insilmaril@758
   489
	}	
insilmaril@758
   490
		
insilmaril@779
   491
	//newbo->updateLinkGeometry();	//FIXME-3
insilmaril@755
   492
insilmaril@755
   493
	return newbo;
insilmaril@755
   494
}
insilmaril@755
   495