1.7.6 New features for floatimages and fixes
authorinsilmaril
Tue, 03 Jan 2006 09:44:41 +0000
changeset 169aa48c7b52549
parent 168 8814a667241a
child 170 e696dd4a100f
1.7.6 New features for floatimages and fixes
branchobj.cpp
branchobj.h
demos/math.vym
demos/todo.vym
mapcenterobj.cpp
xml.cpp
xml.h
     1.1 --- a/branchobj.cpp	Tue Jan 03 09:44:41 2006 +0000
     1.2 +++ b/branchobj.cpp	Tue Jan 03 09:44:41 2006 +0000
     1.3 @@ -102,6 +102,9 @@
     1.4  	scrolled=false;
     1.5  	tmpUnscrolled=false;
     1.6  
     1.7 +	includeImagesVer=false;
     1.8 +	includeImagesHor=false;
     1.9 +
    1.10  	url="";
    1.11  	vymLink="";
    1.12  }
    1.13 @@ -544,6 +547,9 @@
    1.14  void BranchObj::move (double x, double y)
    1.15  {
    1.16  	OrnamentedObj::move (x,y);
    1.17 +	FloatImageObj *fio;
    1.18 +    for (fio=floatimage.first(); fio; fio=floatimage.next() )
    1.19 +		fio->reposition();
    1.20      positionBBox();
    1.21  }
    1.22  
    1.23 @@ -577,17 +583,13 @@
    1.24  		cout << "BO::positionBBox (noHeading)\n";
    1.25  */		
    1.26  
    1.27 -	// Position contents by moving OO
    1.28 -	OrnamentedObj::move (absPos.x(),absPos.y());
    1.29 - 
    1.30 -	// It seems that setting x,y also affects width,height
    1.31 -	int w_old=bbox.width();
    1.32 -	int h_old=bbox.height();
    1.33 -    bbox.setX (absPos.x() );
    1.34 -	bbox.setY (absPos.y() );
    1.35 -	bbox.setWidth(w_old);
    1.36 -	bbox.setHeight(h_old);
    1.37 +	positionContents();
    1.38 +
    1.39 +	int d=frame->getBorder()/2;
    1.40  	
    1.41 +	bbox.moveTopLeft (QPoint (absPos.x(), absPos.y() - topPad));
    1.42 +	clickBox.moveTopLeft(QPoint (absPos.x()+d, absPos.y()+d ));
    1.43 +
    1.44  	setSelBox();
    1.45  
    1.46  	// set the frame
    1.47 @@ -619,8 +621,38 @@
    1.48  	h=max (sysflags_h,stanflags_h);
    1.49  	h=max (h,heading_h);
    1.50  
    1.51 +    clickBox.setSize (QSize (w,h));
    1.52 +
    1.53 +	// Floatimages 
    1.54 +	QPoint rp;
    1.55 +	FloatImageObj *foi;
    1.56 +
    1.57 +	topPad=botPad=leftPad=rightPad=0;
    1.58 +	if (includeImagesVer || includeImagesHor)
    1.59 +	{
    1.60 +		if (countFloatImages()>0)
    1.61 +		{
    1.62 +			for (foi=floatimage.first(); foi; foi=floatimage.next() )
    1.63 +			{
    1.64 +				rp=foi->getRelPos();
    1.65 +				if (includeImagesVer)
    1.66 +				{
    1.67 +					if (rp.y() < 0) 
    1.68 +						topPad=max (topPad,-rp.y());
    1.69 +					if (rp.y()+foi->height() > h)
    1.70 +						botPad=max (botPad,rp.y()+foi->height()-h);
    1.71 +				}		
    1.72 +			}	
    1.73 +		}	
    1.74 +		
    1.75 +		h+=topPad+botPad;
    1.76 +	}
    1.77 +
    1.78 +	// Frame thickness
    1.79      w+=frame->getBorder();
    1.80      h+=frame->getBorder();
    1.81 +	
    1.82 +	// Finally set size
    1.83      bbox.setSize (QSize (w,h));
    1.84  }
    1.85  
    1.86 @@ -636,13 +668,13 @@
    1.87      }
    1.88  	
    1.89  	// Search myself
    1.90 -    if (inBBox (p) && (this != excludeLMO) && isVisibleObj() ) 
    1.91 +    if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) 
    1.92  		return this;
    1.93  
    1.94  	// Search float images
    1.95  	FloatImageObj *foi;
    1.96      for (foi=floatimage.first(); foi; foi=floatimage.next() )
    1.97 -		if (foi->inBBox(p) && 
    1.98 +		if (foi->inBox(p) && 
    1.99  			(foi != excludeLMO) && 
   1.100  			foi->getParObj()!= excludeLMO &&
   1.101  			foi->isVisibleObj() 
   1.102 @@ -653,11 +685,6 @@
   1.103  
   1.104  void BranchObj::setHeading(QString s)
   1.105  {
   1.106 -/* FIXME testing only
   1.107 -	cout << "BO::setHeading ("<<s<<")\n";
   1.108 -	cout << "   bo.pos="<<absPos<<endl;
   1.109 -	cout << "   ho.pos="<<heading->getPos()<<endl;
   1.110 -*/	
   1.111      heading->setText(s);	// set new heading
   1.112  	calcBBoxSize();			// recalculate bbox
   1.113      positionBBox();			// rearrange contents
   1.114 @@ -732,7 +759,8 @@
   1.115  	else
   1.116  		posAttr="";
   1.117  
   1.118 -	QString linkAttr=getLinkAttr();
   1.119 +	QString linkAttr=getLinkAttr()+" "+getIncludeImageAttr();
   1.120 +	
   1.121  
   1.122  	QString urlAttr;
   1.123  	if (!url.isEmpty())
   1.124 @@ -761,7 +789,14 @@
   1.125  	} else
   1.126  		areaAttr="";
   1.127  	
   1.128 -    s=beginElement ("branch" +scrolledAttr +posAttr +linkAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr );
   1.129 +	// Providing an ID for a branch makes export to XHTML easier
   1.130 +	QString idAttr;
   1.131 +	if (countXLinks()>0)
   1.132 +		idAttr=attribut ("id",getSelectString());
   1.133 +	else
   1.134 +		idAttr="";
   1.135 +
   1.136 +    s=beginElement ("branch" +scrolledAttr +posAttr +linkAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr +idAttr);
   1.137      incIndent();
   1.138  
   1.139  	// save heading
   1.140 @@ -837,6 +872,48 @@
   1.141  		return NULL;
   1.142  }
   1.143  
   1.144 +void BranchObj::setIncludeImagesVer(bool b)
   1.145 +{
   1.146 +	includeImagesVer=b;
   1.147 +	calcBBoxSize();
   1.148 +	positionBBox();
   1.149 +	requestReposition();
   1.150 +	// FIMXE undo needed
   1.151 +}
   1.152 +
   1.153 +bool BranchObj::getIncludeImagesVer()
   1.154 +{
   1.155 +	return includeImagesVer;
   1.156 +}
   1.157 +
   1.158 +void BranchObj::setIncludeImagesHor(bool b)
   1.159 +{
   1.160 +	includeImagesHor=b;
   1.161 +	calcBBoxSize();
   1.162 +	positionBBox();
   1.163 +	requestReposition();
   1.164 +	// FIMXE undo needed
   1.165 +}
   1.166 +
   1.167 +bool BranchObj::getIncludeImagesHor()
   1.168 +{
   1.169 +	return includeImagesHor;
   1.170 +}
   1.171 +
   1.172 +QString BranchObj::getIncludeImageAttr()
   1.173 +{
   1.174 +	QString a;
   1.175 +	if (includeImagesVer)
   1.176 +		a=attribut ("incImgV","true");
   1.177 +	else
   1.178 +		a=attribut ("incImgV","false");
   1.179 +	if (includeImagesHor)
   1.180 +		a+=" "+attribut ("incImgH","true");
   1.181 +	else
   1.182 +		a+=" "+attribut ("incImgH","false");
   1.183 +	return a;	
   1.184 +}
   1.185 +
   1.186  LinkableMapObj* BranchObj::addFloatImage ()
   1.187  {
   1.188  	FloatImageObj *newfi=new FloatImageObj (canvas,this);
   1.189 @@ -845,8 +922,11 @@
   1.190  		newfi->setVisibility (false);
   1.191  	else	
   1.192  		newfi->setVisibility(visible);
   1.193 +	calcBBoxSize();
   1.194 +	positionBBox();
   1.195  	requestReposition();
   1.196  	return newfi;
   1.197 +	// FIMXE undo needed
   1.198  }
   1.199  
   1.200  LinkableMapObj* BranchObj::addFloatImage (FloatImageObj *fio)
   1.201 @@ -858,8 +938,11 @@
   1.202  		newfi->setVisibility (false);
   1.203  	else	
   1.204  		newfi->setVisibility(visible);
   1.205 +	calcBBoxSize();
   1.206 +	positionBBox();
   1.207  	requestReposition();
   1.208  	return newfi;
   1.209 +	// FIMXE undo needed
   1.210  }
   1.211  
   1.212  FloatImageObj* BranchObj::getFirstFloatImage ()
   1.213 @@ -880,7 +963,10 @@
   1.214  void BranchObj::removeFloatImage (FloatImageObj *fio)
   1.215  {
   1.216  	floatimage.remove (fio);
   1.217 +	calcBBoxSize();
   1.218 +	positionBBox();
   1.219  	requestReposition();
   1.220 +	// FIMXE undo needed
   1.221  }
   1.222  
   1.223  void BranchObj::savePosInAngle ()
   1.224 @@ -1129,14 +1215,19 @@
   1.225  
   1.226  void BranchObj::alignRelativeTo (QPoint ref)
   1.227  {
   1.228 +	int th = bboxTotal.height();	
   1.229  /* TODO testing
   1.230  	if (!getHeading().isEmpty())
   1.231  		cout << "BO::alignRelTo "<<getHeading()<<endl;
   1.232  	else	
   1.233  		cout << "BO::alignRelTo  ???"<<endl;
   1.234 -	cout << "  d="<<depth<<endl;
   1.235 +	cout << "  d="<<depth<<
   1.236 +	//	"  ref="<<ref<<
   1.237 +	//	"  bbTot="<<bboxTotal.topLeft()<<
   1.238 +	//	"  absPos="<<absPos<<
   1.239 +		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   1.240 +		"  th="<<th<<endl;
   1.241  */	
   1.242 -	int th = bboxTotal.height();	
   1.243  
   1.244  	// If I am the mapcenter or a mainbranch, reposition heading
   1.245  	if (depth<2)
   1.246 @@ -1149,7 +1240,7 @@
   1.247  			// around mapcenter 
   1.248  			angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
   1.249  									(int)(y() - parObj->getChildPos().y() ) ) );
   1.250 -		}	
   1.251 +		} 
   1.252  	} 
   1.253  	else
   1.254      {
   1.255 @@ -1158,10 +1249,10 @@
   1.256  		switch (orientation) 
   1.257  		{
   1.258  			case OrientLeftOfCenter:
   1.259 -				move (ref.x()-bbox.width(), ref.y() + (th-bbox.height())/2 );
   1.260 +				move (ref.x()-bbox.width(), ref.y() + (th-bbox.height())/2 +topPad);
   1.261  			break;
   1.262  			case OrientRightOfCenter:	
   1.263 -				move (ref.x(), ref.y() + (th-bbox.height())/2 );
   1.264 +				move (ref.x(), ref.y() + (th-bbox.height())/2 + topPad);
   1.265  			break;
   1.266  			default:
   1.267  				cout <<"LMO::alignRelativeTo: oops, no orientation given...\n";
   1.268 @@ -1169,10 +1260,6 @@
   1.269  		}		
   1.270      }		
   1.271  
   1.272 -	FloatImageObj *fio;
   1.273 -    for (fio=floatimage.first(); fio; fio=floatimage.next() )
   1.274 -		fio->reposition();
   1.275 -
   1.276  	if (scrolled) return;
   1.277  
   1.278      // Set reference point for alignment of childs
   1.279 @@ -1214,6 +1301,10 @@
   1.280  	    alignRelativeTo ( QPoint (absPos.x(),
   1.281  			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   1.282  		branch.sort();	
   1.283 +
   1.284 +		// After load, the floats might be at wrong position, force
   1.285 +		// them to move, too
   1.286 +		move (absPos);
   1.287  	} else
   1.288  	{
   1.289  		// This is only important for moving branches:
   1.290 @@ -1247,14 +1338,14 @@
   1.291  }
   1.292  
   1.293  void BranchObj::calcBBoxSizeWithChilds()
   1.294 -{
   1.295 -	// This is called only from reposition and
   1.296 +{	
   1.297 +	// This is initially called only from reposition and
   1.298  	// and only for mapcenter. So it won't be
   1.299  	// called more than once for a single user 
   1.300  	// action
   1.301  	
   1.302 +
   1.303  	// Calculate size of LMO including all childs (to align them later)
   1.304 -
   1.305  	bboxTotal.setX(bbox.x() );
   1.306  	bboxTotal.setY(bbox.y() );
   1.307  
   1.308 @@ -1287,8 +1378,10 @@
   1.309  		bboxTotal.setWidth (bbox.width() + r.width() );
   1.310  	else	
   1.311  		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   1.312 -	bboxTotal.setHeight(max (r.height(),  bbox.height() ) );
   1.313 +	
   1.314 +	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   1.315  //	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   1.316 +
   1.317  }
   1.318  
   1.319  void BranchObj::select()
     2.1 --- a/branchobj.h	Tue Jan 03 09:44:41 2006 +0000
     2.2 +++ b/branchobj.h	Tue Jan 03 09:44:41 2006 +0000
     2.3 @@ -73,6 +73,11 @@
     2.4  	virtual XLinkObj* XLinkAt (int);		// return reference of XLinkObj 
     2.5  	virtual int countXLink ();
     2.6  	virtual BranchObj* XLinkTargetAt (int);
     2.7 +	void setIncludeImagesVer(bool);
     2.8 +	bool getIncludeImagesVer();
     2.9 +	void setIncludeImagesHor(bool);
    2.10 +	bool getIncludeImagesHor();
    2.11 +	QString getIncludeImageAttr();
    2.12  	virtual LinkableMapObj* addFloatImage();
    2.13  	virtual LinkableMapObj* addFloatImage(FloatImageObj*);
    2.14  	virtual void removeFloatImage(FloatImageObj*);
    2.15 @@ -125,6 +130,9 @@
    2.16  	bool tmpUnscrolled;				// can only be true (temporary) for a scrolled subtree
    2.17  	QString url;					// url to external doc
    2.18  	QString vymLink;				// path to another map
    2.19 +	bool includeImagesVer;			// include floatimages in bbox vertically
    2.20 +	bool includeImagesHor;			// include floatimages in bbox horizontally
    2.21 +
    2.22  };
    2.23  
    2.24  
     3.1 Binary file demos/math.vym has changed
     4.1 Binary file demos/todo.vym has changed
     5.1 --- a/mapcenterobj.cpp	Tue Jan 03 09:44:41 2006 +0000
     5.2 +++ b/mapcenterobj.cpp	Tue Jan 03 09:44:41 2006 +0000
     5.3 @@ -46,13 +46,11 @@
     5.4  void MapCenterObj::move (double x, double y)
     5.5  {
     5.6  	BranchObj::move(x,y);
     5.7 -	positionBBox();
     5.8  }
     5.9  
    5.10  void MapCenterObj::moveBy (double x, double y)
    5.11  {
    5.12 -	//BranchObj::moveBy(x,y);
    5.13 -	move (x+absPos.x(),y+absPos.y() );
    5.14 +	BranchObj::moveBy(x,y);
    5.15  	positionBBox();
    5.16  }
    5.17  
    5.18 @@ -77,9 +75,8 @@
    5.19  void MapCenterObj::updateLink()
    5.20  {
    5.21  	// set childPos to middle of MapCenterObj
    5.22 -	childPos=QPoint(
    5.23 -		absPos.x() + QSize(getSize() ).width()/2, 
    5.24 -		absPos.y() + QSize(getSize() ).height()/2);
    5.25 +	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
    5.26 +	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
    5.27  	parPos=childPos;		
    5.28  	BranchObj *b;
    5.29  	for (b=branch.first(); b; b=branch.next() )
    5.30 @@ -95,19 +92,15 @@
    5.31  	for (bo=branch.first(); bo; bo=branch.next() )
    5.32  	{	
    5.33  		lmo = bo->findMapObj(p, excludeLMO);
    5.34 -		
    5.35 -		if (lmo!= NULL) 
    5.36 -		{
    5.37 -			return lmo;
    5.38 -		}	
    5.39 +		if (lmo!= NULL) return lmo;
    5.40  	}
    5.41  	// is p in MapCenter?
    5.42 -	if (inBBox (p) && (this != excludeLMO) ) return this;
    5.43 +	if (inBox (p) && (this != excludeLMO) ) return this;
    5.44  
    5.45  	// Search float images
    5.46  	FloatImageObj *foi;
    5.47  	for (foi=floatimage.first(); foi; foi=floatimage.next() )
    5.48 -		if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
    5.49 +		if (foi->inBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
    5.50  
    5.51  	// nothing found
    5.52  	return NULL;
    5.53 @@ -124,9 +117,29 @@
    5.54  		attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
    5.55  		attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
    5.56  	
    5.57 +	// Providing an ID for a branch makes export to XHTML easier
    5.58 +	QString idAttr;
    5.59 +	if (countXLinks()>0)
    5.60 +		idAttr=attribut ("id",getSelectString());
    5.61 +	else
    5.62 +		idAttr="";
    5.63 +
    5.64 +	QString linkAttr=getLinkAttr();
    5.65 +
    5.66 +	QString urlAttr;
    5.67 +	if (!url.isEmpty())
    5.68 +		urlAttr=attribut ("url",url);
    5.69 +	QString vymLinkAttr;
    5.70 +	if (!vymLink.isEmpty())
    5.71 +		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
    5.72 +
    5.73      s=beginElement ("mapcenter" 
    5.74  		+attribut("absPosX",QString().setNum(absPos.x(),10))
    5.75  		+attribut("absPosY",QString().setNum(absPos.y(),10))
    5.76 +		+vymLinkAttr
    5.77 +		+urlAttr
    5.78 +		+linkAttr
    5.79 +		+idAttr
    5.80  		+attribut("frameType",frame->getFrameTypeName()) 
    5.81  		+areaAttr 
    5.82  		);
     6.1 --- a/xml.cpp	Tue Jan 03 09:44:41 2006 +0000
     6.2 +++ b/xml.cpp	Tue Jan 03 09:44:41 2006 +0000
     6.3 @@ -420,7 +420,7 @@
     6.4  		{
     6.5  			x=a.value("absPosX").toInt (&okx, 10);
     6.6  			y=a.value("absPosY").toInt (&oky, 10);
     6.7 -			if (okx && oky) 
     6.8 +			if (okx && oky  )
     6.9  				lastBranch->move(x,y);
    6.10  			else
    6.11  				return false;   // Couldn't read absPos
    6.12 @@ -434,16 +434,26 @@
    6.13  		lastBranch->setVymLink (a.value ("vymLink"));
    6.14  	if (!a.value( "frameType").isEmpty() ) 
    6.15  		lastBranch->setFrameType (a.value("frameType"));
    6.16 +
    6.17 +	if (!a.value( "incImgV").isEmpty() ) 
    6.18 +		lastBranch->setIncludeImagesVer(a.value("incImgV"));
    6.19 +	if (!a.value( "incImgH").isEmpty() ) 
    6.20 +		lastBranch->setIncludeImagesHor(a.value("incImgH"));
    6.21  	return true;	
    6.22  }
    6.23  
    6.24  bool mapBuilderHandler::readLinkAttr (const QXmlAttributes& a)
    6.25  {
    6.26 -	if (!a.value( "hideLinkUnselected").isEmpty()) 
    6.27 +	if (lastLMO)
    6.28  	{
    6.29 -		if (a.value ("hideLinkUnselected") =="true")
    6.30 -			if (lastLMO) lastLMO->setHideLinkUnselected(true);
    6.31 -	}	
    6.32 +		if (!a.value( "hideLink").isEmpty()) 
    6.33 +		{
    6.34 +			if (a.value ("hideLink") =="true")
    6.35 +				lastLMO->setHideLinkUnselected(true);
    6.36 +			else	
    6.37 +				lastLMO->setHideLinkUnselected(false);
    6.38 +		}	
    6.39 +	}
    6.40  	return true;	
    6.41  }
    6.42  
    6.43 @@ -496,7 +506,6 @@
    6.44  bool mapBuilderHandler::readFloatImageAttr (const QXmlAttributes& a)
    6.45  {
    6.46  	lastLMO=lastFloat;
    6.47 -	if (!readLinkAttr(a)) return false;
    6.48  	
    6.49  	if (!a.value( "useOrientation").isEmpty() ) 
    6.50  	{
    6.51 @@ -520,7 +529,7 @@
    6.52  	}	
    6.53  	if (!a.value( "floatExport").isEmpty() ) 
    6.54  	{
    6.55 -		if (a.value ("floatExpofrt") =="true")
    6.56 +		if (a.value ("floatExport") =="true")
    6.57  			lastFloat->setFloatExport (true);
    6.58  		else	
    6.59  			lastFloat->setFloatExport (false);
    6.60 @@ -543,6 +552,9 @@
    6.61  				return false;  
    6.62  		}           
    6.63  	}	
    6.64 +	
    6.65 +	if (!readLinkAttr(a)) return false;
    6.66 +
    6.67  	return true;
    6.68  }
    6.69  
     7.1 --- a/xml.h	Tue Jan 03 09:44:41 2006 +0000
     7.2 +++ b/xml.h	Tue Jan 03 09:44:41 2006 +0000
     7.3 @@ -5,6 +5,7 @@
     7.4  #include <qstring.h>
     7.5  #include <qxml.h>
     7.6  
     7.7 +#include "file.h"
     7.8  #include "mapcenterobj.h"
     7.9  #include "mapeditor.h"
    7.10