branchitem.cpp
author insilmaril
Tue, 07 Apr 2009 16:15:53 +0000
changeset 753 25a77484ec72
parent 750 ff3b01ce0960
child 754 db0ec4bcf416
permissions -rw-r--r--
more work on screwing up the data structures
     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\n";
    21     qDeleteAll(childItems);
    22 }
    23 
    24 void BranchItem::copy (BranchItem *other)
    25 {
    26 	scrolled=other->scrolled;
    27 	tmpUnscrolled=other->tmpUnscrolled;
    28 }
    29 
    30 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    31 {
    32 	// Cloudy stuff can be hidden during exports
    33 	if (hidden) return QString();
    34 
    35     QString s,a;
    36 	BranchObj *bo=(BranchObj*)lmo;
    37 
    38 	/* FIXME-1
    39 	// Update of note is usually done while unselecting a branch
    40 	if (isNoteInEditor) getNoteFromTextEditor();
    41 	
    42 	QString scrolledAttr;
    43 	if (scrolled) 
    44 		scrolledAttr=attribut ("scrolled","yes");
    45 	else
    46 		scrolledAttr="";
    47 
    48 	// save area, if not scrolled
    49 	QString areaAttr;
    50 	if (!((BranchObj*)(parObj))->isScrolled() )
    51 	{
    52 		areaAttr=
    53 			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
    54 			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
    55 			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
    56 			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
    57 
    58 	} else
    59 		areaAttr="";
    60 	
    61 	// Providing an ID for a branch makes export to XHTML easier
    62 	QString idAttr;
    63 	if (countXLinks()>0)
    64 		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
    65 	else
    66 		idAttr="";
    67 
    68 	*/
    69     s=beginElement ("branch" 
    70 	//	+getOrnXMLAttr() 
    71 	//	+scrolledAttr 
    72 	//	+areaAttr 
    73 	//	+idAttr 
    74 	//	+getIncludeImageAttr() 
    75 		);
    76     incIndent();
    77 
    78 	// save heading
    79     s+=valueElement("heading", getHeading(),
    80 		attribut ("textColor",QColor( bo->getColor()).name()));
    81 
    82 /*
    83 	// Save frame
    84 	if (frame->getFrameType()!=FrameObj::NoFrame) 
    85 		s+=frame->saveToDir ();
    86 
    87 	// save names of flags set
    88 	s+=standardFlags->saveToDir(tmpdir,prefix,0);
    89 	
    90 	// Save FloatImages
    91 	for (int i=0; i<floatimage.size(); ++i)
    92 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
    93 */
    94 
    95 	// save note
    96 	if (!note.isEmpty() )
    97 		s+=note.saveToDir();
    98 	
    99 	// Save branches
   100 	TreeItem *ti=getFirstBranch();
   101 	TreeItem *last=getLastBranch();
   102 	while (ti && ti!=last) 
   103 		s+=ti->saveToDir(tmpdir,prefix,offset);
   104 
   105 	/*
   106 	// Save XLinks
   107 	QString ol;	// old link
   108 	QString cl;	// current link
   109 	for (int i=0; i<xlink.size(); ++i)
   110 	{
   111 		cl=xlink.at(i)->saveToDir();
   112 		if (cl!=ol)
   113 		{
   114 			s+=cl;
   115 			ol=cl;
   116 		} else
   117 		{
   118 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   119 		}
   120 	}	
   121 	*/
   122 
   123     decIndent();
   124     s+=endElement   ("branch");
   125     return s;
   126 }
   127 
   128 void BranchItem::updateVisibility()	// FIXME-1
   129 {
   130 }
   131 
   132 void BranchItem::setVymLink(QString s)
   133 {
   134 	if (!s.isEmpty())
   135 	{
   136 		// We need the relative (from loading) 
   137 		// or absolute path (from User event)
   138 		// and build the absolute path.
   139 		// Note: If we have relative, use path of
   140 		// current map to build absolute path
   141 		QDir d(s);
   142 		if (!d.path().startsWith ("/"))
   143 		{
   144 			QString p=model->getDestPath();
   145 			int i=p.findRev("/",-1);
   146 			d.setPath(p.left(i)+"/"+s);
   147 			d.convertToAbs();
   148 		}
   149 		vymLink=d.path();
   150 		//FIXME-2 systemFlags->activate("vymLink");
   151 	}	
   152 	else	
   153 	{
   154 		//FIXME-2 systemFlags->deactivate("vymLink");
   155 		vymLink="";
   156 	}	
   157 	/* FIXME-2
   158 	calcBBoxSize();			// recalculate bbox
   159     positionBBox();			// rearrange contents
   160 	forceReposition();
   161 	*/
   162 }
   163 
   164 QString BranchItem::getVymLink()
   165 {
   166 	return vymLink;
   167 }
   168 
   169 void BranchItem::unScroll()
   170 {
   171 	if (tmpUnscrolled) resetTmpUnscroll();
   172 	if (scrolled) toggleScroll();
   173 }
   174 
   175 void BranchItem::toggleScroll()
   176 {
   177 	if (scrolled)
   178 	{
   179 		scrolled=false;
   180 		//FIXME-1 systemFlags->deactivate("scrolledright");
   181 		/*
   182 		for (int i=0; i<branch.size(); ++i)
   183 			branch.at(i)->setVisibility(true);
   184 		*/	
   185 	} else
   186 	{
   187 		scrolled=true;
   188 		/*
   189 		//FIXME-1 systemFlags->activate("scrolledright");
   190 		for (int i=0; i<branch.size(); ++i)
   191 			branch.at(i)->setVisibility(false);
   192 		*/	
   193 	}
   194 	/*	
   195 	calcBBoxSize();
   196 	positionBBox();	
   197 	move (absPos.x(), absPos.y() );
   198 	forceReposition();
   199 	*/
   200 }
   201 
   202 bool BranchItem::isScrolled()
   203 {
   204 	return scrolled;
   205 }
   206 
   207 bool BranchItem::hasScrolledParent(BranchItem *start)
   208 {
   209 	// Calls parents recursivly to
   210 	// find out, if we are scrolled at all.
   211 	// But ignore myself, just look at parents.
   212 
   213 	if (this !=start && scrolled) return true;
   214 
   215 	BranchItem* bi=(BranchItem*)parentItem;
   216 	if (bi) 
   217 		return bi->hasScrolledParent(start);
   218 	else
   219 		return false;
   220 }
   221 
   222 void BranchItem::tmpUnscroll()
   223 {
   224 	// Unscroll parent (recursivly)
   225 	BranchItem * bi=(BranchItem*)parentItem;
   226 	if (bi) bi->tmpUnscroll();
   227 		
   228 	// Unscroll myself
   229 	if (scrolled)
   230 	{
   231 		tmpUnscrolled=true;
   232 		// FIXME-1 systemFlags->activate("tmpUnscrolledright");
   233 		toggleScroll();
   234 	}	
   235 }
   236 
   237 void BranchItem::resetTmpUnscroll()
   238 {
   239 	// Unscroll parent (recursivly)
   240 	BranchItem * bi=(BranchItem*)parentItem;
   241 	if (bi) bi->resetTmpUnscroll();
   242 		
   243 	// Unscroll myself
   244 	if (tmpUnscrolled)
   245 	{
   246 		tmpUnscrolled=false;
   247 		// FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
   248 		toggleScroll();
   249 	}	
   250 }
   251 
   252 BranchObj* BranchItem::getBranchObj()	// FIXME-3 only for transition BO->BI
   253 {
   254 	return (BranchObj*)lmo;
   255 }
   256