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