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