mapeditor.cpp
author insilmaril
Mon, 30 Jul 2007 09:47:07 +0000
changeset 569 df32d920b04e
parent 564 b8f0eefe4351
child 571 bc9083a4a7fb
permissions -rw-r--r--
1.9.4 New base class for XML based file parsing (vym & Freemind)
insilmaril@0
     1
#include "mapeditor.h"
insilmaril@0
     2
insilmaril@374
     3
#include <q3filedialog.h>
insilmaril@0
     4
insilmaril@0
     5
#include <iostream>
insilmaril@95
     6
#include <cstdlib>
insilmaril@0
     7
#include <typeinfo>
insilmaril@0
     8
insilmaril@0
     9
#include "version.h"
insilmaril@0
    10
insilmaril@432
    11
#include "parser.h"
insilmaril@175
    12
#include "editxlinkdialog.h"
insilmaril@175
    13
#include "exports.h"
insilmaril@517
    14
#include "exportxhtmldialog.h"
insilmaril@175
    15
#include "extrainfodialog.h"
insilmaril@236
    16
#include "file.h"
insilmaril@175
    17
#include "linkablemapobj.h"
insilmaril@175
    18
#include "mainwindow.h"
insilmaril@175
    19
#include "misc.h"
insilmaril@175
    20
#include "texteditor.h"
insilmaril@314
    21
#include "warningdialog.h"
insilmaril@0
    22
#include "xml.h"
insilmaril@564
    23
#include "xml-fm.h"
insilmaril@0
    24
insilmaril@0
    25
insilmaril@0
    26
extern TextEditor *textEditor;
insilmaril@0
    27
extern int statusbarTime;
insilmaril@0
    28
extern Main *mainWindow;
insilmaril@164
    29
extern QString tmpVymDir;
insilmaril@166
    30
extern QString clipboardDir;
insilmaril@491
    31
extern QString clipboardFile;
insilmaril@166
    32
extern bool clipboardEmpty;
insilmaril@473
    33
extern bool debug;
insilmaril@0
    34
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
    35
insilmaril@366
    36
extern QMenu* branchContextMenu;
insilmaril@366
    37
extern QMenu* branchAddContextMenu;
insilmaril@366
    38
extern QMenu* branchRemoveContextMenu;
insilmaril@366
    39
extern QMenu* branchLinksContextMenu;
insilmaril@366
    40
extern QMenu* branchXLinksContextMenuEdit;
insilmaril@366
    41
extern QMenu* branchXLinksContextMenuFollow;
insilmaril@366
    42
extern QMenu* floatimageContextMenu;
insilmaril@366
    43
extern QMenu* canvasContextMenu;
insilmaril@366
    44
insilmaril@0
    45
insilmaril@0
    46
extern Settings settings;
insilmaril@366
    47
extern ImageIO imageIO;
insilmaril@0
    48
insilmaril@404
    49
extern QString vymName;
insilmaril@404
    50
extern QString vymVersion;
insilmaril@404
    51
insilmaril@269
    52
extern QString iconPath;
insilmaril@301
    53
extern QDir vymBaseDir;
insilmaril@366
    54
extern QDir lastImageDir;
insilmaril@421
    55
extern QDir lastFileDir;
insilmaril@269
    56
insilmaril@164
    57
int MapEditor::mapNum=0;	// make instance
insilmaril@0
    58
insilmaril@0
    59
///////////////////////////////////////////////////////////////////////
insilmaril@0
    60
///////////////////////////////////////////////////////////////////////
insilmaril@408
    61
MapEditor::MapEditor( QWidget* parent) :
insilmaril@473
    62
  QGraphicsView(parent)  
insilmaril@0
    63
{
insilmaril@0
    64
	//cout << "Constructor ME "<<this<<endl;
insilmaril@164
    65
	mapNum++;
insilmaril@0
    66
insilmaril@119
    67
insilmaril@408
    68
	mapScene= new QGraphicsScene(parent);
insilmaril@408
    69
	//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
insilmaril@408
    70
	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
insilmaril@408
    71
insilmaril@408
    72
insilmaril@408
    73
    setScene (mapScene);
insilmaril@0
    74
	
insilmaril@408
    75
    mapCenter = new MapCenterObj(mapScene);
insilmaril@0
    76
    mapCenter->setVisibility (true);
insilmaril@0
    77
	mapCenter->setMapEditor (this);
insilmaril@93
    78
	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
insilmaril@408
    79
	//mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
insilmaril@408
    80
	mapCenter->move(0,0);
insilmaril@0
    81
insilmaril@0
    82
    printer=NULL;
insilmaril@0
    83
insilmaril@97
    84
	defLinkColor=QColor (0,0,255);
insilmaril@97
    85
	defXLinkColor=QColor (180,180,180);
insilmaril@473
    86
	linkcolorhint=LinkableMapObj::DefaultColor;
insilmaril@473
    87
	linkstyle=LinkableMapObj::PolyParabel;
insilmaril@0
    88
insilmaril@366
    89
	// Create bitmap cursors, platform dependant
insilmaril@404
    90
	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
insilmaril@404
    91
	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
insilmaril@404
    92
	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
insilmaril@404
    93
	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
insilmaril@398
    94
insilmaril@398
    95
	setFocusPolicy (Qt::StrongFocus);
insilmaril@0
    96
insilmaril@0
    97
	pickingColor=false;
insilmaril@91
    98
	drawingLink=false;
insilmaril@93
    99
	copyingObj=false;
insilmaril@0
   100
insilmaril@0
   101
    editingBO=NULL;
insilmaril@0
   102
    movingObj=NULL;
insilmaril@0
   103
insilmaril@442
   104
	xelection.setMapEditor (this);
insilmaril@424
   105
	xelection.unselect();
insilmaril@366
   106
insilmaril@102
   107
	defXLinkWidth=1;
insilmaril@102
   108
	defXLinkColor=QColor (230,230,230);
insilmaril@102
   109
insilmaril@0
   110
    mapChanged=false;
insilmaril@0
   111
	mapDefault=true;
insilmaril@0
   112
	mapUnsaved=false;
insilmaril@0
   113
	
insilmaril@0
   114
	zipped=true;
insilmaril@0
   115
	filePath="";
insilmaril@294
   116
	fileName=tr("unnamed");
insilmaril@0
   117
	mapName="";
insilmaril@0
   118
insilmaril@398
   119
	stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
insilmaril@381
   120
	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
insilmaril@491
   121
	mainWindow->updateHistory (undoSet);
insilmaril@163
   122
	
insilmaril@0
   123
	// Initialize find routine
insilmaril@0
   124
	itFind=NULL;				
insilmaril@0
   125
	EOFind=false;
insilmaril@0
   126
insilmaril@0
   127
	printFrame=true;
insilmaril@0
   128
	printFooter=true;
insilmaril@0
   129
insilmaril@139
   130
	blockReposition=false;
insilmaril@139
   131
	blockSaveState=false;
insilmaril@260
   132
insilmaril@473
   133
	hidemode=BranchObj::HideNone;
insilmaril@260
   134
insilmaril@377
   135
	// Create temporary files
insilmaril@377
   136
	makeTmpDirs();
insilmaril@0
   137
insilmaril@502
   138
	curStep=0;
insilmaril@502
   139
	redosAvail=0;
insilmaril@502
   140
	undosAvail=0;
insilmaril@502
   141
insilmaril@417
   142
	setAcceptDrops (true);	
insilmaril@0
   143
insilmaril@0
   144
	mapCenter->reposition();	//	for positioning heading
insilmaril@381
   145
insilmaril@473
   146
	// TODO animations
insilmaril@473
   147
	animObjList.clear();
insilmaril@473
   148
	//timerId = startTimer(100);  
insilmaril@473
   149
insilmaril@473
   150
	// autosave
insilmaril@473
   151
	autosaveTimer=new QTimer (this);
insilmaril@473
   152
	connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
insilmaril@531
   153
insilmaril@531
   154
	// Network
insilmaril@531
   155
	netstate=Offline;
insilmaril@0
   156
}
insilmaril@0
   157
insilmaril@0
   158
MapEditor::~MapEditor()
insilmaril@0
   159
{
insilmaril@0
   160
	//cout <<"Destructor MapEditor\n";
insilmaril@473
   161
	autosaveTimer->stop();
insilmaril@0
   162
}
insilmaril@0
   163
insilmaril@0
   164
MapCenterObj* MapEditor::getMapCenter()
insilmaril@0
   165
{
insilmaril@0
   166
    return mapCenter;
insilmaril@0
   167
}
insilmaril@0
   168
insilmaril@408
   169
QGraphicsScene * MapEditor::getScene()
insilmaril@0
   170
{
insilmaril@408
   171
    return mapScene;
insilmaril@0
   172
}
insilmaril@0
   173
insilmaril@491
   174
MapEditor::State MapEditor::getState()
insilmaril@491
   175
{
insilmaril@491
   176
    return state;
insilmaril@491
   177
}
insilmaril@491
   178
insilmaril@491
   179
void MapEditor::setStateEditHeading(bool s)
insilmaril@491
   180
{
insilmaril@491
   181
	if (s)
insilmaril@491
   182
	{
insilmaril@491
   183
		if (state==Idle) state=EditHeading;
insilmaril@491
   184
	}
insilmaril@491
   185
	else	
insilmaril@491
   186
		state=Idle;
insilmaril@491
   187
}
insilmaril@491
   188
insilmaril@139
   189
bool MapEditor::isRepositionBlocked()
insilmaril@0
   190
{
insilmaril@139
   191
	return blockReposition;
insilmaril@0
   192
}
insilmaril@0
   193
insilmaril@473
   194
void MapEditor::setSaveStateBlocked(bool b)
insilmaril@473
   195
{
insilmaril@473
   196
	blockSaveState=b;
insilmaril@473
   197
}
insilmaril@473
   198
insilmaril@491
   199
bool MapEditor::isSelectBlocked()
insilmaril@491
   200
{
insilmaril@491
   201
	if (state==EditHeading)
insilmaril@491
   202
		return true;
insilmaril@491
   203
	else
insilmaril@491
   204
		return false; 
insilmaril@491
   205
}
insilmaril@491
   206
insilmaril@420
   207
QString MapEditor::getName (const LinkableMapObj *lmo)
insilmaril@294
   208
{
insilmaril@314
   209
	QString s;
insilmaril@314
   210
	if (!lmo) return QString("Error: NULL has no name!");
insilmaril@294
   211
insilmaril@294
   212
	if ((typeid(*lmo) == typeid(BranchObj) ||
insilmaril@294
   213
				      typeid(*lmo) == typeid(MapCenterObj))) 
insilmaril@314
   214
	{
insilmaril@314
   215
		
insilmaril@314
   216
		s=(((BranchObj*)lmo)->getHeading());
insilmaril@314
   217
		if (s=="") s="unnamed";
insilmaril@377
   218
		return QString("branch (%1)").arg(s);
insilmaril@377
   219
		//return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
insilmaril@314
   220
	}	
insilmaril@294
   221
	if ((typeid(*lmo) == typeid(FloatImageObj) ))
insilmaril@377
   222
		return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
insilmaril@377
   223
		//return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
insilmaril@294
   224
	return QString("Unknown type has no name!");
insilmaril@294
   225
}
insilmaril@294
   226
insilmaril@0
   227
void MapEditor::makeTmpDirs()
insilmaril@0
   228
{
insilmaril@0
   229
	// Create unique temporary directories
insilmaril@366
   230
	tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
insilmaril@366
   231
	histPath=QDir::convertSeparators (tmpMapDir+"/history");
insilmaril@164
   232
	QDir d;
insilmaril@377
   233
	d.mkdir (tmpMapDir);
insilmaril@0
   234
}
insilmaril@0
   235
insilmaril@408
   236
QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
insilmaril@0
   237
{
insilmaril@163
   238
	// tmpdir		temporary directory to which data will be written
insilmaril@0
   239
	// prefix		mapname, which will be appended to images etc.
insilmaril@0
   240
	// writeflags	Only write flags for "real" save of map, not undo
insilmaril@408
   241
	// offset		offset of bbox of whole map in scene. 
insilmaril@0
   242
	//				Needed for XML export
insilmaril@0
   243
	
insilmaril@0
   244
	// Save Header
insilmaril@0
   245
	QString ls;
insilmaril@0
   246
	switch (linkstyle)
insilmaril@0
   247
	{
insilmaril@473
   248
		case LinkableMapObj::Line: 
insilmaril@0
   249
			ls="StyleLine";
insilmaril@0
   250
			break;
insilmaril@473
   251
		case LinkableMapObj::Parabel:
insilmaril@0
   252
			ls="StyleParabel";
insilmaril@0
   253
			break;
insilmaril@473
   254
		case LinkableMapObj::PolyLine:	
insilmaril@0
   255
			ls="StylePolyLine";
insilmaril@0
   256
			break;
insilmaril@0
   257
		default:
insilmaril@0
   258
			ls="StylePolyParabel";
insilmaril@0
   259
			break;
insilmaril@0
   260
	}	
insilmaril@0
   261
insilmaril@0
   262
	QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
insilmaril@0
   263
	QString colhint="";
insilmaril@473
   264
	if (linkcolorhint==LinkableMapObj::HeadingColor) 
insilmaril@0
   265
		colhint=attribut("linkColorHint","HeadingColor");
insilmaril@0
   266
insilmaril@404
   267
	QString mapAttr=attribut("version",vymVersion);
insilmaril@398
   268
	if (!saveSel || saveSel==mapCenter)
insilmaril@0
   269
		mapAttr+= attribut("author",mapCenter->getAuthor()) +
insilmaril@0
   270
				  attribut("comment",mapCenter->getComment()) +
insilmaril@0
   271
			      attribut("date",mapCenter->getDate()) +
insilmaril@408
   272
		          attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
insilmaril@442
   273
		          attribut("selectionColor", xelection.getColor().name() ) +
insilmaril@0
   274
		          attribut("linkStyle", ls ) +
insilmaril@97
   275
		          attribut("linkColor", defLinkColor.name() ) +
insilmaril@102
   276
		          attribut("defXLinkColor", defXLinkColor.name() ) +
insilmaril@102
   277
		          attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
insilmaril@0
   278
		          colhint; 
insilmaril@0
   279
	s+=beginElement("vymmap",mapAttr);
insilmaril@0
   280
	incIndent();
insilmaril@0
   281
insilmaril@0
   282
	// Find the used flags while traversing the tree
insilmaril@0
   283
	standardFlagsDefault->resetUsedCounter();
insilmaril@0
   284
	
insilmaril@166
   285
	// Reset the counters before saving
insilmaril@406
   286
	// TODO constr. of FIO creates lots of objects, better do this in some other way...
insilmaril@408
   287
	FloatImageObj (mapScene).resetSaveCounter();
insilmaril@166
   288
insilmaril@0
   289
	// Build xml recursivly
insilmaril@398
   290
	if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
insilmaril@366
   291
		// Save complete map, if saveSel not set
insilmaril@0
   292
		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
insilmaril@0
   293
	else
insilmaril@0
   294
	{
insilmaril@366
   295
		if ( typeid(*saveSel) == typeid(BranchObj) )
insilmaril@366
   296
			// Save Subtree
insilmaril@366
   297
			s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
insilmaril@366
   298
		else if ( typeid(*saveSel) == typeid(FloatImageObj) )
insilmaril@366
   299
			// Save image
insilmaril@377
   300
			s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
insilmaril@0
   301
	}
insilmaril@0
   302
insilmaril@0
   303
	// Save local settings
insilmaril@0
   304
	s+=settings.getXMLData (destPath);
insilmaril@0
   305
insilmaril@0
   306
	// Save selection
insilmaril@424
   307
	if (!xelection.isEmpty() && !saveSel ) 
insilmaril@424
   308
		s+=valueElement("select",xelection.getSelectString());
insilmaril@0
   309
insilmaril@0
   310
	decIndent();
insilmaril@0
   311
	s+=endElement("vymmap");
insilmaril@0
   312
insilmaril@0
   313
	if (writeflags)
insilmaril@0
   314
		standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
insilmaril@0
   315
	return s;
insilmaril@0
   316
}
insilmaril@0
   317
insilmaril@505
   318
QString MapEditor::getHistoryDir()
insilmaril@505
   319
{
insilmaril@505
   320
	QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
insilmaril@505
   321
	return QDir::convertSeparators (tmpMapDir +"/"+histName);
insilmaril@505
   322
}
insilmaril@505
   323
insilmaril@486
   324
void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
insilmaril@486
   325
{
insilmaril@528
   326
	sendData(redoCom);	//FIXME testing
insilmaril@528
   327
insilmaril@486
   328
	// Main saveState
insilmaril@486
   329
insilmaril@528
   330
insilmaril@486
   331
	if (blockSaveState) return;
insilmaril@486
   332
insilmaril@486
   333
	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
insilmaril@486
   334
	
insilmaril@486
   335
	// Find out current undo directory
insilmaril@486
   336
	if (undosAvail<stepsTotal) undosAvail++;
insilmaril@486
   337
	curStep++;
insilmaril@486
   338
	if (curStep>stepsTotal) curStep=1;
insilmaril@486
   339
	
insilmaril@486
   340
	QString backupXML="";
insilmaril@505
   341
	QString histDir=getHistoryDir();
insilmaril@505
   342
	QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
insilmaril@505
   343
insilmaril@505
   344
	// Create histDir if not available
insilmaril@505
   345
	QDir d(histDir);
insilmaril@486
   346
	if (!d.exists()) 
insilmaril@505
   347
		makeSubDirs (histDir);
insilmaril@486
   348
insilmaril@486
   349
	// Save depending on how much needs to be saved	
insilmaril@486
   350
	if (saveSel)
insilmaril@505
   351
		backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
insilmaril@486
   352
		
insilmaril@486
   353
	QString undoCommand="";
insilmaril@486
   354
	if (savemode==UndoCommand)
insilmaril@486
   355
	{
insilmaril@486
   356
		undoCommand=undoCom;
insilmaril@486
   357
	}	
insilmaril@486
   358
	else if (savemode==PartOfMap )
insilmaril@486
   359
	{
insilmaril@486
   360
		undoCommand=undoCom;
insilmaril@486
   361
		undoCommand.replace ("PATH",bakMapPath);
insilmaril@486
   362
	}
insilmaril@486
   363
insilmaril@486
   364
	if (!backupXML.isEmpty())
insilmaril@486
   365
		// Write XML Data to disk
insilmaril@486
   366
		saveStringToDisk (QString(bakMapPath),backupXML);
insilmaril@486
   367
insilmaril@486
   368
	// We would have to save all actions in a tree, to keep track of 
insilmaril@486
   369
	// possible redos after a action. Possible, but we are too lazy: forget about redos.
insilmaril@486
   370
	redosAvail=0;
insilmaril@486
   371
insilmaril@486
   372
	// Write the current state to disk
insilmaril@486
   373
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@486
   374
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@486
   375
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@486
   376
	undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
insilmaril@486
   377
	undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
insilmaril@486
   378
	undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
insilmaril@486
   379
	undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
insilmaril@486
   380
	undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
insilmaril@486
   381
	undoSet.setEntry (QString("/history/version"),vymVersion);
insilmaril@486
   382
	undoSet.writeSettings(histPath);
insilmaril@486
   383
insilmaril@486
   384
	if (debug)
insilmaril@486
   385
	{
insilmaril@486
   386
		// TODO remove after testing
insilmaril@486
   387
		//cout << "          into="<< histPath.toStdString()<<endl;
insilmaril@486
   388
		cout << "    stepsTotal="<<stepsTotal<<
insilmaril@486
   389
		", undosAvail="<<undosAvail<<
insilmaril@486
   390
		", redosAvail="<<redosAvail<<
insilmaril@486
   391
		", curStep="<<curStep<<endl;
insilmaril@486
   392
		cout << "    ---------------------------"<<endl;
insilmaril@486
   393
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@486
   394
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@486
   395
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@486
   396
		cout << "    redoCom="<<redoCom.toStdString()<<endl;
insilmaril@486
   397
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@486
   398
		if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
insilmaril@486
   399
		cout << "    ---------------------------"<<endl;
insilmaril@486
   400
	}
insilmaril@486
   401
insilmaril@486
   402
	mainWindow->updateHistory (undoSet);
insilmaril@486
   403
	setChanged();
insilmaril@486
   404
	updateActions();
insilmaril@486
   405
}
insilmaril@486
   406
insilmaril@486
   407
insilmaril@395
   408
void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
insilmaril@0
   409
{
insilmaril@366
   410
	// save the selected part of the map, Undo will replace part of map 
insilmaril@366
   411
	QString undoSelection="";
insilmaril@395
   412
	if (undoSel)
insilmaril@395
   413
		undoSelection=undoSel->getSelectString();
insilmaril@395
   414
	else
insilmaril@395
   415
		qWarning ("MapEditor::saveStateChangingPart  no undoSel given!");
insilmaril@395
   416
	QString redoSelection="";
insilmaril@395
   417
	if (redoSel)
insilmaril@395
   418
		redoSelection=undoSel->getSelectString();
insilmaril@395
   419
	else
insilmaril@395
   420
		qWarning ("MapEditor::saveStateChangingPart  no redoSel given!");
insilmaril@395
   421
		
insilmaril@366
   422
insilmaril@366
   423
	saveState (PartOfMap,
insilmaril@398
   424
		undoSelection, "addMapReplace (\"PATH\")",
insilmaril@395
   425
		redoSelection, rc, 
insilmaril@366
   426
		comment, 
insilmaril@366
   427
		undoSel);
insilmaril@105
   428
}
insilmaril@105
   429
insilmaril@393
   430
void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
insilmaril@393
   431
{
insilmaril@394
   432
	if (!redoSel)
insilmaril@393
   433
	{
insilmaril@394
   434
		qWarning ("MapEditor::saveStateRemovingPart  no redoSel given!");
insilmaril@393
   435
		return;
insilmaril@393
   436
	}
insilmaril@393
   437
	QString undoSelection=redoSel->getParObj()->getSelectString();
insilmaril@393
   438
	QString redoSelection=redoSel->getSelectString();
insilmaril@398
   439
	if (typeid(*redoSel) == typeid(BranchObj)  ) 
insilmaril@394
   440
	{
insilmaril@394
   441
		// save the selected branch of the map, Undo will insert part of map 
insilmaril@394
   442
		saveState (PartOfMap,
insilmaril@394
   443
			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
insilmaril@394
   444
			redoSelection, "delete ()", 
insilmaril@394
   445
			comment, 
insilmaril@394
   446
			redoSel);
insilmaril@394
   447
	}
insilmaril@393
   448
}
insilmaril@393
   449
insilmaril@106
   450
insilmaril@366
   451
void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
insilmaril@366
   452
{
insilmaril@366
   453
	// "Normal" savestate: save commands, selections and comment
insilmaril@366
   454
	// so just save commands for undo and redo
insilmaril@366
   455
	// and use current selection
insilmaril@366
   456
insilmaril@366
   457
	QString redoSelection="";
insilmaril@366
   458
	if (redoSel) redoSelection=redoSel->getSelectString();
insilmaril@366
   459
	QString undoSelection="";
insilmaril@366
   460
	if (undoSel) undoSelection=undoSel->getSelectString();
insilmaril@366
   461
insilmaril@366
   462
	saveState (UndoCommand,
insilmaril@366
   463
		undoSelection, uc,
insilmaril@366
   464
		redoSelection, rc, 
insilmaril@366
   465
		comment, 
insilmaril@366
   466
		NULL);
insilmaril@366
   467
}
insilmaril@366
   468
insilmaril@366
   469
void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) 
insilmaril@366
   470
{
insilmaril@366
   471
	// "Normal" savestate: save commands, selections and comment
insilmaril@366
   472
	// so just save commands for undo and redo
insilmaril@366
   473
	// and use current selection
insilmaril@366
   474
	saveState (UndoCommand,
insilmaril@366
   475
		undoSel, uc,
insilmaril@366
   476
		redoSel, rc, 
insilmaril@366
   477
		comment, 
insilmaril@366
   478
		NULL);
insilmaril@366
   479
}
insilmaril@366
   480
insilmaril@366
   481
		
insilmaril@129
   482
void MapEditor::parseAtom(const QString &atom)
insilmaril@106
   483
{
insilmaril@424
   484
	BranchObj *selb=xelection.getBranch();
insilmaril@163
   485
	QString s,t;
insilmaril@537
   486
	double x,y;
insilmaril@537
   487
	int n;
insilmaril@395
   488
	bool b,ok;
insilmaril@129
   489
insilmaril@129
   490
	// Split string s into command and parameters
insilmaril@432
   491
	parser.parseAtom (atom);
insilmaril@447
   492
	QString com=parser.getCommand();
insilmaril@129
   493
	
insilmaril@106
   494
	// External commands
insilmaril@514
   495
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   496
	if (com=="addBranch")
insilmaril@366
   497
	{
insilmaril@424
   498
		if (xelection.isEmpty())
insilmaril@394
   499
		{
insilmaril@432
   500
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   501
		} else if (! selb )
insilmaril@394
   502
		{				  
insilmaril@432
   503
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   504
		} else 
insilmaril@366
   505
		{	
insilmaril@394
   506
			QList <int> pl;
insilmaril@394
   507
			pl << 0 <<1;
insilmaril@514
   508
			if (parser.checkParCount(pl))
insilmaril@394
   509
			{
insilmaril@514
   510
				if (parser.parCount()==0)
insilmaril@537
   511
					addNewBranch (0);
insilmaril@394
   512
				else
insilmaril@394
   513
				{
insilmaril@537
   514
					n=parser.parInt (ok,0);
insilmaril@537
   515
					if (ok ) addNewBranch (n);
insilmaril@394
   516
				}
insilmaril@394
   517
			}
insilmaril@394
   518
		}
insilmaril@514
   519
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   520
	} else if (com=="addBranchBefore")
insilmaril@394
   521
	{
insilmaril@424
   522
		if (xelection.isEmpty())
insilmaril@394
   523
		{
insilmaril@432
   524
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   525
		} else if (! selb )
insilmaril@394
   526
		{				  
insilmaril@432
   527
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   528
		} else 
insilmaril@394
   529
		{	
insilmaril@514
   530
			if (parser.parCount()==0)
insilmaril@394
   531
			{
insilmaril@394
   532
				addNewBranchBefore ();
insilmaril@394
   533
			}	
insilmaril@394
   534
		}
insilmaril@514
   535
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   536
	} else if (com==QString("addMapReplace"))
insilmaril@393
   537
	{
insilmaril@424
   538
		if (xelection.isEmpty())
insilmaril@394
   539
		{
insilmaril@432
   540
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   541
		} else if (! selb )
insilmaril@394
   542
		{				  
insilmaril@432
   543
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   544
		} else if (parser.checkParCount(1))
insilmaril@393
   545
		{
insilmaril@432
   546
			//s=parser.parString (ok,0);	// selection
insilmaril@432
   547
			t=parser.parString (ok,0);	// path to map
insilmaril@393
   548
			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
insilmaril@424
   549
			addMapReplaceInt(selb->getSelectString(),t);	
insilmaril@393
   550
		}
insilmaril@514
   551
	/////////////////////////////////////////////////////////////////////
insilmaril@434
   552
	} else if (com==QString("addMapInsert"))
insilmaril@393
   553
	{
insilmaril@424
   554
		if (xelection.isEmpty())
insilmaril@393
   555
		{
insilmaril@432
   556
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   557
		} else if (! selb )
insilmaril@394
   558
		{				  
insilmaril@432
   559
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@394
   560
		} else 
insilmaril@394
   561
		{	
insilmaril@514
   562
			if (parser.checkParCount(2))
insilmaril@394
   563
			{
insilmaril@432
   564
				t=parser.parString (ok,0);	// path to map
insilmaril@537
   565
				n=parser.parInt(ok,1);		// position
insilmaril@394
   566
				if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
insilmaril@537
   567
				addMapInsertInt(t,n);	
insilmaril@394
   568
			}
insilmaril@393
   569
		}
insilmaril@514
   570
	/////////////////////////////////////////////////////////////////////
insilmaril@447
   571
	} else if (com=="clearFlags")
insilmaril@447
   572
	{
insilmaril@447
   573
		if (xelection.isEmpty() )
insilmaril@447
   574
		{
insilmaril@447
   575
			parser.setError (Aborted,"Nothing selected");
insilmaril@447
   576
		} else if (! selb )
insilmaril@447
   577
		{				  
insilmaril@447
   578
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   579
		} else if (parser.checkParCount(0))
insilmaril@447
   580
		{
insilmaril@447
   581
			selb->clearStandardFlags();	
insilmaril@447
   582
			selb->updateFlagsToolbar();
insilmaril@447
   583
		}
insilmaril@514
   584
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   585
	} else if (com=="colorBranch")
insilmaril@395
   586
	{
insilmaril@424
   587
		if (xelection.isEmpty())
insilmaril@395
   588
		{
insilmaril@432
   589
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   590
		} else if (! selb )
insilmaril@395
   591
		{				  
insilmaril@432
   592
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   593
		} else if (parser.checkParCount(1))
insilmaril@395
   594
		{	
insilmaril@432
   595
			QColor c=parser.parColor (ok,0);
insilmaril@395
   596
			if (ok) colorBranch (c);
insilmaril@395
   597
		}	
insilmaril@514
   598
	/////////////////////////////////////////////////////////////////////
insilmaril@417
   599
	} else if (com=="colorSubtree")
insilmaril@417
   600
	{
insilmaril@424
   601
		if (xelection.isEmpty())
insilmaril@417
   602
		{
insilmaril@432
   603
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   604
		} else if (! selb )
insilmaril@417
   605
		{				  
insilmaril@432
   606
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   607
		} else if (parser.checkParCount(1))
insilmaril@417
   608
		{	
insilmaril@432
   609
			QColor c=parser.parColor (ok,0);
insilmaril@417
   610
			if (ok) colorSubtree (c);
insilmaril@417
   611
		}	
insilmaril@514
   612
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   613
	} else if (com=="copy")
insilmaril@502
   614
	{
insilmaril@502
   615
		if (xelection.isEmpty())
insilmaril@502
   616
		{
insilmaril@502
   617
			parser.setError (Aborted,"Nothing selected");
insilmaril@502
   618
		} else if (! selb )
insilmaril@502
   619
		{				  
insilmaril@502
   620
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   621
		} else if (parser.checkParCount(0))
insilmaril@502
   622
		{	
insilmaril@502
   623
			//FIXME missing action for copy
insilmaril@502
   624
		}	
insilmaril@514
   625
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   626
	} else if (com=="cut")
insilmaril@395
   627
	{
insilmaril@424
   628
		if (xelection.isEmpty())
insilmaril@395
   629
		{
insilmaril@432
   630
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   631
		} else if ( xelection.type()!=Selection::Branch  && 
insilmaril@491
   632
					xelection.type()!=Selection::MapCenter  &&
insilmaril@491
   633
					xelection.type()!=Selection::FloatImage )
insilmaril@395
   634
		{				  
insilmaril@432
   635
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   636
		} else if (parser.checkParCount(0))
insilmaril@395
   637
		{	
insilmaril@395
   638
			cut();
insilmaril@395
   639
		}	
insilmaril@514
   640
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   641
	} else if (com=="delete")
insilmaril@393
   642
	{
insilmaril@424
   643
		if (xelection.isEmpty())
insilmaril@394
   644
		{
insilmaril@432
   645
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   646
		} else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
insilmaril@424
   647
		{
insilmaril@434
   648
			parser.setError (Aborted,"Type of selection is wrong.");
insilmaril@514
   649
		} else if (parser.checkParCount(0))
insilmaril@393
   650
		{	
insilmaril@393
   651
			deleteSelection();
insilmaril@393
   652
		}	
insilmaril@514
   653
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   654
	} else if (com=="deleteKeepChilds")
insilmaril@394
   655
	{
insilmaril@424
   656
		if (xelection.isEmpty())
insilmaril@394
   657
		{
insilmaril@432
   658
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   659
		} else if (! selb )
insilmaril@424
   660
		{
insilmaril@432
   661
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   662
		} else if (parser.checkParCount(0))
insilmaril@394
   663
		{	
insilmaril@395
   664
			deleteKeepChilds();
insilmaril@395
   665
		}	
insilmaril@514
   666
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   667
	} else if (com=="deleteChilds")
insilmaril@395
   668
	{
insilmaril@424
   669
		if (xelection.isEmpty())
insilmaril@395
   670
		{
insilmaril@432
   671
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   672
		} else if (! selb)
insilmaril@424
   673
		{
insilmaril@432
   674
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   675
		} else if (parser.checkParCount(0))
insilmaril@395
   676
		{	
insilmaril@395
   677
			deleteChilds();
insilmaril@394
   678
		}	
insilmaril@514
   679
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   680
	} else if (com=="exportASCII")
insilmaril@514
   681
	{
insilmaril@517
   682
		QString fname="";
insilmaril@517
   683
		ok=true;
insilmaril@517
   684
		if (parser.parCount()>=2)
insilmaril@517
   685
			// Hey, we even have a filename
insilmaril@517
   686
			fname=parser.parString(ok,1); 
insilmaril@517
   687
		if (!ok)
insilmaril@514
   688
		{
insilmaril@517
   689
			parser.setError (Aborted,"Could not read filename");
insilmaril@514
   690
		} else
insilmaril@514
   691
		{
insilmaril@517
   692
				exportASCII (fname,false);
insilmaril@517
   693
		}
insilmaril@517
   694
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   695
	} else if (com=="exportImage")
insilmaril@517
   696
	{
insilmaril@517
   697
		QString fname="";
insilmaril@517
   698
		ok=true;
insilmaril@517
   699
		if (parser.parCount()>=2)
insilmaril@517
   700
			// Hey, we even have a filename
insilmaril@517
   701
			fname=parser.parString(ok,1); 
insilmaril@517
   702
		if (!ok)
insilmaril@517
   703
		{
insilmaril@517
   704
			parser.setError (Aborted,"Could not read filename");
insilmaril@517
   705
		} else
insilmaril@517
   706
		{
insilmaril@517
   707
			QString format="PNG";
insilmaril@517
   708
			if (parser.parCount()>2)
insilmaril@514
   709
			{
insilmaril@517
   710
				format=parser.parString(ok,2);
insilmaril@514
   711
			}
insilmaril@517
   712
			exportImage (fname,false,format);
insilmaril@517
   713
		}
insilmaril@517
   714
	/////////////////////////////////////////////////////////////////////
insilmaril@517
   715
	} else if (com=="exportXHTML")
insilmaril@517
   716
	{
insilmaril@517
   717
		QString fname="";
insilmaril@517
   718
		ok=true;
insilmaril@517
   719
		if (parser.parCount()>=2)
insilmaril@517
   720
			// Hey, we even have a filename
insilmaril@517
   721
			fname=parser.parString(ok,1); 
insilmaril@517
   722
		if (!ok)
insilmaril@517
   723
		{
insilmaril@517
   724
			parser.setError (Aborted,"Could not read filename");
insilmaril@517
   725
		} else
insilmaril@517
   726
		{
insilmaril@520
   727
			exportXHTML (fname,false);
insilmaril@517
   728
		}
insilmaril@514
   729
	/////////////////////////////////////////////////////////////////////
insilmaril@526
   730
	} else if (com=="exportXML")
insilmaril@526
   731
	{
insilmaril@526
   732
		QString fname="";
insilmaril@526
   733
		ok=true;
insilmaril@526
   734
		if (parser.parCount()>=2)
insilmaril@526
   735
			// Hey, we even have a filename
insilmaril@526
   736
			fname=parser.parString(ok,1); 
insilmaril@526
   737
		if (!ok)
insilmaril@526
   738
		{
insilmaril@526
   739
			parser.setError (Aborted,"Could not read filename");
insilmaril@526
   740
		} else
insilmaril@526
   741
		{
insilmaril@526
   742
			exportXML (fname,false);
insilmaril@526
   743
		}
insilmaril@526
   744
	/////////////////////////////////////////////////////////////////////
insilmaril@491
   745
	} else if (com=="importDir")
insilmaril@491
   746
	{
insilmaril@491
   747
		if (xelection.isEmpty())
insilmaril@491
   748
		{
insilmaril@491
   749
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   750
		} else if (! selb )
insilmaril@491
   751
		{				  
insilmaril@491
   752
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   753
		} else if (parser.checkParCount(1))
insilmaril@491
   754
		{
insilmaril@491
   755
			s=parser.parString(ok,0);
insilmaril@491
   756
			if (ok) importDirInt(s);
insilmaril@491
   757
		}	
insilmaril@514
   758
	/////////////////////////////////////////////////////////////////////
insilmaril@420
   759
	} else if (com=="linkTo")
insilmaril@420
   760
	{
insilmaril@424
   761
		if (xelection.isEmpty())
insilmaril@420
   762
		{
insilmaril@432
   763
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   764
		} else if ( selb)
insilmaril@420
   765
		{
insilmaril@514
   766
			if (parser.checkParCount(4))
insilmaril@421
   767
			{
insilmaril@421
   768
				// 0	selectstring of parent
insilmaril@421
   769
				// 1	num in parent (for branches)
insilmaril@421
   770
				// 2,3	x,y of mainbranch or mapcenter
insilmaril@432
   771
				s=parser.parString(ok,0);
insilmaril@421
   772
				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
insilmaril@421
   773
				if (dst)
insilmaril@421
   774
				{	
insilmaril@421
   775
					if (typeid(*dst) == typeid(BranchObj) ) 
insilmaril@421
   776
					{
insilmaril@421
   777
						// Get number in parent
insilmaril@537
   778
						n=parser.parInt (ok,1);
insilmaril@421
   779
						if (ok)
insilmaril@534
   780
						{
insilmaril@537
   781
							selb->linkTo ((BranchObj*)(dst),n);
insilmaril@534
   782
							xelection.update();
insilmaril@534
   783
						}	
insilmaril@421
   784
					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
insilmaril@421
   785
					{
insilmaril@424
   786
						selb->linkTo ((BranchObj*)(dst),-1);
insilmaril@421
   787
						// Get coordinates of mainbranch
insilmaril@537
   788
						x=parser.parDouble(ok,2);
insilmaril@421
   789
						if (ok)
insilmaril@421
   790
						{
insilmaril@537
   791
							y=parser.parDouble(ok,3);
insilmaril@534
   792
							if (ok) 
insilmaril@534
   793
							{
insilmaril@534
   794
								selb->move (x,y);
insilmaril@534
   795
								xelection.update();
insilmaril@534
   796
							}
insilmaril@421
   797
						}
insilmaril@421
   798
					}	
insilmaril@421
   799
				}	
insilmaril@421
   800
			}	
insilmaril@491
   801
		} else if ( xelection.type() == Selection::FloatImage) 
insilmaril@421
   802
		{
insilmaril@514
   803
			if (parser.checkParCount(1))
insilmaril@421
   804
			{
insilmaril@421
   805
				// 0	selectstring of parent
insilmaril@432
   806
				s=parser.parString(ok,0);
insilmaril@421
   807
				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
insilmaril@421
   808
				if (dst)
insilmaril@421
   809
				{	
insilmaril@421
   810
					if (typeid(*dst) == typeid(BranchObj) ||
insilmaril@421
   811
						typeid(*dst) == typeid(MapCenterObj)) 
insilmaril@421
   812
						linkTo (dst->getSelectString());
insilmaril@421
   813
				} else	
insilmaril@432
   814
					parser.setError (Aborted,"Destination is not a branch");
insilmaril@421
   815
			}		
insilmaril@421
   816
		} else
insilmaril@432
   817
			parser.setError (Aborted,"Type of selection is not a floatimage or branch");
insilmaril@514
   818
	/////////////////////////////////////////////////////////////////////
insilmaril@432
   819
	} else if (com=="loadImage")
insilmaril@432
   820
	{
insilmaril@432
   821
		if (xelection.isEmpty())
insilmaril@432
   822
		{
insilmaril@432
   823
			parser.setError (Aborted,"Nothing selected");
insilmaril@432
   824
		} else if (! selb )
insilmaril@432
   825
		{				  
insilmaril@432
   826
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   827
		} else if (parser.checkParCount(1))
insilmaril@432
   828
		{
insilmaril@432
   829
			s=parser.parString(ok,0);
insilmaril@432
   830
			if (ok) loadFloatImageInt (s);
insilmaril@432
   831
		}	
insilmaril@514
   832
	/////////////////////////////////////////////////////////////////////
insilmaril@393
   833
	} else if (com=="moveBranchUp")
insilmaril@393
   834
	{
insilmaril@424
   835
		if (xelection.isEmpty() )
insilmaril@394
   836
		{
insilmaril@432
   837
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   838
		} else if (! selb )
insilmaril@394
   839
		{				  
insilmaril@432
   840
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   841
		} else if (parser.checkParCount(0))
insilmaril@394
   842
		{
insilmaril@394
   843
			moveBranchUp();
insilmaril@394
   844
		}	
insilmaril@514
   845
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   846
	} else if (com=="moveBranchDown")
insilmaril@394
   847
	{
insilmaril@424
   848
		if (xelection.isEmpty() )
insilmaril@394
   849
		{
insilmaril@432
   850
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   851
		} else if (! selb )
insilmaril@394
   852
		{				  
insilmaril@432
   853
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   854
		} else if (parser.checkParCount(0))
insilmaril@394
   855
		{
insilmaril@394
   856
			moveBranchDown();
insilmaril@394
   857
		}	
insilmaril@514
   858
	/////////////////////////////////////////////////////////////////////
insilmaril@394
   859
	} else if (com=="move")
insilmaril@394
   860
	{
insilmaril@424
   861
		if (xelection.isEmpty() )
insilmaril@394
   862
		{
insilmaril@432
   863
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   864
		} else if ( xelection.type()!=Selection::Branch  && 
insilmaril@491
   865
					xelection.type()!=Selection::MapCenter  &&
insilmaril@491
   866
					xelection.type()!=Selection::FloatImage )
insilmaril@394
   867
		{				  
insilmaril@432
   868
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   869
		} else if (parser.checkParCount(2))
insilmaril@393
   870
		{	
insilmaril@537
   871
			x=parser.parDouble (ok,0);
insilmaril@393
   872
			if (ok)
insilmaril@393
   873
			{
insilmaril@537
   874
				y=parser.parDouble (ok,1);
insilmaril@393
   875
				if (ok) move (x,y);
insilmaril@393
   876
			}
insilmaril@393
   877
		}	
insilmaril@514
   878
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   879
	} else if (com=="moveRel")
insilmaril@393
   880
	{
insilmaril@424
   881
		if (xelection.isEmpty() )
insilmaril@394
   882
		{
insilmaril@432
   883
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
   884
		} else if ( xelection.type()!=Selection::Selection::Branch  && 
insilmaril@491
   885
					xelection.type()!=Selection::Selection::MapCenter  &&
insilmaril@491
   886
					xelection.type()!=Selection::Selection::FloatImage )
insilmaril@394
   887
		{				  
insilmaril@432
   888
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
   889
		} else if (parser.checkParCount(2))
insilmaril@393
   890
		{	
insilmaril@537
   891
			x=parser.parDouble (ok,0);
insilmaril@393
   892
			if (ok)
insilmaril@393
   893
			{
insilmaril@537
   894
				y=parser.parDouble (ok,1);
insilmaril@393
   895
				if (ok) moveRel (x,y);
insilmaril@393
   896
			}
insilmaril@393
   897
		}	
insilmaril@514
   898
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   899
	} else if (com=="nop")
insilmaril@502
   900
	{
insilmaril@514
   901
	/////////////////////////////////////////////////////////////////////
insilmaril@395
   902
	} else if (com=="paste")
insilmaril@395
   903
	{
insilmaril@424
   904
		if (xelection.isEmpty() )
insilmaril@395
   905
		{
insilmaril@432
   906
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
   907
		} else if (! selb )
insilmaril@395
   908
		{				  
insilmaril@432
   909
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   910
		} else if (parser.checkParCount(1))
insilmaril@395
   911
		{	
insilmaril@537
   912
			n=parser.parInt (ok,0);
insilmaril@537
   913
			if (ok) pasteNoSave(n);
insilmaril@502
   914
		}	
insilmaril@502
   915
	/////////////////////////////////////////////////////////////////////
insilmaril@502
   916
	} else if (com=="qa")
insilmaril@502
   917
	{
insilmaril@502
   918
		if (xelection.isEmpty() )
insilmaril@502
   919
		{
insilmaril@502
   920
			parser.setError (Aborted,"Nothing selected");
insilmaril@502
   921
		} else if (! selb )
insilmaril@502
   922
		{				  
insilmaril@502
   923
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
   924
		} else if (parser.checkParCount(4))
insilmaril@502
   925
		{	
insilmaril@502
   926
			QString c,u;
insilmaril@502
   927
			c=parser.parString (ok,0);
insilmaril@502
   928
			if (!ok)
insilmaril@502
   929
			{
insilmaril@502
   930
				parser.setError (Aborted,"No comment given");
insilmaril@502
   931
			} else
insilmaril@502
   932
			{
insilmaril@502
   933
				s=parser.parString (ok,1);
insilmaril@502
   934
				if (!ok)
insilmaril@502
   935
				{
insilmaril@502
   936
					parser.setError (Aborted,"First parameter is not a string");
insilmaril@502
   937
				} else
insilmaril@502
   938
				{
insilmaril@502
   939
					t=parser.parString (ok,2);
insilmaril@502
   940
					if (!ok)
insilmaril@502
   941
					{
insilmaril@502
   942
						parser.setError (Aborted,"Condition is not a string");
insilmaril@502
   943
					} else
insilmaril@502
   944
					{
insilmaril@502
   945
						u=parser.parString (ok,3);
insilmaril@502
   946
						if (!ok)
insilmaril@502
   947
						{
insilmaril@502
   948
							parser.setError (Aborted,"Third parameter is not a string");
insilmaril@502
   949
						} else
insilmaril@502
   950
						{
insilmaril@502
   951
							if (s!="heading")
insilmaril@502
   952
							{
insilmaril@502
   953
								parser.setError (Aborted,"Unknown type: "+s);
insilmaril@502
   954
							} else
insilmaril@502
   955
							{
insilmaril@502
   956
								if (! (t=="eq") ) 
insilmaril@502
   957
								{
insilmaril@502
   958
									parser.setError (Aborted,"Unknown operator: "+t);
insilmaril@502
   959
								} else
insilmaril@502
   960
								{
insilmaril@502
   961
									if (! selb    )
insilmaril@502
   962
									{
insilmaril@502
   963
										parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@502
   964
									} else
insilmaril@502
   965
									{
insilmaril@502
   966
										if (selb->getHeading() == u)
insilmaril@502
   967
										{
insilmaril@502
   968
											cout << "PASSED: " << c.ascii() << endl;
insilmaril@502
   969
										} else
insilmaril@502
   970
										{
insilmaril@502
   971
											cout << "FAILED: " << c.ascii() << endl;
insilmaril@502
   972
										}
insilmaril@502
   973
									}
insilmaril@502
   974
								}
insilmaril@502
   975
							}
insilmaril@502
   976
						} 
insilmaril@502
   977
					} 
insilmaril@502
   978
				} 
insilmaril@502
   979
			}
insilmaril@395
   980
		}	
insilmaril@514
   981
	/////////////////////////////////////////////////////////////////////
insilmaril@434
   982
	} else if (com=="saveImage")
insilmaril@434
   983
	{
insilmaril@434
   984
		FloatImageObj *fio=xelection.getFloatImage();
insilmaril@434
   985
		if (!fio)
insilmaril@434
   986
		{
insilmaril@434
   987
			parser.setError (Aborted,"Type of selection is not an image");
insilmaril@514
   988
		} else if (parser.checkParCount(2))
insilmaril@434
   989
		{
insilmaril@434
   990
			s=parser.parString(ok,0);
insilmaril@434
   991
			if (ok)
insilmaril@434
   992
			{
insilmaril@434
   993
				t=parser.parString(ok,1);
insilmaril@434
   994
				if (ok) saveFloatImageInt (fio,t,s);
insilmaril@434
   995
			}
insilmaril@434
   996
		}	
insilmaril@514
   997
	/////////////////////////////////////////////////////////////////////
insilmaril@427
   998
	} else if (com=="scroll")
insilmaril@427
   999
	{
insilmaril@427
  1000
		if (xelection.isEmpty() )
insilmaril@427
  1001
		{
insilmaril@432
  1002
			parser.setError (Aborted,"Nothing selected");
insilmaril@427
  1003
		} else if (! selb )
insilmaril@427
  1004
		{				  
insilmaril@432
  1005
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1006
		} else if (parser.checkParCount(0))
insilmaril@427
  1007
		{	
insilmaril@473
  1008
			if (!scrollBranch (selb))	
insilmaril@432
  1009
				parser.setError (Aborted,"Could not scroll branch");
insilmaril@427
  1010
		}	
insilmaril@514
  1011
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1012
	} else if (com=="select")
insilmaril@398
  1013
	{
insilmaril@514
  1014
		if (parser.checkParCount(1))
insilmaril@398
  1015
		{
insilmaril@432
  1016
			s=parser.parString(ok,0);
insilmaril@398
  1017
			if (ok) select (s);
insilmaril@398
  1018
		}	
insilmaril@514
  1019
	/////////////////////////////////////////////////////////////////////
insilmaril@432
  1020
	} else if (com=="selectLastBranch")
insilmaril@432
  1021
	{
insilmaril@432
  1022
		if (xelection.isEmpty() )
insilmaril@432
  1023
		{
insilmaril@432
  1024
			parser.setError (Aborted,"Nothing selected");
insilmaril@432
  1025
		} else if (! selb )
insilmaril@432
  1026
		{				  
insilmaril@432
  1027
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1028
		} else if (parser.checkParCount(0))
insilmaril@432
  1029
		{	
insilmaril@432
  1030
			BranchObj *bo=selb->getLastBranch();
insilmaril@432
  1031
			if (!bo)
insilmaril@432
  1032
				parser.setError (Aborted,"Could not select last branch");
insilmaril@432
  1033
			selectInt (bo);	
insilmaril@432
  1034
				
insilmaril@432
  1035
		}	
insilmaril@514
  1036
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1037
	} else if (com=="selectLastImage")
insilmaril@434
  1038
	{
insilmaril@434
  1039
		if (xelection.isEmpty() )
insilmaril@434
  1040
		{
insilmaril@434
  1041
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1042
		} else if (! selb )
insilmaril@434
  1043
		{				  
insilmaril@434
  1044
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1045
		} else if (parser.checkParCount(0))
insilmaril@434
  1046
		{	
insilmaril@434
  1047
			FloatImageObj *fio=selb->getLastFloatImage();
insilmaril@434
  1048
			if (!fio)
insilmaril@434
  1049
				parser.setError (Aborted,"Could not select last image");
insilmaril@434
  1050
			selectInt (fio);	
insilmaril@434
  1051
				
insilmaril@434
  1052
		}	
insilmaril@514
  1053
	/////////////////////////////////////////////////////////////////////
insilmaril@537
  1054
	} else if (com=="selectLatestAdded")
insilmaril@537
  1055
	{
insilmaril@537
  1056
		if (latestSelection.isEmpty() )
insilmaril@537
  1057
		{
insilmaril@537
  1058
			parser.setError (Aborted,"No latest added object");
insilmaril@537
  1059
		} else
insilmaril@537
  1060
		{	
insilmaril@537
  1061
			if (!select (latestSelection))
insilmaril@537
  1062
				parser.setError (Aborted,"Could not select latest added object "+latestSelection);
insilmaril@537
  1063
		}	
insilmaril@537
  1064
	/////////////////////////////////////////////////////////////////////
insilmaril@473
  1065
	} else if (com=="setFrameType")
insilmaril@473
  1066
	{
insilmaril@491
  1067
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@473
  1068
		{
insilmaril@473
  1069
			parser.setError (Aborted,"Type of selection does not allow setting frame type");
insilmaril@473
  1070
		}
insilmaril@514
  1071
		else if (parser.checkParCount(1))
insilmaril@473
  1072
		{
insilmaril@473
  1073
			s=parser.parString(ok,0);
insilmaril@473
  1074
			if (ok) setFrameType (s);
insilmaril@473
  1075
		}	
insilmaril@514
  1076
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1077
	} else if (com=="setFramePenColor")
insilmaril@486
  1078
	{
insilmaril@491
  1079
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1080
		{
insilmaril@486
  1081
			parser.setError (Aborted,"Type of selection does not allow setting of pen color");
insilmaril@486
  1082
		}
insilmaril@514
  1083
		else if (parser.checkParCount(1))
insilmaril@486
  1084
		{
insilmaril@486
  1085
			QColor c=parser.parColor(ok,0);
insilmaril@486
  1086
			if (ok) setFramePenColor (c);
insilmaril@486
  1087
		}	
insilmaril@514
  1088
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1089
	} else if (com=="setFrameBrushColor")
insilmaril@486
  1090
	{
insilmaril@491
  1091
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1092
		{
insilmaril@486
  1093
			parser.setError (Aborted,"Type of selection does not allow setting brush color");
insilmaril@486
  1094
		}
insilmaril@514
  1095
		else if (parser.checkParCount(1))
insilmaril@486
  1096
		{
insilmaril@486
  1097
			QColor c=parser.parColor(ok,0);
insilmaril@486
  1098
			if (ok) setFrameBrushColor (c);
insilmaril@486
  1099
		}	
insilmaril@514
  1100
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1101
	} else if (com=="setFramePadding")
insilmaril@486
  1102
	{
insilmaril@491
  1103
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1104
		{
insilmaril@486
  1105
			parser.setError (Aborted,"Type of selection does not allow setting frame padding");
insilmaril@486
  1106
		}
insilmaril@514
  1107
		else if (parser.checkParCount(1))
insilmaril@486
  1108
		{
insilmaril@537
  1109
			n=parser.parInt(ok,0);
insilmaril@537
  1110
			if (ok) setFramePadding(n);
insilmaril@486
  1111
		}	
insilmaril@514
  1112
	/////////////////////////////////////////////////////////////////////
insilmaril@486
  1113
	} else if (com=="setFrameBorderWidth")
insilmaril@486
  1114
	{
insilmaril@491
  1115
		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@486
  1116
		{
insilmaril@486
  1117
			parser.setError (Aborted,"Type of selection does not allow setting frame border width");
insilmaril@486
  1118
		}
insilmaril@514
  1119
		else if (parser.checkParCount(1))
insilmaril@486
  1120
		{
insilmaril@537
  1121
			n=parser.parInt(ok,0);
insilmaril@537
  1122
			if (ok) setFrameBorderWidth (n);
insilmaril@486
  1123
		}	
insilmaril@514
  1124
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1125
	} else if (com=="setMapAuthor")
insilmaril@398
  1126
	{
insilmaril@514
  1127
		if (parser.checkParCount(1))
insilmaril@398
  1128
		{
insilmaril@432
  1129
			s=parser.parString(ok,0);
insilmaril@398
  1130
			if (ok) setMapAuthor (s);
insilmaril@398
  1131
		}	
insilmaril@514
  1132
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1133
	} else if (com=="setMapComment")
insilmaril@398
  1134
	{
insilmaril@514
  1135
		if (parser.checkParCount(1))
insilmaril@398
  1136
		{
insilmaril@432
  1137
			s=parser.parString(ok,0);
insilmaril@398
  1138
			if (ok) setMapComment(s);
insilmaril@398
  1139
		}	
insilmaril@514
  1140
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1141
	} else if (com=="setMapBackgroundColor")
insilmaril@398
  1142
	{
insilmaril@424
  1143
		if (xelection.isEmpty() )
insilmaril@398
  1144
		{
insilmaril@432
  1145
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1146
		} else if (! xelection.getBranch() )
insilmaril@398
  1147
		{				  
insilmaril@432
  1148
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1149
		} else if (parser.checkParCount(1))
insilmaril@398
  1150
		{
insilmaril@432
  1151
			QColor c=parser.parColor (ok,0);
insilmaril@398
  1152
			if (ok) setMapBackgroundColor (c);
insilmaril@398
  1153
		}	
insilmaril@514
  1154
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1155
	} else if (com=="setMapDefLinkColor")
insilmaril@398
  1156
	{
insilmaril@424
  1157
		if (xelection.isEmpty() )
insilmaril@398
  1158
		{
insilmaril@432
  1159
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1160
		} else if (! selb )
insilmaril@398
  1161
		{				  
insilmaril@432
  1162
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1163
		} else if (parser.checkParCount(1))
insilmaril@398
  1164
		{
insilmaril@432
  1165
			QColor c=parser.parColor (ok,0);
insilmaril@398
  1166
			if (ok) setMapDefLinkColor (c);
insilmaril@398
  1167
		}	
insilmaril@514
  1168
	/////////////////////////////////////////////////////////////////////
insilmaril@398
  1169
	} else if (com=="setMapLinkStyle")
insilmaril@398
  1170
	{
insilmaril@514
  1171
		if (parser.checkParCount(1))
insilmaril@398
  1172
		{
insilmaril@432
  1173
			s=parser.parString (ok,0);
insilmaril@398
  1174
			if (ok) setMapLinkStyle(s);
insilmaril@398
  1175
		}	
insilmaril@514
  1176
	/////////////////////////////////////////////////////////////////////
insilmaril@129
  1177
	} else if (com=="setHeading")
insilmaril@129
  1178
	{
insilmaril@424
  1179
		if (xelection.isEmpty() )
insilmaril@394
  1180
		{
insilmaril@432
  1181
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1182
		} else if (! selb )
insilmaril@394
  1183
		{				  
insilmaril@432
  1184
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1185
		} else if (parser.checkParCount(1))
insilmaril@129
  1186
		{
insilmaril@432
  1187
			s=parser.parString (ok,0);
insilmaril@366
  1188
			if (ok) 
insilmaril@366
  1189
				setHeading (s);
insilmaril@129
  1190
		}	
insilmaril@514
  1191
	/////////////////////////////////////////////////////////////////////
insilmaril@395
  1192
	} else if (com=="setHideExport")
insilmaril@395
  1193
	{
insilmaril@424
  1194
		if (xelection.isEmpty() )
insilmaril@395
  1195
		{
insilmaril@432
  1196
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
  1197
		} else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
insilmaril@395
  1198
		{				  
insilmaril@432
  1199
			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
insilmaril@514
  1200
		} else if (parser.checkParCount(1))
insilmaril@395
  1201
		{
insilmaril@432
  1202
			b=parser.parBool(ok,0);
insilmaril@395
  1203
			if (ok) setHideExport (b);
insilmaril@395
  1204
		}
insilmaril@514
  1205
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1206
	} else if (com=="setIncludeImagesHorizontally")
insilmaril@473
  1207
	{ 
insilmaril@434
  1208
		if (xelection.isEmpty() )
insilmaril@434
  1209
		{
insilmaril@434
  1210
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1211
		} else if (! selb)
insilmaril@434
  1212
		{				  
insilmaril@434
  1213
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1214
		} else if (parser.checkParCount(1))
insilmaril@434
  1215
		{
insilmaril@434
  1216
			b=parser.parBool(ok,0);
insilmaril@434
  1217
			if (ok) setIncludeImagesHor(b);
insilmaril@434
  1218
		}
insilmaril@514
  1219
	/////////////////////////////////////////////////////////////////////
insilmaril@434
  1220
	} else if (com=="setIncludeImagesVertically")
insilmaril@434
  1221
	{
insilmaril@434
  1222
		if (xelection.isEmpty() )
insilmaril@434
  1223
		{
insilmaril@434
  1224
			parser.setError (Aborted,"Nothing selected");
insilmaril@434
  1225
		} else if (! selb)
insilmaril@434
  1226
		{				  
insilmaril@434
  1227
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1228
		} else if (parser.checkParCount(1))
insilmaril@434
  1229
		{
insilmaril@434
  1230
			b=parser.parBool(ok,0);
insilmaril@434
  1231
			if (ok) setIncludeImagesVer(b);
insilmaril@434
  1232
		}
insilmaril@514
  1233
	/////////////////////////////////////////////////////////////////////
insilmaril@491
  1234
	} else if (com=="setHideLinkUnselected")
insilmaril@491
  1235
	{
insilmaril@491
  1236
		if (xelection.isEmpty() )
insilmaril@491
  1237
		{
insilmaril@491
  1238
			parser.setError (Aborted,"Nothing selected");
insilmaril@491
  1239
		} else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
insilmaril@491
  1240
		{				  
insilmaril@491
  1241
			parser.setError (Aborted,"Type of selection does not allow hiding the link");
insilmaril@514
  1242
		} else if (parser.checkParCount(1))
insilmaril@491
  1243
		{
insilmaril@491
  1244
			b=parser.parBool(ok,0);
insilmaril@491
  1245
			if (ok) setHideLinkUnselected(b);
insilmaril@491
  1246
		}
insilmaril@514
  1247
	/////////////////////////////////////////////////////////////////////
insilmaril@442
  1248
	} else if (com=="setSelectionColor")
insilmaril@442
  1249
	{
insilmaril@514
  1250
		if (parser.checkParCount(1))
insilmaril@442
  1251
		{
insilmaril@442
  1252
			QColor c=parser.parColor (ok,0);
insilmaril@442
  1253
			if (ok) setSelectionColorInt (c);
insilmaril@442
  1254
		}	
insilmaril@514
  1255
	/////////////////////////////////////////////////////////////////////
insilmaril@143
  1256
	} else if (com=="setURL")
insilmaril@143
  1257
	{
insilmaril@424
  1258
		if (xelection.isEmpty() )
insilmaril@394
  1259
		{
insilmaril@432
  1260
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1261
		} else if (! selb )
insilmaril@394
  1262
		{				  
insilmaril@432
  1263
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1264
		} else if (parser.checkParCount(1))
insilmaril@143
  1265
		{
insilmaril@432
  1266
			s=parser.parString (ok,0);
insilmaril@491
  1267
			if (ok) setURL(s);
insilmaril@143
  1268
		}	
insilmaril@514
  1269
	/////////////////////////////////////////////////////////////////////
insilmaril@143
  1270
	} else if (com=="setVymLink")
insilmaril@143
  1271
	{
insilmaril@424
  1272
		if (xelection.isEmpty() )
insilmaril@394
  1273
		{
insilmaril@432
  1274
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1275
		} else if (! selb )
insilmaril@394
  1276
		{				  
insilmaril@432
  1277
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1278
		} else if (parser.checkParCount(1))
insilmaril@143
  1279
		{
insilmaril@432
  1280
			s=parser.parString (ok,0);
insilmaril@366
  1281
			if (ok) setVymLinkInt(s);
insilmaril@143
  1282
		}	
insilmaril@143
  1283
	}
insilmaril@514
  1284
	/////////////////////////////////////////////////////////////////////
insilmaril@366
  1285
	else if (com=="setFlag")
insilmaril@366
  1286
	{
insilmaril@424
  1287
		if (xelection.isEmpty() )
insilmaril@366
  1288
		{
insilmaril@432
  1289
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1290
		} else if (! selb )
insilmaril@394
  1291
		{				  
insilmaril@432
  1292
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1293
		} else if (parser.checkParCount(1))
insilmaril@394
  1294
		{
insilmaril@432
  1295
			s=parser.parString(ok,0);
insilmaril@394
  1296
			if (ok) 
insilmaril@394
  1297
			{
insilmaril@424
  1298
				selb->activateStandardFlag(s);
insilmaril@424
  1299
				selb->updateFlagsToolbar();
insilmaril@366
  1300
			}	
insilmaril@366
  1301
		}
insilmaril@514
  1302
	/////////////////////////////////////////////////////////////////////
insilmaril@445
  1303
	} else if (com=="setFrameType")
insilmaril@445
  1304
	{
insilmaril@445
  1305
		if (xelection.isEmpty() )
insilmaril@445
  1306
		{
insilmaril@445
  1307
			parser.setError (Aborted,"Nothing selected");
insilmaril@445
  1308
		} else if (! selb )
insilmaril@445
  1309
		{				  
insilmaril@445
  1310
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1311
		} else if (parser.checkParCount(1))
insilmaril@445
  1312
		{
insilmaril@445
  1313
			s=parser.parString(ok,0);
insilmaril@445
  1314
			if (ok) 
insilmaril@445
  1315
				setFrameType (s);
insilmaril@445
  1316
		}
insilmaril@514
  1317
	/////////////////////////////////////////////////////////////////////
insilmaril@447
  1318
	} else if (com=="toggleFlag")
insilmaril@447
  1319
	{
insilmaril@447
  1320
		if (xelection.isEmpty() )
insilmaril@447
  1321
		{
insilmaril@447
  1322
			parser.setError (Aborted,"Nothing selected");
insilmaril@447
  1323
		} else if (! selb )
insilmaril@447
  1324
		{				  
insilmaril@447
  1325
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1326
		} else if (parser.checkParCount(1))
insilmaril@447
  1327
		{
insilmaril@447
  1328
			s=parser.parString(ok,0);
insilmaril@447
  1329
			if (ok) 
insilmaril@447
  1330
			{
insilmaril@447
  1331
				selb->toggleStandardFlag(s);	
insilmaril@447
  1332
				selb->updateFlagsToolbar();
insilmaril@447
  1333
			}	
insilmaril@447
  1334
		}
insilmaril@514
  1335
	/////////////////////////////////////////////////////////////////////
insilmaril@427
  1336
	} else if (com=="unscroll")
insilmaril@427
  1337
	{
insilmaril@427
  1338
		if (xelection.isEmpty() )
insilmaril@427
  1339
		{
insilmaril@432
  1340
			parser.setError (Aborted,"Nothing selected");
insilmaril@427
  1341
		} else if (! selb )
insilmaril@427
  1342
		{				  
insilmaril@432
  1343
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1344
		} else if (parser.checkParCount(0))
insilmaril@427
  1345
		{	
insilmaril@473
  1346
			if (!unscrollBranch (selb))	
insilmaril@432
  1347
				parser.setError (Aborted,"Could not unscroll branch");
insilmaril@427
  1348
		}	
insilmaril@514
  1349
	/////////////////////////////////////////////////////////////////////
insilmaril@473
  1350
	} else if (com=="unscrollChilds")
insilmaril@473
  1351
	{
insilmaril@473
  1352
		if (xelection.isEmpty() )
insilmaril@473
  1353
		{
insilmaril@473
  1354
			parser.setError (Aborted,"Nothing selected");
insilmaril@473
  1355
		} else if (! selb )
insilmaril@473
  1356
		{				  
insilmaril@473
  1357
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1358
		} else if (parser.checkParCount(0))
insilmaril@473
  1359
		{	
insilmaril@473
  1360
			unscrollChilds ();
insilmaril@473
  1361
		}	
insilmaril@514
  1362
	/////////////////////////////////////////////////////////////////////
insilmaril@427
  1363
	} else if (com=="unsetFlag")
insilmaril@366
  1364
	{
insilmaril@424
  1365
		if (xelection.isEmpty() )
insilmaril@366
  1366
		{
insilmaril@432
  1367
			parser.setError (Aborted,"Nothing selected");
insilmaril@424
  1368
		} else if (! selb )
insilmaril@394
  1369
		{				  
insilmaril@432
  1370
			parser.setError (Aborted,"Type of selection is not a branch");
insilmaril@514
  1371
		} else if (parser.checkParCount(1))
insilmaril@394
  1372
		{
insilmaril@432
  1373
			s=parser.parString(ok,0);
insilmaril@394
  1374
			if (ok) 
insilmaril@394
  1375
			{
insilmaril@424
  1376
				selb->deactivateStandardFlag(s);
insilmaril@424
  1377
				selb->updateFlagsToolbar();
insilmaril@366
  1378
			}	
insilmaril@366
  1379
		}
insilmaril@398
  1380
	} else
insilmaril@432
  1381
		parser.setError (Aborted,"Unknown command");
insilmaril@129
  1382
insilmaril@129
  1383
	// Any errors?
insilmaril@432
  1384
	if (parser.errorLevel()==NoError)
insilmaril@432
  1385
	{
insilmaril@394
  1386
		setChanged();
insilmaril@432
  1387
		mapCenter->reposition();
insilmaril@432
  1388
	}	
insilmaril@394
  1389
	else	
insilmaril@106
  1390
	{
insilmaril@366
  1391
		// TODO Error handling
insilmaril@366
  1392
		qWarning("MapEditor::parseAtom: Error!");
insilmaril@432
  1393
		qWarning(parser.errorMessage());
insilmaril@394
  1394
	} 
insilmaril@0
  1395
}
insilmaril@0
  1396
insilmaril@432
  1397
void MapEditor::runScript (QString script)
insilmaril@432
  1398
{
insilmaril@445
  1399
	parser.setScript (script);
insilmaril@445
  1400
	parser.runScript();
insilmaril@447
  1401
	while (parser.next() ) 
insilmaril@447
  1402
		parseAtom(parser.getAtom());
insilmaril@432
  1403
}
insilmaril@0
  1404
insilmaril@0
  1405
bool MapEditor::isDefault()
insilmaril@0
  1406
{
insilmaril@0
  1407
    return mapDefault;
insilmaril@0
  1408
}
insilmaril@0
  1409
insilmaril@0
  1410
bool MapEditor::hasChanged()
insilmaril@0
  1411
{
insilmaril@0
  1412
    return mapChanged;
insilmaril@0
  1413
}
insilmaril@0
  1414
insilmaril@0
  1415
void MapEditor::setChanged()
insilmaril@0
  1416
{
insilmaril@473
  1417
	if (!mapChanged)
insilmaril@473
  1418
		autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
insilmaril@0
  1419
	mapChanged=true;
insilmaril@0
  1420
	mapDefault=false;
insilmaril@0
  1421
	mapUnsaved=true;
insilmaril@0
  1422
	findReset();
insilmaril@473
  1423
insilmaril@0
  1424
}
insilmaril@0
  1425
insilmaril@0
  1426
void MapEditor::closeMap()
insilmaril@0
  1427
{
insilmaril@0
  1428
	// Unselect before disabling the toolbar actions
insilmaril@424
  1429
	if (!xelection.isEmpty() ) xelection.unselect();
insilmaril@424
  1430
	xelection.clear();
insilmaril@0
  1431
	updateActions();
insilmaril@0
  1432
insilmaril@0
  1433
    clear();
insilmaril@0
  1434
	close();
insilmaril@0
  1435
}
insilmaril@0
  1436
insilmaril@486
  1437
void MapEditor::setFilePath(QString fpath, QString destname)
insilmaril@0
  1438
{
insilmaril@486
  1439
	if (fpath.isEmpty() || fpath=="")
insilmaril@106
  1440
	{
insilmaril@106
  1441
		filePath="";
insilmaril@106
  1442
		fileName="";
insilmaril@106
  1443
		destPath="";
insilmaril@106
  1444
	} else
insilmaril@106
  1445
	{
insilmaril@486
  1446
		filePath=fpath;		// becomes absolute path
insilmaril@486
  1447
		fileName=fpath;		// gets stripped of path
insilmaril@106
  1448
		destPath=destname;	// needed for vymlinks
insilmaril@106
  1449
insilmaril@486
  1450
		// If fpath is not an absolute path, complete it
insilmaril@486
  1451
		filePath=QDir(fpath).absPath();
insilmaril@106
  1452
		fileDir=filePath.left (1+filePath.findRev ("/"));
insilmaril@106
  1453
insilmaril@106
  1454
		// Set short name, too. Search from behind:
insilmaril@106
  1455
		int i=fileName.findRev("/");
insilmaril@106
  1456
		if (i>=0) fileName=fileName.remove (0,i+1);
insilmaril@106
  1457
insilmaril@106
  1458
		// Forget the .vym (or .xml) for name of map
insilmaril@106
  1459
		mapName=fileName.left(fileName.findRev(".",-1,true) );
insilmaril@106
  1460
	}
insilmaril@0
  1461
}
insilmaril@0
  1462
insilmaril@486
  1463
void MapEditor::setFilePath(QString fpath)
insilmaril@486
  1464
{
insilmaril@486
  1465
	setFilePath (fpath,fpath);
insilmaril@486
  1466
}
insilmaril@486
  1467
insilmaril@0
  1468
QString MapEditor::getFilePath()
insilmaril@0
  1469
{
insilmaril@0
  1470
	return filePath;
insilmaril@0
  1471
}
insilmaril@0
  1472
insilmaril@0
  1473
QString MapEditor::getFileName()
insilmaril@0
  1474
{
insilmaril@0
  1475
	return fileName;
insilmaril@0
  1476
}
insilmaril@0
  1477
insilmaril@0
  1478
QString MapEditor::getMapName()
insilmaril@0
  1479
{
insilmaril@0
  1480
	return mapName;
insilmaril@0
  1481
}
insilmaril@0
  1482
insilmaril@0
  1483
QString MapEditor::getDestPath()
insilmaril@0
  1484
{
insilmaril@0
  1485
	return destPath;
insilmaril@0
  1486
}
insilmaril@0
  1487
insilmaril@205
  1488
ErrorCode MapEditor::load (QString fname, LoadMode lmode)
insilmaril@0
  1489
{
insilmaril@205
  1490
	ErrorCode err=success;
insilmaril@0
  1491
insilmaril@0
  1492
	if (lmode==NewMap)
insilmaril@0
  1493
	{
insilmaril@424
  1494
		if (xelection.isEmpty() ) xelection.unselect();
insilmaril@424
  1495
		xelection.clear();
insilmaril@0
  1496
		mapCenter->clear();
insilmaril@0
  1497
		mapCenter->setMapEditor(this);
insilmaril@0
  1498
		// (map state is set later at end of load...)
insilmaril@0
  1499
	} else
insilmaril@0
  1500
	{
insilmaril@424
  1501
		BranchObj *bo=xelection.getBranch();
insilmaril@424
  1502
		if (!bo) return aborted;
insilmaril@395
  1503
		if (lmode==ImportAdd)
insilmaril@395
  1504
			saveStateChangingPart(
insilmaril@424
  1505
				bo,
insilmaril@424
  1506
				bo,
insilmaril@395
  1507
				QString("addMapInsert (%1)").arg(fname),
insilmaril@395
  1508
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@395
  1509
		else	
insilmaril@395
  1510
			saveStateChangingPart(
insilmaril@424
  1511
				bo,
insilmaril@424
  1512
				bo,
insilmaril@395
  1513
				QString("addMapReplace(%1)").arg(fname),
insilmaril@395
  1514
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@0
  1515
	}	
insilmaril@0
  1516
	
insilmaril@0
  1517
    
insilmaril@564
  1518
    parseVYMHandler handler;
insilmaril@0
  1519
	QFile file( fname );
insilmaril@0
  1520
insilmaril@0
  1521
	// I am paranoid: file should exist anyway
insilmaril@0
  1522
	// according to check in mainwindow.
insilmaril@0
  1523
	if (!file.exists() )
insilmaril@0
  1524
	{
insilmaril@0
  1525
		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
  1526
				   tr("Couldn't open map " +fname)+".");
insilmaril@205
  1527
		err=aborted;	
insilmaril@0
  1528
	} else
insilmaril@0
  1529
	{
insilmaril@473
  1530
		bool blockSaveStateOrg=blockSaveState;
insilmaril@139
  1531
		blockReposition=true;
insilmaril@473
  1532
		blockSaveState=true;
insilmaril@0
  1533
		QXmlInputSource source( file);
insilmaril@0
  1534
		QXmlSimpleReader reader;
insilmaril@0
  1535
		reader.setContentHandler( &handler );
insilmaril@0
  1536
		reader.setErrorHandler( &handler );
insilmaril@0
  1537
		handler.setMapEditor( this );
insilmaril@494
  1538
insilmaril@494
  1539
insilmaril@494
  1540
		// We need to set the tmpDir in order  to load files with rel. path
insilmaril@494
  1541
		QString tmpdir= fname.left(fname.findRev("/",-1));	
insilmaril@494
  1542
		handler.setTmpDir (tmpdir);
insilmaril@243
  1543
		handler.setInputFile (file.name());
insilmaril@0
  1544
		handler.setLoadMode (lmode);
insilmaril@0
  1545
		bool ok = reader.parse( source );
insilmaril@139
  1546
		blockReposition=false;
insilmaril@473
  1547
		blockSaveState=blockSaveStateOrg;
insilmaril@0
  1548
		file.close();
insilmaril@0
  1549
		if ( ok ) 
insilmaril@0
  1550
		{
insilmaril@0
  1551
			mapCenter->reposition();
insilmaril@442
  1552
			xelection.update();
insilmaril@0
  1553
			if (lmode==NewMap)
insilmaril@0
  1554
			{
insilmaril@0
  1555
				mapDefault=false;
insilmaril@0
  1556
				mapChanged=false;
insilmaril@0
  1557
				mapUnsaved=false;
insilmaril@473
  1558
				autosaveTimer->stop();
insilmaril@0
  1559
			}
insilmaril@0
  1560
		} else 
insilmaril@0
  1561
		{
insilmaril@0
  1562
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
  1563
					   tr( handler.errorProtocol() ) );
insilmaril@0
  1564
			// returnCode=1;	
insilmaril@0
  1565
			// Still return "success": the map maybe at least
insilmaril@0
  1566
			// partially read by the parser
insilmaril@0
  1567
		}	
insilmaril@0
  1568
	}	
insilmaril@0
  1569
	updateActions();
insilmaril@205
  1570
	return err;
insilmaril@0
  1571
}
insilmaril@0
  1572
insilmaril@0
  1573
int MapEditor::save (const SaveMode &savemode)
insilmaril@0
  1574
{
insilmaril@0
  1575
	// Create mapName and fileDir
insilmaril@0
  1576
	makeSubDirs (fileDir);
insilmaril@0
  1577
	QString fname;
insilmaril@0
  1578
	if (saveZipped())
insilmaril@0
  1579
		// save as .xml
insilmaril@0
  1580
		fname=mapName+".xml";
insilmaril@0
  1581
	else
insilmaril@0
  1582
		// use name given by user, even if he chooses .doc
insilmaril@0
  1583
		fname=fileName;
insilmaril@0
  1584
insilmaril@0
  1585
insilmaril@0
  1586
	QString saveFile;
insilmaril@424
  1587
	if (savemode==CompleteMap || xelection.isEmpty())
insilmaril@408
  1588
		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
insilmaril@106
  1589
	else	
insilmaril@491
  1590
	{
insilmaril@491
  1591
		// TODO take care of multiselections
insilmaril@491
  1592
		if (xelection.type()==Selection::FloatImage)
insilmaril@491
  1593
			saveFloatImage();
insilmaril@491
  1594
		else	
insilmaril@491
  1595
			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
insilmaril@531
  1596
		return 0;	
insilmaril@491
  1597
	}	
insilmaril@0
  1598
insilmaril@163
  1599
	if (!saveStringToDisk(fileDir+fname,saveFile))
insilmaril@0
  1600
		return 1;
insilmaril@0
  1601
insilmaril@531
  1602
	mapChanged=false;
insilmaril@531
  1603
	mapUnsaved=false;
insilmaril@531
  1604
	autosaveTimer->stop();
insilmaril@531
  1605
	updateActions();
insilmaril@531
  1606
	return 0;
insilmaril@0
  1607
}
insilmaril@0
  1608
insilmaril@0
  1609
void MapEditor::setZipped (bool z)
insilmaril@0
  1610
{
insilmaril@0
  1611
	zipped=z;
insilmaril@0
  1612
}
insilmaril@0
  1613
insilmaril@0
  1614
bool MapEditor::saveZipped ()
insilmaril@0
  1615
{
insilmaril@0
  1616
	return zipped;
insilmaril@0
  1617
}
insilmaril@0
  1618
insilmaril@0
  1619
void MapEditor::print()
insilmaril@0
  1620
{
insilmaril@0
  1621
	if ( !printer ) 
insilmaril@0
  1622
	{
insilmaril@0
  1623
		printer = new QPrinter;
insilmaril@0
  1624
		printer->setColorMode (QPrinter::Color);
insilmaril@366
  1625
		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@412
  1626
		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
insilmaril@412
  1627
		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
insilmaril@0
  1628
	}
insilmaril@0
  1629
insilmaril@408
  1630
	QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@0
  1631
insilmaril@0
  1632
	// Try to set orientation automagically
insilmaril@0
  1633
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
  1634
	// there are problems with landscape mode, see
insilmaril@0
  1635
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
  1636
insilmaril@0
  1637
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
  1638
		// recommend landscape
insilmaril@0
  1639
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
  1640
	else	
insilmaril@0
  1641
		// recommend portrait
insilmaril@0
  1642
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
  1643
insilmaril@0
  1644
	if ( printer->setup(this) ) 
insilmaril@0
  1645
	// returns false, if printing is canceled
insilmaril@0
  1646
	{
insilmaril@0
  1647
		QPainter pp(printer);
insilmaril@0
  1648
insilmaril@412
  1649
		pp.setRenderHint(QPainter::Antialiasing,true);
insilmaril@412
  1650
insilmaril@0
  1651
		// Don't print the visualisation of selection
insilmaril@424
  1652
		xelection.unselect();
insilmaril@0
  1653
insilmaril@408
  1654
		QRectF mapRect=totalBBox;
insilmaril@411
  1655
		QGraphicsRectItem *frame=NULL;
insilmaril@412
  1656
insilmaril@417
  1657
		if (printFrame) 
insilmaril@0
  1658
		{
insilmaril@417
  1659
			// Print frame around map
insilmaril@417
  1660
			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@417
  1661
				totalBBox.width()+20, totalBBox.height()+20);
insilmaril@417
  1662
			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
insilmaril@417
  1663
			frame->setZValue(0);
insilmaril@417
  1664
			frame->show();    
insilmaril@417
  1665
		}		
insilmaril@417
  1666
insilmaril@417
  1667
insilmaril@412
  1668
		double paperAspect = (double)printer->width()   / (double)printer->height();
insilmaril@412
  1669
		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
insilmaril@417
  1670
		int viewBottom;
insilmaril@0
  1671
		if (mapAspect>=paperAspect)
insilmaril@0
  1672
		{
insilmaril@0
  1673
			// Fit horizontally to paper width
insilmaril@417
  1674
			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
insilmaril@417
  1675
			viewBottom=(int)(printer->width()/mapAspect);	
insilmaril@0
  1676
		}	else
insilmaril@0
  1677
		{
insilmaril@0
  1678
			// Fit vertically to paper height
insilmaril@417
  1679
			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
insilmaril@417
  1680
			viewBottom=printer->height();	
insilmaril@0
  1681
		}	
insilmaril@417
  1682
		
insilmaril@417
  1683
		if (printFooter) 
insilmaril@417
  1684
		{
insilmaril@417
  1685
			// Print footer below map
insilmaril@417
  1686
			QFont font;		
insilmaril@417
  1687
			font.setPointSize(10);
insilmaril@417
  1688
			pp.setFont (font);
insilmaril@417
  1689
			QRectF footerBox(0,viewBottom,printer->width(),15);
insilmaril@417
  1690
			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
insilmaril@417
  1691
			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
insilmaril@417
  1692
		}
insilmaril@412
  1693
		mapScene->render (
insilmaril@412
  1694
			&pp, 
insilmaril@412
  1695
			QRectF (0,0,printer->width(),printer->height()-15),
insilmaril@412
  1696
			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
insilmaril@412
  1697
		);
insilmaril@412
  1698
		
insilmaril@412
  1699
		// Viewport has paper dimension
insilmaril@412
  1700
		if (frame)  delete (frame);
insilmaril@0
  1701
insilmaril@0
  1702
		// Restore selection
insilmaril@424
  1703
		xelection.reselect();
insilmaril@119
  1704
insilmaril@119
  1705
		// Save settings in vymrc
insilmaril@366
  1706
		settings.writeEntry("/mainwindow/printerName",printer->printerName());
insilmaril@412
  1707
		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
insilmaril@412
  1708
		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
insilmaril@0
  1709
	}
insilmaril@0
  1710
}
insilmaril@0
  1711
insilmaril@408
  1712
void MapEditor::setAntiAlias (bool b)
insilmaril@408
  1713
{
insilmaril@408
  1714
	setRenderHint(QPainter::Antialiasing,b);
insilmaril@408
  1715
}
insilmaril@408
  1716
insilmaril@408
  1717
void MapEditor::setSmoothPixmap(bool b)
insilmaril@408
  1718
{
insilmaril@408
  1719
	setRenderHint(QPainter::SmoothPixmapTransform,b);
insilmaril@408
  1720
}
insilmaril@408
  1721
insilmaril@0
  1722
QPixmap MapEditor::getPixmap()
insilmaril@0
  1723
{
insilmaril@408
  1724
	QRectF mapRect=mapCenter->getTotalBBox();
insilmaril@564
  1725
	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
insilmaril@0
  1726
	QPainter pp (&pix);
insilmaril@420
  1727
	
insilmaril@420
  1728
	pp.setRenderHints(renderHints());
insilmaril@0
  1729
insilmaril@0
  1730
	// Don't print the visualisation of selection
insilmaril@424
  1731
	xelection.unselect();
insilmaril@0
  1732
insilmaril@420
  1733
	mapScene->render (	&pp, 
insilmaril@450
  1734
		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
insilmaril@420
  1735
		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
insilmaril@420
  1736
insilmaril@0
  1737
	// Restore selection
insilmaril@424
  1738
	xelection.reselect();
insilmaril@0
  1739
	
insilmaril@0
  1740
	return pix;
insilmaril@0
  1741
}
insilmaril@0
  1742
insilmaril@473
  1743
void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode)
insilmaril@260
  1744
{
insilmaril@260
  1745
	hidemode=mode;
insilmaril@260
  1746
	mapCenter->setHideTmp (hidemode);
insilmaril@260
  1747
	mapCenter->reposition();
insilmaril@408
  1748
	scene()->update();
insilmaril@260
  1749
}
insilmaril@260
  1750
insilmaril@473
  1751
BranchObj::HideTmpMode MapEditor::getHideTmpMode()
insilmaril@260
  1752
{
insilmaril@260
  1753
	return hidemode;
insilmaril@260
  1754
}
insilmaril@260
  1755
insilmaril@260
  1756
void MapEditor::setExportMode (bool b)
insilmaril@260
  1757
{
insilmaril@260
  1758
	// should be called before and after exports
insilmaril@260
  1759
	// depending on the settings
insilmaril@366
  1760
	if (b && settings.value("/export/useHideExport","yes")=="yes")
insilmaril@473
  1761
		setHideTmpMode (BranchObj::HideExport);
insilmaril@260
  1762
	else	
insilmaril@473
  1763
		setHideTmpMode (BranchObj::HideNone);
insilmaril@0
  1764
}
insilmaril@0
  1765
insilmaril@514
  1766
void MapEditor::exportASCII(QString fname,bool askName)
insilmaril@0
  1767
{
insilmaril@514
  1768
	ExportASCII ex;
insilmaril@514
  1769
	ex.setMapCenter(mapCenter);
insilmaril@514
  1770
	if (fname=="") 
insilmaril@514
  1771
		ex.setFile (mapName+".txt");	
insilmaril@514
  1772
	else
insilmaril@514
  1773
		ex.setFile (fname);
insilmaril@514
  1774
insilmaril@514
  1775
	if (askName)
insilmaril@514
  1776
	{
insilmaril@514
  1777
		//ex.addFilter ("TXT (*.txt)");
insilmaril@514
  1778
		ex.setDir(lastImageDir);
insilmaril@514
  1779
		//ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
insilmaril@514
  1780
		ex.execDialog() ; 
insilmaril@514
  1781
	} 
insilmaril@514
  1782
	if (!ex.canceled())
insilmaril@514
  1783
	{
insilmaril@514
  1784
		setExportMode(true);
insilmaril@514
  1785
		ex.doExport();
insilmaril@514
  1786
		setExportMode(false);
insilmaril@514
  1787
	}
insilmaril@514
  1788
}
insilmaril@514
  1789
insilmaril@514
  1790
void MapEditor::exportImage(QString fname, bool askName, QString format)
insilmaril@514
  1791
{
insilmaril@514
  1792
	if (fname=="")
insilmaril@514
  1793
	{
insilmaril@514
  1794
		fname=mapName+".png";
insilmaril@514
  1795
		format="PNG";
insilmaril@514
  1796
	} 	
insilmaril@514
  1797
insilmaril@514
  1798
	if (askName)
insilmaril@514
  1799
	{
insilmaril@514
  1800
		QStringList fl;
insilmaril@514
  1801
		QFileDialog *fd=new QFileDialog (this);
insilmaril@514
  1802
		fd->setCaption (tr("Export map as image"));
insilmaril@514
  1803
		fd->setDirectory (lastImageDir);
insilmaril@514
  1804
		fd->setFileMode(QFileDialog::AnyFile);
insilmaril@514
  1805
		fd->setFilters  (imageIO.getFilters() );
insilmaril@514
  1806
		if (fd->exec())
insilmaril@514
  1807
		{
insilmaril@514
  1808
			fl=fd->selectedFiles();
insilmaril@514
  1809
			fname=fl.first();
insilmaril@514
  1810
			format=imageIO.getType(fd->selectedFilter());
insilmaril@514
  1811
		} 
insilmaril@514
  1812
	}
insilmaril@514
  1813
insilmaril@260
  1814
	setExportMode (true);
insilmaril@0
  1815
	QPixmap pix (getPixmap());
insilmaril@514
  1816
	pix.save(fname, format);
insilmaril@260
  1817
	setExportMode (false);
insilmaril@0
  1818
}
insilmaril@0
  1819
insilmaril@185
  1820
void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
insilmaril@163
  1821
{
insilmaril@185
  1822
	ExportOO ex;
insilmaril@199
  1823
	ex.setFile (fn);
insilmaril@185
  1824
	ex.setMapCenter(mapCenter);
insilmaril@260
  1825
	if (ex.setConfigFile(cf)) 
insilmaril@260
  1826
	{
insilmaril@260
  1827
		setExportMode (true);
insilmaril@260
  1828
		ex.exportPresentation();
insilmaril@260
  1829
		setExportMode (false);
insilmaril@260
  1830
	}
insilmaril@163
  1831
}
insilmaril@163
  1832
insilmaril@520
  1833
void MapEditor::exportXHTML (const QString &dir, bool askForName)
insilmaril@517
  1834
{
insilmaril@517
  1835
			ExportXHTMLDialog dia(this);
insilmaril@517
  1836
			dia.setFilePath (filePath );
insilmaril@517
  1837
			dia.setMapName (mapName );
insilmaril@517
  1838
			dia.readSettings();
insilmaril@526
  1839
			if (dir!="") dia.setDir (dir);
insilmaril@517
  1840
insilmaril@517
  1841
			bool ok=true;
insilmaril@517
  1842
			
insilmaril@520
  1843
			if (askForName)
insilmaril@517
  1844
			{
insilmaril@517
  1845
				if (dia.exec()!=QDialog::Accepted) 
insilmaril@517
  1846
					ok=false;
insilmaril@517
  1847
				else	
insilmaril@517
  1848
				{
insilmaril@517
  1849
					QDir d (dia.getDir());
insilmaril@517
  1850
					// Check, if warnings should be used before overwriting
insilmaril@517
  1851
					// the output directory
insilmaril@517
  1852
					if (d.exists() && d.count()>0)
insilmaril@517
  1853
					{
insilmaril@517
  1854
						WarningDialog warn;
insilmaril@517
  1855
						warn.showCancelButton (true);
insilmaril@517
  1856
						warn.setText(QString(
insilmaril@517
  1857
							"The directory %1 is not empty.\n"
insilmaril@517
  1858
							"Do you risk to overwrite some of its contents?").arg(d.path() ));
insilmaril@517
  1859
						warn.setCaption("Warning: Directory not empty");
insilmaril@517
  1860
						warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
insilmaril@517
  1861
insilmaril@517
  1862
						if (warn.exec()!=QDialog::Accepted) ok=false;
insilmaril@517
  1863
					}
insilmaril@517
  1864
				}	
insilmaril@517
  1865
			}
insilmaril@517
  1866
insilmaril@517
  1867
			if (ok)
insilmaril@517
  1868
			{
insilmaril@526
  1869
				exportXML (dia.getDir(),false );
insilmaril@517
  1870
				dia.doExport(mapName );
insilmaril@517
  1871
				//if (dia.hasChanged()) setChanged();
insilmaril@517
  1872
			}
insilmaril@517
  1873
}
insilmaril@0
  1874
insilmaril@526
  1875
void MapEditor::exportXML(QString dir, bool askForName)
insilmaril@0
  1876
{
insilmaril@526
  1877
	if (askForName)
insilmaril@526
  1878
	{
insilmaril@526
  1879
		dir=browseDirectory(this,tr("Export XML to directory"));
insilmaril@526
  1880
		if (dir =="" && !reallyWriteDirectory(dir) )
insilmaril@526
  1881
		return;
insilmaril@526
  1882
	}
insilmaril@526
  1883
insilmaril@260
  1884
	// Hide stuff during export, if settings want this
insilmaril@260
  1885
	setExportMode (true);
insilmaril@260
  1886
insilmaril@0
  1887
	// Create subdirectories
insilmaril@0
  1888
	makeSubDirs (dir);
insilmaril@0
  1889
insilmaril@0
  1890
	// write to directory
insilmaril@106
  1891
	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
insilmaril@0
  1892
	QFile file;
insilmaril@0
  1893
insilmaril@0
  1894
	file.setName ( dir + "/"+mapName+".xml");
insilmaril@366
  1895
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
  1896
	{
insilmaril@0
  1897
		// This should neverever happen
insilmaril@159
  1898
		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
insilmaril@0
  1899
		return;
insilmaril@0
  1900
	}	
insilmaril@0
  1901
insilmaril@0
  1902
	// Write it finally, and write in UTF8, no matter what 
insilmaril@0
  1903
	QTextStream ts( &file );
insilmaril@0
  1904
	ts.setEncoding (QTextStream::UnicodeUTF8);
insilmaril@0
  1905
	ts << saveFile;
insilmaril@0
  1906
	file.close();
insilmaril@0
  1907
insilmaril@0
  1908
	// Now write image, too
insilmaril@517
  1909
	exportImage (dir+"/images/"+mapName+".png",false,"PNG");
insilmaril@260
  1910
insilmaril@260
  1911
	setExportMode (false);
insilmaril@0
  1912
}
insilmaril@0
  1913
insilmaril@0
  1914
void MapEditor::clear()
insilmaril@0
  1915
{
insilmaril@424
  1916
	xelection.unselect();
insilmaril@0
  1917
	mapCenter->clear();
insilmaril@0
  1918
}
insilmaril@0
  1919
insilmaril@0
  1920
void MapEditor::copy()
insilmaril@0
  1921
{
insilmaril@424
  1922
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  1923
	if (sel)
insilmaril@0
  1924
	{
insilmaril@502
  1925
		if (redosAvail == 0)
insilmaril@0
  1926
		{
insilmaril@502
  1927
			// Copy to history
insilmaril@502
  1928
			QString s=sel->getSelectString();
insilmaril@505
  1929
			saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel  );
insilmaril@502
  1930
			curClipboard=curStep;
insilmaril@502
  1931
		}
insilmaril@502
  1932
insilmaril@502
  1933
		// Copy also to global clipboard, because we are at last step in history
insilmaril@502
  1934
		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
insilmaril@502
  1935
		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
insilmaril@502
  1936
		copyDir (bakMapDir,clipboardDir );
insilmaril@166
  1937
insilmaril@166
  1938
		clipboardEmpty=false;
insilmaril@166
  1939
		updateActions();
insilmaril@0
  1940
	}	    
insilmaril@0
  1941
}
insilmaril@0
  1942
insilmaril@163
  1943
void MapEditor::redo()
insilmaril@163
  1944
{
insilmaril@381
  1945
	// Can we undo at all?
insilmaril@381
  1946
	if (redosAvail<1) return;
insilmaril@473
  1947
insilmaril@473
  1948
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  1949
	blockSaveState=true;
insilmaril@473
  1950
	
insilmaril@381
  1951
	redosAvail--;
insilmaril@381
  1952
insilmaril@381
  1953
	if (undosAvail<stepsTotal) undosAvail++;
insilmaril@366
  1954
	curStep++;
insilmaril@381
  1955
	if (curStep>stepsTotal) curStep=1;
insilmaril@366
  1956
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  1957
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  1958
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  1959
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  1960
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  1961
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  1962
insilmaril@395
  1963
	if (!checkVersion(version))
insilmaril@395
  1964
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  1965
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@395
  1966
insilmaril@366
  1967
insilmaril@163
  1968
	// Find out current undo directory
insilmaril@366
  1969
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@366
  1970
insilmaril@473
  1971
	if (debug)
insilmaril@473
  1972
	{
insilmaril@473
  1973
		cout << "ME::redo() begin\n";
insilmaril@473
  1974
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  1975
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  1976
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  1977
		cout << "    ---------------------------"<<endl;
insilmaril@473
  1978
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  1979
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  1980
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  1981
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  1982
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  1983
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  1984
	}
insilmaril@163
  1985
insilmaril@163
  1986
	// select  object before redo
insilmaril@163
  1987
	if (!redoSelection.isEmpty())
insilmaril@163
  1988
		select (redoSelection);
insilmaril@163
  1989
insilmaril@366
  1990
insilmaril@366
  1991
	parseAtom (redoCommand);
insilmaril@366
  1992
	mapCenter->reposition();
insilmaril@366
  1993
insilmaril@473
  1994
	blockSaveState=blockSaveStateOrg;
insilmaril@366
  1995
insilmaril@366
  1996
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  1997
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  1998
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  1999
	undoSet.writeSettings(histPath);
insilmaril@366
  2000
insilmaril@408
  2001
	mainWindow->updateHistory (undoSet);
insilmaril@407
  2002
	updateActions();
insilmaril@366
  2003
insilmaril@366
  2004
	/* TODO remove testing
insilmaril@163
  2005
	cout << "ME::redo() end\n";
insilmaril@163
  2006
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2007
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2008
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2009
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2010
	*/
insilmaril@366
  2011
insilmaril@366
  2012
insilmaril@163
  2013
}
insilmaril@163
  2014
insilmaril@390
  2015
bool MapEditor::isRedoAvailable()
insilmaril@390
  2016
{
insilmaril@393
  2017
	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
insilmaril@390
  2018
		return true;
insilmaril@390
  2019
	else	
insilmaril@390
  2020
		return false;
insilmaril@390
  2021
}
insilmaril@390
  2022
insilmaril@106
  2023
void MapEditor::undo()
insilmaril@106
  2024
{
insilmaril@381
  2025
	// Can we undo at all?
insilmaril@381
  2026
	if (undosAvail<1) return;
insilmaril@381
  2027
insilmaril@502
  2028
	mainWindow->statusMessage (tr("Autosave disabled during undo."));
insilmaril@502
  2029
insilmaril@473
  2030
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  2031
	blockSaveState=true;
insilmaril@473
  2032
	
insilmaril@366
  2033
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  2034
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  2035
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  2036
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  2037
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  2038
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  2039
insilmaril@395
  2040
	if (!checkVersion(version))
insilmaril@395
  2041
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  2042
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@366
  2043
insilmaril@163
  2044
	// Find out current undo directory
insilmaril@366
  2045
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@163
  2046
insilmaril@136
  2047
	// select  object before undo
insilmaril@136
  2048
	if (!undoSelection.isEmpty())
insilmaril@136
  2049
		select (undoSelection);
insilmaril@136
  2050
insilmaril@473
  2051
	if (debug)
insilmaril@473
  2052
	{
insilmaril@473
  2053
		cout << "ME::undo() begin\n";
insilmaril@473
  2054
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  2055
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  2056
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  2057
		cout << "    ---------------------------"<<endl;
insilmaril@473
  2058
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  2059
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  2060
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  2061
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  2062
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  2063
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  2064
	}	
insilmaril@106
  2065
	parseAtom (undoCommand);
insilmaril@106
  2066
	mapCenter->reposition();
insilmaril@106
  2067
insilmaril@163
  2068
	undosAvail--;
insilmaril@366
  2069
	curStep--; 
insilmaril@381
  2070
	if (curStep<1) curStep=stepsTotal;
insilmaril@366
  2071
insilmaril@366
  2072
	redosAvail++;
insilmaril@163
  2073
insilmaril@473
  2074
	blockSaveState=blockSaveStateOrg;
insilmaril@163
  2075
/* TODO remove testing
insilmaril@163
  2076
	cout << "ME::undo() end\n";
insilmaril@163
  2077
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2078
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2079
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2080
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2081
*/
insilmaril@366
  2082
insilmaril@366
  2083
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  2084
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  2085
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  2086
	undoSet.writeSettings(histPath);
insilmaril@366
  2087
insilmaril@404
  2088
	mainWindow->updateHistory (undoSet);
insilmaril@366
  2089
	updateActions();
insilmaril@442
  2090
	xelection.update();
insilmaril@420
  2091
	ensureSelectionVisible();
insilmaril@106
  2092
}
insilmaril@106
  2093
insilmaril@390
  2094
bool MapEditor::isUndoAvailable()
insilmaril@390
  2095
{
insilmaril@390
  2096
	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
insilmaril@390
  2097
		return true;
insilmaril@390
  2098
	else	
insilmaril@390
  2099
		return false;
insilmaril@390
  2100
}
insilmaril@390
  2101
insilmaril@404
  2102
void MapEditor::gotoHistoryStep (int i)
insilmaril@381
  2103
{
insilmaril@381
  2104
	// Restore variables
insilmaril@381
  2105
	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
insilmaril@388
  2106
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@388
  2107
insilmaril@388
  2108
	if (i<0) i=undosAvail+redosAvail;
insilmaril@388
  2109
insilmaril@388
  2110
	// Clicking above current step makes us undo things
insilmaril@381
  2111
	if (i<undosAvail) 
insilmaril@381
  2112
	{	
insilmaril@381
  2113
		for (int j=0; j<undosAvail-i; j++) undo();
insilmaril@381
  2114
		return;
insilmaril@381
  2115
	}	
insilmaril@388
  2116
	// Clicking below current step makes us redo things
insilmaril@381
  2117
	if (i>undosAvail) 
insilmaril@491
  2118
		for (int j=undosAvail; j<i; j++) 
insilmaril@491
  2119
		{
insilmaril@491
  2120
		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
insilmaril@491
  2121
		redo();
insilmaril@491
  2122
		}
insilmaril@381
  2123
insilmaril@381
  2124
	// And ignore clicking the current row ;-)	
insilmaril@381
  2125
}
insilmaril@381
  2126
insilmaril@394
  2127
void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
insilmaril@106
  2128
{
insilmaril@393
  2129
	QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2130
	QDir d(pathDir);
insilmaril@393
  2131
	QFile file (path);
insilmaril@163
  2132
insilmaril@106
  2133
	if (d.exists() )
insilmaril@106
  2134
	{
insilmaril@106
  2135
		// We need to parse saved XML data
insilmaril@564
  2136
		parseVYMHandler handler;
insilmaril@163
  2137
		QXmlInputSource source( file);
insilmaril@106
  2138
		QXmlSimpleReader reader;
insilmaril@106
  2139
		reader.setContentHandler( &handler );
insilmaril@106
  2140
		reader.setErrorHandler( &handler );
insilmaril@106
  2141
		handler.setMapEditor( this );
insilmaril@393
  2142
		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@106
  2143
		if (undoSel.isEmpty())
insilmaril@106
  2144
		{
insilmaril@139
  2145
			unselect();
insilmaril@106
  2146
			mapCenter->clear();
insilmaril@106
  2147
			handler.setLoadMode (NewMap);
insilmaril@106
  2148
		} else	
insilmaril@106
  2149
		{
insilmaril@106
  2150
			select (undoSel);
insilmaril@106
  2151
			handler.setLoadMode (ImportReplace);
insilmaril@106
  2152
		}	
insilmaril@139
  2153
		blockReposition=true;
insilmaril@106
  2154
		bool ok = reader.parse( source );
insilmaril@139
  2155
		blockReposition=false;
insilmaril@106
  2156
		if (! ok ) 
insilmaril@106
  2157
		{	
insilmaril@106
  2158
			// This should never ever happen
insilmaril@393
  2159
			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2160
								    handler.errorProtocol());
insilmaril@106
  2161
		}
insilmaril@106
  2162
	} else	
insilmaril@393
  2163
		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2164
}
insilmaril@393
  2165
insilmaril@394
  2166
void MapEditor::addMapInsertInt (const QString &path, int pos)
insilmaril@393
  2167
{
insilmaril@424
  2168
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2169
	if (sel);
insilmaril@106
  2170
	{
insilmaril@393
  2171
		QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2172
		QDir d(pathDir);
insilmaril@393
  2173
		QFile file (path);
insilmaril@393
  2174
insilmaril@393
  2175
		if (d.exists() )
insilmaril@393
  2176
		{
insilmaril@393
  2177
			// We need to parse saved XML data
insilmaril@564
  2178
			parseVYMHandler handler;
insilmaril@393
  2179
			QXmlInputSource source( file);
insilmaril@393
  2180
			QXmlSimpleReader reader;
insilmaril@393
  2181
			reader.setContentHandler( &handler );
insilmaril@393
  2182
			reader.setErrorHandler( &handler );
insilmaril@393
  2183
			handler.setMapEditor( this );
insilmaril@393
  2184
			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@394
  2185
			handler.setLoadMode (ImportAdd);
insilmaril@393
  2186
			blockReposition=true;
insilmaril@393
  2187
			bool ok = reader.parse( source );
insilmaril@393
  2188
			blockReposition=false;
insilmaril@393
  2189
			if (! ok ) 
insilmaril@393
  2190
			{	
insilmaril@393
  2191
				// This should never ever happen
insilmaril@393
  2192
				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2193
										handler.errorProtocol());
insilmaril@393
  2194
			}
insilmaril@424
  2195
			if (sel!=mapCenter)
insilmaril@424
  2196
				sel->getLastBranch()->linkTo (sel,pos);
insilmaril@393
  2197
		} else	
insilmaril@393
  2198
			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2199
	}		
insilmaril@106
  2200
}
insilmaril@106
  2201
insilmaril@502
  2202
void MapEditor::pasteNoSave(const int &n)
insilmaril@0
  2203
{
insilmaril@491
  2204
	bool old=blockSaveState;
insilmaril@491
  2205
	blockSaveState=true;
insilmaril@502
  2206
	if (redosAvail > 0 || n!=0)
insilmaril@502
  2207
	{
insilmaril@502
  2208
		// Use the "historical" buffer
insilmaril@502
  2209
		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
insilmaril@502
  2210
		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
insilmaril@502
  2211
		load (bakMapDir+"/"+clipboardFile,ImportAdd);
insilmaril@502
  2212
	} else
insilmaril@502
  2213
		// Use the global buffer
insilmaril@502
  2214
		load (clipboardDir+"/"+clipboardFile,ImportAdd);
insilmaril@491
  2215
	blockSaveState=old;
insilmaril@0
  2216
}
insilmaril@0
  2217
insilmaril@497
  2218
void MapEditor::paste()		
insilmaril@0
  2219
{   
insilmaril@424
  2220
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2221
	if (sel)
insilmaril@166
  2222
	{
insilmaril@395
  2223
		saveStateChangingPart(
insilmaril@424
  2224
			sel,
insilmaril@424
  2225
			sel,
insilmaril@502
  2226
			QString ("paste (%1)").arg(curClipboard),
insilmaril@424
  2227
			QString("Paste to %1").arg( getName(sel))
insilmaril@395
  2228
		);
insilmaril@502
  2229
		pasteNoSave(0);
insilmaril@166
  2230
		mapCenter->reposition();
insilmaril@166
  2231
	}
insilmaril@0
  2232
}
insilmaril@0
  2233
insilmaril@0
  2234
void MapEditor::cut()
insilmaril@0
  2235
{
insilmaril@424
  2236
	LinkableMapObj *sel=xelection.single();
insilmaril@491
  2237
	if ( sel && (xelection.type() == Selection::Branch ||
insilmaril@491
  2238
		xelection.type()==Selection::MapCenter ||
insilmaril@491
  2239
		xelection.type()==Selection::FloatImage))
insilmaril@424
  2240
	{
insilmaril@491
  2241
	/* No savestate! savestate is called in cutNoSave
insilmaril@424
  2242
		saveStateChangingPart(
insilmaril@424
  2243
			sel->getParObj(),
insilmaril@424
  2244
			sel,
insilmaril@424
  2245
			"cut ()",
insilmaril@424
  2246
			QString("Cut %1").arg(getName(sel ))
insilmaril@424
  2247
		);
insilmaril@491
  2248
	*/	
insilmaril@424
  2249
		copy();
insilmaril@491
  2250
		deleteSelection();
insilmaril@424
  2251
		mapCenter->reposition();
insilmaril@424
  2252
	}
insilmaril@0
  2253
}
insilmaril@0
  2254
insilmaril@537
  2255
void MapEditor::move(const double &x, const double &y)
insilmaril@130
  2256
{
insilmaril@424
  2257
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2258
	if (sel)
insilmaril@366
  2259
	{
insilmaril@424
  2260
		QString ps=qpointfToString (sel->getAbsPos());
insilmaril@424
  2261
		QString s=xelection.single()->getSelectString();
insilmaril@366
  2262
		saveState(
insilmaril@366
  2263
			s, "move "+ps, 
insilmaril@408
  2264
			s, "move "+qpointfToString (QPointF (x,y)), 
insilmaril@424
  2265
			QString("Move %1 to  %2").arg(getName(sel)).arg(ps));
insilmaril@473
  2266
		sel->move(x,y);
insilmaril@366
  2267
		mapCenter->reposition();
insilmaril@442
  2268
		xelection.update();
insilmaril@366
  2269
	}
insilmaril@366
  2270
insilmaril@366
  2271
}
insilmaril@366
  2272
insilmaril@537
  2273
void MapEditor::moveRel (const double &x, const double &y)
insilmaril@366
  2274
{
insilmaril@424
  2275
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2276
	if (sel)
insilmaril@366
  2277
	{
insilmaril@424
  2278
		QString ps=qpointfToString (sel->getRelPos());
insilmaril@424
  2279
		QString s=sel->getSelectString();
insilmaril@366
  2280
		saveState(
insilmaril@366
  2281
			s, "moveRel "+ps, 
insilmaril@408
  2282
			s, "moveRel "+qpointfToString (QPointF (x,y)), 
insilmaril@424
  2283
			QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
insilmaril@424
  2284
		((OrnamentedObj*)sel)->move2RelPos (x,y);
insilmaril@366
  2285
		mapCenter->reposition();
insilmaril@424
  2286
		sel->updateLink();
insilmaril@442
  2287
		xelection.update();
insilmaril@366
  2288
	}
insilmaril@130
  2289
}
insilmaril@130
  2290
insilmaril@0
  2291
void MapEditor::moveBranchUp()
insilmaril@0
  2292
{
insilmaril@424
  2293
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2294
	BranchObj* par;
insilmaril@424
  2295
	if (bo)
insilmaril@0
  2296
	{
insilmaril@314
  2297
		if (!bo->canMoveBranchUp()) return;
insilmaril@0
  2298
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2299
		BranchObj *obo=par->moveBranchUp (bo);	// bo will be the one below selection
insilmaril@473
  2300
		saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
insilmaril@0
  2301
		mapCenter->reposition();
insilmaril@420
  2302
		scene()->update();
insilmaril@442
  2303
		xelection.update();
insilmaril@0
  2304
		ensureSelectionVisible();
insilmaril@0
  2305
	}
insilmaril@0
  2306
}
insilmaril@0
  2307
insilmaril@0
  2308
void MapEditor::moveBranchDown()
insilmaril@0
  2309
{
insilmaril@424
  2310
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2311
	BranchObj* par;
insilmaril@424
  2312
	if (bo)
insilmaril@0
  2313
	{
insilmaril@314
  2314
		if (!bo->canMoveBranchDown()) return;
insilmaril@0
  2315
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2316
		BranchObj *obo=par->moveBranchDown(bo);	// bo will be the one above selection
insilmaril@473
  2317
		saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
insilmaril@0
  2318
		mapCenter->reposition();
insilmaril@420
  2319
		scene()->update();
insilmaril@442
  2320
		xelection.update();
insilmaril@0
  2321
		ensureSelectionVisible();
insilmaril@0
  2322
	}	
insilmaril@0
  2323
}
insilmaril@0
  2324
insilmaril@491
  2325
void MapEditor::linkTo(const QString &dstString)	
insilmaril@420
  2326
{
insilmaril@424
  2327
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2328
	if (fio)
insilmaril@424
  2329
	{
insilmaril@424
  2330
		BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
insilmaril@424
  2331
		if (dst && (typeid(*dst)==typeid (BranchObj) || 
insilmaril@424
  2332
					typeid(*dst)==typeid (MapCenterObj)))
insilmaril@424
  2333
		{			
insilmaril@424
  2334
			LinkableMapObj *dstPar=dst->getParObj();
insilmaril@424
  2335
			QString parString=dstPar->getSelectString();
insilmaril@420
  2336
			QString fioPreSelectString=fio->getSelectString();
insilmaril@420
  2337
			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
insilmaril@420
  2338
			((BranchObj*)(dst))->addFloatImage (fio);
insilmaril@424
  2339
			xelection.unselect();
insilmaril@420
  2340
			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
insilmaril@420
  2341
			fio=((BranchObj*)(dst))->getLastFloatImage();
insilmaril@420
  2342
			fio->setRelPos();
insilmaril@420
  2343
			fio->reposition();
insilmaril@424
  2344
			xelection.select(fio);
insilmaril@420
  2345
			saveState(
insilmaril@420
  2346
				fio->getSelectString(),
insilmaril@420
  2347
				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
insilmaril@420
  2348
				fioPreSelectString, 
insilmaril@420
  2349
				QString ("linkTo (\"%1\")").arg(dstString),
insilmaril@420
  2350
				QString ("Link floatimage to %1").arg(getName(dst)));
insilmaril@424
  2351
		}
insilmaril@420
  2352
	}
insilmaril@420
  2353
}
insilmaril@420
  2354
insilmaril@366
  2355
QString MapEditor::getHeading(bool &ok, QPoint &p)
insilmaril@0
  2356
{
insilmaril@424
  2357
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2358
	if (bo)
insilmaril@366
  2359
	{
insilmaril@366
  2360
		ok=true;
insilmaril@424
  2361
		p=mapFromScene(bo->getAbsPos());
insilmaril@424
  2362
		return bo->getHeading();
insilmaril@366
  2363
	}
insilmaril@366
  2364
	ok=false;
insilmaril@366
  2365
	return QString();
insilmaril@366
  2366
}
insilmaril@366
  2367
insilmaril@366
  2368
void MapEditor::setHeading(const QString &s)
insilmaril@366
  2369
{
insilmaril@424
  2370
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2371
	if (sel)
insilmaril@0
  2372
	{
insilmaril@395
  2373
		saveState(
insilmaril@424
  2374
			sel,
insilmaril@424
  2375
			"setHeading (\""+sel->getHeading()+"\")", 
insilmaril@424
  2376
			sel,
insilmaril@366
  2377
			"setHeading (\""+s+"\")", 
insilmaril@424
  2378
			QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
insilmaril@424
  2379
		sel->setHeading(s );
insilmaril@106
  2380
		mapCenter->reposition();
insilmaril@442
  2381
		xelection.update();
insilmaril@106
  2382
		ensureSelectionVisible();
insilmaril@106
  2383
	}
insilmaril@106
  2384
}
insilmaril@106
  2385
insilmaril@366
  2386
void MapEditor::setHeadingInt(const QString &s)
insilmaril@366
  2387
{
insilmaril@424
  2388
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2389
	if (bo)
insilmaril@366
  2390
	{
insilmaril@424
  2391
		bo->setHeading(s);
insilmaril@366
  2392
		mapCenter->reposition();
insilmaril@442
  2393
		xelection.update();
insilmaril@366
  2394
		ensureSelectionVisible();
insilmaril@366
  2395
	}
insilmaril@366
  2396
}
insilmaril@366
  2397
insilmaril@366
  2398
void MapEditor::setVymLinkInt (const QString &s)
insilmaril@143
  2399
{
insilmaril@143
  2400
	// Internal function, no saveState needed
insilmaril@424
  2401
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2402
	if (bo)
insilmaril@143
  2403
	{
insilmaril@424
  2404
		bo->setVymLink(s);
insilmaril@143
  2405
		mapCenter->reposition();
insilmaril@491
  2406
		updateActions();
insilmaril@442
  2407
		xelection.update();
insilmaril@143
  2408
		ensureSelectionVisible();
insilmaril@143
  2409
	}
insilmaril@143
  2410
}
insilmaril@143
  2411
insilmaril@366
  2412
BranchObj* MapEditor::addNewBranchInt(int num)
insilmaril@0
  2413
{
insilmaril@366
  2414
	// Depending on pos:
insilmaril@366
  2415
	// -3		insert in childs of parent  above selection 
insilmaril@366
  2416
	// -2		add branch to selection 
insilmaril@366
  2417
	// -1		insert in childs of parent below selection 
insilmaril@366
  2418
	// 0..n		insert in childs of parent at pos
insilmaril@366
  2419
	BranchObj *newbo=NULL;
insilmaril@424
  2420
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2421
	if (bo)
insilmaril@0
  2422
	{
insilmaril@366
  2423
		if (num==-2)
insilmaril@0
  2424
		{
insilmaril@0
  2425
			// save scroll state. If scrolled, automatically select
insilmaril@0
  2426
			// new branch in order to tmp unscroll parent...
insilmaril@537
  2427
			newbo=bo->addBranch();
insilmaril@366
  2428
			
insilmaril@366
  2429
		}else if (num==-1)
insilmaril@0
  2430
		{
insilmaril@366
  2431
			num=bo->getNum()+1;
insilmaril@366
  2432
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2433
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2434
		}else if (num==-3)
insilmaril@366
  2435
		{
insilmaril@366
  2436
			num=bo->getNum();
insilmaril@366
  2437
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2438
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2439
		}
insilmaril@537
  2440
		if (!newbo) return NULL;
insilmaril@366
  2441
	}	
insilmaril@366
  2442
	return newbo;
insilmaril@366
  2443
}	
insilmaril@366
  2444
insilmaril@394
  2445
BranchObj* MapEditor::addNewBranch(int pos)
insilmaril@366
  2446
{
insilmaril@366
  2447
	// Different meaning than num in addNewBranchInt!
insilmaril@366
  2448
	// -1	add above
insilmaril@366
  2449
	//  0	add as child
insilmaril@366
  2450
	// +1	add below
insilmaril@424
  2451
	BranchObj *bo = xelection.getBranch();
insilmaril@394
  2452
	BranchObj *newbo=NULL;
insilmaril@394
  2453
insilmaril@424
  2454
	if (bo)
insilmaril@366
  2455
	{
insilmaril@421
  2456
		setCursor (Qt::ArrowCursor);
insilmaril@421
  2457
insilmaril@366
  2458
		newbo=addNewBranchInt (pos-2);
insilmaril@366
  2459
insilmaril@366
  2460
		if (newbo)
insilmaril@366
  2461
		{
insilmaril@395
  2462
			saveState(
insilmaril@417
  2463
				newbo,		
insilmaril@393
  2464
				"delete ()",
insilmaril@424
  2465
				bo,
insilmaril@537
  2466
				QString ("addBranch (%1)").arg(pos),
insilmaril@395
  2467
				QString ("Add new branch to %1").arg(getName(bo)));	
insilmaril@366
  2468
insilmaril@366
  2469
			mapCenter->reposition();
insilmaril@537
  2470
			xelection.update();
insilmaril@537
  2471
			latestSelection=newbo->getSelectString();
insilmaril@531
  2472
			// In Network mode, the client needs to know where the new branch is,
insilmaril@531
  2473
			// so we have to pass on this information via saveState.
insilmaril@531
  2474
			// TODO: Get rid of this positioning workaround
insilmaril@531
  2475
			QString ps=qpointfToString (newbo->getAbsPos());
insilmaril@537
  2476
			sendData ("selectLatestAdded ()");
insilmaril@534
  2477
			sendData (QString("move %1").arg(ps));
insilmaril@534
  2478
			sendSelection();
insilmaril@366
  2479
		}
insilmaril@366
  2480
	}	
insilmaril@394
  2481
	return newbo;
insilmaril@366
  2482
}
insilmaril@366
  2483
insilmaril@366
  2484
insilmaril@394
  2485
BranchObj* MapEditor::addNewBranchBefore()
insilmaril@366
  2486
{
insilmaril@394
  2487
	BranchObj *newbo=NULL;
insilmaril@424
  2488
	BranchObj *bo = xelection.getBranch();
insilmaril@491
  2489
	if (bo && xelection.type()==Selection::Branch)
insilmaril@394
  2490
		 // We accept no MapCenterObj here, so we _have_ a parent
insilmaril@366
  2491
	{
insilmaril@408
  2492
		QPointF p=bo->getRelPos();
insilmaril@394
  2493
insilmaril@394
  2494
insilmaril@424
  2495
		BranchObj *parbo=(BranchObj*)(bo->getParObj());
insilmaril@394
  2496
insilmaril@394
  2497
		// add below selection
insilmaril@394
  2498
		newbo=parbo->insertBranch(bo->getNum()+1);
insilmaril@394
  2499
		if (newbo)
insilmaril@366
  2500
		{
insilmaril@394
  2501
			newbo->move2RelPos (p);
insilmaril@394
  2502
insilmaril@394
  2503
			// Move selection to new branch
insilmaril@424
  2504
			bo->linkTo (newbo,-1);
insilmaril@394
  2505
insilmaril@394
  2506
			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
insilmaril@394
  2507
				QString ("Add branch before %1").arg(getName(bo)));
insilmaril@394
  2508
insilmaril@394
  2509
			mapCenter->reposition();
insilmaril@442
  2510
			xelection.update();
insilmaril@394
  2511
		}
insilmaril@0
  2512
	}	
insilmaril@537
  2513
	latestSelection=xelection.getSelectString();
insilmaril@394
  2514
	return newbo;
insilmaril@0
  2515
}
insilmaril@0
  2516
insilmaril@0
  2517
void MapEditor::deleteSelection()
insilmaril@0
  2518
{
insilmaril@424
  2519
	BranchObj *bo = xelection.getBranch();
insilmaril@491
  2520
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2521
	{
insilmaril@294
  2522
		BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@424
  2523
		xelection.unselect();
insilmaril@394
  2524
		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
insilmaril@0
  2525
		par->removeBranch(bo);
insilmaril@424
  2526
		xelection.select (par);
insilmaril@0
  2527
		ensureSelectionVisible();
insilmaril@0
  2528
		mapCenter->reposition();
insilmaril@442
  2529
		xelection.update();
insilmaril@442
  2530
		xelection.update();
insilmaril@424
  2531
		return;
insilmaril@0
  2532
	}
insilmaril@424
  2533
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2534
	if (fio)
insilmaril@0
  2535
	{
insilmaril@0
  2536
		BranchObj* par=(BranchObj*)(fio->getParObj());
insilmaril@395
  2537
		saveStateChangingPart(
insilmaril@395
  2538
			par, 
insilmaril@395
  2539
			fio,
insilmaril@395
  2540
			"delete ()",
insilmaril@395
  2541
			QString("Delete %1").arg(getName(fio))
insilmaril@395
  2542
		);
insilmaril@424
  2543
		xelection.unselect();
insilmaril@0
  2544
		par->removeFloatImage(fio);
insilmaril@424
  2545
		xelection.select (par);
insilmaril@442
  2546
		mapCenter->reposition();
insilmaril@442
  2547
		xelection.update();
insilmaril@0
  2548
		ensureSelectionVisible();
insilmaril@424
  2549
		return;
insilmaril@0
  2550
	}
insilmaril@0
  2551
}
insilmaril@0
  2552
insilmaril@0
  2553
LinkableMapObj* MapEditor::getSelection()
insilmaril@0
  2554
{
insilmaril@424
  2555
	return xelection.single();
insilmaril@0
  2556
}
insilmaril@0
  2557
insilmaril@442
  2558
BranchObj* MapEditor::getSelectedBranch()
insilmaril@442
  2559
{
insilmaril@442
  2560
	return xelection.getBranch();
insilmaril@442
  2561
}
insilmaril@442
  2562
insilmaril@442
  2563
FloatImageObj* MapEditor::getSelectedFloatImage()
insilmaril@442
  2564
{
insilmaril@442
  2565
	return xelection.getFloatImage();
insilmaril@442
  2566
}
insilmaril@442
  2567
insilmaril@267
  2568
void MapEditor::unselect()
insilmaril@267
  2569
{
insilmaril@424
  2570
	xelection.unselect();
insilmaril@267
  2571
}	
insilmaril@267
  2572
insilmaril@267
  2573
void MapEditor::reselect()
insilmaril@267
  2574
{
insilmaril@424
  2575
	xelection.reselect();
insilmaril@267
  2576
}	
insilmaril@267
  2577
insilmaril@83
  2578
bool MapEditor::select (const QString &s)
insilmaril@83
  2579
{
insilmaril@106
  2580
	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
insilmaril@0
  2581
insilmaril@0
  2582
	// Finally select the found object
insilmaril@0
  2583
	if (lmo)
insilmaril@0
  2584
	{
insilmaril@424
  2585
		xelection.unselect();
insilmaril@424
  2586
		xelection.select(lmo);
insilmaril@442
  2587
		xelection.update();
insilmaril@0
  2588
		ensureSelectionVisible();
insilmaril@528
  2589
		sendSelection ();
insilmaril@0
  2590
		return true;
insilmaril@139
  2591
	} 
insilmaril@139
  2592
	return false;
insilmaril@0
  2593
}
insilmaril@0
  2594
insilmaril@366
  2595
QString MapEditor::getSelectString()
insilmaril@366
  2596
{
insilmaril@424
  2597
	return xelection.getSelectString();
insilmaril@366
  2598
}
insilmaril@366
  2599
insilmaril@366
  2600
void MapEditor::selectInt (LinkableMapObj *lmo)
insilmaril@0
  2601
{
insilmaril@491
  2602
	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
insilmaril@442
  2603
	{
insilmaril@424
  2604
		xelection.select(lmo);
insilmaril@442
  2605
		xelection.update();
insilmaril@528
  2606
		sendSelection ();
insilmaril@442
  2607
	}	
insilmaril@267
  2608
}
insilmaril@0
  2609
insilmaril@366
  2610
void MapEditor::selectNextBranchInt()
insilmaril@0
  2611
{
insilmaril@0
  2612
	// Increase number of branch
insilmaril@424
  2613
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2614
	if (sel)
insilmaril@0
  2615
	{
insilmaril@424
  2616
		QString s=sel->getSelectString();
insilmaril@0
  2617
		QString part;
insilmaril@0
  2618
		QString typ;
insilmaril@0
  2619
		QString num;
insilmaril@0
  2620
insilmaril@0
  2621
		// Where am I? 
insilmaril@0
  2622
		part=s.section(",",-1);
insilmaril@0
  2623
		typ=part.left (3);
insilmaril@0
  2624
		num=part.right(part.length() - 3);
insilmaril@0
  2625
insilmaril@0
  2626
		s=s.left (s.length() -num.length());
insilmaril@0
  2627
insilmaril@0
  2628
		// Go to next lmo
insilmaril@0
  2629
		num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2630
insilmaril@0
  2631
		s=s+num;
insilmaril@0
  2632
		
insilmaril@0
  2633
		// Try to select this one
insilmaril@0
  2634
		if (select (s)) return;
insilmaril@0
  2635
insilmaril@0
  2636
		// We have no direct successor, 
insilmaril@0
  2637
		// try to increase the parental number in order to
insilmaril@0
  2638
		// find a successor with same depth
insilmaril@0
  2639
insilmaril@424
  2640
		int d=xelection.single()->getDepth();
insilmaril@0
  2641
		int oldDepth=d;
insilmaril@0
  2642
		int i;
insilmaril@0
  2643
		bool found=false;
insilmaril@0
  2644
		bool b;
insilmaril@0
  2645
		while (!found && d>0)
insilmaril@0
  2646
		{
insilmaril@0
  2647
			s=s.section (",",0,d-1);
insilmaril@0
  2648
			// replace substring of current depth in s with "1"
insilmaril@0
  2649
			part=s.section(",",-1);
insilmaril@0
  2650
			typ=part.left (3);
insilmaril@0
  2651
			num=part.right(part.length() - 3);
insilmaril@0
  2652
insilmaril@0
  2653
			if (d>1)
insilmaril@0
  2654
			{	
insilmaril@0
  2655
				// increase number of parent
insilmaril@0
  2656
				num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2657
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2658
			} else
insilmaril@0
  2659
			{
insilmaril@0
  2660
				// Special case, look at orientation
insilmaril@473
  2661
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2662
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2663
				else	
insilmaril@0
  2664
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  2665
				s=typ+num;
insilmaril@0
  2666
			}	
insilmaril@0
  2667
insilmaril@0
  2668
			if (select (s))
insilmaril@0
  2669
				// pad to oldDepth, select the first branch for each depth
insilmaril@0
  2670
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2671
				{
insilmaril@0
  2672
					b=select (s);
insilmaril@0
  2673
					if (b)
insilmaril@0
  2674
					{	
insilmaril@424
  2675
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@0
  2676
							s+=",bo:0";
insilmaril@0
  2677
						else	
insilmaril@0
  2678
							break;
insilmaril@0
  2679
					} else
insilmaril@0
  2680
						break;
insilmaril@0
  2681
				}	
insilmaril@0
  2682
insilmaril@0
  2683
			// try to select the freshly built string
insilmaril@0
  2684
			found=select(s);
insilmaril@0
  2685
			d--;
insilmaril@0
  2686
		}
insilmaril@0
  2687
		return;
insilmaril@0
  2688
	}	
insilmaril@0
  2689
}
insilmaril@0
  2690
insilmaril@366
  2691
void MapEditor::selectPrevBranchInt()
insilmaril@0
  2692
{
insilmaril@0
  2693
	// Decrease number of branch
insilmaril@424
  2694
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2695
	if (bo)
insilmaril@0
  2696
	{
insilmaril@424
  2697
		QString s=bo->getSelectString();
insilmaril@0
  2698
		QString part;
insilmaril@0
  2699
		QString typ;
insilmaril@0
  2700
		QString num;
insilmaril@0
  2701
insilmaril@0
  2702
		// Where am I? 
insilmaril@0
  2703
		part=s.section(",",-1);
insilmaril@0
  2704
		typ=part.left (3);
insilmaril@0
  2705
		num=part.right(part.length() - 3);
insilmaril@0
  2706
insilmaril@0
  2707
		s=s.left (s.length() -num.length());
insilmaril@0
  2708
insilmaril@411
  2709
		int n=num.toInt()-1;
insilmaril@411
  2710
		
insilmaril@0
  2711
		// Go to next lmo
insilmaril@411
  2712
		num=QString ("%1").arg(n);
insilmaril@0
  2713
		s=s+num;
insilmaril@0
  2714
		
insilmaril@0
  2715
		// Try to select this one
insilmaril@411
  2716
		if (n>=0 && select (s)) return;
insilmaril@0
  2717
insilmaril@0
  2718
		// We have no direct precessor, 
insilmaril@0
  2719
		// try to decrease the parental number in order to
insilmaril@0
  2720
		// find a precessor with same depth
insilmaril@0
  2721
insilmaril@424
  2722
		int d=xelection.single()->getDepth();
insilmaril@0
  2723
		int oldDepth=d;
insilmaril@0
  2724
		int i;
insilmaril@0
  2725
		bool found=false;
insilmaril@0
  2726
		bool b;
insilmaril@0
  2727
		while (!found && d>0)
insilmaril@0
  2728
		{
insilmaril@0
  2729
			s=s.section (",",0,d-1);
insilmaril@0
  2730
			// replace substring of current depth in s with "1"
insilmaril@0
  2731
			part=s.section(",",-1);
insilmaril@0
  2732
			typ=part.left (3);
insilmaril@0
  2733
			num=part.right(part.length() - 3);
insilmaril@0
  2734
insilmaril@0
  2735
			if (d>1)
insilmaril@0
  2736
			{
insilmaril@0
  2737
				// decrease number of parent
insilmaril@411
  2738
				num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2739
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2740
			} else
insilmaril@0
  2741
			{
insilmaril@0
  2742
				// Special case, look at orientation
insilmaril@473
  2743
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@411
  2744
					num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2745
				else	
insilmaril@411
  2746
					num=QString ("%1").arg(num.toInt()+1);
insilmaril@0
  2747
				s=typ+num;
insilmaril@0
  2748
			}	
insilmaril@0
  2749
insilmaril@0
  2750
			if (select(s))
insilmaril@0
  2751
				// pad to oldDepth, select the last branch for each depth
insilmaril@0
  2752
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2753
				{
insilmaril@0
  2754
					b=select (s);
insilmaril@0
  2755
					if (b)
insilmaril@424
  2756
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@424
  2757
							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
insilmaril@0
  2758
						else	
insilmaril@0
  2759
							break;
insilmaril@0
  2760
					else
insilmaril@0
  2761
						break;
insilmaril@0
  2762
				}	
insilmaril@0
  2763
			
insilmaril@0
  2764
			// try to select the freshly built string
insilmaril@0
  2765
			found=select(s);
insilmaril@0
  2766
			d--;
insilmaril@0
  2767
		}
insilmaril@0
  2768
		return;
insilmaril@0
  2769
	}	
insilmaril@0
  2770
}
insilmaril@0
  2771
insilmaril@0
  2772
void MapEditor::selectUpperBranch()
insilmaril@0
  2773
{
insilmaril@491
  2774
	if (isSelectBlocked() ) return;
insilmaril@491
  2775
insilmaril@424
  2776
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2777
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2778
	{
insilmaril@473
  2779
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2780
			selectPrevBranchInt();
insilmaril@424
  2781
		else
insilmaril@424
  2782
			if (bo->getDepth()==1)
insilmaril@424
  2783
				selectNextBranchInt();
insilmaril@424
  2784
			else
insilmaril@424
  2785
				selectPrevBranchInt();
insilmaril@424
  2786
	}
insilmaril@424
  2787
}
insilmaril@424
  2788
insilmaril@424
  2789
void MapEditor::selectLowerBranch()
insilmaril@424
  2790
{
insilmaril@491
  2791
	if (isSelectBlocked() ) return;
insilmaril@491
  2792
insilmaril@424
  2793
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2794
	if (bo && xelection.type()==Selection::Branch)
insilmaril@473
  2795
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2796
			selectNextBranchInt();
insilmaril@424
  2797
		else
insilmaril@424
  2798
			if (bo->getDepth()==1)
insilmaril@366
  2799
				selectPrevBranchInt();
insilmaril@0
  2800
			else
insilmaril@366
  2801
				selectNextBranchInt();
insilmaril@0
  2802
}
insilmaril@0
  2803
insilmaril@0
  2804
insilmaril@0
  2805
void MapEditor::selectLeftBranch()
insilmaril@0
  2806
{
insilmaril@491
  2807
	if (isSelectBlocked() ) return;
insilmaril@491
  2808
insilmaril@0
  2809
	BranchObj* bo;
insilmaril@0
  2810
	BranchObj* par;
insilmaril@424
  2811
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2812
	if (sel)
insilmaril@0
  2813
	{
insilmaril@491
  2814
		if (xelection.type()== Selection::MapCenter)
insilmaril@0
  2815
		{
insilmaril@424
  2816
			par=xelection.getBranch();
insilmaril@0
  2817
			bo=par->getLastSelectedBranch();
insilmaril@0
  2818
			if (bo)
insilmaril@0
  2819
			{
insilmaril@0
  2820
				// Workaround for reselecting on left and right side
insilmaril@473
  2821
				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2822
					bo=par->getLastBranch();
insilmaril@424
  2823
				if (bo)
insilmaril@0
  2824
				{
insilmaril@0
  2825
					bo=par->getLastBranch();
insilmaril@424
  2826
					xelection.select(bo);
insilmaril@442
  2827
					xelection.update();
insilmaril@0
  2828
					ensureSelectionVisible();
insilmaril@528
  2829
					sendSelection();
insilmaril@0
  2830
				}
insilmaril@0
  2831
			}	
insilmaril@0
  2832
		} else
insilmaril@0
  2833
		{
insilmaril@424
  2834
			par=(BranchObj*)(sel->getParObj());
insilmaril@473
  2835
			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2836
			{
insilmaril@491
  2837
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2838
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2839
				{
insilmaril@424
  2840
					xelection.select(par);
insilmaril@442
  2841
					xelection.update();
insilmaril@0
  2842
					ensureSelectionVisible();
insilmaril@528
  2843
					sendSelection();
insilmaril@0
  2844
				}
insilmaril@0
  2845
			} else
insilmaril@0
  2846
			{
insilmaril@491
  2847
				if (xelection.type() == Selection::Branch )
insilmaril@0
  2848
				{
insilmaril@424
  2849
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  2850
					if (bo) 
insilmaril@0
  2851
					{
insilmaril@424
  2852
						xelection.select(bo);
insilmaril@442
  2853
						xelection.update();
insilmaril@0
  2854
						ensureSelectionVisible();
insilmaril@528
  2855
					sendSelection();
insilmaril@0
  2856
					}
insilmaril@0
  2857
				}
insilmaril@0
  2858
			}
insilmaril@0
  2859
		}	
insilmaril@0
  2860
	}
insilmaril@0
  2861
}
insilmaril@0
  2862
insilmaril@0
  2863
void MapEditor::selectRightBranch()
insilmaril@0
  2864
{
insilmaril@491
  2865
	if (isSelectBlocked() ) return;
insilmaril@491
  2866
insilmaril@0
  2867
	BranchObj* bo;
insilmaril@0
  2868
	BranchObj* par;
insilmaril@424
  2869
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2870
	if (sel)
insilmaril@0
  2871
	{
insilmaril@491
  2872
		if (xelection.type()==Selection::MapCenter) 
insilmaril@0
  2873
		{
insilmaril@424
  2874
			par=xelection.getBranch();
insilmaril@0
  2875
			bo=par->getLastSelectedBranch();
insilmaril@0
  2876
			if (bo)
insilmaril@0
  2877
			{
insilmaril@366
  2878
				// Workaround for reselecting on left and right side
insilmaril@473
  2879
				if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2880
					bo=par->getFirstBranch();
insilmaril@0
  2881
				if (bo)
insilmaril@0
  2882
				{
insilmaril@424
  2883
					xelection.select(bo);
insilmaril@442
  2884
					xelection.update();
insilmaril@0
  2885
					ensureSelectionVisible();
insilmaril@528
  2886
					sendSelection();
insilmaril@0
  2887
				}
insilmaril@0
  2888
			}
insilmaril@0
  2889
		} else
insilmaril@0
  2890
		{
insilmaril@424
  2891
			par=(BranchObj*)(xelection.single()->getParObj());
insilmaril@473
  2892
			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2893
			{
insilmaril@491
  2894
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2895
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2896
				{
insilmaril@424
  2897
					xelection.select(par);
insilmaril@442
  2898
					xelection.update();
insilmaril@0
  2899
					ensureSelectionVisible();
insilmaril@528
  2900
					sendSelection();
insilmaril@0
  2901
				}
insilmaril@0
  2902
			} else
insilmaril@0
  2903
			{
insilmaril@491
  2904
				if (xelection.type()  == Selection::Branch) 
insilmaril@0
  2905
				{
insilmaril@424
  2906
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  2907
					if (bo) 
insilmaril@0
  2908
					{
insilmaril@424
  2909
						xelection.select(bo);
insilmaril@442
  2910
						xelection.update();
insilmaril@0
  2911
						ensureSelectionVisible();
insilmaril@528
  2912
					sendSelection();
insilmaril@0
  2913
					}
insilmaril@0
  2914
				}
insilmaril@0
  2915
			}
insilmaril@0
  2916
		}
insilmaril@0
  2917
	}
insilmaril@0
  2918
}
insilmaril@0
  2919
insilmaril@0
  2920
void MapEditor::selectFirstBranch()
insilmaril@0
  2921
{
insilmaril@424
  2922
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  2923
	BranchObj *bo2;
insilmaril@0
  2924
	BranchObj* par;
insilmaril@424
  2925
	if (bo1)
insilmaril@424
  2926
	{
insilmaril@424
  2927
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  2928
		bo2=par->getFirstBranch();
insilmaril@424
  2929
		if (bo2) {
insilmaril@424
  2930
			xelection.select(bo2);
insilmaril@442
  2931
			xelection.update();
insilmaril@424
  2932
			ensureSelectionVisible();
insilmaril@528
  2933
			sendSelection();
insilmaril@424
  2934
		}
insilmaril@424
  2935
	}		
insilmaril@0
  2936
}
insilmaril@0
  2937
insilmaril@0
  2938
void MapEditor::selectLastBranch()
insilmaril@0
  2939
{
insilmaril@424
  2940
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  2941
	BranchObj *bo2;
insilmaril@0
  2942
	BranchObj* par;
insilmaril@424
  2943
	if (bo1)
insilmaril@424
  2944
	{
insilmaril@424
  2945
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  2946
		bo2=par->getLastBranch();
insilmaril@424
  2947
		if (bo2) 
insilmaril@0
  2948
		{
insilmaril@424
  2949
			xelection.select(bo2);
insilmaril@442
  2950
			xelection.update();
insilmaril@424
  2951
			ensureSelectionVisible();
insilmaril@528
  2952
			sendSelection();
insilmaril@424
  2953
		}
insilmaril@424
  2954
	}		
insilmaril@0
  2955
}
insilmaril@0
  2956
insilmaril@408
  2957
void MapEditor::selectMapBackgroundImage ()
insilmaril@408
  2958
{
insilmaril@408
  2959
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@408
  2960
	fd->setMode (Q3FileDialog::ExistingFile);
insilmaril@408
  2961
	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@408
  2962
	ImagePreview *p =new ImagePreview (fd);
insilmaril@408
  2963
	fd->setContentsPreviewEnabled( TRUE );
insilmaril@408
  2964
	fd->setContentsPreview( p, p );
insilmaril@408
  2965
	fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@408
  2966
	fd->setCaption(vymName+" - " +tr("Load background image"));
insilmaril@408
  2967
	fd->setDir (lastImageDir);
insilmaril@408
  2968
	fd->show();
insilmaril@408
  2969
insilmaril@408
  2970
	if ( fd->exec() == QDialog::Accepted )
insilmaril@408
  2971
	{
insilmaril@412
  2972
		// TODO selectMapBackgroundImg in QT4 use:	lastImageDir=fd->directory();
insilmaril@408
  2973
		lastImageDir=QDir (fd->dirPath());
insilmaril@408
  2974
		setMapBackgroundImage (fd->selectedFile());
insilmaril@408
  2975
	}
insilmaril@408
  2976
}	
insilmaril@408
  2977
insilmaril@442
  2978
void MapEditor::setMapBackgroundImage (const QString &fn)	//FIXME missing savestate
insilmaril@408
  2979
{
insilmaril@408
  2980
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@408
  2981
	/*
insilmaril@408
  2982
	saveState(
insilmaril@408
  2983
		selection,
insilmaril@408
  2984
		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
insilmaril@408
  2985
		selection,
insilmaril@408
  2986
		QString ("setMapBackgroundImage (%1)").arg(col.name()),
insilmaril@408
  2987
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  2988
	*/	
insilmaril@408
  2989
	QBrush brush;
insilmaril@408
  2990
	brush.setTextureImage (QPixmap (fn));
insilmaril@408
  2991
	mapScene->setBackgroundBrush(brush);
insilmaril@408
  2992
}
insilmaril@408
  2993
insilmaril@398
  2994
void MapEditor::selectMapBackgroundColor()
insilmaril@0
  2995
{
insilmaril@408
  2996
	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
insilmaril@0
  2997
	if ( !col.isValid() ) return;
insilmaril@408
  2998
	setMapBackgroundColor( col );
insilmaril@0
  2999
}
insilmaril@0
  3000
insilmaril@398
  3001
insilmaril@398
  3002
void MapEditor::setMapBackgroundColor(QColor col)
insilmaril@0
  3003
{
insilmaril@408
  3004
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@398
  3005
	saveState(
insilmaril@424
  3006
		mapCenter,
insilmaril@445
  3007
		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
insilmaril@424
  3008
		mapCenter,
insilmaril@445
  3009
		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
insilmaril@398
  3010
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  3011
	mapScene->setBackgroundBrush(col);
insilmaril@398
  3012
}
insilmaril@398
  3013
insilmaril@398
  3014
QColor MapEditor::getMapBackgroundColor()
insilmaril@398
  3015
{
insilmaril@408
  3016
    return mapScene->backgroundBrush().color();
insilmaril@0
  3017
}
insilmaril@0
  3018
insilmaril@395
  3019
QColor MapEditor::getCurrentHeadingColor()
insilmaril@0
  3020
{
insilmaril@424
  3021
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3022
	if (bo) return bo->getColor(); 
insilmaril@395
  3023
	
insilmaril@395
  3024
	QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
insilmaril@395
  3025
	return Qt::black;
insilmaril@0
  3026
}
insilmaril@0
  3027
insilmaril@417
  3028
void MapEditor::colorBranch (QColor c)
insilmaril@0
  3029
{
insilmaril@424
  3030
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3031
	if (bo)
insilmaril@0
  3032
	{
insilmaril@424
  3033
		saveState(
insilmaril@424
  3034
			bo, 
insilmaril@445
  3035
			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
insilmaril@424
  3036
			bo,
insilmaril@445
  3037
			QString ("colorBranch (\"%1\")").arg(c.name()),
insilmaril@424
  3038
			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3039
		);	
insilmaril@424
  3040
		bo->setColor(c); // color branch
insilmaril@0
  3041
	}
insilmaril@0
  3042
}
insilmaril@0
  3043
insilmaril@417
  3044
void MapEditor::colorSubtree (QColor c)
insilmaril@0
  3045
{
insilmaril@424
  3046
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3047
	if (bo) 
insilmaril@0
  3048
	{
insilmaril@424
  3049
		saveStateChangingPart(
insilmaril@424
  3050
			bo, 
insilmaril@424
  3051
			bo,
insilmaril@445
  3052
			QString ("colorSubtree (\"%1\")").arg(c.name()),
insilmaril@424
  3053
			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3054
		);	
insilmaril@424
  3055
		bo->setColorSubtree (c); // color links, color childs
insilmaril@0
  3056
	}
insilmaril@0
  3057
}
insilmaril@0
  3058
insilmaril@0
  3059
insilmaril@0
  3060
void MapEditor::toggleStandardFlag(QString f)
insilmaril@0
  3061
{
insilmaril@424
  3062
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3063
	if (bo) 
insilmaril@0
  3064
	{
insilmaril@424
  3065
		QString u,r;
insilmaril@424
  3066
		if (bo->isSetStandardFlag(f))
insilmaril@366
  3067
		{
insilmaril@424
  3068
			r="unsetFlag";
insilmaril@424
  3069
			u="setFlag";
insilmaril@424
  3070
		}	
insilmaril@424
  3071
		else
insilmaril@424
  3072
		{
insilmaril@424
  3073
			u="unsetFlag";
insilmaril@424
  3074
			r="setFlag";
insilmaril@424
  3075
		}	
insilmaril@424
  3076
		saveState(
insilmaril@424
  3077
			bo,
insilmaril@424
  3078
			QString("%1 (\"%2\")").arg(u).arg(f), 
insilmaril@424
  3079
			bo,
insilmaril@424
  3080
			QString("%1 (\"%2\")").arg(r).arg(f),
insilmaril@424
  3081
			QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
insilmaril@424
  3082
		bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
insilmaril@442
  3083
		xelection.update();
insilmaril@424
  3084
	}
insilmaril@0
  3085
}
insilmaril@0
  3086
insilmaril@0
  3087
insilmaril@0
  3088
BranchObj* MapEditor::findText (QString s, bool cs)
insilmaril@0
  3089
{
insilmaril@366
  3090
	QTextDocument::FindFlags flags=0;
insilmaril@366
  3091
	if (cs) flags=QTextDocument::FindCaseSensitively;
insilmaril@366
  3092
insilmaril@0
  3093
	if (!itFind) 
insilmaril@0
  3094
	{	// Nothing found or new find process
insilmaril@0
  3095
		if (EOFind)
insilmaril@0
  3096
			// nothing found, start again
insilmaril@0
  3097
			EOFind=false;
insilmaril@0
  3098
		itFind=mapCenter->first();
insilmaril@0
  3099
	}	
insilmaril@0
  3100
	bool searching=true;
insilmaril@0
  3101
	bool foundNote=false;
insilmaril@0
  3102
	while (searching && !EOFind)
insilmaril@0
  3103
	{
insilmaril@0
  3104
		if (itFind)
insilmaril@0
  3105
		{
insilmaril@0
  3106
			// Searching in Note
insilmaril@0
  3107
			if (itFind->getNote().contains(s,cs))
insilmaril@0
  3108
			{
insilmaril@424
  3109
				if (xelection.single()!=itFind) 
insilmaril@0
  3110
				{
insilmaril@424
  3111
					xelection.select(itFind);
insilmaril@0
  3112
					ensureSelectionVisible();
insilmaril@0
  3113
				}
insilmaril@366
  3114
				if (textEditor->findText(s,flags)) 
insilmaril@0
  3115
				{
insilmaril@0
  3116
					searching=false;
insilmaril@0
  3117
					foundNote=true;
insilmaril@0
  3118
				}	
insilmaril@0
  3119
			}
insilmaril@0
  3120
			// Searching in Heading
insilmaril@0
  3121
			if (searching && itFind->getHeading().contains (s,cs) ) 
insilmaril@0
  3122
			{
insilmaril@424
  3123
				xelection.select(itFind);
insilmaril@0
  3124
				ensureSelectionVisible();
insilmaril@0
  3125
				searching=false;
insilmaril@0
  3126
			}
insilmaril@0
  3127
		}	
insilmaril@0
  3128
		if (!foundNote)
insilmaril@0
  3129
		{
insilmaril@0
  3130
			itFind=itFind->next();
insilmaril@0
  3131
			if (!itFind) EOFind=true;
insilmaril@0
  3132
		}
insilmaril@0
  3133
	}	
insilmaril@0
  3134
	if (!searching)
insilmaril@424
  3135
		return xelection.getBranch();
insilmaril@424
  3136
	else
insilmaril@0
  3137
		return NULL;
insilmaril@0
  3138
}
insilmaril@0
  3139
insilmaril@0
  3140
void MapEditor::findReset()
insilmaril@0
  3141
{	// Necessary if text to find changes during a find process
insilmaril@0
  3142
	itFind=NULL;
insilmaril@0
  3143
	EOFind=false;
insilmaril@0
  3144
}
insilmaril@395
  3145
void MapEditor::setURL(const QString &url)
insilmaril@395
  3146
{
insilmaril@424
  3147
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3148
	if (bo)
insilmaril@424
  3149
	{
insilmaril@395
  3150
		QString oldurl=bo->getURL();
insilmaril@395
  3151
		bo->setURL (url);
insilmaril@395
  3152
		saveState (
insilmaril@424
  3153
			bo,
insilmaril@395
  3154
			QString ("setURL (\"%1\")").arg(oldurl),
insilmaril@424
  3155
			bo,
insilmaril@395
  3156
			QString ("setURL (\"%1\")").arg(url),
insilmaril@395
  3157
			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
insilmaril@395
  3158
		);
insilmaril@395
  3159
		updateActions();
insilmaril@491
  3160
		mapCenter->reposition();
insilmaril@491
  3161
		xelection.update();
insilmaril@491
  3162
		ensureSelectionVisible();
insilmaril@395
  3163
	}
insilmaril@395
  3164
}	
insilmaril@0
  3165
insilmaril@0
  3166
void MapEditor::editURL()
insilmaril@0
  3167
{
insilmaril@424
  3168
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3169
	if (bo)
insilmaril@0
  3170
	{		
insilmaril@0
  3171
		bool ok;
insilmaril@0
  3172
		QString text = QInputDialog::getText(
insilmaril@0
  3173
				"VYM", tr("Enter URL:"), QLineEdit::Normal,
insilmaril@143
  3174
				bo->getURL(), &ok, this );
insilmaril@0
  3175
		if ( ok) 
insilmaril@0
  3176
			// user entered something and pressed OK
insilmaril@395
  3177
			setURL (text);
insilmaril@0
  3178
	}
insilmaril@0
  3179
}
insilmaril@0
  3180
insilmaril@528
  3181
void MapEditor::editLocalURL()
insilmaril@528
  3182
{
insilmaril@528
  3183
	BranchObj *bo=xelection.getBranch();
insilmaril@528
  3184
	if (bo)
insilmaril@528
  3185
	{		
insilmaril@528
  3186
		QStringList filters;
insilmaril@528
  3187
		filters <<"All files (*)";
insilmaril@528
  3188
		filters << tr("Text","Filedialog") + " (*.txt)";
insilmaril@528
  3189
		filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
insilmaril@528
  3190
		filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
insilmaril@528
  3191
		filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
insilmaril@528
  3192
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3193
		fd->setFilters (filters);
insilmaril@528
  3194
		fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3195
		fd->setDirectory (lastFileDir);
insilmaril@528
  3196
		if (! bo->getVymLink().isEmpty() )
insilmaril@528
  3197
			fd->selectFile( bo->getURL() );
insilmaril@528
  3198
		fd->show();
insilmaril@528
  3199
insilmaril@528
  3200
		if ( fd->exec() == QDialog::Accepted )
insilmaril@528
  3201
		{
insilmaril@528
  3202
			lastFileDir=QDir (fd->directory().path());
insilmaril@528
  3203
			setURL (fd->selectedFile() );
insilmaril@528
  3204
		}
insilmaril@528
  3205
	}
insilmaril@528
  3206
}
insilmaril@528
  3207
insilmaril@266
  3208
QString MapEditor::getURL()
insilmaril@266
  3209
{
insilmaril@424
  3210
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3211
	if (bo)
insilmaril@424
  3212
		return bo->getURL();
insilmaril@266
  3213
	else
insilmaril@266
  3214
		return "";
insilmaril@266
  3215
}
insilmaril@266
  3216
insilmaril@366
  3217
QStringList MapEditor::getURLs()
insilmaril@366
  3218
{
insilmaril@366
  3219
	QStringList urls;
insilmaril@424
  3220
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3221
	if (bo)
insilmaril@366
  3222
	{		
insilmaril@366
  3223
		bo=bo->first();	
insilmaril@366
  3224
		while (bo) 
insilmaril@366
  3225
		{
insilmaril@366
  3226
			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
insilmaril@366
  3227
			bo=bo->next();
insilmaril@366
  3228
		}	
insilmaril@366
  3229
	}	
insilmaril@366
  3230
	return urls;
insilmaril@366
  3231
}
insilmaril@366
  3232
insilmaril@366
  3233
insilmaril@0
  3234
void MapEditor::editHeading2URL()
insilmaril@0
  3235
{
insilmaril@424
  3236
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3237
	if (bo)
insilmaril@424
  3238
		setURL (bo->getHeading());
insilmaril@0
  3239
}	
insilmaril@0
  3240
insilmaril@0
  3241
void MapEditor::editBugzilla2URL()
insilmaril@0
  3242
{
insilmaril@424
  3243
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3244
	if (bo)
insilmaril@0
  3245
	{		
insilmaril@143
  3246
		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
insilmaril@395
  3247
		setURL (url);
insilmaril@0
  3248
	}
insilmaril@0
  3249
}	
insilmaril@0
  3250
insilmaril@175
  3251
void MapEditor::editFATE2URL()
insilmaril@175
  3252
{
insilmaril@424
  3253
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3254
	if (bo)
insilmaril@175
  3255
	{		
insilmaril@175
  3256
		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
insilmaril@395
  3257
		saveState(
insilmaril@424
  3258
			bo,
insilmaril@395
  3259
			"setURL (\""+bo->getURL()+"\")",
insilmaril@424
  3260
			bo,
insilmaril@395
  3261
			"setURL (\""+url+"\")",
insilmaril@395
  3262
			QString("Use heading of %1 as link to FATE").arg(getName(bo))
insilmaril@395
  3263
		);	
insilmaril@175
  3264
		bo->setURL (url);
insilmaril@175
  3265
		updateActions();
insilmaril@175
  3266
	}
insilmaril@175
  3267
}	
insilmaril@175
  3268
insilmaril@0
  3269
void MapEditor::editVymLink()
insilmaril@0
  3270
{
insilmaril@424
  3271
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3272
	if (bo)
insilmaril@0
  3273
	{		
insilmaril@404
  3274
		QStringList filters;
insilmaril@404
  3275
		filters <<"VYM map (*.vym)";
insilmaril@404
  3276
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
insilmaril@404
  3277
		fd->setFilters (filters);
insilmaril@404
  3278
		fd->setCaption(vymName+" - " +tr("Link to another map"));
insilmaril@442
  3279
		fd->setDirectory (lastFileDir);
insilmaril@143
  3280
		if (! bo->getVymLink().isEmpty() )
insilmaril@404
  3281
			fd->selectFile( bo->getVymLink() );
insilmaril@0
  3282
		fd->show();
insilmaril@0
  3283
insilmaril@0
  3284
		QString fn;
insilmaril@0
  3285
		if ( fd->exec() == QDialog::Accepted )
insilmaril@143
  3286
		{
insilmaril@442
  3287
			lastFileDir=QDir (fd->directory().path());
insilmaril@395
  3288
			saveState(
insilmaril@424
  3289
				bo,
insilmaril@395
  3290
				"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3291
				bo,
insilmaril@395
  3292
				"setVymLink (\""+fd->selectedFile()+"\")",
insilmaril@395
  3293
				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
insilmaril@395
  3294
			);	
insilmaril@491
  3295
			setVymLinkInt (fd->selectedFile() );
insilmaril@143
  3296
		}
insilmaril@0
  3297
	}
insilmaril@0
  3298
}
insilmaril@0
  3299
insilmaril@0
  3300
void MapEditor::deleteVymLink()
insilmaril@0
  3301
{
insilmaril@424
  3302
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3303
	if (bo)
insilmaril@0
  3304
	{		
insilmaril@395
  3305
		saveState(
insilmaril@424
  3306
			bo,
insilmaril@395
  3307
			"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3308
			bo,
insilmaril@395
  3309
			"setVymLink (\"\")",
insilmaril@395
  3310
			QString("Unset vymlink of %1").arg(getName(bo))
insilmaril@395
  3311
		);	
insilmaril@143
  3312
		bo->setVymLink ("" );
insilmaril@0
  3313
		updateActions();
insilmaril@0
  3314
		mapCenter->reposition();
insilmaril@408
  3315
		scene()->update();
insilmaril@0
  3316
	}
insilmaril@0
  3317
}
insilmaril@0
  3318
insilmaril@395
  3319
void MapEditor::setHideExport(bool b)
insilmaril@243
  3320
{
insilmaril@424
  3321
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3322
	if (bo)
insilmaril@395
  3323
	{
insilmaril@424
  3324
		bo->setHideInExport (b);
insilmaril@395
  3325
		QString u= b ? "false" : "true";
insilmaril@395
  3326
		QString r=!b ? "false" : "true";
insilmaril@395
  3327
		
insilmaril@395
  3328
		saveState(
insilmaril@424
  3329
			bo,
insilmaril@395
  3330
			QString ("setHideExport (%1)").arg(u),
insilmaril@424
  3331
			bo,
insilmaril@395
  3332
			QString ("setHideExport (%1)").arg(r),
insilmaril@424
  3333
			QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
insilmaril@395
  3334
		);	
insilmaril@243
  3335
		updateActions();
insilmaril@243
  3336
		mapCenter->reposition();
insilmaril@491
  3337
		xelection.update();
insilmaril@408
  3338
		scene()->update();
insilmaril@243
  3339
	}
insilmaril@243
  3340
}
insilmaril@243
  3341
insilmaril@395
  3342
void MapEditor::toggleHideExport()
insilmaril@395
  3343
{
insilmaril@424
  3344
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3345
	if (bo)
insilmaril@424
  3346
		setHideExport ( !bo->hideInExport() );
insilmaril@395
  3347
}
insilmaril@395
  3348
insilmaril@0
  3349
QString MapEditor::getVymLink()
insilmaril@0
  3350
{
insilmaril@424
  3351
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3352
	if (bo)
insilmaril@424
  3353
		return bo->getVymLink();
insilmaril@424
  3354
	else	
insilmaril@424
  3355
		return "";
insilmaril@0
  3356
	
insilmaril@0
  3357
}
insilmaril@0
  3358
insilmaril@366
  3359
QStringList MapEditor::getVymLinks()
insilmaril@366
  3360
{
insilmaril@366
  3361
	QStringList links;
insilmaril@424
  3362
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3363
	if (bo)
insilmaril@366
  3364
	{		
insilmaril@366
  3365
		bo=bo->first();	
insilmaril@366
  3366
		while (bo) 
insilmaril@366
  3367
		{
insilmaril@366
  3368
			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
insilmaril@366
  3369
			bo=bo->next();
insilmaril@366
  3370
		}	
insilmaril@366
  3371
	}	
insilmaril@366
  3372
	return links;
insilmaril@366
  3373
}
insilmaril@366
  3374
insilmaril@366
  3375
insilmaril@395
  3376
void MapEditor::deleteKeepChilds()
insilmaril@98
  3377
{
insilmaril@424
  3378
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3379
	BranchObj *par;
insilmaril@424
  3380
	if (bo)
insilmaril@424
  3381
	{
insilmaril@424
  3382
		par=(BranchObj*)(bo->getParObj());
insilmaril@408
  3383
		QPointF p=bo->getRelPos();
insilmaril@395
  3384
		saveStateChangingPart(
insilmaril@424
  3385
			bo->getParObj(),
insilmaril@424
  3386
			bo,
insilmaril@395
  3387
			"deleteKeepChilds ()",
insilmaril@395
  3388
			QString("Remove %1 and keep its childs").arg(getName(bo))
insilmaril@395
  3389
		);
insilmaril@394
  3390
insilmaril@424
  3391
		QString sel=bo->getSelectString();
insilmaril@98
  3392
		unselect();
insilmaril@98
  3393
		par->removeBranchHere(bo);
insilmaril@98
  3394
		mapCenter->reposition();
insilmaril@98
  3395
		select (sel);
insilmaril@424
  3396
		xelection.getBranch()->move2RelPos (p);
insilmaril@394
  3397
		mapCenter->reposition();
insilmaril@98
  3398
	}	
insilmaril@98
  3399
}
insilmaril@98
  3400
insilmaril@395
  3401
void MapEditor::deleteChilds()
insilmaril@98
  3402
{
insilmaril@424
  3403
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3404
	if (bo)
insilmaril@98
  3405
	{		
insilmaril@395
  3406
		saveStateChangingPart(
insilmaril@491
  3407
			bo, 
insilmaril@424
  3408
			bo,
insilmaril@395
  3409
			"deleteChilds ()",
insilmaril@424
  3410
			QString( "Remove childs of branch %1").arg(getName(bo))
insilmaril@395
  3411
		);
insilmaril@424
  3412
		bo->removeChilds();
insilmaril@98
  3413
		mapCenter->reposition();
insilmaril@98
  3414
	}	
insilmaril@98
  3415
}
insilmaril@98
  3416
insilmaril@0
  3417
void MapEditor::editMapInfo()
insilmaril@0
  3418
{
insilmaril@0
  3419
	ExtraInfoDialog dia;
insilmaril@0
  3420
	dia.setMapName (getFileName() );
insilmaril@0
  3421
	dia.setAuthor (mapCenter->getAuthor() );
insilmaril@0
  3422
	dia.setComment(mapCenter->getComment() );
insilmaril@0
  3423
insilmaril@0
  3424
	// Calc some stats
insilmaril@0
  3425
	QString stats;
insilmaril@408
  3426
    stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
insilmaril@0
  3427
insilmaril@0
  3428
	uint b=0;
insilmaril@0
  3429
	uint f=0;
insilmaril@0
  3430
	uint n=0;
insilmaril@103
  3431
	uint xl=0;
insilmaril@0
  3432
	BranchObj *bo;
insilmaril@0
  3433
	bo=mapCenter->first();
insilmaril@0
  3434
	while (bo) 
insilmaril@0
  3435
	{
insilmaril@0
  3436
		if (!bo->getNote().isEmpty() ) n++;
insilmaril@0
  3437
		f+= bo->countFloatImages();
insilmaril@0
  3438
		b++;
insilmaril@103
  3439
		xl+=bo->countXLinks();
insilmaril@0
  3440
		bo=bo->next();
insilmaril@0
  3441
	}
insilmaril@0
  3442
    stats+=QString ("%1 branches\n").arg (b-1,6);
insilmaril@104
  3443
    stats+=QString ("%1 xLinks \n").arg (xl,6);
insilmaril@0
  3444
    stats+=QString ("%1 notes\n").arg (n,6);
insilmaril@0
  3445
    stats+=QString ("%1 images\n").arg (f,6);
insilmaril@0
  3446
	dia.setStats (stats);
insilmaril@0
  3447
insilmaril@0
  3448
	// Finally show dialog
insilmaril@0
  3449
	if (dia.exec() == QDialog::Accepted)
insilmaril@0
  3450
	{
insilmaril@398
  3451
		setMapAuthor (dia.getAuthor() );
insilmaril@398
  3452
		setMapComment (dia.getComment() );
insilmaril@0
  3453
	}
insilmaril@0
  3454
}
insilmaril@0
  3455
insilmaril@442
  3456
void MapEditor::ensureSelectionVisible()
insilmaril@442
  3457
{
insilmaril@442
  3458
	LinkableMapObj *lmo=xelection.single();
insilmaril@442
  3459
	if (lmo) ensureVisible (lmo->getBBox() );
insilmaril@442
  3460
	
insilmaril@442
  3461
}
insilmaril@442
  3462
insilmaril@442
  3463
void MapEditor::updateSelection()
insilmaril@442
  3464
{
insilmaril@442
  3465
	// Tell selection to update geometries
insilmaril@442
  3466
	xelection.update();
insilmaril@442
  3467
}
insilmaril@442
  3468
insilmaril@0
  3469
void MapEditor::updateActions()
insilmaril@0
  3470
{
insilmaril@442
  3471
	// Tell mainwindow to update states of actions
insilmaril@390
  3472
	mainWindow->updateActions();
insilmaril@412
  3473
	// TODO maybe don't update if blockReposition is set
insilmaril@0
  3474
}
insilmaril@0
  3475
insilmaril@160
  3476
void MapEditor::updateNoteFlag()
insilmaril@160
  3477
{
insilmaril@427
  3478
	setChanged();
insilmaril@424
  3479
	BranchObj *bo=xelection.getBranch();
insilmaril@427
  3480
	if (bo) 
insilmaril@427
  3481
	{
insilmaril@427
  3482
		bo->updateNoteFlag();
insilmaril@427
  3483
		mainWindow->updateActions();
insilmaril@427
  3484
	}	
insilmaril@160
  3485
}
insilmaril@160
  3486
insilmaril@398
  3487
void MapEditor::setMapAuthor (const QString &s)
insilmaril@0
  3488
{
insilmaril@398
  3489
	saveState (
insilmaril@424
  3490
		mapCenter,
insilmaril@398
  3491
		QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
insilmaril@424
  3492
		mapCenter,
insilmaril@398
  3493
		QString ("setMapAuthor (\"%1\")").arg(s),
insilmaril@398
  3494
		QString ("Set author of map to \"%1\"").arg(s)
insilmaril@398
  3495
	);
insilmaril@398
  3496
	mapCenter->setAuthor (s);
insilmaril@398
  3497
}
insilmaril@398
  3498
insilmaril@398
  3499
void MapEditor::setMapComment (const QString &s)
insilmaril@398
  3500
{
insilmaril@398
  3501
	saveState (
insilmaril@424
  3502
		mapCenter,
insilmaril@398
  3503
		QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
insilmaril@424
  3504
		mapCenter,
insilmaril@398
  3505
		QString ("setMapComment (\"%1\")").arg(s),
insilmaril@398
  3506
		QString ("Set comment of map")
insilmaril@398
  3507
	);
insilmaril@398
  3508
	mapCenter->setComment (s);
insilmaril@398
  3509
}
insilmaril@398
  3510
insilmaril@398
  3511
void MapEditor::setMapLinkStyle (const QString & s)
insilmaril@398
  3512
{
insilmaril@398
  3513
	saveStateChangingPart (
insilmaril@398
  3514
		mapCenter,
insilmaril@398
  3515
		mapCenter,
insilmaril@398
  3516
		QString("setMapLinkStyle (\"%1\")").arg(s),
insilmaril@398
  3517
		QString("Set map link style (\"%1\")").arg(s)
insilmaril@398
  3518
	);	
insilmaril@398
  3519
insilmaril@398
  3520
	if (s=="StyleLine")
insilmaril@473
  3521
		linkstyle=LinkableMapObj::Line;
insilmaril@398
  3522
	else if (s=="StyleParabel")
insilmaril@473
  3523
		linkstyle=LinkableMapObj::Parabel;
insilmaril@398
  3524
	else if (s=="StylePolyLine")
insilmaril@473
  3525
		linkstyle=LinkableMapObj::PolyLine;
insilmaril@398
  3526
	else	
insilmaril@473
  3527
		linkstyle=LinkableMapObj::PolyParabel;
insilmaril@398
  3528
insilmaril@0
  3529
	BranchObj *bo;
insilmaril@0
  3530
	bo=mapCenter->first();
insilmaril@0
  3531
	bo=bo->next();
insilmaril@0
  3532
	while (bo) 
insilmaril@0
  3533
	{
insilmaril@0
  3534
		bo->setLinkStyle(bo->getDefLinkStyle());
insilmaril@0
  3535
		bo=bo->next();
insilmaril@0
  3536
	}
insilmaril@102
  3537
	mapCenter->reposition();
insilmaril@0
  3538
}
insilmaril@0
  3539
insilmaril@473
  3540
LinkableMapObj::Style MapEditor::getMapLinkStyle ()
insilmaril@0
  3541
{
insilmaril@0
  3542
	return linkstyle;
insilmaril@0
  3543
}	
insilmaril@0
  3544
insilmaril@398
  3545
void MapEditor::setMapDefLinkColor(QColor c)
insilmaril@0
  3546
{
insilmaril@97
  3547
	defLinkColor=c;
insilmaril@497
  3548
	BranchObj *bo;
insilmaril@497
  3549
	bo=mapCenter->first();
insilmaril@497
  3550
	while (bo) 
insilmaril@497
  3551
	{
insilmaril@497
  3552
		bo->setLinkColor();
insilmaril@497
  3553
		bo=bo->next();
insilmaril@497
  3554
	}
insilmaril@0
  3555
	updateActions();
insilmaril@0
  3556
}
insilmaril@0
  3557
insilmaril@398
  3558
void MapEditor::setMapLinkColorHintInt()
insilmaril@0
  3559
{
insilmaril@398
  3560
	// called from setMapLinkColorHint(lch) or at end of parse
insilmaril@0
  3561
	BranchObj *bo;
insilmaril@0
  3562
	bo=mapCenter->first();
insilmaril@0
  3563
	while (bo) 
insilmaril@0
  3564
	{
insilmaril@0
  3565
		bo->setLinkColor();
insilmaril@0
  3566
		bo=bo->next();
insilmaril@0
  3567
	}
insilmaril@0
  3568
}
insilmaril@0
  3569
insilmaril@473
  3570
void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
insilmaril@0
  3571
{
insilmaril@0
  3572
	linkcolorhint=lch;
insilmaril@398
  3573
	setMapLinkColorHintInt();
insilmaril@0
  3574
}
insilmaril@0
  3575
insilmaril@398
  3576
void MapEditor::toggleMapLinkColorHint()
insilmaril@0
  3577
{
insilmaril@473
  3578
	if (linkcolorhint==LinkableMapObj::HeadingColor)
insilmaril@473
  3579
		linkcolorhint=LinkableMapObj::DefaultColor;
insilmaril@0
  3580
	else	
insilmaril@473
  3581
		linkcolorhint=LinkableMapObj::HeadingColor;
insilmaril@0
  3582
	BranchObj *bo;
insilmaril@0
  3583
	bo=mapCenter->first();
insilmaril@0
  3584
	while (bo) 
insilmaril@0
  3585
	{
insilmaril@0
  3586
		bo->setLinkColor();
insilmaril@0
  3587
		bo=bo->next();
insilmaril@0
  3588
	}
insilmaril@0
  3589
}
insilmaril@0
  3590
insilmaril@473
  3591
LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
insilmaril@0
  3592
{
insilmaril@0
  3593
	return linkcolorhint;
insilmaril@0
  3594
}
insilmaril@0
  3595
insilmaril@398
  3596
QColor MapEditor::getMapDefLinkColor()
insilmaril@0
  3597
{
insilmaril@97
  3598
	return defLinkColor;
insilmaril@97
  3599
}
insilmaril@97
  3600
insilmaril@398
  3601
void MapEditor::setMapDefXLinkColor(QColor col)
insilmaril@97
  3602
{
insilmaril@97
  3603
	defXLinkColor=col;
insilmaril@97
  3604
}
insilmaril@97
  3605
insilmaril@398
  3606
QColor MapEditor::getMapDefXLinkColor()
insilmaril@97
  3607
{
insilmaril@97
  3608
	return defXLinkColor;
insilmaril@97
  3609
}
insilmaril@97
  3610
insilmaril@398
  3611
void MapEditor::setMapDefXLinkWidth (int w)
insilmaril@97
  3612
{
insilmaril@97
  3613
	defXLinkWidth=w;
insilmaril@97
  3614
}
insilmaril@97
  3615
insilmaril@398
  3616
int MapEditor::getMapDefXLinkWidth()
insilmaril@97
  3617
{
insilmaril@97
  3618
	return defXLinkWidth;
insilmaril@0
  3619
}
insilmaril@0
  3620
insilmaril@398
  3621
void MapEditor::selectMapLinkColor()
insilmaril@0
  3622
{
insilmaril@97
  3623
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@0
  3624
	if ( !col.isValid() ) return;
insilmaril@398
  3625
	saveState (
insilmaril@424
  3626
		mapCenter,
insilmaril@398
  3627
		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
insilmaril@424
  3628
		mapCenter,
insilmaril@398
  3629
		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
insilmaril@497
  3630
		QString("Set map link color to %1").arg(col.name())
insilmaril@398
  3631
	);
insilmaril@398
  3632
	setMapDefLinkColor( col );
insilmaril@442
  3633
}
insilmaril@442
  3634
insilmaril@442
  3635
void MapEditor::selectMapSelectionColor()
insilmaril@442
  3636
{
insilmaril@442
  3637
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@442
  3638
	setSelectionColor (col);
insilmaril@442
  3639
}
insilmaril@442
  3640
insilmaril@442
  3641
void MapEditor::setSelectionColorInt (QColor col)
insilmaril@442
  3642
{
insilmaril@442
  3643
	if ( !col.isValid() ) return;
insilmaril@442
  3644
	xelection.setColor (col);
insilmaril@442
  3645
}
insilmaril@442
  3646
insilmaril@442
  3647
void MapEditor::setSelectionColor(QColor col)
insilmaril@442
  3648
{
insilmaril@442
  3649
	if ( !col.isValid() ) return;
insilmaril@442
  3650
	saveState (
insilmaril@442
  3651
		mapCenter,
insilmaril@442
  3652
		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
insilmaril@442
  3653
		mapCenter,
insilmaril@442
  3654
		QString("setSelectionColor (%1)").arg(col.name()),
insilmaril@442
  3655
		QString("Set color of selection box to %1").arg(col.name())
insilmaril@442
  3656
	);
insilmaril@442
  3657
	setSelectionColorInt (col);
insilmaril@442
  3658
}
insilmaril@442
  3659
insilmaril@442
  3660
QColor MapEditor::getSelectionColor()
insilmaril@442
  3661
{
insilmaril@442
  3662
	return xelection.getColor();
insilmaril@0
  3663
}
insilmaril@0
  3664
insilmaril@473
  3665
bool MapEditor::scrollBranch(BranchObj *bo)
insilmaril@0
  3666
{
insilmaril@427
  3667
	if (bo)
insilmaril@0
  3668
	{
insilmaril@427
  3669
		if (bo->isScrolled()) return false;
insilmaril@427
  3670
		if (bo->countBranches()==0) return false;
insilmaril@427
  3671
		if (bo->getDepth()==0) return false;
insilmaril@395
  3672
		QString u,r;
insilmaril@427
  3673
		r="scroll";
insilmaril@427
  3674
		u="unscroll";
insilmaril@395
  3675
		saveState(
insilmaril@424
  3676
			bo,
insilmaril@395
  3677
			QString ("%1 ()").arg(u),
insilmaril@424
  3678
			bo,
insilmaril@395
  3679
			QString ("%1 ()").arg(r),
insilmaril@395
  3680
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@395
  3681
		);
insilmaril@0
  3682
		bo->toggleScroll();
insilmaril@491
  3683
		xelection.update();
insilmaril@408
  3684
		scene()->update();
insilmaril@427
  3685
		return true;
insilmaril@427
  3686
	}	
insilmaril@427
  3687
	return false;
insilmaril@427
  3688
}
insilmaril@427
  3689
insilmaril@473
  3690
bool MapEditor::unscrollBranch(BranchObj *bo)
insilmaril@427
  3691
{
insilmaril@427
  3692
	if (bo)
insilmaril@427
  3693
	{
insilmaril@427
  3694
		if (!bo->isScrolled()) return false;
insilmaril@427
  3695
		if (bo->countBranches()==0) return false;
insilmaril@427
  3696
		if (bo->getDepth()==0) return false;
insilmaril@427
  3697
		QString u,r;
insilmaril@427
  3698
		u="scroll";
insilmaril@427
  3699
		r="unscroll";
insilmaril@427
  3700
		saveState(
insilmaril@427
  3701
			bo,
insilmaril@427
  3702
			QString ("%1 ()").arg(u),
insilmaril@427
  3703
			bo,
insilmaril@427
  3704
			QString ("%1 ()").arg(r),
insilmaril@427
  3705
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@427
  3706
		);
insilmaril@427
  3707
		bo->toggleScroll();
insilmaril@491
  3708
		xelection.update();
insilmaril@427
  3709
		scene()->update();
insilmaril@427
  3710
		return true;
insilmaril@427
  3711
	}	
insilmaril@427
  3712
	return false;
insilmaril@427
  3713
}
insilmaril@427
  3714
insilmaril@427
  3715
void MapEditor::toggleScroll()
insilmaril@427
  3716
{
insilmaril@427
  3717
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  3718
	if (xelection.type()==Selection::Branch )
insilmaril@427
  3719
	{
insilmaril@427
  3720
		if (bo->isScrolled())
insilmaril@473
  3721
			unscrollBranch (bo);
insilmaril@427
  3722
		else
insilmaril@473
  3723
			scrollBranch (bo);
insilmaril@0
  3724
	}
insilmaril@0
  3725
}
insilmaril@0
  3726
insilmaril@473
  3727
void MapEditor::unscrollChilds() 
insilmaril@0
  3728
{
insilmaril@428
  3729
	BranchObj *bo=xelection.getBranch();
insilmaril@428
  3730
	if (bo)
insilmaril@0
  3731
	{
insilmaril@428
  3732
		bo->first();
insilmaril@428
  3733
		while (bo) 
insilmaril@428
  3734
		{
insilmaril@473
  3735
			if (bo->isScrolled()) unscrollBranch (bo);
insilmaril@428
  3736
			bo=bo->next();
insilmaril@428
  3737
		}
insilmaril@428
  3738
	}	
insilmaril@0
  3739
}
insilmaril@0
  3740
insilmaril@432
  3741
FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
insilmaril@432
  3742
{
insilmaril@432
  3743
	BranchObj *bo=xelection.getBranch();
insilmaril@432
  3744
	if (bo)
insilmaril@432
  3745
	{
insilmaril@432
  3746
		FloatImageObj *fio;
insilmaril@432
  3747
		bo->addFloatImage();
insilmaril@432
  3748
		fio=bo->getLastFloatImage();
insilmaril@432
  3749
		fio->load(fn);
insilmaril@432
  3750
		mapCenter->reposition();
insilmaril@432
  3751
		scene()->update();
insilmaril@432
  3752
		return fio;
insilmaril@432
  3753
	}
insilmaril@432
  3754
	return NULL;
insilmaril@432
  3755
}	
insilmaril@428
  3756
insilmaril@0
  3757
void MapEditor::loadFloatImage ()
insilmaril@0
  3758
{
insilmaril@424
  3759
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3760
	if (bo)
insilmaril@0
  3761
	{
insilmaril@0
  3762
insilmaril@366
  3763
		Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@366
  3764
		fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@0
  3765
		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@0
  3766
		ImagePreview *p =new ImagePreview (fd);
insilmaril@0
  3767
		fd->setContentsPreviewEnabled( TRUE );
insilmaril@0
  3768
		fd->setContentsPreview( p, p );
insilmaril@366
  3769
		fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@404
  3770
		fd->setCaption(vymName+" - " +tr("Load image"));
insilmaril@0
  3771
		fd->setDir (lastImageDir);
insilmaril@0
  3772
		fd->show();
insilmaril@0
  3773
insilmaril@0
  3774
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  3775
		{
insilmaril@491
  3776
			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
insilmaril@366
  3777
			lastImageDir=QDir (fd->dirPath());
insilmaril@432
  3778
			QString s;
insilmaril@395
  3779
			FloatImageObj *fio;
insilmaril@432
  3780
			for (int j=0; j<fd->selectedFiles().count(); j++)
insilmaril@185
  3781
			{
insilmaril@432
  3782
				s=fd->selectedFiles().at(j);
insilmaril@432
  3783
				fio=loadFloatImageInt (s);
insilmaril@432
  3784
				if (fio)
insilmaril@432
  3785
					saveState(
insilmaril@432
  3786
						(LinkableMapObj*)fio,
insilmaril@432
  3787
						"delete ()",
insilmaril@432
  3788
						bo, 
insilmaril@432
  3789
						QString ("loadImage (%1)").arg(s ),
insilmaril@432
  3790
						QString("Add image %1 to %2").arg(s).arg(getName(bo))
insilmaril@432
  3791
					);
insilmaril@432
  3792
				else
insilmaril@491
  3793
					// TODO loadFIO error handling
insilmaril@432
  3794
					qWarning ("Failed to load "+s);
insilmaril@185
  3795
			}
insilmaril@0
  3796
		}
insilmaril@236
  3797
		delete (p);
insilmaril@236
  3798
		delete (fd);
insilmaril@0
  3799
	}
insilmaril@0
  3800
}
insilmaril@0
  3801
insilmaril@434
  3802
void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
insilmaril@434
  3803
{
insilmaril@434
  3804
	fio->save (fn,type);
insilmaril@434
  3805
}
insilmaril@434
  3806
insilmaril@366
  3807
void MapEditor::saveFloatImage ()
insilmaril@0
  3808
{
insilmaril@424
  3809
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  3810
	if (fio)
insilmaril@0
  3811
	{
insilmaril@366
  3812
		QFileDialog *fd=new QFileDialog( this);
insilmaril@366
  3813
		fd->setFilters (imageIO.getFilters());
insilmaril@404
  3814
		fd->setCaption(vymName+" - " +tr("Save image"));
insilmaril@366
  3815
		fd->setFileMode( QFileDialog::AnyFile );
insilmaril@366
  3816
		fd->setDirectory (lastImageDir);
insilmaril@366
  3817
//		fd->setSelection (fio->getOriginalFilename());
insilmaril@0
  3818
		fd->show();
insilmaril@0
  3819
insilmaril@0
  3820
		QString fn;
insilmaril@434
  3821
		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
insilmaril@0
  3822
		{
insilmaril@434
  3823
			fn=fd->selectedFiles().at(0);
insilmaril@434
  3824
			if (QFile (fn).exists() )
insilmaril@0
  3825
			{
insilmaril@404
  3826
				QMessageBox mb( vymName,
insilmaril@159
  3827
					tr("The file %1 exists already.\n"
insilmaril@434
  3828
					"Do you want to overwrite it?").arg(fn),
insilmaril@0
  3829
				QMessageBox::Warning,
insilmaril@0
  3830
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  3831
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  3832
				QMessageBox::QMessageBox::NoButton );
insilmaril@0
  3833
insilmaril@0
  3834
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  3835
				mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  3836
				switch( mb.exec() ) 
insilmaril@0
  3837
				{
insilmaril@0
  3838
					case QMessageBox::Yes:
insilmaril@0
  3839
						// save 
insilmaril@0
  3840
						break;;
insilmaril@0
  3841
					case QMessageBox::Cancel:
insilmaril@0
  3842
						// do nothing
insilmaril@377
  3843
						delete (fd);
insilmaril@0
  3844
						return;
insilmaril@0
  3845
						break;
insilmaril@0
  3846
				}
insilmaril@0
  3847
			}
insilmaril@434
  3848
			saveFloatImageInt (fio,fd->selectedFilter(),fn );
insilmaril@0
  3849
		}
insilmaril@377
  3850
		delete (fd);
insilmaril@0
  3851
	}
insilmaril@0
  3852
}
insilmaril@0
  3853
insilmaril@473
  3854
void MapEditor::setFrameType(const FrameObj::FrameType &t)
insilmaril@0
  3855
{
insilmaril@424
  3856
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3857
	if (bo)
insilmaril@0
  3858
	{
insilmaril@473
  3859
		QString s=bo->getFrameTypeName();
insilmaril@424
  3860
		bo->setFrameType (t);
insilmaril@473
  3861
		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
insilmaril@473
  3862
			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
insilmaril@0
  3863
		mapCenter->reposition();
insilmaril@424
  3864
		bo->updateLink();
insilmaril@0
  3865
	}
insilmaril@0
  3866
}
insilmaril@0
  3867
insilmaril@473
  3868
void MapEditor::setFrameType(const QString &s)	
insilmaril@445
  3869
{
insilmaril@445
  3870
	BranchObj *bo=xelection.getBranch();
insilmaril@445
  3871
	if (bo)
insilmaril@445
  3872
	{
insilmaril@473
  3873
		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
insilmaril@473
  3874
			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
insilmaril@445
  3875
		bo->setFrameType (s);
insilmaril@445
  3876
		mapCenter->reposition();
insilmaril@445
  3877
		bo->updateLink();
insilmaril@445
  3878
	}
insilmaril@445
  3879
}
insilmaril@445
  3880
insilmaril@473
  3881
void MapEditor::setFramePenColor(const QColor &c)	
insilmaril@442
  3882
{
insilmaril@442
  3883
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3884
	if (bo)
insilmaril@473
  3885
	{
insilmaril@473
  3886
		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
insilmaril@473
  3887
			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
insilmaril@442
  3888
		bo->setFramePenColor (c);
insilmaril@473
  3889
	}	
insilmaril@442
  3890
}
insilmaril@442
  3891
insilmaril@473
  3892
void MapEditor::setFrameBrushColor(const QColor &c)	
insilmaril@442
  3893
{
insilmaril@442
  3894
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3895
	if (bo)
insilmaril@473
  3896
	{
insilmaril@473
  3897
		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
insilmaril@473
  3898
			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
insilmaril@442
  3899
		bo->setFrameBrushColor (c);
insilmaril@473
  3900
	}	
insilmaril@473
  3901
}
insilmaril@473
  3902
insilmaril@486
  3903
void MapEditor::setFramePadding (const int &i)
insilmaril@473
  3904
{
insilmaril@473
  3905
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  3906
	if (bo)
insilmaril@473
  3907
	{
insilmaril@486
  3908
		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
insilmaril@486
  3909
			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
insilmaril@486
  3910
		bo->setFramePadding (i);
insilmaril@486
  3911
		mapCenter->reposition();
insilmaril@486
  3912
		bo->updateLink();
insilmaril@473
  3913
	}	
insilmaril@473
  3914
}
insilmaril@473
  3915
insilmaril@486
  3916
void MapEditor::setFrameBorderWidth(const int &i)
insilmaril@473
  3917
{
insilmaril@473
  3918
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  3919
	if (bo)
insilmaril@473
  3920
	{
insilmaril@486
  3921
		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
insilmaril@486
  3922
			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
insilmaril@486
  3923
		bo->setFrameBorderWidth (i);
insilmaril@486
  3924
		mapCenter->reposition();
insilmaril@486
  3925
		bo->updateLink();
insilmaril@473
  3926
	}	
insilmaril@442
  3927
}
insilmaril@442
  3928
insilmaril@437
  3929
void MapEditor::setIncludeImagesVer(bool b)	
insilmaril@175
  3930
{
insilmaril@424
  3931
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3932
	if (bo)
insilmaril@424
  3933
	{
insilmaril@434
  3934
		QString u= b ? "false" : "true";
insilmaril@434
  3935
		QString r=!b ? "false" : "true";
insilmaril@434
  3936
		
insilmaril@434
  3937
		saveState(
insilmaril@434
  3938
			bo,
insilmaril@434
  3939
			QString("setIncludeImagesVertically (%1)").arg(u),
insilmaril@434
  3940
			bo, 
insilmaril@434
  3941
			QString("setIncludeImagesVertically (%1)").arg(r),
insilmaril@434
  3942
			QString("Include images vertically in %1").arg(getName(bo))
insilmaril@434
  3943
		);	
insilmaril@424
  3944
		bo->setIncludeImagesVer(b);
insilmaril@175
  3945
		mapCenter->reposition();
insilmaril@424
  3946
	}	
insilmaril@175
  3947
}
insilmaril@175
  3948
insilmaril@437
  3949
void MapEditor::setIncludeImagesHor(bool b)	
insilmaril@175
  3950
{
insilmaril@424
  3951
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3952
	if (bo)
insilmaril@424
  3953
	{
insilmaril@434
  3954
		QString u= b ? "false" : "true";
insilmaril@434
  3955
		QString r=!b ? "false" : "true";
insilmaril@434
  3956
		
insilmaril@434
  3957
		saveState(
insilmaril@434
  3958
			bo,
insilmaril@434
  3959
			QString("setIncludeImagesHorizontally (%1)").arg(u),
insilmaril@434
  3960
			bo, 
insilmaril@434
  3961
			QString("setIncludeImagesHorizontally (%1)").arg(r),
insilmaril@434
  3962
			QString("Include images horizontally in %1").arg(getName(bo))
insilmaril@434
  3963
		);	
insilmaril@424
  3964
		bo->setIncludeImagesHor(b);
insilmaril@175
  3965
		mapCenter->reposition();
insilmaril@424
  3966
	}	
insilmaril@175
  3967
}
insilmaril@175
  3968
insilmaril@491
  3969
void MapEditor::setHideLinkUnselected (bool b)
insilmaril@160
  3970
{
insilmaril@424
  3971
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  3972
	if (sel &&
insilmaril@491
  3973
		(xelection.type() == Selection::Branch || 
insilmaril@491
  3974
		xelection.type() == Selection::MapCenter  ||
insilmaril@491
  3975
		xelection.type() == Selection::FloatImage ))
insilmaril@491
  3976
	{
insilmaril@491
  3977
		QString u= b ? "false" : "true";
insilmaril@491
  3978
		QString r=!b ? "false" : "true";
insilmaril@491
  3979
		
insilmaril@491
  3980
		saveState(
insilmaril@491
  3981
			sel,
insilmaril@491
  3982
			QString("setHideLinkUnselected (%1)").arg(u),
insilmaril@491
  3983
			sel, 
insilmaril@491
  3984
			QString("setHideLinkUnselected (%1)").arg(r),
insilmaril@491
  3985
			QString("Hide link of %1 if unselected").arg(getName(sel))
insilmaril@491
  3986
		);	
insilmaril@424
  3987
		sel->setHideLinkUnselected(b);
insilmaril@491
  3988
	}
insilmaril@160
  3989
}
insilmaril@160
  3990
insilmaril@491
  3991
void MapEditor::importDirInt(BranchObj *dst, QDir d)
insilmaril@0
  3992
{
insilmaril@424
  3993
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3994
	if (bo)
insilmaril@0
  3995
	{
insilmaril@0
  3996
		// Traverse directories
insilmaril@0
  3997
		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  3998
		QFileInfoList list = d.entryInfoList();
insilmaril@366
  3999
		QFileInfo fi;
insilmaril@366
  4000
insilmaril@366
  4001
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4002
		{
insilmaril@366
  4003
			fi=list.at(i);
insilmaril@366
  4004
			if (fi.fileName() != "." && fi.fileName() != ".." )
insilmaril@0
  4005
			{
insilmaril@0
  4006
				dst->addBranch();
insilmaril@0
  4007
				bo=dst->getLastBranch();
insilmaril@366
  4008
				bo->setHeading (fi.fileName() );
insilmaril@243
  4009
				bo->setColor (QColor("blue"));
insilmaril@0
  4010
				bo->toggleScroll();
insilmaril@366
  4011
				if ( !d.cd(fi.fileName()) ) 
insilmaril@366
  4012
					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
insilmaril@0
  4013
				else 
insilmaril@0
  4014
				{
insilmaril@103
  4015
					// Recursively add subdirs
insilmaril@366
  4016
					importDirInt (bo,d);
insilmaril@0
  4017
					d.cdUp();
insilmaril@0
  4018
				}
insilmaril@0
  4019
			}	
insilmaril@0
  4020
		}		
insilmaril@0
  4021
		// Traverse files
insilmaril@0
  4022
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  4023
		list = d.entryInfoList();
insilmaril@366
  4024
insilmaril@366
  4025
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4026
		{
insilmaril@366
  4027
			fi=list.at(i);
insilmaril@0
  4028
			dst->addBranch();
insilmaril@0
  4029
			bo=dst->getLastBranch();
insilmaril@366
  4030
			bo->setHeading (fi.fileName() );
insilmaril@243
  4031
			bo->setColor (QColor("black"));
insilmaril@366
  4032
			if (fi.fileName().right(4) == ".vym" )
insilmaril@366
  4033
				bo->setVymLink (fi.filePath());
insilmaril@0
  4034
		}	
insilmaril@0
  4035
	}		
insilmaril@0
  4036
}
insilmaril@0
  4037
insilmaril@491
  4038
void MapEditor::importDirInt (const QString &s)
insilmaril@491
  4039
{
insilmaril@491
  4040
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  4041
	if (bo)
insilmaril@491
  4042
	{
insilmaril@491
  4043
		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
insilmaril@491
  4044
insilmaril@491
  4045
		QDir d(s);
insilmaril@491
  4046
		importDirInt (bo,d);
insilmaril@491
  4047
	}
insilmaril@491
  4048
}	
insilmaril@491
  4049
insilmaril@0
  4050
void MapEditor::importDir()
insilmaril@0
  4051
{
insilmaril@424
  4052
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4053
	if (bo)
insilmaril@0
  4054
	{
insilmaril@404
  4055
		QStringList filters;
insilmaril@404
  4056
		filters <<"VYM map (*.vym)";
insilmaril@404
  4057
		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
insilmaril@404
  4058
		fd->setMode (QFileDialog::DirectoryOnly);
insilmaril@404
  4059
		fd->setFilters (filters);
insilmaril@404
  4060
		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
insilmaril@0
  4061
		fd->show();
insilmaril@0
  4062
insilmaril@0
  4063
		QString fn;
insilmaril@0
  4064
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  4065
		{
insilmaril@491
  4066
			importDirInt (fd->selectedFile() );
insilmaril@0
  4067
			mapCenter->reposition();
insilmaril@408
  4068
			scene()->update();
insilmaril@0
  4069
		}
insilmaril@0
  4070
	}	
insilmaril@0
  4071
}
insilmaril@0
  4072
insilmaril@95
  4073
void MapEditor::followXLink(int i)
insilmaril@89
  4074
{
insilmaril@424
  4075
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4076
	if (bo)
insilmaril@89
  4077
	{
insilmaril@424
  4078
		bo=bo->XLinkTargetAt(i);
insilmaril@97
  4079
		if (bo) 
insilmaril@97
  4080
		{
insilmaril@424
  4081
			xelection.select(bo);
insilmaril@97
  4082
			ensureSelectionVisible();
insilmaril@97
  4083
		}
insilmaril@89
  4084
	}
insilmaril@89
  4085
}
insilmaril@89
  4086
insilmaril@421
  4087
void MapEditor::editXLink(int i)	// FIXME missing saveState
insilmaril@94
  4088
{
insilmaril@424
  4089
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4090
	if (bo)
insilmaril@94
  4091
	{
insilmaril@424
  4092
		XLinkObj *xlo=bo->XLinkAt(i);
insilmaril@97
  4093
		if (xlo) 
insilmaril@94
  4094
		{
insilmaril@97
  4095
			EditXLinkDialog dia;
insilmaril@97
  4096
			dia.setXLink (xlo);
insilmaril@424
  4097
			dia.setSelection(bo);
insilmaril@97
  4098
			if (dia.exec() == QDialog::Accepted)
insilmaril@97
  4099
			{
insilmaril@97
  4100
				if (dia.useSettingsGlobal() )
insilmaril@97
  4101
				{
insilmaril@398
  4102
					setMapDefXLinkColor (xlo->getColor() );
insilmaril@398
  4103
					setMapDefXLinkWidth (xlo->getWidth() );
insilmaril@97
  4104
				}
insilmaril@97
  4105
				if (dia.deleteXLink())
insilmaril@424
  4106
					bo->deleteXLinkAt(i);
insilmaril@97
  4107
			}
insilmaril@97
  4108
		}	
insilmaril@97
  4109
	}
insilmaril@94
  4110
}
insilmaril@94
  4111
insilmaril@527
  4112
void MapEditor::testFunction1()
insilmaril@0
  4113
{
insilmaril@564
  4114
	ErrorCode err=success;
insilmaril@564
  4115
	LoadMode lmode=NewMap;
insilmaril@564
  4116
insilmaril@564
  4117
	//QString fname="test/freemind/doc/freemind.xml";
insilmaril@564
  4118
	QString fname="test/freemind/doc/icons.mm";
insilmaril@564
  4119
    parseFMHandler handler;
insilmaril@564
  4120
	QFile file( fname );
insilmaril@564
  4121
insilmaril@564
  4122
	// I am paranoid: file should exist anyway
insilmaril@564
  4123
	// according to check in mainwindow.
insilmaril@564
  4124
	if (!file.exists() )
insilmaril@564
  4125
	{
insilmaril@564
  4126
		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@564
  4127
				   tr("Couldn't open map " +fname)+".");
insilmaril@564
  4128
		err=aborted;	
insilmaril@564
  4129
	} else
insilmaril@564
  4130
	{
insilmaril@564
  4131
		bool blockSaveStateOrg=blockSaveState;
insilmaril@564
  4132
		blockReposition=true;
insilmaril@564
  4133
		blockSaveState=true;
insilmaril@564
  4134
		QXmlInputSource source( file);
insilmaril@564
  4135
		QXmlSimpleReader reader;
insilmaril@564
  4136
		reader.setContentHandler( &handler );
insilmaril@564
  4137
		reader.setErrorHandler( &handler );
insilmaril@564
  4138
		handler.setMapEditor( this );
insilmaril@564
  4139
insilmaril@564
  4140
insilmaril@564
  4141
		// We need to set the tmpDir in order  to load files with rel. path
insilmaril@564
  4142
		QString tmpdir= fname.left(fname.findRev("/",-1));	
insilmaril@564
  4143
		handler.setTmpDir (tmpdir);
insilmaril@564
  4144
		handler.setInputFile (file.name());
insilmaril@564
  4145
		//handler.setLoadMode (lmode);
insilmaril@564
  4146
		bool ok = reader.parse( source );
insilmaril@564
  4147
		blockReposition=false;
insilmaril@564
  4148
		blockSaveState=blockSaveStateOrg;
insilmaril@564
  4149
		file.close();
insilmaril@564
  4150
		if ( ok ) 
insilmaril@564
  4151
		{
insilmaril@564
  4152
			mapCenter->reposition();
insilmaril@564
  4153
			xelection.update();
insilmaril@564
  4154
			if (lmode==NewMap)
insilmaril@564
  4155
			{
insilmaril@564
  4156
				mapDefault=false;
insilmaril@564
  4157
				mapChanged=false;
insilmaril@564
  4158
				mapUnsaved=false;
insilmaril@564
  4159
				autosaveTimer->stop();
insilmaril@564
  4160
			}
insilmaril@564
  4161
		} else 
insilmaril@564
  4162
		{
insilmaril@564
  4163
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@564
  4164
					   tr( handler.errorProtocol() ) );
insilmaril@564
  4165
			// returnCode=1;	
insilmaril@564
  4166
			// Still return "success": the map maybe at least
insilmaril@564
  4167
			// partially read by the parser
insilmaril@564
  4168
		}	
insilmaril@564
  4169
	}	
insilmaril@564
  4170
	updateActions();
insilmaril@564
  4171
	//return err;
insilmaril@527
  4172
/*
insilmaril@473
  4173
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4174
	if (bo) animObjList.append( bo );
insilmaril@527
  4175
*/	
insilmaril@432
  4176
	
insilmaril@432
  4177
/*
insilmaril@314
  4178
	WarningDialog dia;
insilmaril@388
  4179
	dia.showCancelButton (true);
insilmaril@314
  4180
	dia.setText("This is a longer \nWarning");
insilmaril@314
  4181
	dia.setCaption("Warning: Flux problem");
insilmaril@432
  4182
	dia.setShowAgainName("mapeditor/testDialog");
insilmaril@314
  4183
	if (dia.exec()==QDialog::Accepted)
insilmaril@314
  4184
		cout << "accepted!\n";
insilmaril@314
  4185
	else	
insilmaril@314
  4186
		cout << "canceled!\n";
insilmaril@301
  4187
	return;
insilmaril@432
  4188
*/
insilmaril@366
  4189
insilmaril@420
  4190
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
insilmaril@260
  4191
	if (hidemode==HideNone)
insilmaril@185
  4192
	{
insilmaril@260
  4193
		setHideTmpMode (HideExport);
insilmaril@260
  4194
		mapCenter->calcBBoxSizeWithChilds();
insilmaril@408
  4195
		QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@408
  4196
		QRectF mapRect=totalBBox;
insilmaril@260
  4197
		QCanvasRectangle *frame=NULL;
insilmaril@260
  4198
insilmaril@260
  4199
		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
insilmaril@260
  4200
	
insilmaril@260
  4201
		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
insilmaril@260
  4202
			totalBBox.width(), totalBBox.height());
insilmaril@408
  4203
		frame=new QCanvasRectangle (mapRect,mapScene);
insilmaril@260
  4204
		frame->setBrush (QColor(white));
insilmaril@260
  4205
		frame->setPen (QColor(black));
insilmaril@408
  4206
		frame->setZValue(0);
insilmaril@260
  4207
		frame->show();    
insilmaril@260
  4208
	}	
insilmaril@260
  4209
	else	
insilmaril@260
  4210
	{
insilmaril@260
  4211
		setHideTmpMode (HideNone);
insilmaril@260
  4212
	}	
insilmaril@260
  4213
	cout <<"  hidemode="<<hidemode<<endl;
insilmaril@301
  4214
	*/
insilmaril@527
  4215
}	
insilmaril@527
  4216
	
insilmaril@527
  4217
void MapEditor::testFunction2()
insilmaril@527
  4218
{
insilmaril@105
  4219
}
insilmaril@105
  4220
insilmaril@408
  4221
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
insilmaril@0
  4222
{
insilmaril@0
  4223
	// Lineedits are already closed by preceding
insilmaril@0
  4224
	// mouseEvent, we don't need to close here.
insilmaril@0
  4225
insilmaril@408
  4226
    QPointF p = mapToScene(e->pos());
insilmaril@0
  4227
    LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
insilmaril@0
  4228
	
insilmaril@0
  4229
    if (lmo) 
insilmaril@0
  4230
	{	// MapObj was found
insilmaril@424
  4231
		if (xelection.single() != lmo)
insilmaril@0
  4232
		{
insilmaril@0
  4233
			// select the MapObj
insilmaril@424
  4234
			xelection.select(lmo);
insilmaril@0
  4235
		}
insilmaril@0
  4236
		// Context Menu 
insilmaril@424
  4237
		if (xelection.getBranch() ) 
insilmaril@0
  4238
		{
insilmaril@424
  4239
			// Context Menu on branch or mapcenter
insilmaril@424
  4240
			updateActions();
insilmaril@424
  4241
			branchContextMenu->popup(e->globalPos() );
insilmaril@424
  4242
		} else
insilmaril@424
  4243
		{
insilmaril@424
  4244
			if (xelection.getFloatImage() )
insilmaril@0
  4245
			{
insilmaril@0
  4246
				// Context Menu on floatimage
insilmaril@0
  4247
				updateActions();
insilmaril@0
  4248
				floatimageContextMenu->popup(e->globalPos() );
insilmaril@0
  4249
			}	
insilmaril@0
  4250
		}	
insilmaril@0
  4251
	} else 
insilmaril@0
  4252
	{ // No MapObj found, we are on the Canvas itself
insilmaril@408
  4253
		// Context Menu on scene
insilmaril@0
  4254
		updateActions();
insilmaril@0
  4255
		canvasContextMenu->popup(e->globalPos() );
insilmaril@0
  4256
    } 
insilmaril@329
  4257
	e->accept();
insilmaril@0
  4258
}
insilmaril@0
  4259
insilmaril@398
  4260
void MapEditor::keyPressEvent(QKeyEvent* e)
insilmaril@398
  4261
{
insilmaril@411
  4262
	if (e->modifiers() & Qt::ControlModifier)
insilmaril@398
  4263
	{
insilmaril@398
  4264
		switch (mainWindow->getModMode())
insilmaril@398
  4265
		{
insilmaril@473
  4266
			case Main::ModModeColor: 
insilmaril@398
  4267
				setCursor (PickColorCursor);
insilmaril@398
  4268
				break;
insilmaril@473
  4269
			case Main::ModModeCopy: 
insilmaril@398
  4270
				setCursor (CopyCursor);
insilmaril@398
  4271
				break;
insilmaril@473
  4272
			case Main::ModModeXLink: 
insilmaril@398
  4273
				setCursor (XLinkCursor);
insilmaril@398
  4274
				break;
insilmaril@398
  4275
			default :
insilmaril@398
  4276
				setCursor (Qt::ArrowCursor);
insilmaril@398
  4277
				break;
insilmaril@398
  4278
		} 
insilmaril@398
  4279
	}	
insilmaril@398
  4280
}
insilmaril@398
  4281
insilmaril@398
  4282
void MapEditor::keyReleaseEvent(QKeyEvent* e)
insilmaril@398
  4283
{
insilmaril@411
  4284
	if (!(e->modifiers() & Qt::ControlModifier))
insilmaril@398
  4285
		setCursor (Qt::ArrowCursor);
insilmaril@398
  4286
}
insilmaril@398
  4287
insilmaril@408
  4288
void MapEditor::mousePressEvent(QMouseEvent* e)
insilmaril@0
  4289
{
insilmaril@329
  4290
	// Ignore right clicks, these will go to context menus
insilmaril@366
  4291
	if (e->button() == Qt::RightButton )
insilmaril@329
  4292
	{
insilmaril@329
  4293
		e->ignore();
insilmaril@329
  4294
		return;
insilmaril@329
  4295
	}
insilmaril@329
  4296
insilmaril@491
  4297
	//Ignore clicks while editing heading
insilmaril@491
  4298
	if (isSelectBlocked() ) 
insilmaril@491
  4299
	{
insilmaril@491
  4300
		e->ignore();
insilmaril@491
  4301
		return;
insilmaril@491
  4302
	}
insilmaril@491
  4303
insilmaril@408
  4304
    QPointF p = mapToScene(e->pos());
insilmaril@0
  4305
    LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
insilmaril@0
  4306
	
insilmaril@329
  4307
	e->accept();
insilmaril@329
  4308
insilmaril@442
  4309
	//Take care of  system flags _or_ modifier modes
insilmaril@267
  4310
	//
insilmaril@267
  4311
	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@267
  4312
		typeid(*lmo)==typeid(MapCenterObj) ))
insilmaril@267
  4313
	{
insilmaril@267
  4314
		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
insilmaril@267
  4315
		if (!foname.isEmpty())
insilmaril@267
  4316
		{
insilmaril@267
  4317
			// systemFlag clicked
insilmaril@366
  4318
			selectInt (lmo);
insilmaril@267
  4319
			if (foname=="url") 
insilmaril@267
  4320
			{
insilmaril@366
  4321
				if (e->state() & Qt::ControlModifier)
insilmaril@267
  4322
					mainWindow->editOpenURLTab();
insilmaril@267
  4323
				else	
insilmaril@267
  4324
					mainWindow->editOpenURL();
insilmaril@267
  4325
			}	
insilmaril@267
  4326
			else if (foname=="vymLink")
insilmaril@267
  4327
			{
insilmaril@267
  4328
				mainWindow->editOpenVymLink();
insilmaril@267
  4329
				// tabWidget may change, better return now
insilmaril@267
  4330
				// before segfaulting...
insilmaril@267
  4331
			} else if (foname=="note")
insilmaril@267
  4332
				mainWindow->windowToggleNoteEditor();
insilmaril@267
  4333
			else if (foname=="hideInExport")		
insilmaril@267
  4334
				toggleHideExport();
insilmaril@442
  4335
			xelection.update();	
insilmaril@267
  4336
			return;	
insilmaril@267
  4337
		} 
insilmaril@267
  4338
	} 
insilmaril@442
  4339
insilmaril@442
  4340
	// No system flag clicked, take care of modmodes (CTRL-Click)
insilmaril@366
  4341
	if (e->state() & Qt::ControlModifier)
insilmaril@0
  4342
	{
insilmaril@473
  4343
		if (mainWindow->getModMode()==Main::ModModeColor)
insilmaril@83
  4344
		{
insilmaril@83
  4345
				pickingColor=true;
insilmaril@398
  4346
				setCursor (PickColorCursor);
insilmaril@83
  4347
				return;
insilmaril@83
  4348
		} 
insilmaril@473
  4349
		if (mainWindow->getModMode()==Main::ModModeXLink)
insilmaril@83
  4350
		{	
insilmaril@90
  4351
			BranchObj *bo_begin=NULL;
insilmaril@90
  4352
			if (lmo)
insilmaril@90
  4353
				bo_begin=(BranchObj*)(lmo);
insilmaril@90
  4354
			else	
insilmaril@424
  4355
				if (xelection.getBranch() ) 
insilmaril@424
  4356
					bo_begin=xelection.getBranch();
insilmaril@90
  4357
			if (bo_begin)	
insilmaril@83
  4358
			{
insilmaril@83
  4359
				drawingLink=true;
insilmaril@90
  4360
				linkingObj_src=bo_begin;
insilmaril@408
  4361
				tmpXLink=new XLinkObj (mapScene);
insilmaril@95
  4362
				tmpXLink->setBegin (bo_begin);
insilmaril@95
  4363
				tmpXLink->setEnd   (p);
insilmaril@97
  4364
				tmpXLink->setColor(defXLinkColor);
insilmaril@97
  4365
				tmpXLink->setWidth(defXLinkWidth);
insilmaril@95
  4366
				tmpXLink->updateXLink();
insilmaril@95
  4367
				tmpXLink->setVisibility (true);
insilmaril@83
  4368
				return;
insilmaril@89
  4369
			} 
insilmaril@267
  4370
		}
insilmaril@442
  4371
	}	// End of modmodes
insilmaril@442
  4372
insilmaril@0
  4373
    if (lmo) 
insilmaril@267
  4374
	{	
insilmaril@442
  4375
		// Select the clicked object
insilmaril@366
  4376
		selectInt (lmo);
insilmaril@442
  4377
insilmaril@0
  4378
		// Left Button	    Move Branches
insilmaril@366
  4379
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4380
		{
insilmaril@424
  4381
			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
insilmaril@424
  4382
			//movingObj_start.setY( p.y() - selection->y() );	
insilmaril@424
  4383
			movingObj_start.setX( p.x() - lmo->x() );	
insilmaril@424
  4384
			movingObj_start.setY( p.y() - lmo->y() );	
insilmaril@129
  4385
			movingObj_orgPos.setX (lmo->x() );
insilmaril@129
  4386
			movingObj_orgPos.setY (lmo->y() );
insilmaril@366
  4387
			movingObj_orgRelPos=lmo->getRelPos();
insilmaril@129
  4388
insilmaril@93
  4389
			// If modMode==copy, then we want to "move" the _new_ object around
insilmaril@93
  4390
			// then we need the offset from p to the _old_ selection, because of tmp
insilmaril@473
  4391
			if (mainWindow->getModMode()==Main::ModModeCopy &&
insilmaril@366
  4392
				e->state() & Qt::ControlModifier)
insilmaril@93
  4393
			{
insilmaril@491
  4394
				if (xelection.type()==Selection::Branch)
insilmaril@93
  4395
				{
insilmaril@93
  4396
					copyingObj=true;
insilmaril@424
  4397
					mapCenter->addBranch ((BranchObj*)xelection.single());
insilmaril@93
  4398
					unselect();
insilmaril@424
  4399
					xelection.select(mapCenter->getLastBranch());
insilmaril@104
  4400
					mapCenter->reposition();
insilmaril@93
  4401
				}
insilmaril@421
  4402
			} 
insilmaril@421
  4403
insilmaril@424
  4404
			movingObj=xelection.single();	
insilmaril@0
  4405
		} else
insilmaril@0
  4406
			// Middle Button    Toggle Scroll
insilmaril@0
  4407
			// (On Mac OS X this won't work, but we still have 
insilmaril@0
  4408
			// a button in the toolbar)
insilmaril@366
  4409
			if (e->button() == Qt::MidButton )
insilmaril@0
  4410
				toggleScroll();
insilmaril@0
  4411
		updateActions();
insilmaril@442
  4412
		xelection.update();
insilmaril@0
  4413
	} else 
insilmaril@408
  4414
	{ // No MapObj found, we are on the scene itself
insilmaril@408
  4415
		// Left Button	    move Pos of sceneView
insilmaril@366
  4416
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4417
		{
insilmaril@0
  4418
			movingObj=NULL;	// move Content not Obj
insilmaril@0
  4419
			movingObj_start=e->globalPos();
insilmaril@408
  4420
			movingCont_start=QPointF (
insilmaril@408
  4421
				horizontalScrollBar()->value(),
insilmaril@408
  4422
				verticalScrollBar()->value());
insilmaril@408
  4423
			movingVec=QPointF(0,0);
insilmaril@398
  4424
			setCursor(HandOpenCursor);
insilmaril@0
  4425
		} 
insilmaril@0
  4426
    } 
insilmaril@0
  4427
}
insilmaril@0
  4428
insilmaril@408
  4429
void MapEditor::mouseMoveEvent(QMouseEvent* e)
insilmaril@0
  4430
{
insilmaril@408
  4431
    QPointF p = mapToScene(e->pos());
insilmaril@424
  4432
	LinkableMapObj *lmosel=xelection.single();
insilmaril@83
  4433
insilmaril@0
  4434
    // Move the selected MapObj
insilmaril@424
  4435
    if ( lmosel && movingObj) 
insilmaril@0
  4436
    {	
insilmaril@421
  4437
		// reset cursor if we are moving and don't copy
insilmaril@473
  4438
		if (mainWindow->getModMode()!=Main::ModModeCopy)
insilmaril@421
  4439
			setCursor (Qt::ArrowCursor);
insilmaril@421
  4440
insilmaril@408
  4441
		// To avoid jumping of the sceneView, only 
insilmaril@164
  4442
		// ensureSelectionVisible, if not tmp linked
insilmaril@424
  4443
		if (!lmosel->hasParObjTmp())
insilmaril@164
  4444
			ensureSelectionVisible ();
insilmaril@0
  4445
		
insilmaril@83
  4446
		// Now move the selection, but add relative position 
insilmaril@83
  4447
		// (movingObj_start) where selection was chosen with 
insilmaril@83
  4448
		// mousepointer. (This avoids flickering resp. jumping 
insilmaril@0
  4449
		// of selection back to absPos)
insilmaril@0
  4450
		
insilmaril@0
  4451
		// Check if we could link 
insilmaril@0
  4452
		LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
insilmaril@0
  4453
		
insilmaril@0
  4454
insilmaril@424
  4455
		FloatObj *fio=xelection.getFloatImage();
insilmaril@424
  4456
		if (fio)
insilmaril@0
  4457
		{
insilmaril@424
  4458
			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@424
  4459
			fio->setRelPos();
insilmaril@424
  4460
			fio->updateLink(); //no need for reposition, if we update link here
insilmaril@442
  4461
			xelection.update();
insilmaril@0
  4462
insilmaril@0
  4463
			// Relink float to new mapcenter or branch, if shift is pressed	
insilmaril@0
  4464
			// Only relink, if selection really has a new parent
insilmaril@388
  4465
			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
insilmaril@0
  4466
				( (typeid(*lmo)==typeid(BranchObj)) ||
insilmaril@0
  4467
				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
insilmaril@424
  4468
				( lmo != fio->getParObj())  
insilmaril@0
  4469
				)
insilmaril@0
  4470
			{
insilmaril@424
  4471
				if (typeid(*fio) == typeid(FloatImageObj) && 
insilmaril@420
  4472
				( (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@420
  4473
				  typeid(*lmo)==typeid(MapCenterObj)) ))  
insilmaril@0
  4474
				{
insilmaril@420
  4475
insilmaril@420
  4476
					// Also save the move which was done so far
insilmaril@420
  4477
					QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@420
  4478
					QString pnow=qpointfToString(fio->getRelPos());
insilmaril@420
  4479
					saveState(
insilmaril@424
  4480
						fio,
insilmaril@420
  4481
						"moveRel "+pold,
insilmaril@424
  4482
						fio,
insilmaril@420
  4483
						"moveRel "+pnow,
insilmaril@424
  4484
						QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
insilmaril@420
  4485
					fio->getParObj()->requestReposition();
insilmaril@420
  4486
					mapCenter->reposition();
insilmaril@420
  4487
insilmaril@420
  4488
					linkTo (lmo->getSelectString());
insilmaril@442
  4489
					//movingObj=lmosel;
insilmaril@442
  4490
					//movingObj_orgRelPos=lmosel->getRelPos();	
insilmaril@420
  4491
insilmaril@420
  4492
					mapCenter->reposition();
insilmaril@0
  4493
				}	
insilmaril@0
  4494
			}
insilmaril@388
  4495
		} else	
insilmaril@388
  4496
		{	// selection != a FloatObj
insilmaril@0
  4497
			if (lmosel->getDepth()==0)
insilmaril@0
  4498
			{
insilmaril@388
  4499
				// Move MapCenter
insilmaril@388
  4500
				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
insilmaril@0
  4501
					mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@0
  4502
				else	
insilmaril@0
  4503
					mapCenter->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@388
  4504
				mapCenter->updateRelPositions();	
insilmaril@0
  4505
			} else
insilmaril@0
  4506
			{	
insilmaril@0
  4507
				if (lmosel->getDepth()==1)
insilmaril@0
  4508
				{
insilmaril@388
  4509
					// Move mainbranch
insilmaril@0
  4510
					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@388
  4511
					lmosel->setRelPos();
insilmaril@0
  4512
				} else
insilmaril@0
  4513
				{
insilmaril@388
  4514
					// Move ordinary branch
insilmaril@473
  4515
					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
insilmaril@0
  4516
						// Add width of bbox here, otherwise alignRelTo will cause jumping around
insilmaril@0
  4517
						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
insilmaril@175
  4518
							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
insilmaril@0
  4519
					else	
insilmaril@175
  4520
						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
insilmaril@0
  4521
				} 
insilmaril@0
  4522
insilmaril@431
  4523
				// Maybe we can relink temporary?
insilmaril@431
  4524
				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
insilmaril@431
  4525
					 (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@431
  4526
					  typeid(*lmo)==typeid(MapCenterObj)) ) 
insilmaril@431
  4527
insilmaril@0
  4528
				{
insilmaril@388
  4529
					if (e->modifiers()==Qt::ControlModifier)
insilmaril@0
  4530
					{
insilmaril@0
  4531
						// Special case: CTRL to link below lmo
insilmaril@0
  4532
						lmosel->setParObjTmp (lmo,p,+1);
insilmaril@0
  4533
					}
insilmaril@388
  4534
					else if (e->modifiers()==Qt::ShiftModifier)
insilmaril@0
  4535
						lmosel->setParObjTmp (lmo,p,-1);
insilmaril@0
  4536
					else
insilmaril@0
  4537
						lmosel->setParObjTmp (lmo,p,0);
insilmaril@0
  4538
				} else	
insilmaril@0
  4539
				{
insilmaril@93
  4540
					lmosel->unsetParObjTmp();
insilmaril@0
  4541
				}		
insilmaril@428
  4542
				// reposition subbranch
insilmaril@428
  4543
				lmosel->reposition();	
insilmaril@0
  4544
			} // depth>0
insilmaril@0
  4545
insilmaril@442
  4546
			xelection.update();
insilmaril@0
  4547
		} // no FloatImageObj
insilmaril@0
  4548
insilmaril@408
  4549
		scene()->update();
insilmaril@0
  4550
		return;
insilmaril@0
  4551
	} // selection && moving_obj
insilmaril@0
  4552
		
insilmaril@83
  4553
	// Draw a link from one branch to another
insilmaril@83
  4554
	if (drawingLink)
insilmaril@83
  4555
	{
insilmaril@95
  4556
		 tmpXLink->setEnd (p);
insilmaril@95
  4557
		 tmpXLink->updateXLink();
insilmaril@83
  4558
	}	 
insilmaril@83
  4559
	
insilmaril@408
  4560
    // Move sceneView 
insilmaril@411
  4561
    if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
insilmaril@0
  4562
	{
insilmaril@408
  4563
		QPointF p=e->globalPos();
insilmaril@0
  4564
		movingVec.setX(-p.x() + movingObj_start.x() );
insilmaril@0
  4565
		movingVec.setY(-p.y() + movingObj_start.y() );
insilmaril@408
  4566
		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
insilmaril@408
  4567
		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
insilmaril@0
  4568
    }
insilmaril@0
  4569
}
insilmaril@0
  4570
insilmaril@0
  4571
insilmaril@408
  4572
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
insilmaril@0
  4573
{
insilmaril@408
  4574
    QPointF p = mapToScene(e->pos());
insilmaril@0
  4575
	LinkableMapObj *dst;
insilmaril@424
  4576
	LinkableMapObj *lmosel=xelection.single();
insilmaril@0
  4577
	// Have we been picking color?
insilmaril@0
  4578
	if (pickingColor)
insilmaril@0
  4579
	{
insilmaril@0
  4580
		pickingColor=false;
insilmaril@366
  4581
		setCursor (Qt::ArrowCursor);
insilmaril@0
  4582
		// Check if we are over another branch
insilmaril@408
  4583
		dst=mapCenter->findMapObj(p, NULL);
insilmaril@424
  4584
		if (dst && lmosel) 
insilmaril@0
  4585
		{	
insilmaril@366
  4586
			if (e->state() & Qt::ShiftModifier)
insilmaril@417
  4587
				colorBranch (((BranchObj*)(dst))->getColor());
insilmaril@0
  4588
			else	
insilmaril@417
  4589
				colorSubtree (((BranchObj*)(dst))->getColor());
insilmaril@0
  4590
		} 
insilmaril@0
  4591
		return;
insilmaril@0
  4592
	}
insilmaril@83
  4593
insilmaril@83
  4594
	// Have we been drawing a link?
insilmaril@491
  4595
	if (drawingLink)	
insilmaril@83
  4596
	{
insilmaril@83
  4597
		drawingLink=false;
insilmaril@83
  4598
		// Check if we are over another branch
insilmaril@408
  4599
		dst=mapCenter->findMapObj(p, NULL);
insilmaril@424
  4600
		if (dst && lmosel) 
insilmaril@83
  4601
		{	
insilmaril@95
  4602
			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
insilmaril@95
  4603
			tmpXLink->updateXLink();
insilmaril@491
  4604
			tmpXLink->activate(); //FIXME savestate missing
insilmaril@473
  4605
			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
insilmaril@83
  4606
		} else
insilmaril@83
  4607
		{
insilmaril@95
  4608
			delete(tmpXLink);
insilmaril@95
  4609
			tmpXLink=NULL;
insilmaril@83
  4610
		}
insilmaril@83
  4611
		return;
insilmaril@83
  4612
	}
insilmaril@83
  4613
	
insilmaril@0
  4614
    // Have we been moving something?
insilmaril@424
  4615
    if ( lmosel && movingObj ) 
insilmaril@0
  4616
    {	
insilmaril@424
  4617
		FloatImageObj *fo=xelection.getFloatImage();
insilmaril@424
  4618
		if(fo)
insilmaril@175
  4619
		{
insilmaril@388
  4620
			// Moved FloatObj. Maybe we need to reposition
insilmaril@408
  4621
		    QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@408
  4622
		    QString pnow=qpointfToString(fo->getRelPos());
insilmaril@395
  4623
			saveState(
insilmaril@424
  4624
				fo,
insilmaril@366
  4625
				"moveRel "+pold,
insilmaril@424
  4626
				fo,
insilmaril@366
  4627
				"moveRel "+pnow,
insilmaril@424
  4628
				QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
insilmaril@424
  4629
insilmaril@424
  4630
			fo->getParObj()->requestReposition();
insilmaril@175
  4631
			mapCenter->reposition();
insilmaril@175
  4632
		}	
insilmaril@175
  4633
insilmaril@0
  4634
		// Check if we are over another branch, but ignore 
insilmaril@0
  4635
		// any found LMOs, which are FloatObjs
insilmaril@424
  4636
		dst=mapCenter->findMapObj(mapToScene(e->pos() ), lmosel);
insilmaril@0
  4637
insilmaril@336
  4638
		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
insilmaril@0
  4639
			dst=NULL;
insilmaril@0
  4640
		
insilmaril@491
  4641
		if (xelection.type() == Selection::MapCenter )
insilmaril@497
  4642
		{	
insilmaril@497
  4643
			// TODO: Check for problems if graphicsview is resized for 
insilmaril@497
  4644
			// undo/redo...
insilmaril@497
  4645
		    QString pold=qpointfToString(movingObj_orgPos);
insilmaril@497
  4646
		    QString pnow=qpointfToString(mapCenter->getAbsPos());
insilmaril@497
  4647
			saveState(
insilmaril@497
  4648
				fo,
insilmaril@497
  4649
				"move "+pold,
insilmaril@497
  4650
				fo,
insilmaril@497
  4651
				"move "+pnow,
insilmaril@497
  4652
				QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
insilmaril@388
  4653
		}
insilmaril@388
  4654
		
insilmaril@491
  4655
		if (xelection.type() == Selection::Branch )
insilmaril@388
  4656
		{	// A branch was moved
insilmaril@388
  4657
			
insilmaril@0
  4658
			// save the position in case we link to mapcenter
insilmaril@424
  4659
			QPointF savePos=QPointF (lmosel->getAbsPos()  );
insilmaril@0
  4660
insilmaril@0
  4661
			// Reset the temporary drawn link to the original one
insilmaril@424
  4662
			lmosel->unsetParObjTmp();
insilmaril@0
  4663
insilmaril@366
  4664
			// For Redo we may need to save original selection
insilmaril@424
  4665
			QString preSelStr=lmosel->getSelectString();
insilmaril@93
  4666
insilmaril@94
  4667
			copyingObj=false;	
insilmaril@129
  4668
			if (dst ) 
insilmaril@93
  4669
			{
insilmaril@424
  4670
				BranchObj* bsel=xelection.getBranch();
insilmaril@366
  4671
				BranchObj* bdst=(BranchObj*)dst;
insilmaril@366
  4672
insilmaril@366
  4673
				QString preParStr=(bsel->getParObj())->getSelectString();
insilmaril@366
  4674
				QString preNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4675
				QString preDstParStr;
insilmaril@366
  4676
insilmaril@366
  4677
				if (e->state() & Qt::ShiftModifier && dst->getParObj())
insilmaril@366
  4678
				{	// Link above dst
insilmaril@366
  4679
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4680
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
insilmaril@366
  4681
				} else 
insilmaril@366
  4682
				if (e->state() & Qt::ControlModifier && dst->getParObj())
insilmaril@366
  4683
				{
insilmaril@366
  4684
					// Link below dst
insilmaril@366
  4685
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4686
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
insilmaril@366
  4687
				} else	
insilmaril@366
  4688
				{	// Append to dst
insilmaril@366
  4689
					preDstParStr=dst->getSelectString();
insilmaril@421
  4690
					bsel->linkTo (bdst,-1);
insilmaril@366
  4691
					if (dst->getDepth()==0) bsel->move (savePos);
insilmaril@366
  4692
				} 
insilmaril@424
  4693
				QString postSelStr=lmosel->getSelectString();
insilmaril@366
  4694
				QString postNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4695
insilmaril@421
  4696
				QString undoCom="linkTo (\""+ 
insilmaril@366
  4697
					preParStr+ "\"," + preNum  +"," + 
insilmaril@366
  4698
					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
insilmaril@366
  4699
insilmaril@421
  4700
				QString redoCom="linkTo (\""+ 
insilmaril@366
  4701
					preDstParStr + "\"," + postNum + "," +
insilmaril@366
  4702
					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
insilmaril@366
  4703
insilmaril@366
  4704
				saveState (
insilmaril@366
  4705
					postSelStr,undoCom,
insilmaril@366
  4706
					preSelStr, redoCom,
insilmaril@366
  4707
					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
insilmaril@163
  4708
			} else
insilmaril@424
  4709
				if (lmosel->getDepth()==1)
insilmaril@366
  4710
				{
insilmaril@366
  4711
					// The select string might be different _after_ moving around.
insilmaril@366
  4712
					// Therefor reposition and then use string of old selection, too
insilmaril@366
  4713
					mapCenter->reposition();
insilmaril@366
  4714
insilmaril@424
  4715
					QString ps=qpointfToString ( lmosel->getRelPos() );
insilmaril@366
  4716
					saveState(
insilmaril@424
  4717
						lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
insilmaril@366
  4718
						preSelStr, "moveRel "+ps, 
insilmaril@424
  4719
						QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
insilmaril@163
  4720
			
insilmaril@366
  4721
				}
insilmaril@0
  4722
			// Draw the original link, before selection was moved around
insilmaril@0
  4723
			mapCenter->reposition();
insilmaril@0
  4724
		}
insilmaril@442
  4725
		xelection.update();
insilmaril@408
  4726
		// Finally resize scene, if needed
insilmaril@408
  4727
		scene()->update();
insilmaril@0
  4728
		movingObj=NULL;		
insilmaril@366
  4729
insilmaril@366
  4730
		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
insilmaril@366
  4731
		updateActions();
insilmaril@0
  4732
	} else 
insilmaril@83
  4733
		// maybe we moved View: set old cursor
insilmaril@366
  4734
		setCursor (Qt::ArrowCursor);
insilmaril@83
  4735
    
insilmaril@0
  4736
}
insilmaril@0
  4737
insilmaril@408
  4738
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
insilmaril@0
  4739
{
insilmaril@491
  4740
	if (isSelectBlocked() ) 
insilmaril@491
  4741
	{
insilmaril@491
  4742
		e->ignore();
insilmaril@491
  4743
		return;
insilmaril@491
  4744
	}
insilmaril@491
  4745
insilmaril@366
  4746
	if (e->button() == Qt::LeftButton )
insilmaril@0
  4747
	{
insilmaril@408
  4748
		QPointF p = mapToScene(e->pos());
insilmaril@0
  4749
		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
insilmaril@0
  4750
		if (lmo) {	// MapObj was found
insilmaril@0
  4751
			// First select the MapObj than edit heading
insilmaril@424
  4752
			xelection.select(lmo);
insilmaril@366
  4753
			mainWindow->editHeading();
insilmaril@0
  4754
		}
insilmaril@0
  4755
	}
insilmaril@0
  4756
}
insilmaril@0
  4757
insilmaril@0
  4758
void MapEditor::resizeEvent (QResizeEvent* e)
insilmaril@0
  4759
{
insilmaril@408
  4760
	QGraphicsView::resizeEvent( e );
insilmaril@0
  4761
}
insilmaril@0
  4762
insilmaril@412
  4763
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
insilmaril@119
  4764
{
insilmaril@417
  4765
	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
insilmaril@417
  4766
	//	cerr << event->format(i) << endl;
insilmaril@417
  4767
insilmaril@417
  4768
	if (event->mimeData()->hasImage())
insilmaril@417
  4769
		event->acceptProposedAction();
insilmaril@417
  4770
	else	
insilmaril@417
  4771
		if (event->mimeData()->hasUrls())
insilmaril@417
  4772
			event->acceptProposedAction();
insilmaril@417
  4773
}
insilmaril@417
  4774
insilmaril@531
  4775
void MapEditor::dragMoveEvent(QDragMoveEvent *)
insilmaril@417
  4776
{
insilmaril@417
  4777
}
insilmaril@417
  4778
insilmaril@417
  4779
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
insilmaril@417
  4780
{
insilmaril@417
  4781
	event->accept();
insilmaril@119
  4782
}
insilmaril@129
  4783
insilmaril@412
  4784
void MapEditor::dropEvent(QDropEvent *event)
insilmaril@129
  4785
{
insilmaril@424
  4786
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  4787
	if (sel)
insilmaril@128
  4788
	{
insilmaril@505
  4789
		if (debug)
insilmaril@505
  4790
			foreach (QString format,event->mimeData()->formats()) 
insilmaril@505
  4791
				cout << "MapEditor: Dropped format: "<<format.ascii()<<endl;
insilmaril@497
  4792
insilmaril@497
  4793
insilmaril@417
  4794
		QList <QUrl> uris;
insilmaril@417
  4795
		if (event->mimeData()->hasImage()) 
insilmaril@128
  4796
		{
insilmaril@417
  4797
			 QVariant imageData = event->mimeData()->imageData();
insilmaril@417
  4798
			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
insilmaril@417
  4799
		} else
insilmaril@417
  4800
		if (event->mimeData()->hasUrls())
insilmaril@417
  4801
			uris=event->mimeData()->urls();
insilmaril@417
  4802
insilmaril@417
  4803
		if (uris.count()>0)
insilmaril@128
  4804
		{
insilmaril@417
  4805
			QStringList files;
insilmaril@417
  4806
			QString s;
insilmaril@417
  4807
			QString heading;
insilmaril@417
  4808
			BranchObj *bo;
insilmaril@428
  4809
			for (int i=0; i<uris.count();i++)
insilmaril@408
  4810
			{
insilmaril@428
  4811
				// Workaround to avoid adding empty branches
insilmaril@428
  4812
				if (!uris.at(i).toString().isEmpty())
insilmaril@417
  4813
				{
insilmaril@428
  4814
					bo=sel->addBranch();
insilmaril@428
  4815
					if (bo)
insilmaril@417
  4816
					{
insilmaril@428
  4817
						s=uris.at(i).toLocalFile();
insilmaril@428
  4818
						if (!s.isEmpty()) 
insilmaril@428
  4819
						{
insilmaril@428
  4820
						   QString file = QDir::convertSeparators(s);
insilmaril@428
  4821
						   heading = QFileInfo(file).baseName();
insilmaril@428
  4822
						   files.append(file);
insilmaril@428
  4823
						   if (file.endsWith(".vym", false))
insilmaril@428
  4824
							   bo->setVymLink(file);
insilmaril@428
  4825
						   else
insilmaril@428
  4826
							   bo->setURL(uris.at(i).toString());
insilmaril@428
  4827
					   } else 
insilmaril@428
  4828
					   {
insilmaril@428
  4829
						   bo->setURL(uris.at(i).toString());
insilmaril@428
  4830
					   }
insilmaril@428
  4831
insilmaril@428
  4832
					   if (!heading.isEmpty())
insilmaril@428
  4833
						   bo->setHeading(heading);
insilmaril@428
  4834
					   else
insilmaril@428
  4835
						   bo->setHeading(uris.at(i).toString());
insilmaril@428
  4836
					}
insilmaril@417
  4837
				}
insilmaril@417
  4838
			}
insilmaril@420
  4839
			mapCenter->reposition();
insilmaril@417
  4840
		}
insilmaril@417
  4841
	}	
insilmaril@417
  4842
	event->acceptProposedAction();
insilmaril@417
  4843
}
insilmaril@417
  4844
insilmaril@491
  4845
void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
insilmaril@473
  4846
{
insilmaril@473
  4847
    Q_UNUSED(event);
insilmaril@473
  4848
insilmaril@473
  4849
	cout << "ME::timerEvent\n";
insilmaril@473
  4850
insilmaril@473
  4851
	for (int i=0; i<animObjList.size(); ++i)
insilmaril@473
  4852
	{
insilmaril@473
  4853
		animObjList.at(i)->animate();
insilmaril@473
  4854
		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
insilmaril@473
  4855
	}
insilmaril@473
  4856
	mapCenter->reposition();
insilmaril@473
  4857
}
insilmaril@473
  4858
insilmaril@528
  4859
insilmaril@528
  4860
void MapEditor::sendSelection()
insilmaril@473
  4861
{
insilmaril@531
  4862
	if (netstate!=Server) return;
insilmaril@531
  4863
	sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
insilmaril@528
  4864
}
insilmaril@528
  4865
insilmaril@528
  4866
void MapEditor::newServer()
insilmaril@528
  4867
{
insilmaril@531
  4868
	port=54321;
insilmaril@531
  4869
	sendCounter=0;
insilmaril@528
  4870
    tcpServer = new QTcpServer(this);
insilmaril@531
  4871
    if (!tcpServer->listen(QHostAddress::Any,port)) {
insilmaril@528
  4872
        QMessageBox::critical(this, "vym server",
insilmaril@528
  4873
                              QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
insilmaril@528
  4874
        close();
insilmaril@528
  4875
        return;
insilmaril@528
  4876
    }
insilmaril@528
  4877
	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
insilmaril@531
  4878
	netstate=Server;
insilmaril@534
  4879
	cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
insilmaril@473
  4880
}
insilmaril@473
  4881
insilmaril@531
  4882
void MapEditor::connectToServer()
insilmaril@531
  4883
{
insilmaril@531
  4884
	port=54321;
insilmaril@531
  4885
	server="salam.suse.de";
insilmaril@531
  4886
	server="localhost";
insilmaril@531
  4887
	clientSocket = new QTcpSocket (this);
insilmaril@531
  4888
	clientSocket->abort();
insilmaril@531
  4889
    clientSocket->connectToHost(server ,port);
insilmaril@531
  4890
	connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
insilmaril@531
  4891
    connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
insilmaril@531
  4892
            this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
insilmaril@531
  4893
	netstate=Client;		
insilmaril@531
  4894
	cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
insilmaril@531
  4895
insilmaril@531
  4896
	
insilmaril@531
  4897
}
insilmaril@531
  4898
insilmaril@527
  4899
void MapEditor::newClient()
insilmaril@527
  4900
{
insilmaril@527
  4901
    QTcpSocket *newClient = tcpServer->nextPendingConnection();
insilmaril@527
  4902
    connect(newClient, SIGNAL(disconnected()),
insilmaril@527
  4903
            newClient, SLOT(deleteLater()));
insilmaril@527
  4904
insilmaril@527
  4905
	cout <<"ME::newClient  at "<<newClient->peerAddress().toString().ascii()<<endl;
insilmaril@527
  4906
insilmaril@527
  4907
	clientList.append (newClient);
insilmaril@527
  4908
}
insilmaril@473
  4909
insilmaril@528
  4910
insilmaril@528
  4911
void MapEditor::sendData(const QString &s)
insilmaril@528
  4912
{
insilmaril@537
  4913
	if (clientList.size()==0) return;
insilmaril@537
  4914
insilmaril@528
  4915
	// Create bytearray to send
insilmaril@528
  4916
	QByteArray block;
insilmaril@528
  4917
    QDataStream out(&block, QIODevice::WriteOnly);
insilmaril@528
  4918
    out.setVersion(QDataStream::Qt_4_0);
insilmaril@528
  4919
insilmaril@528
  4920
	// Reserve some space for blocksize
insilmaril@528
  4921
    out << (quint16)0;
insilmaril@528
  4922
insilmaril@531
  4923
	// Write sendCounter
insilmaril@531
  4924
    out << sendCounter++;
insilmaril@531
  4925
insilmaril@528
  4926
	// Write data
insilmaril@528
  4927
    out << s;
insilmaril@528
  4928
insilmaril@528
  4929
	// Go back and write blocksize so far
insilmaril@528
  4930
    out.device()->seek(0);
insilmaril@531
  4931
    quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
insilmaril@531
  4932
	out << bs;
insilmaril@531
  4933
insilmaril@537
  4934
	if (debug)
insilmaril@537
  4935
		cout << "ME::sendData  bs="<<bs<<"  counter="<<sendCounter<<"  s="<<s.ascii()<<endl;
insilmaril@528
  4936
insilmaril@528
  4937
	for (int i=0; i<clientList.size(); ++i)
insilmaril@528
  4938
	{
insilmaril@531
  4939
		//cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
insilmaril@528
  4940
		clientList.at(i)->write (block);
insilmaril@528
  4941
	}
insilmaril@528
  4942
}
insilmaril@531
  4943
insilmaril@531
  4944
void MapEditor::readData ()
insilmaril@531
  4945
{
insilmaril@531
  4946
	while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
insilmaril@531
  4947
	{
insilmaril@537
  4948
		if (debug)
insilmaril@537
  4949
			cout <<"readData  bytesAvail="<<clientSocket->bytesAvailable();
insilmaril@534
  4950
		quint16 recCounter;
insilmaril@534
  4951
		quint16 blockSize;
insilmaril@534
  4952
insilmaril@534
  4953
		QDataStream in(clientSocket);
insilmaril@534
  4954
		in.setVersion(QDataStream::Qt_4_0);
insilmaril@534
  4955
insilmaril@534
  4956
		in >> blockSize;
insilmaril@534
  4957
		in >> recCounter;
insilmaril@534
  4958
		
insilmaril@534
  4959
		QString t;
insilmaril@534
  4960
		in >>t;
insilmaril@537
  4961
		if (debug)
insilmaril@537
  4962
			cout << "  t="<<t.ascii()<<endl;
insilmaril@534
  4963
		parseAtom (t);
insilmaril@531
  4964
	}
insilmaril@534
  4965
	return;
insilmaril@531
  4966
}
insilmaril@531
  4967
insilmaril@531
  4968
void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
insilmaril@531
  4969
{
insilmaril@531
  4970
    switch (socketError) {
insilmaril@531
  4971
    case QAbstractSocket::RemoteHostClosedError:
insilmaril@531
  4972
        break;
insilmaril@531
  4973
    case QAbstractSocket::HostNotFoundError:
insilmaril@531
  4974
        QMessageBox::information(this, __VYM_NAME " Network client",
insilmaril@531
  4975
                                 "The host was not found. Please check the "
insilmaril@531
  4976
                                    "host name and port settings.");
insilmaril@531
  4977
        break;
insilmaril@531
  4978
    case QAbstractSocket::ConnectionRefusedError:
insilmaril@531
  4979
        QMessageBox::information(this, __VYM_NAME " Network client",
insilmaril@531
  4980
                                 "The connection was refused by the peer. "
insilmaril@531
  4981
                                    "Make sure the fortune server is running, "
insilmaril@531
  4982
                                    "and check that the host name and port "
insilmaril@531
  4983
                                    "settings are correct.");
insilmaril@531
  4984
        break;
insilmaril@531
  4985
    default:
insilmaril@531
  4986
        QMessageBox::information(this, __VYM_NAME " Network client",
insilmaril@531
  4987
                                 QString("The following error occurred: %1.")
insilmaril@531
  4988
                                 .arg(clientSocket->errorString()));
insilmaril@531
  4989
    }
insilmaril@531
  4990
}
insilmaril@531
  4991
insilmaril@528
  4992
void MapEditor::autosave()
insilmaril@528
  4993
{
insilmaril@528
  4994
	// Disable autosave, while we have gone back in history
insilmaril@528
  4995
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@528
  4996
	if (redosAvail>0) return;
insilmaril@528
  4997
insilmaril@528
  4998
insilmaril@528
  4999
	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
insilmaril@528
  5000
		mainWindow->fileSave (this);
insilmaril@528
  5001
}
insilmaril@528
  5002
insilmaril@528
  5003
insilmaril@491
  5004
/*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
insilmaril@417
  5005
{
insilmaril@408
  5006
insilmaril@408
  5007
		} else if (event->provides("application/x-moz-file-promise-url") && 
insilmaril@408
  5008
			 event->provides("application/x-moz-nativeimage")) 
insilmaril@408
  5009
		{
insilmaril@129
  5010
			// Contains url to the img src in unicode16
insilmaril@128
  5011
			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
insilmaril@128
  5012
			QString url = QString((const QChar*)d.data(),d.size()/2);
insilmaril@408
  5013
			fetchImage(url);
insilmaril@408
  5014
			event->accept();
insilmaril@128
  5015
			update=true;
insilmaril@408
  5016
		} else if (event->provides ("text/uri-list"))
insilmaril@408
  5017
		{	// Uris provided e.g. by konqueror
insilmaril@408
  5018
			Q3UriDrag::decode (event,uris);
insilmaril@408
  5019
		} else if (event->provides ("_NETSCAPE_URL"))
insilmaril@128
  5020
		{	// Uris provided by Mozilla
insilmaril@129
  5021
		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
insilmaril@129
  5022
		  uris.append(l[0]);
insilmaril@129
  5023
		  heading = l[1];
insilmaril@129
  5024
		} else if (event->provides("text/html")) {
insilmaril@129
  5025
insilmaril@129
  5026
		  // Handels text mime types
insilmaril@129
  5027
		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
insilmaril@129
  5028
		  QByteArray d = event->encodedData("text/html");
insilmaril@129
  5029
		  QString text;
insilmaril@129
  5030
		  if (isUnicode16(d)) 
insilmaril@129
  5031
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5032
		  else 
insilmaril@129
  5033
		    text = QString(d);
insilmaril@129
  5034
insilmaril@129
  5035
		  textEditor->setText(text);
insilmaril@129
  5036
insilmaril@129
  5037
		  event->accept();
insilmaril@129
  5038
		  update=true;
insilmaril@129
  5039
		} else if (event->provides("text/plain")) {
insilmaril@129
  5040
		  QByteArray d = event->encodedData("text/plain");
insilmaril@129
  5041
		  QString text;
insilmaril@129
  5042
		  if (isUnicode16(d))
insilmaril@129
  5043
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5044
		  else 
insilmaril@129
  5045
		    text = QString(d);
insilmaril@129
  5046
insilmaril@129
  5047
		  textEditor->setText(text);
insilmaril@129
  5048
		  
insilmaril@129
  5049
		  event->accept();
insilmaril@129
  5050
		  update= true;
insilmaril@128
  5051
		}
insilmaril@417
  5052
insilmaril@406
  5053
		*/
insilmaril@406
  5054
insilmaril@417
  5055
insilmaril@412
  5056
insilmaril@412
  5057
bool isUnicode16(const QByteArray &d) 
insilmaril@412
  5058
{
insilmaril@412
  5059
  // TODO: make more precise check for unicode 16.
insilmaril@412
  5060
  // Guess unicode16 if any of second bytes are zero
insilmaril@412
  5061
  unsigned int length = max(0,d.size()-2)/2;
insilmaril@412
  5062
  for (unsigned int i = 0; i<length ; i++)
insilmaril@412
  5063
    if (d.at(i*2+1)==0) return true;
insilmaril@412
  5064
  return false;
insilmaril@412
  5065
}
insilmaril@412
  5066
      
insilmaril@395
  5067
void MapEditor::addFloatImageInt (const QPixmap &img) 
insilmaril@119
  5068
{
insilmaril@424
  5069
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  5070
	if (bo)
insilmaril@119
  5071
  {
insilmaril@395
  5072
	FloatImageObj *fio=bo->addFloatImage();
insilmaril@395
  5073
    fio->load(img);
insilmaril@505
  5074
    fio->setOriginalFilename("No original filename (image added by dropevent)");	
insilmaril@505
  5075
	QString s=bo->getSelectString();
insilmaril@505
  5076
	saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio  );
insilmaril@505
  5077
	saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
insilmaril@119
  5078
    mapCenter->reposition();
insilmaril@408
  5079
    scene()->update();
insilmaril@119
  5080
  }
insilmaril@119
  5081
}
insilmaril@119
  5082
insilmaril@412
  5083
/*
insilmaril@412
  5084
insilmaril@412
  5085
void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
insilmaril@119
  5086
{
insilmaril@119
  5087
  if (!imageBuffer) imageBuffer = new QBuffer();
insilmaril@119
  5088
  if (!imageBuffer->isOpen()) {
insilmaril@366
  5089
    imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
insilmaril@119
  5090
  }
insilmaril@119
  5091
  imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
insilmaril@119
  5092
}
insilmaril@119
  5093
insilmaril@119
  5094
insilmaril@366
  5095
void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
insilmaril@119
  5096
{
insilmaril@366
  5097
	if (nop->state()==Q3NetworkProtocol::StDone) {
insilmaril@129
  5098
		QPixmap img(imageBuffer->buffer());
insilmaril@395
  5099
		addFloatImageInt (img);
insilmaril@129
  5100
	}
insilmaril@129
  5101
insilmaril@129
  5102
	if (imageBuffer) {
insilmaril@129
  5103
		imageBuffer->close();
insilmaril@129
  5104
		if (imageBuffer) {
insilmaril@129
  5105
			imageBuffer->close();
insilmaril@129
  5106
			delete imageBuffer;
insilmaril@129
  5107
			imageBuffer = 0;
insilmaril@129
  5108
		}
insilmaril@129
  5109
	}
insilmaril@119
  5110
}
insilmaril@119
  5111
insilmaril@129
  5112
void MapEditor::fetchImage(const QString &url) 
insilmaril@119
  5113
{
insilmaril@119
  5114
  if (urlOperator) {
insilmaril@119
  5115
    urlOperator->stop();
insilmaril@119
  5116
    disconnect(urlOperator);
insilmaril@119
  5117
    delete urlOperator;
insilmaril@119
  5118
  }
insilmaril@119
  5119
  
insilmaril@366
  5120
  urlOperator = new Q3UrlOperator(url);
insilmaril@366
  5121
  connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
insilmaril@366
  5122
	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
insilmaril@366
  5123
insilmaril@366
  5124
  connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
insilmaril@366
  5125
	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
insilmaril@119
  5126
  urlOperator->get();
insilmaril@119
  5127
}
insilmaril@412
  5128
*/
insilmaril@412
  5129