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