# HG changeset patch
# User insilmaril
# Date 1226488537 0
# Node ID 6cd53d63956fd4b08937759d1e441c79920537c7
# Parent  b2224ebf331f2fe5427dc4a5fd0e9edd33a43e12
Fix: Save note of MapCenter

diff -r b2224ebf331f -r 6cd53d63956f mapcenterobj.cpp
--- a/mapcenterobj.cpp	Mon Oct 06 12:28:25 2008 +0000
+++ b/mapcenterobj.cpp	Wed Nov 12 11:15:37 2008 +0000
@@ -1,9 +1,11 @@
-#include <qdatetime.h>
+#include <QDateTime>
 
+#include "floatimageobj.h"
+#include "geometry.h"
 #include "mapcenterobj.h"
-#include "floatimageobj.h"
 #include "mapeditor.h"
 
+
 /////////////////////////////////////////////////////////////////
 // MapCenterObj
 /////////////////////////////////////////////////////////////////
@@ -13,54 +15,50 @@
     init();
 }
 
-MapCenterObj::MapCenterObj(QCanvas* c) : BranchObj (c)
+MapCenterObj::MapCenterObj(QGraphicsScene* s) : BranchObj (s)
 {
-//    cout << "Const MapCenterObj   canvas="<<c<<"\n";
+//    cout << "Const MapCenterObj   canvas="<<s<<"\n";
     init();
 }
 
 MapCenterObj::~MapCenterObj() 
 {
 //    cout << "Destr MapCenterObj\n";
+	clear();
 }	
 
 void MapCenterObj::clear() 
 {
 	BranchObj::clear();
-    init();
 }
 
 void MapCenterObj::init () 
 {
-    orientation=OrientUndef;
-    absPos=QPoint (canvas->width()/2, canvas->height()/2);
+	BranchObj::init();
+    orientation=LinkableMapObj::UndefinedOrientation;
 
-	// FIXME this should be done in TextObj later...
-	QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
-	heading->setFont(font);
+	// TODO this should be done in TextObj later...
+	//QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
+	//heading->setFont(font);
+	depth=0;
+	setDefAttr(MovedBranch);
 
-	branch.setAutoDelete (TRUE);
-	floatimage.setAutoDelete (TRUE);
-
-	move (absPos.x(), absPos.y() );
-	depth=0;
-
-	scrolled=false;
-	tmpUnscrolled=false;
-
-	frame->setFrameType (Rectangle);
+	frame->setFrameType (FrameObj::Rectangle);
 }
 
 void MapCenterObj::move (double x, double y)
 {
 	BranchObj::move(x,y);
-	positionBBox();
+}
+
+void MapCenterObj::move (QPointF absPos)
+{
+	BranchObj::move(absPos);
 }
 
 void MapCenterObj::moveBy (double x, double y)
 {
 	BranchObj::moveBy(x,y);
-	positionBBox();
 }
 
 void MapCenterObj::moveAll (double x, double y)
@@ -75,69 +73,84 @@
 
 void MapCenterObj::moveAllBy (double dx, double dy)
 {
-	// Move myself
-	moveBy(dx,dy);
-
-	positionBBox();
+	// Move myself and childs
+	BranchObj::moveBy(dx,dy);
 }
 
 void MapCenterObj::updateLink()
 {
 	// set childPos to middle of MapCenterObj
-	childPos=QPoint(
-		absPos.x() + QSize(getSize() ).width()/2, 
-		absPos.y() + QSize(getSize() ).height()/2);
+	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
+	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
 	parPos=childPos;		
-	BranchObj *b;
-	for (b=branch.first(); b; b=branch.next() )
-		b->updateLink();
+	for (int i=0; i<branch.size(); ++i)
+		branch.at(i)->updateLink();
 }
 
-LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
+void MapCenterObj::updateRelPositions()
+{
+	if (repositionRequest) unsetAllRepositionRequests();
+
+	// update relative Positions of branches and floats
+	for (int i=0; i<branch.size(); ++i)
 	{
-	BranchObj *bo;
+		branch.at(i)->setRelPos();
+		branch.at(i)->setOrientation();
+	}
+	
+	for (int i=0; i<floatimage.size(); ++i)
+		floatimage.at(i)->setRelPos();
+
+	if (repositionRequest) reposition();
+}
+
+LinkableMapObj* MapCenterObj::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
+	{
 	LinkableMapObj *lmo;
 
 	// Search through child branches
-	for (bo=branch.first(); bo; bo=branch.next() )
+	for (int i=0; i<branch.size(); ++i)
 	{	
-		lmo = bo->findMapObj(p, excludeLMO);
-		
-		if (lmo!= NULL) 
-		{
-			return lmo;
-		}	
+		lmo = branch.at(i)->findMapObj(p, excludeLMO);
+		if (lmo!= NULL) return lmo;
 	}
 	// is p in MapCenter?
-	if (inBBox (p) && (this != excludeLMO) ) return this;
+	if (inBox (p,clickBox) && (this != excludeLMO) ) return this;
 
 	// Search float images
-	FloatImageObj *foi;
-	for (foi=floatimage.first(); foi; foi=floatimage.next() )
-		if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
+	for (int i=0; i<floatimage.size(); ++i)
+		if (inBox(p,floatimage.at(i)->getClickBox()) && (floatimage.at(i) != excludeLMO) && floatimage.at(i)->getParObj()!= excludeLMO) return floatimage.at(i);
 
 	// nothing found
 	return NULL;
 }
 
-QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
+QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
 {
     QString s,a;
 
 	// save area, if not scrolled
 	QString areaAttr=
-		attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
-		attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
-		attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
-		attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
+		attribut("x1",QString().setNum(absPos.x()-offset.x())) +
+		attribut("y1",QString().setNum(absPos.y()-offset.y())) +
+		attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
+		attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
 	
+	// Providing an ID for a branch makes export to XHTML easier
+	QString idAttr;
+	if (countXLinks()>0)
+		idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
+
+	else
+		idAttr="";
+
+	QString linkAttr=getLinkAttr();
+
     s=beginElement ("mapcenter" 
-		+attribut("absPosX",QString().setNum(absPos.x(),10))
-		+attribut("absPosY",QString().setNum(absPos.y(),10))
-		+attribut("frameType",frame->getFrameTypeName()) 
+		+getOrnXMLAttr() 
 		+areaAttr 
-		);
-		
+		+idAttr 
+		+getIncludeImageAttr() );
     incIndent();
     if (heading->getColor()!=QColor("black"))
 		a=attribut ("textColor",QColor(heading->getColor()).name() );
@@ -147,24 +160,31 @@
 	// Save flags. If verbose is set (export to xml dir), also write
 	// the flags as picture
 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
-    s=s+valueElement("heading", getHeading(),a);
 
-	// Reset the counters before saving
-	FloatImageObj (canvas).resetSaveCounter();
+	// Save heading
+    s+=valueElement("heading", getHeading(),a);
 
-	// add link to file in s
+	// Save frame
+	s+=frame->saveToDir ();
+
+	// Update of note is usually done while unselecting a branch
+	if (isNoteInEditor) getNoteFromTextEditor();
+
+	// save note
 	if (!note.isEmpty() )
 		s+=note.saveToDir();
 	
+	// Save branches
+	for (int i=0; i<branch.size(); ++i)
+		s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
+
 	// Save FloatImages
-	FloatImageObj *fio;
-	for (fio=floatimage.first(); fio; fio=floatimage.next() )
-		s+=fio->saveToDir (tmpdir,prefix);
+	for (int i=0; i<floatimage.size(); ++i)
+		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
 
-	// Save branches
-    BranchObj *bo;
-    for (bo=branch.first(); bo; bo=branch.next() )
-		s+=bo->saveToDir(tmpdir,prefix, offset);
+	// Save XLinks
+	for (int i=0;i<xlink.size(); ++i)
+		s+=xlink.at(i)->saveToDir();
 
     decIndent();
     s+=endElement   ("mapcenter");
@@ -176,39 +196,6 @@
 	version=s;
 }
 
-bool MapCenterObj::checkVersion ()
-{
-	// returns true, if vym is able to read file regarding 
-	// the version set with setVersion
-	QString s1=version.section (".",0,0);
-	QString s2=version.section (".",1,1);
-	QString s3=version.section (".",2,2);
-	bool ok;
-	int vv1 =QString(__VYM_VERSION__).section (".",0,0).toInt(&ok,10);
-	int vv2 =QString(__VYM_VERSION__).section (".",1,1).toInt(&ok,10);
-	int vv3 =QString(__VYM_VERSION__).section (".",2,2).toInt(&ok,10);
-	int mv1=0;
-	int mv2=0;
-	int mv3=0;
-	if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
-	if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
-	if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
-	
-	if (vv1 > mv1)
-		return true;
-	if (vv1 < mv1)
-		return false;
-	if (vv2 > mv2)
-		return true;
-	if (vv2 < mv2)
-		return false;
-	if (vv3 > mv3)
-		return true;
-	if (vv3 < mv3)
-		return false;
-	return true;	
-}
-
 void MapCenterObj::setAuthor (const QString &s)
 {
 	author=s;
@@ -233,3 +220,4 @@
 {
 	return QDate::currentDate().toString ("yyyy-MM-dd");
 }
+
diff -r b2224ebf331f -r 6cd53d63956f version.h
--- a/version.h	Mon Oct 06 12:28:25 2008 +0000
+++ b/version.h	Wed Nov 12 11:15:37 2008 +0000
@@ -5,9 +5,9 @@
 
 #define __VYM_NAME "VYM"
 #define __VYM_VERSION "1.12.2"
-#define __VYM_CODENAME "Maintenance Update"
+#define __VYM_CODENAME "Maintenance Update a"
 //#define __VYM_CODENAME "Codename: development version"
-#define __VYM_BUILD_DATE "2008-10-05"
+#define __VYM_BUILD_DATE "2008-11-12"
 
 
 bool checkVersion(const QString &);