branchitem.cpp
author insilmaril
Wed, 01 Apr 2009 15:06:57 +0000
changeset 749 9ff332964015
parent 748 edb78a44240b
child 750 ff3b01ce0960
permissions -rw-r--r--
moved scroll functions from BranchObj to BranchItem
     1 #include "branchitem.h"
     2 #include "branchobj.h"
     3 
     4 #include <iostream>
     5 using namespace std;
     6 
     7 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
     8 {
     9 	//cout << "Constr. BranchItem\n";
    10 
    11 	scrolled=false;
    12 	tmpUnscrolled=false;
    13 }
    14 
    15 BranchItem::~BranchItem()
    16 {
    17 	cout << "Destr. BranchItem\n";
    18     qDeleteAll(childItems);
    19 }
    20 
    21 void BranchItem::copy (BranchItem *other)
    22 {
    23 	scrolled=other->scrolled;
    24 	tmpUnscrolled=other->tmpUnscrolled;
    25 }
    26 
    27 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    28 {
    29 	// Cloudy stuff can be hidden during exports
    30 	if (hidden) return QString();
    31 
    32     QString s,a;
    33 	BranchObj *bo=(BranchObj*)lmo;
    34 
    35 	/* FIXME-1
    36 	// Update of note is usually done while unselecting a branch
    37 	if (isNoteInEditor) getNoteFromTextEditor();
    38 	
    39 	QString scrolledAttr;
    40 	if (scrolled) 
    41 		scrolledAttr=attribut ("scrolled","yes");
    42 	else
    43 		scrolledAttr="";
    44 
    45 	// save area, if not scrolled
    46 	QString areaAttr;
    47 	if (!((BranchObj*)(parObj))->isScrolled() )
    48 	{
    49 		areaAttr=
    50 			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
    51 			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
    52 			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
    53 			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
    54 
    55 	} else
    56 		areaAttr="";
    57 	
    58 	// Providing an ID for a branch makes export to XHTML easier
    59 	QString idAttr;
    60 	if (countXLinks()>0)
    61 		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
    62 	else
    63 		idAttr="";
    64 
    65 	*/
    66     s=beginElement ("branch" 
    67 	//	+getOrnXMLAttr() 
    68 	//	+scrolledAttr 
    69 	//	+areaAttr 
    70 	//	+idAttr 
    71 	//	+getIncludeImageAttr() 
    72 		);
    73     incIndent();
    74 
    75 	// save heading
    76     s+=valueElement("heading", getHeading(),
    77 		attribut ("textColor",QColor( bo->getColor()).name()));
    78 
    79 /*
    80 	// Save frame
    81 	if (frame->getFrameType()!=FrameObj::NoFrame) 
    82 		s+=frame->saveToDir ();
    83 
    84 	// save names of flags set
    85 	s+=standardFlags->saveToDir(tmpdir,prefix,0);
    86 	
    87 	// Save FloatImages
    88 	for (int i=0; i<floatimage.size(); ++i)
    89 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
    90 */
    91 
    92 	// save note
    93 	if (!note.isEmpty() )
    94 		s+=note.saveToDir();
    95 	
    96 	// Save branches
    97 	TreeItem *ti=getFirstBranch();
    98 	TreeItem *last=getLastBranch();
    99 	while (ti && ti!=last) 
   100 		s+=ti->saveToDir(tmpdir,prefix,offset);
   101 
   102 	/*
   103 	// Save XLinks
   104 	QString ol;	// old link
   105 	QString cl;	// current link
   106 	for (int i=0; i<xlink.size(); ++i)
   107 	{
   108 		cl=xlink.at(i)->saveToDir();
   109 		if (cl!=ol)
   110 		{
   111 			s+=cl;
   112 			ol=cl;
   113 		} else
   114 		{
   115 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   116 		}
   117 	}	
   118 	*/
   119 
   120     decIndent();
   121     s+=endElement   ("branch");
   122     return s;
   123 }
   124 
   125 void BranchItem::unScroll()
   126 {
   127 	if (tmpUnscrolled) resetTmpUnscroll();
   128 	if (scrolled) toggleScroll();
   129 }
   130 
   131 void BranchItem::toggleScroll()
   132 {
   133 	if (scrolled)
   134 	{
   135 		scrolled=false;
   136 		//FIXME-1 systemFlags->deactivate("scrolledright");
   137 		/*
   138 		for (int i=0; i<branch.size(); ++i)
   139 			branch.at(i)->setVisibility(true);
   140 		*/	
   141 	} else
   142 	{
   143 		scrolled=true;
   144 		/*
   145 		//FIXME-1 systemFlags->activate("scrolledright");
   146 		for (int i=0; i<branch.size(); ++i)
   147 			branch.at(i)->setVisibility(false);
   148 		*/	
   149 	}
   150 	/*
   151 	calcBBoxSize();
   152 	positionBBox();	
   153 	move (absPos.x(), absPos.y() );
   154 	forceReposition();
   155 	*/
   156 }
   157 
   158 bool BranchItem::isScrolled()
   159 {
   160 	return scrolled;
   161 }
   162 
   163 bool BranchItem::hasScrolledParent(BranchItem *start)
   164 {
   165 	// Calls parents recursivly to
   166 	// find out, if we are scrolled at all.
   167 	// But ignore myself, just look at parents.
   168 
   169 	if (this !=start && scrolled) return true;
   170 
   171 	BranchItem* bi=(BranchItem*)parentItem;
   172 	if (bi) 
   173 		return bi->hasScrolledParent(start);
   174 	else
   175 		return false;
   176 }
   177 
   178 void BranchItem::tmpUnscroll()
   179 {
   180 	// Unscroll parent (recursivly)
   181 	BranchItem * bi=(BranchItem*)parentItem;
   182 	if (bi) bi->tmpUnscroll();
   183 		
   184 	// Unscroll myself
   185 	if (scrolled)
   186 	{
   187 		tmpUnscrolled=true;
   188 		// FIXME-1 systemFlags->activate("tmpUnscrolledright");
   189 		toggleScroll();
   190 	}	
   191 }
   192 
   193 void BranchItem::resetTmpUnscroll()
   194 {
   195 	// Unscroll parent (recursivly)
   196 	BranchItem * bi=(BranchItem*)parentItem;
   197 	if (bi) bi->resetTmpUnscroll();
   198 		
   199 	// Unscroll myself
   200 	if (tmpUnscrolled)
   201 	{
   202 		tmpUnscrolled=false;
   203 		// FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
   204 		toggleScroll();
   205 	}	
   206 }
   207 
   208