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