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