branchitem.cpp
author insilmaril
Tue, 28 Apr 2009 20:53:44 +0000
changeset 759 bf3ea1f1520b
parent 758 04039e47ac74
child 760 59614eaf5fbb
permissions -rw-r--r--
minor fixes
     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::setHeadingColor (QColor color)
   187 {
   188 	TreeItem::setHeadingColor (color);
   189 	if (lmo) ((BranchObj*)lmo)->setColor (color);
   190 }
   191 
   192 void BranchItem::unScroll()
   193 {
   194 	if (tmpUnscrolled) resetTmpUnscroll();
   195 	if (scrolled) toggleScroll();
   196 }
   197 
   198 void BranchItem::toggleScroll()
   199 {
   200 	if (scrolled)
   201 	{
   202 		scrolled=false;
   203 		//FIXME-1 systemFlags->deactivate("scrolledright");
   204 		/*
   205 		for (int i=0; i<branch.size(); ++i)
   206 			branch.at(i)->setVisibility(true);
   207 		*/	
   208 	} else
   209 	{
   210 		scrolled=true;
   211 		/*
   212 		//FIXME-1 systemFlags->activate("scrolledright");
   213 		for (int i=0; i<branch.size(); ++i)
   214 			branch.at(i)->setVisibility(false);
   215 		*/	
   216 	}
   217 	/*	
   218 	calcBBoxSize();
   219 	positionBBox();	
   220 	move (absPos.x(), absPos.y() );
   221 	forceReposition();
   222 	*/
   223 }
   224 
   225 bool BranchItem::isScrolled()
   226 {
   227 	return scrolled;
   228 }
   229 
   230 bool BranchItem::hasScrolledParent(BranchItem *start)
   231 {
   232 	// Calls parents recursivly to
   233 	// find out, if we are scrolled at all.
   234 	// But ignore myself, just look at parents.
   235 
   236 	if (this !=start && scrolled) return true;
   237 
   238 	BranchItem* bi=(BranchItem*)parentItem;
   239 	if (bi) 
   240 		return bi->hasScrolledParent(start);
   241 	else
   242 		return false;
   243 }
   244 
   245 void BranchItem::tmpUnscroll()
   246 {
   247 	// Unscroll parent (recursivly)
   248 	BranchItem * bi=(BranchItem*)parentItem;
   249 	if (bi) bi->tmpUnscroll();
   250 		
   251 	// Unscroll myself
   252 	if (scrolled)
   253 	{
   254 		tmpUnscrolled=true;
   255 		// FIXME-1 systemFlags->activate("tmpUnscrolledright");
   256 		toggleScroll();
   257 	}	
   258 }
   259 
   260 void BranchItem::resetTmpUnscroll()
   261 {
   262 	// Unscroll parent (recursivly)
   263 	BranchItem * bi=(BranchItem*)parentItem;
   264 	if (bi) bi->resetTmpUnscroll();
   265 		
   266 	// Unscroll myself
   267 	if (tmpUnscrolled)
   268 	{
   269 		tmpUnscrolled=false;
   270 		// FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
   271 		toggleScroll();
   272 	}	
   273 }
   274 
   275 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
   276 {
   277 	// Search branches
   278 	TreeItem *ti;
   279 	for (int i=0; i<branchCount(); ++i)
   280     {	
   281 		ti=getBranchNum(i)->findMapItem(p, excludeTI);
   282 		if (ti != NULL) return ti;
   283     }
   284 	
   285 
   286 	// Search myself
   287     if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() ) 
   288 		return this;
   289 
   290 /* FIXME-2 // Search float images
   291     for (int i=0; i<floatimage.size(); ++i )
   292 		if (floatimage.at(i)->isInClickBox(p) && 
   293 			(floatimage.at(i) != excludeTI) && 
   294 			floatimage.at(i)->getParObj()!= excludeTI &&
   295 			floatimage.at(i)->isVisibleObj() 
   296 		) return floatimage.at(i)->getTreeItem();
   297 */
   298     return NULL;
   299 }
   300 
   301 TreeItem* BranchItem::findID (QString sid)
   302 {
   303 	// Search branches
   304     TreeItem *ti;
   305 	for (int i=0; i<branchCount(); ++i)
   306     {	
   307 		ti=getBranchNum(i)->findID (sid);
   308 		if (ti != NULL) return ti;
   309     }
   310 	
   311 	// Search myself
   312 	if (sid==objID) return this;
   313 
   314 
   315 /*
   316 	// Search float images
   317     for (int i=0; i<floatimage.size(); ++i )
   318 		if (floatimage.at(i)->inBox(p) && 
   319 			(floatimage.at(i) != excludeLMO) && 
   320 			floatimage.at(i)->getParObj()!= excludeLMO &&
   321 			floatimage.at(i)->isVisibleObj() 
   322 		) return floatimage.at(i);
   323 */
   324     return NULL;
   325 }
   326 
   327 
   328 BranchObj* BranchItem::getBranchObj()	// FIXME-3 only for transition BO->BI
   329 {
   330 	return (BranchObj*)lmo;
   331 }
   332 
   333 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)	
   334 {
   335 	// Initialize BranchObj, order of things is important...
   336     BranchObj* newbo=new BranchObj(scene);
   337     newbo->setParObj(parent()->getLMO() );
   338 	newbo->setTreeItem (this);
   339 	newbo->setDefAttr(BranchObj::NewBranch);
   340 	
   341 
   342 	if (!getHeading().isEmpty() ) 
   343 	{
   344 		newbo->updateHeading();
   345 		newbo->setColor (headingColor);
   346 	}	
   347 
   348 		
   349 	//newbo->updateLink();	//FIXME-3
   350 
   351 	lmo=newbo;
   352 	return newbo;
   353 }
   354