mapeditor.cpp
author insilmaril
Wed, 24 Oct 2007 12:21:24 +0000
changeset 613 8fb5b3956b3e
parent 608 6cdc2e7b1937
child 615 497f19b3c1fe
permissions -rw-r--r--
Improved ascii export
insilmaril@0
     1
#include "mapeditor.h"
insilmaril@0
     2
insilmaril@374
     3
#include <q3filedialog.h>
insilmaril@0
     4
insilmaril@0
     5
#include <iostream>
insilmaril@95
     6
#include <cstdlib>
insilmaril@0
     7
#include <typeinfo>
insilmaril@0
     8
insilmaril@0
     9
#include "version.h"
insilmaril@0
    10
insilmaril@432
    11
#include "parser.h"
insilmaril@175
    12
#include "editxlinkdialog.h"
insilmaril@175
    13
#include "exports.h"
insilmaril@517
    14
#include "exportxhtmldialog.h"
insilmaril@175
    15
#include "extrainfodialog.h"
insilmaril@236
    16
#include "file.h"
insilmaril@175
    17
#include "linkablemapobj.h"
insilmaril@175
    18
#include "mainwindow.h"
insilmaril@175
    19
#include "misc.h"
insilmaril@175
    20
#include "texteditor.h"
insilmaril@314
    21
#include "warningdialog.h"
insilmaril@571
    22
#include "xml-freemind.h"
insilmaril@571
    23
#include "xml-vym.h"
insilmaril@0
    24
insilmaril@0
    25
insilmaril@0
    26
extern TextEditor *textEditor;
insilmaril@0
    27
extern int statusbarTime;
insilmaril@0
    28
extern Main *mainWindow;
insilmaril@164
    29
extern QString tmpVymDir;
insilmaril@166
    30
extern QString clipboardDir;
insilmaril@491
    31
extern QString clipboardFile;
insilmaril@166
    32
extern bool clipboardEmpty;
insilmaril@473
    33
extern bool debug;
insilmaril@0
    34
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
    35
insilmaril@366
    36
extern QMenu* branchContextMenu;
insilmaril@366
    37
extern QMenu* branchAddContextMenu;
insilmaril@366
    38
extern QMenu* branchRemoveContextMenu;
insilmaril@366
    39
extern QMenu* branchLinksContextMenu;
insilmaril@366
    40
extern QMenu* branchXLinksContextMenuEdit;
insilmaril@366
    41
extern QMenu* branchXLinksContextMenuFollow;
insilmaril@366
    42
extern QMenu* floatimageContextMenu;
insilmaril@366
    43
extern QMenu* canvasContextMenu;
insilmaril@366
    44
insilmaril@0
    45
insilmaril@0
    46
extern Settings settings;
insilmaril@366
    47
extern ImageIO imageIO;
insilmaril@0
    48
insilmaril@404
    49
extern QString vymName;
insilmaril@404
    50
extern QString vymVersion;
insilmaril@404
    51
insilmaril@269
    52
extern QString iconPath;
insilmaril@301
    53
extern QDir vymBaseDir;
insilmaril@366
    54
extern QDir lastImageDir;
insilmaril@421
    55
extern QDir lastFileDir;
insilmaril@269
    56
insilmaril@164
    57
int MapEditor::mapNum=0;	// make instance
insilmaril@0
    58
insilmaril@0
    59
///////////////////////////////////////////////////////////////////////
insilmaril@0
    60
///////////////////////////////////////////////////////////////////////
insilmaril@408
    61
MapEditor::MapEditor( QWidget* parent) :
insilmaril@473
    62
  QGraphicsView(parent)  
insilmaril@0
    63
{
insilmaril@0
    64
	//cout << "Constructor ME "<<this<<endl;
insilmaril@164
    65
	mapNum++;
insilmaril@0
    66
insilmaril@119
    67
insilmaril@408
    68
	mapScene= new QGraphicsScene(parent);
insilmaril@408
    69
	//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
insilmaril@408
    70
	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
insilmaril@408
    71
insilmaril@408
    72
insilmaril@408
    73
    setScene (mapScene);
insilmaril@0
    74
	
insilmaril@408
    75
    mapCenter = new MapCenterObj(mapScene);
insilmaril@0
    76
    mapCenter->setVisibility (true);
insilmaril@0
    77
	mapCenter->setMapEditor (this);
insilmaril@93
    78
	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
insilmaril@408
    79
	//mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
insilmaril@408
    80
	mapCenter->move(0,0);
insilmaril@0
    81
insilmaril@0
    82
    printer=NULL;
insilmaril@0
    83
insilmaril@97
    84
	defLinkColor=QColor (0,0,255);
insilmaril@97
    85
	defXLinkColor=QColor (180,180,180);
insilmaril@473
    86
	linkcolorhint=LinkableMapObj::DefaultColor;
insilmaril@473
    87
	linkstyle=LinkableMapObj::PolyParabel;
insilmaril@0
    88
insilmaril@366
    89
	// Create bitmap cursors, platform dependant
insilmaril@404
    90
	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
insilmaril@404
    91
	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
insilmaril@404
    92
	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
insilmaril@404
    93
	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
insilmaril@398
    94
insilmaril@398
    95
	setFocusPolicy (Qt::StrongFocus);
insilmaril@0
    96
insilmaril@0
    97
	pickingColor=false;
insilmaril@91
    98
	drawingLink=false;
insilmaril@93
    99
	copyingObj=false;
insilmaril@0
   100
insilmaril@0
   101
    editingBO=NULL;
insilmaril@0
   102
    movingObj=NULL;
insilmaril@0
   103
insilmaril@442
   104
	xelection.setMapEditor (this);
insilmaril@424
   105
	xelection.unselect();
insilmaril@366
   106
insilmaril@102
   107
	defXLinkWidth=1;
insilmaril@102
   108
	defXLinkColor=QColor (230,230,230);
insilmaril@102
   109
insilmaril@0
   110
    mapChanged=false;
insilmaril@0
   111
	mapDefault=true;
insilmaril@0
   112
	mapUnsaved=false;
insilmaril@0
   113
	
insilmaril@0
   114
	zipped=true;
insilmaril@0
   115
	filePath="";
insilmaril@294
   116
	fileName=tr("unnamed");
insilmaril@0
   117
	mapName="";
insilmaril@0
   118
insilmaril@398
   119
	stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
insilmaril@381
   120
	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
insilmaril@491
   121
	mainWindow->updateHistory (undoSet);
insilmaril@163
   122
	
insilmaril@0
   123
	// Initialize find routine
insilmaril@0
   124
	itFind=NULL;				
insilmaril@0
   125
	EOFind=false;
insilmaril@0
   126
insilmaril@0
   127
	printFrame=true;
insilmaril@0
   128
	printFooter=true;
insilmaril@0
   129
insilmaril@139
   130
	blockReposition=false;
insilmaril@139
   131
	blockSaveState=false;
insilmaril@260
   132
insilmaril@473
   133
	hidemode=BranchObj::HideNone;
insilmaril@260
   134
insilmaril@377
   135
	// Create temporary files
insilmaril@377
   136
	makeTmpDirs();
insilmaril@0
   137
insilmaril@502
   138
	curStep=0;
insilmaril@502
   139
	redosAvail=0;
insilmaril@502
   140
	undosAvail=0;
insilmaril@502
   141
insilmaril@417
   142
	setAcceptDrops (true);	
insilmaril@0
   143
insilmaril@0
   144
	mapCenter->reposition();	//	for positioning heading
insilmaril@381
   145
insilmaril@473
   146
	// TODO animations
insilmaril@473
   147
	animObjList.clear();
insilmaril@473
   148
	//timerId = startTimer(100);  
insilmaril@473
   149
insilmaril@473
   150
	// autosave
insilmaril@473
   151
	autosaveTimer=new QTimer (this);
insilmaril@473
   152
	connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
insilmaril@531
   153
insilmaril@531
   154
	// Network
insilmaril@531
   155
	netstate=Offline;
insilmaril@0
   156
}
insilmaril@0
   157
insilmaril@0
   158
MapEditor::~MapEditor()
insilmaril@0
   159
{
insilmaril@0
   160
	//cout <<"Destructor MapEditor\n";
insilmaril@473
   161
	autosaveTimer->stop();
insilmaril@0
   162
}
insilmaril@0
   163
insilmaril@0
   164
MapCenterObj* MapEditor::getMapCenter()
insilmaril@0
   165
{
insilmaril@0
   166
    return mapCenter;
insilmaril@0
   167
}
insilmaril@0
   168
insilmaril@408
   169
QGraphicsScene * MapEditor::getScene()
insilmaril@0
   170
{
insilmaril@408
   171
    return mapScene;
insilmaril@0
   172
}
insilmaril@0
   173
insilmaril@491
   174
MapEditor::State MapEditor::getState()
insilmaril@491
   175
{
insilmaril@491
   176
    return state;
insilmaril@491
   177
}
insilmaril@491
   178
insilmaril@491
   179
void MapEditor::setStateEditHeading(bool s)
insilmaril@491
   180
{
insilmaril@491
   181
	if (s)
insilmaril@491
   182
	{
insilmaril@491
   183
		if (state==Idle) state=EditHeading;
insilmaril@491
   184
	}
insilmaril@491
   185
	else	
insilmaril@491
   186
		state=Idle;
insilmaril@491
   187
}
insilmaril@491
   188
insilmaril@139
   189
bool MapEditor::isRepositionBlocked()
insilmaril@0
   190
{
insilmaril@139
   191
	return blockReposition;
insilmaril@0
   192
}
insilmaril@0
   193
insilmaril@473
   194
void MapEditor::setSaveStateBlocked(bool b)
insilmaril@473
   195
{
insilmaril@473
   196
	blockSaveState=b;
insilmaril@473
   197
}
insilmaril@473
   198
insilmaril@491
   199
bool MapEditor::isSelectBlocked()
insilmaril@491
   200
{
insilmaril@491
   201
	if (state==EditHeading)
insilmaril@491
   202
		return true;
insilmaril@491
   203
	else
insilmaril@491
   204
		return false; 
insilmaril@491
   205
}
insilmaril@491
   206
insilmaril@420
   207
QString MapEditor::getName (const LinkableMapObj *lmo)
insilmaril@294
   208
{
insilmaril@314
   209
	QString s;
insilmaril@314
   210
	if (!lmo) return QString("Error: NULL has no name!");
insilmaril@294
   211
insilmaril@294
   212
	if ((typeid(*lmo) == typeid(BranchObj) ||
insilmaril@294
   213
				      typeid(*lmo) == typeid(MapCenterObj))) 
insilmaril@314
   214
	{
insilmaril@314
   215
		
insilmaril@314
   216
		s=(((BranchObj*)lmo)->getHeading());
insilmaril@314
   217
		if (s=="") s="unnamed";
insilmaril@377
   218
		return QString("branch (%1)").arg(s);
insilmaril@377
   219
		//return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
insilmaril@314
   220
	}	
insilmaril@294
   221
	if ((typeid(*lmo) == typeid(FloatImageObj) ))
insilmaril@377
   222
		return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
insilmaril@377
   223
		//return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
insilmaril@294
   224
	return QString("Unknown type has no name!");
insilmaril@294
   225
}
insilmaril@294
   226
insilmaril@0
   227
void MapEditor::makeTmpDirs()
insilmaril@0
   228
{
insilmaril@0
   229
	// Create unique temporary directories
insilmaril@366
   230
	tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
insilmaril@366
   231
	histPath=QDir::convertSeparators (tmpMapDir+"/history");
insilmaril@164
   232
	QDir d;
insilmaril@377
   233
	d.mkdir (tmpMapDir);
insilmaril@0
   234
}
insilmaril@0
   235
insilmaril@408
   236
QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
insilmaril@0
   237
{
insilmaril@163
   238
	// tmpdir		temporary directory to which data will be written
insilmaril@0
   239
	// prefix		mapname, which will be appended to images etc.
insilmaril@0
   240
	// writeflags	Only write flags for "real" save of map, not undo
insilmaril@408
   241
	// offset		offset of bbox of whole map in scene. 
insilmaril@0
   242
	//				Needed for XML export
insilmaril@0
   243
	
insilmaril@0
   244
	// Save Header
insilmaril@0
   245
	QString ls;
insilmaril@0
   246
	switch (linkstyle)
insilmaril@0
   247
	{
insilmaril@473
   248
		case LinkableMapObj::Line: 
insilmaril@0
   249
			ls="StyleLine";
insilmaril@0
   250
			break;
insilmaril@473
   251
		case LinkableMapObj::Parabel:
insilmaril@0
   252
			ls="StyleParabel";
insilmaril@0
   253
			break;
insilmaril@473
   254
		case LinkableMapObj::PolyLine:	
insilmaril@0
   255
			ls="StylePolyLine";
insilmaril@0
   256
			break;
insilmaril@0
   257
		default:
insilmaril@0
   258
			ls="StylePolyParabel";
insilmaril@0
   259
			break;
insilmaril@0
   260
	}	
insilmaril@0
   261
insilmaril@0
   262
	QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
insilmaril@0
   263
	QString colhint="";
insilmaril@473
   264
	if (linkcolorhint==LinkableMapObj::HeadingColor) 
insilmaril@0
   265
		colhint=attribut("linkColorHint","HeadingColor");
insilmaril@0
   266
insilmaril@404
   267
	QString mapAttr=attribut("version",vymVersion);
insilmaril@398
   268
	if (!saveSel || saveSel==mapCenter)
insilmaril@0
   269
		mapAttr+= attribut("author",mapCenter->getAuthor()) +
insilmaril@0
   270
				  attribut("comment",mapCenter->getComment()) +
insilmaril@0
   271
			      attribut("date",mapCenter->getDate()) +
insilmaril@408
   272
		          attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
insilmaril@442
   273
		          attribut("selectionColor", xelection.getColor().name() ) +
insilmaril@0
   274
		          attribut("linkStyle", ls ) +
insilmaril@97
   275
		          attribut("linkColor", defLinkColor.name() ) +
insilmaril@102
   276
		          attribut("defXLinkColor", defXLinkColor.name() ) +
insilmaril@102
   277
		          attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
insilmaril@0
   278
		          colhint; 
insilmaril@0
   279
	s+=beginElement("vymmap",mapAttr);
insilmaril@0
   280
	incIndent();
insilmaril@0
   281
insilmaril@0
   282
	// Find the used flags while traversing the tree
insilmaril@0
   283
	standardFlagsDefault->resetUsedCounter();
insilmaril@0
   284
	
insilmaril@166
   285
	// Reset the counters before saving
insilmaril@406
   286
	// TODO constr. of FIO creates lots of objects, better do this in some other way...
insilmaril@408
   287
	FloatImageObj (mapScene).resetSaveCounter();
insilmaril@166
   288
insilmaril@0
   289
	// Build xml recursivly
insilmaril@398
   290
	if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
insilmaril@366
   291
		// Save complete map, if saveSel not set
insilmaril@0
   292
		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
insilmaril@0
   293
	else
insilmaril@0
   294
	{
insilmaril@366
   295
		if ( typeid(*saveSel) == typeid(BranchObj) )
insilmaril@366
   296
			// Save Subtree
insilmaril@366
   297
			s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
insilmaril@366
   298
		else if ( typeid(*saveSel) == typeid(FloatImageObj) )
insilmaril@366
   299
			// Save image
insilmaril@377
   300
			s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
insilmaril@0
   301
	}
insilmaril@0
   302
insilmaril@0
   303
	// Save local settings
insilmaril@0
   304
	s+=settings.getXMLData (destPath);
insilmaril@0
   305
insilmaril@0
   306
	// Save selection
insilmaril@424
   307
	if (!xelection.isEmpty() && !saveSel ) 
insilmaril@424
   308
		s+=valueElement("select",xelection.getSelectString());
insilmaril@0
   309
insilmaril@0
   310
	decIndent();
insilmaril@0
   311
	s+=endElement("vymmap");
insilmaril@0
   312
insilmaril@0
   313
	if (writeflags)
insilmaril@0
   314
		standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
insilmaril@0
   315
	return s;
insilmaril@0
   316
}
insilmaril@0
   317
insilmaril@505
   318
QString MapEditor::getHistoryDir()
insilmaril@505
   319
{
insilmaril@505
   320
	QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
insilmaril@505
   321
	return QDir::convertSeparators (tmpMapDir +"/"+histName);
insilmaril@505
   322
}
insilmaril@505
   323
insilmaril@486
   324
void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
insilmaril@486
   325
{
insilmaril@528
   326
	sendData(redoCom);	//FIXME testing
insilmaril@528
   327
insilmaril@486
   328
	// Main saveState
insilmaril@486
   329
insilmaril@528
   330
insilmaril@486
   331
	if (blockSaveState) return;
insilmaril@486
   332
insilmaril@486
   333
	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
insilmaril@486
   334
	
insilmaril@486
   335
	// Find out current undo directory
insilmaril@486
   336
	if (undosAvail<stepsTotal) undosAvail++;
insilmaril@486
   337
	curStep++;
insilmaril@486
   338
	if (curStep>stepsTotal) curStep=1;
insilmaril@486
   339
	
insilmaril@486
   340
	QString backupXML="";
insilmaril@505
   341
	QString histDir=getHistoryDir();
insilmaril@505
   342
	QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
insilmaril@505
   343
insilmaril@505
   344
	// Create histDir if not available
insilmaril@505
   345
	QDir d(histDir);
insilmaril@486
   346
	if (!d.exists()) 
insilmaril@505
   347
		makeSubDirs (histDir);
insilmaril@486
   348
insilmaril@486
   349
	// Save depending on how much needs to be saved	
insilmaril@486
   350
	if (saveSel)
insilmaril@505
   351
		backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
insilmaril@486
   352
		
insilmaril@486
   353
	QString undoCommand="";
insilmaril@486
   354
	if (savemode==UndoCommand)
insilmaril@486
   355
	{
insilmaril@486
   356
		undoCommand=undoCom;
insilmaril@486
   357
	}	
insilmaril@486
   358
	else if (savemode==PartOfMap )
insilmaril@486
   359
	{
insilmaril@486
   360
		undoCommand=undoCom;
insilmaril@486
   361
		undoCommand.replace ("PATH",bakMapPath);
insilmaril@486
   362
	}
insilmaril@486
   363
insilmaril@486
   364
	if (!backupXML.isEmpty())
insilmaril@486
   365
		// Write XML Data to disk
insilmaril@486
   366
		saveStringToDisk (QString(bakMapPath),backupXML);
insilmaril@486
   367
insilmaril@486
   368
	// We would have to save all actions in a tree, to keep track of 
insilmaril@486
   369
	// possible redos after a action. Possible, but we are too lazy: forget about redos.
insilmaril@486
   370
	redosAvail=0;
insilmaril@486
   371
insilmaril@486
   372
	// Write the current state to disk
insilmaril@486
   373
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@486
   374
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@486
   375
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@486
   376
	undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
insilmaril@486
   377
	undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
insilmaril@486
   378
	undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
insilmaril@486
   379
	undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
insilmaril@486
   380
	undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
insilmaril@486
   381
	undoSet.setEntry (QString("/history/version"),vymVersion);
insilmaril@486
   382
	undoSet.writeSettings(histPath);
insilmaril@486
   383
insilmaril@486
   384
	if (debug)
insilmaril@486
   385
	{
insilmaril@486
   386
		// TODO remove after testing
insilmaril@486
   387
		//cout << "          into="<< histPath.toStdString()<<endl;
insilmaril@486
   388
		cout << "    stepsTotal="<<stepsTotal<<
insilmaril@486
   389
		", undosAvail="<<undosAvail<<
insilmaril@486
   390
		", redosAvail="<<redosAvail<<
insilmaril@486
   391
		", curStep="<<curStep<<endl;
insilmaril@486
   392
		cout << "    ---------------------------"<<endl;
insilmaril@486
   393
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@486
   394
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@486
   395
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@486
   396
		cout << "    redoCom="<<redoCom.toStdString()<<endl;
insilmaril@486
   397
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@486
   398
		if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
insilmaril@486
   399
		cout << "    ---------------------------"<<endl;
insilmaril@486
   400
	}
insilmaril@486
   401
insilmaril@486
   402
	mainWindow->updateHistory (undoSet);
insilmaril@486
   403
	setChanged();
insilmaril@486
   404
	updateActions();
insilmaril@486
   405
}
insilmaril@486
   406
insilmaril@486
   407
insilmaril@395
   408
void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
insilmaril@0
   409
{
insilmaril@366
   410
	// save the selected part of the map, Undo will replace part of map 
insilmaril@366
   411
	QString undoSelection="";
insilmaril@395
   412
	if (undoSel)
insilmaril@395
   413
		undoSelection=undoSel->getSelectString();
insilmaril@395
   414
	else
insilmaril@395
   415
		qWarning ("MapEditor::saveStateChangingPart  no undoSel given!");
insilmaril@395
   416
	QString redoSelection="";
insilmaril@395
   417
	if (redoSel)
insilmaril@395
   418
		redoSelection=undoSel->getSelectString();
insilmaril@395
   419
	else
insilmaril@395
   420
		qWarning ("MapEditor::saveStateChangingPart  no redoSel given!");
insilmaril@395
   421
		
insilmaril@366
   422
insilmaril@366
   423
	saveState (PartOfMap,
insilmaril@398
   424
		undoSelection, "addMapReplace (\"PATH\")",
insilmaril@395
   425
		redoSelection, rc, 
insilmaril@366
   426
		comment, 
insilmaril@366
   427
		undoSel);
insilmaril@105
   428
}
insilmaril@105
   429
insilmaril@393
   430
void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
insilmaril@393
   431
{
insilmaril@394
   432
	if (!redoSel)
insilmaril@393
   433
	{
insilmaril@394
   434
		qWarning ("MapEditor::saveStateRemovingPart  no redoSel given!");
insilmaril@393
   435
		return;
insilmaril@393
   436
	}
insilmaril@393
   437
	QString undoSelection=redoSel->getParObj()->getSelectString();
insilmaril@393
   438
	QString redoSelection=redoSel->getSelectString();
insilmaril@398
   439
	if (typeid(*redoSel) == typeid(BranchObj)  ) 
insilmaril@394
   440
	{
insilmaril@394
   441
		// save the selected branch of the map, Undo will insert part of map 
insilmaril@394
   442
		saveState (PartOfMap,
insilmaril@394
   443
			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
insilmaril@394
   444
			redoSelection, "delete ()", 
insilmaril@394
   445
			comment, 
insilmaril@394
   446
			redoSel);
insilmaril@394
   447
	}
insilmaril@393
   448
}
insilmaril@393
   449
insilmaril@106
   450
insilmaril@366
   451
void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
insilmaril@366
   452
{
insilmaril@366
   453
	// "Normal" savestate: save commands, selections and comment
insilmaril@366
   454
	// so just save commands for undo and redo
insilmaril@366
   455
	// and use current selection
insilmaril@366
   456
insilmaril@366
   457
	QString redoSelection="";
insilmaril@366
   458
	if (redoSel) redoSelection=redoSel->getSelectString();
insilmaril@366
   459
	QString undoSelection="";
insilmaril@366
   460
	if (undoSel) undoSelection=undoSel->getSelectString();
insilmaril@366
   461
insilmaril@366
   462
	saveState (UndoCommand,
insilmaril@366
   463
		undoSelection, uc,
insilmaril@366
   464
		redoSelection, rc, 
insilmaril@366
   465
		comment, 
insilmaril@366
   466
		NULL);
insilmaril@366
   467
}
insilmaril@366
   468
insilmaril@366
   469
void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) 
insilmaril@366
   470
{
insilmaril@366
   471
	// "Normal" savestate: save commands, selections and comment
insilmaril@366
   472
	// so just save commands for undo and redo
insilmaril@366
   473
	// and use current selection
insilmaril@366
   474
	saveState (UndoCommand,
insilmaril@366
   475
		undoSel, uc,
insilmaril@366
   476
		redoSel, rc, 
insilmaril@366
   477
		comment, 
insilmaril@366
   478
		NULL);
insilmaril@366
   479
}
insilmaril@366
   480
insilmaril@366
   481
		
insilmaril@129
   482
void MapEditor::parseAtom(const QString &atom)
insilmaril@106
   483
{
insilmaril@424
   484
	BranchObj *selb=xelection.getBranch();
insilmaril@163
   485
	QString s,t;
insilmaril@537
   486
	double x,y;
insilmaril@537
   487
	int n;
insilmaril@395
   488
	bool b,ok;
insilmaril@129
   489
insilmaril@129
   490
	// Split string s into command and parameters
insilmaril@432
   491
	parser.parseAtom (atom);
insilmaril@447
   492
	QString com=parser.getCommand();
insilmaril@129
   493
	
insilmaril@106
   494
	// External commands
insilmaril@514
   495
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   496
	if (com=="addBranch")
insilmaril@366
   497
	{
insilmaril@424
   498
		if (xelection.isEmpty())
insilmaril@394
   499
		{
insilmaril@432
   500
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   501
		} else if (! selb )
insilmaril@394
   502
		{				  
insilmaril@432
   503
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   504
		} else 
insilmaril@366
   505
		{	
insilmaril@394
   506
			QList <int> pl;
insilmaril@394
   507
			pl << 0 <<1;
insilmaril@514
   508
			if (parser.checkParCount(pl))
insilmaril@394
   509
			{
insilmaril@514
   510
				if (parser.parCount()==0)
insilmaril@537
   511
					addNewBranch (0);
insilmaril@394
   512
				else
insilmaril@394
   513
				{
insilmaril@537
   514
					n=parser.parInt (ok,0);
insilmaril@537
   515
					if (ok ) addNewBranch (n);
insilmaril@394
   516
				}
insilmaril@394
   517
			}
insilmaril@394
   518
		}
insilmaril@514
   519
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   520
	} else if (com=="addBranchBefore")
insilmaril@394
   521
	{
insilmaril@424
   522
		if (xelection.isEmpty())
insilmaril@394
   523
		{
insilmaril@432
   524
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   525
		} else if (! selb )
insilmaril@394
   526
		{				  
insilmaril@432
   527
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   528
		} else 
insilmaril@394
   529
		{	
insilmaril@514
   530
			if (parser.parCount()==0)
insilmaril@394
   531
			{
insilmaril@394
   532
				addNewBranchBefore ();
insilmaril@394
   533
			}	
insilmaril@394
   534
		}
insilmaril@514
   535
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   536
	} else if (com==QString("addMapReplace"))
insilmaril@393
   537
	{
insilmaril@424
   538
		if (xelection.isEmpty())
insilmaril@394
   539
		{
insilmaril@432
   540
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   541
		} else if (! selb )
insilmaril@394
   542
		{				  
insilmaril@432
   543
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   544
		} else if (parser.checkParCount(1))
insilmaril@393
   545
		{
insilmaril@432
   546
			//s=parser.parString (ok,0);	// selection
insilmaril@432
   547
			t=parser.parString (ok,0);	// path to map
insilmaril@393
   548
			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
insilmaril@424
   549
			addMapReplaceInt(selb->getSelectString(),t);	
insilmaril@393
   550
		}
insilmaril@514
   551
	/////////////////////////////////////////////////////////////////////
insilmaril@434
   552
	} else if (com==QString("addMapInsert"))
insilmaril@393
   553
	{
insilmaril@424
   554
		if (xelection.isEmpty())
insilmaril@393
   555
		{
insilmaril@432
   556
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   557
		} else if (! selb )
insilmaril@394
   558
		{				  
insilmaril@432
   559
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   560
		} else 
insilmaril@394
   561
		{	
insilmaril@514
   562
			if (parser.checkParCount(2))
insilmaril@394
   563
			{
insilmaril@432
   564
				t=parser.parString (ok,0);	// path to map
insilmaril@537
   565
				n=parser.parInt(ok,1);		// position
insilmaril@394
   566
				if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
insilmaril@537
   567
				addMapInsertInt(t,n);	
insilmaril@394
   568
			}
insilmaril@393
   569
		}
insilmaril@514
   570
	/////////////////////////////////////////////////////////////////////
insilmaril@447
   571
	} else if (com=="clearFlags")
insilmaril@447
   572
	{
insilmaril@447
   573
		if (xelection.isEmpty() )
insilmaril@447
   574
		{
insilmaril@447
   575
			parser.setError (Aborted,"Nothing selected");
insilmaril@447
   576
		} else if (! selb )
insilmaril@447
   577
		{				  
insilmaril@447
   578
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   579
		} else if (parser.checkParCount(0))
insilmaril@447
   580
		{
insilmaril@447
   581
			selb->clearStandardFlags();	
insilmaril@447
   582
			selb->updateFlagsToolbar();
insilmaril@447
   583
		}
insilmaril@514
   584
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   585
	} else if (com=="colorBranch")
insilmaril@395
   586
	{
insilmaril@424
   587
		if (xelection.isEmpty())
insilmaril@395
   588
		{
insilmaril@432
   589
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   590
		} else if (! selb )
insilmaril@395
   591
		{				  
insilmaril@432
   592
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   593
		} else if (parser.checkParCount(1))
insilmaril@395
   594
		{	
insilmaril@432
   595
			QColor c=parser.parColor (ok,0);
insilmaril@395
   596
			if (ok) colorBranch (c);
insilmaril@395
   597
		}	
insilmaril@514
   598
	/////////////////////////////////////////////////////////////////////
insilmaril@417
   599
	} else if (com=="colorSubtree")
insilmaril@417
   600
	{
insilmaril@424
   601
		if (xelection.isEmpty())
insilmaril@417
   602
		{
insilmaril@432
   603
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   604
		} else if (! selb )
insilmaril@417
   605
		{				  
insilmaril@432
   606
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   607
		} else if (parser.checkParCount(1))
insilmaril@417
   608
		{	
insilmaril@432
   609
			QColor c=parser.parColor (ok,0);
insilmaril@417
   610
			if (ok) colorSubtree (c);
insilmaril@417
   611
		}	
insilmaril@514
   612
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   613
	} else if (com=="copy")
insilmaril@502
   614
	{
insilmaril@502
   615
		if (xelection.isEmpty())
insilmaril@502
   616
		{
insilmaril@502
   617
			parser.setError (Aborted,"Nothing selected");
insilmaril@502
   618
		} else if (! selb )
insilmaril@502
   619
		{				  
insilmaril@502
   620
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   621
		} else if (parser.checkParCount(0))
insilmaril@502
   622
		{	
insilmaril@502
   623
			//FIXME missing action for copy
insilmaril@502
   624
		}	
insilmaril@514
   625
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   626
	} else if (com=="cut")
insilmaril@395
   627
	{
insilmaril@424
   628
		if (xelection.isEmpty())
insilmaril@395
   629
		{
insilmaril@432
   630
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   631
		} else if ( xelection.type()!=Selection::Branch  && 
insilmaril@491
   632
					xelection.type()!=Selection::MapCenter  &&
insilmaril@491
   633
					xelection.type()!=Selection::FloatImage )
insilmaril@395
   634
		{				  
insilmaril@432
   635
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   636
		} else if (parser.checkParCount(0))
insilmaril@395
   637
		{	
insilmaril@395
   638
			cut();
insilmaril@395
   639
		}	
insilmaril@514
   640
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   641
	} else if (com=="delete")
insilmaril@393
   642
	{
insilmaril@424
   643
		if (xelection.isEmpty())
insilmaril@394
   644
		{
insilmaril@432
   645
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   646
		} else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
insilmaril@424
   647
		{
insilmaril@434
   648
			parser.setError (Aborted,"Type of selection is wrong.");
insilmaril@514
   649
		} else if (parser.checkParCount(0))
insilmaril@393
   650
		{	
insilmaril@393
   651
			deleteSelection();
insilmaril@393
   652
		}	
insilmaril@514
   653
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   654
	} else if (com=="deleteKeepChilds")
insilmaril@394
   655
	{
insilmaril@424
   656
		if (xelection.isEmpty())
insilmaril@394
   657
		{
insilmaril@432
   658
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   659
		} else if (! selb )
insilmaril@424
   660
		{
insilmaril@432
   661
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   662
		} else if (parser.checkParCount(0))
insilmaril@394
   663
		{	
insilmaril@395
   664
			deleteKeepChilds();
insilmaril@395
   665
		}	
insilmaril@514
   666
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   667
	} else if (com=="deleteChilds")
insilmaril@395
   668
	{
insilmaril@424
   669
		if (xelection.isEmpty())
insilmaril@395
   670
		{
insilmaril@432
   671
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   672
		} else if (! selb)
insilmaril@424
   673
		{
insilmaril@432
   674
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   675
		} else if (parser.checkParCount(0))
insilmaril@395
   676
		{	
insilmaril@395
   677
			deleteChilds();
insilmaril@394
   678
		}	
insilmaril@514
   679
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   680
	} else if (com=="exportASCII")
insilmaril@514
   681
	{
insilmaril@517
   682
		QString fname="";
insilmaril@517
   683
		ok=true;
insilmaril@613
   684
		if (parser.parCount()>=1)
insilmaril@517
   685
			// Hey, we even have a filename
insilmaril@613
   686
			fname=parser.parString(ok,0); 
insilmaril@517
   687
		if (!ok)
insilmaril@514
   688
		{
insilmaril@517
   689
			parser.setError (Aborted,"Could not read filename");
insilmaril@514
   690
		} else
insilmaril@514
   691
		{
insilmaril@517
   692
				exportASCII (fname,false);
insilmaril@517
   693
		}
insilmaril@517
   694
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   695
	} else if (com=="exportImage")
insilmaril@517
   696
	{
insilmaril@517
   697
		QString fname="";
insilmaril@517
   698
		ok=true;
insilmaril@517
   699
		if (parser.parCount()>=2)
insilmaril@517
   700
			// Hey, we even have a filename
insilmaril@613
   701
			fname=parser.parString(ok,0); 
insilmaril@517
   702
		if (!ok)
insilmaril@517
   703
		{
insilmaril@517
   704
			parser.setError (Aborted,"Could not read filename");
insilmaril@517
   705
		} else
insilmaril@517
   706
		{
insilmaril@517
   707
			QString format="PNG";
insilmaril@613
   708
			if (parser.parCount()>=2)
insilmaril@514
   709
			{
insilmaril@613
   710
				format=parser.parString(ok,1);
insilmaril@514
   711
			}
insilmaril@517
   712
			exportImage (fname,false,format);
insilmaril@517
   713
		}
insilmaril@517
   714
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   715
	} else if (com=="exportXHTML")
insilmaril@517
   716
	{
insilmaril@517
   717
		QString fname="";
insilmaril@517
   718
		ok=true;
insilmaril@517
   719
		if (parser.parCount()>=2)
insilmaril@517
   720
			// Hey, we even have a filename
insilmaril@517
   721
			fname=parser.parString(ok,1); 
insilmaril@517
   722
		if (!ok)
insilmaril@517
   723
		{
insilmaril@517
   724
			parser.setError (Aborted,"Could not read filename");
insilmaril@517
   725
		} else
insilmaril@517
   726
		{
insilmaril@520
   727
			exportXHTML (fname,false);
insilmaril@517
   728
		}
insilmaril@514
   729
	/////////////////////////////////////////////////////////////////////
insilmaril@526
   730
	} else if (com=="exportXML")
insilmaril@526
   731
	{
insilmaril@526
   732
		QString fname="";
insilmaril@526
   733
		ok=true;
insilmaril@526
   734
		if (parser.parCount()>=2)
insilmaril@526
   735
			// Hey, we even have a filename
insilmaril@526
   736
			fname=parser.parString(ok,1); 
insilmaril@526
   737
		if (!ok)
insilmaril@526
   738
		{
insilmaril@526
   739
			parser.setError (Aborted,"Could not read filename");
insilmaril@526
   740
		} else
insilmaril@526
   741
		{
insilmaril@526
   742
			exportXML (fname,false);
insilmaril@526
   743
		}
insilmaril@526
   744
	/////////////////////////////////////////////////////////////////////
insilmaril@491
   745
	} else if (com=="importDir")
insilmaril@491
   746
	{
insilmaril@491
   747
		if (xelection.isEmpty())
insilmaril@491
   748
		{
insilmaril@491
   749
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   750
		} else if (! selb )
insilmaril@491
   751
		{				  
insilmaril@491
   752
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   753
		} else if (parser.checkParCount(1))
insilmaril@491
   754
		{
insilmaril@491
   755
			s=parser.parString(ok,0);
insilmaril@491
   756
			if (ok) importDirInt(s);
insilmaril@491
   757
		}	
insilmaril@514
   758
	/////////////////////////////////////////////////////////////////////
insilmaril@420
   759
	} else if (com=="linkTo")
insilmaril@420
   760
	{
insilmaril@424
   761
		if (xelection.isEmpty())
insilmaril@420
   762
		{
insilmaril@432
   763
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   764
		} else if ( selb)
insilmaril@420
   765
		{
insilmaril@514
   766
			if (parser.checkParCount(4))
insilmaril@421
   767
			{
insilmaril@421
   768
				// 0	selectstring of parent
insilmaril@421
   769
				// 1	num in parent (for branches)
insilmaril@421
   770
				// 2,3	x,y of mainbranch or mapcenter
insilmaril@432
   771
				s=parser.parString(ok,0);
insilmaril@421
   772
				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
insilmaril@421
   773
				if (dst)
insilmaril@421
   774
				{	
insilmaril@421
   775
					if (typeid(*dst) == typeid(BranchObj) ) 
insilmaril@421
   776
					{
insilmaril@421
   777
						// Get number in parent
insilmaril@537
   778
						n=parser.parInt (ok,1);
insilmaril@421
   779
						if (ok)
insilmaril@534
   780
						{
insilmaril@537
   781
							selb->linkTo ((BranchObj*)(dst),n);
insilmaril@534
   782
							xelection.update();
insilmaril@534
   783
						}	
insilmaril@421
   784
					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
insilmaril@421
   785
					{
insilmaril@424
   786
						selb->linkTo ((BranchObj*)(dst),-1);
insilmaril@421
   787
						// Get coordinates of mainbranch
insilmaril@537
   788
						x=parser.parDouble(ok,2);
insilmaril@421
   789
						if (ok)
insilmaril@421
   790
						{
insilmaril@537
   791
							y=parser.parDouble(ok,3);
insilmaril@534
   792
							if (ok) 
insilmaril@534
   793
							{
insilmaril@534
   794
								selb->move (x,y);
insilmaril@534
   795
								xelection.update();
insilmaril@534
   796
							}
insilmaril@421
   797
						}
insilmaril@421
   798
					}	
insilmaril@421
   799
				}	
insilmaril@421
   800
			}	
insilmaril@491
   801
		} else if ( xelection.type() == Selection::FloatImage) 
insilmaril@421
   802
		{
insilmaril@514
   803
			if (parser.checkParCount(1))
insilmaril@421
   804
			{
insilmaril@421
   805
				// 0	selectstring of parent
insilmaril@432
   806
				s=parser.parString(ok,0);
insilmaril@421
   807
				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
insilmaril@421
   808
				if (dst)
insilmaril@421
   809
				{	
insilmaril@421
   810
					if (typeid(*dst) == typeid(BranchObj) ||
insilmaril@421
   811
						typeid(*dst) == typeid(MapCenterObj)) 
insilmaril@421
   812
						linkTo (dst->getSelectString());
insilmaril@421
   813
				} else	
insilmaril@432
   814
					parser.setError (Aborted,"Destination is not a branch");
insilmaril@421
   815
			}		
insilmaril@421
   816
		} else
insilmaril@432
   817
			parser.setError (Aborted,"Type of selection is not a floatimage or branch");
insilmaril@514
   818
	/////////////////////////////////////////////////////////////////////
insilmaril@432
   819
	} else if (com=="loadImage")
insilmaril@432
   820
	{
insilmaril@432
   821
		if (xelection.isEmpty())
insilmaril@432
   822
		{
insilmaril@432
   823
			parser.setError (Aborted,"Nothing selected");
insilmaril@432
   824
		} else if (! selb )
insilmaril@432
   825
		{				  
insilmaril@432
   826
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   827
		} else if (parser.checkParCount(1))
insilmaril@432
   828
		{
insilmaril@432
   829
			s=parser.parString(ok,0);
insilmaril@432
   830
			if (ok) loadFloatImageInt (s);
insilmaril@432
   831
		}	
insilmaril@514
   832
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   833
	} else if (com=="moveBranchUp")
insilmaril@393
   834
	{
insilmaril@424
   835
		if (xelection.isEmpty() )
insilmaril@394
   836
		{
insilmaril@432
   837
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   838
		} else if (! selb )
insilmaril@394
   839
		{				  
insilmaril@432
   840
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   841
		} else if (parser.checkParCount(0))
insilmaril@394
   842
		{
insilmaril@394
   843
			moveBranchUp();
insilmaril@394
   844
		}	
insilmaril@514
   845
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   846
	} else if (com=="moveBranchDown")
insilmaril@394
   847
	{
insilmaril@424
   848
		if (xelection.isEmpty() )
insilmaril@394
   849
		{
insilmaril@432
   850
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   851
		} else if (! selb )
insilmaril@394
   852
		{				  
insilmaril@432
   853
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   854
		} else if (parser.checkParCount(0))
insilmaril@394
   855
		{
insilmaril@394
   856
			moveBranchDown();
insilmaril@394
   857
		}	
insilmaril@514
   858
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   859
	} else if (com=="move")
insilmaril@394
   860
	{
insilmaril@424
   861
		if (xelection.isEmpty() )
insilmaril@394
   862
		{
insilmaril@432
   863
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   864
		} else if ( xelection.type()!=Selection::Branch  && 
insilmaril@491
   865
					xelection.type()!=Selection::MapCenter  &&
insilmaril@491
   866
					xelection.type()!=Selection::FloatImage )
insilmaril@394
   867
		{				  
insilmaril@432
   868
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   869
		} else if (parser.checkParCount(2))
insilmaril@393
   870
		{	
insilmaril@537
   871
			x=parser.parDouble (ok,0);
insilmaril@393
   872
			if (ok)
insilmaril@393
   873
			{
insilmaril@537
   874
				y=parser.parDouble (ok,1);
insilmaril@393
   875
				if (ok) move (x,y);
insilmaril@393
   876
			}
insilmaril@393
   877
		}	
insilmaril@514
   878
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   879
	} else if (com=="moveRel")
insilmaril@393
   880
	{
insilmaril@424
   881
		if (xelection.isEmpty() )
insilmaril@394
   882
		{
insilmaril@432
   883
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   884
		} else if ( xelection.type()!=Selection::Selection::Branch  && 
insilmaril@491
   885
					xelection.type()!=Selection::Selection::MapCenter  &&
insilmaril@491
   886
					xelection.type()!=Selection::Selection::FloatImage )
insilmaril@394
   887
		{				  
insilmaril@432
   888
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   889
		} else if (parser.checkParCount(2))
insilmaril@393
   890
		{	
insilmaril@537
   891
			x=parser.parDouble (ok,0);
insilmaril@393
   892
			if (ok)
insilmaril@393
   893
			{
insilmaril@537
   894
				y=parser.parDouble (ok,1);
insilmaril@393
   895
				if (ok) moveRel (x,y);
insilmaril@393
   896
			}
insilmaril@393
   897
		}	
insilmaril@514
   898
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   899
	} else if (com=="nop")
insilmaril@502
   900
	{
insilmaril@514
   901
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   902
	} else if (com=="paste")
insilmaril@395
   903
	{
insilmaril@424
   904
		if (xelection.isEmpty() )
insilmaril@395
   905
		{
insilmaril@432
   906
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   907
		} else if (! selb )
insilmaril@395
   908
		{				  
insilmaril@432
   909
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   910
		} else if (parser.checkParCount(1))
insilmaril@395
   911
		{	
insilmaril@537
   912
			n=parser.parInt (ok,0);
insilmaril@537
   913
			if (ok) pasteNoSave(n);
insilmaril@502
   914
		}	
insilmaril@502
   915
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   916
	} else if (com=="qa")
insilmaril@502
   917
	{
insilmaril@502
   918
		if (xelection.isEmpty() )
insilmaril@502
   919
		{
insilmaril@502
   920
			parser.setError (Aborted,"Nothing selected");
insilmaril@502
   921
		} else if (! selb )
insilmaril@502
   922
		{				  
insilmaril@502
   923
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   924
		} else if (parser.checkParCount(4))
insilmaril@502
   925
		{	
insilmaril@502
   926
			QString c,u;
insilmaril@502
   927
			c=parser.parString (ok,0);
insilmaril@502
   928
			if (!ok)
insilmaril@502
   929
			{
insilmaril@502
   930
				parser.setError (Aborted,"No comment given");
insilmaril@502
   931
			} else
insilmaril@502
   932
			{
insilmaril@502
   933
				s=parser.parString (ok,1);
insilmaril@502
   934
				if (!ok)
insilmaril@502
   935
				{
insilmaril@502
   936
					parser.setError (Aborted,"First parameter is not a string");
insilmaril@502
   937
				} else
insilmaril@502
   938
				{
insilmaril@502
   939
					t=parser.parString (ok,2);
insilmaril@502
   940
					if (!ok)
insilmaril@502
   941
					{
insilmaril@502
   942
						parser.setError (Aborted,"Condition is not a string");
insilmaril@502
   943
					} else
insilmaril@502
   944
					{
insilmaril@502
   945
						u=parser.parString (ok,3);
insilmaril@502
   946
						if (!ok)
insilmaril@502
   947
						{
insilmaril@502
   948
							parser.setError (Aborted,"Third parameter is not a string");
insilmaril@502
   949
						} else
insilmaril@502
   950
						{
insilmaril@502
   951
							if (s!="heading")
insilmaril@502
   952
							{
insilmaril@502
   953
								parser.setError (Aborted,"Unknown type: "+s);
insilmaril@502
   954
							} else
insilmaril@502
   955
							{
insilmaril@502
   956
								if (! (t=="eq") ) 
insilmaril@502
   957
								{
insilmaril@502
   958
									parser.setError (Aborted,"Unknown operator: "+t);
insilmaril@502
   959
								} else
insilmaril@502
   960
								{
insilmaril@502
   961
									if (! selb    )
insilmaril@502
   962
									{
insilmaril@502
   963
										parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@502
   964
									} else
insilmaril@502
   965
									{
insilmaril@502
   966
										if (selb->getHeading() == u)
insilmaril@502
   967
										{
insilmaril@502
   968
											cout << "PASSED: " << c.ascii() << endl;
insilmaril@502
   969
										} else
insilmaril@502
   970
										{
insilmaril@502
   971
											cout << "FAILED: " << c.ascii() << endl;
insilmaril@502
   972
										}
insilmaril@502
   973
									}
insilmaril@502
   974
								}
insilmaril@502
   975
							}
insilmaril@502
   976
						} 
insilmaril@502
   977
					} 
insilmaril@502
   978
				} 
insilmaril@502
   979
			}
insilmaril@395
   980
		}	
insilmaril@514
   981
	/////////////////////////////////////////////////////////////////////
insilmaril@434
   982
	} else if (com=="saveImage")
insilmaril@434
   983
	{
insilmaril@434
   984
		FloatImageObj *fio=xelection.getFloatImage();
insilmaril@434
   985
		if (!fio)
insilmaril@434
   986
		{
insilmaril@434
   987
			parser.setError (Aborted,"Type of selection is not an image");
insilmaril@514
   988
		} else if (parser.checkParCount(2))
insilmaril@434
   989
		{
insilmaril@434
   990
			s=parser.parString(ok,0);
insilmaril@434
   991
			if (ok)
insilmaril@434
   992
			{
insilmaril@434
   993
				t=parser.parString(ok,1);
insilmaril@434
   994
				if (ok) saveFloatImageInt (fio,t,s);
insilmaril@434
   995
			}
insilmaril@434
   996
		}	
insilmaril@514
   997
	/////////////////////////////////////////////////////////////////////
insilmaril@427
   998
	} else if (com=="scroll")
insilmaril@427
   999
	{
insilmaril@427
  1000
		if (xelection.isEmpty() )
insilmaril@427
  1001
		{
insilmaril@432
  1002
			parser.setError (Aborted,"Nothing selected");
insilmaril@427
  1003
		} else if (! selb )
insilmaril@427
  1004
		{				  
insilmaril@432
  1005
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1006
		} else if (parser.checkParCount(0))
insilmaril@427
  1007
		{	
insilmaril@473
  1008
			if (!scrollBranch (selb))	
insilmaril@432
  1009
				parser.setError (Aborted,"Could not scroll branch");
insilmaril@427
  1010
		}	
insilmaril@514
  1011
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1012
	} else if (com=="select")
insilmaril@398
  1013
	{
insilmaril@514
  1014
		if (parser.checkParCount(1))
insilmaril@398
  1015
		{
insilmaril@432
  1016
			s=parser.parString(ok,0);
insilmaril@398
  1017
			if (ok) select (s);
insilmaril@398
  1018
		}	
insilmaril@514
  1019
	/////////////////////////////////////////////////////////////////////
insilmaril@432
  1020
	} else if (com=="selectLastBranch")
insilmaril@432
  1021
	{
insilmaril@432
  1022
		if (xelection.isEmpty() )
insilmaril@432
  1023
		{
insilmaril@432
  1024
			parser.setError (Aborted,"Nothing selected");
insilmaril@432
  1025
		} else if (! selb )
insilmaril@432
  1026
		{				  
insilmaril@432
  1027
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1028
		} else if (parser.checkParCount(0))
insilmaril@432
  1029
		{	
insilmaril@432
  1030
			BranchObj *bo=selb->getLastBranch();
insilmaril@432
  1031
			if (!bo)
insilmaril@432
  1032
				parser.setError (Aborted,"Could not select last branch");
insilmaril@432
  1033
			selectInt (bo);	
insilmaril@432
  1034
				
insilmaril@432
  1035
		}	
insilmaril@514
  1036
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1037
	} else if (com=="selectLastImage")
insilmaril@434
  1038
	{
insilmaril@434
  1039
		if (xelection.isEmpty() )
insilmaril@434
  1040
		{
insilmaril@434
  1041
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1042
		} else if (! selb )
insilmaril@434
  1043
		{				  
insilmaril@434
  1044
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1045
		} else if (parser.checkParCount(0))
insilmaril@434
  1046
		{	
insilmaril@434
  1047
			FloatImageObj *fio=selb->getLastFloatImage();
insilmaril@434
  1048
			if (!fio)
insilmaril@434
  1049
				parser.setError (Aborted,"Could not select last image");
insilmaril@434
  1050
			selectInt (fio);	
insilmaril@434
  1051
				
insilmaril@434
  1052
		}	
insilmaril@514
  1053
	/////////////////////////////////////////////////////////////////////
insilmaril@537
  1054
	} else if (com=="selectLatestAdded")
insilmaril@537
  1055
	{
insilmaril@537
  1056
		if (latestSelection.isEmpty() )
insilmaril@537
  1057
		{
insilmaril@537
  1058
			parser.setError (Aborted,"No latest added object");
insilmaril@537
  1059
		} else
insilmaril@537
  1060
		{	
insilmaril@537
  1061
			if (!select (latestSelection))
insilmaril@537
  1062
				parser.setError (Aborted,"Could not select latest added object "+latestSelection);
insilmaril@537
  1063
		}	
insilmaril@537
  1064
	/////////////////////////////////////////////////////////////////////
insilmaril@473
  1065
	} else if (com=="setFrameType")
insilmaril@473
  1066
	{
insilmaril@491
  1067
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@473
  1068
		{
insilmaril@473
  1069
			parser.setError (Aborted,"Type of selection does not allow setting frame type");
insilmaril@473
  1070
		}
insilmaril@514
  1071
		else if (parser.checkParCount(1))
insilmaril@473
  1072
		{
insilmaril@473
  1073
			s=parser.parString(ok,0);
insilmaril@473
  1074
			if (ok) setFrameType (s);
insilmaril@473
  1075
		}	
insilmaril@514
  1076
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1077
	} else if (com=="setFramePenColor")
insilmaril@486
  1078
	{
insilmaril@491
  1079
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1080
		{
insilmaril@486
  1081
			parser.setError (Aborted,"Type of selection does not allow setting of pen color");
insilmaril@486
  1082
		}
insilmaril@514
  1083
		else if (parser.checkParCount(1))
insilmaril@486
  1084
		{
insilmaril@486
  1085
			QColor c=parser.parColor(ok,0);
insilmaril@486
  1086
			if (ok) setFramePenColor (c);
insilmaril@486
  1087
		}	
insilmaril@514
  1088
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1089
	} else if (com=="setFrameBrushColor")
insilmaril@486
  1090
	{
insilmaril@491
  1091
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1092
		{
insilmaril@486
  1093
			parser.setError (Aborted,"Type of selection does not allow setting brush color");
insilmaril@486
  1094
		}
insilmaril@514
  1095
		else if (parser.checkParCount(1))
insilmaril@486
  1096
		{
insilmaril@486
  1097
			QColor c=parser.parColor(ok,0);
insilmaril@486
  1098
			if (ok) setFrameBrushColor (c);
insilmaril@486
  1099
		}	
insilmaril@514
  1100
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1101
	} else if (com=="setFramePadding")
insilmaril@486
  1102
	{
insilmaril@491
  1103
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1104
		{
insilmaril@486
  1105
			parser.setError (Aborted,"Type of selection does not allow setting frame padding");
insilmaril@486
  1106
		}
insilmaril@514
  1107
		else if (parser.checkParCount(1))
insilmaril@486
  1108
		{
insilmaril@537
  1109
			n=parser.parInt(ok,0);
insilmaril@537
  1110
			if (ok) setFramePadding(n);
insilmaril@486
  1111
		}	
insilmaril@514
  1112
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1113
	} else if (com=="setFrameBorderWidth")
insilmaril@486
  1114
	{
insilmaril@491
  1115
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1116
		{
insilmaril@486
  1117
			parser.setError (Aborted,"Type of selection does not allow setting frame border width");
insilmaril@486
  1118
		}
insilmaril@514
  1119
		else if (parser.checkParCount(1))
insilmaril@486
  1120
		{
insilmaril@537
  1121
			n=parser.parInt(ok,0);
insilmaril@537
  1122
			if (ok) setFrameBorderWidth (n);
insilmaril@486
  1123
		}	
insilmaril@514
  1124
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1125
	} else if (com=="setMapAuthor")
insilmaril@398
  1126
	{
insilmaril@514
  1127
		if (parser.checkParCount(1))
insilmaril@398
  1128
		{
insilmaril@432
  1129
			s=parser.parString(ok,0);
insilmaril@398
  1130
			if (ok) setMapAuthor (s);
insilmaril@398
  1131
		}	
insilmaril@514
  1132
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1133
	} else if (com=="setMapComment")
insilmaril@398
  1134
	{
insilmaril@514
  1135
		if (parser.checkParCount(1))
insilmaril@398
  1136
		{
insilmaril@432
  1137
			s=parser.parString(ok,0);
insilmaril@398
  1138
			if (ok) setMapComment(s);
insilmaril@398
  1139
		}	
insilmaril@514
  1140
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1141
	} else if (com=="setMapBackgroundColor")
insilmaril@398
  1142
	{
insilmaril@424
  1143
		if (xelection.isEmpty() )
insilmaril@398
  1144
		{
insilmaril@432
  1145
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1146
		} else if (! xelection.getBranch() )
insilmaril@398
  1147
		{				  
insilmaril@432
  1148
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1149
		} else if (parser.checkParCount(1))
insilmaril@398
  1150
		{
insilmaril@432
  1151
			QColor c=parser.parColor (ok,0);
insilmaril@398
  1152
			if (ok) setMapBackgroundColor (c);
insilmaril@398
  1153
		}	
insilmaril@514
  1154
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1155
	} else if (com=="setMapDefLinkColor")
insilmaril@398
  1156
	{
insilmaril@424
  1157
		if (xelection.isEmpty() )
insilmaril@398
  1158
		{
insilmaril@432
  1159
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1160
		} else if (! selb )
insilmaril@398
  1161
		{				  
insilmaril@432
  1162
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1163
		} else if (parser.checkParCount(1))
insilmaril@398
  1164
		{
insilmaril@432
  1165
			QColor c=parser.parColor (ok,0);
insilmaril@398
  1166
			if (ok) setMapDefLinkColor (c);
insilmaril@398
  1167
		}	
insilmaril@514
  1168
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1169
	} else if (com=="setMapLinkStyle")
insilmaril@398
  1170
	{
insilmaril@514
  1171
		if (parser.checkParCount(1))
insilmaril@398
  1172
		{
insilmaril@432
  1173
			s=parser.parString (ok,0);
insilmaril@398
  1174
			if (ok) setMapLinkStyle(s);
insilmaril@398
  1175
		}	
insilmaril@514
  1176
	/////////////////////////////////////////////////////////////////////
insilmaril@129
  1177
	} else if (com=="setHeading")
insilmaril@129
  1178
	{
insilmaril@424
  1179
		if (xelection.isEmpty() )
insilmaril@394
  1180
		{
insilmaril@432
  1181
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1182
		} else if (! selb )
insilmaril@394
  1183
		{				  
insilmaril@432
  1184
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1185
		} else if (parser.checkParCount(1))
insilmaril@129
  1186
		{
insilmaril@432
  1187
			s=parser.parString (ok,0);
insilmaril@366
  1188
			if (ok) 
insilmaril@366
  1189
				setHeading (s);
insilmaril@129
  1190
		}	
insilmaril@514
  1191
	/////////////////////////////////////////////////////////////////////
insilmaril@395
  1192
	} else if (com=="setHideExport")
insilmaril@395
  1193
	{
insilmaril@424
  1194
		if (xelection.isEmpty() )
insilmaril@395
  1195
		{
insilmaril@432
  1196
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
  1197
		} else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
insilmaril@395
  1198
		{				  
insilmaril@432
  1199
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
  1200
		} else if (parser.checkParCount(1))
insilmaril@395
  1201
		{
insilmaril@432
  1202
			b=parser.parBool(ok,0);
insilmaril@395
  1203
			if (ok) setHideExport (b);
insilmaril@395
  1204
		}
insilmaril@514
  1205
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1206
	} else if (com=="setIncludeImagesHorizontally")
insilmaril@473
  1207
	{ 
insilmaril@434
  1208
		if (xelection.isEmpty() )
insilmaril@434
  1209
		{
insilmaril@434
  1210
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1211
		} else if (! selb)
insilmaril@434
  1212
		{				  
insilmaril@434
  1213
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1214
		} else if (parser.checkParCount(1))
insilmaril@434
  1215
		{
insilmaril@434
  1216
			b=parser.parBool(ok,0);
insilmaril@434
  1217
			if (ok) setIncludeImagesHor(b);
insilmaril@434
  1218
		}
insilmaril@514
  1219
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1220
	} else if (com=="setIncludeImagesVertically")
insilmaril@434
  1221
	{
insilmaril@434
  1222
		if (xelection.isEmpty() )
insilmaril@434
  1223
		{
insilmaril@434
  1224
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1225
		} else if (! selb)
insilmaril@434
  1226
		{				  
insilmaril@434
  1227
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1228
		} else if (parser.checkParCount(1))
insilmaril@434
  1229
		{
insilmaril@434
  1230
			b=parser.parBool(ok,0);
insilmaril@434
  1231
			if (ok) setIncludeImagesVer(b);
insilmaril@434
  1232
		}
insilmaril@514
  1233
	/////////////////////////////////////////////////////////////////////
insilmaril@491
  1234
	} else if (com=="setHideLinkUnselected")
insilmaril@491
  1235
	{
insilmaril@491
  1236
		if (xelection.isEmpty() )
insilmaril@491
  1237
		{
insilmaril@491
  1238
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
  1239
		} else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@491
  1240
		{				  
insilmaril@491
  1241
			parser.setError (Aborted,"Type of selection does not allow hiding the link");
insilmaril@514
  1242
		} else if (parser.checkParCount(1))
insilmaril@491
  1243
		{
insilmaril@491
  1244
			b=parser.parBool(ok,0);
insilmaril@491
  1245
			if (ok) setHideLinkUnselected(b);
insilmaril@491
  1246
		}
insilmaril@514
  1247
	/////////////////////////////////////////////////////////////////////
insilmaril@442
  1248
	} else if (com=="setSelectionColor")
insilmaril@442
  1249
	{
insilmaril@514
  1250
		if (parser.checkParCount(1))
insilmaril@442
  1251
		{
insilmaril@442
  1252
			QColor c=parser.parColor (ok,0);
insilmaril@442
  1253
			if (ok) setSelectionColorInt (c);
insilmaril@442
  1254
		}	
insilmaril@514
  1255
	/////////////////////////////////////////////////////////////////////
insilmaril@143
  1256
	} else if (com=="setURL")
insilmaril@143
  1257
	{
insilmaril@424
  1258
		if (xelection.isEmpty() )
insilmaril@394
  1259
		{
insilmaril@432
  1260
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1261
		} else if (! selb )
insilmaril@394
  1262
		{				  
insilmaril@432
  1263
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1264
		} else if (parser.checkParCount(1))
insilmaril@143
  1265
		{
insilmaril@432
  1266
			s=parser.parString (ok,0);
insilmaril@491
  1267
			if (ok) setURL(s);
insilmaril@143
  1268
		}	
insilmaril@514
  1269
	/////////////////////////////////////////////////////////////////////
insilmaril@143
  1270
	} else if (com=="setVymLink")
insilmaril@143
  1271
	{
insilmaril@424
  1272
		if (xelection.isEmpty() )
insilmaril@394
  1273
		{
insilmaril@432
  1274
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1275
		} else if (! selb )
insilmaril@394
  1276
		{				  
insilmaril@432
  1277
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1278
		} else if (parser.checkParCount(1))
insilmaril@143
  1279
		{
insilmaril@432
  1280
			s=parser.parString (ok,0);
insilmaril@366
  1281
			if (ok) setVymLinkInt(s);
insilmaril@143
  1282
		}	
insilmaril@143
  1283
	}
insilmaril@514
  1284
	/////////////////////////////////////////////////////////////////////
insilmaril@366
  1285
	else if (com=="setFlag")
insilmaril@366
  1286
	{
insilmaril@424
  1287
		if (xelection.isEmpty() )
insilmaril@366
  1288
		{
insilmaril@432
  1289
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1290
		} else if (! selb )
insilmaril@394
  1291
		{				  
insilmaril@432
  1292
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1293
		} else if (parser.checkParCount(1))
insilmaril@394
  1294
		{
insilmaril@432
  1295
			s=parser.parString(ok,0);
insilmaril@394
  1296
			if (ok) 
insilmaril@394
  1297
			{
insilmaril@424
  1298
				selb->activateStandardFlag(s);
insilmaril@424
  1299
				selb->updateFlagsToolbar();
insilmaril@366
  1300
			}	
insilmaril@366
  1301
		}
insilmaril@514
  1302
	/////////////////////////////////////////////////////////////////////
insilmaril@445
  1303
	} else if (com=="setFrameType")
insilmaril@445
  1304
	{
insilmaril@445
  1305
		if (xelection.isEmpty() )
insilmaril@445
  1306
		{
insilmaril@445
  1307
			parser.setError (Aborted,"Nothing selected");
insilmaril@445
  1308
		} else if (! selb )
insilmaril@445
  1309
		{				  
insilmaril@445
  1310
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1311
		} else if (parser.checkParCount(1))
insilmaril@445
  1312
		{
insilmaril@445
  1313
			s=parser.parString(ok,0);
insilmaril@445
  1314
			if (ok) 
insilmaril@445
  1315
				setFrameType (s);
insilmaril@445
  1316
		}
insilmaril@514
  1317
	/////////////////////////////////////////////////////////////////////
insilmaril@447
  1318
	} else if (com=="toggleFlag")
insilmaril@447
  1319
	{
insilmaril@447
  1320
		if (xelection.isEmpty() )
insilmaril@447
  1321
		{
insilmaril@447
  1322
			parser.setError (Aborted,"Nothing selected");
insilmaril@447
  1323
		} else if (! selb )
insilmaril@447
  1324
		{				  
insilmaril@447
  1325
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1326
		} else if (parser.checkParCount(1))
insilmaril@447
  1327
		{
insilmaril@447
  1328
			s=parser.parString(ok,0);
insilmaril@447
  1329
			if (ok) 
insilmaril@447
  1330
			{
insilmaril@447
  1331
				selb->toggleStandardFlag(s);	
insilmaril@447
  1332
				selb->updateFlagsToolbar();
insilmaril@447
  1333
			}	
insilmaril@447
  1334
		}
insilmaril@514
  1335
	/////////////////////////////////////////////////////////////////////
insilmaril@427
  1336
	} else if (com=="unscroll")
insilmaril@427
  1337
	{
insilmaril@427
  1338
		if (xelection.isEmpty() )
insilmaril@427
  1339
		{
insilmaril@432
  1340
			parser.setError (Aborted,"Nothing selected");
insilmaril@427
  1341
		} else if (! selb )
insilmaril@427
  1342
		{				  
insilmaril@432
  1343
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1344
		} else if (parser.checkParCount(0))
insilmaril@427
  1345
		{	
insilmaril@473
  1346
			if (!unscrollBranch (selb))	
insilmaril@432
  1347
				parser.setError (Aborted,"Could not unscroll branch");
insilmaril@427
  1348
		}	
insilmaril@514
  1349
	/////////////////////////////////////////////////////////////////////
insilmaril@473
  1350
	} else if (com=="unscrollChilds")
insilmaril@473
  1351
	{
insilmaril@473
  1352
		if (xelection.isEmpty() )
insilmaril@473
  1353
		{
insilmaril@473
  1354
			parser.setError (Aborted,"Nothing selected");
insilmaril@473
  1355
		} else if (! selb )
insilmaril@473
  1356
		{				  
insilmaril@473
  1357
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1358
		} else if (parser.checkParCount(0))
insilmaril@473
  1359
		{	
insilmaril@473
  1360
			unscrollChilds ();
insilmaril@473
  1361
		}	
insilmaril@514
  1362
	/////////////////////////////////////////////////////////////////////
insilmaril@427
  1363
	} else if (com=="unsetFlag")
insilmaril@366
  1364
	{
insilmaril@424
  1365
		if (xelection.isEmpty() )
insilmaril@366
  1366
		{
insilmaril@432
  1367
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1368
		} else if (! selb )
insilmaril@394
  1369
		{				  
insilmaril@432
  1370
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1371
		} else if (parser.checkParCount(1))
insilmaril@394
  1372
		{
insilmaril@432
  1373
			s=parser.parString(ok,0);
insilmaril@394
  1374
			if (ok) 
insilmaril@394
  1375
			{
insilmaril@424
  1376
				selb->deactivateStandardFlag(s);
insilmaril@424
  1377
				selb->updateFlagsToolbar();
insilmaril@366
  1378
			}	
insilmaril@366
  1379
		}
insilmaril@398
  1380
	} else
insilmaril@432
  1381
		parser.setError (Aborted,"Unknown command");
insilmaril@129
  1382
insilmaril@129
  1383
	// Any errors?
insilmaril@432
  1384
	if (parser.errorLevel()==NoError)
insilmaril@432
  1385
	{
insilmaril@613
  1386
		// setChanged();  FIXME should not be called e.g. for export?!
insilmaril@432
  1387
		mapCenter->reposition();
insilmaril@432
  1388
	}	
insilmaril@394
  1389
	else	
insilmaril@106
  1390
	{
insilmaril@366
  1391
		// TODO Error handling
insilmaril@366
  1392
		qWarning("MapEditor::parseAtom: Error!");
insilmaril@432
  1393
		qWarning(parser.errorMessage());
insilmaril@394
  1394
	} 
insilmaril@0
  1395
}
insilmaril@0
  1396
insilmaril@432
  1397
void MapEditor::runScript (QString script)
insilmaril@432
  1398
{
insilmaril@445
  1399
	parser.setScript (script);
insilmaril@445
  1400
	parser.runScript();
insilmaril@447
  1401
	while (parser.next() ) 
insilmaril@447
  1402
		parseAtom(parser.getAtom());
insilmaril@432
  1403
}
insilmaril@0
  1404
insilmaril@0
  1405
bool MapEditor::isDefault()
insilmaril@0
  1406
{
insilmaril@0
  1407
    return mapDefault;
insilmaril@0
  1408
}
insilmaril@0
  1409
insilmaril@0
  1410
bool MapEditor::hasChanged()
insilmaril@0
  1411
{
insilmaril@0
  1412
    return mapChanged;
insilmaril@0
  1413
}
insilmaril@0
  1414
insilmaril@0
  1415
void MapEditor::setChanged()
insilmaril@0
  1416
{
insilmaril@473
  1417
	if (!mapChanged)
insilmaril@473
  1418
		autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
insilmaril@0
  1419
	mapChanged=true;
insilmaril@0
  1420
	mapDefault=false;
insilmaril@0
  1421
	mapUnsaved=true;
insilmaril@0
  1422
	findReset();
insilmaril@473
  1423
insilmaril@0
  1424
}
insilmaril@0
  1425
insilmaril@0
  1426
void MapEditor::closeMap()
insilmaril@0
  1427
{
insilmaril@0
  1428
	// Unselect before disabling the toolbar actions
insilmaril@424
  1429
	if (!xelection.isEmpty() ) xelection.unselect();
insilmaril@424
  1430
	xelection.clear();
insilmaril@0
  1431
	updateActions();
insilmaril@0
  1432
insilmaril@0
  1433
    clear();
insilmaril@0
  1434
	close();
insilmaril@0
  1435
}
insilmaril@0
  1436
insilmaril@486
  1437
void MapEditor::setFilePath(QString fpath, QString destname)
insilmaril@0
  1438
{
insilmaril@486
  1439
	if (fpath.isEmpty() || fpath=="")
insilmaril@106
  1440
	{
insilmaril@106
  1441
		filePath="";
insilmaril@106
  1442
		fileName="";
insilmaril@106
  1443
		destPath="";
insilmaril@106
  1444
	} else
insilmaril@106
  1445
	{
insilmaril@486
  1446
		filePath=fpath;		// becomes absolute path
insilmaril@486
  1447
		fileName=fpath;		// gets stripped of path
insilmaril@106
  1448
		destPath=destname;	// needed for vymlinks
insilmaril@106
  1449
insilmaril@486
  1450
		// If fpath is not an absolute path, complete it
insilmaril@486
  1451
		filePath=QDir(fpath).absPath();
insilmaril@106
  1452
		fileDir=filePath.left (1+filePath.findRev ("/"));
insilmaril@106
  1453
insilmaril@106
  1454
		// Set short name, too. Search from behind:
insilmaril@106
  1455
		int i=fileName.findRev("/");
insilmaril@106
  1456
		if (i>=0) fileName=fileName.remove (0,i+1);
insilmaril@106
  1457
insilmaril@106
  1458
		// Forget the .vym (or .xml) for name of map
insilmaril@106
  1459
		mapName=fileName.left(fileName.findRev(".",-1,true) );
insilmaril@106
  1460
	}
insilmaril@0
  1461
}
insilmaril@0
  1462
insilmaril@486
  1463
void MapEditor::setFilePath(QString fpath)
insilmaril@486
  1464
{
insilmaril@486
  1465
	setFilePath (fpath,fpath);
insilmaril@486
  1466
}
insilmaril@486
  1467
insilmaril@0
  1468
QString MapEditor::getFilePath()
insilmaril@0
  1469
{
insilmaril@0
  1470
	return filePath;
insilmaril@0
  1471
}
insilmaril@0
  1472
insilmaril@0
  1473
QString MapEditor::getFileName()
insilmaril@0
  1474
{
insilmaril@0
  1475
	return fileName;
insilmaril@0
  1476
}
insilmaril@0
  1477
insilmaril@0
  1478
QString MapEditor::getMapName()
insilmaril@0
  1479
{
insilmaril@0
  1480
	return mapName;
insilmaril@0
  1481
}
insilmaril@0
  1482
insilmaril@0
  1483
QString MapEditor::getDestPath()
insilmaril@0
  1484
{
insilmaril@0
  1485
	return destPath;
insilmaril@0
  1486
}
insilmaril@0
  1487
insilmaril@571
  1488
ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
insilmaril@0
  1489
{
insilmaril@205
  1490
	ErrorCode err=success;
insilmaril@0
  1491
insilmaril@571
  1492
	parseBaseHandler *handler;
insilmaril@571
  1493
	switch (ftype)
insilmaril@571
  1494
	{
insilmaril@571
  1495
		case VymMap: handler=new parseVYMHandler; break;
insilmaril@571
  1496
		case FreemindMap : handler=new parseFreemindHandler; break;
insilmaril@571
  1497
		default: 
insilmaril@571
  1498
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@571
  1499
				   "Unknown FileType in MapEditor::load()");
insilmaril@571
  1500
		return aborted;	
insilmaril@571
  1501
	}
insilmaril@0
  1502
	if (lmode==NewMap)
insilmaril@0
  1503
	{
insilmaril@424
  1504
		if (xelection.isEmpty() ) xelection.unselect();
insilmaril@424
  1505
		xelection.clear();
insilmaril@0
  1506
		mapCenter->clear();
insilmaril@0
  1507
		mapCenter->setMapEditor(this);
insilmaril@0
  1508
		// (map state is set later at end of load...)
insilmaril@0
  1509
	} else
insilmaril@0
  1510
	{
insilmaril@424
  1511
		BranchObj *bo=xelection.getBranch();
insilmaril@424
  1512
		if (!bo) return aborted;
insilmaril@395
  1513
		if (lmode==ImportAdd)
insilmaril@395
  1514
			saveStateChangingPart(
insilmaril@424
  1515
				bo,
insilmaril@424
  1516
				bo,
insilmaril@395
  1517
				QString("addMapInsert (%1)").arg(fname),
insilmaril@395
  1518
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@395
  1519
		else	
insilmaril@395
  1520
			saveStateChangingPart(
insilmaril@424
  1521
				bo,
insilmaril@424
  1522
				bo,
insilmaril@395
  1523
				QString("addMapReplace(%1)").arg(fname),
insilmaril@395
  1524
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@0
  1525
	}	
insilmaril@0
  1526
    
insilmaril@0
  1527
	QFile file( fname );
insilmaril@0
  1528
insilmaril@0
  1529
	// I am paranoid: file should exist anyway
insilmaril@0
  1530
	// according to check in mainwindow.
insilmaril@0
  1531
	if (!file.exists() )
insilmaril@0
  1532
	{
insilmaril@0
  1533
		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
  1534
				   tr("Couldn't open map " +fname)+".");
insilmaril@205
  1535
		err=aborted;	
insilmaril@0
  1536
	} else
insilmaril@0
  1537
	{
insilmaril@473
  1538
		bool blockSaveStateOrg=blockSaveState;
insilmaril@139
  1539
		blockReposition=true;
insilmaril@473
  1540
		blockSaveState=true;
insilmaril@0
  1541
		QXmlInputSource source( file);
insilmaril@0
  1542
		QXmlSimpleReader reader;
insilmaril@571
  1543
		reader.setContentHandler( handler );
insilmaril@571
  1544
		reader.setErrorHandler( handler );
insilmaril@571
  1545
		handler->setMapEditor( this );
insilmaril@494
  1546
insilmaril@494
  1547
insilmaril@494
  1548
		// We need to set the tmpDir in order  to load files with rel. path
insilmaril@494
  1549
		QString tmpdir= fname.left(fname.findRev("/",-1));	
insilmaril@571
  1550
		handler->setTmpDir (tmpdir);
insilmaril@571
  1551
		handler->setInputFile (file.name());
insilmaril@571
  1552
		handler->setLoadMode (lmode);
insilmaril@0
  1553
		bool ok = reader.parse( source );
insilmaril@139
  1554
		blockReposition=false;
insilmaril@473
  1555
		blockSaveState=blockSaveStateOrg;
insilmaril@0
  1556
		file.close();
insilmaril@0
  1557
		if ( ok ) 
insilmaril@0
  1558
		{
insilmaril@0
  1559
			mapCenter->reposition();
insilmaril@442
  1560
			xelection.update();
insilmaril@0
  1561
			if (lmode==NewMap)
insilmaril@0
  1562
			{
insilmaril@0
  1563
				mapDefault=false;
insilmaril@0
  1564
				mapChanged=false;
insilmaril@0
  1565
				mapUnsaved=false;
insilmaril@473
  1566
				autosaveTimer->stop();
insilmaril@0
  1567
			}
insilmaril@0
  1568
		} else 
insilmaril@0
  1569
		{
insilmaril@0
  1570
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@571
  1571
					   tr( handler->errorProtocol() ) );
insilmaril@0
  1572
			// returnCode=1;	
insilmaril@0
  1573
			// Still return "success": the map maybe at least
insilmaril@0
  1574
			// partially read by the parser
insilmaril@0
  1575
		}	
insilmaril@0
  1576
	}	
insilmaril@0
  1577
	updateActions();
insilmaril@205
  1578
	return err;
insilmaril@0
  1579
}
insilmaril@0
  1580
insilmaril@0
  1581
int MapEditor::save (const SaveMode &savemode)
insilmaril@0
  1582
{
insilmaril@0
  1583
	// Create mapName and fileDir
insilmaril@0
  1584
	makeSubDirs (fileDir);
insilmaril@0
  1585
	QString fname;
insilmaril@0
  1586
	if (saveZipped())
insilmaril@0
  1587
		// save as .xml
insilmaril@0
  1588
		fname=mapName+".xml";
insilmaril@0
  1589
	else
insilmaril@0
  1590
		// use name given by user, even if he chooses .doc
insilmaril@0
  1591
		fname=fileName;
insilmaril@0
  1592
insilmaril@0
  1593
insilmaril@0
  1594
	QString saveFile;
insilmaril@424
  1595
	if (savemode==CompleteMap || xelection.isEmpty())
insilmaril@408
  1596
		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
insilmaril@106
  1597
	else	
insilmaril@491
  1598
	{
insilmaril@491
  1599
		// TODO take care of multiselections
insilmaril@491
  1600
		if (xelection.type()==Selection::FloatImage)
insilmaril@491
  1601
			saveFloatImage();
insilmaril@491
  1602
		else	
insilmaril@491
  1603
			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
insilmaril@531
  1604
		return 0;	
insilmaril@491
  1605
	}	
insilmaril@0
  1606
insilmaril@163
  1607
	if (!saveStringToDisk(fileDir+fname,saveFile))
insilmaril@0
  1608
		return 1;
insilmaril@0
  1609
insilmaril@531
  1610
	mapChanged=false;
insilmaril@531
  1611
	mapUnsaved=false;
insilmaril@531
  1612
	autosaveTimer->stop();
insilmaril@531
  1613
	updateActions();
insilmaril@531
  1614
	return 0;
insilmaril@0
  1615
}
insilmaril@0
  1616
insilmaril@0
  1617
void MapEditor::setZipped (bool z)
insilmaril@0
  1618
{
insilmaril@0
  1619
	zipped=z;
insilmaril@0
  1620
}
insilmaril@0
  1621
insilmaril@0
  1622
bool MapEditor::saveZipped ()
insilmaril@0
  1623
{
insilmaril@0
  1624
	return zipped;
insilmaril@0
  1625
}
insilmaril@0
  1626
insilmaril@0
  1627
void MapEditor::print()
insilmaril@0
  1628
{
insilmaril@0
  1629
	if ( !printer ) 
insilmaril@0
  1630
	{
insilmaril@0
  1631
		printer = new QPrinter;
insilmaril@0
  1632
		printer->setColorMode (QPrinter::Color);
insilmaril@366
  1633
		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@412
  1634
		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
insilmaril@412
  1635
		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
insilmaril@0
  1636
	}
insilmaril@0
  1637
insilmaril@408
  1638
	QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@0
  1639
insilmaril@0
  1640
	// Try to set orientation automagically
insilmaril@0
  1641
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
  1642
	// there are problems with landscape mode, see
insilmaril@0
  1643
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
  1644
insilmaril@0
  1645
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
  1646
		// recommend landscape
insilmaril@0
  1647
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
  1648
	else	
insilmaril@0
  1649
		// recommend portrait
insilmaril@0
  1650
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
  1651
insilmaril@0
  1652
	if ( printer->setup(this) ) 
insilmaril@0
  1653
	// returns false, if printing is canceled
insilmaril@0
  1654
	{
insilmaril@0
  1655
		QPainter pp(printer);
insilmaril@0
  1656
insilmaril@412
  1657
		pp.setRenderHint(QPainter::Antialiasing,true);
insilmaril@412
  1658
insilmaril@0
  1659
		// Don't print the visualisation of selection
insilmaril@424
  1660
		xelection.unselect();
insilmaril@0
  1661
insilmaril@408
  1662
		QRectF mapRect=totalBBox;
insilmaril@411
  1663
		QGraphicsRectItem *frame=NULL;
insilmaril@412
  1664
insilmaril@417
  1665
		if (printFrame) 
insilmaril@0
  1666
		{
insilmaril@417
  1667
			// Print frame around map
insilmaril@417
  1668
			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@417
  1669
				totalBBox.width()+20, totalBBox.height()+20);
insilmaril@417
  1670
			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
insilmaril@417
  1671
			frame->setZValue(0);
insilmaril@417
  1672
			frame->show();    
insilmaril@417
  1673
		}		
insilmaril@417
  1674
insilmaril@417
  1675
insilmaril@412
  1676
		double paperAspect = (double)printer->width()   / (double)printer->height();
insilmaril@412
  1677
		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
insilmaril@417
  1678
		int viewBottom;
insilmaril@0
  1679
		if (mapAspect>=paperAspect)
insilmaril@0
  1680
		{
insilmaril@0
  1681
			// Fit horizontally to paper width
insilmaril@417
  1682
			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
insilmaril@417
  1683
			viewBottom=(int)(printer->width()/mapAspect);	
insilmaril@0
  1684
		}	else
insilmaril@0
  1685
		{
insilmaril@0
  1686
			// Fit vertically to paper height
insilmaril@417
  1687
			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
insilmaril@417
  1688
			viewBottom=printer->height();	
insilmaril@0
  1689
		}	
insilmaril@417
  1690
		
insilmaril@417
  1691
		if (printFooter) 
insilmaril@417
  1692
		{
insilmaril@417
  1693
			// Print footer below map
insilmaril@417
  1694
			QFont font;		
insilmaril@417
  1695
			font.setPointSize(10);
insilmaril@417
  1696
			pp.setFont (font);
insilmaril@417
  1697
			QRectF footerBox(0,viewBottom,printer->width(),15);
insilmaril@417
  1698
			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
insilmaril@417
  1699
			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
insilmaril@417
  1700
		}
insilmaril@412
  1701
		mapScene->render (
insilmaril@412
  1702
			&pp, 
insilmaril@412
  1703
			QRectF (0,0,printer->width(),printer->height()-15),
insilmaril@412
  1704
			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
insilmaril@412
  1705
		);
insilmaril@412
  1706
		
insilmaril@412
  1707
		// Viewport has paper dimension
insilmaril@412
  1708
		if (frame)  delete (frame);
insilmaril@0
  1709
insilmaril@0
  1710
		// Restore selection
insilmaril@424
  1711
		xelection.reselect();
insilmaril@119
  1712
insilmaril@119
  1713
		// Save settings in vymrc
insilmaril@366
  1714
		settings.writeEntry("/mainwindow/printerName",printer->printerName());
insilmaril@412
  1715
		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
insilmaril@412
  1716
		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
insilmaril@0
  1717
	}
insilmaril@0
  1718
}
insilmaril@0
  1719
insilmaril@408
  1720
void MapEditor::setAntiAlias (bool b)
insilmaril@408
  1721
{
insilmaril@408
  1722
	setRenderHint(QPainter::Antialiasing,b);
insilmaril@408
  1723
}
insilmaril@408
  1724
insilmaril@408
  1725
void MapEditor::setSmoothPixmap(bool b)
insilmaril@408
  1726
{
insilmaril@408
  1727
	setRenderHint(QPainter::SmoothPixmapTransform,b);
insilmaril@408
  1728
}
insilmaril@408
  1729
insilmaril@0
  1730
QPixmap MapEditor::getPixmap()
insilmaril@0
  1731
{
insilmaril@408
  1732
	QRectF mapRect=mapCenter->getTotalBBox();
insilmaril@564
  1733
	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
insilmaril@0
  1734
	QPainter pp (&pix);
insilmaril@420
  1735
	
insilmaril@420
  1736
	pp.setRenderHints(renderHints());
insilmaril@0
  1737
insilmaril@0
  1738
	// Don't print the visualisation of selection
insilmaril@424
  1739
	xelection.unselect();
insilmaril@0
  1740
insilmaril@420
  1741
	mapScene->render (	&pp, 
insilmaril@450
  1742
		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
insilmaril@420
  1743
		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
insilmaril@420
  1744
insilmaril@0
  1745
	// Restore selection
insilmaril@424
  1746
	xelection.reselect();
insilmaril@0
  1747
	
insilmaril@0
  1748
	return pix;
insilmaril@0
  1749
}
insilmaril@0
  1750
insilmaril@473
  1751
void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
insilmaril@260
  1752
{
insilmaril@260
  1753
	hidemode=mode;
insilmaril@260
  1754
	mapCenter->setHideTmp (hidemode);
insilmaril@260
  1755
	mapCenter->reposition();
insilmaril@408
  1756
	scene()->update();
insilmaril@260
  1757
}
insilmaril@260
  1758
insilmaril@473
  1759
BranchObj::HideTmpMode MapEditor::getHideTmpMode()
insilmaril@260
  1760
{
insilmaril@260
  1761
	return hidemode;
insilmaril@260
  1762
}
insilmaril@260
  1763
insilmaril@260
  1764
void MapEditor::setExportMode (bool b)
insilmaril@260
  1765
{
insilmaril@260
  1766
	// should be called before and after exports
insilmaril@260
  1767
	// depending on the settings
insilmaril@600
  1768
	if (b && settings.value("/export/useHideExport","true")=="true")
insilmaril@473
  1769
		setHideTmpMode (BranchObj::HideExport);
insilmaril@260
  1770
	else	
insilmaril@473
  1771
		setHideTmpMode (BranchObj::HideNone);
insilmaril@0
  1772
}
insilmaril@0
  1773
insilmaril@514
  1774
void MapEditor::exportASCII(QString fname,bool askName)
insilmaril@0
  1775
{
insilmaril@514
  1776
	ExportASCII ex;
insilmaril@514
  1777
	ex.setMapCenter(mapCenter);
insilmaril@514
  1778
	if (fname=="") 
insilmaril@514
  1779
		ex.setFile (mapName+".txt");	
insilmaril@514
  1780
	else
insilmaril@514
  1781
		ex.setFile (fname);
insilmaril@514
  1782
insilmaril@514
  1783
	if (askName)
insilmaril@514
  1784
	{
insilmaril@514
  1785
		//ex.addFilter ("TXT (*.txt)");
insilmaril@514
  1786
		ex.setDir(lastImageDir);
insilmaril@514
  1787
		//ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
insilmaril@514
  1788
		ex.execDialog() ; 
insilmaril@514
  1789
	} 
insilmaril@514
  1790
	if (!ex.canceled())
insilmaril@514
  1791
	{
insilmaril@514
  1792
		setExportMode(true);
insilmaril@514
  1793
		ex.doExport();
insilmaril@514
  1794
		setExportMode(false);
insilmaril@514
  1795
	}
insilmaril@514
  1796
}
insilmaril@514
  1797
insilmaril@514
  1798
void MapEditor::exportImage(QString fname, bool askName, QString format)
insilmaril@514
  1799
{
insilmaril@514
  1800
	if (fname=="")
insilmaril@514
  1801
	{
insilmaril@514
  1802
		fname=mapName+".png";
insilmaril@514
  1803
		format="PNG";
insilmaril@514
  1804
	} 	
insilmaril@514
  1805
insilmaril@514
  1806
	if (askName)
insilmaril@514
  1807
	{
insilmaril@514
  1808
		QStringList fl;
insilmaril@514
  1809
		QFileDialog *fd=new QFileDialog (this);
insilmaril@514
  1810
		fd->setCaption (tr("Export map as image"));
insilmaril@514
  1811
		fd->setDirectory (lastImageDir);
insilmaril@514
  1812
		fd->setFileMode(QFileDialog::AnyFile);
insilmaril@514
  1813
		fd->setFilters  (imageIO.getFilters() );
insilmaril@514
  1814
		if (fd->exec())
insilmaril@514
  1815
		{
insilmaril@514
  1816
			fl=fd->selectedFiles();
insilmaril@514
  1817
			fname=fl.first();
insilmaril@514
  1818
			format=imageIO.getType(fd->selectedFilter());
insilmaril@514
  1819
		} 
insilmaril@514
  1820
	}
insilmaril@514
  1821
insilmaril@260
  1822
	setExportMode (true);
insilmaril@0
  1823
	QPixmap pix (getPixmap());
insilmaril@514
  1824
	pix.save(fname, format);
insilmaril@260
  1825
	setExportMode (false);
insilmaril@0
  1826
}
insilmaril@0
  1827
insilmaril@185
  1828
void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
insilmaril@163
  1829
{
insilmaril@185
  1830
	ExportOO ex;
insilmaril@199
  1831
	ex.setFile (fn);
insilmaril@185
  1832
	ex.setMapCenter(mapCenter);
insilmaril@260
  1833
	if (ex.setConfigFile(cf)) 
insilmaril@260
  1834
	{
insilmaril@260
  1835
		setExportMode (true);
insilmaril@260
  1836
		ex.exportPresentation();
insilmaril@260
  1837
		setExportMode (false);
insilmaril@260
  1838
	}
insilmaril@163
  1839
}
insilmaril@163
  1840
insilmaril@520
  1841
void MapEditor::exportXHTML (const QString &dir, bool askForName)
insilmaril@517
  1842
{
insilmaril@517
  1843
			ExportXHTMLDialog dia(this);
insilmaril@517
  1844
			dia.setFilePath (filePath );
insilmaril@517
  1845
			dia.setMapName (mapName );
insilmaril@517
  1846
			dia.readSettings();
insilmaril@526
  1847
			if (dir!="") dia.setDir (dir);
insilmaril@517
  1848
insilmaril@517
  1849
			bool ok=true;
insilmaril@517
  1850
			
insilmaril@520
  1851
			if (askForName)
insilmaril@517
  1852
			{
insilmaril@517
  1853
				if (dia.exec()!=QDialog::Accepted) 
insilmaril@517
  1854
					ok=false;
insilmaril@517
  1855
				else	
insilmaril@517
  1856
				{
insilmaril@517
  1857
					QDir d (dia.getDir());
insilmaril@517
  1858
					// Check, if warnings should be used before overwriting
insilmaril@517
  1859
					// the output directory
insilmaril@517
  1860
					if (d.exists() && d.count()>0)
insilmaril@517
  1861
					{
insilmaril@517
  1862
						WarningDialog warn;
insilmaril@517
  1863
						warn.showCancelButton (true);
insilmaril@517
  1864
						warn.setText(QString(
insilmaril@517
  1865
							"The directory %1 is not empty.\n"
insilmaril@517
  1866
							"Do you risk to overwrite some of its contents?").arg(d.path() ));
insilmaril@517
  1867
						warn.setCaption("Warning: Directory not empty");
insilmaril@517
  1868
						warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
insilmaril@517
  1869
insilmaril@517
  1870
						if (warn.exec()!=QDialog::Accepted) ok=false;
insilmaril@517
  1871
					}
insilmaril@517
  1872
				}	
insilmaril@517
  1873
			}
insilmaril@517
  1874
insilmaril@517
  1875
			if (ok)
insilmaril@517
  1876
			{
insilmaril@526
  1877
				exportXML (dia.getDir(),false );
insilmaril@517
  1878
				dia.doExport(mapName );
insilmaril@517
  1879
				//if (dia.hasChanged()) setChanged();
insilmaril@517
  1880
			}
insilmaril@517
  1881
}
insilmaril@0
  1882
insilmaril@526
  1883
void MapEditor::exportXML(QString dir, bool askForName)
insilmaril@0
  1884
{
insilmaril@526
  1885
	if (askForName)
insilmaril@526
  1886
	{
insilmaril@526
  1887
		dir=browseDirectory(this,tr("Export XML to directory"));
insilmaril@526
  1888
		if (dir =="" && !reallyWriteDirectory(dir) )
insilmaril@526
  1889
		return;
insilmaril@526
  1890
	}
insilmaril@526
  1891
insilmaril@260
  1892
	// Hide stuff during export, if settings want this
insilmaril@260
  1893
	setExportMode (true);
insilmaril@260
  1894
insilmaril@0
  1895
	// Create subdirectories
insilmaril@0
  1896
	makeSubDirs (dir);
insilmaril@0
  1897
insilmaril@0
  1898
	// write to directory
insilmaril@106
  1899
	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
insilmaril@0
  1900
	QFile file;
insilmaril@0
  1901
insilmaril@0
  1902
	file.setName ( dir + "/"+mapName+".xml");
insilmaril@366
  1903
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
  1904
	{
insilmaril@0
  1905
		// This should neverever happen
insilmaril@159
  1906
		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
insilmaril@0
  1907
		return;
insilmaril@0
  1908
	}	
insilmaril@0
  1909
insilmaril@0
  1910
	// Write it finally, and write in UTF8, no matter what 
insilmaril@0
  1911
	QTextStream ts( &file );
insilmaril@0
  1912
	ts.setEncoding (QTextStream::UnicodeUTF8);
insilmaril@0
  1913
	ts << saveFile;
insilmaril@0
  1914
	file.close();
insilmaril@0
  1915
insilmaril@0
  1916
	// Now write image, too
insilmaril@517
  1917
	exportImage (dir+"/images/"+mapName+".png",false,"PNG");
insilmaril@260
  1918
insilmaril@260
  1919
	setExportMode (false);
insilmaril@0
  1920
}
insilmaril@0
  1921
insilmaril@0
  1922
void MapEditor::clear()
insilmaril@0
  1923
{
insilmaril@424
  1924
	xelection.unselect();
insilmaril@0
  1925
	mapCenter->clear();
insilmaril@0
  1926
}
insilmaril@0
  1927
insilmaril@0
  1928
void MapEditor::copy()
insilmaril@0
  1929
{
insilmaril@424
  1930
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  1931
	if (sel)
insilmaril@0
  1932
	{
insilmaril@502
  1933
		if (redosAvail == 0)
insilmaril@0
  1934
		{
insilmaril@502
  1935
			// Copy to history
insilmaril@502
  1936
			QString s=sel->getSelectString();
insilmaril@505
  1937
			saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel  );
insilmaril@502
  1938
			curClipboard=curStep;
insilmaril@502
  1939
		}
insilmaril@502
  1940
insilmaril@502
  1941
		// Copy also to global clipboard, because we are at last step in history
insilmaril@502
  1942
		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
insilmaril@502
  1943
		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
insilmaril@502
  1944
		copyDir (bakMapDir,clipboardDir );
insilmaril@166
  1945
insilmaril@166
  1946
		clipboardEmpty=false;
insilmaril@166
  1947
		updateActions();
insilmaril@0
  1948
	}	    
insilmaril@0
  1949
}
insilmaril@0
  1950
insilmaril@163
  1951
void MapEditor::redo()
insilmaril@163
  1952
{
insilmaril@381
  1953
	// Can we undo at all?
insilmaril@381
  1954
	if (redosAvail<1) return;
insilmaril@473
  1955
insilmaril@473
  1956
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  1957
	blockSaveState=true;
insilmaril@473
  1958
	
insilmaril@381
  1959
	redosAvail--;
insilmaril@381
  1960
insilmaril@381
  1961
	if (undosAvail<stepsTotal) undosAvail++;
insilmaril@366
  1962
	curStep++;
insilmaril@381
  1963
	if (curStep>stepsTotal) curStep=1;
insilmaril@366
  1964
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  1965
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  1966
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  1967
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  1968
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  1969
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  1970
insilmaril@395
  1971
	if (!checkVersion(version))
insilmaril@395
  1972
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  1973
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@395
  1974
insilmaril@366
  1975
insilmaril@163
  1976
	// Find out current undo directory
insilmaril@366
  1977
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@366
  1978
insilmaril@473
  1979
	if (debug)
insilmaril@473
  1980
	{
insilmaril@473
  1981
		cout << "ME::redo() begin\n";
insilmaril@473
  1982
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  1983
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  1984
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  1985
		cout << "    ---------------------------"<<endl;
insilmaril@473
  1986
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  1987
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  1988
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  1989
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  1990
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  1991
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  1992
	}
insilmaril@163
  1993
insilmaril@163
  1994
	// select  object before redo
insilmaril@163
  1995
	if (!redoSelection.isEmpty())
insilmaril@163
  1996
		select (redoSelection);
insilmaril@163
  1997
insilmaril@366
  1998
insilmaril@366
  1999
	parseAtom (redoCommand);
insilmaril@366
  2000
	mapCenter->reposition();
insilmaril@366
  2001
insilmaril@473
  2002
	blockSaveState=blockSaveStateOrg;
insilmaril@366
  2003
insilmaril@366
  2004
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  2005
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  2006
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  2007
	undoSet.writeSettings(histPath);
insilmaril@366
  2008
insilmaril@408
  2009
	mainWindow->updateHistory (undoSet);
insilmaril@407
  2010
	updateActions();
insilmaril@366
  2011
insilmaril@366
  2012
	/* TODO remove testing
insilmaril@163
  2013
	cout << "ME::redo() end\n";
insilmaril@163
  2014
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2015
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2016
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2017
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2018
	*/
insilmaril@366
  2019
insilmaril@366
  2020
insilmaril@163
  2021
}
insilmaril@163
  2022
insilmaril@390
  2023
bool MapEditor::isRedoAvailable()
insilmaril@390
  2024
{
insilmaril@393
  2025
	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
insilmaril@390
  2026
		return true;
insilmaril@390
  2027
	else	
insilmaril@390
  2028
		return false;
insilmaril@390
  2029
}
insilmaril@390
  2030
insilmaril@106
  2031
void MapEditor::undo()
insilmaril@106
  2032
{
insilmaril@381
  2033
	// Can we undo at all?
insilmaril@381
  2034
	if (undosAvail<1) return;
insilmaril@381
  2035
insilmaril@502
  2036
	mainWindow->statusMessage (tr("Autosave disabled during undo."));
insilmaril@502
  2037
insilmaril@473
  2038
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  2039
	blockSaveState=true;
insilmaril@473
  2040
	
insilmaril@366
  2041
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  2042
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  2043
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  2044
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  2045
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  2046
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  2047
insilmaril@395
  2048
	if (!checkVersion(version))
insilmaril@395
  2049
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  2050
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@366
  2051
insilmaril@163
  2052
	// Find out current undo directory
insilmaril@366
  2053
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@163
  2054
insilmaril@136
  2055
	// select  object before undo
insilmaril@136
  2056
	if (!undoSelection.isEmpty())
insilmaril@136
  2057
		select (undoSelection);
insilmaril@136
  2058
insilmaril@473
  2059
	if (debug)
insilmaril@473
  2060
	{
insilmaril@473
  2061
		cout << "ME::undo() begin\n";
insilmaril@473
  2062
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  2063
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  2064
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  2065
		cout << "    ---------------------------"<<endl;
insilmaril@473
  2066
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  2067
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  2068
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  2069
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  2070
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  2071
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  2072
	}	
insilmaril@106
  2073
	parseAtom (undoCommand);
insilmaril@106
  2074
	mapCenter->reposition();
insilmaril@106
  2075
insilmaril@163
  2076
	undosAvail--;
insilmaril@366
  2077
	curStep--; 
insilmaril@381
  2078
	if (curStep<1) curStep=stepsTotal;
insilmaril@366
  2079
insilmaril@366
  2080
	redosAvail++;
insilmaril@163
  2081
insilmaril@473
  2082
	blockSaveState=blockSaveStateOrg;
insilmaril@163
  2083
/* TODO remove testing
insilmaril@163
  2084
	cout << "ME::undo() end\n";
insilmaril@163
  2085
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2086
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2087
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2088
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2089
*/
insilmaril@366
  2090
insilmaril@366
  2091
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  2092
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  2093
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  2094
	undoSet.writeSettings(histPath);
insilmaril@366
  2095
insilmaril@404
  2096
	mainWindow->updateHistory (undoSet);
insilmaril@366
  2097
	updateActions();
insilmaril@442
  2098
	xelection.update();
insilmaril@420
  2099
	ensureSelectionVisible();
insilmaril@106
  2100
}
insilmaril@106
  2101
insilmaril@390
  2102
bool MapEditor::isUndoAvailable()
insilmaril@390
  2103
{
insilmaril@390
  2104
	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
insilmaril@390
  2105
		return true;
insilmaril@390
  2106
	else	
insilmaril@390
  2107
		return false;
insilmaril@390
  2108
}
insilmaril@390
  2109
insilmaril@404
  2110
void MapEditor::gotoHistoryStep (int i)
insilmaril@381
  2111
{
insilmaril@381
  2112
	// Restore variables
insilmaril@381
  2113
	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
insilmaril@388
  2114
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@388
  2115
insilmaril@388
  2116
	if (i<0) i=undosAvail+redosAvail;
insilmaril@388
  2117
insilmaril@388
  2118
	// Clicking above current step makes us undo things
insilmaril@381
  2119
	if (i<undosAvail) 
insilmaril@381
  2120
	{	
insilmaril@381
  2121
		for (int j=0; j<undosAvail-i; j++) undo();
insilmaril@381
  2122
		return;
insilmaril@381
  2123
	}	
insilmaril@388
  2124
	// Clicking below current step makes us redo things
insilmaril@381
  2125
	if (i>undosAvail) 
insilmaril@491
  2126
		for (int j=undosAvail; j<i; j++) 
insilmaril@491
  2127
		{
insilmaril@491
  2128
		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
insilmaril@491
  2129
		redo();
insilmaril@491
  2130
		}
insilmaril@381
  2131
insilmaril@381
  2132
	// And ignore clicking the current row ;-)	
insilmaril@381
  2133
}
insilmaril@381
  2134
insilmaril@394
  2135
void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
insilmaril@106
  2136
{
insilmaril@393
  2137
	QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2138
	QDir d(pathDir);
insilmaril@393
  2139
	QFile file (path);
insilmaril@163
  2140
insilmaril@106
  2141
	if (d.exists() )
insilmaril@106
  2142
	{
insilmaril@106
  2143
		// We need to parse saved XML data
insilmaril@564
  2144
		parseVYMHandler handler;
insilmaril@163
  2145
		QXmlInputSource source( file);
insilmaril@106
  2146
		QXmlSimpleReader reader;
insilmaril@106
  2147
		reader.setContentHandler( &handler );
insilmaril@106
  2148
		reader.setErrorHandler( &handler );
insilmaril@106
  2149
		handler.setMapEditor( this );
insilmaril@393
  2150
		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@106
  2151
		if (undoSel.isEmpty())
insilmaril@106
  2152
		{
insilmaril@139
  2153
			unselect();
insilmaril@106
  2154
			mapCenter->clear();
insilmaril@106
  2155
			handler.setLoadMode (NewMap);
insilmaril@106
  2156
		} else	
insilmaril@106
  2157
		{
insilmaril@106
  2158
			select (undoSel);
insilmaril@106
  2159
			handler.setLoadMode (ImportReplace);
insilmaril@106
  2160
		}	
insilmaril@139
  2161
		blockReposition=true;
insilmaril@106
  2162
		bool ok = reader.parse( source );
insilmaril@139
  2163
		blockReposition=false;
insilmaril@106
  2164
		if (! ok ) 
insilmaril@106
  2165
		{	
insilmaril@106
  2166
			// This should never ever happen
insilmaril@393
  2167
			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2168
								    handler.errorProtocol());
insilmaril@106
  2169
		}
insilmaril@106
  2170
	} else	
insilmaril@393
  2171
		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2172
}
insilmaril@393
  2173
insilmaril@394
  2174
void MapEditor::addMapInsertInt (const QString &path, int pos)
insilmaril@393
  2175
{
insilmaril@424
  2176
	BranchObj *sel=xelection.getBranch();
insilmaril@608
  2177
	if (sel)
insilmaril@106
  2178
	{
insilmaril@393
  2179
		QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2180
		QDir d(pathDir);
insilmaril@393
  2181
		QFile file (path);
insilmaril@393
  2182
insilmaril@393
  2183
		if (d.exists() )
insilmaril@393
  2184
		{
insilmaril@393
  2185
			// We need to parse saved XML data
insilmaril@564
  2186
			parseVYMHandler handler;
insilmaril@393
  2187
			QXmlInputSource source( file);
insilmaril@393
  2188
			QXmlSimpleReader reader;
insilmaril@393
  2189
			reader.setContentHandler( &handler );
insilmaril@393
  2190
			reader.setErrorHandler( &handler );
insilmaril@393
  2191
			handler.setMapEditor( this );
insilmaril@393
  2192
			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@394
  2193
			handler.setLoadMode (ImportAdd);
insilmaril@393
  2194
			blockReposition=true;
insilmaril@393
  2195
			bool ok = reader.parse( source );
insilmaril@393
  2196
			blockReposition=false;
insilmaril@393
  2197
			if (! ok ) 
insilmaril@393
  2198
			{	
insilmaril@393
  2199
				// This should never ever happen
insilmaril@393
  2200
				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2201
										handler.errorProtocol());
insilmaril@393
  2202
			}
insilmaril@424
  2203
			if (sel!=mapCenter)
insilmaril@424
  2204
				sel->getLastBranch()->linkTo (sel,pos);
insilmaril@393
  2205
		} else	
insilmaril@393
  2206
			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2207
	}		
insilmaril@106
  2208
}
insilmaril@106
  2209
insilmaril@502
  2210
void MapEditor::pasteNoSave(const int &n)
insilmaril@0
  2211
{
insilmaril@491
  2212
	bool old=blockSaveState;
insilmaril@491
  2213
	blockSaveState=true;
insilmaril@502
  2214
	if (redosAvail > 0 || n!=0)
insilmaril@502
  2215
	{
insilmaril@502
  2216
		// Use the "historical" buffer
insilmaril@502
  2217
		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
insilmaril@502
  2218
		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
insilmaril@571
  2219
		load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
insilmaril@502
  2220
	} else
insilmaril@502
  2221
		// Use the global buffer
insilmaril@571
  2222
		load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
insilmaril@491
  2223
	blockSaveState=old;
insilmaril@0
  2224
}
insilmaril@0
  2225
insilmaril@497
  2226
void MapEditor::paste()		
insilmaril@0
  2227
{   
insilmaril@424
  2228
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2229
	if (sel)
insilmaril@166
  2230
	{
insilmaril@395
  2231
		saveStateChangingPart(
insilmaril@424
  2232
			sel,
insilmaril@424
  2233
			sel,
insilmaril@502
  2234
			QString ("paste (%1)").arg(curClipboard),
insilmaril@424
  2235
			QString("Paste to %1").arg( getName(sel))
insilmaril@395
  2236
		);
insilmaril@502
  2237
		pasteNoSave(0);
insilmaril@166
  2238
		mapCenter->reposition();
insilmaril@166
  2239
	}
insilmaril@0
  2240
}
insilmaril@0
  2241
insilmaril@0
  2242
void MapEditor::cut()
insilmaril@0
  2243
{
insilmaril@424
  2244
	LinkableMapObj *sel=xelection.single();
insilmaril@491
  2245
	if ( sel && (xelection.type() == Selection::Branch ||
insilmaril@491
  2246
		xelection.type()==Selection::MapCenter ||
insilmaril@491
  2247
		xelection.type()==Selection::FloatImage))
insilmaril@424
  2248
	{
insilmaril@491
  2249
	/* No savestate! savestate is called in cutNoSave
insilmaril@424
  2250
		saveStateChangingPart(
insilmaril@424
  2251
			sel->getParObj(),
insilmaril@424
  2252
			sel,
insilmaril@424
  2253
			"cut ()",
insilmaril@424
  2254
			QString("Cut %1").arg(getName(sel ))
insilmaril@424
  2255
		);
insilmaril@491
  2256
	*/	
insilmaril@424
  2257
		copy();
insilmaril@491
  2258
		deleteSelection();
insilmaril@424
  2259
		mapCenter->reposition();
insilmaril@424
  2260
	}
insilmaril@0
  2261
}
insilmaril@0
  2262
insilmaril@537
  2263
void MapEditor::move(const double &x, const double &y)
insilmaril@130
  2264
{
insilmaril@424
  2265
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2266
	if (sel)
insilmaril@366
  2267
	{
insilmaril@424
  2268
		QString ps=qpointfToString (sel->getAbsPos());
insilmaril@424
  2269
		QString s=xelection.single()->getSelectString();
insilmaril@366
  2270
		saveState(
insilmaril@366
  2271
			s, "move "+ps, 
insilmaril@408
  2272
			s, "move "+qpointfToString (QPointF (x,y)), 
insilmaril@424
  2273
			QString("Move %1 to  %2").arg(getName(sel)).arg(ps));
insilmaril@473
  2274
		sel->move(x,y);
insilmaril@366
  2275
		mapCenter->reposition();
insilmaril@442
  2276
		xelection.update();
insilmaril@366
  2277
	}
insilmaril@366
  2278
insilmaril@366
  2279
}
insilmaril@366
  2280
insilmaril@537
  2281
void MapEditor::moveRel (const double &x, const double &y)
insilmaril@366
  2282
{
insilmaril@424
  2283
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2284
	if (sel)
insilmaril@366
  2285
	{
insilmaril@424
  2286
		QString ps=qpointfToString (sel->getRelPos());
insilmaril@424
  2287
		QString s=sel->getSelectString();
insilmaril@366
  2288
		saveState(
insilmaril@366
  2289
			s, "moveRel "+ps, 
insilmaril@408
  2290
			s, "moveRel "+qpointfToString (QPointF (x,y)), 
insilmaril@424
  2291
			QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
insilmaril@424
  2292
		((OrnamentedObj*)sel)->move2RelPos (x,y);
insilmaril@366
  2293
		mapCenter->reposition();
insilmaril@424
  2294
		sel->updateLink();
insilmaril@442
  2295
		xelection.update();
insilmaril@366
  2296
	}
insilmaril@130
  2297
}
insilmaril@130
  2298
insilmaril@0
  2299
void MapEditor::moveBranchUp()
insilmaril@0
  2300
{
insilmaril@424
  2301
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2302
	BranchObj* par;
insilmaril@424
  2303
	if (bo)
insilmaril@0
  2304
	{
insilmaril@314
  2305
		if (!bo->canMoveBranchUp()) return;
insilmaril@0
  2306
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2307
		BranchObj *obo=par->moveBranchUp (bo);	// bo will be the one below selection
insilmaril@473
  2308
		saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
insilmaril@0
  2309
		mapCenter->reposition();
insilmaril@420
  2310
		scene()->update();
insilmaril@442
  2311
		xelection.update();
insilmaril@0
  2312
		ensureSelectionVisible();
insilmaril@0
  2313
	}
insilmaril@0
  2314
}
insilmaril@0
  2315
insilmaril@0
  2316
void MapEditor::moveBranchDown()
insilmaril@0
  2317
{
insilmaril@424
  2318
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2319
	BranchObj* par;
insilmaril@424
  2320
	if (bo)
insilmaril@0
  2321
	{
insilmaril@314
  2322
		if (!bo->canMoveBranchDown()) return;
insilmaril@0
  2323
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2324
		BranchObj *obo=par->moveBranchDown(bo);	// bo will be the one above selection
insilmaril@473
  2325
		saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
insilmaril@0
  2326
		mapCenter->reposition();
insilmaril@420
  2327
		scene()->update();
insilmaril@442
  2328
		xelection.update();
insilmaril@0
  2329
		ensureSelectionVisible();
insilmaril@0
  2330
	}	
insilmaril@0
  2331
}
insilmaril@0
  2332
insilmaril@608
  2333
void MapEditor::sortChildren()
insilmaril@608
  2334
{
insilmaril@608
  2335
	BranchObj* bo=xelection.getBranch();
insilmaril@608
  2336
	if (bo)
insilmaril@608
  2337
	{
insilmaril@608
  2338
		if(bo->countBranches()>1)
insilmaril@608
  2339
		{
insilmaril@608
  2340
			bo->sortChildren();
insilmaril@608
  2341
			saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
insilmaril@608
  2342
			mapCenter->reposition();
insilmaril@608
  2343
			ensureSelectionVisible();
insilmaril@608
  2344
		}
insilmaril@608
  2345
	}
insilmaril@608
  2346
}
insilmaril@608
  2347
insilmaril@491
  2348
void MapEditor::linkTo(const QString &dstString)	
insilmaril@420
  2349
{
insilmaril@424
  2350
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2351
	if (fio)
insilmaril@424
  2352
	{
insilmaril@424
  2353
		BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
insilmaril@424
  2354
		if (dst && (typeid(*dst)==typeid (BranchObj) || 
insilmaril@424
  2355
					typeid(*dst)==typeid (MapCenterObj)))
insilmaril@424
  2356
		{			
insilmaril@424
  2357
			LinkableMapObj *dstPar=dst->getParObj();
insilmaril@424
  2358
			QString parString=dstPar->getSelectString();
insilmaril@420
  2359
			QString fioPreSelectString=fio->getSelectString();
insilmaril@420
  2360
			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
insilmaril@420
  2361
			((BranchObj*)(dst))->addFloatImage (fio);
insilmaril@424
  2362
			xelection.unselect();
insilmaril@420
  2363
			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
insilmaril@420
  2364
			fio=((BranchObj*)(dst))->getLastFloatImage();
insilmaril@420
  2365
			fio->setRelPos();
insilmaril@420
  2366
			fio->reposition();
insilmaril@424
  2367
			xelection.select(fio);
insilmaril@420
  2368
			saveState(
insilmaril@420
  2369
				fio->getSelectString(),
insilmaril@420
  2370
				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
insilmaril@420
  2371
				fioPreSelectString, 
insilmaril@420
  2372
				QString ("linkTo (\"%1\")").arg(dstString),
insilmaril@420
  2373
				QString ("Link floatimage to %1").arg(getName(dst)));
insilmaril@424
  2374
		}
insilmaril@420
  2375
	}
insilmaril@420
  2376
}
insilmaril@420
  2377
insilmaril@366
  2378
QString MapEditor::getHeading(bool &ok, QPoint &p)
insilmaril@0
  2379
{
insilmaril@424
  2380
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2381
	if (bo)
insilmaril@366
  2382
	{
insilmaril@366
  2383
		ok=true;
insilmaril@424
  2384
		p=mapFromScene(bo->getAbsPos());
insilmaril@424
  2385
		return bo->getHeading();
insilmaril@366
  2386
	}
insilmaril@366
  2387
	ok=false;
insilmaril@366
  2388
	return QString();
insilmaril@366
  2389
}
insilmaril@366
  2390
insilmaril@366
  2391
void MapEditor::setHeading(const QString &s)
insilmaril@366
  2392
{
insilmaril@424
  2393
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2394
	if (sel)
insilmaril@0
  2395
	{
insilmaril@395
  2396
		saveState(
insilmaril@424
  2397
			sel,
insilmaril@424
  2398
			"setHeading (\""+sel->getHeading()+"\")", 
insilmaril@424
  2399
			sel,
insilmaril@366
  2400
			"setHeading (\""+s+"\")", 
insilmaril@424
  2401
			QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
insilmaril@424
  2402
		sel->setHeading(s );
insilmaril@106
  2403
		mapCenter->reposition();
insilmaril@442
  2404
		xelection.update();
insilmaril@106
  2405
		ensureSelectionVisible();
insilmaril@106
  2406
	}
insilmaril@106
  2407
}
insilmaril@106
  2408
insilmaril@366
  2409
void MapEditor::setHeadingInt(const QString &s)
insilmaril@366
  2410
{
insilmaril@424
  2411
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2412
	if (bo)
insilmaril@366
  2413
	{
insilmaril@424
  2414
		bo->setHeading(s);
insilmaril@366
  2415
		mapCenter->reposition();
insilmaril@442
  2416
		xelection.update();
insilmaril@366
  2417
		ensureSelectionVisible();
insilmaril@366
  2418
	}
insilmaril@366
  2419
}
insilmaril@366
  2420
insilmaril@366
  2421
void MapEditor::setVymLinkInt (const QString &s)
insilmaril@143
  2422
{
insilmaril@143
  2423
	// Internal function, no saveState needed
insilmaril@424
  2424
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2425
	if (bo)
insilmaril@143
  2426
	{
insilmaril@424
  2427
		bo->setVymLink(s);
insilmaril@143
  2428
		mapCenter->reposition();
insilmaril@491
  2429
		updateActions();
insilmaril@442
  2430
		xelection.update();
insilmaril@143
  2431
		ensureSelectionVisible();
insilmaril@143
  2432
	}
insilmaril@143
  2433
}
insilmaril@143
  2434
insilmaril@366
  2435
BranchObj* MapEditor::addNewBranchInt(int num)
insilmaril@0
  2436
{
insilmaril@366
  2437
	// Depending on pos:
insilmaril@366
  2438
	// -3		insert in childs of parent  above selection 
insilmaril@366
  2439
	// -2		add branch to selection 
insilmaril@366
  2440
	// -1		insert in childs of parent below selection 
insilmaril@366
  2441
	// 0..n		insert in childs of parent at pos
insilmaril@366
  2442
	BranchObj *newbo=NULL;
insilmaril@424
  2443
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2444
	if (bo)
insilmaril@0
  2445
	{
insilmaril@366
  2446
		if (num==-2)
insilmaril@0
  2447
		{
insilmaril@0
  2448
			// save scroll state. If scrolled, automatically select
insilmaril@0
  2449
			// new branch in order to tmp unscroll parent...
insilmaril@537
  2450
			newbo=bo->addBranch();
insilmaril@366
  2451
			
insilmaril@366
  2452
		}else if (num==-1)
insilmaril@0
  2453
		{
insilmaril@366
  2454
			num=bo->getNum()+1;
insilmaril@366
  2455
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2456
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2457
		}else if (num==-3)
insilmaril@366
  2458
		{
insilmaril@366
  2459
			num=bo->getNum();
insilmaril@366
  2460
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2461
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2462
		}
insilmaril@537
  2463
		if (!newbo) return NULL;
insilmaril@366
  2464
	}	
insilmaril@366
  2465
	return newbo;
insilmaril@366
  2466
}	
insilmaril@366
  2467
insilmaril@394
  2468
BranchObj* MapEditor::addNewBranch(int pos)
insilmaril@366
  2469
{
insilmaril@366
  2470
	// Different meaning than num in addNewBranchInt!
insilmaril@366
  2471
	// -1	add above
insilmaril@366
  2472
	//  0	add as child
insilmaril@366
  2473
	// +1	add below
insilmaril@424
  2474
	BranchObj *bo = xelection.getBranch();
insilmaril@394
  2475
	BranchObj *newbo=NULL;
insilmaril@394
  2476
insilmaril@424
  2477
	if (bo)
insilmaril@366
  2478
	{
insilmaril@421
  2479
		setCursor (Qt::ArrowCursor);
insilmaril@421
  2480
insilmaril@366
  2481
		newbo=addNewBranchInt (pos-2);
insilmaril@366
  2482
insilmaril@366
  2483
		if (newbo)
insilmaril@366
  2484
		{
insilmaril@395
  2485
			saveState(
insilmaril@417
  2486
				newbo,		
insilmaril@393
  2487
				"delete ()",
insilmaril@424
  2488
				bo,
insilmaril@537
  2489
				QString ("addBranch (%1)").arg(pos),
insilmaril@395
  2490
				QString ("Add new branch to %1").arg(getName(bo)));	
insilmaril@366
  2491
insilmaril@366
  2492
			mapCenter->reposition();
insilmaril@537
  2493
			xelection.update();
insilmaril@537
  2494
			latestSelection=newbo->getSelectString();
insilmaril@531
  2495
			// In Network mode, the client needs to know where the new branch is,
insilmaril@531
  2496
			// so we have to pass on this information via saveState.
insilmaril@531
  2497
			// TODO: Get rid of this positioning workaround
insilmaril@531
  2498
			QString ps=qpointfToString (newbo->getAbsPos());
insilmaril@537
  2499
			sendData ("selectLatestAdded ()");
insilmaril@534
  2500
			sendData (QString("move %1").arg(ps));
insilmaril@534
  2501
			sendSelection();
insilmaril@366
  2502
		}
insilmaril@366
  2503
	}	
insilmaril@394
  2504
	return newbo;
insilmaril@366
  2505
}
insilmaril@366
  2506
insilmaril@366
  2507
insilmaril@394
  2508
BranchObj* MapEditor::addNewBranchBefore()
insilmaril@366
  2509
{
insilmaril@394
  2510
	BranchObj *newbo=NULL;
insilmaril@424
  2511
	BranchObj *bo = xelection.getBranch();
insilmaril@491
  2512
	if (bo && xelection.type()==Selection::Branch)
insilmaril@394
  2513
		 // We accept no MapCenterObj here, so we _have_ a parent
insilmaril@366
  2514
	{
insilmaril@408
  2515
		QPointF p=bo->getRelPos();
insilmaril@394
  2516
insilmaril@394
  2517
insilmaril@424
  2518
		BranchObj *parbo=(BranchObj*)(bo->getParObj());
insilmaril@394
  2519
insilmaril@394
  2520
		// add below selection
insilmaril@394
  2521
		newbo=parbo->insertBranch(bo->getNum()+1);
insilmaril@394
  2522
		if (newbo)
insilmaril@366
  2523
		{
insilmaril@394
  2524
			newbo->move2RelPos (p);
insilmaril@394
  2525
insilmaril@394
  2526
			// Move selection to new branch
insilmaril@424
  2527
			bo->linkTo (newbo,-1);
insilmaril@394
  2528
insilmaril@394
  2529
			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
insilmaril@394
  2530
				QString ("Add branch before %1").arg(getName(bo)));
insilmaril@394
  2531
insilmaril@394
  2532
			mapCenter->reposition();
insilmaril@442
  2533
			xelection.update();
insilmaril@394
  2534
		}
insilmaril@0
  2535
	}	
insilmaril@537
  2536
	latestSelection=xelection.getSelectString();
insilmaril@394
  2537
	return newbo;
insilmaril@0
  2538
}
insilmaril@0
  2539
insilmaril@0
  2540
void MapEditor::deleteSelection()
insilmaril@0
  2541
{
insilmaril@424
  2542
	BranchObj *bo = xelection.getBranch();
insilmaril@491
  2543
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2544
	{
insilmaril@294
  2545
		BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@424
  2546
		xelection.unselect();
insilmaril@394
  2547
		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
insilmaril@0
  2548
		par->removeBranch(bo);
insilmaril@424
  2549
		xelection.select (par);
insilmaril@0
  2550
		ensureSelectionVisible();
insilmaril@0
  2551
		mapCenter->reposition();
insilmaril@442
  2552
		xelection.update();
insilmaril@442
  2553
		xelection.update();
insilmaril@424
  2554
		return;
insilmaril@0
  2555
	}
insilmaril@424
  2556
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2557
	if (fio)
insilmaril@0
  2558
	{
insilmaril@0
  2559
		BranchObj* par=(BranchObj*)(fio->getParObj());
insilmaril@395
  2560
		saveStateChangingPart(
insilmaril@395
  2561
			par, 
insilmaril@395
  2562
			fio,
insilmaril@395
  2563
			"delete ()",
insilmaril@395
  2564
			QString("Delete %1").arg(getName(fio))
insilmaril@395
  2565
		);
insilmaril@424
  2566
		xelection.unselect();
insilmaril@0
  2567
		par->removeFloatImage(fio);
insilmaril@424
  2568
		xelection.select (par);
insilmaril@442
  2569
		mapCenter->reposition();
insilmaril@442
  2570
		xelection.update();
insilmaril@0
  2571
		ensureSelectionVisible();
insilmaril@424
  2572
		return;
insilmaril@0
  2573
	}
insilmaril@0
  2574
}
insilmaril@0
  2575
insilmaril@0
  2576
LinkableMapObj* MapEditor::getSelection()
insilmaril@0
  2577
{
insilmaril@424
  2578
	return xelection.single();
insilmaril@0
  2579
}
insilmaril@0
  2580
insilmaril@442
  2581
BranchObj* MapEditor::getSelectedBranch()
insilmaril@442
  2582
{
insilmaril@442
  2583
	return xelection.getBranch();
insilmaril@442
  2584
}
insilmaril@442
  2585
insilmaril@442
  2586
FloatImageObj* MapEditor::getSelectedFloatImage()
insilmaril@442
  2587
{
insilmaril@442
  2588
	return xelection.getFloatImage();
insilmaril@442
  2589
}
insilmaril@442
  2590
insilmaril@267
  2591
void MapEditor::unselect()
insilmaril@267
  2592
{
insilmaril@424
  2593
	xelection.unselect();
insilmaril@267
  2594
}	
insilmaril@267
  2595
insilmaril@267
  2596
void MapEditor::reselect()
insilmaril@267
  2597
{
insilmaril@424
  2598
	xelection.reselect();
insilmaril@267
  2599
}	
insilmaril@267
  2600
insilmaril@83
  2601
bool MapEditor::select (const QString &s)
insilmaril@83
  2602
{
insilmaril@106
  2603
	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
insilmaril@0
  2604
insilmaril@0
  2605
	// Finally select the found object
insilmaril@0
  2606
	if (lmo)
insilmaril@0
  2607
	{
insilmaril@424
  2608
		xelection.unselect();
insilmaril@424
  2609
		xelection.select(lmo);
insilmaril@442
  2610
		xelection.update();
insilmaril@0
  2611
		ensureSelectionVisible();
insilmaril@528
  2612
		sendSelection ();
insilmaril@0
  2613
		return true;
insilmaril@139
  2614
	} 
insilmaril@139
  2615
	return false;
insilmaril@0
  2616
}
insilmaril@0
  2617
insilmaril@366
  2618
QString MapEditor::getSelectString()
insilmaril@366
  2619
{
insilmaril@424
  2620
	return xelection.getSelectString();
insilmaril@366
  2621
}
insilmaril@366
  2622
insilmaril@366
  2623
void MapEditor::selectInt (LinkableMapObj *lmo)
insilmaril@0
  2624
{
insilmaril@491
  2625
	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
insilmaril@442
  2626
	{
insilmaril@424
  2627
		xelection.select(lmo);
insilmaril@442
  2628
		xelection.update();
insilmaril@528
  2629
		sendSelection ();
insilmaril@442
  2630
	}	
insilmaril@267
  2631
}
insilmaril@0
  2632
insilmaril@366
  2633
void MapEditor::selectNextBranchInt()
insilmaril@0
  2634
{
insilmaril@0
  2635
	// Increase number of branch
insilmaril@424
  2636
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2637
	if (sel)
insilmaril@0
  2638
	{
insilmaril@424
  2639
		QString s=sel->getSelectString();
insilmaril@0
  2640
		QString part;
insilmaril@0
  2641
		QString typ;
insilmaril@0
  2642
		QString num;
insilmaril@0
  2643
insilmaril@0
  2644
		// Where am I? 
insilmaril@0
  2645
		part=s.section(",",-1);
insilmaril@0
  2646
		typ=part.left (3);
insilmaril@0
  2647
		num=part.right(part.length() - 3);
insilmaril@0
  2648
insilmaril@0
  2649
		s=s.left (s.length() -num.length());
insilmaril@0
  2650
insilmaril@0
  2651
		// Go to next lmo
insilmaril@0
  2652
		num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2653
insilmaril@0
  2654
		s=s+num;
insilmaril@0
  2655
		
insilmaril@0
  2656
		// Try to select this one
insilmaril@0
  2657
		if (select (s)) return;
insilmaril@0
  2658
insilmaril@0
  2659
		// We have no direct successor, 
insilmaril@0
  2660
		// try to increase the parental number in order to
insilmaril@0
  2661
		// find a successor with same depth
insilmaril@0
  2662
insilmaril@424
  2663
		int d=xelection.single()->getDepth();
insilmaril@0
  2664
		int oldDepth=d;
insilmaril@0
  2665
		int i;
insilmaril@0
  2666
		bool found=false;
insilmaril@0
  2667
		bool b;
insilmaril@0
  2668
		while (!found && d>0)
insilmaril@0
  2669
		{
insilmaril@0
  2670
			s=s.section (",",0,d-1);
insilmaril@0
  2671
			// replace substring of current depth in s with "1"
insilmaril@0
  2672
			part=s.section(",",-1);
insilmaril@0
  2673
			typ=part.left (3);
insilmaril@0
  2674
			num=part.right(part.length() - 3);
insilmaril@0
  2675
insilmaril@0
  2676
			if (d>1)
insilmaril@0
  2677
			{	
insilmaril@0
  2678
				// increase number of parent
insilmaril@0
  2679
				num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2680
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2681
			} else
insilmaril@0
  2682
			{
insilmaril@0
  2683
				// Special case, look at orientation
insilmaril@473
  2684
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2685
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2686
				else	
insilmaril@0
  2687
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  2688
				s=typ+num;
insilmaril@0
  2689
			}	
insilmaril@0
  2690
insilmaril@0
  2691
			if (select (s))
insilmaril@0
  2692
				// pad to oldDepth, select the first branch for each depth
insilmaril@0
  2693
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2694
				{
insilmaril@0
  2695
					b=select (s);
insilmaril@0
  2696
					if (b)
insilmaril@0
  2697
					{	
insilmaril@424
  2698
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@0
  2699
							s+=",bo:0";
insilmaril@0
  2700
						else	
insilmaril@0
  2701
							break;
insilmaril@0
  2702
					} else
insilmaril@0
  2703
						break;
insilmaril@0
  2704
				}	
insilmaril@0
  2705
insilmaril@0
  2706
			// try to select the freshly built string
insilmaril@0
  2707
			found=select(s);
insilmaril@0
  2708
			d--;
insilmaril@0
  2709
		}
insilmaril@0
  2710
		return;
insilmaril@0
  2711
	}	
insilmaril@0
  2712
}
insilmaril@0
  2713
insilmaril@366
  2714
void MapEditor::selectPrevBranchInt()
insilmaril@0
  2715
{
insilmaril@0
  2716
	// Decrease number of branch
insilmaril@424
  2717
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2718
	if (bo)
insilmaril@0
  2719
	{
insilmaril@424
  2720
		QString s=bo->getSelectString();
insilmaril@0
  2721
		QString part;
insilmaril@0
  2722
		QString typ;
insilmaril@0
  2723
		QString num;
insilmaril@0
  2724
insilmaril@0
  2725
		// Where am I? 
insilmaril@0
  2726
		part=s.section(",",-1);
insilmaril@0
  2727
		typ=part.left (3);
insilmaril@0
  2728
		num=part.right(part.length() - 3);
insilmaril@0
  2729
insilmaril@0
  2730
		s=s.left (s.length() -num.length());
insilmaril@0
  2731
insilmaril@411
  2732
		int n=num.toInt()-1;
insilmaril@411
  2733
		
insilmaril@0
  2734
		// Go to next lmo
insilmaril@411
  2735
		num=QString ("%1").arg(n);
insilmaril@0
  2736
		s=s+num;
insilmaril@0
  2737
		
insilmaril@0
  2738
		// Try to select this one
insilmaril@411
  2739
		if (n>=0 && select (s)) return;
insilmaril@0
  2740
insilmaril@0
  2741
		// We have no direct precessor, 
insilmaril@0
  2742
		// try to decrease the parental number in order to
insilmaril@0
  2743
		// find a precessor with same depth
insilmaril@0
  2744
insilmaril@424
  2745
		int d=xelection.single()->getDepth();
insilmaril@0
  2746
		int oldDepth=d;
insilmaril@0
  2747
		int i;
insilmaril@0
  2748
		bool found=false;
insilmaril@0
  2749
		bool b;
insilmaril@0
  2750
		while (!found && d>0)
insilmaril@0
  2751
		{
insilmaril@0
  2752
			s=s.section (",",0,d-1);
insilmaril@0
  2753
			// replace substring of current depth in s with "1"
insilmaril@0
  2754
			part=s.section(",",-1);
insilmaril@0
  2755
			typ=part.left (3);
insilmaril@0
  2756
			num=part.right(part.length() - 3);
insilmaril@0
  2757
insilmaril@0
  2758
			if (d>1)
insilmaril@0
  2759
			{
insilmaril@0
  2760
				// decrease number of parent
insilmaril@411
  2761
				num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2762
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2763
			} else
insilmaril@0
  2764
			{
insilmaril@0
  2765
				// Special case, look at orientation
insilmaril@473
  2766
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@411
  2767
					num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2768
				else	
insilmaril@411
  2769
					num=QString ("%1").arg(num.toInt()+1);
insilmaril@0
  2770
				s=typ+num;
insilmaril@0
  2771
			}	
insilmaril@0
  2772
insilmaril@0
  2773
			if (select(s))
insilmaril@0
  2774
				// pad to oldDepth, select the last branch for each depth
insilmaril@0
  2775
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2776
				{
insilmaril@0
  2777
					b=select (s);
insilmaril@0
  2778
					if (b)
insilmaril@424
  2779
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@424
  2780
							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
insilmaril@0
  2781
						else	
insilmaril@0
  2782
							break;
insilmaril@0
  2783
					else
insilmaril@0
  2784
						break;
insilmaril@0
  2785
				}	
insilmaril@0
  2786
			
insilmaril@0
  2787
			// try to select the freshly built string
insilmaril@0
  2788
			found=select(s);
insilmaril@0
  2789
			d--;
insilmaril@0
  2790
		}
insilmaril@0
  2791
		return;
insilmaril@0
  2792
	}	
insilmaril@0
  2793
}
insilmaril@0
  2794
insilmaril@0
  2795
void MapEditor::selectUpperBranch()
insilmaril@0
  2796
{
insilmaril@491
  2797
	if (isSelectBlocked() ) return;
insilmaril@491
  2798
insilmaril@424
  2799
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2800
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2801
	{
insilmaril@473
  2802
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2803
			selectPrevBranchInt();
insilmaril@424
  2804
		else
insilmaril@424
  2805
			if (bo->getDepth()==1)
insilmaril@424
  2806
				selectNextBranchInt();
insilmaril@424
  2807
			else
insilmaril@424
  2808
				selectPrevBranchInt();
insilmaril@424
  2809
	}
insilmaril@424
  2810
}
insilmaril@424
  2811
insilmaril@424
  2812
void MapEditor::selectLowerBranch()
insilmaril@424
  2813
{
insilmaril@491
  2814
	if (isSelectBlocked() ) return;
insilmaril@491
  2815
insilmaril@424
  2816
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2817
	if (bo && xelection.type()==Selection::Branch)
insilmaril@473
  2818
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2819
			selectNextBranchInt();
insilmaril@424
  2820
		else
insilmaril@424
  2821
			if (bo->getDepth()==1)
insilmaril@366
  2822
				selectPrevBranchInt();
insilmaril@0
  2823
			else
insilmaril@366
  2824
				selectNextBranchInt();
insilmaril@0
  2825
}
insilmaril@0
  2826
insilmaril@0
  2827
insilmaril@0
  2828
void MapEditor::selectLeftBranch()
insilmaril@0
  2829
{
insilmaril@491
  2830
	if (isSelectBlocked() ) return;
insilmaril@491
  2831
insilmaril@0
  2832
	BranchObj* bo;
insilmaril@0
  2833
	BranchObj* par;
insilmaril@424
  2834
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2835
	if (sel)
insilmaril@0
  2836
	{
insilmaril@491
  2837
		if (xelection.type()== Selection::MapCenter)
insilmaril@0
  2838
		{
insilmaril@424
  2839
			par=xelection.getBranch();
insilmaril@0
  2840
			bo=par->getLastSelectedBranch();
insilmaril@0
  2841
			if (bo)
insilmaril@0
  2842
			{
insilmaril@0
  2843
				// Workaround for reselecting on left and right side
insilmaril@473
  2844
				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2845
					bo=par->getLastBranch();
insilmaril@424
  2846
				if (bo)
insilmaril@0
  2847
				{
insilmaril@0
  2848
					bo=par->getLastBranch();
insilmaril@424
  2849
					xelection.select(bo);
insilmaril@442
  2850
					xelection.update();
insilmaril@0
  2851
					ensureSelectionVisible();
insilmaril@528
  2852
					sendSelection();
insilmaril@0
  2853
				}
insilmaril@0
  2854
			}	
insilmaril@0
  2855
		} else
insilmaril@0
  2856
		{
insilmaril@424
  2857
			par=(BranchObj*)(sel->getParObj());
insilmaril@473
  2858
			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2859
			{
insilmaril@491
  2860
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2861
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2862
				{
insilmaril@424
  2863
					xelection.select(par);
insilmaril@442
  2864
					xelection.update();
insilmaril@0
  2865
					ensureSelectionVisible();
insilmaril@528
  2866
					sendSelection();
insilmaril@0
  2867
				}
insilmaril@0
  2868
			} else
insilmaril@0
  2869
			{
insilmaril@491
  2870
				if (xelection.type() == Selection::Branch )
insilmaril@0
  2871
				{
insilmaril@424
  2872
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  2873
					if (bo) 
insilmaril@0
  2874
					{
insilmaril@424
  2875
						xelection.select(bo);
insilmaril@442
  2876
						xelection.update();
insilmaril@0
  2877
						ensureSelectionVisible();
insilmaril@528
  2878
					sendSelection();
insilmaril@0
  2879
					}
insilmaril@0
  2880
				}
insilmaril@0
  2881
			}
insilmaril@0
  2882
		}	
insilmaril@0
  2883
	}
insilmaril@0
  2884
}
insilmaril@0
  2885
insilmaril@0
  2886
void MapEditor::selectRightBranch()
insilmaril@0
  2887
{
insilmaril@491
  2888
	if (isSelectBlocked() ) return;
insilmaril@491
  2889
insilmaril@0
  2890
	BranchObj* bo;
insilmaril@0
  2891
	BranchObj* par;
insilmaril@424
  2892
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2893
	if (sel)
insilmaril@0
  2894
	{
insilmaril@491
  2895
		if (xelection.type()==Selection::MapCenter) 
insilmaril@0
  2896
		{
insilmaril@424
  2897
			par=xelection.getBranch();
insilmaril@0
  2898
			bo=par->getLastSelectedBranch();
insilmaril@0