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