branchitem.cpp
author insilmaril
Wed, 06 May 2009 11:08:38 +0000
changeset 765 d7f79e51b00d
parent 763 8c028a5d9083
child 767 6d2b32f305f9
permissions -rw-r--r--
added lyx file for french translation
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@756
    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@760
    48
QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-1
insilmaril@747
    49
{
insilmaril@760
    50
		cout << "BI::saveToDir: "<<getHeadingStd()<<endl;
insilmaril@747
    51
	// Cloudy stuff can be hidden during exports
insilmaril@748
    52
	if (hidden) return QString();
insilmaril@747
    53
insilmaril@747
    54
    QString s,a;
insilmaril@747
    55
	BranchObj *bo=(BranchObj*)lmo;
insilmaril@747
    56
insilmaril@760
    57
	/* 
insilmaril@747
    58
	// Update of note is usually done while unselecting a branch
insilmaril@747
    59
	if (isNoteInEditor) getNoteFromTextEditor();
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@747
    67
	// save area, if not scrolled
insilmaril@747
    68
	QString areaAttr;
insilmaril@747
    69
	if (!((BranchObj*)(parObj))->isScrolled() )
insilmaril@747
    70
	{
insilmaril@747
    71
		areaAttr=
insilmaril@747
    72
			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
insilmaril@747
    73
			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
insilmaril@747
    74
			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
insilmaril@747
    75
			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
insilmaril@747
    76
insilmaril@747
    77
	} else
insilmaril@747
    78
		areaAttr="";
insilmaril@747
    79
	
insilmaril@747
    80
	// Providing an ID for a branch makes export to XHTML easier
insilmaril@747
    81
	QString idAttr;
insilmaril@747
    82
	if (countXLinks()>0)
insilmaril@747
    83
		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
insilmaril@747
    84
	else
insilmaril@747
    85
		idAttr="";
insilmaril@747
    86
insilmaril@747
    87
	*/
insilmaril@747
    88
    s=beginElement ("branch" 
insilmaril@762
    89
		+getAttr()
insilmaril@747
    90
	//	+getOrnXMLAttr() 
insilmaril@747
    91
	//	+scrolledAttr 
insilmaril@747
    92
	//	+areaAttr 
insilmaril@747
    93
	//	+idAttr 
insilmaril@747
    94
	//	+getIncludeImageAttr() 
insilmaril@747
    95
		);
insilmaril@747
    96
    incIndent();
insilmaril@747
    97
insilmaril@747
    98
	// save heading
insilmaril@747
    99
    s+=valueElement("heading", getHeading(),
insilmaril@747
   100
		attribut ("textColor",QColor( bo->getColor()).name()));
insilmaril@747
   101
insilmaril@747
   102
/*
insilmaril@747
   103
	// Save frame
insilmaril@747
   104
	if (frame->getFrameType()!=FrameObj::NoFrame) 
insilmaril@747
   105
		s+=frame->saveToDir ();
insilmaril@747
   106
insilmaril@747
   107
	// save names of flags set
insilmaril@747
   108
	s+=standardFlags->saveToDir(tmpdir,prefix,0);
insilmaril@747
   109
	
insilmaril@747
   110
	// Save FloatImages
insilmaril@747
   111
	for (int i=0; i<floatimage.size(); ++i)
insilmaril@747
   112
		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
insilmaril@747
   113
*/
insilmaril@747
   114
insilmaril@747
   115
	// save note
insilmaril@747
   116
	if (!note.isEmpty() )
insilmaril@747
   117
		s+=note.saveToDir();
insilmaril@747
   118
	
insilmaril@747
   119
	// Save branches
insilmaril@760
   120
	int i=0;
insilmaril@760
   121
	TreeItem *ti=getBranchNum(i);
insilmaril@760
   122
	while (ti)
insilmaril@760
   123
	{
insilmaril@760
   124
		s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
insilmaril@760
   125
		i++;
insilmaril@760
   126
		ti=getBranchNum(i);
insilmaril@760
   127
	}	
insilmaril@747
   128
insilmaril@747
   129
	/*
insilmaril@747
   130
	// Save XLinks
insilmaril@747
   131
	QString ol;	// old link
insilmaril@747
   132
	QString cl;	// current link
insilmaril@747
   133
	for (int i=0; i<xlink.size(); ++i)
insilmaril@747
   134
	{
insilmaril@747
   135
		cl=xlink.at(i)->saveToDir();
insilmaril@747
   136
		if (cl!=ol)
insilmaril@747
   137
		{
insilmaril@747
   138
			s+=cl;
insilmaril@747
   139
			ol=cl;
insilmaril@747
   140
		} else
insilmaril@747
   141
		{
insilmaril@747
   142
			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
insilmaril@747
   143
		}
insilmaril@747
   144
	}	
insilmaril@747
   145
	*/
insilmaril@747
   146
insilmaril@747
   147
    decIndent();
insilmaril@747
   148
    s+=endElement   ("branch");
insilmaril@747
   149
    return s;
insilmaril@747
   150
}
insilmaril@747
   151
insilmaril@753
   152
void BranchItem::updateVisibility()	// FIXME-1
insilmaril@753
   153
{
insilmaril@753
   154
}
insilmaril@753
   155
insilmaril@753
   156
void BranchItem::setVymLink(QString s)
insilmaril@753
   157
{
insilmaril@753
   158
	if (!s.isEmpty())
insilmaril@753
   159
	{
insilmaril@753
   160
		// We need the relative (from loading) 
insilmaril@753
   161
		// or absolute path (from User event)
insilmaril@753
   162
		// and build the absolute path.
insilmaril@753
   163
		// Note: If we have relative, use path of
insilmaril@753
   164
		// current map to build absolute path
insilmaril@753
   165
		QDir d(s);
insilmaril@753
   166
		if (!d.path().startsWith ("/"))
insilmaril@753
   167
		{
insilmaril@753
   168
			QString p=model->getDestPath();
insilmaril@753
   169
			int i=p.findRev("/",-1);
insilmaril@753
   170
			d.setPath(p.left(i)+"/"+s);
insilmaril@753
   171
			d.convertToAbs();
insilmaril@753
   172
		}
insilmaril@753
   173
		vymLink=d.path();
insilmaril@753
   174
		//FIXME-2 systemFlags->activate("vymLink");
insilmaril@753
   175
	}	
insilmaril@753
   176
	else	
insilmaril@753
   177
	{
insilmaril@753
   178
		//FIXME-2 systemFlags->deactivate("vymLink");
insilmaril@753
   179
		vymLink="";
insilmaril@753
   180
	}	
insilmaril@753
   181
	/* FIXME-2
insilmaril@753
   182
	calcBBoxSize();			// recalculate bbox
insilmaril@753
   183
    positionBBox();			// rearrange contents
insilmaril@753
   184
	forceReposition();
insilmaril@753
   185
	*/
insilmaril@753
   186
}
insilmaril@753
   187
insilmaril@753
   188
QString BranchItem::getVymLink()
insilmaril@753
   189
{
insilmaril@753
   190
	return vymLink;
insilmaril@753
   191
}
insilmaril@753
   192
insilmaril@758
   193
void BranchItem::setHeadingColor (QColor color)
insilmaril@758
   194
{
insilmaril@758
   195
	TreeItem::setHeadingColor (color);
insilmaril@758
   196
	if (lmo) ((BranchObj*)lmo)->setColor (color);
insilmaril@758
   197
}
insilmaril@758
   198
insilmaril@749
   199
void BranchItem::unScroll()
insilmaril@749
   200
{
insilmaril@749
   201
	if (tmpUnscrolled) resetTmpUnscroll();
insilmaril@749
   202
	if (scrolled) toggleScroll();
insilmaril@749
   203
}
insilmaril@747
   204
insilmaril@749
   205
void BranchItem::toggleScroll()
insilmaril@749
   206
{
insilmaril@763
   207
	BranchItem *bi=getFirstBranch();
insilmaril@763
   208
insilmaril@763
   209
	BranchObj *bo=NULL;
insilmaril@749
   210
	if (scrolled)
insilmaril@749
   211
	{
insilmaril@749
   212
		scrolled=false;
insilmaril@749
   213
		//FIXME-1 systemFlags->deactivate("scrolledright");
insilmaril@763
   214
		while (bi)
insilmaril@763
   215
		{
insilmaril@763
   216
			bo=(BranchObj*)(bi->getLMO());
insilmaril@763
   217
			if (bo) bo->setVisibility(true);
insilmaril@763
   218
			bi=getNextBranch(bi);
insilmaril@763
   219
		}
insilmaril@749
   220
	} else
insilmaril@749
   221
	{
insilmaril@749
   222
		scrolled=true;
insilmaril@749
   223
		//FIXME-1 systemFlags->activate("scrolledright");
insilmaril@763
   224
		while (bi)
insilmaril@763
   225
		{
insilmaril@763
   226
			bo=(BranchObj*)(bi->getLMO());
insilmaril@763
   227
			if (bo) bo->setVisibility(false);
insilmaril@763
   228
			bi=getNextBranch(bi);
insilmaril@763
   229
		}
insilmaril@749
   230
	}
insilmaril@763
   231
	if (bo)
insilmaril@763
   232
	{
insilmaril@763
   233
		bo->calcBBoxSize();
insilmaril@763
   234
		bo->positionBBox();	
insilmaril@763
   235
		bo->forceReposition();
insilmaril@763
   236
	}
insilmaril@749
   237
}
insilmaril@749
   238
insilmaril@749
   239
bool BranchItem::isScrolled()
insilmaril@749
   240
{
insilmaril@749
   241
	return scrolled;
insilmaril@749
   242
}
insilmaril@749
   243
insilmaril@749
   244
bool BranchItem::hasScrolledParent(BranchItem *start)
insilmaril@749
   245
{
insilmaril@749
   246
	// Calls parents recursivly to
insilmaril@749
   247
	// find out, if we are scrolled at all.
insilmaril@749
   248
	// But ignore myself, just look at parents.
insilmaril@749
   249
insilmaril@749
   250
	if (this !=start && scrolled) return true;
insilmaril@749
   251
insilmaril@749
   252
	BranchItem* bi=(BranchItem*)parentItem;
insilmaril@749
   253
	if (bi) 
insilmaril@749
   254
		return bi->hasScrolledParent(start);
insilmaril@749
   255
	else
insilmaril@749
   256
		return false;
insilmaril@749
   257
}
insilmaril@749
   258
insilmaril@749
   259
void BranchItem::tmpUnscroll()
insilmaril@749
   260
{
insilmaril@749
   261
	// Unscroll parent (recursivly)
insilmaril@749
   262
	BranchItem * bi=(BranchItem*)parentItem;
insilmaril@749
   263
	if (bi) bi->tmpUnscroll();
insilmaril@749
   264
		
insilmaril@749
   265
	// Unscroll myself
insilmaril@749
   266
	if (scrolled)
insilmaril@749
   267
	{
insilmaril@749
   268
		tmpUnscrolled=true;
insilmaril@749
   269
		// FIXME-1 systemFlags->activate("tmpUnscrolledright");
insilmaril@749
   270
		toggleScroll();
insilmaril@749
   271
	}	
insilmaril@749
   272
}
insilmaril@749
   273
insilmaril@749
   274
void BranchItem::resetTmpUnscroll()
insilmaril@749
   275
{
insilmaril@749
   276
	// Unscroll parent (recursivly)
insilmaril@749
   277
	BranchItem * bi=(BranchItem*)parentItem;
insilmaril@749
   278
	if (bi) bi->resetTmpUnscroll();
insilmaril@749
   279
		
insilmaril@749
   280
	// Unscroll myself
insilmaril@749
   281
	if (tmpUnscrolled)
insilmaril@749
   282
	{
insilmaril@749
   283
		tmpUnscrolled=false;
insilmaril@749
   284
		// FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
insilmaril@749
   285
		toggleScroll();
insilmaril@749
   286
	}	
insilmaril@749
   287
}
insilmaril@749
   288
insilmaril@758
   289
TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
insilmaril@754
   290
{
insilmaril@754
   291
	// Search branches
insilmaril@754
   292
	TreeItem *ti;
insilmaril@754
   293
	for (int i=0; i<branchCount(); ++i)
insilmaril@754
   294
    {	
insilmaril@758
   295
		ti=getBranchNum(i)->findMapItem(p, excludeTI);
insilmaril@754
   296
		if (ti != NULL) return ti;
insilmaril@754
   297
    }
insilmaril@754
   298
	
insilmaril@754
   299
insilmaril@754
   300
	// Search myself
insilmaril@758
   301
    if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() ) 
insilmaril@754
   302
		return this;
insilmaril@754
   303
insilmaril@754
   304
/* FIXME-2 // Search float images
insilmaril@754
   305
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@754
   306
		if (floatimage.at(i)->isInClickBox(p) && 
insilmaril@758
   307
			(floatimage.at(i) != excludeTI) && 
insilmaril@758
   308
			floatimage.at(i)->getParObj()!= excludeTI &&
insilmaril@754
   309
			floatimage.at(i)->isVisibleObj() 
insilmaril@754
   310
		) return floatimage.at(i)->getTreeItem();
insilmaril@754
   311
*/
insilmaril@754
   312
    return NULL;
insilmaril@754
   313
}
insilmaril@754
   314
insilmaril@754
   315
TreeItem* BranchItem::findID (QString sid)
insilmaril@754
   316
{
insilmaril@754
   317
	// Search branches
insilmaril@754
   318
    TreeItem *ti;
insilmaril@754
   319
	for (int i=0; i<branchCount(); ++i)
insilmaril@754
   320
    {	
insilmaril@754
   321
		ti=getBranchNum(i)->findID (sid);
insilmaril@754
   322
		if (ti != NULL) return ti;
insilmaril@754
   323
    }
insilmaril@754
   324
	
insilmaril@754
   325
	// Search myself
insilmaril@754
   326
	if (sid==objID) return this;
insilmaril@754
   327
insilmaril@754
   328
insilmaril@754
   329
/*
insilmaril@754
   330
	// Search float images
insilmaril@754
   331
    for (int i=0; i<floatimage.size(); ++i )
insilmaril@754
   332
		if (floatimage.at(i)->inBox(p) && 
insilmaril@754
   333
			(floatimage.at(i) != excludeLMO) && 
insilmaril@754
   334
			floatimage.at(i)->getParObj()!= excludeLMO &&
insilmaril@754
   335
			floatimage.at(i)->isVisibleObj() 
insilmaril@754
   336
		) return floatimage.at(i);
insilmaril@754
   337
*/
insilmaril@754
   338
    return NULL;
insilmaril@754
   339
}
insilmaril@754
   340
insilmaril@754
   341
insilmaril@750
   342
BranchObj* BranchItem::getBranchObj()	// FIXME-3 only for transition BO->BI
insilmaril@750
   343
{
insilmaril@750
   344
	return (BranchObj*)lmo;
insilmaril@750
   345
}
insilmaril@749
   346
insilmaril@755
   347
BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)	
insilmaril@755
   348
{
insilmaril@755
   349
	// Initialize BranchObj, order of things is important...
insilmaril@755
   350
    BranchObj* newbo=new BranchObj(scene);
insilmaril@760
   351
	lmo=newbo;
insilmaril@755
   352
    newbo->setParObj(parent()->getLMO() );
insilmaril@755
   353
	newbo->setTreeItem (this);
insilmaril@755
   354
	newbo->setDefAttr(BranchObj::NewBranch);
insilmaril@758
   355
	
insilmaril@760
   356
	initLMO();
insilmaril@758
   357
insilmaril@758
   358
	if (!getHeading().isEmpty() ) 
insilmaril@758
   359
	{
insilmaril@758
   360
		newbo->updateHeading();
insilmaril@758
   361
		newbo->setColor (headingColor);
insilmaril@758
   362
	}	
insilmaril@758
   363
insilmaril@758
   364
		
insilmaril@756
   365
	//newbo->updateLink();	//FIXME-3
insilmaril@755
   366
insilmaril@755
   367
	return newbo;
insilmaril@755
   368
}
insilmaril@755
   369