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