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