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