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