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