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