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