mapcenterobj.cpp
author insilmaril
Fri, 11 Jul 2008 12:36:39 +0000
changeset 715 c7f2d53c98d1
parent 681 4e558a15a804
child 721 12958f987bcf
permissions -rw-r--r--
Fix for umlauts in paths
     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 	// add link to file in s
   171 	if (!note.isEmpty() )
   172 		s+=note.saveToDir();
   173 	
   174 	// Save branches
   175 	for (int i=0; i<branch.size(); ++i)
   176 		s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
   177 
   178 	// Save FloatImages
   179 	for (int i=0; i<floatimage.size(); ++i)
   180 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   181 
   182 	// Save XLinks
   183 	for (int i=0;i<xlink.size(); ++i)
   184 		s+=xlink.at(i)->saveToDir();
   185 
   186     decIndent();
   187     s+=endElement   ("mapcenter");
   188     return s;
   189 }
   190 
   191 void MapCenterObj::setVersion (const QString &s)
   192 {
   193 	version=s;
   194 }
   195 
   196 void MapCenterObj::setAuthor (const QString &s)
   197 {
   198 	author=s;
   199 }
   200 
   201 QString MapCenterObj::getAuthor()
   202 {
   203 	return author;
   204 }
   205 
   206 void MapCenterObj::setComment (const QString &s)
   207 {
   208 	comment=s;
   209 }
   210 
   211 QString MapCenterObj::getComment ()
   212 {
   213 	return comment;
   214 }
   215 
   216 QString MapCenterObj::getDate ()
   217 {
   218 	return QDate::currentDate().toString ("yyyy-MM-dd");
   219 }
   220