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