mapcenterobj.cpp
author insilmaril
Wed, 12 Nov 2008 11:15:37 +0000
branchrelease-1-12-maintained
changeset 52 6cd53d63956f
parent 0 7a96bd401351
permissions -rw-r--r--
Fix: Save note of MapCenter
     1 #include <QDateTime>
     2 
     3 #include "floatimageobj.h"
     4 #include "geometry.h"
     5 #include "mapcenterobj.h"
     6 #include "mapeditor.h"
     7 
     8 
     9 /////////////////////////////////////////////////////////////////
    10 // MapCenterObj
    11 /////////////////////////////////////////////////////////////////
    12 MapCenterObj::MapCenterObj() : BranchObj ()
    13 {
    14 //    cout << "Const MapCenterObj\n";
    15     init();
    16 }
    17 
    18 MapCenterObj::MapCenterObj(QGraphicsScene* s) : BranchObj (s)
    19 {
    20 //    cout << "Const MapCenterObj   canvas="<<s<<"\n";
    21     init();
    22 }
    23 
    24 MapCenterObj::~MapCenterObj() 
    25 {
    26 //    cout << "Destr MapCenterObj\n";
    27 	clear();
    28 }	
    29 
    30 void MapCenterObj::clear() 
    31 {
    32 	BranchObj::clear();
    33 }
    34 
    35 void MapCenterObj::init () 
    36 {
    37 	BranchObj::init();
    38     orientation=LinkableMapObj::UndefinedOrientation;
    39 
    40 	// TODO this should be done in TextObj later...
    41 	//QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
    42 	//heading->setFont(font);
    43 	depth=0;
    44 	setDefAttr(MovedBranch);
    45 
    46 	frame->setFrameType (FrameObj::Rectangle);
    47 }
    48 
    49 void MapCenterObj::move (double x, double y)
    50 {
    51 	BranchObj::move(x,y);
    52 }
    53 
    54 void MapCenterObj::move (QPointF absPos)
    55 {
    56 	BranchObj::move(absPos);
    57 }
    58 
    59 void MapCenterObj::moveBy (double x, double y)
    60 {
    61 	BranchObj::moveBy(x,y);
    62 }
    63 
    64 void MapCenterObj::moveAll (double x, double y)
    65 {
    66 	// Get rel. position
    67 	double dx=x-absPos.x();
    68 	double dy=y-absPos.y();
    69 
    70 	// Move myself and branches
    71 	moveAllBy (dx,dy);
    72 }
    73 
    74 void MapCenterObj::moveAllBy (double dx, double dy)
    75 {
    76 	// Move myself and childs
    77 	BranchObj::moveBy(dx,dy);
    78 }
    79 
    80 void MapCenterObj::updateLink()
    81 {
    82 	// set childPos to middle of MapCenterObj
    83 	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
    84 	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
    85 	parPos=childPos;		
    86 	for (int i=0; i<branch.size(); ++i)
    87 		branch.at(i)->updateLink();
    88 }
    89 
    90 void MapCenterObj::updateRelPositions()
    91 {
    92 	if (repositionRequest) unsetAllRepositionRequests();
    93 
    94 	// update relative Positions of branches and floats
    95 	for (int i=0; i<branch.size(); ++i)
    96 	{
    97 		branch.at(i)->setRelPos();
    98 		branch.at(i)->setOrientation();
    99 	}
   100 	
   101 	for (int i=0; i<floatimage.size(); ++i)
   102 		floatimage.at(i)->setRelPos();
   103 
   104 	if (repositionRequest) reposition();
   105 }
   106 
   107 LinkableMapObj* MapCenterObj::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
   108 	{
   109 	LinkableMapObj *lmo;
   110 
   111 	// Search through child branches
   112 	for (int i=0; i<branch.size(); ++i)
   113 	{	
   114 		lmo = branch.at(i)->findMapObj(p, excludeLMO);
   115 		if (lmo!= NULL) return lmo;
   116 	}
   117 	// is p in MapCenter?
   118 	if (inBox (p,clickBox) && (this != excludeLMO) ) return this;
   119 
   120 	// Search float images
   121 	for (int i=0; i<floatimage.size(); ++i)
   122 		if (inBox(p,floatimage.at(i)->getClickBox()) && (floatimage.at(i) != excludeLMO) && floatimage.at(i)->getParObj()!= excludeLMO) return floatimage.at(i);
   123 
   124 	// nothing found
   125 	return NULL;
   126 }
   127 
   128 QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
   129 {
   130     QString s,a;
   131 
   132 	// save area, if not scrolled
   133 	QString areaAttr=
   134 		attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   135 		attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   136 		attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   137 		attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   138 	
   139 	// Providing an ID for a branch makes export to XHTML easier
   140 	QString idAttr;
   141 	if (countXLinks()>0)
   142 		idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
   143 
   144 	else
   145 		idAttr="";
   146 
   147 	QString linkAttr=getLinkAttr();
   148 
   149     s=beginElement ("mapcenter" 
   150 		+getOrnXMLAttr() 
   151 		+areaAttr 
   152 		+idAttr 
   153 		+getIncludeImageAttr() );
   154     incIndent();
   155     if (heading->getColor()!=QColor("black"))
   156 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   157     else	
   158 		a="";
   159     
   160 	// Save flags. If verbose is set (export to xml dir), also write
   161 	// the flags as picture
   162 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   163 
   164 	// Save heading
   165     s+=valueElement("heading", getHeading(),a);
   166 
   167 	// Save frame
   168 	s+=frame->saveToDir ();
   169 
   170 	// Update of note is usually done while unselecting a branch
   171 	if (isNoteInEditor) getNoteFromTextEditor();
   172 
   173 	// save note
   174 	if (!note.isEmpty() )
   175 		s+=note.saveToDir();
   176 	
   177 	// Save branches
   178 	for (int i=0; i<branch.size(); ++i)
   179 		s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
   180 
   181 	// Save FloatImages
   182 	for (int i=0; i<floatimage.size(); ++i)
   183 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   184 
   185 	// Save XLinks
   186 	for (int i=0;i<xlink.size(); ++i)
   187 		s+=xlink.at(i)->saveToDir();
   188 
   189     decIndent();
   190     s+=endElement   ("mapcenter");
   191     return s;
   192 }
   193 
   194 void MapCenterObj::setVersion (const QString &s)
   195 {
   196 	version=s;
   197 }
   198 
   199 void MapCenterObj::setAuthor (const QString &s)
   200 {
   201 	author=s;
   202 }
   203 
   204 QString MapCenterObj::getAuthor()
   205 {
   206 	return author;
   207 }
   208 
   209 void MapCenterObj::setComment (const QString &s)
   210 {
   211 	comment=s;
   212 }
   213 
   214 QString MapCenterObj::getComment ()
   215 {
   216 	return comment;
   217 }
   218 
   219 QString MapCenterObj::getDate ()
   220 {
   221 	return QDate::currentDate().toString ("yyyy-MM-dd");
   222 }
   223