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