diff -r 7a96bd401351 -r 79b0656dbe7d mapcenterobj.cpp --- a/mapcenterobj.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/mapcenterobj.cpp Thu Dec 04 13:47:47 2008 +0000 @@ -1,9 +1,11 @@ -#include +#include +#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="<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; iupdateLink(); } -LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO) +void MapCenterObj::updateRelPositions() +{ + if (repositionRequest) unsetAllRepositionRequests(); + + // update relative Positions of branches and floats + for (int i=0; isetRelPos(); + branch.at(i)->setOrientation(); + } + + for (int i=0; isetRelPos(); + + 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; ifindMapObj(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; igetClickBox()) && (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; isaveToDir(tmpdir,prefix, offset); + // Save FloatImages - FloatImageObj *fio; - for (fio=floatimage.first(); fio; fio=floatimage.next() ) - s+=fio->saveToDir (tmpdir,prefix); + for (int i=0; isaveToDir (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;isaveToDir(); 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"); } +