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