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