mapeditor.cpp
author insilmaril
Fri Feb 01 15:28:35 2008 +0000 (2008-02-01)
changeset 662 9abdd5e6c3dc
parent 652 700553af9ca5
child 663 827d334d55f1
permissions -rw-r--r--
Added brasilian translation by Amadeu Júnior
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@658
   362
	if (debug) cout << "ME::saveState() for  "<<qPrintable (mapName)<<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@658
   427
		if (saveSel) cout << "    saveSel="<<qPrintable (saveSel->getSelectString())<<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@658
  1008
											cout << "PASSED: " << qPrintable (c)  << endl;
insilmaril@502
  1009
										} else
insilmaril@502
  1010
										{
insilmaril@658
  1011
											cout << "FAILED: " << qPrintable (c)  << 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@652
  2688
	if (xelection.select(s))
insilmaril@0
  2689
	{
insilmaril@442
  2690
		xelection.update();
insilmaril@0
  2691
		ensureSelectionVisible();
insilmaril@528
  2692
		sendSelection ();
insilmaril@0
  2693
		return true;
insilmaril@652
  2694
	}
insilmaril@139
  2695
	return false;
insilmaril@0
  2696
}
insilmaril@0
  2697
insilmaril@366
  2698
QString MapEditor::getSelectString()
insilmaril@366
  2699
{
insilmaril@424
  2700
	return xelection.getSelectString();
insilmaril@366
  2701
}
insilmaril@366
  2702
insilmaril@366
  2703
void MapEditor::selectInt (LinkableMapObj *lmo)
insilmaril@0
  2704
{
insilmaril@491
  2705
	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
insilmaril@442
  2706
	{
insilmaril@424
  2707
		xelection.select(lmo);
insilmaril@442
  2708
		xelection.update();
insilmaril@528
  2709
		sendSelection ();
insilmaril@442
  2710
	}	
insilmaril@267
  2711
}
insilmaril@0
  2712
insilmaril@366
  2713
void MapEditor::selectNextBranchInt()
insilmaril@0
  2714
{
insilmaril@0
  2715
	// Increase number of branch
insilmaril@424
  2716
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2717
	if (sel)
insilmaril@0
  2718
	{
insilmaril@424
  2719
		QString s=sel->getSelectString();
insilmaril@0
  2720
		QString part;
insilmaril@0
  2721
		QString typ;
insilmaril@0
  2722
		QString num;
insilmaril@0
  2723
insilmaril@0
  2724
		// Where am I? 
insilmaril@0
  2725
		part=s.section(",",-1);
insilmaril@0
  2726
		typ=part.left (3);
insilmaril@0
  2727
		num=part.right(part.length() - 3);
insilmaril@0
  2728
insilmaril@0
  2729
		s=s.left (s.length() -num.length());
insilmaril@0
  2730
insilmaril@0
  2731
		// Go to next lmo
insilmaril@0
  2732
		num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2733
insilmaril@0
  2734
		s=s+num;
insilmaril@0
  2735
		
insilmaril@0
  2736
		// Try to select this one
insilmaril@0
  2737
		if (select (s)) return;
insilmaril@0
  2738
insilmaril@0
  2739
		// We have no direct successor, 
insilmaril@0
  2740
		// try to increase the parental number in order to
insilmaril@0
  2741
		// find a successor with same depth
insilmaril@0
  2742
insilmaril@424
  2743
		int d=xelection.single()->getDepth();
insilmaril@0
  2744
		int oldDepth=d;
insilmaril@0
  2745
		int i;
insilmaril@0
  2746
		bool found=false;
insilmaril@0
  2747
		bool b;
insilmaril@0
  2748
		while (!found && d>0)
insilmaril@0
  2749
		{
insilmaril@0
  2750
			s=s.section (",",0,d-1);
insilmaril@0
  2751
			// replace substring of current depth in s with "1"
insilmaril@0
  2752
			part=s.section(",",-1);
insilmaril@0
  2753
			typ=part.left (3);
insilmaril@0
  2754
			num=part.right(part.length() - 3);
insilmaril@0
  2755
insilmaril@0
  2756
			if (d>1)
insilmaril@0
  2757
			{	
insilmaril@0
  2758
				// increase number of parent
insilmaril@0
  2759
				num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2760
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2761
			} else
insilmaril@0
  2762
			{
insilmaril@0
  2763
				// Special case, look at orientation
insilmaril@473
  2764
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2765
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2766
				else	
insilmaril@0
  2767
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  2768
				s=typ+num;
insilmaril@0
  2769
			}	
insilmaril@0
  2770
insilmaril@0
  2771
			if (select (s))
insilmaril@0
  2772
				// pad to oldDepth, select the first branch for each depth
insilmaril@0
  2773
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2774
				{
insilmaril@0
  2775
					b=select (s);
insilmaril@0
  2776
					if (b)
insilmaril@0
  2777
					{	
insilmaril@424
  2778
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@0
  2779
							s+=",bo:0";
insilmaril@0
  2780
						else	
insilmaril@0
  2781
							break;
insilmaril@0
  2782
					} else
insilmaril@0
  2783
						break;
insilmaril@0
  2784
				}	
insilmaril@0
  2785
insilmaril@0
  2786
			// try to select the freshly built string
insilmaril@0
  2787
			found=select(s);
insilmaril@0
  2788
			d--;
insilmaril@0
  2789
		}
insilmaril@0
  2790
		return;
insilmaril@0
  2791
	}	
insilmaril@0
  2792
}
insilmaril@0
  2793
insilmaril@366
  2794
void MapEditor::selectPrevBranchInt()
insilmaril@0
  2795
{
insilmaril@0
  2796
	// Decrease number of branch
insilmaril@424
  2797
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2798
	if (bo)
insilmaril@0
  2799
	{
insilmaril@424
  2800
		QString s=bo->getSelectString();
insilmaril@0
  2801
		QString part;
insilmaril@0
  2802
		QString typ;
insilmaril@0
  2803
		QString num;
insilmaril@0
  2804
insilmaril@0
  2805
		// Where am I? 
insilmaril@0
  2806
		part=s.section(",",-1);
insilmaril@0
  2807
		typ=part.left (3);
insilmaril@0
  2808
		num=part.right(part.length() - 3);
insilmaril@0
  2809
insilmaril@0
  2810
		s=s.left (s.length() -num.length());
insilmaril@0
  2811
insilmaril@411
  2812
		int n=num.toInt()-1;
insilmaril@411
  2813
		
insilmaril@0
  2814
		// Go to next lmo
insilmaril@411
  2815
		num=QString ("%1").arg(n);
insilmaril@0
  2816
		s=s+num;
insilmaril@0
  2817
		
insilmaril@0
  2818
		// Try to select this one
insilmaril@411
  2819
		if (n>=0 && select (s)) return;
insilmaril@0
  2820
insilmaril@0
  2821
		// We have no direct precessor, 
insilmaril@0
  2822
		// try to decrease the parental number in order to
insilmaril@0
  2823
		// find a precessor with same depth
insilmaril@0
  2824
insilmaril@424
  2825
		int d=xelection.single()->getDepth();
insilmaril@0
  2826
		int oldDepth=d;
insilmaril@0
  2827
		int i;
insilmaril@0
  2828
		bool found=false;
insilmaril@0
  2829
		bool b;
insilmaril@0
  2830
		while (!found && d>0)
insilmaril@0
  2831
		{
insilmaril@0
  2832
			s=s.section (",",0,d-1);
insilmaril@0
  2833
			// replace substring of current depth in s with "1"
insilmaril@0
  2834
			part=s.section(",",-1);
insilmaril@0
  2835
			typ=part.left (3);
insilmaril@0
  2836
			num=part.right(part.length() - 3);
insilmaril@0
  2837
insilmaril@0
  2838
			if (d>1)
insilmaril@0
  2839
			{
insilmaril@0
  2840
				// decrease number of parent
insilmaril@411
  2841
				num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2842
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2843
			} else
insilmaril@0
  2844
			{
insilmaril@0
  2845
				// Special case, look at orientation
insilmaril@473
  2846
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@411
  2847
					num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2848
				else	
insilmaril@411
  2849
					num=QString ("%1").arg(num.toInt()+1);
insilmaril@0
  2850
				s=typ+num;
insilmaril@0
  2851
			}	
insilmaril@0
  2852
insilmaril@0
  2853
			if (select(s))
insilmaril@0
  2854
				// pad to oldDepth, select the last branch for each depth
insilmaril@0
  2855
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2856
				{
insilmaril@0
  2857
					b=select (s);
insilmaril@0
  2858
					if (b)
insilmaril@424
  2859
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@424
  2860
							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
insilmaril@0
  2861
						else	
insilmaril@0
  2862
							break;
insilmaril@0
  2863
					else
insilmaril@0
  2864
						break;
insilmaril@0
  2865
				}	
insilmaril@0
  2866
			
insilmaril@0
  2867
			// try to select the freshly built string
insilmaril@0
  2868
			found=select(s);
insilmaril@0
  2869
			d--;
insilmaril@0
  2870
		}
insilmaril@0
  2871
		return;
insilmaril@0
  2872
	}	
insilmaril@0
  2873
}
insilmaril@0
  2874
insilmaril@0
  2875
void MapEditor::selectUpperBranch()
insilmaril@0
  2876
{
insilmaril@491
  2877
	if (isSelectBlocked() ) return;
insilmaril@491
  2878
insilmaril@424
  2879
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2880
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2881
	{
insilmaril@473
  2882
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2883
			selectPrevBranchInt();
insilmaril@424
  2884
		else
insilmaril@424
  2885
			if (bo->getDepth()==1)
insilmaril@424
  2886
				selectNextBranchInt();
insilmaril@424
  2887
			else
insilmaril@424
  2888
				selectPrevBranchInt();
insilmaril@424
  2889
	}
insilmaril@424
  2890
}
insilmaril@424
  2891
insilmaril@424
  2892
void MapEditor::selectLowerBranch()
insilmaril@424
  2893
{
insilmaril@491
  2894
	if (isSelectBlocked() ) return;
insilmaril@491
  2895
insilmaril@424
  2896
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2897
	if (bo && xelection.type()==Selection::Branch)
insilmaril@473
  2898
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2899
			selectNextBranchInt();
insilmaril@424
  2900
		else
insilmaril@424
  2901
			if (bo->getDepth()==1)
insilmaril@366
  2902
				selectPrevBranchInt();
insilmaril@0
  2903
			else
insilmaril@366
  2904
				selectNextBranchInt();
insilmaril@0
  2905
}
insilmaril@0
  2906
insilmaril@0
  2907
insilmaril@0
  2908
void MapEditor::selectLeftBranch()
insilmaril@0
  2909
{
insilmaril@491
  2910
	if (isSelectBlocked() ) return;
insilmaril@491
  2911
insilmaril@0
  2912
	BranchObj* bo;
insilmaril@0
  2913
	BranchObj* par;
insilmaril@424
  2914
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2915
	if (sel)
insilmaril@0
  2916
	{
insilmaril@491
  2917
		if (xelection.type()== Selection::MapCenter)
insilmaril@0
  2918
		{
insilmaril@424
  2919
			par=xelection.getBranch();
insilmaril@0
  2920
			bo=par->getLastSelectedBranch();
insilmaril@0
  2921
			if (bo)
insilmaril@0
  2922
			{
insilmaril@0
  2923
				// Workaround for reselecting on left and right side
insilmaril@473
  2924
				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2925
					bo=par->getLastBranch();
insilmaril@424
  2926
				if (bo)
insilmaril@0
  2927
				{
insilmaril@0
  2928
					bo=par->getLastBranch();
insilmaril@424
  2929
					xelection.select(bo);
insilmaril@442
  2930
					xelection.update();
insilmaril@0
  2931
					ensureSelectionVisible();
insilmaril@528
  2932
					sendSelection();
insilmaril@0
  2933
				}
insilmaril@0
  2934
			}	
insilmaril@0
  2935
		} else
insilmaril@0
  2936
		{
insilmaril@424
  2937
			par=(BranchObj*)(sel->getParObj());
insilmaril@473
  2938
			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2939
			{
insilmaril@491
  2940
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2941
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2942
				{
insilmaril@424
  2943
					xelection.select(par);
insilmaril@442
  2944
					xelection.update();
insilmaril@0
  2945
					ensureSelectionVisible();
insilmaril@528
  2946
					sendSelection();
insilmaril@0
  2947
				}
insilmaril@0
  2948
			} else
insilmaril@0
  2949
			{
insilmaril@491
  2950
				if (xelection.type() == Selection::Branch )
insilmaril@0
  2951
				{
insilmaril@424
  2952
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  2953
					if (bo) 
insilmaril@0
  2954
					{
insilmaril@424
  2955
						xelection.select(bo);
insilmaril@442
  2956
						xelection.update();
insilmaril@0
  2957
						ensureSelectionVisible();
insilmaril@528
  2958
					sendSelection();
insilmaril@0
  2959
					}
insilmaril@0
  2960
				}
insilmaril@0
  2961
			}
insilmaril@0
  2962
		}	
insilmaril@0
  2963
	}
insilmaril@0
  2964
}
insilmaril@0
  2965
insilmaril@0
  2966
void MapEditor::selectRightBranch()
insilmaril@0
  2967
{
insilmaril@491
  2968
	if (isSelectBlocked() ) return;
insilmaril@491
  2969
insilmaril@0
  2970
	BranchObj* bo;
insilmaril@0
  2971
	BranchObj* par;
insilmaril@424
  2972
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2973
	if (sel)
insilmaril@0
  2974
	{
insilmaril@491
  2975
		if (xelection.type()==Selection::MapCenter) 
insilmaril@0
  2976
		{
insilmaril@424
  2977
			par=xelection.getBranch();
insilmaril@0
  2978
			bo=par->getLastSelectedBranch();
insilmaril@0
  2979
			if (bo)
insilmaril@0
  2980
			{
insilmaril@366
  2981
				// Workaround for reselecting on left and right side
insilmaril@473
  2982
				if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2983
					bo=par->getFirstBranch();
insilmaril@0
  2984
				if (bo)
insilmaril@0
  2985
				{
insilmaril@424
  2986
					xelection.select(bo);
insilmaril@442
  2987
					xelection.update();
insilmaril@0
  2988
					ensureSelectionVisible();
insilmaril@528
  2989
					sendSelection();
insilmaril@0
  2990
				}
insilmaril@0
  2991
			}
insilmaril@0
  2992
		} else
insilmaril@0
  2993
		{
insilmaril@424
  2994
			par=(BranchObj*)(xelection.single()->getParObj());
insilmaril@473
  2995
			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2996
			{
insilmaril@491
  2997
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2998
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2999
				{
insilmaril@424
  3000
					xelection.select(par);
insilmaril@442
  3001
					xelection.update();
insilmaril@0
  3002
					ensureSelectionVisible();
insilmaril@528
  3003
					sendSelection();
insilmaril@0
  3004
				}
insilmaril@0
  3005
			} else
insilmaril@0
  3006
			{
insilmaril@491
  3007
				if (xelection.type()  == Selection::Branch) 
insilmaril@0
  3008
				{
insilmaril@424
  3009
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  3010
					if (bo) 
insilmaril@0
  3011
					{
insilmaril@424
  3012
						xelection.select(bo);
insilmaril@442
  3013
						xelection.update();
insilmaril@0
  3014
						ensureSelectionVisible();
insilmaril@528
  3015
					sendSelection();
insilmaril@0
  3016
					}
insilmaril@0
  3017
				}
insilmaril@0
  3018
			}
insilmaril@0
  3019
		}
insilmaril@0
  3020
	}
insilmaril@0
  3021
}
insilmaril@0
  3022
insilmaril@0
  3023
void MapEditor::selectFirstBranch()
insilmaril@0
  3024
{
insilmaril@424
  3025
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  3026
	BranchObj *bo2;
insilmaril@0
  3027
	BranchObj* par;
insilmaril@424
  3028
	if (bo1)
insilmaril@424
  3029
	{
insilmaril@424
  3030
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  3031
		bo2=par->getFirstBranch();
insilmaril@424
  3032
		if (bo2) {
insilmaril@424
  3033
			xelection.select(bo2);
insilmaril@442
  3034
			xelection.update();
insilmaril@424
  3035
			ensureSelectionVisible();
insilmaril@528
  3036
			sendSelection();
insilmaril@424
  3037
		}
insilmaril@424
  3038
	}		
insilmaril@0
  3039
}
insilmaril@0
  3040
insilmaril@0
  3041
void MapEditor::selectLastBranch()
insilmaril@0
  3042
{
insilmaril@424
  3043
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  3044
	BranchObj *bo2;
insilmaril@0
  3045
	BranchObj* par;
insilmaril@424
  3046
	if (bo1)
insilmaril@424
  3047
	{
insilmaril@424
  3048
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  3049
		bo2=par->getLastBranch();
insilmaril@424
  3050
		if (bo2) 
insilmaril@0
  3051
		{
insilmaril@424
  3052
			xelection.select(bo2);
insilmaril@442
  3053
			xelection.update();
insilmaril@424
  3054
			ensureSelectionVisible();
insilmaril@528
  3055
			sendSelection();
insilmaril@424
  3056
		}
insilmaril@424
  3057
	}		
insilmaril@0
  3058
}
insilmaril@0
  3059
insilmaril@408
  3060
void MapEditor::selectMapBackgroundImage ()
insilmaril@408
  3061
{
insilmaril@408
  3062
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@408
  3063
	fd->setMode (Q3FileDialog::ExistingFile);
insilmaril@408
  3064
	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@408
  3065
	ImagePreview *p =new ImagePreview (fd);
insilmaril@408
  3066
	fd->setContentsPreviewEnabled( TRUE );
insilmaril@408
  3067
	fd->setContentsPreview( p, p );
insilmaril@408
  3068
	fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@408
  3069
	fd->setCaption(vymName+" - " +tr("Load background image"));
insilmaril@408
  3070
	fd->setDir (lastImageDir);
insilmaril@408
  3071
	fd->show();
insilmaril@408
  3072
insilmaril@408
  3073
	if ( fd->exec() == QDialog::Accepted )
insilmaril@408
  3074
	{
insilmaril@412
  3075
		// TODO selectMapBackgroundImg in QT4 use:	lastImageDir=fd->directory();
insilmaril@408
  3076
		lastImageDir=QDir (fd->dirPath());
insilmaril@408
  3077
		setMapBackgroundImage (fd->selectedFile());
insilmaril@408
  3078
	}
insilmaril@408
  3079
}	
insilmaril@408
  3080
insilmaril@442
  3081
void MapEditor::setMapBackgroundImage (const QString &fn)	//FIXME missing savestate
insilmaril@408
  3082
{
insilmaril@408
  3083
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@408
  3084
	/*
insilmaril@408
  3085
	saveState(
insilmaril@408
  3086
		selection,
insilmaril@408
  3087
		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
insilmaril@408
  3088
		selection,
insilmaril@408
  3089
		QString ("setMapBackgroundImage (%1)").arg(col.name()),
insilmaril@408
  3090
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  3091
	*/	
insilmaril@408
  3092
	QBrush brush;
insilmaril@408
  3093
	brush.setTextureImage (QPixmap (fn));
insilmaril@408
  3094
	mapScene->setBackgroundBrush(brush);
insilmaril@408
  3095
}
insilmaril@408
  3096
insilmaril@398
  3097
void MapEditor::selectMapBackgroundColor()
insilmaril@0
  3098
{
insilmaril@408
  3099
	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
insilmaril@0
  3100
	if ( !col.isValid() ) return;
insilmaril@408
  3101
	setMapBackgroundColor( col );
insilmaril@0
  3102
}
insilmaril@0
  3103
insilmaril@398
  3104
insilmaril@398
  3105
void MapEditor::setMapBackgroundColor(QColor col)
insilmaril@0
  3106
{
insilmaril@408
  3107
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@398
  3108
	saveState(
insilmaril@445
  3109
		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
insilmaril@445
  3110
		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
insilmaril@398
  3111
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  3112
	mapScene->setBackgroundBrush(col);
insilmaril@398
  3113
}
insilmaril@398
  3114
insilmaril@398
  3115
QColor MapEditor::getMapBackgroundColor()
insilmaril@398
  3116
{
insilmaril@408
  3117
    return mapScene->backgroundBrush().color();
insilmaril@0
  3118
}
insilmaril@0
  3119
insilmaril@395
  3120
QColor MapEditor::getCurrentHeadingColor()
insilmaril@0
  3121
{
insilmaril@424
  3122
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3123
	if (bo) return bo->getColor(); 
insilmaril@395
  3124
	
insilmaril@395
  3125
	QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
insilmaril@395
  3126
	return Qt::black;
insilmaril@0
  3127
}
insilmaril@0
  3128
insilmaril@417
  3129
void MapEditor::colorBranch (QColor c)
insilmaril@0
  3130
{
insilmaril@424
  3131
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3132
	if (bo)
insilmaril@0
  3133
	{
insilmaril@424
  3134
		saveState(
insilmaril@424
  3135
			bo, 
insilmaril@445
  3136
			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
insilmaril@424
  3137
			bo,
insilmaril@445
  3138
			QString ("colorBranch (\"%1\")").arg(c.name()),
insilmaril@424
  3139
			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3140
		);	
insilmaril@424
  3141
		bo->setColor(c); // color branch
insilmaril@0
  3142
	}
insilmaril@0
  3143
}
insilmaril@0
  3144
insilmaril@417
  3145
void MapEditor::colorSubtree (QColor c)
insilmaril@0
  3146
{
insilmaril@424
  3147
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3148
	if (bo) 
insilmaril@0
  3149
	{
insilmaril@424
  3150
		saveStateChangingPart(
insilmaril@424
  3151
			bo, 
insilmaril@424
  3152
			bo,
insilmaril@445
  3153
			QString ("colorSubtree (\"%1\")").arg(c.name()),
insilmaril@424
  3154
			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3155
		);	
insilmaril@424
  3156
		bo->setColorSubtree (c); // color links, color childs
insilmaril@0
  3157
	}
insilmaril@0
  3158
}
insilmaril@0
  3159
insilmaril@0
  3160
insilmaril@0
  3161
void MapEditor::toggleStandardFlag(QString f)
insilmaril@0
  3162
{
insilmaril@424
  3163
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3164
	if (bo) 
insilmaril@0
  3165
	{
insilmaril@424
  3166
		QString u,r;
insilmaril@424
  3167
		if (bo->isSetStandardFlag(f))
insilmaril@366
  3168
		{
insilmaril@424
  3169
			r="unsetFlag";
insilmaril@424
  3170
			u="setFlag";
insilmaril@424
  3171
		}	
insilmaril@424
  3172
		else
insilmaril@424
  3173
		{
insilmaril@424
  3174
			u="unsetFlag";
insilmaril@424
  3175
			r="setFlag";
insilmaril@424
  3176
		}	
insilmaril@424
  3177
		saveState(
insilmaril@424
  3178
			bo,
insilmaril@424
  3179
			QString("%1 (\"%2\")").arg(u).arg(f), 
insilmaril@424
  3180
			bo,
insilmaril@424
  3181
			QString("%1 (\"%2\")").arg(r).arg(f),
insilmaril@424
  3182
			QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
insilmaril@424
  3183
		bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
insilmaril@442
  3184
		xelection.update();
insilmaril@424
  3185
	}
insilmaril@0
  3186
}
insilmaril@0
  3187
insilmaril@0
  3188
insilmaril@0
  3189
BranchObj* MapEditor::findText (QString s, bool cs)
insilmaril@0
  3190
{
insilmaril@366
  3191
	QTextDocument::FindFlags flags=0;
insilmaril@366
  3192
	if (cs) flags=QTextDocument::FindCaseSensitively;
insilmaril@366
  3193
insilmaril@0
  3194
	if (!itFind) 
insilmaril@0
  3195
	{	// Nothing found or new find process
insilmaril@0
  3196
		if (EOFind)
insilmaril@0
  3197
			// nothing found, start again
insilmaril@0
  3198
			EOFind=false;
insilmaril@645
  3199
		itFind=model->first();
insilmaril@0
  3200
	}	
insilmaril@0
  3201
	bool searching=true;
insilmaril@0
  3202
	bool foundNote=false;
insilmaril@0
  3203
	while (searching && !EOFind)
insilmaril@0
  3204
	{
insilmaril@0
  3205
		if (itFind)
insilmaril@0
  3206
		{
insilmaril@0
  3207
			// Searching in Note
insilmaril@0
  3208
			if (itFind->getNote().contains(s,cs))
insilmaril@0
  3209
			{
insilmaril@424
  3210
				if (xelection.single()!=itFind) 
insilmaril@0
  3211
				{
insilmaril@424
  3212
					xelection.select(itFind);
insilmaril@0
  3213
					ensureSelectionVisible();
insilmaril@0
  3214
				}
insilmaril@366
  3215
				if (textEditor->findText(s,flags)) 
insilmaril@0
  3216
				{
insilmaril@0
  3217
					searching=false;
insilmaril@0
  3218
					foundNote=true;
insilmaril@0
  3219
				}	
insilmaril@0
  3220
			}
insilmaril@0
  3221
			// Searching in Heading
insilmaril@0
  3222
			if (searching && itFind->getHeading().contains (s,cs) ) 
insilmaril@0
  3223
			{
insilmaril@424
  3224
				xelection.select(itFind);
insilmaril@0
  3225
				ensureSelectionVisible();
insilmaril@0
  3226
				searching=false;
insilmaril@0
  3227
			}
insilmaril@0
  3228
		}	
insilmaril@0
  3229
		if (!foundNote)
insilmaril@0
  3230
		{
insilmaril@645
  3231
			itFind=model->next(itFind);
insilmaril@0
  3232
			if (!itFind) EOFind=true;
insilmaril@0
  3233
		}
insilmaril@0
  3234
	}	
insilmaril@0
  3235
	if (!searching)
insilmaril@424
  3236
		return xelection.getBranch();
insilmaril@424
  3237
	else
insilmaril@0
  3238
		return NULL;
insilmaril@0
  3239
}
insilmaril@0
  3240
insilmaril@0
  3241
void MapEditor::findReset()
insilmaril@0
  3242
{	// Necessary if text to find changes during a find process
insilmaril@0
  3243
	itFind=NULL;
insilmaril@0
  3244
	EOFind=false;
insilmaril@0
  3245
}
insilmaril@395
  3246
void MapEditor::setURL(const QString &url)
insilmaril@395
  3247
{
insilmaril@424
  3248
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3249
	if (bo)
insilmaril@424
  3250
	{
insilmaril@395
  3251
		QString oldurl=bo->getURL();
insilmaril@395
  3252
		bo->setURL (url);
insilmaril@395
  3253
		saveState (
insilmaril@424
  3254
			bo,
insilmaril@395
  3255
			QString ("setURL (\"%1\")").arg(oldurl),
insilmaril@424
  3256
			bo,
insilmaril@395
  3257
			QString ("setURL (\"%1\")").arg(url),
insilmaril@395
  3258
			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
insilmaril@395
  3259
		);
insilmaril@395
  3260
		updateActions();
insilmaril@645
  3261
		model->reposition();
insilmaril@491
  3262
		xelection.update();
insilmaril@491
  3263
		ensureSelectionVisible();
insilmaril@395
  3264
	}
insilmaril@395
  3265
}	
insilmaril@0
  3266
insilmaril@0
  3267
void MapEditor::editURL()
insilmaril@0
  3268
{
insilmaril@424
  3269
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3270
	if (bo)
insilmaril@0
  3271
	{		
insilmaril@0
  3272
		bool ok;
insilmaril@0
  3273
		QString text = QInputDialog::getText(
insilmaril@0
  3274
				"VYM", tr("Enter URL:"), QLineEdit::Normal,
insilmaril@143
  3275
				bo->getURL(), &ok, this );
insilmaril@0
  3276
		if ( ok) 
insilmaril@0
  3277
			// user entered something and pressed OK
insilmaril@395
  3278
			setURL (text);
insilmaril@0
  3279
	}
insilmaril@0
  3280
}
insilmaril@0
  3281
insilmaril@528
  3282
void MapEditor::editLocalURL()
insilmaril@528
  3283
{
insilmaril@528
  3284
	BranchObj *bo=xelection.getBranch();
insilmaril@528
  3285
	if (bo)
insilmaril@528
  3286
	{		
insilmaril@528
  3287
		QStringList filters;
insilmaril@528
  3288
		filters <<"All files (*)";
insilmaril@528
  3289
		filters << tr("Text","Filedialog") + " (*.txt)";
insilmaril@528
  3290
		filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
insilmaril@528
  3291
		filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
insilmaril@528
  3292
		filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
insilmaril@528
  3293
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3294
		fd->setFilters (filters);
insilmaril@528
  3295
		fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3296
		fd->setDirectory (lastFileDir);
insilmaril@528
  3297
		if (! bo->getVymLink().isEmpty() )
insilmaril@528
  3298
			fd->selectFile( bo->getURL() );
insilmaril@528
  3299
		fd->show();
insilmaril@528
  3300
insilmaril@528
  3301
		if ( fd->exec() == QDialog::Accepted )
insilmaril@528
  3302
		{
insilmaril@528
  3303
			lastFileDir=QDir (fd->directory().path());
insilmaril@528
  3304
			setURL (fd->selectedFile() );
insilmaril@528
  3305
		}
insilmaril@528
  3306
	}
insilmaril@528
  3307
}
insilmaril@528
  3308
insilmaril@266
  3309
QString MapEditor::getURL()
insilmaril@266
  3310
{
insilmaril@424
  3311
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3312
	if (bo)
insilmaril@424
  3313
		return bo->getURL();
insilmaril@266
  3314
	else
insilmaril@266
  3315
		return "";
insilmaril@266
  3316
}
insilmaril@266
  3317
insilmaril@366
  3318
QStringList MapEditor::getURLs()
insilmaril@366
  3319
{
insilmaril@366
  3320
	QStringList urls;
insilmaril@424
  3321
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3322
	if (bo)
insilmaril@366
  3323
	{		
insilmaril@366
  3324
		bo=bo->first();	
insilmaril@366
  3325
		while (bo) 
insilmaril@366
  3326
		{
insilmaril@366
  3327
			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
insilmaril@366
  3328
			bo=bo->next();
insilmaril@366
  3329
		}	
insilmaril@366
  3330
	}	
insilmaril@366
  3331
	return urls;
insilmaril@366
  3332
}
insilmaril@366
  3333
insilmaril@366
  3334
insilmaril@0
  3335
void MapEditor::editHeading2URL()
insilmaril@0
  3336
{
insilmaril@424
  3337
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3338
	if (bo)
insilmaril@424
  3339
		setURL (bo->getHeading());
insilmaril@0
  3340
}	
insilmaril@0
  3341
insilmaril@0
  3342
void MapEditor::editBugzilla2URL()
insilmaril@0
  3343
{
insilmaril@424
  3344
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3345
	if (bo)
insilmaril@0
  3346
	{		
insilmaril@143
  3347
		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
insilmaril@395
  3348
		setURL (url);
insilmaril@0
  3349
	}
insilmaril@0
  3350
}	
insilmaril@0
  3351
insilmaril@175
  3352
void MapEditor::editFATE2URL()
insilmaril@175
  3353
{
insilmaril@424
  3354
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3355
	if (bo)
insilmaril@175
  3356
	{		
insilmaril@175
  3357
		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
insilmaril@395
  3358
		saveState(
insilmaril@424
  3359
			bo,
insilmaril@395
  3360
			"setURL (\""+bo->getURL()+"\")",
insilmaril@424
  3361
			bo,
insilmaril@395
  3362
			"setURL (\""+url+"\")",
insilmaril@395
  3363
			QString("Use heading of %1 as link to FATE").arg(getName(bo))
insilmaril@395
  3364
		);	
insilmaril@175
  3365
		bo->setURL (url);
insilmaril@175
  3366
		updateActions();
insilmaril@175
  3367
	}
insilmaril@175
  3368
}	
insilmaril@175
  3369
insilmaril@0
  3370
void MapEditor::editVymLink()
insilmaril@0
  3371
{
insilmaril@424
  3372
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3373
	if (bo)
insilmaril@0
  3374
	{		
insilmaril@404
  3375
		QStringList filters;
insilmaril@404
  3376
		filters <<"VYM map (*.vym)";
insilmaril@404
  3377
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
insilmaril@404
  3378
		fd->setFilters (filters);
insilmaril@404
  3379
		fd->setCaption(vymName+" - " +tr("Link to another map"));
insilmaril@442
  3380
		fd->setDirectory (lastFileDir);
insilmaril@143
  3381
		if (! bo->getVymLink().isEmpty() )
insilmaril@404
  3382
			fd->selectFile( bo->getVymLink() );
insilmaril@0
  3383
		fd->show();
insilmaril@0
  3384
insilmaril@0
  3385
		QString fn;
insilmaril@0
  3386
		if ( fd->exec() == QDialog::Accepted )
insilmaril@143
  3387
		{
insilmaril@442
  3388
			lastFileDir=QDir (fd->directory().path());
insilmaril@395
  3389
			saveState(
insilmaril@424
  3390
				bo,
insilmaril@395
  3391
				"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3392
				bo,
insilmaril@395
  3393
				"setVymLink (\""+fd->selectedFile()+"\")",
insilmaril@395
  3394
				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
insilmaril@395
  3395
			);	
insilmaril@491
  3396
			setVymLinkInt (fd->selectedFile() );
insilmaril@143
  3397
		}
insilmaril@0
  3398
	}
insilmaril@0
  3399
}
insilmaril@0
  3400
insilmaril@0
  3401
void MapEditor::deleteVymLink()
insilmaril@0
  3402
{
insilmaril@424
  3403
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3404
	if (bo)
insilmaril@0
  3405
	{		
insilmaril@395
  3406
		saveState(
insilmaril@424
  3407
			bo,
insilmaril@395
  3408
			"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3409
			bo,
insilmaril@395
  3410
			"setVymLink (\"\")",
insilmaril@395
  3411
			QString("Unset vymlink of %1").arg(getName(bo))
insilmaril@395
  3412
		);	
insilmaril@143
  3413
		bo->setVymLink ("" );
insilmaril@0
  3414
		updateActions();
insilmaril@645
  3415
		model->reposition();
insilmaril@408
  3416
		scene()->update();
insilmaril@0
  3417
	}
insilmaril@0
  3418
}
insilmaril@0
  3419
insilmaril@395
  3420
void MapEditor::setHideExport(bool b)
insilmaril@243
  3421
{
insilmaril@424
  3422
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3423
	if (bo)
insilmaril@395
  3424
	{
insilmaril@424
  3425
		bo->setHideInExport (b);
insilmaril@395
  3426
		QString u= b ? "false" : "true";
insilmaril@395
  3427
		QString r=!b ? "false" : "true";
insilmaril@395
  3428
		
insilmaril@395
  3429
		saveState(
insilmaril@424
  3430
			bo,
insilmaril@395
  3431
			QString ("setHideExport (%1)").arg(u),
insilmaril@424
  3432
			bo,
insilmaril@395
  3433
			QString ("setHideExport (%1)").arg(r),
insilmaril@424
  3434
			QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
insilmaril@395
  3435
		);	
insilmaril@243
  3436
		updateActions();
insilmaril@645
  3437
		model->reposition();
insilmaril@491
  3438
		xelection.update();
insilmaril@408
  3439
		scene()->update();
insilmaril@243
  3440
	}
insilmaril@243
  3441
}
insilmaril@243
  3442
insilmaril@395
  3443
void MapEditor::toggleHideExport()
insilmaril@395
  3444
{
insilmaril@424
  3445
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3446
	if (bo)
insilmaril@424
  3447
		setHideExport ( !bo->hideInExport() );
insilmaril@395
  3448
}
insilmaril@395
  3449
insilmaril@0
  3450
QString MapEditor::getVymLink()
insilmaril@0
  3451
{
insilmaril@424
  3452
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3453
	if (bo)
insilmaril@424
  3454
		return bo->getVymLink();
insilmaril@424
  3455
	else	
insilmaril@424
  3456
		return "";
insilmaril@0
  3457
	
insilmaril@0
  3458
}
insilmaril@0
  3459
insilmaril@366
  3460
QStringList MapEditor::getVymLinks()
insilmaril@366
  3461
{
insilmaril@366
  3462
	QStringList links;
insilmaril@424
  3463
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3464
	if (bo)
insilmaril@366
  3465
	{		
insilmaril@366
  3466
		bo=bo->first();	
insilmaril@366
  3467
		while (bo) 
insilmaril@366
  3468
		{
insilmaril@366
  3469
			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
insilmaril@366
  3470
			bo=bo->next();
insilmaril@366
  3471
		}	
insilmaril@366
  3472
	}	
insilmaril@366
  3473
	return links;
insilmaril@366
  3474
}
insilmaril@366
  3475
insilmaril@366
  3476
insilmaril@395
  3477
void MapEditor::deleteKeepChilds()
insilmaril@98
  3478
{
insilmaril@424
  3479
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3480
	BranchObj *par;
insilmaril@424
  3481
	if (bo)
insilmaril@424
  3482
	{
insilmaril@424
  3483
		par=(BranchObj*)(bo->getParObj());
insilmaril@408
  3484
		QPointF p=bo->getRelPos();
insilmaril@395
  3485
		saveStateChangingPart(
insilmaril@424
  3486
			bo->getParObj(),
insilmaril@424
  3487
			bo,
insilmaril@395
  3488
			"deleteKeepChilds ()",
insilmaril@395
  3489
			QString("Remove %1 and keep its childs").arg(getName(bo))
insilmaril@395
  3490
		);
insilmaril@394
  3491
insilmaril@424
  3492
		QString sel=bo->getSelectString();
insilmaril@98
  3493
		unselect();
insilmaril@98
  3494
		par->removeBranchHere(bo);
insilmaril@645
  3495
		model->reposition();
insilmaril@98
  3496
		select (sel);
insilmaril@424
  3497
		xelection.getBranch()->move2RelPos (p);
insilmaril@645
  3498
		model->reposition();
insilmaril@98
  3499
	}	
insilmaril@98
  3500
}
insilmaril@98
  3501
insilmaril@395
  3502
void MapEditor::deleteChilds()
insilmaril@98
  3503
{
insilmaril@424
  3504
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3505
	if (bo)
insilmaril@98
  3506
	{		
insilmaril@395
  3507
		saveStateChangingPart(
insilmaril@491
  3508
			bo, 
insilmaril@424
  3509
			bo,
insilmaril@395
  3510
			"deleteChilds ()",
insilmaril@424
  3511
			QString( "Remove childs of branch %1").arg(getName(bo))
insilmaril@395
  3512
		);
insilmaril@424
  3513
		bo->removeChilds();
insilmaril@645
  3514
		model->reposition();
insilmaril@98
  3515
	}	
insilmaril@98
  3516
}
insilmaril@98
  3517
insilmaril@0
  3518
void MapEditor::editMapInfo()
insilmaril@0
  3519
{
insilmaril@0
  3520
	ExtraInfoDialog dia;
insilmaril@0
  3521
	dia.setMapName (getFileName() );
insilmaril@645
  3522
	dia.setAuthor (model->getAuthor() );
insilmaril@645
  3523
	dia.setComment(model->getComment() );
insilmaril@0
  3524
insilmaril@0
  3525
	// Calc some stats
insilmaril@0
  3526
	QString stats;
insilmaril@408
  3527
    stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
insilmaril@0
  3528
insilmaril@0
  3529
	uint b=0;
insilmaril@0
  3530
	uint f=0;
insilmaril@0
  3531
	uint n=0;
insilmaril@103
  3532
	uint xl=0;
insilmaril@0
  3533
	BranchObj *bo;
insilmaril@645
  3534
	bo=model->first();
insilmaril@0
  3535
	while (bo) 
insilmaril@0
  3536
	{
insilmaril@0
  3537
		if (!bo->getNote().isEmpty() ) n++;
insilmaril@0
  3538
		f+= bo->countFloatImages();
insilmaril@0
  3539
		b++;
insilmaril@103
  3540
		xl+=bo->countXLinks();
insilmaril@645
  3541
		bo=model->next(bo);
insilmaril@0
  3542
	}
insilmaril@0
  3543
    stats+=QString ("%1 branches\n").arg (b-1,6);
insilmaril@104
  3544
    stats+=QString ("%1 xLinks \n").arg (xl,6);
insilmaril@0
  3545
    stats+=QString ("%1 notes\n").arg (n,6);
insilmaril@0
  3546
    stats+=QString ("%1 images\n").arg (f,6);
insilmaril@0
  3547
	dia.setStats (stats);
insilmaril@0
  3548
insilmaril@0
  3549
	// Finally show dialog
insilmaril@0
  3550
	if (dia.exec() == QDialog::Accepted)
insilmaril@0
  3551
	{
insilmaril@398
  3552
		setMapAuthor (dia.getAuthor() );
insilmaril@398
  3553
		setMapComment (dia.getComment() );
insilmaril@0
  3554
	}
insilmaril@0
  3555
}
insilmaril@0
  3556
insilmaril@442
  3557
void MapEditor::ensureSelectionVisible()
insilmaril@442
  3558
{
insilmaril@442
  3559
	LinkableMapObj *lmo=xelection.single();
insilmaril@442
  3560
	if (lmo) ensureVisible (lmo->getBBox() );
insilmaril@442
  3561
	
insilmaril@442
  3562
}
insilmaril@442
  3563
insilmaril@442
  3564
void MapEditor::updateSelection()
insilmaril@442
  3565
{
insilmaril@442
  3566
	// Tell selection to update geometries
insilmaril@442
  3567
	xelection.update();
insilmaril@442
  3568
}
insilmaril@442
  3569
insilmaril@0
  3570
void MapEditor::updateActions()
insilmaril@0
  3571
{
insilmaril@442
  3572
	// Tell mainwindow to update states of actions
insilmaril@390
  3573
	mainWindow->updateActions();
insilmaril@412
  3574
	// TODO maybe don't update if blockReposition is set
insilmaril@0
  3575
}
insilmaril@0
  3576
insilmaril@160
  3577
void MapEditor::updateNoteFlag()
insilmaril@160
  3578
{
insilmaril@427
  3579
	setChanged();
insilmaril@424
  3580
	BranchObj *bo=xelection.getBranch();
insilmaril@427
  3581
	if (bo) 
insilmaril@427
  3582
	{
insilmaril@427
  3583
		bo->updateNoteFlag();
insilmaril@427
  3584
		mainWindow->updateActions();
insilmaril@427
  3585
	}	
insilmaril@160
  3586
}
insilmaril@160
  3587
insilmaril@398
  3588
void MapEditor::setMapAuthor (const QString &s)
insilmaril@0
  3589
{
insilmaril@398
  3590
	saveState (
insilmaril@645
  3591
		QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
insilmaril@398
  3592
		QString ("setMapAuthor (\"%1\")").arg(s),
insilmaril@398
  3593
		QString ("Set author of map to \"%1\"").arg(s)
insilmaril@398
  3594
	);
insilmaril@645
  3595
	model->setAuthor (s);
insilmaril@398
  3596
}
insilmaril@398
  3597
insilmaril@398
  3598
void MapEditor::setMapComment (const QString &s)
insilmaril@398
  3599
{
insilmaril@398
  3600
	saveState (
insilmaril@645
  3601
		QString ("setMapComment (\"%1\")").arg(model->getComment()),
insilmaril@398
  3602
		QString ("setMapComment (\"%1\")").arg(s),
insilmaril@398
  3603
		QString ("Set comment of map")
insilmaril@398
  3604
	);
insilmaril@645
  3605
	model->setComment (s);
insilmaril@398
  3606
}
insilmaril@398
  3607
insilmaril@398
  3608
void MapEditor::setMapLinkStyle (const QString & s)
insilmaril@398
  3609
{
insilmaril@645
  3610
	QString snow;
insilmaril@645
  3611
	if (linkstyle==LinkableMapObj::Line)
insilmaril@645
  3612
		snow="StyleLine";
insilmaril@645
  3613
	else if (linkstyle==LinkableMapObj::Parabel)
insilmaril@645
  3614
		snow="StyleParabel";
insilmaril@645
  3615
	else if (linkstyle==LinkableMapObj::PolyLine)
insilmaril@645
  3616
		snow="StylePolyLine";
insilmaril@645
  3617
	else if (linkstyle==LinkableMapObj::PolyParabel)
insilmaril@645
  3618
		snow="StyleParabel";
insilmaril@645
  3619
insilmaril@645
  3620
	saveState (
insilmaril@398
  3621
		QString("setMapLinkStyle (\"%1\")").arg(s),
insilmaril@645
  3622
		QString("setMapLinkStyle (\"%1\")").arg(snow),
insilmaril@398
  3623
		QString("Set map link style (\"%1\")").arg(s)
insilmaril@398
  3624
	);	
insilmaril@398
  3625
insilmaril@398
  3626
	if (s=="StyleLine")
insilmaril@473
  3627
		linkstyle=LinkableMapObj::Line;
insilmaril@398
  3628
	else if (s=="StyleParabel")
insilmaril@473
  3629
		linkstyle=LinkableMapObj::Parabel;
insilmaril@398
  3630
	else if (s=="StylePolyLine")
insilmaril@473
  3631
		linkstyle=LinkableMapObj::PolyLine;
insilmaril@398
  3632
	else	
insilmaril@473
  3633
		linkstyle=LinkableMapObj::PolyParabel;
insilmaril@398
  3634
insilmaril@0
  3635
	BranchObj *bo;
insilmaril@645
  3636
	bo=model->first();
insilmaril@645
  3637
	bo=model->next(bo);
insilmaril@0
  3638
	while (bo) 
insilmaril@0
  3639
	{
insilmaril@0
  3640
		bo->setLinkStyle(bo->getDefLinkStyle());
insilmaril@645
  3641
		bo=model->next(bo);
insilmaril@0
  3642
	}
insilmaril@645
  3643
	model->reposition();
insilmaril@0
  3644
}
insilmaril@0
  3645
insilmaril@473
  3646
LinkableMapObj::Style MapEditor::getMapLinkStyle ()
insilmaril@0
  3647
{
insilmaril@0
  3648
	return linkstyle;
insilmaril@0
  3649
}	
insilmaril@0
  3650
insilmaril@398
  3651
void MapEditor::setMapDefLinkColor(QColor c)
insilmaril@0
  3652
{
insilmaril@97
  3653
	defLinkColor=c;
insilmaril@497
  3654
	BranchObj *bo;
insilmaril@645
  3655
	bo=model->first();
insilmaril@497
  3656
	while (bo) 
insilmaril@497
  3657
	{
insilmaril@497
  3658
		bo->setLinkColor();
insilmaril@645
  3659
		bo=model->next(bo);
insilmaril@497
  3660
	}
insilmaril@0
  3661
	updateActions();
insilmaril@0
  3662
}
insilmaril@0
  3663
insilmaril@398
  3664
void MapEditor::setMapLinkColorHintInt()
insilmaril@0
  3665
{
insilmaril@398
  3666
	// called from setMapLinkColorHint(lch) or at end of parse
insilmaril@0
  3667
	BranchObj *bo;
insilmaril@645
  3668
	bo=model->first();
insilmaril@0
  3669
	while (bo) 
insilmaril@0
  3670
	{
insilmaril@0
  3671
		bo->setLinkColor();
insilmaril@645
  3672
		bo=model->next(bo);
insilmaril@0
  3673
	}
insilmaril@0
  3674
}
insilmaril@0
  3675
insilmaril@473
  3676
void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
insilmaril@0
  3677
{
insilmaril@0
  3678
	linkcolorhint=lch;
insilmaril@398
  3679
	setMapLinkColorHintInt();
insilmaril@0
  3680
}
insilmaril@0
  3681
insilmaril@398
  3682
void MapEditor::toggleMapLinkColorHint()
insilmaril@0
  3683
{
insilmaril@473
  3684
	if (linkcolorhint==LinkableMapObj::HeadingColor)
insilmaril@473
  3685
		linkcolorhint=LinkableMapObj::DefaultColor;
insilmaril@0
  3686
	else	
insilmaril@473
  3687
		linkcolorhint=LinkableMapObj::HeadingColor;
insilmaril@0
  3688
	BranchObj *bo;
insilmaril@645
  3689
	bo=model->first();
insilmaril@0
  3690
	while (bo) 
insilmaril@0
  3691
	{
insilmaril@0
  3692
		bo->setLinkColor();
insilmaril@645
  3693
		bo=model->next(bo);
insilmaril@0
  3694
	}
insilmaril@0
  3695
}
insilmaril@0
  3696
insilmaril@473
  3697
LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
insilmaril@0
  3698
{
insilmaril@0
  3699
	return linkcolorhint;
insilmaril@0
  3700
}
insilmaril@0
  3701
insilmaril@398
  3702
QColor MapEditor::getMapDefLinkColor()
insilmaril@0
  3703
{
insilmaril@97
  3704
	return defLinkColor;
insilmaril@97
  3705
}
insilmaril@97
  3706
insilmaril@398
  3707
void MapEditor::setMapDefXLinkColor(QColor col)
insilmaril@97
  3708
{
insilmaril@97
  3709
	defXLinkColor=col;
insilmaril@97
  3710
}
insilmaril@97
  3711
insilmaril@398
  3712
QColor MapEditor::getMapDefXLinkColor()
insilmaril@97
  3713
{
insilmaril@97
  3714
	return defXLinkColor;
insilmaril@97
  3715
}
insilmaril@97
  3716
insilmaril@398
  3717
void MapEditor::setMapDefXLinkWidth (int w)
insilmaril@97
  3718
{
insilmaril@97
  3719
	defXLinkWidth=w;
insilmaril@97
  3720
}
insilmaril@97
  3721
insilmaril@398
  3722
int MapEditor::getMapDefXLinkWidth()
insilmaril@97
  3723
{
insilmaril@97
  3724
	return defXLinkWidth;
insilmaril@0
  3725
}
insilmaril@0
  3726
insilmaril@398
  3727
void MapEditor::selectMapLinkColor()
insilmaril@0
  3728
{
insilmaril@97
  3729
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@0
  3730
	if ( !col.isValid() ) return;
insilmaril@398
  3731
	saveState (
insilmaril@398
  3732
		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
insilmaril@398
  3733
		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
insilmaril@497
  3734
		QString("Set map link color to %1").arg(col.name())
insilmaril@398
  3735
	);
insilmaril@398
  3736
	setMapDefLinkColor( col );
insilmaril@442
  3737
}
insilmaril@442
  3738
insilmaril@442
  3739
void MapEditor::selectMapSelectionColor()
insilmaril@442
  3740
{
insilmaril@442
  3741
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@442
  3742
	setSelectionColor (col);
insilmaril@442
  3743
}
insilmaril@442
  3744
insilmaril@442
  3745
void MapEditor::setSelectionColorInt (QColor col)
insilmaril@442
  3746
{
insilmaril@442
  3747
	if ( !col.isValid() ) return;
insilmaril@442
  3748
	xelection.setColor (col);
insilmaril@442
  3749
}
insilmaril@442
  3750
insilmaril@442
  3751
void MapEditor::setSelectionColor(QColor col)
insilmaril@442
  3752
{
insilmaril@442
  3753
	if ( !col.isValid() ) return;
insilmaril@442
  3754
	saveState (
insilmaril@442
  3755
		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
insilmaril@442
  3756
		QString("setSelectionColor (%1)").arg(col.name()),
insilmaril@442
  3757
		QString("Set color of selection box to %1").arg(col.name())
insilmaril@442
  3758
	);
insilmaril@442
  3759
	setSelectionColorInt (col);
insilmaril@442
  3760
}
insilmaril@442
  3761
insilmaril@442
  3762
QColor MapEditor::getSelectionColor()
insilmaril@442
  3763
{
insilmaril@442
  3764
	return xelection.getColor();
insilmaril@0
  3765
}
insilmaril@0
  3766
insilmaril@473
  3767
bool MapEditor::scrollBranch(BranchObj *bo)
insilmaril@0
  3768
{
insilmaril@427
  3769
	if (bo)
insilmaril@0
  3770
	{
insilmaril@427
  3771
		if (bo->isScrolled()) return false;
insilmaril@427
  3772
		if (bo->countBranches()==0) return false;
insilmaril@427
  3773
		if (bo->getDepth()==0) return false;
insilmaril@395
  3774
		QString u,r;
insilmaril@427
  3775
		r="scroll";
insilmaril@427
  3776
		u="unscroll";
insilmaril@395
  3777
		saveState(
insilmaril@424
  3778
			bo,
insilmaril@395
  3779
			QString ("%1 ()").arg(u),
insilmaril@424
  3780
			bo,
insilmaril@395
  3781
			QString ("%1 ()").arg(r),
insilmaril@395
  3782
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@395
  3783
		);
insilmaril@0
  3784
		bo->toggleScroll();
insilmaril@491
  3785
		xelection.update();
insilmaril@408
  3786
		scene()->update();
insilmaril@427
  3787
		return true;
insilmaril@427
  3788
	}	
insilmaril@427
  3789
	return false;
insilmaril@427
  3790
}
insilmaril@427
  3791
insilmaril@473
  3792
bool MapEditor::unscrollBranch(BranchObj *bo)
insilmaril@427
  3793
{
insilmaril@427
  3794
	if (bo)
insilmaril@427
  3795
	{
insilmaril@427
  3796
		if (!bo->isScrolled()) return false;
insilmaril@427
  3797
		if (bo->countBranches()==0) return false;
insilmaril@427
  3798
		if (bo->getDepth()==0) return false;
insilmaril@427
  3799
		QString u,r;
insilmaril@427
  3800
		u="scroll";
insilmaril@427
  3801
		r="unscroll";
insilmaril@427
  3802
		saveState(
insilmaril@427
  3803
			bo,
insilmaril@427
  3804
			QString ("%1 ()").arg(u),
insilmaril@427
  3805
			bo,
insilmaril@427
  3806
			QString ("%1 ()").arg(r),
insilmaril@427
  3807
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@427
  3808
		);
insilmaril@427
  3809
		bo->toggleScroll();
insilmaril@491
  3810
		xelection.update();
insilmaril@427
  3811
		scene()->update();
insilmaril@427
  3812
		return true;
insilmaril@427
  3813
	}	
insilmaril@427
  3814
	return false;
insilmaril@427
  3815
}
insilmaril@427
  3816
insilmaril@427
  3817
void MapEditor::toggleScroll()
insilmaril@427
  3818
{
insilmaril@427
  3819
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  3820
	if (xelection.type()==Selection::Branch )
insilmaril@427
  3821
	{
insilmaril@427
  3822
		if (bo->isScrolled())
insilmaril@473
  3823
			unscrollBranch (bo);
insilmaril@427
  3824
		else
insilmaril@473
  3825
			scrollBranch (bo);
insilmaril@0
  3826
	}
insilmaril@0
  3827
}
insilmaril@0
  3828
insilmaril@473
  3829
void MapEditor::unscrollChilds() 
insilmaril@0
  3830
{
insilmaril@428
  3831
	BranchObj *bo=xelection.getBranch();
insilmaril@428
  3832
	if (bo)
insilmaril@0
  3833
	{
insilmaril@428
  3834
		bo->first();
insilmaril@428
  3835
		while (bo) 
insilmaril@428
  3836
		{
insilmaril@473
  3837
			if (bo->isScrolled()) unscrollBranch (bo);
insilmaril@428
  3838
			bo=bo->next();
insilmaril@428
  3839
		}
insilmaril@428
  3840
	}	
insilmaril@0
  3841
}
insilmaril@0
  3842
insilmaril@432
  3843
FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
insilmaril@432
  3844
{
insilmaril@432
  3845
	BranchObj *bo=xelection.getBranch();
insilmaril@432
  3846
	if (bo)
insilmaril@432
  3847
	{
insilmaril@432
  3848
		FloatImageObj *fio;
insilmaril@432
  3849
		bo->addFloatImage();
insilmaril@432
  3850
		fio=bo->getLastFloatImage();
insilmaril@432
  3851
		fio->load(fn);
insilmaril@645
  3852
		model->reposition();
insilmaril@432
  3853
		scene()->update();
insilmaril@432
  3854
		return fio;
insilmaril@432
  3855
	}
insilmaril@432
  3856
	return NULL;
insilmaril@432
  3857
}	
insilmaril@428
  3858
insilmaril@0
  3859
void MapEditor::loadFloatImage ()
insilmaril@0
  3860
{
insilmaril@424
  3861
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3862
	if (bo)
insilmaril@0
  3863
	{
insilmaril@0
  3864
insilmaril@366
  3865
		Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@366
  3866
		fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@0
  3867
		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@0
  3868
		ImagePreview *p =new ImagePreview (fd);
insilmaril@0
  3869
		fd->setContentsPreviewEnabled( TRUE );
insilmaril@0
  3870
		fd->setContentsPreview( p, p );
insilmaril@366
  3871
		fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@404
  3872
		fd->setCaption(vymName+" - " +tr("Load image"));
insilmaril@0
  3873
		fd->setDir (lastImageDir);
insilmaril@0
  3874
		fd->show();
insilmaril@0
  3875
insilmaril@0
  3876
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  3877
		{
insilmaril@491
  3878
			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
insilmaril@366
  3879
			lastImageDir=QDir (fd->dirPath());
insilmaril@432
  3880
			QString s;
insilmaril@395
  3881
			FloatImageObj *fio;
insilmaril@432
  3882
			for (int j=0; j<fd->selectedFiles().count(); j++)
insilmaril@185
  3883
			{
insilmaril@432
  3884
				s=fd->selectedFiles().at(j);
insilmaril@432
  3885
				fio=loadFloatImageInt (s);
insilmaril@432
  3886
				if (fio)
insilmaril@432
  3887
					saveState(
insilmaril@432
  3888
						(LinkableMapObj*)fio,
insilmaril@432
  3889
						"delete ()",
insilmaril@432
  3890
						bo, 
insilmaril@432
  3891
						QString ("loadImage (%1)").arg(s ),
insilmaril@432
  3892
						QString("Add image %1 to %2").arg(s).arg(getName(bo))
insilmaril@432
  3893
					);
insilmaril@432
  3894
				else
insilmaril@491
  3895
					// TODO loadFIO error handling
insilmaril@432
  3896
					qWarning ("Failed to load "+s);
insilmaril@185
  3897
			}
insilmaril@0
  3898
		}
insilmaril@236
  3899
		delete (p);
insilmaril@236
  3900
		delete (fd);
insilmaril@0
  3901
	}
insilmaril@0
  3902
}
insilmaril@0
  3903
insilmaril@434
  3904
void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
insilmaril@434
  3905
{
insilmaril@434
  3906
	fio->save (fn,type);
insilmaril@434
  3907
}
insilmaril@434
  3908
insilmaril@366
  3909
void MapEditor::saveFloatImage ()
insilmaril@0
  3910
{
insilmaril@424
  3911
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  3912
	if (fio)
insilmaril@0
  3913
	{
insilmaril@366
  3914
		QFileDialog *fd=new QFileDialog( this);
insilmaril@366
  3915
		fd->setFilters (imageIO.getFilters());
insilmaril@404
  3916
		fd->setCaption(vymName+" - " +tr("Save image"));
insilmaril@366
  3917
		fd->setFileMode( QFileDialog::AnyFile );
insilmaril@366
  3918
		fd->setDirectory (lastImageDir);
insilmaril@366
  3919
//		fd->setSelection (fio->getOriginalFilename());
insilmaril@0
  3920
		fd->show();
insilmaril@0
  3921
insilmaril@0
  3922
		QString fn;
insilmaril@434
  3923
		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
insilmaril@0
  3924
		{
insilmaril@434
  3925
			fn=fd->selectedFiles().at(0);
insilmaril@434
  3926
			if (QFile (fn).exists() )
insilmaril@0
  3927
			{
insilmaril@404
  3928
				QMessageBox mb( vymName,
insilmaril@159
  3929
					tr("The file %1 exists already.\n"
insilmaril@434
  3930
					"Do you want to overwrite it?").arg(fn),
insilmaril@0
  3931
				QMessageBox::Warning,
insilmaril@0
  3932
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  3933
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  3934
				QMessageBox::QMessageBox::NoButton );
insilmaril@0
  3935
insilmaril@0
  3936
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  3937
				mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  3938
				switch( mb.exec() ) 
insilmaril@0
  3939
				{
insilmaril@0
  3940
					case QMessageBox::Yes:
insilmaril@0
  3941
						// save 
insilmaril@0
  3942
						break;;
insilmaril@0
  3943
					case QMessageBox::Cancel:
insilmaril@0
  3944
						// do nothing
insilmaril@377
  3945
						delete (fd);
insilmaril@0
  3946
						return;
insilmaril@0
  3947
						break;
insilmaril@0
  3948
				}
insilmaril@0
  3949
			}
insilmaril@434
  3950
			saveFloatImageInt (fio,fd->selectedFilter(),fn );
insilmaril@0
  3951
		}
insilmaril@377
  3952
		delete (fd);
insilmaril@0
  3953
	}
insilmaril@0
  3954
}
insilmaril@0
  3955
insilmaril@473
  3956
void MapEditor::setFrameType(const FrameObj::FrameType &t)
insilmaril@0
  3957
{
insilmaril@424
  3958
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3959
	if (bo)
insilmaril@0
  3960
	{
insilmaril@473
  3961
		QString s=bo->getFrameTypeName();
insilmaril@424
  3962
		bo->setFrameType (t);
insilmaril@473
  3963
		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
insilmaril@473
  3964
			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
insilmaril@645
  3965
		model->reposition();
insilmaril@424
  3966
		bo->updateLink();
insilmaril@0
  3967
	}
insilmaril@0
  3968
}
insilmaril@0
  3969
insilmaril@473
  3970
void MapEditor::setFrameType(const QString &s)	
insilmaril@445
  3971
{
insilmaril@445
  3972
	BranchObj *bo=xelection.getBranch();
insilmaril@445
  3973
	if (bo)
insilmaril@445
  3974
	{
insilmaril@473
  3975
		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
insilmaril@473
  3976
			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
insilmaril@445
  3977
		bo->setFrameType (s);
insilmaril@645
  3978
		model->reposition();
insilmaril@445
  3979
		bo->updateLink();
insilmaril@445
  3980
	}
insilmaril@445
  3981
}
insilmaril@445
  3982
insilmaril@473
  3983
void MapEditor::setFramePenColor(const QColor &c)	
insilmaril@442
  3984
{
insilmaril@442
  3985
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3986
	if (bo)
insilmaril@473
  3987
	{
insilmaril@473
  3988
		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
insilmaril@473
  3989
			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
insilmaril@442
  3990
		bo->setFramePenColor (c);
insilmaril@473
  3991
	}	
insilmaril@442
  3992
}
insilmaril@442
  3993
insilmaril@473
  3994
void MapEditor::setFrameBrushColor(const QColor &c)	
insilmaril@442
  3995
{
insilmaril@442
  3996
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3997
	if (bo)
insilmaril@473
  3998
	{
insilmaril@473
  3999
		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
insilmaril@473
  4000
			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
insilmaril@442
  4001
		bo->setFrameBrushColor (c);
insilmaril@473
  4002
	}	
insilmaril@473
  4003
}
insilmaril@473
  4004
insilmaril@486
  4005
void MapEditor::setFramePadding (const int &i)
insilmaril@473
  4006
{
insilmaril@473
  4007
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4008
	if (bo)
insilmaril@473
  4009
	{
insilmaril@486
  4010
		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
insilmaril@486
  4011
			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
insilmaril@486
  4012
		bo->setFramePadding (i);
insilmaril@645
  4013
		model->reposition();
insilmaril@486
  4014
		bo->updateLink();
insilmaril@473
  4015
	}	
insilmaril@473
  4016
}
insilmaril@473
  4017
insilmaril@486
  4018
void MapEditor::setFrameBorderWidth(const int &i)
insilmaril@473
  4019
{
insilmaril@473
  4020
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4021
	if (bo)
insilmaril@473
  4022
	{
insilmaril@486
  4023
		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
insilmaril@486
  4024
			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
insilmaril@486
  4025
		bo->setFrameBorderWidth (i);
insilmaril@645
  4026
		model->reposition();
insilmaril@486
  4027
		bo->updateLink();
insilmaril@473
  4028
	}	
insilmaril@442
  4029
}
insilmaril@442
  4030
insilmaril@437
  4031
void MapEditor::setIncludeImagesVer(bool b)	
insilmaril@175
  4032
{
insilmaril@424
  4033
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4034
	if (bo)
insilmaril@424
  4035
	{
insilmaril@434
  4036
		QString u= b ? "false" : "true";
insilmaril@434
  4037
		QString r=!b ? "false" : "true";
insilmaril@434
  4038
		
insilmaril@434
  4039
		saveState(
insilmaril@434
  4040
			bo,
insilmaril@434
  4041
			QString("setIncludeImagesVertically (%1)").arg(u),
insilmaril@434
  4042
			bo, 
insilmaril@434
  4043
			QString("setIncludeImagesVertically (%1)").arg(r),
insilmaril@434
  4044
			QString("Include images vertically in %1").arg(getName(bo))
insilmaril@434
  4045
		);	
insilmaril@424
  4046
		bo->setIncludeImagesVer(b);
insilmaril@645
  4047
		model->reposition();
insilmaril@424
  4048
	}	
insilmaril@175
  4049
}
insilmaril@175
  4050
insilmaril@437
  4051
void MapEditor::setIncludeImagesHor(bool b)	
insilmaril@175
  4052
{
insilmaril@424
  4053
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4054
	if (bo)
insilmaril@424
  4055
	{
insilmaril@434
  4056
		QString u= b ? "false" : "true";
insilmaril@434
  4057
		QString r=!b ? "false" : "true";
insilmaril@434
  4058
		
insilmaril@434
  4059
		saveState(
insilmaril@434
  4060
			bo,
insilmaril@434
  4061
			QString("setIncludeImagesHorizontally (%1)").arg(u),
insilmaril@434
  4062
			bo, 
insilmaril@434
  4063
			QString("setIncludeImagesHorizontally (%1)").arg(r),
insilmaril@434
  4064
			QString("Include images horizontally in %1").arg(getName(bo))
insilmaril@434
  4065
		);	
insilmaril@424
  4066
		bo->setIncludeImagesHor(b);
insilmaril@645
  4067
		model->reposition();
insilmaril@424
  4068
	}	
insilmaril@175
  4069
}
insilmaril@175
  4070
insilmaril@491
  4071
void MapEditor::setHideLinkUnselected (bool b)
insilmaril@160
  4072
{
insilmaril@424
  4073
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  4074
	if (sel &&
insilmaril@491
  4075
		(xelection.type() == Selection::Branch || 
insilmaril@491
  4076
		xelection.type() == Selection::MapCenter  ||
insilmaril@491
  4077
		xelection.type() == Selection::FloatImage ))
insilmaril@491
  4078
	{
insilmaril@491
  4079
		QString u= b ? "false" : "true";
insilmaril@491
  4080
		QString r=!b ? "false" : "true";
insilmaril@491
  4081
		
insilmaril@491
  4082
		saveState(
insilmaril@491
  4083
			sel,
insilmaril@491
  4084
			QString("setHideLinkUnselected (%1)").arg(u),
insilmaril@491
  4085
			sel, 
insilmaril@491
  4086
			QString("setHideLinkUnselected (%1)").arg(r),
insilmaril@491
  4087
			QString("Hide link of %1 if unselected").arg(getName(sel))
insilmaril@491
  4088
		);	
insilmaril@424
  4089
		sel->setHideLinkUnselected(b);
insilmaril@491
  4090
	}
insilmaril@160
  4091
}
insilmaril@160
  4092
insilmaril@491
  4093
void MapEditor::importDirInt(BranchObj *dst, QDir d)
insilmaril@0
  4094
{
insilmaril@424
  4095
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4096
	if (bo)
insilmaril@0
  4097
	{
insilmaril@0
  4098
		// Traverse directories
insilmaril@0
  4099
		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  4100
		QFileInfoList list = d.entryInfoList();
insilmaril@366
  4101
		QFileInfo fi;
insilmaril@366
  4102
insilmaril@366
  4103
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4104
		{
insilmaril@366
  4105
			fi=list.at(i);
insilmaril@366
  4106
			if (fi.fileName() != "." && fi.fileName() != ".." )
insilmaril@0
  4107
			{
insilmaril@0
  4108
				dst->addBranch();
insilmaril@0
  4109
				bo=dst->getLastBranch();
insilmaril@366
  4110
				bo->setHeading (fi.fileName() );
insilmaril@243
  4111
				bo->setColor (QColor("blue"));
insilmaril@0
  4112
				bo->toggleScroll();
insilmaril@366
  4113
				if ( !d.cd(fi.fileName()) ) 
insilmaril@366
  4114
					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
insilmaril@0
  4115
				else 
insilmaril@0
  4116
				{
insilmaril@103
  4117
					// Recursively add subdirs
insilmaril@366
  4118
					importDirInt (bo,d);
insilmaril@0
  4119
					d.cdUp();
insilmaril@0
  4120
				}
insilmaril@0
  4121
			}	
insilmaril@0
  4122
		}		
insilmaril@0
  4123
		// Traverse files
insilmaril@0
  4124
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  4125
		list = d.entryInfoList();
insilmaril@366
  4126
insilmaril@366
  4127
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4128
		{
insilmaril@366
  4129
			fi=list.at(i);
insilmaril@0
  4130
			dst->addBranch();
insilmaril@0
  4131
			bo=dst->getLastBranch();
insilmaril@366
  4132
			bo->setHeading (fi.fileName() );
insilmaril@243
  4133
			bo->setColor (QColor("black"));
insilmaril@366
  4134
			if (fi.fileName().right(4) == ".vym" )
insilmaril@366
  4135
				bo->setVymLink (fi.filePath());
insilmaril@0
  4136
		}	
insilmaril@0
  4137
	}		
insilmaril@0
  4138
}
insilmaril@0
  4139
insilmaril@491
  4140
void MapEditor::importDirInt (const QString &s)
insilmaril@491
  4141
{
insilmaril@491
  4142
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  4143
	if (bo)
insilmaril@491
  4144
	{
insilmaril@491
  4145
		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
insilmaril@491
  4146
insilmaril@491
  4147
		QDir d(s);
insilmaril@491
  4148
		importDirInt (bo,d);
insilmaril@491
  4149
	}
insilmaril@491
  4150
}	
insilmaril@491
  4151
insilmaril@0
  4152
void MapEditor::importDir()
insilmaril@0
  4153
{
insilmaril@424
  4154
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4155
	if (bo)
insilmaril@0
  4156
	{
insilmaril@404
  4157
		QStringList filters;
insilmaril@404
  4158
		filters <<"VYM map (*.vym)";
insilmaril@404
  4159
		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
insilmaril@404
  4160
		fd->setMode (QFileDialog::DirectoryOnly);
insilmaril@404
  4161
		fd->setFilters (filters);
insilmaril@404
  4162
		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
insilmaril@0
  4163
		fd->show();
insilmaril@0
  4164
insilmaril@0
  4165
		QString fn;
insilmaril@0
  4166
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  4167
		{
insilmaril@491
  4168
			importDirInt (fd->selectedFile() );
insilmaril@645
  4169
			model->reposition();
insilmaril@408
  4170
			scene()->update();
insilmaril@0
  4171
		}
insilmaril@0
  4172
	}	
insilmaril@0
  4173
}
insilmaril@0
  4174
insilmaril@95
  4175
void MapEditor::followXLink(int i)
insilmaril@89
  4176
{
insilmaril@424
  4177
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4178
	if (bo)
insilmaril@89
  4179
	{
insilmaril@424
  4180
		bo=bo->XLinkTargetAt(i);
insilmaril@97
  4181
		if (bo) 
insilmaril@97
  4182
		{
insilmaril@424
  4183
			xelection.select(bo);
insilmaril@97
  4184
			ensureSelectionVisible();
insilmaril@97
  4185
		}
insilmaril@89
  4186
	}
insilmaril@89
  4187
}
insilmaril@89
  4188
insilmaril@421
  4189
void MapEditor::editXLink(int i)	// FIXME missing saveState
insilmaril@94
  4190
{
insilmaril@424
  4191
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4192
	if (bo)
insilmaril@94
  4193
	{
insilmaril@424
  4194
		XLinkObj *xlo=bo->XLinkAt(i);
insilmaril@97
  4195
		if (xlo) 
insilmaril@94
  4196
		{
insilmaril@97
  4197
			EditXLinkDialog dia;
insilmaril@97
  4198
			dia.setXLink (xlo);
insilmaril@424
  4199
			dia.setSelection(bo);
insilmaril@97
  4200
			if (dia.exec() == QDialog::Accepted)
insilmaril@97
  4201
			{
insilmaril@97
  4202
				if (dia.useSettingsGlobal() )
insilmaril@97
  4203
				{
insilmaril@398
  4204
					setMapDefXLinkColor (xlo->getColor() );
insilmaril@398
  4205
					setMapDefXLinkWidth (xlo->getWidth() );
insilmaril@97
  4206
				}
insilmaril@97
  4207
				if (dia.deleteXLink())
insilmaril@424
  4208
					bo->deleteXLinkAt(i);
insilmaril@97
  4209
			}
insilmaril@97
  4210
		}	
insilmaril@97
  4211
	}
insilmaril@94
  4212
}
insilmaril@94
  4213
insilmaril@628
  4214
AttributeTable* MapEditor::attributeTable()
insilmaril@628
  4215
{
insilmaril@628
  4216
	return attrTable;
insilmaril@628
  4217
}
insilmaril@628
  4218
insilmaril@527
  4219
void MapEditor::testFunction1()
insilmaril@0
  4220
{
insilmaril@527
  4221
/*
insilmaril@473
  4222
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4223
	if (bo) animObjList.append( bo );
insilmaril@527
  4224
*/	
insilmaril@432
  4225
	
insilmaril@420
  4226
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
insilmaril@260
  4227
	if (hidemode==HideNone)
insilmaril@185
  4228
	{
insilmaril@260
  4229
		setHideTmpMode (HideExport);
insilmaril@260
  4230
		mapCenter->calcBBoxSizeWithChilds();
insilmaril@408
  4231
		QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@408
  4232
		QRectF mapRect=totalBBox;
insilmaril@260
  4233
		QCanvasRectangle *frame=NULL;
insilmaril@260
  4234
insilmaril@260
  4235
		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
insilmaril@260
  4236
	
insilmaril@260
  4237
		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
insilmaril@260
  4238
			totalBBox.width(), totalBBox.height());
insilmaril@408
  4239
		frame=new QCanvasRectangle (mapRect,mapScene);
insilmaril@260
  4240
		frame->setBrush (QColor(white));
insilmaril@260
  4241
		frame->setPen (QColor(black));
insilmaril@408
  4242
		frame->setZValue(0);
insilmaril@260
  4243
		frame->show();    
insilmaril@260
  4244
	}	
insilmaril@260
  4245
	else	
insilmaril@260
  4246
	{
insilmaril@260
  4247
		setHideTmpMode (HideNone);
insilmaril@260
  4248
	}	
insilmaril@260
  4249
	cout <<"  hidemode="<<hidemode<<endl;
insilmaril@301
  4250
	*/
insilmaril@527
  4251
}	
insilmaril@527
  4252
	
insilmaril@527
  4253
void MapEditor::testFunction2()
insilmaril@527
  4254
{
insilmaril@645
  4255
insilmaril@652
  4256
	xelection.select (model->addMapCenter());
insilmaril@652
  4257
	ensureSelectionVisible();
insilmaril@638
  4258
insilmaril@638
  4259
/*
insilmaril@628
  4260
	// Toggle hidemode
insilmaril@628
  4261
	if (hidemode==HideExport)
insilmaril@628
  4262
		setHideTmpMode (HideNone);
insilmaril@628
  4263
	else	
insilmaril@628
  4264
		setHideTmpMode (HideExport);
insilmaril@638
  4265
*/		
insilmaril@105
  4266
}
insilmaril@105
  4267
insilmaril@408
  4268
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
insilmaril@0
  4269
{
insilmaril@0
  4270
	// Lineedits are already closed by preceding
insilmaril@0
  4271
	// mouseEvent, we don't need to close here.
insilmaril@0
  4272
insilmaril@408
  4273
    QPointF p = mapToScene(e->pos());
insilmaril@645
  4274
    LinkableMapObj* lmo=model->findMapObj(p, NULL);
insilmaril@0
  4275
	
insilmaril@0
  4276
    if (lmo) 
insilmaril@0
  4277
	{	// MapObj was found
insilmaril@424
  4278
		if (xelection.single() != lmo)
insilmaril@0
  4279
		{
insilmaril@0
  4280
			// select the MapObj
insilmaril@424
  4281
			xelection.select(lmo);
insilmaril@0
  4282
		}
insilmaril@0
  4283
		// Context Menu 
insilmaril@424
  4284
		if (xelection.getBranch() ) 
insilmaril@0
  4285
		{
insilmaril@424
  4286
			// Context Menu on branch or mapcenter
insilmaril@424
  4287
			updateActions();
insilmaril@424
  4288
			branchContextMenu->popup(e->globalPos() );
insilmaril@424
  4289
		} else
insilmaril@424
  4290
		{
insilmaril@424
  4291
			if (xelection.getFloatImage() )
insilmaril@0
  4292
			{
insilmaril@0
  4293
				// Context Menu on floatimage
insilmaril@0
  4294
				updateActions();
insilmaril@0
  4295
				floatimageContextMenu->popup(e->globalPos() );
insilmaril@0
  4296
			}	
insilmaril@0
  4297
		}	
insilmaril@0
  4298
	} else 
insilmaril@0
  4299
	{ // No MapObj found, we are on the Canvas itself
insilmaril@408
  4300
		// Context Menu on scene
insilmaril@0
  4301
		updateActions();
insilmaril@0
  4302
		canvasContextMenu->popup(e->globalPos() );
insilmaril@0
  4303
    } 
insilmaril@329
  4304
	e->accept();
insilmaril@0
  4305
}
insilmaril@0
  4306
insilmaril@398
  4307
void MapEditor::keyPressEvent(QKeyEvent* e)
insilmaril@398
  4308
{
insilmaril@411
  4309
	if (e->modifiers() & Qt::ControlModifier)
insilmaril@398
  4310
	{
insilmaril@398
  4311
		switch (mainWindow->getModMode())
insilmaril@398
  4312
		{
insilmaril@473
  4313
			case Main::ModModeColor: 
insilmaril@398
  4314
				setCursor (PickColorCursor);
insilmaril@398
  4315
				break;
insilmaril@473
  4316
			case Main::ModModeCopy: 
insilmaril@398
  4317
				setCursor (CopyCursor);
insilmaril@398
  4318
				break;
insilmaril@473
  4319
			case Main::ModModeXLink: 
insilmaril@398
  4320
				setCursor (XLinkCursor);
insilmaril@398
  4321
				break;
insilmaril@398
  4322
			default :
insilmaril@398
  4323
				setCursor (Qt::ArrowCursor);
insilmaril@398
  4324
				break;
insilmaril@398
  4325
		} 
insilmaril@398
  4326
	}	
insilmaril@398
  4327
}
insilmaril@398
  4328
insilmaril@398
  4329
void MapEditor::keyReleaseEvent(QKeyEvent* e)
insilmaril@398
  4330
{
insilmaril@411
  4331
	if (!(e->modifiers() & Qt::ControlModifier))
insilmaril@398
  4332
		setCursor (Qt::ArrowCursor);
insilmaril@398
  4333
}
insilmaril@398
  4334
insilmaril@408
  4335
void MapEditor::mousePressEvent(QMouseEvent* e)
insilmaril@0
  4336
{
insilmaril@329
  4337
	// Ignore right clicks, these will go to context menus
insilmaril@366
  4338
	if (e->button() == Qt::RightButton )
insilmaril@329
  4339
	{
insilmaril@329
  4340
		e->ignore();
insilmaril@329
  4341
		return;
insilmaril@329
  4342
	}
insilmaril@329
  4343
insilmaril@491
  4344
	//Ignore clicks while editing heading
insilmaril@491
  4345
	if (isSelectBlocked() ) 
insilmaril@491
  4346
	{
insilmaril@491
  4347
		e->ignore();
insilmaril@491
  4348
		return;
insilmaril@491
  4349
	}
insilmaril@491
  4350
insilmaril@408
  4351
    QPointF p = mapToScene(e->pos());
insilmaril@645
  4352
    LinkableMapObj* lmo=model->findMapObj(p, NULL);
insilmaril@0
  4353
	
insilmaril@329
  4354
	e->accept();
insilmaril@329
  4355
insilmaril@442
  4356
	//Take care of  system flags _or_ modifier modes
insilmaril@267
  4357
	//
insilmaril@267
  4358
	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@267
  4359
		typeid(*lmo)==typeid(MapCenterObj) ))
insilmaril@267
  4360
	{
insilmaril@267
  4361
		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
insilmaril@267
  4362
		if (!foname.isEmpty())
insilmaril@267
  4363
		{
insilmaril@267
  4364
			// systemFlag clicked
insilmaril@366
  4365
			selectInt (lmo);
insilmaril@267
  4366
			if (foname=="url") 
insilmaril@267
  4367
			{
insilmaril@366
  4368
				if (e->state() & Qt::ControlModifier)
insilmaril@267
  4369
					mainWindow->editOpenURLTab();
insilmaril@267
  4370
				else	
insilmaril@267
  4371
					mainWindow->editOpenURL();
insilmaril@267
  4372
			}	
insilmaril@267
  4373
			else if (foname=="vymLink")
insilmaril@267
  4374
			{
insilmaril@267
  4375
				mainWindow->editOpenVymLink();
insilmaril@267
  4376
				// tabWidget may change, better return now
insilmaril@267
  4377
				// before segfaulting...
insilmaril@267
  4378
			} else if (foname=="note")
insilmaril@267
  4379
				mainWindow->windowToggleNoteEditor();
insilmaril@267
  4380
			else if (foname=="hideInExport")		
insilmaril@267
  4381
				toggleHideExport();
insilmaril@442
  4382
			xelection.update();	
insilmaril@267
  4383
			return;	
insilmaril@267
  4384
		} 
insilmaril@267
  4385
	} 
insilmaril@442
  4386
insilmaril@442
  4387
	// No system flag clicked, take care of modmodes (CTRL-Click)
insilmaril@366
  4388
	if (e->state() & Qt::ControlModifier)
insilmaril@0
  4389
	{
insilmaril@473
  4390
		if (mainWindow->getModMode()==Main::ModModeColor)
insilmaril@83
  4391
		{
insilmaril@83
  4392
				pickingColor=true;
insilmaril@398
  4393
				setCursor (PickColorCursor);
insilmaril@83
  4394
				return;
insilmaril@83
  4395
		} 
insilmaril@473
  4396
		if (mainWindow->getModMode()==Main::ModModeXLink)
insilmaril@83
  4397
		{	
insilmaril@90
  4398
			BranchObj *bo_begin=NULL;
insilmaril@90
  4399
			if (lmo)
insilmaril@90
  4400
				bo_begin=(BranchObj*)(lmo);
insilmaril@90
  4401
			else	
insilmaril@424
  4402
				if (xelection.getBranch() ) 
insilmaril@424
  4403
					bo_begin=xelection.getBranch();
insilmaril@90
  4404
			if (bo_begin)	
insilmaril@83
  4405
			{
insilmaril@83
  4406
				drawingLink=true;
insilmaril@90
  4407
				linkingObj_src=bo_begin;
insilmaril@408
  4408
				tmpXLink=new XLinkObj (mapScene);
insilmaril@95
  4409
				tmpXLink->setBegin (bo_begin);
insilmaril@95
  4410
				tmpXLink->setEnd   (p);
insilmaril@97
  4411
				tmpXLink->setColor(defXLinkColor);
insilmaril@97
  4412
				tmpXLink->setWidth(defXLinkWidth);
insilmaril@95
  4413
				tmpXLink->updateXLink();
insilmaril@95
  4414
				tmpXLink->setVisibility (true);
insilmaril@83
  4415
				return;
insilmaril@89
  4416
			} 
insilmaril@267
  4417
		}
insilmaril@442
  4418
	}	// End of modmodes
insilmaril@442
  4419
insilmaril@0
  4420
    if (lmo) 
insilmaril@267
  4421
	{	
insilmaril@442
  4422
		// Select the clicked object
insilmaril@366
  4423
		selectInt (lmo);
insilmaril@442
  4424
insilmaril@0
  4425
		// Left Button	    Move Branches
insilmaril@366
  4426
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4427
		{
insilmaril@424
  4428
			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
insilmaril@424
  4429
			//movingObj_start.setY( p.y() - selection->y() );	
insilmaril@424
  4430
			movingObj_start.setX( p.x() - lmo->x() );	
insilmaril@424
  4431
			movingObj_start.setY( p.y() - lmo->y() );	
insilmaril@129
  4432
			movingObj_orgPos.setX (lmo->x() );
insilmaril@129
  4433
			movingObj_orgPos.setY (lmo->y() );
insilmaril@366
  4434
			movingObj_orgRelPos=lmo->getRelPos();
insilmaril@129
  4435
insilmaril@93
  4436
			// If modMode==copy, then we want to "move" the _new_ object around
insilmaril@93
  4437
			// then we need the offset from p to the _old_ selection, because of tmp
insilmaril@473
  4438
			if (mainWindow->getModMode()==Main::ModModeCopy &&
insilmaril@366
  4439
				e->state() & Qt::ControlModifier)
insilmaril@93
  4440
			{
insilmaril@645
  4441
				BranchObj *bo=xelection.getBranch();
insilmaril@645
  4442
				if (bo)
insilmaril@93
  4443
				{
insilmaril@93
  4444
					copyingObj=true;
insilmaril@645
  4445
					bo->addBranch ((BranchObj*)xelection.single());
insilmaril@93
  4446
					unselect();
insilmaril@645
  4447
					xelection.select(bo->getLastBranch());
insilmaril@645
  4448
					model->reposition();
insilmaril@93
  4449
				}
insilmaril@421
  4450
			} 
insilmaril@421
  4451
insilmaril@424
  4452
			movingObj=xelection.single();	
insilmaril@0
  4453
		} else
insilmaril@0
  4454
			// Middle Button    Toggle Scroll
insilmaril@0
  4455
			// (On Mac OS X this won't work, but we still have 
insilmaril@0
  4456
			// a button in the toolbar)
insilmaril@366
  4457
			if (e->button() == Qt::MidButton )
insilmaril@0
  4458
				toggleScroll();
insilmaril@0
  4459
		updateActions();
insilmaril@442
  4460
		xelection.update();
insilmaril@0
  4461
	} else 
insilmaril@408
  4462
	{ // No MapObj found, we are on the scene itself
insilmaril@408
  4463
		// Left Button	    move Pos of sceneView
insilmaril@366
  4464
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4465
		{
insilmaril@0
  4466
			movingObj=NULL;	// move Content not Obj
insilmaril@0
  4467
			movingObj_start=e->globalPos();
insilmaril@408
  4468
			movingCont_start=QPointF (
insilmaril@408
  4469
				horizontalScrollBar()->value(),
insilmaril@408
  4470
				verticalScrollBar()->value());
insilmaril@408
  4471
			movingVec=QPointF(0,0);
insilmaril@398
  4472
			setCursor(HandOpenCursor);
insilmaril@0
  4473
		} 
insilmaril@0
  4474
    } 
insilmaril@0
  4475
}
insilmaril@0
  4476
insilmaril@408
  4477
void MapEditor::mouseMoveEvent(QMouseEvent* e)
insilmaril@0
  4478
{
insilmaril@408
  4479
    QPointF p = mapToScene(e->pos());
insilmaril@424
  4480
	LinkableMapObj *lmosel=xelection.single();
insilmaril@83
  4481
insilmaril@0
  4482
    // Move the selected MapObj
insilmaril@424
  4483
    if ( lmosel && movingObj) 
insilmaril@0
  4484
    {	
insilmaril@421
  4485
		// reset cursor if we are moving and don't copy
insilmaril@473
  4486
		if (mainWindow->getModMode()!=Main::ModModeCopy)
insilmaril@421
  4487
			setCursor (Qt::ArrowCursor);
insilmaril@421
  4488
insilmaril@408
  4489
		// To avoid jumping of the sceneView, only 
insilmaril@164
  4490
		// ensureSelectionVisible, if not tmp linked
insilmaril@424
  4491
		if (!lmosel->hasParObjTmp())
insilmaril@164
  4492
			ensureSelectionVisible ();
insilmaril@0
  4493
		
insilmaril@83
  4494
		// Now move the selection, but add relative position 
insilmaril@83
  4495
		// (movingObj_start) where selection was chosen with 
insilmaril@83
  4496
		// mousepointer. (This avoids flickering resp. jumping 
insilmaril@0
  4497
		// of selection back to absPos)
insilmaril@0
  4498
		
insilmaril@0
  4499
		// Check if we could link 
insilmaril@645
  4500
		LinkableMapObj* lmo=model->findMapObj(p, lmosel);
insilmaril@0
  4501
		
insilmaril@0
  4502
insilmaril@424
  4503
		FloatObj *fio=xelection.getFloatImage();
insilmaril@424
  4504
		if (fio)
insilmaril@0
  4505
		{
insilmaril@424
  4506
			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@424
  4507
			fio->setRelPos();
insilmaril@424
  4508
			fio->updateLink(); //no need for reposition, if we update link here
insilmaril@442
  4509
			xelection.update();
insilmaril@0
  4510
insilmaril@0
  4511
			// Relink float to new mapcenter or branch, if shift is pressed	
insilmaril@0
  4512
			// Only relink, if selection really has a new parent
insilmaril@388
  4513
			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
insilmaril@0
  4514
				( (typeid(*lmo)==typeid(BranchObj)) ||
insilmaril@0
  4515
				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
insilmaril@424
  4516
				( lmo != fio->getParObj())  
insilmaril@0
  4517
				)
insilmaril@0
  4518
			{
insilmaril@424
  4519
				if (typeid(*fio) == typeid(FloatImageObj) && 
insilmaril@420
  4520
				( (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@420
  4521
				  typeid(*lmo)==typeid(MapCenterObj)) ))  
insilmaril@0
  4522
				{
insilmaril@420
  4523
insilmaril@420
  4524
					// Also save the move which was done so far
insilmaril@420
  4525
					QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@420
  4526
					QString pnow=qpointfToString(fio->getRelPos());
insilmaril@420
  4527
					saveState(
insilmaril@424
  4528
						fio,
insilmaril@420
  4529
						"moveRel "+pold,
insilmaril@424
  4530
						fio,
insilmaril@420
  4531
						"moveRel "+pnow,
insilmaril@625
  4532
						QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
insilmaril@420
  4533
					fio->getParObj()->requestReposition();
insilmaril@645
  4534
					model->reposition();
insilmaril@420
  4535
insilmaril@420
  4536
					linkTo (lmo->getSelectString());
insilmaril@442
  4537
					//movingObj=lmosel;
insilmaril@442
  4538
					//movingObj_orgRelPos=lmosel->getRelPos();	
insilmaril@420
  4539
insilmaril@645
  4540
					model->reposition();
insilmaril@0
  4541
				}	
insilmaril@0
  4542
			}
insilmaril@388
  4543
		} else	
insilmaril@388
  4544
		{	// selection != a FloatObj
insilmaril@0
  4545
			if (lmosel->getDepth()==0)
insilmaril@0
  4546
			{
insilmaril@388
  4547
				// Move MapCenter
insilmaril@388
  4548
				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
insilmaril@645
  4549
					((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@0
  4550
				else	
insilmaril@645
  4551
					lmosel->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@645
  4552
				model->updateRelPositions();
insilmaril@0
  4553
			} else
insilmaril@0
  4554
			{	
insilmaril@0
  4555
				if (lmosel->getDepth()==1)
insilmaril@0
  4556
				{
insilmaril@388
  4557
					// Move mainbranch
insilmaril@0
  4558
					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@388
  4559
					lmosel->setRelPos();
insilmaril@0
  4560
				} else
insilmaril@0
  4561
				{
insilmaril@388
  4562
					// Move ordinary branch
insilmaril@473
  4563
					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
insilmaril@0
  4564
						// Add width of bbox here, otherwise alignRelTo will cause jumping around
insilmaril@0
  4565
						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
insilmaril@175
  4566
							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
insilmaril@0
  4567
					else	
insilmaril@175
  4568
						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
insilmaril@0
  4569
				} 
insilmaril@0
  4570
insilmaril@431
  4571
				// Maybe we can relink temporary?
insilmaril@431
  4572
				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
insilmaril@431
  4573
					 (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@431
  4574
					  typeid(*lmo)==typeid(MapCenterObj)) ) 
insilmaril@431
  4575
insilmaril@0
  4576
				{
insilmaril@388
  4577
					if (e->modifiers()==Qt::ControlModifier)
insilmaril@0
  4578
					{
insilmaril@0
  4579
						// Special case: CTRL to link below lmo
insilmaril@0
  4580
						lmosel->setParObjTmp (lmo,p,+1);
insilmaril@0
  4581
					}
insilmaril@388
  4582
					else if (e->modifiers()==Qt::ShiftModifier)
insilmaril@0
  4583
						lmosel->setParObjTmp (lmo,p,-1);
insilmaril@0
  4584
					else
insilmaril@0
  4585
						lmosel->setParObjTmp (lmo,p,0);
insilmaril@0
  4586
				} else	
insilmaril@0
  4587
				{
insilmaril@93
  4588
					lmosel->unsetParObjTmp();
insilmaril@0
  4589
				}		
insilmaril@428
  4590
				// reposition subbranch
insilmaril@428
  4591
				lmosel->reposition();	
insilmaril@0
  4592
			} // depth>0
insilmaril@0
  4593
insilmaril@442
  4594
			xelection.update();
insilmaril@0
  4595
		} // no FloatImageObj
insilmaril@0
  4596
insilmaril@408
  4597
		scene()->update();
insilmaril@0
  4598
		return;
insilmaril@0
  4599
	} // selection && moving_obj
insilmaril@0
  4600
		
insilmaril@83
  4601
	// Draw a link from one branch to another
insilmaril@83
  4602
	if (drawingLink)
insilmaril@83
  4603
	{
insilmaril@95
  4604
		 tmpXLink->setEnd (p);
insilmaril@95
  4605
		 tmpXLink->updateXLink();
insilmaril@83
  4606
	}	 
insilmaril@83
  4607
	
insilmaril@408
  4608
    // Move sceneView 
insilmaril@411
  4609
    if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
insilmaril@0
  4610
	{
insilmaril@408
  4611
		QPointF p=e->globalPos();
insilmaril@0
  4612
		movingVec.setX(-p.x() + movingObj_start.x() );
insilmaril@0
  4613
		movingVec.setY(-p.y() + movingObj_start.y() );
insilmaril@408
  4614
		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
insilmaril@408
  4615
		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
insilmaril@0
  4616
    }
insilmaril@0
  4617
}
insilmaril@0
  4618
insilmaril@0
  4619
insilmaril@408
  4620
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
insilmaril@0
  4621
{
insilmaril@408
  4622
    QPointF p = mapToScene(e->pos());
insilmaril@0
  4623
	LinkableMapObj *dst;
insilmaril@424
  4624
	LinkableMapObj *lmosel=xelection.single();
insilmaril@0
  4625
	// Have we been picking color?
insilmaril@0
  4626
	if (pickingColor)
insilmaril@0
  4627
	{
insilmaril@0
  4628
		pickingColor=false;
insilmaril@366
  4629
		setCursor (Qt::ArrowCursor);
insilmaril@0
  4630
		// Check if we are over another branch
insilmaril@645
  4631
		dst=model->findMapObj(p, NULL);
insilmaril@424
  4632
		if (dst && lmosel) 
insilmaril@0
  4633
		{	
insilmaril@366
  4634
			if (e->state() & Qt::ShiftModifier)
insilmaril@638
  4635
				colorBranch (((BranchObj*)dst)->getColor());
insilmaril@0
  4636
			else	
insilmaril@638
  4637
				colorSubtree (((BranchObj*)dst)->getColor());
insilmaril@0
  4638
		} 
insilmaril@0
  4639
		return;
insilmaril@0
  4640
	}
insilmaril@83
  4641
insilmaril@83
  4642
	// Have we been drawing a link?
insilmaril@491
  4643
	if (drawingLink)	
insilmaril@83
  4644
	{
insilmaril@83
  4645
		drawingLink=false;
insilmaril@83
  4646
		// Check if we are over another branch
insilmaril@645
  4647
		dst=model->findMapObj(p, NULL);
insilmaril@424
  4648
		if (dst && lmosel) 
insilmaril@83
  4649
		{	
insilmaril@95
  4650
			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
insilmaril@95
  4651
			tmpXLink->updateXLink();
insilmaril@491
  4652
			tmpXLink->activate(); //FIXME savestate missing
insilmaril@473
  4653
			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
insilmaril@83
  4654
		} else
insilmaril@83
  4655
		{
insilmaril@95
  4656
			delete(tmpXLink);
insilmaril@95
  4657
			tmpXLink=NULL;
insilmaril@83
  4658
		}
insilmaril@83
  4659
		return;
insilmaril@83
  4660
	}
insilmaril@83
  4661
	
insilmaril@0
  4662
    // Have we been moving something?
insilmaril@424
  4663
    if ( lmosel && movingObj ) 
insilmaril@0
  4664
    {	
insilmaril@424
  4665
		FloatImageObj *fo=xelection.getFloatImage();
insilmaril@424
  4666
		if(fo)
insilmaril@175
  4667
		{
insilmaril@388
  4668
			// Moved FloatObj. Maybe we need to reposition
insilmaril@408
  4669
		    QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@408
  4670
		    QString pnow=qpointfToString(fo->getRelPos());
insilmaril@395
  4671
			saveState(
insilmaril@424
  4672
				fo,
insilmaril@366
  4673
				"moveRel "+pold,
insilmaril@424
  4674
				fo,
insilmaril@366
  4675
				"moveRel "+pnow,
insilmaril@625
  4676
				QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
insilmaril@424
  4677
insilmaril@424
  4678
			fo->getParObj()->requestReposition();
insilmaril@645
  4679
			model->reposition();
insilmaril@175
  4680
		}	
insilmaril@175
  4681
insilmaril@0
  4682
		// Check if we are over another branch, but ignore 
insilmaril@0
  4683
		// any found LMOs, which are FloatObjs
insilmaril@645
  4684
		dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
insilmaril@0
  4685
insilmaril@336
  4686
		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
insilmaril@0
  4687
			dst=NULL;
insilmaril@0
  4688
		
insilmaril@645
  4689
		BranchObj *bo=xelection.getBranch();
insilmaril@645
  4690
		if (bo && bo->getDepth()==0)
insilmaril@497
  4691
		{	
insilmaril@645
  4692
            if (movingObj_orgPos != bo->getAbsPos())
insilmaril@625
  4693
            {
insilmaril@625
  4694
                QString pold=qpointfToString(movingObj_orgPos);
insilmaril@645
  4695
                QString pnow=qpointfToString(bo->getAbsPos());
insilmaril@625
  4696
                saveState(
insilmaril@625
  4697
                    fo,
insilmaril@625
  4698
                    "move "+pold,
insilmaril@625
  4699
                    fo,
insilmaril@625
  4700
                    "move "+pnow,
insilmaril@645
  4701
                    QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
insilmaril@625
  4702
            }
insilmaril@388
  4703
		}
insilmaril@645
  4704
	
insilmaril@491
  4705
		if (xelection.type() == Selection::Branch )
insilmaril@388
  4706
		{	// A branch was moved
insilmaril@388
  4707
			
insilmaril@0
  4708
			// save the position in case we link to mapcenter
insilmaril@424
  4709
			QPointF savePos=QPointF (lmosel->getAbsPos()  );
insilmaril@0
  4710
insilmaril@0
  4711
			// Reset the temporary drawn link to the original one
insilmaril@424
  4712
			lmosel->unsetParObjTmp();
insilmaril@0
  4713
insilmaril@366
  4714
			// For Redo we may need to save original selection
insilmaril@424
  4715
			QString preSelStr=lmosel->getSelectString();
insilmaril@93
  4716
insilmaril@94
  4717
			copyingObj=false;	
insilmaril@129
  4718
			if (dst ) 
insilmaril@93
  4719
			{
insilmaril@424
  4720
				BranchObj* bsel=xelection.getBranch();
insilmaril@366
  4721
				BranchObj* bdst=(BranchObj*)dst;
insilmaril@366
  4722
insilmaril@366
  4723
				QString preParStr=(bsel->getParObj())->getSelectString();
insilmaril@366
  4724
				QString preNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4725
				QString preDstParStr;
insilmaril@366
  4726
insilmaril@366
  4727
				if (e->state() & Qt::ShiftModifier && dst->getParObj())
insilmaril@366
  4728
				{	// Link above dst
insilmaril@366
  4729
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4730
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
insilmaril@366
  4731
				} else 
insilmaril@366
  4732
				if (e->state() & Qt::ControlModifier && dst->getParObj())
insilmaril@366
  4733
				{
insilmaril@366
  4734
					// Link below dst
insilmaril@366
  4735
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4736
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
insilmaril@366
  4737
				} else	
insilmaril@366
  4738
				{	// Append to dst
insilmaril@366
  4739
					preDstParStr=dst->getSelectString();
insilmaril@421
  4740
					bsel->linkTo (bdst,-1);
insilmaril@366
  4741
					if (dst->getDepth()==0) bsel->move (savePos);
insilmaril@366
  4742
				} 
insilmaril@424
  4743
				QString postSelStr=lmosel->getSelectString();
insilmaril@366
  4744
				QString postNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4745
insilmaril@421
  4746
				QString undoCom="linkTo (\""+ 
insilmaril@366
  4747
					preParStr+ "\"," + preNum  +"," + 
insilmaril@366
  4748
					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
insilmaril@366
  4749
insilmaril@421
  4750
				QString redoCom="linkTo (\""+ 
insilmaril@366
  4751
					preDstParStr + "\"," + postNum + "," +
insilmaril@366
  4752
					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
insilmaril@366
  4753
insilmaril@366
  4754
				saveState (
insilmaril@366
  4755
					postSelStr,undoCom,
insilmaril@366
  4756
					preSelStr, redoCom,
insilmaril@366
  4757
					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
insilmaril@163
  4758
			} else
insilmaril@424
  4759
				if (lmosel->getDepth()==1)
insilmaril@366
  4760
				{
insilmaril@366
  4761
					// The select string might be different _after_ moving around.
insilmaril@366
  4762
					// Therefor reposition and then use string of old selection, too
insilmaril@645
  4763
					model->reposition();
insilmaril@366
  4764
insilmaril@625
  4765
                    QPointF rp(lmosel->getRelPos());
insilmaril@625
  4766
                    if (rp != movingObj_orgRelPos)
insilmaril@625
  4767
                    {
insilmaril@625
  4768
                        QString ps=qpointfToString(rp);
insilmaril@625
  4769
                        saveState(
insilmaril@625
  4770
                            lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
insilmaril@625
  4771
                            preSelStr, "moveRel "+ps, 
insilmaril@625
  4772
                            QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
insilmaril@625
  4773
                    }
insilmaril@366
  4774
				}
insilmaril@0
  4775
			// Draw the original link, before selection was moved around
insilmaril@645
  4776
			model->reposition();
insilmaril@0
  4777
		}
insilmaril@442
  4778
		xelection.update();
insilmaril@408
  4779
		// Finally resize scene, if needed
insilmaril@408
  4780
		scene()->update();
insilmaril@0
  4781
		movingObj=NULL;		
insilmaril@366
  4782
insilmaril@366
  4783
		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
insilmaril@366
  4784
		updateActions();
insilmaril@0
  4785
	} else 
insilmaril@83
  4786
		// maybe we moved View: set old cursor
insilmaril@366
  4787
		setCursor (Qt::ArrowCursor);
insilmaril@83
  4788
    
insilmaril@0
  4789
}
insilmaril@0
  4790
insilmaril@408
  4791
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
insilmaril@0
  4792
{
insilmaril@491
  4793
	if (isSelectBlocked() ) 
insilmaril@491
  4794
	{
insilmaril@491
  4795
		e->ignore();
insilmaril@491
  4796
		return;
insilmaril@491
  4797
	}
insilmaril@491
  4798
insilmaril@366
  4799
	if (e->button() == Qt::LeftButton )
insilmaril@0
  4800
	{
insilmaril@408
  4801
		QPointF p = mapToScene(e->pos());
insilmaril@645
  4802
		LinkableMapObj *lmo=model->findMapObj(p, NULL);
insilmaril@0
  4803
		if (lmo) {	// MapObj was found
insilmaril@0
  4804
			// First select the MapObj than edit heading
insilmaril@424
  4805
			xelection.select(lmo);
insilmaril@366
  4806
			mainWindow->editHeading();
insilmaril@0
  4807
		}
insilmaril@0
  4808
	}
insilmaril@0
  4809
}
insilmaril@0
  4810
insilmaril@0
  4811
void MapEditor::resizeEvent (QResizeEvent* e)
insilmaril@0
  4812
{
insilmaril@408
  4813
	QGraphicsView::resizeEvent( e );
insilmaril@0
  4814
}
insilmaril@0
  4815
insilmaril@412
  4816
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
insilmaril@119
  4817
{
insilmaril@417
  4818
	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
insilmaril@417
  4819
	//	cerr << event->format(i) << endl;
insilmaril@417
  4820
insilmaril@417
  4821
	if (event->mimeData()->hasImage())
insilmaril@417
  4822
		event->acceptProposedAction();
insilmaril@417
  4823
	else	
insilmaril@417
  4824
		if (event->mimeData()->hasUrls())
insilmaril@417
  4825
			event->acceptProposedAction();
insilmaril@417
  4826
}
insilmaril@417
  4827
insilmaril@531
  4828
void MapEditor::dragMoveEvent(QDragMoveEvent *)
insilmaril@417
  4829
{
insilmaril@417
  4830
}
insilmaril@417
  4831
insilmaril@417
  4832
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
insilmaril@417
  4833
{
insilmaril@417
  4834
	event->accept();
insilmaril@119
  4835
}
insilmaril@129
  4836
insilmaril@412
  4837
void MapEditor::dropEvent(QDropEvent *event)
insilmaril@129
  4838
{
insilmaril@424
  4839
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  4840
	if (sel)
insilmaril@128
  4841
	{
insilmaril@505
  4842
		if (debug)
insilmaril@505
  4843
			foreach (QString format,event->mimeData()->formats()) 
insilmaril@658
  4844
				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
insilmaril@497
  4845
insilmaril@497
  4846
insilmaril@417
  4847
		QList <QUrl> uris;
insilmaril@417
  4848
		if (event->mimeData()->hasImage()) 
insilmaril@128
  4849
		{
insilmaril@417
  4850
			 QVariant imageData = event->mimeData()->imageData();
insilmaril@417
  4851
			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
insilmaril@417
  4852
		} else
insilmaril@417
  4853
		if (event->mimeData()->hasUrls())
insilmaril@417
  4854
			uris=event->mimeData()->urls();
insilmaril@417
  4855
insilmaril@417
  4856
		if (uris.count()>0)
insilmaril@128
  4857
		{
insilmaril@417
  4858
			QStringList files;
insilmaril@417
  4859
			QString s;
insilmaril@417
  4860
			QString heading;
insilmaril@417
  4861
			BranchObj *bo;
insilmaril@428
  4862
			for (int i=0; i<uris.count();i++)
insilmaril@408
  4863
			{
insilmaril@428
  4864
				// Workaround to avoid adding empty branches
insilmaril@428
  4865
				if (!uris.at(i).toString().isEmpty())
insilmaril@417
  4866
				{
insilmaril@428
  4867
					bo=sel->addBranch();
insilmaril@428
  4868
					if (bo)
insilmaril@417
  4869
					{
insilmaril@428
  4870
						s=uris.at(i).toLocalFile();
insilmaril@428
  4871
						if (!s.isEmpty()) 
insilmaril@428
  4872
						{
insilmaril@625
  4873
						   QString file = QDir::fromNativeSeparators(s);
insilmaril@428
  4874
						   heading = QFileInfo(file).baseName();
insilmaril@428
  4875
						   files.append(file);
insilmaril@428
  4876
						   if (file.endsWith(".vym", false))
insilmaril@428
  4877
							   bo->setVymLink(file);
insilmaril@428
  4878
						   else
insilmaril@428
  4879
							   bo->setURL(uris.at(i).toString());
insilmaril@428
  4880
					   } else 
insilmaril@428
  4881
					   {
insilmaril@428
  4882
						   bo->setURL(uris.at(i).toString());
insilmaril@428
  4883
					   }
insilmaril@428
  4884
insilmaril@428
  4885
					   if (!heading.isEmpty())
insilmaril@428
  4886
						   bo->setHeading(heading);
insilmaril@428
  4887
					   else
insilmaril@428
  4888
						   bo->setHeading(uris.at(i).toString());
insilmaril@428
  4889
					}
insilmaril@417
  4890
				}
insilmaril@417
  4891
			}
insilmaril@645
  4892
			model->reposition();
insilmaril@417
  4893
		}
insilmaril@417
  4894
	}	
insilmaril@417
  4895
	event->acceptProposedAction();
insilmaril@417
  4896
}
insilmaril@417
  4897
insilmaril@491
  4898
void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
insilmaril@473
  4899
{
insilmaril@473
  4900
    Q_UNUSED(event);
insilmaril@473
  4901
insilmaril@473
  4902
	cout << "ME::timerEvent\n";
insilmaril@473
  4903
insilmaril@473
  4904
	for (int i=0; i<animObjList.size(); ++i)
insilmaril@473
  4905
	{
insilmaril@473
  4906
		animObjList.at(i)->animate();
insilmaril@473
  4907
		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
insilmaril@473
  4908
	}
insilmaril@645
  4909
	model->reposition();
insilmaril@473
  4910
}
insilmaril@473
  4911
insilmaril@528
  4912
insilmaril@528
  4913
void MapEditor::sendSelection()
insilmaril@473
  4914
{
insilmaril@531
  4915
	if (netstate!=Server) return;
insilmaril@531
  4916
	sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
insilmaril@528
  4917
}
insilmaril@528
  4918
insilmaril@528
  4919
void MapEditor::newServer()
insilmaril@528
  4920
{
insilmaril@531
  4921
	port=54321;
insilmaril@531
  4922
	sendCounter=0;
insilmaril@528
  4923
    tcpServer = new QTcpServer(this);
insilmaril@531
  4924
    if (!tcpServer->listen(QHostAddress::Any,port)) {
insilmaril@528
  4925
        QMessageBox::critical(this, "vym server",
insilmaril@528
  4926
                              QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
insilmaril@528
  4927
        close();
insilmaril@528
  4928
        return;
insilmaril@528
  4929
    }
insilmaril@528
  4930
	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
insilmaril@531
  4931
	netstate=Server;
insilmaril@534
  4932
	cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
insilmaril@473
  4933
}
insilmaril@473
  4934
insilmaril@531
  4935
void MapEditor::connectToServer()
insilmaril@531
  4936
{
insilmaril@531
  4937
	port=54321;
insilmaril@531
  4938
	server="salam.suse.de";
insilmaril@531
  4939
	server="localhost";
insilmaril@531
  4940
	clientSocket = new QTcpSocket (this);
insilmaril@531
  4941
	clientSocket->abort();
insilmaril@531
  4942
    clientSocket->connectToHost(server ,port);
insilmaril@531
  4943
	connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
insilmaril@531
  4944
    connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
insilmaril@531
  4945
            this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
insilmaril@531
  4946
	netstate=Client;		
insilmaril@658
  4947
	cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
insilmaril@531
  4948
insilmaril@531
  4949
	
insilmaril@531
  4950
}
insilmaril@531
  4951
insilmaril@527
  4952
void MapEditor::newClient()
insilmaril@527
  4953
{
insilmaril@527
  4954
    QTcpSocket *newClient = tcpServer->nextPendingConnection();
insilmaril@527
  4955
    connect(newClient, SIGNAL(disconnected()),
insilmaril@527
  4956
            newClient, SLOT(deleteLater()));
insilmaril@527
  4957
insilmaril@658
  4958
	cout <<"ME::newClient  at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
insilmaril@527
  4959
insilmaril@527
  4960
	clientList.append (newClient);
insilmaril@527
  4961
}
insilmaril@473
  4962
insilmaril@528
  4963
insilmaril@528
  4964
void MapEditor::sendData(const QString &s)
insilmaril@528
  4965
{
insilmaril@537
  4966
	if (clientList.size()==0) return;
insilmaril@537
  4967
insilmaril@528
  4968
	// Create bytearray to send
insilmaril@528
  4969
	QByteArray block;
insilmaril@528
  4970
    QDataStream out(&block, QIODevice::WriteOnly);
insilmaril@528
  4971
    out.setVersion(QDataStream::Qt_4_0);
insilmaril@528
  4972
insilmaril@528
  4973
	// Reserve some space for blocksize
insilmaril@528
  4974
    out << (quint16)0;
insilmaril@528
  4975
insilmaril@531
  4976
	// Write sendCounter
insilmaril@531
  4977
    out << sendCounter++;
insilmaril@531
  4978
insilmaril@528
  4979
	// Write data
insilmaril@528
  4980
    out << s;
insilmaril@528
  4981
insilmaril@528
  4982
	// Go back and write blocksize so far
insilmaril@528
  4983
    out.device()->seek(0);
insilmaril@531
  4984
    quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
insilmaril@531
  4985
	out << bs;
insilmaril@531
  4986
insilmaril@537
  4987
	if (debug)
insilmaril@658
  4988
		cout << "ME::sendData  bs="<<bs<<"  counter="<<sendCounter<<"  s="<<qPrintable(s)<<endl;
insilmaril@528
  4989
insilmaril@528
  4990
	for (int i=0; i<clientList.size(); ++i)
insilmaril@528
  4991
	{
insilmaril@658
  4992
		//cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
insilmaril@528
  4993
		clientList.at(i)->write (block);
insilmaril@528
  4994
	}
insilmaril@528
  4995
}
insilmaril@531
  4996
insilmaril@531
  4997
void MapEditor::readData ()
insilmaril@531
  4998
{
insilmaril@531
  4999
	while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
insilmaril@531
  5000
	{
insilmaril@537
  5001
		if (debug)
insilmaril@537
  5002
			cout <<"readData  bytesAvail="<<clientSocket->bytesAvailable();
insilmaril@534
  5003
		quint16 recCounter;
insilmaril@534
  5004
		quint16 blockSize;
insilmaril@534
  5005
insilmaril@534
  5006
		QDataStream in(clientSocket);
insilmaril@534
  5007
		in.setVersion(QDataStream::Qt_4_0);
insilmaril@534
  5008
insilmaril@534
  5009
		in >> blockSize;
insilmaril@534
  5010
		in >> recCounter;
insilmaril@534
  5011
		
insilmaril@534
  5012
		QString t;
insilmaril@534
  5013
		in >>t;
insilmaril@537
  5014
		if (debug)
insilmaril@658
  5015
			cout << "  t="<<qPrintable (t)<<endl;
insilmaril@534
  5016
		parseAtom (t);
insilmaril@531
  5017
	}
insilmaril@534
  5018
	return;
insilmaril@531
  5019
}
insilmaril@531
  5020
insilmaril@531
  5021
void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
insilmaril@531
  5022
{
insilmaril@531
  5023
    switch (socketError) {
insilmaril@531
  5024
    case QAbstractSocket::RemoteHostClosedError:
insilmaril@531
  5025
        break;
insilmaril@531
  5026
    case QAbstractSocket::HostNotFoundError:
insilmaril@645
  5027
        QMessageBox::information(this, vymName +" Network client",
insilmaril@531
  5028
                                 "The host was not found. Please check the "
insilmaril@531
  5029
                                    "host name and port settings.");
insilmaril@531
  5030
        break;
insilmaril@531
  5031
    case QAbstractSocket::ConnectionRefusedError:
insilmaril@645
  5032
        QMessageBox::information(this, vymName + " Network client",
insilmaril@531
  5033
                                 "The connection was refused by the peer. "
insilmaril@531
  5034
                                    "Make sure the fortune server is running, "
insilmaril@531
  5035
                                    "and check that the host name and port "
insilmaril@531
  5036
                                    "settings are correct.");
insilmaril@531
  5037
        break;
insilmaril@531
  5038
    default:
insilmaril@645
  5039
        QMessageBox::information(this, vymName + " Network client",
insilmaril@531
  5040
                                 QString("The following error occurred: %1.")
insilmaril@531
  5041
                                 .arg(clientSocket->errorString()));
insilmaril@531
  5042
    }
insilmaril@531
  5043
}
insilmaril@531
  5044
insilmaril@528
  5045
void MapEditor::autosave()
insilmaril@528
  5046
{
insilmaril@528
  5047
	// Disable autosave, while we have gone back in history
insilmaril@528
  5048
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@528
  5049
	if (redosAvail>0) return;
insilmaril@528
  5050
insilmaril@528
  5051
insilmaril@528
  5052
	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
insilmaril@528
  5053
		mainWindow->fileSave (this);
insilmaril@528
  5054
}
insilmaril@528
  5055
insilmaril@528
  5056
insilmaril@491
  5057
/*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
insilmaril@417
  5058
{
insilmaril@408
  5059
insilmaril@408
  5060
		} else if (event->provides("application/x-moz-file-promise-url") && 
insilmaril@408
  5061
			 event->provides("application/x-moz-nativeimage")) 
insilmaril@408
  5062
		{
insilmaril@129
  5063
			// Contains url to the img src in unicode16
insilmaril@128
  5064
			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
insilmaril@128
  5065
			QString url = QString((const QChar*)d.data(),d.size()/2);
insilmaril@408
  5066
			fetchImage(url);
insilmaril@408
  5067
			event->accept();
insilmaril@128
  5068
			update=true;
insilmaril@408
  5069
		} else if (event->provides ("text/uri-list"))
insilmaril@408
  5070
		{	// Uris provided e.g. by konqueror
insilmaril@408
  5071
			Q3UriDrag::decode (event,uris);
insilmaril@408
  5072
		} else if (event->provides ("_NETSCAPE_URL"))
insilmaril@128
  5073
		{	// Uris provided by Mozilla
insilmaril@129
  5074
		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
insilmaril@129
  5075
		  uris.append(l[0]);
insilmaril@129
  5076
		  heading = l[1];
insilmaril@129
  5077
		} else if (event->provides("text/html")) {
insilmaril@129
  5078
insilmaril@129
  5079
		  // Handels text mime types
insilmaril@129
  5080
		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
insilmaril@129
  5081
		  QByteArray d = event->encodedData("text/html");
insilmaril@129
  5082
		  QString text;
insilmaril@129
  5083
		  if (isUnicode16(d)) 
insilmaril@129
  5084
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5085
		  else 
insilmaril@129
  5086
		    text = QString(d);
insilmaril@129
  5087
insilmaril@129
  5088
		  textEditor->setText(text);
insilmaril@129
  5089
insilmaril@129
  5090
		  event->accept();
insilmaril@129
  5091
		  update=true;
insilmaril@129
  5092
		} else if (event->provides("text/plain")) {
insilmaril@129
  5093
		  QByteArray d = event->encodedData("text/plain");
insilmaril@129
  5094
		  QString text;
insilmaril@129
  5095
		  if (isUnicode16(d))
insilmaril@129
  5096
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5097
		  else 
insilmaril@129
  5098
		    text = QString(d);
insilmaril@129
  5099
insilmaril@129
  5100
		  textEditor->setText(text);
insilmaril@129
  5101
		  
insilmaril@129
  5102
		  event->accept();
insilmaril@129
  5103
		  update= true;
insilmaril@128
  5104
		}
insilmaril@417
  5105
insilmaril@406
  5106
		*/
insilmaril@406
  5107
insilmaril@417
  5108
insilmaril@412
  5109
insilmaril@412
  5110
bool isUnicode16(const QByteArray &d) 
insilmaril@412
  5111
{
insilmaril@412
  5112
  // TODO: make more precise check for unicode 16.
insilmaril@412
  5113
  // Guess unicode16 if any of second bytes are zero
insilmaril@412
  5114
  unsigned int length = max(0,d.size()-2)/2;
insilmaril@412
  5115
  for (unsigned int i = 0; i<length ; i++)
insilmaril@412
  5116
    if (d.at(i*2+1)==0) return true;
insilmaril@412
  5117
  return false;
insilmaril@412
  5118
}
insilmaril@412
  5119
      
insilmaril@395
  5120
void MapEditor::addFloatImageInt (const QPixmap &img) 
insilmaril@119
  5121
{
insilmaril@424
  5122
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  5123
	if (bo)
insilmaril@119
  5124
  {
insilmaril@395
  5125
	FloatImageObj *fio=bo->addFloatImage();
insilmaril@395
  5126
    fio->load(img);
insilmaril@505
  5127
    fio->setOriginalFilename("No original filename (image added by dropevent)");	
insilmaril@505
  5128
	QString s=bo->getSelectString();
insilmaril@505
  5129
	saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio  );
insilmaril@505
  5130
	saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
insilmaril@645
  5131
    model->reposition();
insilmaril@408
  5132
    scene()->update();
insilmaril@119
  5133
  }
insilmaril@119
  5134
}
insilmaril@119
  5135
insilmaril@412
  5136
/*
insilmaril@412
  5137
insilmaril@412
  5138
void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
insilmaril@119
  5139
{
insilmaril@119
  5140
  if (!imageBuffer) imageBuffer = new QBuffer();
insilmaril@119
  5141
  if (!imageBuffer->isOpen()) {
insilmaril@366
  5142
    imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
insilmaril@119
  5143
  }
insilmaril@119
  5144
  imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
insilmaril@119
  5145
}
insilmaril@119
  5146
insilmaril@119
  5147
insilmaril@366
  5148
void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
insilmaril@119
  5149
{
insilmaril@366
  5150
	if (nop->state()==Q3NetworkProtocol::StDone) {
insilmaril@129
  5151
		QPixmap img(imageBuffer->buffer());
insilmaril@395
  5152
		addFloatImageInt (img);
insilmaril@129
  5153
	}
insilmaril@129
  5154
insilmaril@129
  5155
	if (imageBuffer) {
insilmaril@129
  5156
		imageBuffer->close();
insilmaril@129
  5157
		if (imageBuffer) {
insilmaril@129
  5158
			imageBuffer->close();
insilmaril@129
  5159
			delete imageBuffer;
insilmaril@129
  5160
			imageBuffer = 0;
insilmaril@129
  5161
		}
insilmaril@129
  5162
	}
insilmaril@119
  5163
}
insilmaril@119
  5164
insilmaril@129
  5165
void MapEditor::fetchImage(const QString &url) 
insilmaril@119
  5166
{
insilmaril@119
  5167
  if (urlOperator) {
insilmaril@119
  5168
    urlOperator->stop();
insilmaril@119
  5169
    disconnect(urlOperator);
insilmaril@119
  5170
    delete urlOperator;
insilmaril@119
  5171
  }
insilmaril@119
  5172
  
insilmaril@366
  5173
  urlOperator = new Q3UrlOperator(url);
insilmaril@366
  5174
  connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
insilmaril@366
  5175
	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
insilmaril@366
  5176
insilmaril@366
  5177
  connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
insilmaril@366
  5178
	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
insilmaril@119
  5179
  urlOperator->get();
insilmaril@119
  5180
}
insilmaril@412
  5181
*/
insilmaril@412
  5182