mapeditor.cpp
author insilmaril
Fri, 01 Feb 2008 16:59:09 +0000
changeset 668 b63ff428c781
parent 663 827d334d55f1
child 676 3dabc6424d73
permissions -rw-r--r--
Added simplified chinese by Shaodong
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
		xelection.clear();
insilmaril@645
  1558
		model->setMapEditor(this);
insilmaril@0
  1559
		// (map state is set later at end of load...)
insilmaril@0
  1560
	} else
insilmaril@0
  1561
	{
insilmaril@424
  1562
		BranchObj *bo=xelection.getBranch();
insilmaril@424
  1563
		if (!bo) return aborted;
insilmaril@395
  1564
		if (lmode==ImportAdd)
insilmaril@395
  1565
			saveStateChangingPart(
insilmaril@424
  1566
				bo,
insilmaril@424
  1567
				bo,
insilmaril@395
  1568
				QString("addMapInsert (%1)").arg(fname),
insilmaril@395
  1569
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@395
  1570
		else	
insilmaril@395
  1571
			saveStateChangingPart(
insilmaril@424
  1572
				bo,
insilmaril@424
  1573
				bo,
insilmaril@395
  1574
				QString("addMapReplace(%1)").arg(fname),
insilmaril@395
  1575
				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
insilmaril@0
  1576
	}	
insilmaril@0
  1577
    
insilmaril@0
  1578
	QFile file( fname );
insilmaril@0
  1579
insilmaril@0
  1580
	// I am paranoid: file should exist anyway
insilmaril@0
  1581
	// according to check in mainwindow.
insilmaril@0
  1582
	if (!file.exists() )
insilmaril@0
  1583
	{
insilmaril@0
  1584
		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
  1585
				   tr("Couldn't open map " +fname)+".");
insilmaril@205
  1586
		err=aborted;	
insilmaril@0
  1587
	} else
insilmaril@0
  1588
	{
insilmaril@473
  1589
		bool blockSaveStateOrg=blockSaveState;
insilmaril@139
  1590
		blockReposition=true;
insilmaril@473
  1591
		blockSaveState=true;
insilmaril@0
  1592
		QXmlInputSource source( file);
insilmaril@0
  1593
		QXmlSimpleReader reader;
insilmaril@571
  1594
		reader.setContentHandler( handler );
insilmaril@571
  1595
		reader.setErrorHandler( handler );
insilmaril@645
  1596
		handler->setModel ( model);
insilmaril@494
  1597
insilmaril@494
  1598
insilmaril@494
  1599
		// We need to set the tmpDir in order  to load files with rel. path
insilmaril@494
  1600
		QString tmpdir= fname.left(fname.findRev("/",-1));	
insilmaril@571
  1601
		handler->setTmpDir (tmpdir);
insilmaril@571
  1602
		handler->setInputFile (file.name());
insilmaril@571
  1603
		handler->setLoadMode (lmode);
insilmaril@0
  1604
		bool ok = reader.parse( source );
insilmaril@139
  1605
		blockReposition=false;
insilmaril@473
  1606
		blockSaveState=blockSaveStateOrg;
insilmaril@0
  1607
		file.close();
insilmaril@0
  1608
		if ( ok ) 
insilmaril@0
  1609
		{
insilmaril@645
  1610
			model->reposition();
insilmaril@442
  1611
			xelection.update();
insilmaril@0
  1612
			if (lmode==NewMap)
insilmaril@0
  1613
			{
insilmaril@0
  1614
				mapDefault=false;
insilmaril@0
  1615
				mapChanged=false;
insilmaril@0
  1616
				mapUnsaved=false;
insilmaril@473
  1617
				autosaveTimer->stop();
insilmaril@0
  1618
			}
insilmaril@0
  1619
		} else 
insilmaril@0
  1620
		{
insilmaril@0
  1621
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@571
  1622
					   tr( handler->errorProtocol() ) );
insilmaril@0
  1623
			// returnCode=1;	
insilmaril@0
  1624
			// Still return "success": the map maybe at least
insilmaril@0
  1625
			// partially read by the parser
insilmaril@0
  1626
		}	
insilmaril@0
  1627
	}	
insilmaril@0
  1628
	updateActions();
insilmaril@205
  1629
	return err;
insilmaril@0
  1630
}
insilmaril@0
  1631
insilmaril@0
  1632
int MapEditor::save (const SaveMode &savemode)
insilmaril@0
  1633
{
insilmaril@0
  1634
	// Create mapName and fileDir
insilmaril@0
  1635
	makeSubDirs (fileDir);
insilmaril@0
  1636
	QString fname;
insilmaril@0
  1637
	if (saveZipped())
insilmaril@0
  1638
		// save as .xml
insilmaril@0
  1639
		fname=mapName+".xml";
insilmaril@0
  1640
	else
insilmaril@0
  1641
		// use name given by user, even if he chooses .doc
insilmaril@0
  1642
		fname=fileName;
insilmaril@0
  1643
insilmaril@0
  1644
insilmaril@0
  1645
	QString saveFile;
insilmaril@424
  1646
	if (savemode==CompleteMap || xelection.isEmpty())
insilmaril@629
  1647
	{
insilmaril@629
  1648
		// Save complete map
insilmaril@408
  1649
		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
insilmaril@629
  1650
		mapChanged=false;
insilmaril@629
  1651
		mapUnsaved=false;
insilmaril@629
  1652
		autosaveTimer->stop();
insilmaril@629
  1653
	}
insilmaril@106
  1654
	else	
insilmaril@491
  1655
	{
insilmaril@629
  1656
		// Save part of map
insilmaril@491
  1657
		if (xelection.type()==Selection::FloatImage)
insilmaril@491
  1658
			saveFloatImage();
insilmaril@491
  1659
		else	
insilmaril@491
  1660
			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
insilmaril@629
  1661
		// TODO take care of multiselections
insilmaril@491
  1662
	}	
insilmaril@0
  1663
insilmaril@163
  1664
	if (!saveStringToDisk(fileDir+fname,saveFile))
insilmaril@0
  1665
		return 1;
insilmaril@0
  1666
insilmaril@531
  1667
	updateActions();
insilmaril@531
  1668
	return 0;
insilmaril@0
  1669
}
insilmaril@0
  1670
insilmaril@0
  1671
void MapEditor::setZipped (bool z)
insilmaril@0
  1672
{
insilmaril@0
  1673
	zipped=z;
insilmaril@0
  1674
}
insilmaril@0
  1675
insilmaril@0
  1676
bool MapEditor::saveZipped ()
insilmaril@0
  1677
{
insilmaril@0
  1678
	return zipped;
insilmaril@0
  1679
}
insilmaril@0
  1680
insilmaril@0
  1681
void MapEditor::print()
insilmaril@0
  1682
{
insilmaril@0
  1683
	if ( !printer ) 
insilmaril@0
  1684
	{
insilmaril@0
  1685
		printer = new QPrinter;
insilmaril@0
  1686
		printer->setColorMode (QPrinter::Color);
insilmaril@366
  1687
		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@412
  1688
		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
insilmaril@412
  1689
		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
insilmaril@0
  1690
	}
insilmaril@0
  1691
insilmaril@645
  1692
	QRectF totalBBox=model->getTotalBBox();
insilmaril@0
  1693
insilmaril@0
  1694
	// Try to set orientation automagically
insilmaril@0
  1695
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
  1696
	// there are problems with landscape mode, see
insilmaril@0
  1697
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
  1698
insilmaril@0
  1699
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
  1700
		// recommend landscape
insilmaril@0
  1701
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
  1702
	else	
insilmaril@0
  1703
		// recommend portrait
insilmaril@0
  1704
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
  1705
insilmaril@0
  1706
	if ( printer->setup(this) ) 
insilmaril@0
  1707
	// returns false, if printing is canceled
insilmaril@0
  1708
	{
insilmaril@0
  1709
		QPainter pp(printer);
insilmaril@0
  1710
insilmaril@412
  1711
		pp.setRenderHint(QPainter::Antialiasing,true);
insilmaril@412
  1712
insilmaril@0
  1713
		// Don't print the visualisation of selection
insilmaril@424
  1714
		xelection.unselect();
insilmaril@0
  1715
insilmaril@408
  1716
		QRectF mapRect=totalBBox;
insilmaril@411
  1717
		QGraphicsRectItem *frame=NULL;
insilmaril@412
  1718
insilmaril@417
  1719
		if (printFrame) 
insilmaril@0
  1720
		{
insilmaril@417
  1721
			// Print frame around map
insilmaril@417
  1722
			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@417
  1723
				totalBBox.width()+20, totalBBox.height()+20);
insilmaril@417
  1724
			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
insilmaril@417
  1725
			frame->setZValue(0);
insilmaril@417
  1726
			frame->show();    
insilmaril@417
  1727
		}		
insilmaril@417
  1728
insilmaril@417
  1729
insilmaril@412
  1730
		double paperAspect = (double)printer->width()   / (double)printer->height();
insilmaril@412
  1731
		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
insilmaril@417
  1732
		int viewBottom;
insilmaril@0
  1733
		if (mapAspect>=paperAspect)
insilmaril@0
  1734
		{
insilmaril@0
  1735
			// Fit horizontally to paper width
insilmaril@417
  1736
			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
insilmaril@417
  1737
			viewBottom=(int)(printer->width()/mapAspect);	
insilmaril@0
  1738
		}	else
insilmaril@0
  1739
		{
insilmaril@0
  1740
			// Fit vertically to paper height
insilmaril@417
  1741
			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
insilmaril@417
  1742
			viewBottom=printer->height();	
insilmaril@0
  1743
		}	
insilmaril@417
  1744
		
insilmaril@417
  1745
		if (printFooter) 
insilmaril@417
  1746
		{
insilmaril@417
  1747
			// Print footer below map
insilmaril@417
  1748
			QFont font;		
insilmaril@417
  1749
			font.setPointSize(10);
insilmaril@417
  1750
			pp.setFont (font);
insilmaril@417
  1751
			QRectF footerBox(0,viewBottom,printer->width(),15);
insilmaril@417
  1752
			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
insilmaril@417
  1753
			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
insilmaril@417
  1754
		}
insilmaril@412
  1755
		mapScene->render (
insilmaril@412
  1756
			&pp, 
insilmaril@412
  1757
			QRectF (0,0,printer->width(),printer->height()-15),
insilmaril@412
  1758
			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
insilmaril@412
  1759
		);
insilmaril@412
  1760
		
insilmaril@412
  1761
		// Viewport has paper dimension
insilmaril@412
  1762
		if (frame)  delete (frame);
insilmaril@0
  1763
insilmaril@0
  1764
		// Restore selection
insilmaril@424
  1765
		xelection.reselect();
insilmaril@119
  1766
insilmaril@119
  1767
		// Save settings in vymrc
insilmaril@366
  1768
		settings.writeEntry("/mainwindow/printerName",printer->printerName());
insilmaril@412
  1769
		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
insilmaril@412
  1770
		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
insilmaril@0
  1771
	}
insilmaril@0
  1772
}
insilmaril@0
  1773
insilmaril@408
  1774
void MapEditor::setAntiAlias (bool b)
insilmaril@408
  1775
{
insilmaril@408
  1776
	setRenderHint(QPainter::Antialiasing,b);
insilmaril@408
  1777
}
insilmaril@408
  1778
insilmaril@408
  1779
void MapEditor::setSmoothPixmap(bool b)
insilmaril@408
  1780
{
insilmaril@408
  1781
	setRenderHint(QPainter::SmoothPixmapTransform,b);
insilmaril@408
  1782
}
insilmaril@408
  1783
insilmaril@0
  1784
QPixmap MapEditor::getPixmap()
insilmaril@0
  1785
{
insilmaril@645
  1786
	QRectF mapRect=model->getTotalBBox();
insilmaril@564
  1787
	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
insilmaril@0
  1788
	QPainter pp (&pix);
insilmaril@420
  1789
	
insilmaril@420
  1790
	pp.setRenderHints(renderHints());
insilmaril@0
  1791
insilmaril@0
  1792
	// Don't print the visualisation of selection
insilmaril@424
  1793
	xelection.unselect();
insilmaril@0
  1794
insilmaril@420
  1795
	mapScene->render (	&pp, 
insilmaril@450
  1796
		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
insilmaril@420
  1797
		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
insilmaril@420
  1798
insilmaril@0
  1799
	// Restore selection
insilmaril@424
  1800
	xelection.reselect();
insilmaril@0
  1801
	
insilmaril@0
  1802
	return pix;
insilmaril@0
  1803
}
insilmaril@0
  1804
insilmaril@628
  1805
void MapEditor::setHideTmpMode (HideTmpMode mode)
insilmaril@260
  1806
{
insilmaril@260
  1807
	hidemode=mode;
insilmaril@645
  1808
	model->setHideTmp (hidemode);
insilmaril@645
  1809
	model->reposition();
insilmaril@408
  1810
	scene()->update();
insilmaril@260
  1811
}
insilmaril@260
  1812
insilmaril@628
  1813
HideTmpMode MapEditor::getHideTmpMode()
insilmaril@260
  1814
{
insilmaril@260
  1815
	return hidemode;
insilmaril@260
  1816
}
insilmaril@260
  1817
insilmaril@260
  1818
void MapEditor::setExportMode (bool b)
insilmaril@260
  1819
{
insilmaril@260
  1820
	// should be called before and after exports
insilmaril@260
  1821
	// depending on the settings
insilmaril@600
  1822
	if (b && settings.value("/export/useHideExport","true")=="true")
insilmaril@628
  1823
		setHideTmpMode (HideExport);
insilmaril@260
  1824
	else	
insilmaril@628
  1825
		setHideTmpMode (HideNone);
insilmaril@0
  1826
}
insilmaril@0
  1827
insilmaril@514
  1828
void MapEditor::exportASCII(QString fname,bool askName)
insilmaril@0
  1829
{
insilmaril@514
  1830
	ExportASCII ex;
insilmaril@645
  1831
	ex.setModel (model);
insilmaril@514
  1832
	if (fname=="") 
insilmaril@514
  1833
		ex.setFile (mapName+".txt");	
insilmaril@514
  1834
	else
insilmaril@514
  1835
		ex.setFile (fname);
insilmaril@514
  1836
insilmaril@514
  1837
	if (askName)
insilmaril@514
  1838
	{
insilmaril@514
  1839
		//ex.addFilter ("TXT (*.txt)");
insilmaril@514
  1840
		ex.setDir(lastImageDir);
insilmaril@514
  1841
		//ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
insilmaril@514
  1842
		ex.execDialog() ; 
insilmaril@514
  1843
	} 
insilmaril@514
  1844
	if (!ex.canceled())
insilmaril@514
  1845
	{
insilmaril@514
  1846
		setExportMode(true);
insilmaril@514
  1847
		ex.doExport();
insilmaril@514
  1848
		setExportMode(false);
insilmaril@514
  1849
	}
insilmaril@514
  1850
}
insilmaril@514
  1851
insilmaril@514
  1852
void MapEditor::exportImage(QString fname, bool askName, QString format)
insilmaril@514
  1853
{
insilmaril@514
  1854
	if (fname=="")
insilmaril@514
  1855
	{
insilmaril@514
  1856
		fname=mapName+".png";
insilmaril@514
  1857
		format="PNG";
insilmaril@514
  1858
	} 	
insilmaril@514
  1859
insilmaril@514
  1860
	if (askName)
insilmaril@514
  1861
	{
insilmaril@514
  1862
		QStringList fl;
insilmaril@514
  1863
		QFileDialog *fd=new QFileDialog (this);
insilmaril@514
  1864
		fd->setCaption (tr("Export map as image"));
insilmaril@514
  1865
		fd->setDirectory (lastImageDir);
insilmaril@514
  1866
		fd->setFileMode(QFileDialog::AnyFile);
insilmaril@514
  1867
		fd->setFilters  (imageIO.getFilters() );
insilmaril@514
  1868
		if (fd->exec())
insilmaril@514
  1869
		{
insilmaril@514
  1870
			fl=fd->selectedFiles();
insilmaril@514
  1871
			fname=fl.first();
insilmaril@514
  1872
			format=imageIO.getType(fd->selectedFilter());
insilmaril@514
  1873
		} 
insilmaril@514
  1874
	}
insilmaril@514
  1875
insilmaril@260
  1876
	setExportMode (true);
insilmaril@0
  1877
	QPixmap pix (getPixmap());
insilmaril@514
  1878
	pix.save(fname, format);
insilmaril@260
  1879
	setExportMode (false);
insilmaril@0
  1880
}
insilmaril@0
  1881
insilmaril@185
  1882
void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
insilmaril@163
  1883
{
insilmaril@185
  1884
	ExportOO ex;
insilmaril@199
  1885
	ex.setFile (fn);
insilmaril@645
  1886
	ex.setModel (model);
insilmaril@260
  1887
	if (ex.setConfigFile(cf)) 
insilmaril@260
  1888
	{
insilmaril@260
  1889
		setExportMode (true);
insilmaril@260
  1890
		ex.exportPresentation();
insilmaril@260
  1891
		setExportMode (false);
insilmaril@260
  1892
	}
insilmaril@163
  1893
}
insilmaril@163
  1894
insilmaril@520
  1895
void MapEditor::exportXHTML (const QString &dir, bool askForName)
insilmaril@517
  1896
{
insilmaril@517
  1897
			ExportXHTMLDialog dia(this);
insilmaril@517
  1898
			dia.setFilePath (filePath );
insilmaril@517
  1899
			dia.setMapName (mapName );
insilmaril@517
  1900
			dia.readSettings();
insilmaril@526
  1901
			if (dir!="") dia.setDir (dir);
insilmaril@517
  1902
insilmaril@517
  1903
			bool ok=true;
insilmaril@517
  1904
			
insilmaril@520
  1905
			if (askForName)
insilmaril@517
  1906
			{
insilmaril@517
  1907
				if (dia.exec()!=QDialog::Accepted) 
insilmaril@517
  1908
					ok=false;
insilmaril@517
  1909
				else	
insilmaril@517
  1910
				{
insilmaril@517
  1911
					QDir d (dia.getDir());
insilmaril@517
  1912
					// Check, if warnings should be used before overwriting
insilmaril@517
  1913
					// the output directory
insilmaril@517
  1914
					if (d.exists() && d.count()>0)
insilmaril@517
  1915
					{
insilmaril@517
  1916
						WarningDialog warn;
insilmaril@517
  1917
						warn.showCancelButton (true);
insilmaril@517
  1918
						warn.setText(QString(
insilmaril@517
  1919
							"The directory %1 is not empty.\n"
insilmaril@517
  1920
							"Do you risk to overwrite some of its contents?").arg(d.path() ));
insilmaril@517
  1921
						warn.setCaption("Warning: Directory not empty");
insilmaril@517
  1922
						warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
insilmaril@517
  1923
insilmaril@517
  1924
						if (warn.exec()!=QDialog::Accepted) ok=false;
insilmaril@517
  1925
					}
insilmaril@517
  1926
				}	
insilmaril@517
  1927
			}
insilmaril@517
  1928
insilmaril@517
  1929
			if (ok)
insilmaril@517
  1930
			{
insilmaril@526
  1931
				exportXML (dia.getDir(),false );
insilmaril@517
  1932
				dia.doExport(mapName );
insilmaril@517
  1933
				//if (dia.hasChanged()) setChanged();
insilmaril@517
  1934
			}
insilmaril@517
  1935
}
insilmaril@0
  1936
insilmaril@526
  1937
void MapEditor::exportXML(QString dir, bool askForName)
insilmaril@0
  1938
{
insilmaril@526
  1939
	if (askForName)
insilmaril@526
  1940
	{
insilmaril@526
  1941
		dir=browseDirectory(this,tr("Export XML to directory"));
insilmaril@526
  1942
		if (dir =="" && !reallyWriteDirectory(dir) )
insilmaril@526
  1943
		return;
insilmaril@526
  1944
	}
insilmaril@526
  1945
insilmaril@260
  1946
	// Hide stuff during export, if settings want this
insilmaril@260
  1947
	setExportMode (true);
insilmaril@260
  1948
insilmaril@0
  1949
	// Create subdirectories
insilmaril@0
  1950
	makeSubDirs (dir);
insilmaril@0
  1951
insilmaril@0
  1952
	// write to directory
insilmaril@645
  1953
	QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
insilmaril@0
  1954
	QFile file;
insilmaril@0
  1955
insilmaril@0
  1956
	file.setName ( dir + "/"+mapName+".xml");
insilmaril@366
  1957
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
  1958
	{
insilmaril@0
  1959
		// This should neverever happen
insilmaril@159
  1960
		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
insilmaril@0
  1961
		return;
insilmaril@0
  1962
	}	
insilmaril@0
  1963
insilmaril@0
  1964
	// Write it finally, and write in UTF8, no matter what 
insilmaril@0
  1965
	QTextStream ts( &file );
insilmaril@0
  1966
	ts.setEncoding (QTextStream::UnicodeUTF8);
insilmaril@0
  1967
	ts << saveFile;
insilmaril@0
  1968
	file.close();
insilmaril@0
  1969
insilmaril@0
  1970
	// Now write image, too
insilmaril@517
  1971
	exportImage (dir+"/images/"+mapName+".png",false,"PNG");
insilmaril@260
  1972
insilmaril@260
  1973
	setExportMode (false);
insilmaril@0
  1974
}
insilmaril@0
  1975
insilmaril@0
  1976
void MapEditor::clear()
insilmaril@0
  1977
{
insilmaril@424
  1978
	xelection.unselect();
insilmaril@645
  1979
	model->clear();
insilmaril@0
  1980
}
insilmaril@0
  1981
insilmaril@0
  1982
void MapEditor::copy()
insilmaril@0
  1983
{
insilmaril@424
  1984
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  1985
	if (sel)
insilmaril@0
  1986
	{
insilmaril@502
  1987
		if (redosAvail == 0)
insilmaril@0
  1988
		{
insilmaril@502
  1989
			// Copy to history
insilmaril@502
  1990
			QString s=sel->getSelectString();
insilmaril@505
  1991
			saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel  );
insilmaril@502
  1992
			curClipboard=curStep;
insilmaril@502
  1993
		}
insilmaril@502
  1994
insilmaril@502
  1995
		// Copy also to global clipboard, because we are at last step in history
insilmaril@625
  1996
		QString bakMapName(QString("history-%1").arg(curStep));
insilmaril@625
  1997
		QString bakMapDir(tmpMapDir +"/"+bakMapName);
insilmaril@502
  1998
		copyDir (bakMapDir,clipboardDir );
insilmaril@166
  1999
insilmaril@166
  2000
		clipboardEmpty=false;
insilmaril@166
  2001
		updateActions();
insilmaril@0
  2002
	}	    
insilmaril@0
  2003
}
insilmaril@0
  2004
insilmaril@163
  2005
void MapEditor::redo()
insilmaril@163
  2006
{
insilmaril@381
  2007
	// Can we undo at all?
insilmaril@381
  2008
	if (redosAvail<1) return;
insilmaril@473
  2009
insilmaril@473
  2010
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  2011
	blockSaveState=true;
insilmaril@473
  2012
	
insilmaril@381
  2013
	redosAvail--;
insilmaril@381
  2014
insilmaril@381
  2015
	if (undosAvail<stepsTotal) undosAvail++;
insilmaril@366
  2016
	curStep++;
insilmaril@381
  2017
	if (curStep>stepsTotal) curStep=1;
insilmaril@366
  2018
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  2019
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  2020
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  2021
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  2022
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  2023
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  2024
insilmaril@645
  2025
	/* TODO Maybe check for version, if we save the history
insilmaril@395
  2026
	if (!checkVersion(version))
insilmaril@395
  2027
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  2028
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@645
  2029
	*/ 
insilmaril@366
  2030
insilmaril@163
  2031
	// Find out current undo directory
insilmaril@625
  2032
	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@366
  2033
insilmaril@473
  2034
	if (debug)
insilmaril@473
  2035
	{
insilmaril@473
  2036
		cout << "ME::redo() begin\n";
insilmaril@473
  2037
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  2038
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  2039
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  2040
		cout << "    ---------------------------"<<endl;
insilmaril@473
  2041
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  2042
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  2043
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  2044
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  2045
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  2046
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  2047
	}
insilmaril@163
  2048
insilmaril@163
  2049
	// select  object before redo
insilmaril@163
  2050
	if (!redoSelection.isEmpty())
insilmaril@163
  2051
		select (redoSelection);
insilmaril@163
  2052
insilmaril@366
  2053
insilmaril@366
  2054
	parseAtom (redoCommand);
insilmaril@645
  2055
	model->reposition();
insilmaril@366
  2056
insilmaril@473
  2057
	blockSaveState=blockSaveStateOrg;
insilmaril@366
  2058
insilmaril@366
  2059
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  2060
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  2061
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  2062
	undoSet.writeSettings(histPath);
insilmaril@366
  2063
insilmaril@408
  2064
	mainWindow->updateHistory (undoSet);
insilmaril@407
  2065
	updateActions();
insilmaril@366
  2066
insilmaril@366
  2067
	/* TODO remove testing
insilmaril@163
  2068
	cout << "ME::redo() end\n";
insilmaril@163
  2069
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2070
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2071
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2072
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2073
	*/
insilmaril@366
  2074
insilmaril@366
  2075
insilmaril@163
  2076
}
insilmaril@163
  2077
insilmaril@390
  2078
bool MapEditor::isRedoAvailable()
insilmaril@390
  2079
{
insilmaril@393
  2080
	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
insilmaril@390
  2081
		return true;
insilmaril@390
  2082
	else	
insilmaril@390
  2083
		return false;
insilmaril@390
  2084
}
insilmaril@390
  2085
insilmaril@106
  2086
void MapEditor::undo()
insilmaril@106
  2087
{
insilmaril@381
  2088
	// Can we undo at all?
insilmaril@381
  2089
	if (undosAvail<1) return;
insilmaril@381
  2090
insilmaril@502
  2091
	mainWindow->statusMessage (tr("Autosave disabled during undo."));
insilmaril@502
  2092
insilmaril@473
  2093
	bool blockSaveStateOrg=blockSaveState;
insilmaril@473
  2094
	blockSaveState=true;
insilmaril@473
  2095
	
insilmaril@366
  2096
	QString undoCommand=  undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
insilmaril@366
  2097
	QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
insilmaril@366
  2098
	QString redoCommand=  undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
insilmaril@366
  2099
	QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
insilmaril@366
  2100
	QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
insilmaril@395
  2101
	QString version=undoSet.readEntry ("/history/version");
insilmaril@395
  2102
insilmaril@645
  2103
	/* TODO Maybe check for version, if we save the history
insilmaril@395
  2104
	if (!checkVersion(version))
insilmaril@395
  2105
		QMessageBox::warning(0,tr("Warning"),
insilmaril@404
  2106
			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
insilmaril@645
  2107
	*/
insilmaril@366
  2108
insilmaril@163
  2109
	// Find out current undo directory
insilmaril@625
  2110
	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
insilmaril@163
  2111
insilmaril@136
  2112
	// select  object before undo
insilmaril@136
  2113
	if (!undoSelection.isEmpty())
insilmaril@136
  2114
		select (undoSelection);
insilmaril@136
  2115
insilmaril@473
  2116
	if (debug)
insilmaril@473
  2117
	{
insilmaril@473
  2118
		cout << "ME::undo() begin\n";
insilmaril@473
  2119
		cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@473
  2120
		cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@473
  2121
		cout << "       curStep="<<curStep<<endl;
insilmaril@473
  2122
		cout << "    ---------------------------"<<endl;
insilmaril@473
  2123
		cout << "    comment="<<comment.toStdString()<<endl;
insilmaril@473
  2124
		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
insilmaril@473
  2125
		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
insilmaril@473
  2126
		cout << "    redoCom="<<redoCommand.toStdString()<<endl;
insilmaril@473
  2127
		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
insilmaril@473
  2128
		cout << "    ---------------------------"<<endl<<endl;
insilmaril@473
  2129
	}	
insilmaril@106
  2130
	parseAtom (undoCommand);
insilmaril@645
  2131
	model->reposition();
insilmaril@106
  2132
insilmaril@163
  2133
	undosAvail--;
insilmaril@366
  2134
	curStep--; 
insilmaril@381
  2135
	if (curStep<1) curStep=stepsTotal;
insilmaril@366
  2136
insilmaril@366
  2137
	redosAvail++;
insilmaril@163
  2138
insilmaril@473
  2139
	blockSaveState=blockSaveStateOrg;
insilmaril@163
  2140
/* TODO remove testing
insilmaril@163
  2141
	cout << "ME::undo() end\n";
insilmaril@163
  2142
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@366
  2143
	cout << "    redosAvail="<<redosAvail<<endl;
insilmaril@366
  2144
	cout << "       curStep="<<curStep<<endl;
insilmaril@163
  2145
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@404
  2146
*/
insilmaril@366
  2147
insilmaril@366
  2148
	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
insilmaril@366
  2149
	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
insilmaril@366
  2150
	undoSet.setEntry ("/history/curStep",QString::number(curStep));
insilmaril@366
  2151
	undoSet.writeSettings(histPath);
insilmaril@366
  2152
insilmaril@404
  2153
	mainWindow->updateHistory (undoSet);
insilmaril@366
  2154
	updateActions();
insilmaril@442
  2155
	xelection.update();
insilmaril@420
  2156
	ensureSelectionVisible();
insilmaril@106
  2157
}
insilmaril@106
  2158
insilmaril@390
  2159
bool MapEditor::isUndoAvailable()
insilmaril@390
  2160
{
insilmaril@390
  2161
	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
insilmaril@390
  2162
		return true;
insilmaril@390
  2163
	else	
insilmaril@390
  2164
		return false;
insilmaril@390
  2165
}
insilmaril@390
  2166
insilmaril@404
  2167
void MapEditor::gotoHistoryStep (int i)
insilmaril@381
  2168
{
insilmaril@381
  2169
	// Restore variables
insilmaril@381
  2170
	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
insilmaril@388
  2171
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@388
  2172
insilmaril@388
  2173
	if (i<0) i=undosAvail+redosAvail;
insilmaril@388
  2174
insilmaril@388
  2175
	// Clicking above current step makes us undo things
insilmaril@381
  2176
	if (i<undosAvail) 
insilmaril@381
  2177
	{	
insilmaril@381
  2178
		for (int j=0; j<undosAvail-i; j++) undo();
insilmaril@381
  2179
		return;
insilmaril@381
  2180
	}	
insilmaril@388
  2181
	// Clicking below current step makes us redo things
insilmaril@381
  2182
	if (i>undosAvail) 
insilmaril@491
  2183
		for (int j=undosAvail; j<i; j++) 
insilmaril@491
  2184
		{
insilmaril@491
  2185
		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
insilmaril@491
  2186
		redo();
insilmaril@491
  2187
		}
insilmaril@381
  2188
insilmaril@381
  2189
	// And ignore clicking the current row ;-)	
insilmaril@381
  2190
}
insilmaril@381
  2191
insilmaril@394
  2192
void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
insilmaril@106
  2193
{
insilmaril@393
  2194
	QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2195
	QDir d(pathDir);
insilmaril@393
  2196
	QFile file (path);
insilmaril@163
  2197
insilmaril@106
  2198
	if (d.exists() )
insilmaril@106
  2199
	{
insilmaril@106
  2200
		// We need to parse saved XML data
insilmaril@564
  2201
		parseVYMHandler handler;
insilmaril@163
  2202
		QXmlInputSource source( file);
insilmaril@106
  2203
		QXmlSimpleReader reader;
insilmaril@106
  2204
		reader.setContentHandler( &handler );
insilmaril@106
  2205
		reader.setErrorHandler( &handler );
insilmaril@645
  2206
		handler.setModel ( model);
insilmaril@393
  2207
		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@106
  2208
		if (undoSel.isEmpty())
insilmaril@106
  2209
		{
insilmaril@139
  2210
			unselect();
insilmaril@645
  2211
			model->clear();
insilmaril@106
  2212
			handler.setLoadMode (NewMap);
insilmaril@106
  2213
		} else	
insilmaril@106
  2214
		{
insilmaril@106
  2215
			select (undoSel);
insilmaril@106
  2216
			handler.setLoadMode (ImportReplace);
insilmaril@106
  2217
		}	
insilmaril@139
  2218
		blockReposition=true;
insilmaril@106
  2219
		bool ok = reader.parse( source );
insilmaril@139
  2220
		blockReposition=false;
insilmaril@106
  2221
		if (! ok ) 
insilmaril@106
  2222
		{	
insilmaril@106
  2223
			// This should never ever happen
insilmaril@393
  2224
			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2225
								    handler.errorProtocol());
insilmaril@106
  2226
		}
insilmaril@106
  2227
	} else	
insilmaril@393
  2228
		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2229
}
insilmaril@393
  2230
insilmaril@394
  2231
void MapEditor::addMapInsertInt (const QString &path, int pos)
insilmaril@393
  2232
{
insilmaril@424
  2233
	BranchObj *sel=xelection.getBranch();
insilmaril@608
  2234
	if (sel)
insilmaril@106
  2235
	{
insilmaril@393
  2236
		QString pathDir=path.left(path.findRev("/"));
insilmaril@393
  2237
		QDir d(pathDir);
insilmaril@393
  2238
		QFile file (path);
insilmaril@393
  2239
insilmaril@393
  2240
		if (d.exists() )
insilmaril@393
  2241
		{
insilmaril@393
  2242
			// We need to parse saved XML data
insilmaril@564
  2243
			parseVYMHandler handler;
insilmaril@393
  2244
			QXmlInputSource source( file);
insilmaril@393
  2245
			QXmlSimpleReader reader;
insilmaril@393
  2246
			reader.setContentHandler( &handler );
insilmaril@393
  2247
			reader.setErrorHandler( &handler );
insilmaril@645
  2248
			handler.setModel (model);
insilmaril@393
  2249
			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
insilmaril@394
  2250
			handler.setLoadMode (ImportAdd);
insilmaril@393
  2251
			blockReposition=true;
insilmaril@393
  2252
			bool ok = reader.parse( source );
insilmaril@393
  2253
			blockReposition=false;
insilmaril@393
  2254
			if (! ok ) 
insilmaril@393
  2255
			{	
insilmaril@393
  2256
				// This should never ever happen
insilmaril@393
  2257
				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
insilmaril@393
  2258
										handler.errorProtocol());
insilmaril@393
  2259
			}
insilmaril@645
  2260
			if (sel->getDepth()>0)
insilmaril@424
  2261
				sel->getLastBranch()->linkTo (sel,pos);
insilmaril@393
  2262
		} else	
insilmaril@393
  2263
			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
insilmaril@393
  2264
	}		
insilmaril@106
  2265
}
insilmaril@106
  2266
insilmaril@502
  2267
void MapEditor::pasteNoSave(const int &n)
insilmaril@0
  2268
{
insilmaril@491
  2269
	bool old=blockSaveState;
insilmaril@491
  2270
	blockSaveState=true;
insilmaril@502
  2271
	if (redosAvail > 0 || n!=0)
insilmaril@502
  2272
	{
insilmaril@502
  2273
		// Use the "historical" buffer
insilmaril@625
  2274
		QString bakMapName(QString("history-%1").arg(n));
insilmaril@625
  2275
		QString bakMapDir(tmpMapDir +"/"+bakMapName);
insilmaril@571
  2276
		load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
insilmaril@502
  2277
	} else
insilmaril@502
  2278
		// Use the global buffer
insilmaril@571
  2279
		load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
insilmaril@491
  2280
	blockSaveState=old;
insilmaril@0
  2281
}
insilmaril@0
  2282
insilmaril@497
  2283
void MapEditor::paste()		
insilmaril@0
  2284
{   
insilmaril@424
  2285
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2286
	if (sel)
insilmaril@166
  2287
	{
insilmaril@395
  2288
		saveStateChangingPart(
insilmaril@424
  2289
			sel,
insilmaril@424
  2290
			sel,
insilmaril@502
  2291
			QString ("paste (%1)").arg(curClipboard),
insilmaril@424
  2292
			QString("Paste to %1").arg( getName(sel))
insilmaril@395
  2293
		);
insilmaril@502
  2294
		pasteNoSave(0);
insilmaril@645
  2295
		model->reposition();
insilmaril@166
  2296
	}
insilmaril@0
  2297
}
insilmaril@0
  2298
insilmaril@0
  2299
void MapEditor::cut()
insilmaril@0
  2300
{
insilmaril@424
  2301
	LinkableMapObj *sel=xelection.single();
insilmaril@491
  2302
	if ( sel && (xelection.type() == Selection::Branch ||
insilmaril@491
  2303
		xelection.type()==Selection::MapCenter ||
insilmaril@491
  2304
		xelection.type()==Selection::FloatImage))
insilmaril@424
  2305
	{
insilmaril@491
  2306
	/* No savestate! savestate is called in cutNoSave
insilmaril@424
  2307
		saveStateChangingPart(
insilmaril@424
  2308
			sel->getParObj(),
insilmaril@424
  2309
			sel,
insilmaril@424
  2310
			"cut ()",
insilmaril@424
  2311
			QString("Cut %1").arg(getName(sel ))
insilmaril@424
  2312
		);
insilmaril@491
  2313
	*/	
insilmaril@424
  2314
		copy();
insilmaril@491
  2315
		deleteSelection();
insilmaril@645
  2316
		model->reposition();
insilmaril@424
  2317
	}
insilmaril@0
  2318
}
insilmaril@0
  2319
insilmaril@537
  2320
void MapEditor::move(const double &x, const double &y)
insilmaril@130
  2321
{
insilmaril@424
  2322
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2323
	if (sel)
insilmaril@366
  2324
	{
insilmaril@625
  2325
        QPointF ap(sel->getAbsPos());
insilmaril@625
  2326
        QPointF to(x, y);
insilmaril@625
  2327
        if (ap != to)
insilmaril@625
  2328
        {
insilmaril@625
  2329
            QString ps=qpointfToString(ap);
insilmaril@625
  2330
            QString s=xelection.single()->getSelectString();
insilmaril@625
  2331
            saveState(
insilmaril@625
  2332
                s, "move "+ps, 
insilmaril@625
  2333
                s, "move "+qpointfToString(to), 
insilmaril@625
  2334
                QString("Move %1 to %2").arg(getName(sel)).arg(ps));
insilmaril@625
  2335
            sel->move(x,y);
insilmaril@645
  2336
            model->reposition();
insilmaril@625
  2337
            xelection.update();
insilmaril@625
  2338
        }
insilmaril@366
  2339
	}
insilmaril@366
  2340
}
insilmaril@366
  2341
insilmaril@537
  2342
void MapEditor::moveRel (const double &x, const double &y)
insilmaril@366
  2343
{
insilmaril@424
  2344
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2345
	if (sel)
insilmaril@366
  2346
	{
insilmaril@625
  2347
        QPointF rp(sel->getRelPos());
insilmaril@625
  2348
        QPointF to(x, y);
insilmaril@625
  2349
        if (rp != to)
insilmaril@625
  2350
        {
insilmaril@625
  2351
            QString ps=qpointfToString (sel->getRelPos());
insilmaril@625
  2352
            QString s=sel->getSelectString();
insilmaril@625
  2353
            saveState(
insilmaril@625
  2354
                s, "moveRel "+ps, 
insilmaril@625
  2355
                s, "moveRel "+qpointfToString(to), 
insilmaril@625
  2356
                QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
insilmaril@625
  2357
            ((OrnamentedObj*)sel)->move2RelPos (x,y);
insilmaril@645
  2358
            model->reposition();
insilmaril@625
  2359
            sel->updateLink();
insilmaril@625
  2360
            xelection.update();
insilmaril@625
  2361
        }
insilmaril@366
  2362
	}
insilmaril@130
  2363
}
insilmaril@130
  2364
insilmaril@0
  2365
void MapEditor::moveBranchUp()
insilmaril@0
  2366
{
insilmaril@424
  2367
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2368
	BranchObj* par;
insilmaril@424
  2369
	if (bo)
insilmaril@0
  2370
	{
insilmaril@314
  2371
		if (!bo->canMoveBranchUp()) return;
insilmaril@0
  2372
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2373
		BranchObj *obo=par->moveBranchUp (bo);	// bo will be the one below selection
insilmaril@473
  2374
		saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
insilmaril@645
  2375
		model->reposition();
insilmaril@420
  2376
		scene()->update();
insilmaril@442
  2377
		xelection.update();
insilmaril@0
  2378
		ensureSelectionVisible();
insilmaril@0
  2379
	}
insilmaril@0
  2380
}
insilmaril@0
  2381
insilmaril@0
  2382
void MapEditor::moveBranchDown()
insilmaril@0
  2383
{
insilmaril@424
  2384
	BranchObj* bo=xelection.getBranch();
insilmaril@0
  2385
	BranchObj* par;
insilmaril@424
  2386
	if (bo)
insilmaril@0
  2387
	{
insilmaril@314
  2388
		if (!bo->canMoveBranchDown()) return;
insilmaril@0
  2389
		par=(BranchObj*)(bo->getParObj());
insilmaril@473
  2390
		BranchObj *obo=par->moveBranchDown(bo);	// bo will be the one above selection
insilmaril@473
  2391
		saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
insilmaril@645
  2392
		model->reposition();
insilmaril@420
  2393
		scene()->update();
insilmaril@442
  2394
		xelection.update();
insilmaril@0
  2395
		ensureSelectionVisible();
insilmaril@0
  2396
	}	
insilmaril@0
  2397
}
insilmaril@0
  2398
insilmaril@608
  2399
void MapEditor::sortChildren()
insilmaril@608
  2400
{
insilmaril@608
  2401
	BranchObj* bo=xelection.getBranch();
insilmaril@608
  2402
	if (bo)
insilmaril@608
  2403
	{
insilmaril@608
  2404
		if(bo->countBranches()>1)
insilmaril@608
  2405
		{
insilmaril@615
  2406
			saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
insilmaril@608
  2407
			bo->sortChildren();
insilmaril@645
  2408
			model->reposition();
insilmaril@608
  2409
			ensureSelectionVisible();
insilmaril@608
  2410
		}
insilmaril@608
  2411
	}
insilmaril@608
  2412
}
insilmaril@608
  2413
insilmaril@491
  2414
void MapEditor::linkTo(const QString &dstString)	
insilmaril@420
  2415
{
insilmaril@424
  2416
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2417
	if (fio)
insilmaril@424
  2418
	{
insilmaril@645
  2419
		BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
insilmaril@424
  2420
		if (dst && (typeid(*dst)==typeid (BranchObj) || 
insilmaril@424
  2421
					typeid(*dst)==typeid (MapCenterObj)))
insilmaril@424
  2422
		{			
insilmaril@424
  2423
			LinkableMapObj *dstPar=dst->getParObj();
insilmaril@424
  2424
			QString parString=dstPar->getSelectString();
insilmaril@420
  2425
			QString fioPreSelectString=fio->getSelectString();
insilmaril@420
  2426
			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
insilmaril@420
  2427
			((BranchObj*)(dst))->addFloatImage (fio);
insilmaril@424
  2428
			xelection.unselect();
insilmaril@420
  2429
			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
insilmaril@420
  2430
			fio=((BranchObj*)(dst))->getLastFloatImage();
insilmaril@420
  2431
			fio->setRelPos();
insilmaril@420
  2432
			fio->reposition();
insilmaril@424
  2433
			xelection.select(fio);
insilmaril@420
  2434
			saveState(
insilmaril@420
  2435
				fio->getSelectString(),
insilmaril@420
  2436
				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
insilmaril@420
  2437
				fioPreSelectString, 
insilmaril@420
  2438
				QString ("linkTo (\"%1\")").arg(dstString),
insilmaril@420
  2439
				QString ("Link floatimage to %1").arg(getName(dst)));
insilmaril@424
  2440
		}
insilmaril@420
  2441
	}
insilmaril@420
  2442
}
insilmaril@420
  2443
insilmaril@366
  2444
QString MapEditor::getHeading(bool &ok, QPoint &p)
insilmaril@0
  2445
{
insilmaril@424
  2446
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2447
	if (bo)
insilmaril@366
  2448
	{
insilmaril@366
  2449
		ok=true;
insilmaril@424
  2450
		p=mapFromScene(bo->getAbsPos());
insilmaril@424
  2451
		return bo->getHeading();
insilmaril@366
  2452
	}
insilmaril@366
  2453
	ok=false;
insilmaril@366
  2454
	return QString();
insilmaril@366
  2455
}
insilmaril@366
  2456
insilmaril@366
  2457
void MapEditor::setHeading(const QString &s)
insilmaril@366
  2458
{
insilmaril@424
  2459
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  2460
	if (sel)
insilmaril@0
  2461
	{
insilmaril@395
  2462
		saveState(
insilmaril@424
  2463
			sel,
insilmaril@424
  2464
			"setHeading (\""+sel->getHeading()+"\")", 
insilmaril@424
  2465
			sel,
insilmaril@366
  2466
			"setHeading (\""+s+"\")", 
insilmaril@424
  2467
			QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
insilmaril@424
  2468
		sel->setHeading(s );
insilmaril@645
  2469
		model->reposition();
insilmaril@442
  2470
		xelection.update();
insilmaril@106
  2471
		ensureSelectionVisible();
insilmaril@106
  2472
	}
insilmaril@106
  2473
}
insilmaril@106
  2474
insilmaril@366
  2475
void MapEditor::setHeadingInt(const QString &s)
insilmaril@366
  2476
{
insilmaril@424
  2477
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2478
	if (bo)
insilmaril@366
  2479
	{
insilmaril@424
  2480
		bo->setHeading(s);
insilmaril@645
  2481
		model->reposition();
insilmaril@442
  2482
		xelection.update();
insilmaril@366
  2483
		ensureSelectionVisible();
insilmaril@366
  2484
	}
insilmaril@366
  2485
}
insilmaril@366
  2486
insilmaril@366
  2487
void MapEditor::setVymLinkInt (const QString &s)
insilmaril@143
  2488
{
insilmaril@143
  2489
	// Internal function, no saveState needed
insilmaril@424
  2490
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2491
	if (bo)
insilmaril@143
  2492
	{
insilmaril@424
  2493
		bo->setVymLink(s);
insilmaril@645
  2494
		model->reposition();
insilmaril@491
  2495
		updateActions();
insilmaril@442
  2496
		xelection.update();
insilmaril@143
  2497
		ensureSelectionVisible();
insilmaril@143
  2498
	}
insilmaril@143
  2499
}
insilmaril@143
  2500
insilmaril@366
  2501
BranchObj* MapEditor::addNewBranchInt(int num)
insilmaril@0
  2502
{
insilmaril@366
  2503
	// Depending on pos:
insilmaril@366
  2504
	// -3		insert in childs of parent  above selection 
insilmaril@366
  2505
	// -2		add branch to selection 
insilmaril@366
  2506
	// -1		insert in childs of parent below selection 
insilmaril@366
  2507
	// 0..n		insert in childs of parent at pos
insilmaril@366
  2508
	BranchObj *newbo=NULL;
insilmaril@424
  2509
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2510
	if (bo)
insilmaril@0
  2511
	{
insilmaril@366
  2512
		if (num==-2)
insilmaril@0
  2513
		{
insilmaril@0
  2514
			// save scroll state. If scrolled, automatically select
insilmaril@0
  2515
			// new branch in order to tmp unscroll parent...
insilmaril@537
  2516
			newbo=bo->addBranch();
insilmaril@366
  2517
			
insilmaril@366
  2518
		}else if (num==-1)
insilmaril@0
  2519
		{
insilmaril@366
  2520
			num=bo->getNum()+1;
insilmaril@366
  2521
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2522
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2523
		}else if (num==-3)
insilmaril@366
  2524
		{
insilmaril@366
  2525
			num=bo->getNum();
insilmaril@366
  2526
			bo=(BranchObj*)bo->getParObj();
insilmaril@537
  2527
			if (bo) newbo=bo->insertBranch(num);
insilmaril@366
  2528
		}
insilmaril@537
  2529
		if (!newbo) return NULL;
insilmaril@366
  2530
	}	
insilmaril@366
  2531
	return newbo;
insilmaril@366
  2532
}	
insilmaril@366
  2533
insilmaril@394
  2534
BranchObj* MapEditor::addNewBranch(int pos)
insilmaril@366
  2535
{
insilmaril@366
  2536
	// Different meaning than num in addNewBranchInt!
insilmaril@366
  2537
	// -1	add above
insilmaril@366
  2538
	//  0	add as child
insilmaril@366
  2539
	// +1	add below
insilmaril@424
  2540
	BranchObj *bo = xelection.getBranch();
insilmaril@394
  2541
	BranchObj *newbo=NULL;
insilmaril@394
  2542
insilmaril@424
  2543
	if (bo)
insilmaril@366
  2544
	{
insilmaril@421
  2545
		setCursor (Qt::ArrowCursor);
insilmaril@421
  2546
insilmaril@366
  2547
		newbo=addNewBranchInt (pos-2);
insilmaril@366
  2548
insilmaril@366
  2549
		if (newbo)
insilmaril@366
  2550
		{
insilmaril@395
  2551
			saveState(
insilmaril@417
  2552
				newbo,		
insilmaril@393
  2553
				"delete ()",
insilmaril@424
  2554
				bo,
insilmaril@537
  2555
				QString ("addBranch (%1)").arg(pos),
insilmaril@395
  2556
				QString ("Add new branch to %1").arg(getName(bo)));	
insilmaril@366
  2557
insilmaril@645
  2558
			model->reposition();
insilmaril@537
  2559
			xelection.update();
insilmaril@537
  2560
			latestSelection=newbo->getSelectString();
insilmaril@531
  2561
			// In Network mode, the client needs to know where the new branch is,
insilmaril@531
  2562
			// so we have to pass on this information via saveState.
insilmaril@531
  2563
			// TODO: Get rid of this positioning workaround
insilmaril@531
  2564
			QString ps=qpointfToString (newbo->getAbsPos());
insilmaril@537
  2565
			sendData ("selectLatestAdded ()");
insilmaril@534
  2566
			sendData (QString("move %1").arg(ps));
insilmaril@534
  2567
			sendSelection();
insilmaril@366
  2568
		}
insilmaril@366
  2569
	}	
insilmaril@394
  2570
	return newbo;
insilmaril@366
  2571
}
insilmaril@366
  2572
insilmaril@366
  2573
insilmaril@394
  2574
BranchObj* MapEditor::addNewBranchBefore()
insilmaril@366
  2575
{
insilmaril@394
  2576
	BranchObj *newbo=NULL;
insilmaril@424
  2577
	BranchObj *bo = xelection.getBranch();
insilmaril@491
  2578
	if (bo && xelection.type()==Selection::Branch)
insilmaril@394
  2579
		 // We accept no MapCenterObj here, so we _have_ a parent
insilmaril@366
  2580
	{
insilmaril@408
  2581
		QPointF p=bo->getRelPos();
insilmaril@394
  2582
insilmaril@394
  2583
insilmaril@424
  2584
		BranchObj *parbo=(BranchObj*)(bo->getParObj());
insilmaril@394
  2585
insilmaril@394
  2586
		// add below selection
insilmaril@394
  2587
		newbo=parbo->insertBranch(bo->getNum()+1);
insilmaril@394
  2588
		if (newbo)
insilmaril@366
  2589
		{
insilmaril@394
  2590
			newbo->move2RelPos (p);
insilmaril@394
  2591
insilmaril@394
  2592
			// Move selection to new branch
insilmaril@424
  2593
			bo->linkTo (newbo,-1);
insilmaril@394
  2594
insilmaril@394
  2595
			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
insilmaril@394
  2596
				QString ("Add branch before %1").arg(getName(bo)));
insilmaril@394
  2597
insilmaril@645
  2598
			model->reposition();
insilmaril@442
  2599
			xelection.update();
insilmaril@394
  2600
		}
insilmaril@0
  2601
	}	
insilmaril@537
  2602
	latestSelection=xelection.getSelectString();
insilmaril@394
  2603
	return newbo;
insilmaril@0
  2604
}
insilmaril@0
  2605
insilmaril@0
  2606
void MapEditor::deleteSelection()
insilmaril@0
  2607
{
insilmaril@424
  2608
	BranchObj *bo = xelection.getBranch();
insilmaril@645
  2609
	if (bo && xelection.type()==Selection::MapCenter)
insilmaril@645
  2610
	{
insilmaril@645
  2611
	//	BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@645
  2612
		xelection.unselect();
insilmaril@645
  2613
	/* FIXME Note:  does saveStateRemovingPart work for MCO? (No parent!)
insilmaril@645
  2614
		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
insilmaril@645
  2615
		*/
insilmaril@645
  2616
		bo=model->removeMapCenter ((MapCenterObj*)bo);
insilmaril@645
  2617
		if (bo) 
insilmaril@645
  2618
		{
insilmaril@645
  2619
			xelection.select (bo);
insilmaril@645
  2620
			ensureSelectionVisible();
insilmaril@645
  2621
			xelection.update();
insilmaril@645
  2622
		}	
insilmaril@645
  2623
		model->reposition();
insilmaril@645
  2624
		return;
insilmaril@645
  2625
	}
insilmaril@491
  2626
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2627
	{
insilmaril@294
  2628
		BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@424
  2629
		xelection.unselect();
insilmaril@394
  2630
		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
insilmaril@0
  2631
		par->removeBranch(bo);
insilmaril@424
  2632
		xelection.select (par);
insilmaril@0
  2633
		ensureSelectionVisible();
insilmaril@645
  2634
		model->reposition();
insilmaril@442
  2635
		xelection.update();
insilmaril@442
  2636
		xelection.update();
insilmaril@424
  2637
		return;
insilmaril@0
  2638
	}
insilmaril@424
  2639
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  2640
	if (fio)
insilmaril@0
  2641
	{
insilmaril@0
  2642
		BranchObj* par=(BranchObj*)(fio->getParObj());
insilmaril@395
  2643
		saveStateChangingPart(
insilmaril@395
  2644
			par, 
insilmaril@395
  2645
			fio,
insilmaril@395
  2646
			"delete ()",
insilmaril@395
  2647
			QString("Delete %1").arg(getName(fio))
insilmaril@395
  2648
		);
insilmaril@424
  2649
		xelection.unselect();
insilmaril@0
  2650
		par->removeFloatImage(fio);
insilmaril@424
  2651
		xelection.select (par);
insilmaril@645
  2652
		model->reposition();
insilmaril@442
  2653
		xelection.update();
insilmaril@0
  2654
		ensureSelectionVisible();
insilmaril@424
  2655
		return;
insilmaril@0
  2656
	}
insilmaril@0
  2657
}
insilmaril@0
  2658
insilmaril@0
  2659
LinkableMapObj* MapEditor::getSelection()
insilmaril@0
  2660
{
insilmaril@424
  2661
	return xelection.single();
insilmaril@0
  2662
}
insilmaril@0
  2663
insilmaril@442
  2664
BranchObj* MapEditor::getSelectedBranch()
insilmaril@442
  2665
{
insilmaril@442
  2666
	return xelection.getBranch();
insilmaril@442
  2667
}
insilmaril@442
  2668
insilmaril@442
  2669
FloatImageObj* MapEditor::getSelectedFloatImage()
insilmaril@442
  2670
{
insilmaril@442
  2671
	return xelection.getFloatImage();
insilmaril@442
  2672
}
insilmaril@442
  2673
insilmaril@267
  2674
void MapEditor::unselect()
insilmaril@267
  2675
{
insilmaril@424
  2676
	xelection.unselect();
insilmaril@267
  2677
}	
insilmaril@267
  2678
insilmaril@267
  2679
void MapEditor::reselect()
insilmaril@267
  2680
{
insilmaril@424
  2681
	xelection.reselect();
insilmaril@267
  2682
}	
insilmaril@267
  2683
insilmaril@83
  2684
bool MapEditor::select (const QString &s)
insilmaril@83
  2685
{
insilmaril@652
  2686
	if (xelection.select(s))
insilmaril@0
  2687
	{
insilmaril@442
  2688
		xelection.update();
insilmaril@0
  2689
		ensureSelectionVisible();
insilmaril@528
  2690
		sendSelection ();
insilmaril@0
  2691
		return true;
insilmaril@652
  2692
	}
insilmaril@139
  2693
	return false;
insilmaril@0
  2694
}
insilmaril@0
  2695
insilmaril@366
  2696
QString MapEditor::getSelectString()
insilmaril@366
  2697
{
insilmaril@424
  2698
	return xelection.getSelectString();
insilmaril@366
  2699
}
insilmaril@366
  2700
insilmaril@366
  2701
void MapEditor::selectInt (LinkableMapObj *lmo)
insilmaril@0
  2702
{
insilmaril@491
  2703
	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
insilmaril@442
  2704
	{
insilmaril@424
  2705
		xelection.select(lmo);
insilmaril@442
  2706
		xelection.update();
insilmaril@528
  2707
		sendSelection ();
insilmaril@442
  2708
	}	
insilmaril@267
  2709
}
insilmaril@0
  2710
insilmaril@366
  2711
void MapEditor::selectNextBranchInt()
insilmaril@0
  2712
{
insilmaril@0
  2713
	// Increase number of branch
insilmaril@424
  2714
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2715
	if (sel)
insilmaril@0
  2716
	{
insilmaril@424
  2717
		QString s=sel->getSelectString();
insilmaril@0
  2718
		QString part;
insilmaril@0
  2719
		QString typ;
insilmaril@0
  2720
		QString num;
insilmaril@0
  2721
insilmaril@0
  2722
		// Where am I? 
insilmaril@0
  2723
		part=s.section(",",-1);
insilmaril@0
  2724
		typ=part.left (3);
insilmaril@0
  2725
		num=part.right(part.length() - 3);
insilmaril@0
  2726
insilmaril@0
  2727
		s=s.left (s.length() -num.length());
insilmaril@0
  2728
insilmaril@0
  2729
		// Go to next lmo
insilmaril@0
  2730
		num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2731
insilmaril@0
  2732
		s=s+num;
insilmaril@0
  2733
		
insilmaril@0
  2734
		// Try to select this one
insilmaril@0
  2735
		if (select (s)) return;
insilmaril@0
  2736
insilmaril@0
  2737
		// We have no direct successor, 
insilmaril@0
  2738
		// try to increase the parental number in order to
insilmaril@0
  2739
		// find a successor with same depth
insilmaril@0
  2740
insilmaril@424
  2741
		int d=xelection.single()->getDepth();
insilmaril@0
  2742
		int oldDepth=d;
insilmaril@0
  2743
		int i;
insilmaril@0
  2744
		bool found=false;
insilmaril@0
  2745
		bool b;
insilmaril@0
  2746
		while (!found && d>0)
insilmaril@0
  2747
		{
insilmaril@0
  2748
			s=s.section (",",0,d-1);
insilmaril@0
  2749
			// replace substring of current depth in s with "1"
insilmaril@0
  2750
			part=s.section(",",-1);
insilmaril@0
  2751
			typ=part.left (3);
insilmaril@0
  2752
			num=part.right(part.length() - 3);
insilmaril@0
  2753
insilmaril@0
  2754
			if (d>1)
insilmaril@0
  2755
			{	
insilmaril@0
  2756
				// increase number of parent
insilmaril@0
  2757
				num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2758
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2759
			} else
insilmaril@0
  2760
			{
insilmaril@0
  2761
				// Special case, look at orientation
insilmaril@473
  2762
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2763
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  2764
				else	
insilmaril@0
  2765
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  2766
				s=typ+num;
insilmaril@0
  2767
			}	
insilmaril@0
  2768
insilmaril@0
  2769
			if (select (s))
insilmaril@0
  2770
				// pad to oldDepth, select the first branch for each depth
insilmaril@0
  2771
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2772
				{
insilmaril@0
  2773
					b=select (s);
insilmaril@0
  2774
					if (b)
insilmaril@0
  2775
					{	
insilmaril@424
  2776
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@0
  2777
							s+=",bo:0";
insilmaril@0
  2778
						else	
insilmaril@0
  2779
							break;
insilmaril@0
  2780
					} else
insilmaril@0
  2781
						break;
insilmaril@0
  2782
				}	
insilmaril@0
  2783
insilmaril@0
  2784
			// try to select the freshly built string
insilmaril@0
  2785
			found=select(s);
insilmaril@0
  2786
			d--;
insilmaril@0
  2787
		}
insilmaril@0
  2788
		return;
insilmaril@0
  2789
	}	
insilmaril@0
  2790
}
insilmaril@0
  2791
insilmaril@366
  2792
void MapEditor::selectPrevBranchInt()
insilmaril@0
  2793
{
insilmaril@0
  2794
	// Decrease number of branch
insilmaril@424
  2795
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  2796
	if (bo)
insilmaril@0
  2797
	{
insilmaril@424
  2798
		QString s=bo->getSelectString();
insilmaril@0
  2799
		QString part;
insilmaril@0
  2800
		QString typ;
insilmaril@0
  2801
		QString num;
insilmaril@0
  2802
insilmaril@0
  2803
		// Where am I? 
insilmaril@0
  2804
		part=s.section(",",-1);
insilmaril@0
  2805
		typ=part.left (3);
insilmaril@0
  2806
		num=part.right(part.length() - 3);
insilmaril@0
  2807
insilmaril@0
  2808
		s=s.left (s.length() -num.length());
insilmaril@0
  2809
insilmaril@411
  2810
		int n=num.toInt()-1;
insilmaril@411
  2811
		
insilmaril@0
  2812
		// Go to next lmo
insilmaril@411
  2813
		num=QString ("%1").arg(n);
insilmaril@0
  2814
		s=s+num;
insilmaril@0
  2815
		
insilmaril@0
  2816
		// Try to select this one
insilmaril@411
  2817
		if (n>=0 && select (s)) return;
insilmaril@0
  2818
insilmaril@0
  2819
		// We have no direct precessor, 
insilmaril@0
  2820
		// try to decrease the parental number in order to
insilmaril@0
  2821
		// find a precessor with same depth
insilmaril@0
  2822
insilmaril@424
  2823
		int d=xelection.single()->getDepth();
insilmaril@0
  2824
		int oldDepth=d;
insilmaril@0
  2825
		int i;
insilmaril@0
  2826
		bool found=false;
insilmaril@0
  2827
		bool b;
insilmaril@0
  2828
		while (!found && d>0)
insilmaril@0
  2829
		{
insilmaril@0
  2830
			s=s.section (",",0,d-1);
insilmaril@0
  2831
			// replace substring of current depth in s with "1"
insilmaril@0
  2832
			part=s.section(",",-1);
insilmaril@0
  2833
			typ=part.left (3);
insilmaril@0
  2834
			num=part.right(part.length() - 3);
insilmaril@0
  2835
insilmaril@0
  2836
			if (d>1)
insilmaril@0
  2837
			{
insilmaril@0
  2838
				// decrease number of parent
insilmaril@411
  2839
				num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2840
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  2841
			} else
insilmaril@0
  2842
			{
insilmaril@0
  2843
				// Special case, look at orientation
insilmaril@473
  2844
				if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@411
  2845
					num=QString ("%1").arg(num.toInt()-1);
insilmaril@0
  2846
				else	
insilmaril@411
  2847
					num=QString ("%1").arg(num.toInt()+1);
insilmaril@0
  2848
				s=typ+num;
insilmaril@0
  2849
			}	
insilmaril@0
  2850
insilmaril@0
  2851
			if (select(s))
insilmaril@0
  2852
				// pad to oldDepth, select the last branch for each depth
insilmaril@0
  2853
				for (i=d;i<oldDepth;i++)
insilmaril@0
  2854
				{
insilmaril@0
  2855
					b=select (s);
insilmaril@0
  2856
					if (b)
insilmaril@424
  2857
						if ( xelection.getBranch()->countBranches()>0)
insilmaril@424
  2858
							s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
insilmaril@0
  2859
						else	
insilmaril@0
  2860
							break;
insilmaril@0
  2861
					else
insilmaril@0
  2862
						break;
insilmaril@0
  2863
				}	
insilmaril@0
  2864
			
insilmaril@0
  2865
			// try to select the freshly built string
insilmaril@0
  2866
			found=select(s);
insilmaril@0
  2867
			d--;
insilmaril@0
  2868
		}
insilmaril@0
  2869
		return;
insilmaril@0
  2870
	}	
insilmaril@0
  2871
}
insilmaril@0
  2872
insilmaril@0
  2873
void MapEditor::selectUpperBranch()
insilmaril@0
  2874
{
insilmaril@491
  2875
	if (isSelectBlocked() ) return;
insilmaril@491
  2876
insilmaril@424
  2877
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2878
	if (bo && xelection.type()==Selection::Branch)
insilmaril@0
  2879
	{
insilmaril@473
  2880
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2881
			selectPrevBranchInt();
insilmaril@424
  2882
		else
insilmaril@424
  2883
			if (bo->getDepth()==1)
insilmaril@424
  2884
				selectNextBranchInt();
insilmaril@424
  2885
			else
insilmaril@424
  2886
				selectPrevBranchInt();
insilmaril@424
  2887
	}
insilmaril@424
  2888
}
insilmaril@424
  2889
insilmaril@424
  2890
void MapEditor::selectLowerBranch()
insilmaril@424
  2891
{
insilmaril@491
  2892
	if (isSelectBlocked() ) return;
insilmaril@491
  2893
insilmaril@424
  2894
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  2895
	if (bo && xelection.type()==Selection::Branch)
insilmaril@473
  2896
		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2897
			selectNextBranchInt();
insilmaril@424
  2898
		else
insilmaril@424
  2899
			if (bo->getDepth()==1)
insilmaril@366
  2900
				selectPrevBranchInt();
insilmaril@0
  2901
			else
insilmaril@366
  2902
				selectNextBranchInt();
insilmaril@0
  2903
}
insilmaril@0
  2904
insilmaril@0
  2905
insilmaril@0
  2906
void MapEditor::selectLeftBranch()
insilmaril@0
  2907
{
insilmaril@491
  2908
	if (isSelectBlocked() ) return;
insilmaril@491
  2909
insilmaril@0
  2910
	BranchObj* bo;
insilmaril@0
  2911
	BranchObj* par;
insilmaril@424
  2912
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2913
	if (sel)
insilmaril@0
  2914
	{
insilmaril@491
  2915
		if (xelection.type()== Selection::MapCenter)
insilmaril@0
  2916
		{
insilmaril@424
  2917
			par=xelection.getBranch();
insilmaril@0
  2918
			bo=par->getLastSelectedBranch();
insilmaril@0
  2919
			if (bo)
insilmaril@0
  2920
			{
insilmaril@0
  2921
				// Workaround for reselecting on left and right side
insilmaril@473
  2922
				if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@424
  2923
					bo=par->getLastBranch();
insilmaril@424
  2924
				if (bo)
insilmaril@0
  2925
				{
insilmaril@0
  2926
					bo=par->getLastBranch();
insilmaril@424
  2927
					xelection.select(bo);
insilmaril@442
  2928
					xelection.update();
insilmaril@0
  2929
					ensureSelectionVisible();
insilmaril@528
  2930
					sendSelection();
insilmaril@0
  2931
				}
insilmaril@0
  2932
			}	
insilmaril@0
  2933
		} else
insilmaril@0
  2934
		{
insilmaril@424
  2935
			par=(BranchObj*)(sel->getParObj());
insilmaril@473
  2936
			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
insilmaril@0
  2937
			{
insilmaril@491
  2938
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2939
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2940
				{
insilmaril@424
  2941
					xelection.select(par);
insilmaril@442
  2942
					xelection.update();
insilmaril@0
  2943
					ensureSelectionVisible();
insilmaril@528
  2944
					sendSelection();
insilmaril@0
  2945
				}
insilmaril@0
  2946
			} else
insilmaril@0
  2947
			{
insilmaril@491
  2948
				if (xelection.type() == Selection::Branch )
insilmaril@0
  2949
				{
insilmaril@424
  2950
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  2951
					if (bo) 
insilmaril@0
  2952
					{
insilmaril@424
  2953
						xelection.select(bo);
insilmaril@442
  2954
						xelection.update();
insilmaril@0
  2955
						ensureSelectionVisible();
insilmaril@528
  2956
					sendSelection();
insilmaril@0
  2957
					}
insilmaril@0
  2958
				}
insilmaril@0
  2959
			}
insilmaril@0
  2960
		}	
insilmaril@0
  2961
	}
insilmaril@0
  2962
}
insilmaril@0
  2963
insilmaril@0
  2964
void MapEditor::selectRightBranch()
insilmaril@0
  2965
{
insilmaril@491
  2966
	if (isSelectBlocked() ) return;
insilmaril@491
  2967
insilmaril@0
  2968
	BranchObj* bo;
insilmaril@0
  2969
	BranchObj* par;
insilmaril@424
  2970
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  2971
	if (sel)
insilmaril@0
  2972
	{
insilmaril@491
  2973
		if (xelection.type()==Selection::MapCenter) 
insilmaril@0
  2974
		{
insilmaril@424
  2975
			par=xelection.getBranch();
insilmaril@0
  2976
			bo=par->getLastSelectedBranch();
insilmaril@0
  2977
			if (bo)
insilmaril@0
  2978
			{
insilmaril@366
  2979
				// Workaround for reselecting on left and right side
insilmaril@473
  2980
				if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2981
					bo=par->getFirstBranch();
insilmaril@0
  2982
				if (bo)
insilmaril@0
  2983
				{
insilmaril@424
  2984
					xelection.select(bo);
insilmaril@442
  2985
					xelection.update();
insilmaril@0
  2986
					ensureSelectionVisible();
insilmaril@528
  2987
					sendSelection();
insilmaril@0
  2988
				}
insilmaril@0
  2989
			}
insilmaril@0
  2990
		} else
insilmaril@0
  2991
		{
insilmaril@424
  2992
			par=(BranchObj*)(xelection.single()->getParObj());
insilmaril@473
  2993
			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@0
  2994
			{
insilmaril@491
  2995
				if (xelection.type() == Selection::Branch ||
insilmaril@491
  2996
					xelection.type() == Selection::FloatImage)
insilmaril@0
  2997
				{
insilmaril@424
  2998
					xelection.select(par);
insilmaril@442
  2999
					xelection.update();
insilmaril@0
  3000
					ensureSelectionVisible();
insilmaril@528
  3001
					sendSelection();
insilmaril@0
  3002
				}
insilmaril@0
  3003
			} else
insilmaril@0
  3004
			{
insilmaril@491
  3005
				if (xelection.type()  == Selection::Branch) 
insilmaril@0
  3006
				{
insilmaril@424
  3007
					bo=xelection.getBranch()->getLastSelectedBranch();
insilmaril@0
  3008
					if (bo) 
insilmaril@0
  3009
					{
insilmaril@424
  3010
						xelection.select(bo);
insilmaril@442
  3011
						xelection.update();
insilmaril@0
  3012
						ensureSelectionVisible();
insilmaril@528
  3013
					sendSelection();
insilmaril@0
  3014
					}
insilmaril@0
  3015
				}
insilmaril@0
  3016
			}
insilmaril@0
  3017
		}
insilmaril@0
  3018
	}
insilmaril@0
  3019
}
insilmaril@0
  3020
insilmaril@0
  3021
void MapEditor::selectFirstBranch()
insilmaril@0
  3022
{
insilmaril@424
  3023
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  3024
	BranchObj *bo2;
insilmaril@0
  3025
	BranchObj* par;
insilmaril@424
  3026
	if (bo1)
insilmaril@424
  3027
	{
insilmaril@424
  3028
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  3029
		bo2=par->getFirstBranch();
insilmaril@424
  3030
		if (bo2) {
insilmaril@424
  3031
			xelection.select(bo2);
insilmaril@442
  3032
			xelection.update();
insilmaril@424
  3033
			ensureSelectionVisible();
insilmaril@528
  3034
			sendSelection();
insilmaril@424
  3035
		}
insilmaril@424
  3036
	}		
insilmaril@0
  3037
}
insilmaril@0
  3038
insilmaril@0
  3039
void MapEditor::selectLastBranch()
insilmaril@0
  3040
{
insilmaril@424
  3041
	BranchObj *bo1=xelection.getBranch();
insilmaril@0
  3042
	BranchObj *bo2;
insilmaril@0
  3043
	BranchObj* par;
insilmaril@424
  3044
	if (bo1)
insilmaril@424
  3045
	{
insilmaril@424
  3046
		par=(BranchObj*)(bo1->getParObj());
insilmaril@424
  3047
		bo2=par->getLastBranch();
insilmaril@424
  3048
		if (bo2) 
insilmaril@0
  3049
		{
insilmaril@424
  3050
			xelection.select(bo2);
insilmaril@442
  3051
			xelection.update();
insilmaril@424
  3052
			ensureSelectionVisible();
insilmaril@528
  3053
			sendSelection();
insilmaril@424
  3054
		}
insilmaril@424
  3055
	}		
insilmaril@0
  3056
}
insilmaril@0
  3057
insilmaril@408
  3058
void MapEditor::selectMapBackgroundImage ()
insilmaril@408
  3059
{
insilmaril@408
  3060
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@408
  3061
	fd->setMode (Q3FileDialog::ExistingFile);
insilmaril@408
  3062
	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@408
  3063
	ImagePreview *p =new ImagePreview (fd);
insilmaril@408
  3064
	fd->setContentsPreviewEnabled( TRUE );
insilmaril@408
  3065
	fd->setContentsPreview( p, p );
insilmaril@408
  3066
	fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@408
  3067
	fd->setCaption(vymName+" - " +tr("Load background image"));
insilmaril@408
  3068
	fd->setDir (lastImageDir);
insilmaril@408
  3069
	fd->show();
insilmaril@408
  3070
insilmaril@408
  3071
	if ( fd->exec() == QDialog::Accepted )
insilmaril@408
  3072
	{
insilmaril@412
  3073
		// TODO selectMapBackgroundImg in QT4 use:	lastImageDir=fd->directory();
insilmaril@408
  3074
		lastImageDir=QDir (fd->dirPath());
insilmaril@408
  3075
		setMapBackgroundImage (fd->selectedFile());
insilmaril@408
  3076
	}
insilmaril@408
  3077
}	
insilmaril@408
  3078
insilmaril@442
  3079
void MapEditor::setMapBackgroundImage (const QString &fn)	//FIXME missing savestate
insilmaril@408
  3080
{
insilmaril@408
  3081
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@408
  3082
	/*
insilmaril@408
  3083
	saveState(
insilmaril@408
  3084
		selection,
insilmaril@408
  3085
		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
insilmaril@408
  3086
		selection,
insilmaril@408
  3087
		QString ("setMapBackgroundImage (%1)").arg(col.name()),
insilmaril@408
  3088
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  3089
	*/	
insilmaril@408
  3090
	QBrush brush;
insilmaril@408
  3091
	brush.setTextureImage (QPixmap (fn));
insilmaril@408
  3092
	mapScene->setBackgroundBrush(brush);
insilmaril@408
  3093
}
insilmaril@408
  3094
insilmaril@398
  3095
void MapEditor::selectMapBackgroundColor()
insilmaril@0
  3096
{
insilmaril@408
  3097
	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
insilmaril@0
  3098
	if ( !col.isValid() ) return;
insilmaril@408
  3099
	setMapBackgroundColor( col );
insilmaril@0
  3100
}
insilmaril@0
  3101
insilmaril@398
  3102
insilmaril@398
  3103
void MapEditor::setMapBackgroundColor(QColor col)
insilmaril@0
  3104
{
insilmaril@408
  3105
	QColor oldcol=mapScene->backgroundBrush().color();
insilmaril@398
  3106
	saveState(
insilmaril@445
  3107
		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
insilmaril@445
  3108
		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
insilmaril@398
  3109
		QString("Set background color of map to %1").arg(col.name()));
insilmaril@408
  3110
	mapScene->setBackgroundBrush(col);
insilmaril@398
  3111
}
insilmaril@398
  3112
insilmaril@398
  3113
QColor MapEditor::getMapBackgroundColor()
insilmaril@398
  3114
{
insilmaril@408
  3115
    return mapScene->backgroundBrush().color();
insilmaril@0
  3116
}
insilmaril@0
  3117
insilmaril@395
  3118
QColor MapEditor::getCurrentHeadingColor()
insilmaril@0
  3119
{
insilmaril@424
  3120
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3121
	if (bo) return bo->getColor(); 
insilmaril@395
  3122
	
insilmaril@395
  3123
	QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
insilmaril@395
  3124
	return Qt::black;
insilmaril@0
  3125
}
insilmaril@0
  3126
insilmaril@417
  3127
void MapEditor::colorBranch (QColor c)
insilmaril@0
  3128
{
insilmaril@424
  3129
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3130
	if (bo)
insilmaril@0
  3131
	{
insilmaril@424
  3132
		saveState(
insilmaril@424
  3133
			bo, 
insilmaril@445
  3134
			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
insilmaril@424
  3135
			bo,
insilmaril@445
  3136
			QString ("colorBranch (\"%1\")").arg(c.name()),
insilmaril@424
  3137
			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3138
		);	
insilmaril@424
  3139
		bo->setColor(c); // color branch
insilmaril@0
  3140
	}
insilmaril@0
  3141
}
insilmaril@0
  3142
insilmaril@417
  3143
void MapEditor::colorSubtree (QColor c)
insilmaril@0
  3144
{
insilmaril@424
  3145
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3146
	if (bo) 
insilmaril@0
  3147
	{
insilmaril@424
  3148
		saveStateChangingPart(
insilmaril@424
  3149
			bo, 
insilmaril@424
  3150
			bo,
insilmaril@445
  3151
			QString ("colorSubtree (\"%1\")").arg(c.name()),
insilmaril@424
  3152
			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
insilmaril@424
  3153
		);	
insilmaril@424
  3154
		bo->setColorSubtree (c); // color links, color childs
insilmaril@0
  3155
	}
insilmaril@0
  3156
}
insilmaril@0
  3157
insilmaril@0
  3158
insilmaril@0
  3159
void MapEditor::toggleStandardFlag(QString f)
insilmaril@0
  3160
{
insilmaril@424
  3161
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3162
	if (bo) 
insilmaril@0
  3163
	{
insilmaril@424
  3164
		QString u,r;
insilmaril@424
  3165
		if (bo->isSetStandardFlag(f))
insilmaril@366
  3166
		{
insilmaril@424
  3167
			r="unsetFlag";
insilmaril@424
  3168
			u="setFlag";
insilmaril@424
  3169
		}	
insilmaril@424
  3170
		else
insilmaril@424
  3171
		{
insilmaril@424
  3172
			u="unsetFlag";
insilmaril@424
  3173
			r="setFlag";
insilmaril@424
  3174
		}	
insilmaril@424
  3175
		saveState(
insilmaril@424
  3176
			bo,
insilmaril@424
  3177
			QString("%1 (\"%2\")").arg(u).arg(f), 
insilmaril@424
  3178
			bo,
insilmaril@424
  3179
			QString("%1 (\"%2\")").arg(r).arg(f),
insilmaril@424
  3180
			QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
insilmaril@424
  3181
		bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
insilmaril@442
  3182
		xelection.update();
insilmaril@424
  3183
	}
insilmaril@0
  3184
}
insilmaril@0
  3185
insilmaril@0
  3186
insilmaril@0
  3187
BranchObj* MapEditor::findText (QString s, bool cs)
insilmaril@0
  3188
{
insilmaril@366
  3189
	QTextDocument::FindFlags flags=0;
insilmaril@366
  3190
	if (cs) flags=QTextDocument::FindCaseSensitively;
insilmaril@366
  3191
insilmaril@0
  3192
	if (!itFind) 
insilmaril@0
  3193
	{	// Nothing found or new find process
insilmaril@0
  3194
		if (EOFind)
insilmaril@0
  3195
			// nothing found, start again
insilmaril@0
  3196
			EOFind=false;
insilmaril@645
  3197
		itFind=model->first();
insilmaril@0
  3198
	}	
insilmaril@0
  3199
	bool searching=true;
insilmaril@0
  3200
	bool foundNote=false;
insilmaril@0
  3201
	while (searching && !EOFind)
insilmaril@0
  3202
	{
insilmaril@0
  3203
		if (itFind)
insilmaril@0
  3204
		{
insilmaril@0
  3205
			// Searching in Note
insilmaril@0
  3206
			if (itFind->getNote().contains(s,cs))
insilmaril@0
  3207
			{
insilmaril@424
  3208
				if (xelection.single()!=itFind) 
insilmaril@0
  3209
				{
insilmaril@424
  3210
					xelection.select(itFind);
insilmaril@0
  3211
					ensureSelectionVisible();
insilmaril@0
  3212
				}
insilmaril@366
  3213
				if (textEditor->findText(s,flags)) 
insilmaril@0
  3214
				{
insilmaril@0
  3215
					searching=false;
insilmaril@0
  3216
					foundNote=true;
insilmaril@0
  3217
				}	
insilmaril@0
  3218
			}
insilmaril@0
  3219
			// Searching in Heading
insilmaril@0
  3220
			if (searching && itFind->getHeading().contains (s,cs) ) 
insilmaril@0
  3221
			{
insilmaril@424
  3222
				xelection.select(itFind);
insilmaril@0
  3223
				ensureSelectionVisible();
insilmaril@0
  3224
				searching=false;
insilmaril@0
  3225
			}
insilmaril@0
  3226
		}	
insilmaril@0
  3227
		if (!foundNote)
insilmaril@0
  3228
		{
insilmaril@645
  3229
			itFind=model->next(itFind);
insilmaril@0
  3230
			if (!itFind) EOFind=true;
insilmaril@0
  3231
		}
insilmaril@0
  3232
	}	
insilmaril@0
  3233
	if (!searching)
insilmaril@424
  3234
		return xelection.getBranch();
insilmaril@424
  3235
	else
insilmaril@0
  3236
		return NULL;
insilmaril@0
  3237
}
insilmaril@0
  3238
insilmaril@0
  3239
void MapEditor::findReset()
insilmaril@0
  3240
{	// Necessary if text to find changes during a find process
insilmaril@0
  3241
	itFind=NULL;
insilmaril@0
  3242
	EOFind=false;
insilmaril@0
  3243
}
insilmaril@395
  3244
void MapEditor::setURL(const QString &url)
insilmaril@395
  3245
{
insilmaril@424
  3246
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3247
	if (bo)
insilmaril@424
  3248
	{
insilmaril@395
  3249
		QString oldurl=bo->getURL();
insilmaril@395
  3250
		bo->setURL (url);
insilmaril@395
  3251
		saveState (
insilmaril@424
  3252
			bo,
insilmaril@395
  3253
			QString ("setURL (\"%1\")").arg(oldurl),
insilmaril@424
  3254
			bo,
insilmaril@395
  3255
			QString ("setURL (\"%1\")").arg(url),
insilmaril@395
  3256
			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
insilmaril@395
  3257
		);
insilmaril@395
  3258
		updateActions();
insilmaril@645
  3259
		model->reposition();
insilmaril@491
  3260
		xelection.update();
insilmaril@491
  3261
		ensureSelectionVisible();
insilmaril@395
  3262
	}
insilmaril@395
  3263
}	
insilmaril@0
  3264
insilmaril@0
  3265
void MapEditor::editURL()
insilmaril@0
  3266
{
insilmaril@424
  3267
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3268
	if (bo)
insilmaril@0
  3269
	{		
insilmaril@0
  3270
		bool ok;
insilmaril@0
  3271
		QString text = QInputDialog::getText(
insilmaril@0
  3272
				"VYM", tr("Enter URL:"), QLineEdit::Normal,
insilmaril@143
  3273
				bo->getURL(), &ok, this );
insilmaril@0
  3274
		if ( ok) 
insilmaril@0
  3275
			// user entered something and pressed OK
insilmaril@395
  3276
			setURL (text);
insilmaril@0
  3277
	}
insilmaril@0
  3278
}
insilmaril@0
  3279
insilmaril@528
  3280
void MapEditor::editLocalURL()
insilmaril@528
  3281
{
insilmaril@528
  3282
	BranchObj *bo=xelection.getBranch();
insilmaril@528
  3283
	if (bo)
insilmaril@528
  3284
	{		
insilmaril@528
  3285
		QStringList filters;
insilmaril@528
  3286
		filters <<"All files (*)";
insilmaril@528
  3287
		filters << tr("Text","Filedialog") + " (*.txt)";
insilmaril@528
  3288
		filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
insilmaril@528
  3289
		filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
insilmaril@528
  3290
		filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
insilmaril@528
  3291
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3292
		fd->setFilters (filters);
insilmaril@528
  3293
		fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
insilmaril@528
  3294
		fd->setDirectory (lastFileDir);
insilmaril@528
  3295
		if (! bo->getVymLink().isEmpty() )
insilmaril@528
  3296
			fd->selectFile( bo->getURL() );
insilmaril@528
  3297
		fd->show();
insilmaril@528
  3298
insilmaril@528
  3299
		if ( fd->exec() == QDialog::Accepted )
insilmaril@528
  3300
		{
insilmaril@528
  3301
			lastFileDir=QDir (fd->directory().path());
insilmaril@528
  3302
			setURL (fd->selectedFile() );
insilmaril@528
  3303
		}
insilmaril@528
  3304
	}
insilmaril@528
  3305
}
insilmaril@528
  3306
insilmaril@266
  3307
QString MapEditor::getURL()
insilmaril@266
  3308
{
insilmaril@424
  3309
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3310
	if (bo)
insilmaril@424
  3311
		return bo->getURL();
insilmaril@266
  3312
	else
insilmaril@266
  3313
		return "";
insilmaril@266
  3314
}
insilmaril@266
  3315
insilmaril@366
  3316
QStringList MapEditor::getURLs()
insilmaril@366
  3317
{
insilmaril@366
  3318
	QStringList urls;
insilmaril@424
  3319
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3320
	if (bo)
insilmaril@366
  3321
	{		
insilmaril@366
  3322
		bo=bo->first();	
insilmaril@366
  3323
		while (bo) 
insilmaril@366
  3324
		{
insilmaril@366
  3325
			if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
insilmaril@366
  3326
			bo=bo->next();
insilmaril@366
  3327
		}	
insilmaril@366
  3328
	}	
insilmaril@366
  3329
	return urls;
insilmaril@366
  3330
}
insilmaril@366
  3331
insilmaril@366
  3332
insilmaril@0
  3333
void MapEditor::editHeading2URL()
insilmaril@0
  3334
{
insilmaril@424
  3335
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3336
	if (bo)
insilmaril@424
  3337
		setURL (bo->getHeading());
insilmaril@0
  3338
}	
insilmaril@0
  3339
insilmaril@0
  3340
void MapEditor::editBugzilla2URL()
insilmaril@0
  3341
{
insilmaril@424
  3342
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3343
	if (bo)
insilmaril@0
  3344
	{		
insilmaril@143
  3345
		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
insilmaril@395
  3346
		setURL (url);
insilmaril@0
  3347
	}
insilmaril@0
  3348
}	
insilmaril@0
  3349
insilmaril@175
  3350
void MapEditor::editFATE2URL()
insilmaril@175
  3351
{
insilmaril@424
  3352
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3353
	if (bo)
insilmaril@175
  3354
	{		
insilmaril@175
  3355
		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
insilmaril@395
  3356
		saveState(
insilmaril@424
  3357
			bo,
insilmaril@395
  3358
			"setURL (\""+bo->getURL()+"\")",
insilmaril@424
  3359
			bo,
insilmaril@395
  3360
			"setURL (\""+url+"\")",
insilmaril@395
  3361
			QString("Use heading of %1 as link to FATE").arg(getName(bo))
insilmaril@395
  3362
		);	
insilmaril@175
  3363
		bo->setURL (url);
insilmaril@175
  3364
		updateActions();
insilmaril@175
  3365
	}
insilmaril@175
  3366
}	
insilmaril@175
  3367
insilmaril@0
  3368
void MapEditor::editVymLink()
insilmaril@0
  3369
{
insilmaril@424
  3370
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3371
	if (bo)
insilmaril@0
  3372
	{		
insilmaril@404
  3373
		QStringList filters;
insilmaril@404
  3374
		filters <<"VYM map (*.vym)";
insilmaril@404
  3375
		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
insilmaril@404
  3376
		fd->setFilters (filters);
insilmaril@404
  3377
		fd->setCaption(vymName+" - " +tr("Link to another map"));
insilmaril@442
  3378
		fd->setDirectory (lastFileDir);
insilmaril@143
  3379
		if (! bo->getVymLink().isEmpty() )
insilmaril@404
  3380
			fd->selectFile( bo->getVymLink() );
insilmaril@0
  3381
		fd->show();
insilmaril@0
  3382
insilmaril@0
  3383
		QString fn;
insilmaril@0
  3384
		if ( fd->exec() == QDialog::Accepted )
insilmaril@143
  3385
		{
insilmaril@442
  3386
			lastFileDir=QDir (fd->directory().path());
insilmaril@395
  3387
			saveState(
insilmaril@424
  3388
				bo,
insilmaril@395
  3389
				"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3390
				bo,
insilmaril@395
  3391
				"setVymLink (\""+fd->selectedFile()+"\")",
insilmaril@395
  3392
				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
insilmaril@395
  3393
			);	
insilmaril@491
  3394
			setVymLinkInt (fd->selectedFile() );
insilmaril@143
  3395
		}
insilmaril@0
  3396
	}
insilmaril@0
  3397
}
insilmaril@0
  3398
insilmaril@0
  3399
void MapEditor::deleteVymLink()
insilmaril@0
  3400
{
insilmaril@424
  3401
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3402
	if (bo)
insilmaril@0
  3403
	{		
insilmaril@395
  3404
		saveState(
insilmaril@424
  3405
			bo,
insilmaril@395
  3406
			"setVymLink (\""+bo->getVymLink()+"\")",
insilmaril@424
  3407
			bo,
insilmaril@395
  3408
			"setVymLink (\"\")",
insilmaril@395
  3409
			QString("Unset vymlink of %1").arg(getName(bo))
insilmaril@395
  3410
		);	
insilmaril@143
  3411
		bo->setVymLink ("" );
insilmaril@0
  3412
		updateActions();
insilmaril@645
  3413
		model->reposition();
insilmaril@408
  3414
		scene()->update();
insilmaril@0
  3415
	}
insilmaril@0
  3416
}
insilmaril@0
  3417
insilmaril@395
  3418
void MapEditor::setHideExport(bool b)
insilmaril@243
  3419
{
insilmaril@424
  3420
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3421
	if (bo)
insilmaril@395
  3422
	{
insilmaril@424
  3423
		bo->setHideInExport (b);
insilmaril@395
  3424
		QString u= b ? "false" : "true";
insilmaril@395
  3425
		QString r=!b ? "false" : "true";
insilmaril@395
  3426
		
insilmaril@395
  3427
		saveState(
insilmaril@424
  3428
			bo,
insilmaril@395
  3429
			QString ("setHideExport (%1)").arg(u),
insilmaril@424
  3430
			bo,
insilmaril@395
  3431
			QString ("setHideExport (%1)").arg(r),
insilmaril@424
  3432
			QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
insilmaril@395
  3433
		);	
insilmaril@243
  3434
		updateActions();
insilmaril@645
  3435
		model->reposition();
insilmaril@491
  3436
		xelection.update();
insilmaril@408
  3437
		scene()->update();
insilmaril@243
  3438
	}
insilmaril@243
  3439
}
insilmaril@243
  3440
insilmaril@395
  3441
void MapEditor::toggleHideExport()
insilmaril@395
  3442
{
insilmaril@424
  3443
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3444
	if (bo)
insilmaril@424
  3445
		setHideExport ( !bo->hideInExport() );
insilmaril@395
  3446
}
insilmaril@395
  3447
insilmaril@0
  3448
QString MapEditor::getVymLink()
insilmaril@0
  3449
{
insilmaril@424
  3450
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3451
	if (bo)
insilmaril@424
  3452
		return bo->getVymLink();
insilmaril@424
  3453
	else	
insilmaril@424
  3454
		return "";
insilmaril@0
  3455
	
insilmaril@0
  3456
}
insilmaril@0
  3457
insilmaril@366
  3458
QStringList MapEditor::getVymLinks()
insilmaril@366
  3459
{
insilmaril@366
  3460
	QStringList links;
insilmaril@424
  3461
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3462
	if (bo)
insilmaril@366
  3463
	{		
insilmaril@366
  3464
		bo=bo->first();	
insilmaril@366
  3465
		while (bo) 
insilmaril@366
  3466
		{
insilmaril@366
  3467
			if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
insilmaril@366
  3468
			bo=bo->next();
insilmaril@366
  3469
		}	
insilmaril@366
  3470
	}	
insilmaril@366
  3471
	return links;
insilmaril@366
  3472
}
insilmaril@366
  3473
insilmaril@366
  3474
insilmaril@395
  3475
void MapEditor::deleteKeepChilds()
insilmaril@98
  3476
{
insilmaril@424
  3477
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3478
	BranchObj *par;
insilmaril@424
  3479
	if (bo)
insilmaril@424
  3480
	{
insilmaril@424
  3481
		par=(BranchObj*)(bo->getParObj());
insilmaril@408
  3482
		QPointF p=bo->getRelPos();
insilmaril@395
  3483
		saveStateChangingPart(
insilmaril@424
  3484
			bo->getParObj(),
insilmaril@424
  3485
			bo,
insilmaril@395
  3486
			"deleteKeepChilds ()",
insilmaril@395
  3487
			QString("Remove %1 and keep its childs").arg(getName(bo))
insilmaril@395
  3488
		);
insilmaril@394
  3489
insilmaril@424
  3490
		QString sel=bo->getSelectString();
insilmaril@98
  3491
		unselect();
insilmaril@98
  3492
		par->removeBranchHere(bo);
insilmaril@645
  3493
		model->reposition();
insilmaril@98
  3494
		select (sel);
insilmaril@424
  3495
		xelection.getBranch()->move2RelPos (p);
insilmaril@645
  3496
		model->reposition();
insilmaril@98
  3497
	}	
insilmaril@98
  3498
}
insilmaril@98
  3499
insilmaril@395
  3500
void MapEditor::deleteChilds()
insilmaril@98
  3501
{
insilmaril@424
  3502
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3503
	if (bo)
insilmaril@98
  3504
	{		
insilmaril@395
  3505
		saveStateChangingPart(
insilmaril@491
  3506
			bo, 
insilmaril@424
  3507
			bo,
insilmaril@395
  3508
			"deleteChilds ()",
insilmaril@424
  3509
			QString( "Remove childs of branch %1").arg(getName(bo))
insilmaril@395
  3510
		);
insilmaril@424
  3511
		bo->removeChilds();
insilmaril@645
  3512
		model->reposition();
insilmaril@98
  3513
	}	
insilmaril@98
  3514
}
insilmaril@98
  3515
insilmaril@0
  3516
void MapEditor::editMapInfo()
insilmaril@0
  3517
{
insilmaril@0
  3518
	ExtraInfoDialog dia;
insilmaril@0
  3519
	dia.setMapName (getFileName() );
insilmaril@645
  3520
	dia.setAuthor (model->getAuthor() );
insilmaril@645
  3521
	dia.setComment(model->getComment() );
insilmaril@0
  3522
insilmaril@0
  3523
	// Calc some stats
insilmaril@0
  3524
	QString stats;
insilmaril@408
  3525
    stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
insilmaril@0
  3526
insilmaril@0
  3527
	uint b=0;
insilmaril@0
  3528
	uint f=0;
insilmaril@0
  3529
	uint n=0;
insilmaril@103
  3530
	uint xl=0;
insilmaril@0
  3531
	BranchObj *bo;
insilmaril@645
  3532
	bo=model->first();
insilmaril@0
  3533
	while (bo) 
insilmaril@0
  3534
	{
insilmaril@0
  3535
		if (!bo->getNote().isEmpty() ) n++;
insilmaril@0
  3536
		f+= bo->countFloatImages();
insilmaril@0
  3537
		b++;
insilmaril@103
  3538
		xl+=bo->countXLinks();
insilmaril@645
  3539
		bo=model->next(bo);
insilmaril@0
  3540
	}
insilmaril@0
  3541
    stats+=QString ("%1 branches\n").arg (b-1,6);
insilmaril@104
  3542
    stats+=QString ("%1 xLinks \n").arg (xl,6);
insilmaril@0
  3543
    stats+=QString ("%1 notes\n").arg (n,6);
insilmaril@0
  3544
    stats+=QString ("%1 images\n").arg (f,6);
insilmaril@0
  3545
	dia.setStats (stats);
insilmaril@0
  3546
insilmaril@0
  3547
	// Finally show dialog
insilmaril@0
  3548
	if (dia.exec() == QDialog::Accepted)
insilmaril@0
  3549
	{
insilmaril@398
  3550
		setMapAuthor (dia.getAuthor() );
insilmaril@398
  3551
		setMapComment (dia.getComment() );
insilmaril@0
  3552
	}
insilmaril@0
  3553
}
insilmaril@0
  3554
insilmaril@442
  3555
void MapEditor::ensureSelectionVisible()
insilmaril@442
  3556
{
insilmaril@442
  3557
	LinkableMapObj *lmo=xelection.single();
insilmaril@442
  3558
	if (lmo) ensureVisible (lmo->getBBox() );
insilmaril@442
  3559
	
insilmaril@442
  3560
}
insilmaril@442
  3561
insilmaril@442
  3562
void MapEditor::updateSelection()
insilmaril@442
  3563
{
insilmaril@442
  3564
	// Tell selection to update geometries
insilmaril@442
  3565
	xelection.update();
insilmaril@442
  3566
}
insilmaril@442
  3567
insilmaril@0
  3568
void MapEditor::updateActions()
insilmaril@0
  3569
{
insilmaril@442
  3570
	// Tell mainwindow to update states of actions
insilmaril@390
  3571
	mainWindow->updateActions();
insilmaril@412
  3572
	// TODO maybe don't update if blockReposition is set
insilmaril@0
  3573
}
insilmaril@0
  3574
insilmaril@160
  3575
void MapEditor::updateNoteFlag()
insilmaril@160
  3576
{
insilmaril@427
  3577
	setChanged();
insilmaril@424
  3578
	BranchObj *bo=xelection.getBranch();
insilmaril@427
  3579
	if (bo) 
insilmaril@427
  3580
	{
insilmaril@427
  3581
		bo->updateNoteFlag();
insilmaril@427
  3582
		mainWindow->updateActions();
insilmaril@427
  3583
	}	
insilmaril@160
  3584
}
insilmaril@160
  3585
insilmaril@398
  3586
void MapEditor::setMapAuthor (const QString &s)
insilmaril@0
  3587
{
insilmaril@398
  3588
	saveState (
insilmaril@645
  3589
		QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
insilmaril@398
  3590
		QString ("setMapAuthor (\"%1\")").arg(s),
insilmaril@398
  3591
		QString ("Set author of map to \"%1\"").arg(s)
insilmaril@398
  3592
	);
insilmaril@645
  3593
	model->setAuthor (s);
insilmaril@398
  3594
}
insilmaril@398
  3595
insilmaril@398
  3596
void MapEditor::setMapComment (const QString &s)
insilmaril@398
  3597
{
insilmaril@398
  3598
	saveState (
insilmaril@645
  3599
		QString ("setMapComment (\"%1\")").arg(model->getComment()),
insilmaril@398
  3600
		QString ("setMapComment (\"%1\")").arg(s),
insilmaril@398
  3601
		QString ("Set comment of map")
insilmaril@398
  3602
	);
insilmaril@645
  3603
	model->setComment (s);
insilmaril@398
  3604
}
insilmaril@398
  3605
insilmaril@398
  3606
void MapEditor::setMapLinkStyle (const QString & s)
insilmaril@398
  3607
{
insilmaril@645
  3608
	QString snow;
insilmaril@645
  3609
	if (linkstyle==LinkableMapObj::Line)
insilmaril@645
  3610
		snow="StyleLine";
insilmaril@645
  3611
	else if (linkstyle==LinkableMapObj::Parabel)
insilmaril@645
  3612
		snow="StyleParabel";
insilmaril@645
  3613
	else if (linkstyle==LinkableMapObj::PolyLine)
insilmaril@645
  3614
		snow="StylePolyLine";
insilmaril@645
  3615
	else if (linkstyle==LinkableMapObj::PolyParabel)
insilmaril@645
  3616
		snow="StyleParabel";
insilmaril@645
  3617
insilmaril@645
  3618
	saveState (
insilmaril@398
  3619
		QString("setMapLinkStyle (\"%1\")").arg(s),
insilmaril@645
  3620
		QString("setMapLinkStyle (\"%1\")").arg(snow),
insilmaril@398
  3621
		QString("Set map link style (\"%1\")").arg(s)
insilmaril@398
  3622
	);	
insilmaril@398
  3623
insilmaril@398
  3624
	if (s=="StyleLine")
insilmaril@473
  3625
		linkstyle=LinkableMapObj::Line;
insilmaril@398
  3626
	else if (s=="StyleParabel")
insilmaril@473
  3627
		linkstyle=LinkableMapObj::Parabel;
insilmaril@398
  3628
	else if (s=="StylePolyLine")
insilmaril@473
  3629
		linkstyle=LinkableMapObj::PolyLine;
insilmaril@398
  3630
	else	
insilmaril@473
  3631
		linkstyle=LinkableMapObj::PolyParabel;
insilmaril@398
  3632
insilmaril@0
  3633
	BranchObj *bo;
insilmaril@645
  3634
	bo=model->first();
insilmaril@645
  3635
	bo=model->next(bo);
insilmaril@0
  3636
	while (bo) 
insilmaril@0
  3637
	{
insilmaril@0
  3638
		bo->setLinkStyle(bo->getDefLinkStyle());
insilmaril@645
  3639
		bo=model->next(bo);
insilmaril@0
  3640
	}
insilmaril@645
  3641
	model->reposition();
insilmaril@0
  3642
}
insilmaril@0
  3643
insilmaril@473
  3644
LinkableMapObj::Style MapEditor::getMapLinkStyle ()
insilmaril@0
  3645
{
insilmaril@0
  3646
	return linkstyle;
insilmaril@0
  3647
}	
insilmaril@0
  3648
insilmaril@398
  3649
void MapEditor::setMapDefLinkColor(QColor c)
insilmaril@0
  3650
{
insilmaril@97
  3651
	defLinkColor=c;
insilmaril@497
  3652
	BranchObj *bo;
insilmaril@645
  3653
	bo=model->first();
insilmaril@497
  3654
	while (bo) 
insilmaril@497
  3655
	{
insilmaril@497
  3656
		bo->setLinkColor();
insilmaril@645
  3657
		bo=model->next(bo);
insilmaril@497
  3658
	}
insilmaril@0
  3659
	updateActions();
insilmaril@0
  3660
}
insilmaril@0
  3661
insilmaril@398
  3662
void MapEditor::setMapLinkColorHintInt()
insilmaril@0
  3663
{
insilmaril@398
  3664
	// called from setMapLinkColorHint(lch) or at end of parse
insilmaril@0
  3665
	BranchObj *bo;
insilmaril@645
  3666
	bo=model->first();
insilmaril@0
  3667
	while (bo) 
insilmaril@0
  3668
	{
insilmaril@0
  3669
		bo->setLinkColor();
insilmaril@645
  3670
		bo=model->next(bo);
insilmaril@0
  3671
	}
insilmaril@0
  3672
}
insilmaril@0
  3673
insilmaril@473
  3674
void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
insilmaril@0
  3675
{
insilmaril@0
  3676
	linkcolorhint=lch;
insilmaril@398
  3677
	setMapLinkColorHintInt();
insilmaril@0
  3678
}
insilmaril@0
  3679
insilmaril@398
  3680
void MapEditor::toggleMapLinkColorHint()
insilmaril@0
  3681
{
insilmaril@473
  3682
	if (linkcolorhint==LinkableMapObj::HeadingColor)
insilmaril@473
  3683
		linkcolorhint=LinkableMapObj::DefaultColor;
insilmaril@0
  3684
	else	
insilmaril@473
  3685
		linkcolorhint=LinkableMapObj::HeadingColor;
insilmaril@0
  3686
	BranchObj *bo;
insilmaril@645
  3687
	bo=model->first();
insilmaril@0
  3688
	while (bo) 
insilmaril@0
  3689
	{
insilmaril@0
  3690
		bo->setLinkColor();
insilmaril@645
  3691
		bo=model->next(bo);
insilmaril@0
  3692
	}
insilmaril@0
  3693
}
insilmaril@0
  3694
insilmaril@473
  3695
LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
insilmaril@0
  3696
{
insilmaril@0
  3697
	return linkcolorhint;
insilmaril@0
  3698
}
insilmaril@0
  3699
insilmaril@398
  3700
QColor MapEditor::getMapDefLinkColor()
insilmaril@0
  3701
{
insilmaril@97
  3702
	return defLinkColor;
insilmaril@97
  3703
}
insilmaril@97
  3704
insilmaril@398
  3705
void MapEditor::setMapDefXLinkColor(QColor col)
insilmaril@97
  3706
{
insilmaril@97
  3707
	defXLinkColor=col;
insilmaril@97
  3708
}
insilmaril@97
  3709
insilmaril@398
  3710
QColor MapEditor::getMapDefXLinkColor()
insilmaril@97
  3711
{
insilmaril@97
  3712
	return defXLinkColor;
insilmaril@97
  3713
}
insilmaril@97
  3714
insilmaril@398
  3715
void MapEditor::setMapDefXLinkWidth (int w)
insilmaril@97
  3716
{
insilmaril@97
  3717
	defXLinkWidth=w;
insilmaril@97
  3718
}
insilmaril@97
  3719
insilmaril@398
  3720
int MapEditor::getMapDefXLinkWidth()
insilmaril@97
  3721
{
insilmaril@97
  3722
	return defXLinkWidth;
insilmaril@0
  3723
}
insilmaril@0
  3724
insilmaril@398
  3725
void MapEditor::selectMapLinkColor()
insilmaril@0
  3726
{
insilmaril@97
  3727
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@0
  3728
	if ( !col.isValid() ) return;
insilmaril@398
  3729
	saveState (
insilmaril@398
  3730
		QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
insilmaril@398
  3731
		QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
insilmaril@497
  3732
		QString("Set map link color to %1").arg(col.name())
insilmaril@398
  3733
	);
insilmaril@398
  3734
	setMapDefLinkColor( col );
insilmaril@442
  3735
}
insilmaril@442
  3736
insilmaril@442
  3737
void MapEditor::selectMapSelectionColor()
insilmaril@442
  3738
{
insilmaril@442
  3739
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@442
  3740
	setSelectionColor (col);
insilmaril@442
  3741
}
insilmaril@442
  3742
insilmaril@442
  3743
void MapEditor::setSelectionColorInt (QColor col)
insilmaril@442
  3744
{
insilmaril@442
  3745
	if ( !col.isValid() ) return;
insilmaril@442
  3746
	xelection.setColor (col);
insilmaril@442
  3747
}
insilmaril@442
  3748
insilmaril@442
  3749
void MapEditor::setSelectionColor(QColor col)
insilmaril@442
  3750
{
insilmaril@442
  3751
	if ( !col.isValid() ) return;
insilmaril@442
  3752
	saveState (
insilmaril@442
  3753
		QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
insilmaril@442
  3754
		QString("setSelectionColor (%1)").arg(col.name()),
insilmaril@442
  3755
		QString("Set color of selection box to %1").arg(col.name())
insilmaril@442
  3756
	);
insilmaril@442
  3757
	setSelectionColorInt (col);
insilmaril@442
  3758
}
insilmaril@442
  3759
insilmaril@442
  3760
QColor MapEditor::getSelectionColor()
insilmaril@442
  3761
{
insilmaril@442
  3762
	return xelection.getColor();
insilmaril@0
  3763
}
insilmaril@0
  3764
insilmaril@473
  3765
bool MapEditor::scrollBranch(BranchObj *bo)
insilmaril@0
  3766
{
insilmaril@427
  3767
	if (bo)
insilmaril@0
  3768
	{
insilmaril@427
  3769
		if (bo->isScrolled()) return false;
insilmaril@427
  3770
		if (bo->countBranches()==0) return false;
insilmaril@427
  3771
		if (bo->getDepth()==0) return false;
insilmaril@395
  3772
		QString u,r;
insilmaril@427
  3773
		r="scroll";
insilmaril@427
  3774
		u="unscroll";
insilmaril@395
  3775
		saveState(
insilmaril@424
  3776
			bo,
insilmaril@395
  3777
			QString ("%1 ()").arg(u),
insilmaril@424
  3778
			bo,
insilmaril@395
  3779
			QString ("%1 ()").arg(r),
insilmaril@395
  3780
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@395
  3781
		);
insilmaril@0
  3782
		bo->toggleScroll();
insilmaril@491
  3783
		xelection.update();
insilmaril@408
  3784
		scene()->update();
insilmaril@427
  3785
		return true;
insilmaril@427
  3786
	}	
insilmaril@427
  3787
	return false;
insilmaril@427
  3788
}
insilmaril@427
  3789
insilmaril@473
  3790
bool MapEditor::unscrollBranch(BranchObj *bo)
insilmaril@427
  3791
{
insilmaril@427
  3792
	if (bo)
insilmaril@427
  3793
	{
insilmaril@427
  3794
		if (!bo->isScrolled()) return false;
insilmaril@427
  3795
		if (bo->countBranches()==0) return false;
insilmaril@427
  3796
		if (bo->getDepth()==0) return false;
insilmaril@427
  3797
		QString u,r;
insilmaril@427
  3798
		u="scroll";
insilmaril@427
  3799
		r="unscroll";
insilmaril@427
  3800
		saveState(
insilmaril@427
  3801
			bo,
insilmaril@427
  3802
			QString ("%1 ()").arg(u),
insilmaril@427
  3803
			bo,
insilmaril@427
  3804
			QString ("%1 ()").arg(r),
insilmaril@427
  3805
			QString ("%1 %2").arg(r).arg(getName(bo))
insilmaril@427
  3806
		);
insilmaril@427
  3807
		bo->toggleScroll();
insilmaril@491
  3808
		xelection.update();
insilmaril@427
  3809
		scene()->update();
insilmaril@427
  3810
		return true;
insilmaril@427
  3811
	}	
insilmaril@427
  3812
	return false;
insilmaril@427
  3813
}
insilmaril@427
  3814
insilmaril@427
  3815
void MapEditor::toggleScroll()
insilmaril@427
  3816
{
insilmaril@427
  3817
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  3818
	if (xelection.type()==Selection::Branch )
insilmaril@427
  3819
	{
insilmaril@427
  3820
		if (bo->isScrolled())
insilmaril@473
  3821
			unscrollBranch (bo);
insilmaril@427
  3822
		else
insilmaril@473
  3823
			scrollBranch (bo);
insilmaril@0
  3824
	}
insilmaril@0
  3825
}
insilmaril@0
  3826
insilmaril@473
  3827
void MapEditor::unscrollChilds() 
insilmaril@0
  3828
{
insilmaril@428
  3829
	BranchObj *bo=xelection.getBranch();
insilmaril@428
  3830
	if (bo)
insilmaril@0
  3831
	{
insilmaril@428
  3832
		bo->first();
insilmaril@428
  3833
		while (bo) 
insilmaril@428
  3834
		{
insilmaril@473
  3835
			if (bo->isScrolled()) unscrollBranch (bo);
insilmaril@428
  3836
			bo=bo->next();
insilmaril@428
  3837
		}
insilmaril@428
  3838
	}	
insilmaril@0
  3839
}
insilmaril@0
  3840
insilmaril@432
  3841
FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
insilmaril@432
  3842
{
insilmaril@432
  3843
	BranchObj *bo=xelection.getBranch();
insilmaril@432
  3844
	if (bo)
insilmaril@432
  3845
	{
insilmaril@432
  3846
		FloatImageObj *fio;
insilmaril@432
  3847
		bo->addFloatImage();
insilmaril@432
  3848
		fio=bo->getLastFloatImage();
insilmaril@432
  3849
		fio->load(fn);
insilmaril@645
  3850
		model->reposition();
insilmaril@432
  3851
		scene()->update();
insilmaril@432
  3852
		return fio;
insilmaril@432
  3853
	}
insilmaril@432
  3854
	return NULL;
insilmaril@432
  3855
}	
insilmaril@428
  3856
insilmaril@0
  3857
void MapEditor::loadFloatImage ()
insilmaril@0
  3858
{
insilmaril@424
  3859
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3860
	if (bo)
insilmaril@0
  3861
	{
insilmaril@0
  3862
insilmaril@366
  3863
		Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@366
  3864
		fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@0
  3865
		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@0
  3866
		ImagePreview *p =new ImagePreview (fd);
insilmaril@0
  3867
		fd->setContentsPreviewEnabled( TRUE );
insilmaril@0
  3868
		fd->setContentsPreview( p, p );
insilmaril@366
  3869
		fd->setPreviewMode( Q3FileDialog::Contents );
insilmaril@404
  3870
		fd->setCaption(vymName+" - " +tr("Load image"));
insilmaril@0
  3871
		fd->setDir (lastImageDir);
insilmaril@0
  3872
		fd->show();
insilmaril@0
  3873
insilmaril@0
  3874
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  3875
		{
insilmaril@491
  3876
			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
insilmaril@366
  3877
			lastImageDir=QDir (fd->dirPath());
insilmaril@432
  3878
			QString s;
insilmaril@395
  3879
			FloatImageObj *fio;
insilmaril@432
  3880
			for (int j=0; j<fd->selectedFiles().count(); j++)
insilmaril@185
  3881
			{
insilmaril@432
  3882
				s=fd->selectedFiles().at(j);
insilmaril@432
  3883
				fio=loadFloatImageInt (s);
insilmaril@432
  3884
				if (fio)
insilmaril@432
  3885
					saveState(
insilmaril@432
  3886
						(LinkableMapObj*)fio,
insilmaril@432
  3887
						"delete ()",
insilmaril@432
  3888
						bo, 
insilmaril@432
  3889
						QString ("loadImage (%1)").arg(s ),
insilmaril@432
  3890
						QString("Add image %1 to %2").arg(s).arg(getName(bo))
insilmaril@432
  3891
					);
insilmaril@432
  3892
				else
insilmaril@491
  3893
					// TODO loadFIO error handling
insilmaril@432
  3894
					qWarning ("Failed to load "+s);
insilmaril@185
  3895
			}
insilmaril@0
  3896
		}
insilmaril@236
  3897
		delete (p);
insilmaril@236
  3898
		delete (fd);
insilmaril@0
  3899
	}
insilmaril@0
  3900
}
insilmaril@0
  3901
insilmaril@434
  3902
void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
insilmaril@434
  3903
{
insilmaril@434
  3904
	fio->save (fn,type);
insilmaril@434
  3905
}
insilmaril@434
  3906
insilmaril@366
  3907
void MapEditor::saveFloatImage ()
insilmaril@0
  3908
{
insilmaril@424
  3909
	FloatImageObj *fio=xelection.getFloatImage();
insilmaril@424
  3910
	if (fio)
insilmaril@0
  3911
	{
insilmaril@366
  3912
		QFileDialog *fd=new QFileDialog( this);
insilmaril@366
  3913
		fd->setFilters (imageIO.getFilters());
insilmaril@404
  3914
		fd->setCaption(vymName+" - " +tr("Save image"));
insilmaril@366
  3915
		fd->setFileMode( QFileDialog::AnyFile );
insilmaril@366
  3916
		fd->setDirectory (lastImageDir);
insilmaril@366
  3917
//		fd->setSelection (fio->getOriginalFilename());
insilmaril@0
  3918
		fd->show();
insilmaril@0
  3919
insilmaril@0
  3920
		QString fn;
insilmaril@434
  3921
		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
insilmaril@0
  3922
		{
insilmaril@434
  3923
			fn=fd->selectedFiles().at(0);
insilmaril@434
  3924
			if (QFile (fn).exists() )
insilmaril@0
  3925
			{
insilmaril@404
  3926
				QMessageBox mb( vymName,
insilmaril@159
  3927
					tr("The file %1 exists already.\n"
insilmaril@434
  3928
					"Do you want to overwrite it?").arg(fn),
insilmaril@0
  3929
				QMessageBox::Warning,
insilmaril@0
  3930
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  3931
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  3932
				QMessageBox::QMessageBox::NoButton );
insilmaril@0
  3933
insilmaril@0
  3934
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  3935
				mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  3936
				switch( mb.exec() ) 
insilmaril@0
  3937
				{
insilmaril@0
  3938
					case QMessageBox::Yes:
insilmaril@0
  3939
						// save 
insilmaril@0
  3940
						break;;
insilmaril@0
  3941
					case QMessageBox::Cancel:
insilmaril@0
  3942
						// do nothing
insilmaril@377
  3943
						delete (fd);
insilmaril@0
  3944
						return;
insilmaril@0
  3945
						break;
insilmaril@0
  3946
				}
insilmaril@0
  3947
			}
insilmaril@434
  3948
			saveFloatImageInt (fio,fd->selectedFilter(),fn );
insilmaril@0
  3949
		}
insilmaril@377
  3950
		delete (fd);
insilmaril@0
  3951
	}
insilmaril@0
  3952
}
insilmaril@0
  3953
insilmaril@473
  3954
void MapEditor::setFrameType(const FrameObj::FrameType &t)
insilmaril@0
  3955
{
insilmaril@424
  3956
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  3957
	if (bo)
insilmaril@0
  3958
	{
insilmaril@473
  3959
		QString s=bo->getFrameTypeName();
insilmaril@424
  3960
		bo->setFrameType (t);
insilmaril@473
  3961
		saveState (bo, QString("setFrameType (\"%1\")").arg(s),
insilmaril@473
  3962
			bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
insilmaril@645
  3963
		model->reposition();
insilmaril@424
  3964
		bo->updateLink();
insilmaril@0
  3965
	}
insilmaril@0
  3966
}
insilmaril@0
  3967
insilmaril@473
  3968
void MapEditor::setFrameType(const QString &s)	
insilmaril@445
  3969
{
insilmaril@445
  3970
	BranchObj *bo=xelection.getBranch();
insilmaril@445
  3971
	if (bo)
insilmaril@445
  3972
	{
insilmaril@473
  3973
		saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
insilmaril@473
  3974
			bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
insilmaril@445
  3975
		bo->setFrameType (s);
insilmaril@645
  3976
		model->reposition();
insilmaril@445
  3977
		bo->updateLink();
insilmaril@445
  3978
	}
insilmaril@445
  3979
}
insilmaril@445
  3980
insilmaril@473
  3981
void MapEditor::setFramePenColor(const QColor &c)	
insilmaril@442
  3982
{
insilmaril@442
  3983
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3984
	if (bo)
insilmaril@473
  3985
	{
insilmaril@473
  3986
		saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
insilmaril@473
  3987
			bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
insilmaril@442
  3988
		bo->setFramePenColor (c);
insilmaril@473
  3989
	}	
insilmaril@442
  3990
}
insilmaril@442
  3991
insilmaril@473
  3992
void MapEditor::setFrameBrushColor(const QColor &c)	
insilmaril@442
  3993
{
insilmaril@442
  3994
	BranchObj *bo=xelection.getBranch();
insilmaril@442
  3995
	if (bo)
insilmaril@473
  3996
	{
insilmaril@473
  3997
		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
insilmaril@473
  3998
			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
insilmaril@442
  3999
		bo->setFrameBrushColor (c);
insilmaril@473
  4000
	}	
insilmaril@473
  4001
}
insilmaril@473
  4002
insilmaril@486
  4003
void MapEditor::setFramePadding (const int &i)
insilmaril@473
  4004
{
insilmaril@473
  4005
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4006
	if (bo)
insilmaril@473
  4007
	{
insilmaril@486
  4008
		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
insilmaril@486
  4009
			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
insilmaril@486
  4010
		bo->setFramePadding (i);
insilmaril@645
  4011
		model->reposition();
insilmaril@486
  4012
		bo->updateLink();
insilmaril@473
  4013
	}	
insilmaril@473
  4014
}
insilmaril@473
  4015
insilmaril@486
  4016
void MapEditor::setFrameBorderWidth(const int &i)
insilmaril@473
  4017
{
insilmaril@473
  4018
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4019
	if (bo)
insilmaril@473
  4020
	{
insilmaril@486
  4021
		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
insilmaril@486
  4022
			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
insilmaril@486
  4023
		bo->setFrameBorderWidth (i);
insilmaril@645
  4024
		model->reposition();
insilmaril@486
  4025
		bo->updateLink();
insilmaril@473
  4026
	}	
insilmaril@442
  4027
}
insilmaril@442
  4028
insilmaril@437
  4029
void MapEditor::setIncludeImagesVer(bool b)	
insilmaril@175
  4030
{
insilmaril@424
  4031
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4032
	if (bo)
insilmaril@424
  4033
	{
insilmaril@434
  4034
		QString u= b ? "false" : "true";
insilmaril@434
  4035
		QString r=!b ? "false" : "true";
insilmaril@434
  4036
		
insilmaril@434
  4037
		saveState(
insilmaril@434
  4038
			bo,
insilmaril@434
  4039
			QString("setIncludeImagesVertically (%1)").arg(u),
insilmaril@434
  4040
			bo, 
insilmaril@434
  4041
			QString("setIncludeImagesVertically (%1)").arg(r),
insilmaril@434
  4042
			QString("Include images vertically in %1").arg(getName(bo))
insilmaril@434
  4043
		);	
insilmaril@424
  4044
		bo->setIncludeImagesVer(b);
insilmaril@645
  4045
		model->reposition();
insilmaril@424
  4046
	}	
insilmaril@175
  4047
}
insilmaril@175
  4048
insilmaril@437
  4049
void MapEditor::setIncludeImagesHor(bool b)	
insilmaril@175
  4050
{
insilmaril@424
  4051
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4052
	if (bo)
insilmaril@424
  4053
	{
insilmaril@434
  4054
		QString u= b ? "false" : "true";
insilmaril@434
  4055
		QString r=!b ? "false" : "true";
insilmaril@434
  4056
		
insilmaril@434
  4057
		saveState(
insilmaril@434
  4058
			bo,
insilmaril@434
  4059
			QString("setIncludeImagesHorizontally (%1)").arg(u),
insilmaril@434
  4060
			bo, 
insilmaril@434
  4061
			QString("setIncludeImagesHorizontally (%1)").arg(r),
insilmaril@434
  4062
			QString("Include images horizontally in %1").arg(getName(bo))
insilmaril@434
  4063
		);	
insilmaril@424
  4064
		bo->setIncludeImagesHor(b);
insilmaril@645
  4065
		model->reposition();
insilmaril@424
  4066
	}	
insilmaril@175
  4067
}
insilmaril@175
  4068
insilmaril@491
  4069
void MapEditor::setHideLinkUnselected (bool b)
insilmaril@160
  4070
{
insilmaril@424
  4071
	LinkableMapObj *sel=xelection.single();
insilmaril@424
  4072
	if (sel &&
insilmaril@491
  4073
		(xelection.type() == Selection::Branch || 
insilmaril@491
  4074
		xelection.type() == Selection::MapCenter  ||
insilmaril@491
  4075
		xelection.type() == Selection::FloatImage ))
insilmaril@491
  4076
	{
insilmaril@491
  4077
		QString u= b ? "false" : "true";
insilmaril@491
  4078
		QString r=!b ? "false" : "true";
insilmaril@491
  4079
		
insilmaril@491
  4080
		saveState(
insilmaril@491
  4081
			sel,
insilmaril@491
  4082
			QString("setHideLinkUnselected (%1)").arg(u),
insilmaril@491
  4083
			sel, 
insilmaril@491
  4084
			QString("setHideLinkUnselected (%1)").arg(r),
insilmaril@491
  4085
			QString("Hide link of %1 if unselected").arg(getName(sel))
insilmaril@491
  4086
		);	
insilmaril@424
  4087
		sel->setHideLinkUnselected(b);
insilmaril@491
  4088
	}
insilmaril@160
  4089
}
insilmaril@160
  4090
insilmaril@491
  4091
void MapEditor::importDirInt(BranchObj *dst, QDir d)
insilmaril@0
  4092
{
insilmaril@424
  4093
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4094
	if (bo)
insilmaril@0
  4095
	{
insilmaril@0
  4096
		// Traverse directories
insilmaril@0
  4097
		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  4098
		QFileInfoList list = d.entryInfoList();
insilmaril@366
  4099
		QFileInfo fi;
insilmaril@366
  4100
insilmaril@366
  4101
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4102
		{
insilmaril@366
  4103
			fi=list.at(i);
insilmaril@366
  4104
			if (fi.fileName() != "." && fi.fileName() != ".." )
insilmaril@0
  4105
			{
insilmaril@0
  4106
				dst->addBranch();
insilmaril@0
  4107
				bo=dst->getLastBranch();
insilmaril@366
  4108
				bo->setHeading (fi.fileName() );
insilmaril@243
  4109
				bo->setColor (QColor("blue"));
insilmaril@0
  4110
				bo->toggleScroll();
insilmaril@366
  4111
				if ( !d.cd(fi.fileName()) ) 
insilmaril@366
  4112
					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
insilmaril@0
  4113
				else 
insilmaril@0
  4114
				{
insilmaril@103
  4115
					// Recursively add subdirs
insilmaril@366
  4116
					importDirInt (bo,d);
insilmaril@0
  4117
					d.cdUp();
insilmaril@0
  4118
				}
insilmaril@0
  4119
			}	
insilmaril@0
  4120
		}		
insilmaril@0
  4121
		// Traverse files
insilmaril@0
  4122
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@366
  4123
		list = d.entryInfoList();
insilmaril@366
  4124
insilmaril@366
  4125
		for (int i = 0; i < list.size(); ++i) 
insilmaril@0
  4126
		{
insilmaril@366
  4127
			fi=list.at(i);
insilmaril@0
  4128
			dst->addBranch();
insilmaril@0
  4129
			bo=dst->getLastBranch();
insilmaril@366
  4130
			bo->setHeading (fi.fileName() );
insilmaril@243
  4131
			bo->setColor (QColor("black"));
insilmaril@366
  4132
			if (fi.fileName().right(4) == ".vym" )
insilmaril@366
  4133
				bo->setVymLink (fi.filePath());
insilmaril@0
  4134
		}	
insilmaril@0
  4135
	}		
insilmaril@0
  4136
}
insilmaril@0
  4137
insilmaril@491
  4138
void MapEditor::importDirInt (const QString &s)
insilmaril@491
  4139
{
insilmaril@491
  4140
	BranchObj *bo=xelection.getBranch();
insilmaril@491
  4141
	if (bo)
insilmaril@491
  4142
	{
insilmaril@491
  4143
		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
insilmaril@491
  4144
insilmaril@491
  4145
		QDir d(s);
insilmaril@491
  4146
		importDirInt (bo,d);
insilmaril@491
  4147
	}
insilmaril@491
  4148
}	
insilmaril@491
  4149
insilmaril@0
  4150
void MapEditor::importDir()
insilmaril@0
  4151
{
insilmaril@424
  4152
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4153
	if (bo)
insilmaril@0
  4154
	{
insilmaril@404
  4155
		QStringList filters;
insilmaril@404
  4156
		filters <<"VYM map (*.vym)";
insilmaril@404
  4157
		QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
insilmaril@404
  4158
		fd->setMode (QFileDialog::DirectoryOnly);
insilmaril@404
  4159
		fd->setFilters (filters);
insilmaril@404
  4160
		fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
insilmaril@0
  4161
		fd->show();
insilmaril@0
  4162
insilmaril@0
  4163
		QString fn;
insilmaril@0
  4164
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  4165
		{
insilmaril@491
  4166
			importDirInt (fd->selectedFile() );
insilmaril@645
  4167
			model->reposition();
insilmaril@408
  4168
			scene()->update();
insilmaril@0
  4169
		}
insilmaril@0
  4170
	}	
insilmaril@0
  4171
}
insilmaril@0
  4172
insilmaril@95
  4173
void MapEditor::followXLink(int i)
insilmaril@89
  4174
{
insilmaril@424
  4175
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4176
	if (bo)
insilmaril@89
  4177
	{
insilmaril@424
  4178
		bo=bo->XLinkTargetAt(i);
insilmaril@97
  4179
		if (bo) 
insilmaril@97
  4180
		{
insilmaril@424
  4181
			xelection.select(bo);
insilmaril@97
  4182
			ensureSelectionVisible();
insilmaril@97
  4183
		}
insilmaril@89
  4184
	}
insilmaril@89
  4185
}
insilmaril@89
  4186
insilmaril@421
  4187
void MapEditor::editXLink(int i)	// FIXME missing saveState
insilmaril@94
  4188
{
insilmaril@424
  4189
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  4190
	if (bo)
insilmaril@94
  4191
	{
insilmaril@424
  4192
		XLinkObj *xlo=bo->XLinkAt(i);
insilmaril@97
  4193
		if (xlo) 
insilmaril@94
  4194
		{
insilmaril@97
  4195
			EditXLinkDialog dia;
insilmaril@97
  4196
			dia.setXLink (xlo);
insilmaril@424
  4197
			dia.setSelection(bo);
insilmaril@97
  4198
			if (dia.exec() == QDialog::Accepted)
insilmaril@97
  4199
			{
insilmaril@97
  4200
				if (dia.useSettingsGlobal() )
insilmaril@97
  4201
				{
insilmaril@398
  4202
					setMapDefXLinkColor (xlo->getColor() );
insilmaril@398
  4203
					setMapDefXLinkWidth (xlo->getWidth() );
insilmaril@97
  4204
				}
insilmaril@97
  4205
				if (dia.deleteXLink())
insilmaril@424
  4206
					bo->deleteXLinkAt(i);
insilmaril@97
  4207
			}
insilmaril@97
  4208
		}	
insilmaril@97
  4209
	}
insilmaril@94
  4210
}
insilmaril@94
  4211
insilmaril@628
  4212
AttributeTable* MapEditor::attributeTable()
insilmaril@628
  4213
{
insilmaril@628
  4214
	return attrTable;
insilmaril@628
  4215
}
insilmaril@628
  4216
insilmaril@527
  4217
void MapEditor::testFunction1()
insilmaril@0
  4218
{
insilmaril@663
  4219
	BranchObj *bo=xelection.getBranch();
insilmaril@663
  4220
	if (bo) model->moveAway (bo);
insilmaril@663
  4221
insilmaril@663
  4222
insilmaril@527
  4223
/*
insilmaril@473
  4224
	BranchObj *bo=xelection.getBranch();
insilmaril@473
  4225
	if (bo) animObjList.append( bo );
insilmaril@527
  4226
*/	
insilmaril@432
  4227
	
insilmaril@420
  4228
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
insilmaril@260
  4229
	if (hidemode==HideNone)
insilmaril@185
  4230
	{
insilmaril@260
  4231
		setHideTmpMode (HideExport);
insilmaril@260
  4232
		mapCenter->calcBBoxSizeWithChilds();
insilmaril@408
  4233
		QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@408
  4234
		QRectF mapRect=totalBBox;
insilmaril@260
  4235
		QCanvasRectangle *frame=NULL;
insilmaril@260
  4236
insilmaril@260
  4237
		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
insilmaril@260
  4238
	
insilmaril@260
  4239
		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
insilmaril@260
  4240
			totalBBox.width(), totalBBox.height());
insilmaril@408
  4241
		frame=new QCanvasRectangle (mapRect,mapScene);
insilmaril@260
  4242
		frame->setBrush (QColor(white));
insilmaril@260
  4243
		frame->setPen (QColor(black));
insilmaril@408
  4244
		frame->setZValue(0);
insilmaril@260
  4245
		frame->show();    
insilmaril@260
  4246
	}	
insilmaril@260
  4247
	else	
insilmaril@260
  4248
	{
insilmaril@260
  4249
		setHideTmpMode (HideNone);
insilmaril@260
  4250
	}	
insilmaril@260
  4251
	cout <<"  hidemode="<<hidemode<<endl;
insilmaril@301
  4252
	*/
insilmaril@527
  4253
}	
insilmaril@527
  4254
	
insilmaril@527
  4255
void MapEditor::testFunction2()
insilmaril@527
  4256
{
insilmaril@645
  4257
insilmaril@652
  4258
	xelection.select (model->addMapCenter());
insilmaril@652
  4259
	ensureSelectionVisible();
insilmaril@638
  4260
insilmaril@638
  4261
/*
insilmaril@628
  4262
	// Toggle hidemode
insilmaril@628
  4263
	if (hidemode==HideExport)
insilmaril@628
  4264
		setHideTmpMode (HideNone);
insilmaril@628
  4265
	else	
insilmaril@628
  4266
		setHideTmpMode (HideExport);
insilmaril@638
  4267
*/		
insilmaril@105
  4268
}
insilmaril@105
  4269
insilmaril@408
  4270
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
insilmaril@0
  4271
{
insilmaril@0
  4272
	// Lineedits are already closed by preceding
insilmaril@0
  4273
	// mouseEvent, we don't need to close here.
insilmaril@0
  4274
insilmaril@408
  4275
    QPointF p = mapToScene(e->pos());
insilmaril@645
  4276
    LinkableMapObj* lmo=model->findMapObj(p, NULL);
insilmaril@0
  4277
	
insilmaril@0
  4278
    if (lmo) 
insilmaril@0
  4279
	{	// MapObj was found
insilmaril@424
  4280
		if (xelection.single() != lmo)
insilmaril@0
  4281
		{
insilmaril@0
  4282
			// select the MapObj
insilmaril@424
  4283
			xelection.select(lmo);
insilmaril@0
  4284
		}
insilmaril@0
  4285
		// Context Menu 
insilmaril@424
  4286
		if (xelection.getBranch() ) 
insilmaril@0
  4287
		{
insilmaril@424
  4288
			// Context Menu on branch or mapcenter
insilmaril@424
  4289
			updateActions();
insilmaril@424
  4290
			branchContextMenu->popup(e->globalPos() );
insilmaril@424
  4291
		} else
insilmaril@424
  4292
		{
insilmaril@424
  4293
			if (xelection.getFloatImage() )
insilmaril@0
  4294
			{
insilmaril@0
  4295
				// Context Menu on floatimage
insilmaril@0
  4296
				updateActions();
insilmaril@0
  4297
				floatimageContextMenu->popup(e->globalPos() );
insilmaril@0
  4298
			}	
insilmaril@0
  4299
		}	
insilmaril@0
  4300
	} else 
insilmaril@0
  4301
	{ // No MapObj found, we are on the Canvas itself
insilmaril@408
  4302
		// Context Menu on scene
insilmaril@0
  4303
		updateActions();
insilmaril@0
  4304
		canvasContextMenu->popup(e->globalPos() );
insilmaril@0
  4305
    } 
insilmaril@329
  4306
	e->accept();
insilmaril@0
  4307
}
insilmaril@0
  4308
insilmaril@398
  4309
void MapEditor::keyPressEvent(QKeyEvent* e)
insilmaril@398
  4310
{
insilmaril@411
  4311
	if (e->modifiers() & Qt::ControlModifier)
insilmaril@398
  4312
	{
insilmaril@398
  4313
		switch (mainWindow->getModMode())
insilmaril@398
  4314
		{
insilmaril@473
  4315
			case Main::ModModeColor: 
insilmaril@398
  4316
				setCursor (PickColorCursor);
insilmaril@398
  4317
				break;
insilmaril@473
  4318
			case Main::ModModeCopy: 
insilmaril@398
  4319
				setCursor (CopyCursor);
insilmaril@398
  4320
				break;
insilmaril@473
  4321
			case Main::ModModeXLink: 
insilmaril@398
  4322
				setCursor (XLinkCursor);
insilmaril@398
  4323
				break;
insilmaril@398
  4324
			default :
insilmaril@398
  4325
				setCursor (Qt::ArrowCursor);
insilmaril@398
  4326
				break;
insilmaril@398
  4327
		} 
insilmaril@398
  4328
	}	
insilmaril@398
  4329
}
insilmaril@398
  4330
insilmaril@398
  4331
void MapEditor::keyReleaseEvent(QKeyEvent* e)
insilmaril@398
  4332
{
insilmaril@411
  4333
	if (!(e->modifiers() & Qt::ControlModifier))
insilmaril@398
  4334
		setCursor (Qt::ArrowCursor);
insilmaril@398
  4335
}
insilmaril@398
  4336
insilmaril@408
  4337
void MapEditor::mousePressEvent(QMouseEvent* e)
insilmaril@0
  4338
{
insilmaril@329
  4339
	// Ignore right clicks, these will go to context menus
insilmaril@366
  4340
	if (e->button() == Qt::RightButton )
insilmaril@329
  4341
	{
insilmaril@329
  4342
		e->ignore();
insilmaril@329
  4343
		return;
insilmaril@329
  4344
	}
insilmaril@329
  4345
insilmaril@491
  4346
	//Ignore clicks while editing heading
insilmaril@491
  4347
	if (isSelectBlocked() ) 
insilmaril@491
  4348
	{
insilmaril@491
  4349
		e->ignore();
insilmaril@491
  4350
		return;
insilmaril@491
  4351
	}
insilmaril@491
  4352
insilmaril@408
  4353
    QPointF p = mapToScene(e->pos());
insilmaril@645
  4354
    LinkableMapObj* lmo=model->findMapObj(p, NULL);
insilmaril@0
  4355
	
insilmaril@329
  4356
	e->accept();
insilmaril@329
  4357
insilmaril@442
  4358
	//Take care of  system flags _or_ modifier modes
insilmaril@267
  4359
	//
insilmaril@267
  4360
	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@267
  4361
		typeid(*lmo)==typeid(MapCenterObj) ))
insilmaril@267
  4362
	{
insilmaril@267
  4363
		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
insilmaril@267
  4364
		if (!foname.isEmpty())
insilmaril@267
  4365
		{
insilmaril@267
  4366
			// systemFlag clicked
insilmaril@366
  4367
			selectInt (lmo);
insilmaril@267
  4368
			if (foname=="url") 
insilmaril@267
  4369
			{
insilmaril@366
  4370
				if (e->state() & Qt::ControlModifier)
insilmaril@267
  4371
					mainWindow->editOpenURLTab();
insilmaril@267
  4372
				else	
insilmaril@267
  4373
					mainWindow->editOpenURL();
insilmaril@267
  4374
			}	
insilmaril@267
  4375
			else if (foname=="vymLink")
insilmaril@267
  4376
			{
insilmaril@267
  4377
				mainWindow->editOpenVymLink();
insilmaril@267
  4378
				// tabWidget may change, better return now
insilmaril@267
  4379
				// before segfaulting...
insilmaril@267
  4380
			} else if (foname=="note")
insilmaril@267
  4381
				mainWindow->windowToggleNoteEditor();
insilmaril@267
  4382
			else if (foname=="hideInExport")		
insilmaril@267
  4383
				toggleHideExport();
insilmaril@442
  4384
			xelection.update();	
insilmaril@267
  4385
			return;	
insilmaril@267
  4386
		} 
insilmaril@267
  4387
	} 
insilmaril@442
  4388
insilmaril@442
  4389
	// No system flag clicked, take care of modmodes (CTRL-Click)
insilmaril@366
  4390
	if (e->state() & Qt::ControlModifier)
insilmaril@0
  4391
	{
insilmaril@473
  4392
		if (mainWindow->getModMode()==Main::ModModeColor)
insilmaril@83
  4393
		{
insilmaril@83
  4394
				pickingColor=true;
insilmaril@398
  4395
				setCursor (PickColorCursor);
insilmaril@83
  4396
				return;
insilmaril@83
  4397
		} 
insilmaril@473
  4398
		if (mainWindow->getModMode()==Main::ModModeXLink)
insilmaril@83
  4399
		{	
insilmaril@90
  4400
			BranchObj *bo_begin=NULL;
insilmaril@90
  4401
			if (lmo)
insilmaril@90
  4402
				bo_begin=(BranchObj*)(lmo);
insilmaril@90
  4403
			else	
insilmaril@424
  4404
				if (xelection.getBranch() ) 
insilmaril@424
  4405
					bo_begin=xelection.getBranch();
insilmaril@90
  4406
			if (bo_begin)	
insilmaril@83
  4407
			{
insilmaril@83
  4408
				drawingLink=true;
insilmaril@90
  4409
				linkingObj_src=bo_begin;
insilmaril@408
  4410
				tmpXLink=new XLinkObj (mapScene);
insilmaril@95
  4411
				tmpXLink->setBegin (bo_begin);
insilmaril@95
  4412
				tmpXLink->setEnd   (p);
insilmaril@97
  4413
				tmpXLink->setColor(defXLinkColor);
insilmaril@97
  4414
				tmpXLink->setWidth(defXLinkWidth);
insilmaril@95
  4415
				tmpXLink->updateXLink();
insilmaril@95
  4416
				tmpXLink->setVisibility (true);
insilmaril@83
  4417
				return;
insilmaril@89
  4418
			} 
insilmaril@267
  4419
		}
insilmaril@442
  4420
	}	// End of modmodes
insilmaril@442
  4421
insilmaril@0
  4422
    if (lmo) 
insilmaril@267
  4423
	{	
insilmaril@442
  4424
		// Select the clicked object
insilmaril@366
  4425
		selectInt (lmo);
insilmaril@442
  4426
insilmaril@0
  4427
		// Left Button	    Move Branches
insilmaril@366
  4428
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4429
		{
insilmaril@424
  4430
			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
insilmaril@424
  4431
			//movingObj_start.setY( p.y() - selection->y() );	
insilmaril@424
  4432
			movingObj_start.setX( p.x() - lmo->x() );	
insilmaril@424
  4433
			movingObj_start.setY( p.y() - lmo->y() );	
insilmaril@129
  4434
			movingObj_orgPos.setX (lmo->x() );
insilmaril@129
  4435
			movingObj_orgPos.setY (lmo->y() );
insilmaril@366
  4436
			movingObj_orgRelPos=lmo->getRelPos();
insilmaril@129
  4437
insilmaril@93
  4438
			// If modMode==copy, then we want to "move" the _new_ object around
insilmaril@93
  4439
			// then we need the offset from p to the _old_ selection, because of tmp
insilmaril@473
  4440
			if (mainWindow->getModMode()==Main::ModModeCopy &&
insilmaril@366
  4441
				e->state() & Qt::ControlModifier)
insilmaril@93
  4442
			{
insilmaril@645
  4443
				BranchObj *bo=xelection.getBranch();
insilmaril@645
  4444
				if (bo)
insilmaril@93
  4445
				{
insilmaril@93
  4446
					copyingObj=true;
insilmaril@645
  4447
					bo->addBranch ((BranchObj*)xelection.single());
insilmaril@93
  4448
					unselect();
insilmaril@645
  4449
					xelection.select(bo->getLastBranch());
insilmaril@645
  4450
					model->reposition();
insilmaril@93
  4451
				}
insilmaril@421
  4452
			} 
insilmaril@421
  4453
insilmaril@424
  4454
			movingObj=xelection.single();	
insilmaril@0
  4455
		} else
insilmaril@0
  4456
			// Middle Button    Toggle Scroll
insilmaril@0
  4457
			// (On Mac OS X this won't work, but we still have 
insilmaril@0
  4458
			// a button in the toolbar)
insilmaril@366
  4459
			if (e->button() == Qt::MidButton )
insilmaril@0
  4460
				toggleScroll();
insilmaril@0
  4461
		updateActions();
insilmaril@442
  4462
		xelection.update();
insilmaril@0
  4463
	} else 
insilmaril@408
  4464
	{ // No MapObj found, we are on the scene itself
insilmaril@408
  4465
		// Left Button	    move Pos of sceneView
insilmaril@366
  4466
		if (e->button() == Qt::LeftButton )
insilmaril@0
  4467
		{
insilmaril@0
  4468
			movingObj=NULL;	// move Content not Obj
insilmaril@0
  4469
			movingObj_start=e->globalPos();
insilmaril@408
  4470
			movingCont_start=QPointF (
insilmaril@408
  4471
				horizontalScrollBar()->value(),
insilmaril@408
  4472
				verticalScrollBar()->value());
insilmaril@408
  4473
			movingVec=QPointF(0,0);
insilmaril@398
  4474
			setCursor(HandOpenCursor);
insilmaril@0
  4475
		} 
insilmaril@0
  4476
    } 
insilmaril@0
  4477
}
insilmaril@0
  4478
insilmaril@408
  4479
void MapEditor::mouseMoveEvent(QMouseEvent* e)
insilmaril@0
  4480
{
insilmaril@408
  4481
    QPointF p = mapToScene(e->pos());
insilmaril@424
  4482
	LinkableMapObj *lmosel=xelection.single();
insilmaril@83
  4483
insilmaril@0
  4484
    // Move the selected MapObj
insilmaril@424
  4485
    if ( lmosel && movingObj) 
insilmaril@0
  4486
    {	
insilmaril@421
  4487
		// reset cursor if we are moving and don't copy
insilmaril@473
  4488
		if (mainWindow->getModMode()!=Main::ModModeCopy)
insilmaril@421
  4489
			setCursor (Qt::ArrowCursor);
insilmaril@421
  4490
insilmaril@408
  4491
		// To avoid jumping of the sceneView, only 
insilmaril@164
  4492
		// ensureSelectionVisible, if not tmp linked
insilmaril@424
  4493
		if (!lmosel->hasParObjTmp())
insilmaril@164
  4494
			ensureSelectionVisible ();
insilmaril@0
  4495
		
insilmaril@83
  4496
		// Now move the selection, but add relative position 
insilmaril@83
  4497
		// (movingObj_start) where selection was chosen with 
insilmaril@83
  4498
		// mousepointer. (This avoids flickering resp. jumping 
insilmaril@0
  4499
		// of selection back to absPos)
insilmaril@0
  4500
		
insilmaril@0
  4501
		// Check if we could link 
insilmaril@645
  4502
		LinkableMapObj* lmo=model->findMapObj(p, lmosel);
insilmaril@0
  4503
		
insilmaril@0
  4504
insilmaril@424
  4505
		FloatObj *fio=xelection.getFloatImage();
insilmaril@424
  4506
		if (fio)
insilmaril@0
  4507
		{
insilmaril@424
  4508
			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@424
  4509
			fio->setRelPos();
insilmaril@424
  4510
			fio->updateLink(); //no need for reposition, if we update link here
insilmaril@442
  4511
			xelection.update();
insilmaril@0
  4512
insilmaril@0
  4513
			// Relink float to new mapcenter or branch, if shift is pressed	
insilmaril@0
  4514
			// Only relink, if selection really has a new parent
insilmaril@388
  4515
			if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
insilmaril@0
  4516
				( (typeid(*lmo)==typeid(BranchObj)) ||
insilmaril@0
  4517
				  (typeid(*lmo)==typeid(MapCenterObj)) ) &&
insilmaril@424
  4518
				( lmo != fio->getParObj())  
insilmaril@0
  4519
				)
insilmaril@0
  4520
			{
insilmaril@424
  4521
				if (typeid(*fio) == typeid(FloatImageObj) && 
insilmaril@420
  4522
				( (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@420
  4523
				  typeid(*lmo)==typeid(MapCenterObj)) ))  
insilmaril@0
  4524
				{
insilmaril@420
  4525
insilmaril@420
  4526
					// Also save the move which was done so far
insilmaril@420
  4527
					QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@420
  4528
					QString pnow=qpointfToString(fio->getRelPos());
insilmaril@420
  4529
					saveState(
insilmaril@424
  4530
						fio,
insilmaril@420
  4531
						"moveRel "+pold,
insilmaril@424
  4532
						fio,
insilmaril@420
  4533
						"moveRel "+pnow,
insilmaril@625
  4534
						QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
insilmaril@420
  4535
					fio->getParObj()->requestReposition();
insilmaril@645
  4536
					model->reposition();
insilmaril@420
  4537
insilmaril@420
  4538
					linkTo (lmo->getSelectString());
insilmaril@442
  4539
					//movingObj=lmosel;
insilmaril@442
  4540
					//movingObj_orgRelPos=lmosel->getRelPos();	
insilmaril@420
  4541
insilmaril@645
  4542
					model->reposition();
insilmaril@0
  4543
				}	
insilmaril@0
  4544
			}
insilmaril@388
  4545
		} else	
insilmaril@388
  4546
		{	// selection != a FloatObj
insilmaril@0
  4547
			if (lmosel->getDepth()==0)
insilmaril@0
  4548
			{
insilmaril@388
  4549
				// Move MapCenter
insilmaril@388
  4550
				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
insilmaril@645
  4551
					((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@0
  4552
				else	
insilmaril@645
  4553
					lmosel->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@645
  4554
				model->updateRelPositions();
insilmaril@0
  4555
			} else
insilmaril@0
  4556
			{	
insilmaril@0
  4557
				if (lmosel->getDepth()==1)
insilmaril@0
  4558
				{
insilmaril@388
  4559
					// Move mainbranch
insilmaril@0
  4560
					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@388
  4561
					lmosel->setRelPos();
insilmaril@0
  4562
				} else
insilmaril@0
  4563
				{
insilmaril@388
  4564
					// Move ordinary branch
insilmaril@473
  4565
					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
insilmaril@0
  4566
						// Add width of bbox here, otherwise alignRelTo will cause jumping around
insilmaril@0
  4567
						lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), 
insilmaril@175
  4568
							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
insilmaril@0
  4569
					else	
insilmaril@175
  4570
						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
insilmaril@0
  4571
				} 
insilmaril@0
  4572
insilmaril@431
  4573
				// Maybe we can relink temporary?
insilmaril@431
  4574
				if (lmo && (lmo!=lmosel) && xelection.getBranch() && 
insilmaril@431
  4575
					 (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@431
  4576
					  typeid(*lmo)==typeid(MapCenterObj)) ) 
insilmaril@431
  4577
insilmaril@0
  4578
				{
insilmaril@388
  4579
					if (e->modifiers()==Qt::ControlModifier)
insilmaril@0
  4580
					{
insilmaril@0
  4581
						// Special case: CTRL to link below lmo
insilmaril@0
  4582
						lmosel->setParObjTmp (lmo,p,+1);
insilmaril@0
  4583
					}
insilmaril@388
  4584
					else if (e->modifiers()==Qt::ShiftModifier)
insilmaril@0
  4585
						lmosel->setParObjTmp (lmo,p,-1);
insilmaril@0
  4586
					else
insilmaril@0
  4587
						lmosel->setParObjTmp (lmo,p,0);
insilmaril@0
  4588
				} else	
insilmaril@0
  4589
				{
insilmaril@93
  4590
					lmosel->unsetParObjTmp();
insilmaril@0
  4591
				}		
insilmaril@428
  4592
				// reposition subbranch
insilmaril@428
  4593
				lmosel->reposition();	
insilmaril@0
  4594
			} // depth>0
insilmaril@0
  4595
insilmaril@442
  4596
			xelection.update();
insilmaril@0
  4597
		} // no FloatImageObj
insilmaril@0
  4598
insilmaril@408
  4599
		scene()->update();
insilmaril@0
  4600
		return;
insilmaril@0
  4601
	} // selection && moving_obj
insilmaril@0
  4602
		
insilmaril@83
  4603
	// Draw a link from one branch to another
insilmaril@83
  4604
	if (drawingLink)
insilmaril@83
  4605
	{
insilmaril@95
  4606
		 tmpXLink->setEnd (p);
insilmaril@95
  4607
		 tmpXLink->updateXLink();
insilmaril@83
  4608
	}	 
insilmaril@83
  4609
	
insilmaril@408
  4610
    // Move sceneView 
insilmaril@411
  4611
    if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
insilmaril@0
  4612
	{
insilmaril@408
  4613
		QPointF p=e->globalPos();
insilmaril@0
  4614
		movingVec.setX(-p.x() + movingObj_start.x() );
insilmaril@0
  4615
		movingVec.setY(-p.y() + movingObj_start.y() );
insilmaril@408
  4616
		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
insilmaril@408
  4617
		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
insilmaril@0
  4618
    }
insilmaril@0
  4619
}
insilmaril@0
  4620
insilmaril@0
  4621
insilmaril@408
  4622
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
insilmaril@0
  4623
{
insilmaril@408
  4624
    QPointF p = mapToScene(e->pos());
insilmaril@0
  4625
	LinkableMapObj *dst;
insilmaril@424
  4626
	LinkableMapObj *lmosel=xelection.single();
insilmaril@0
  4627
	// Have we been picking color?
insilmaril@0
  4628
	if (pickingColor)
insilmaril@0
  4629
	{
insilmaril@0
  4630
		pickingColor=false;
insilmaril@366
  4631
		setCursor (Qt::ArrowCursor);
insilmaril@0
  4632
		// Check if we are over another branch
insilmaril@645
  4633
		dst=model->findMapObj(p, NULL);
insilmaril@424
  4634
		if (dst && lmosel) 
insilmaril@0
  4635
		{	
insilmaril@366
  4636
			if (e->state() & Qt::ShiftModifier)
insilmaril@638
  4637
				colorBranch (((BranchObj*)dst)->getColor());
insilmaril@0
  4638
			else	
insilmaril@638
  4639
				colorSubtree (((BranchObj*)dst)->getColor());
insilmaril@0
  4640
		} 
insilmaril@0
  4641
		return;
insilmaril@0
  4642
	}
insilmaril@83
  4643
insilmaril@83
  4644
	// Have we been drawing a link?
insilmaril@491
  4645
	if (drawingLink)	
insilmaril@83
  4646
	{
insilmaril@83
  4647
		drawingLink=false;
insilmaril@83
  4648
		// Check if we are over another branch
insilmaril@645
  4649
		dst=model->findMapObj(p, NULL);
insilmaril@424
  4650
		if (dst && lmosel) 
insilmaril@83
  4651
		{	
insilmaril@95
  4652
			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
insilmaril@95
  4653
			tmpXLink->updateXLink();
insilmaril@491
  4654
			tmpXLink->activate(); //FIXME savestate missing
insilmaril@473
  4655
			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
insilmaril@83
  4656
		} else
insilmaril@83
  4657
		{
insilmaril@95
  4658
			delete(tmpXLink);
insilmaril@95
  4659
			tmpXLink=NULL;
insilmaril@83
  4660
		}
insilmaril@83
  4661
		return;
insilmaril@83
  4662
	}
insilmaril@83
  4663
	
insilmaril@0
  4664
    // Have we been moving something?
insilmaril@424
  4665
    if ( lmosel && movingObj ) 
insilmaril@0
  4666
    {	
insilmaril@424
  4667
		FloatImageObj *fo=xelection.getFloatImage();
insilmaril@424
  4668
		if(fo)
insilmaril@175
  4669
		{
insilmaril@388
  4670
			// Moved FloatObj. Maybe we need to reposition
insilmaril@408
  4671
		    QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@408
  4672
		    QString pnow=qpointfToString(fo->getRelPos());
insilmaril@395
  4673
			saveState(
insilmaril@424
  4674
				fo,
insilmaril@366
  4675
				"moveRel "+pold,
insilmaril@424
  4676
				fo,
insilmaril@366
  4677
				"moveRel "+pnow,
insilmaril@625
  4678
				QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
insilmaril@424
  4679
insilmaril@424
  4680
			fo->getParObj()->requestReposition();
insilmaril@645
  4681
			model->reposition();
insilmaril@175
  4682
		}	
insilmaril@175
  4683
insilmaril@0
  4684
		// Check if we are over another branch, but ignore 
insilmaril@0
  4685
		// any found LMOs, which are FloatObjs
insilmaril@645
  4686
		dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
insilmaril@0
  4687
insilmaril@336
  4688
		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
insilmaril@0
  4689
			dst=NULL;
insilmaril@0
  4690
		
insilmaril@645
  4691
		BranchObj *bo=xelection.getBranch();
insilmaril@645
  4692
		if (bo && bo->getDepth()==0)
insilmaril@497
  4693
		{	
insilmaril@645
  4694
            if (movingObj_orgPos != bo->getAbsPos())
insilmaril@625
  4695
            {
insilmaril@625
  4696
                QString pold=qpointfToString(movingObj_orgPos);
insilmaril@645
  4697
                QString pnow=qpointfToString(bo->getAbsPos());
insilmaril@625
  4698
                saveState(
insilmaril@625
  4699
                    fo,
insilmaril@625
  4700
                    "move "+pold,
insilmaril@625
  4701
                    fo,
insilmaril@625
  4702
                    "move "+pnow,
insilmaril@645
  4703
                    QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
insilmaril@625
  4704
            }
insilmaril@388
  4705
		}
insilmaril@645
  4706
	
insilmaril@491
  4707
		if (xelection.type() == Selection::Branch )
insilmaril@388
  4708
		{	// A branch was moved
insilmaril@388
  4709
			
insilmaril@0
  4710
			// save the position in case we link to mapcenter
insilmaril@424
  4711
			QPointF savePos=QPointF (lmosel->getAbsPos()  );
insilmaril@0
  4712
insilmaril@0
  4713
			// Reset the temporary drawn link to the original one
insilmaril@424
  4714
			lmosel->unsetParObjTmp();
insilmaril@0
  4715
insilmaril@366
  4716
			// For Redo we may need to save original selection
insilmaril@424
  4717
			QString preSelStr=lmosel->getSelectString();
insilmaril@93
  4718
insilmaril@94
  4719
			copyingObj=false;	
insilmaril@129
  4720
			if (dst ) 
insilmaril@93
  4721
			{
insilmaril@424
  4722
				BranchObj* bsel=xelection.getBranch();
insilmaril@366
  4723
				BranchObj* bdst=(BranchObj*)dst;
insilmaril@366
  4724
insilmaril@366
  4725
				QString preParStr=(bsel->getParObj())->getSelectString();
insilmaril@366
  4726
				QString preNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4727
				QString preDstParStr;
insilmaril@366
  4728
insilmaril@366
  4729
				if (e->state() & Qt::ShiftModifier && dst->getParObj())
insilmaril@366
  4730
				{	// Link above dst
insilmaril@366
  4731
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4732
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
insilmaril@366
  4733
				} else 
insilmaril@366
  4734
				if (e->state() & Qt::ControlModifier && dst->getParObj())
insilmaril@366
  4735
				{
insilmaril@366
  4736
					// Link below dst
insilmaril@366
  4737
					preDstParStr=dst->getParObj()->getSelectString();
insilmaril@421
  4738
					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
insilmaril@366
  4739
				} else	
insilmaril@366
  4740
				{	// Append to dst
insilmaril@366
  4741
					preDstParStr=dst->getSelectString();
insilmaril@421
  4742
					bsel->linkTo (bdst,-1);
insilmaril@366
  4743
					if (dst->getDepth()==0) bsel->move (savePos);
insilmaril@366
  4744
				} 
insilmaril@424
  4745
				QString postSelStr=lmosel->getSelectString();
insilmaril@366
  4746
				QString postNum=QString::number (bsel->getNum(),10);
insilmaril@366
  4747
insilmaril@421
  4748
				QString undoCom="linkTo (\""+ 
insilmaril@366
  4749
					preParStr+ "\"," + preNum  +"," + 
insilmaril@366
  4750
					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
insilmaril@366
  4751
insilmaril@421
  4752
				QString redoCom="linkTo (\""+ 
insilmaril@366
  4753
					preDstParStr + "\"," + postNum + "," +
insilmaril@366
  4754
					QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
insilmaril@366
  4755
insilmaril@366
  4756
				saveState (
insilmaril@366
  4757
					postSelStr,undoCom,
insilmaril@366
  4758
					preSelStr, redoCom,
insilmaril@366
  4759
					QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
insilmaril@163
  4760
			} else
insilmaril@424
  4761
				if (lmosel->getDepth()==1)
insilmaril@366
  4762
				{
insilmaril@366
  4763
					// The select string might be different _after_ moving around.
insilmaril@366
  4764
					// Therefor reposition and then use string of old selection, too
insilmaril@645
  4765
					model->reposition();
insilmaril@366
  4766
insilmaril@625
  4767
                    QPointF rp(lmosel->getRelPos());
insilmaril@625
  4768
                    if (rp != movingObj_orgRelPos)
insilmaril@625
  4769
                    {
insilmaril@625
  4770
                        QString ps=qpointfToString(rp);
insilmaril@625
  4771
                        saveState(
insilmaril@625
  4772
                            lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
insilmaril@625
  4773
                            preSelStr, "moveRel "+ps, 
insilmaril@625
  4774
                            QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
insilmaril@625
  4775
                    }
insilmaril@366
  4776
				}
insilmaril@0
  4777
			// Draw the original link, before selection was moved around
insilmaril@645
  4778
			model->reposition();
insilmaril@0
  4779
		}
insilmaril@442
  4780
		xelection.update();
insilmaril@408
  4781
		// Finally resize scene, if needed
insilmaril@408
  4782
		scene()->update();
insilmaril@0
  4783
		movingObj=NULL;		
insilmaril@366
  4784
insilmaril@366
  4785
		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
insilmaril@366
  4786
		updateActions();
insilmaril@0
  4787
	} else 
insilmaril@83
  4788
		// maybe we moved View: set old cursor
insilmaril@366
  4789
		setCursor (Qt::ArrowCursor);
insilmaril@83
  4790
    
insilmaril@0
  4791
}
insilmaril@0
  4792
insilmaril@408
  4793
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
insilmaril@0
  4794
{
insilmaril@491
  4795
	if (isSelectBlocked() ) 
insilmaril@491
  4796
	{
insilmaril@491
  4797
		e->ignore();
insilmaril@491
  4798
		return;
insilmaril@491
  4799
	}
insilmaril@491
  4800
insilmaril@366
  4801
	if (e->button() == Qt::LeftButton )
insilmaril@0
  4802
	{
insilmaril@408
  4803
		QPointF p = mapToScene(e->pos());
insilmaril@645
  4804
		LinkableMapObj *lmo=model->findMapObj(p, NULL);
insilmaril@0
  4805
		if (lmo) {	// MapObj was found
insilmaril@0
  4806
			// First select the MapObj than edit heading
insilmaril@424
  4807
			xelection.select(lmo);
insilmaril@366
  4808
			mainWindow->editHeading();
insilmaril@0
  4809
		}
insilmaril@0
  4810
	}
insilmaril@0
  4811
}
insilmaril@0
  4812
insilmaril@0
  4813
void MapEditor::resizeEvent (QResizeEvent* e)
insilmaril@0
  4814
{
insilmaril@408
  4815
	QGraphicsView::resizeEvent( e );
insilmaril@0
  4816
}
insilmaril@0
  4817
insilmaril@412
  4818
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
insilmaril@119
  4819
{
insilmaril@417
  4820
	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
insilmaril@417
  4821
	//	cerr << event->format(i) << endl;
insilmaril@417
  4822
insilmaril@417
  4823
	if (event->mimeData()->hasImage())
insilmaril@417
  4824
		event->acceptProposedAction();
insilmaril@417
  4825
	else	
insilmaril@417
  4826
		if (event->mimeData()->hasUrls())
insilmaril@417
  4827
			event->acceptProposedAction();
insilmaril@417
  4828
}
insilmaril@417
  4829
insilmaril@531
  4830
void MapEditor::dragMoveEvent(QDragMoveEvent *)
insilmaril@417
  4831
{
insilmaril@417
  4832
}
insilmaril@417
  4833
insilmaril@417
  4834
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
insilmaril@417
  4835
{
insilmaril@417
  4836
	event->accept();
insilmaril@119
  4837
}
insilmaril@129
  4838
insilmaril@412
  4839
void MapEditor::dropEvent(QDropEvent *event)
insilmaril@129
  4840
{
insilmaril@424
  4841
	BranchObj *sel=xelection.getBranch();
insilmaril@424
  4842
	if (sel)
insilmaril@128
  4843
	{
insilmaril@505
  4844
		if (debug)
insilmaril@505
  4845
			foreach (QString format,event->mimeData()->formats()) 
insilmaril@658
  4846
				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
insilmaril@497
  4847
insilmaril@497
  4848
insilmaril@417
  4849
		QList <QUrl> uris;
insilmaril@417
  4850
		if (event->mimeData()->hasImage()) 
insilmaril@128
  4851
		{
insilmaril@417
  4852
			 QVariant imageData = event->mimeData()->imageData();
insilmaril@417
  4853
			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
insilmaril@417
  4854
		} else
insilmaril@417
  4855
		if (event->mimeData()->hasUrls())
insilmaril@417
  4856
			uris=event->mimeData()->urls();
insilmaril@417
  4857
insilmaril@417
  4858
		if (uris.count()>0)
insilmaril@128
  4859
		{
insilmaril@417
  4860
			QStringList files;
insilmaril@417
  4861
			QString s;
insilmaril@417
  4862
			QString heading;
insilmaril@417
  4863
			BranchObj *bo;
insilmaril@428
  4864
			for (int i=0; i<uris.count();i++)
insilmaril@408
  4865
			{
insilmaril@428
  4866
				// Workaround to avoid adding empty branches
insilmaril@428
  4867
				if (!uris.at(i).toString().isEmpty())
insilmaril@417
  4868
				{
insilmaril@428
  4869
					bo=sel->addBranch();
insilmaril@428
  4870
					if (bo)
insilmaril@417
  4871
					{
insilmaril@428
  4872
						s=uris.at(i).toLocalFile();
insilmaril@428
  4873
						if (!s.isEmpty()) 
insilmaril@428
  4874
						{
insilmaril@625
  4875
						   QString file = QDir::fromNativeSeparators(s);
insilmaril@428
  4876
						   heading = QFileInfo(file).baseName();
insilmaril@428
  4877
						   files.append(file);
insilmaril@428
  4878
						   if (file.endsWith(".vym", false))
insilmaril@428
  4879
							   bo->setVymLink(file);
insilmaril@428
  4880
						   else
insilmaril@428
  4881
							   bo->setURL(uris.at(i).toString());
insilmaril@428
  4882
					   } else 
insilmaril@428
  4883
					   {
insilmaril@428
  4884
						   bo->setURL(uris.at(i).toString());
insilmaril@428
  4885
					   }
insilmaril@428
  4886
insilmaril@428
  4887
					   if (!heading.isEmpty())
insilmaril@428
  4888
						   bo->setHeading(heading);
insilmaril@428
  4889
					   else
insilmaril@428
  4890
						   bo->setHeading(uris.at(i).toString());
insilmaril@428
  4891
					}
insilmaril@417
  4892
				}
insilmaril@417
  4893
			}
insilmaril@645
  4894
			model->reposition();
insilmaril@417
  4895
		}
insilmaril@417
  4896
	}	
insilmaril@417
  4897
	event->acceptProposedAction();
insilmaril@417
  4898
}
insilmaril@417
  4899
insilmaril@491
  4900
void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
insilmaril@473
  4901
{
insilmaril@473
  4902
    Q_UNUSED(event);
insilmaril@473
  4903
insilmaril@473
  4904
	cout << "ME::timerEvent\n";
insilmaril@473
  4905
insilmaril@473
  4906
	for (int i=0; i<animObjList.size(); ++i)
insilmaril@473
  4907
	{
insilmaril@473
  4908
		animObjList.at(i)->animate();
insilmaril@473
  4909
		((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
insilmaril@473
  4910
	}
insilmaril@645
  4911
	model->reposition();
insilmaril@473
  4912
}
insilmaril@473
  4913
insilmaril@528
  4914
insilmaril@528
  4915
void MapEditor::sendSelection()
insilmaril@473
  4916
{
insilmaril@531
  4917
	if (netstate!=Server) return;
insilmaril@531
  4918
	sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
insilmaril@528
  4919
}
insilmaril@528
  4920
insilmaril@528
  4921
void MapEditor::newServer()
insilmaril@528
  4922
{
insilmaril@531
  4923
	port=54321;
insilmaril@531
  4924
	sendCounter=0;
insilmaril@528
  4925
    tcpServer = new QTcpServer(this);
insilmaril@531
  4926
    if (!tcpServer->listen(QHostAddress::Any,port)) {
insilmaril@528
  4927
        QMessageBox::critical(this, "vym server",
insilmaril@528
  4928
                              QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
insilmaril@528
  4929
        close();
insilmaril@528
  4930
        return;
insilmaril@528
  4931
    }
insilmaril@528
  4932
	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
insilmaril@531
  4933
	netstate=Server;
insilmaril@534
  4934
	cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
insilmaril@473
  4935
}
insilmaril@473
  4936
insilmaril@531
  4937
void MapEditor::connectToServer()
insilmaril@531
  4938
{
insilmaril@531
  4939
	port=54321;
insilmaril@531
  4940
	server="salam.suse.de";
insilmaril@531
  4941
	server="localhost";
insilmaril@531
  4942
	clientSocket = new QTcpSocket (this);
insilmaril@531
  4943
	clientSocket->abort();
insilmaril@531
  4944
    clientSocket->connectToHost(server ,port);
insilmaril@531
  4945
	connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
insilmaril@531
  4946
    connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
insilmaril@531
  4947
            this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
insilmaril@531
  4948
	netstate=Client;		
insilmaril@658
  4949
	cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
insilmaril@531
  4950
insilmaril@531
  4951
	
insilmaril@531
  4952
}
insilmaril@531
  4953
insilmaril@527
  4954
void MapEditor::newClient()
insilmaril@527
  4955
{
insilmaril@527
  4956
    QTcpSocket *newClient = tcpServer->nextPendingConnection();
insilmaril@527
  4957
    connect(newClient, SIGNAL(disconnected()),
insilmaril@527
  4958
            newClient, SLOT(deleteLater()));
insilmaril@527
  4959
insilmaril@658
  4960
	cout <<"ME::newClient  at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
insilmaril@527
  4961
insilmaril@527
  4962
	clientList.append (newClient);
insilmaril@527
  4963
}
insilmaril@473
  4964
insilmaril@528
  4965
insilmaril@528
  4966
void MapEditor::sendData(const QString &s)
insilmaril@528
  4967
{
insilmaril@537
  4968
	if (clientList.size()==0) return;
insilmaril@537
  4969
insilmaril@528
  4970
	// Create bytearray to send
insilmaril@528
  4971
	QByteArray block;
insilmaril@528
  4972
    QDataStream out(&block, QIODevice::WriteOnly);
insilmaril@528
  4973
    out.setVersion(QDataStream::Qt_4_0);
insilmaril@528
  4974
insilmaril@528
  4975
	// Reserve some space for blocksize
insilmaril@528
  4976
    out << (quint16)0;
insilmaril@528
  4977
insilmaril@531
  4978
	// Write sendCounter
insilmaril@531
  4979
    out << sendCounter++;
insilmaril@531
  4980
insilmaril@528
  4981
	// Write data
insilmaril@528
  4982
    out << s;
insilmaril@528
  4983
insilmaril@528
  4984
	// Go back and write blocksize so far
insilmaril@528
  4985
    out.device()->seek(0);
insilmaril@531
  4986
    quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
insilmaril@531
  4987
	out << bs;
insilmaril@531
  4988
insilmaril@537
  4989
	if (debug)
insilmaril@658
  4990
		cout << "ME::sendData  bs="<<bs<<"  counter="<<sendCounter<<"  s="<<qPrintable(s)<<endl;
insilmaril@528
  4991
insilmaril@528
  4992
	for (int i=0; i<clientList.size(); ++i)
insilmaril@528
  4993
	{
insilmaril@658
  4994
		//cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
insilmaril@528
  4995
		clientList.at(i)->write (block);
insilmaril@528
  4996
	}
insilmaril@528
  4997
}
insilmaril@531
  4998
insilmaril@531
  4999
void MapEditor::readData ()
insilmaril@531
  5000
{
insilmaril@531
  5001
	while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
insilmaril@531
  5002
	{
insilmaril@537
  5003
		if (debug)
insilmaril@537
  5004
			cout <<"readData  bytesAvail="<<clientSocket->bytesAvailable();
insilmaril@534
  5005
		quint16 recCounter;
insilmaril@534
  5006
		quint16 blockSize;
insilmaril@534
  5007
insilmaril@534
  5008
		QDataStream in(clientSocket);
insilmaril@534
  5009
		in.setVersion(QDataStream::Qt_4_0);
insilmaril@534
  5010
insilmaril@534
  5011
		in >> blockSize;
insilmaril@534
  5012
		in >> recCounter;
insilmaril@534
  5013
		
insilmaril@534
  5014
		QString t;
insilmaril@534
  5015
		in >>t;
insilmaril@537
  5016
		if (debug)
insilmaril@658
  5017
			cout << "  t="<<qPrintable (t)<<endl;
insilmaril@534
  5018
		parseAtom (t);
insilmaril@531
  5019
	}
insilmaril@534
  5020
	return;
insilmaril@531
  5021
}
insilmaril@531
  5022
insilmaril@531
  5023
void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
insilmaril@531
  5024
{
insilmaril@531
  5025
    switch (socketError) {
insilmaril@531
  5026
    case QAbstractSocket::RemoteHostClosedError:
insilmaril@531
  5027
        break;
insilmaril@531
  5028
    case QAbstractSocket::HostNotFoundError:
insilmaril@645
  5029
        QMessageBox::information(this, vymName +" Network client",
insilmaril@531
  5030
                                 "The host was not found. Please check the "
insilmaril@531
  5031
                                    "host name and port settings.");
insilmaril@531
  5032
        break;
insilmaril@531
  5033
    case QAbstractSocket::ConnectionRefusedError:
insilmaril@645
  5034
        QMessageBox::information(this, vymName + " Network client",
insilmaril@531
  5035
                                 "The connection was refused by the peer. "
insilmaril@531
  5036
                                    "Make sure the fortune server is running, "
insilmaril@531
  5037
                                    "and check that the host name and port "
insilmaril@531
  5038
                                    "settings are correct.");
insilmaril@531
  5039
        break;
insilmaril@531
  5040
    default:
insilmaril@645
  5041
        QMessageBox::information(this, vymName + " Network client",
insilmaril@531
  5042
                                 QString("The following error occurred: %1.")
insilmaril@531
  5043
                                 .arg(clientSocket->errorString()));
insilmaril@531
  5044
    }
insilmaril@531
  5045
}
insilmaril@531
  5046
insilmaril@528
  5047
void MapEditor::autosave()
insilmaril@528
  5048
{
insilmaril@528
  5049
	// Disable autosave, while we have gone back in history
insilmaril@528
  5050
	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
insilmaril@528
  5051
	if (redosAvail>0) return;
insilmaril@528
  5052
insilmaril@528
  5053
insilmaril@528
  5054
	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
insilmaril@528
  5055
		mainWindow->fileSave (this);
insilmaril@528
  5056
}
insilmaril@528
  5057
insilmaril@528
  5058
insilmaril@491
  5059
/*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
insilmaril@417
  5060
{
insilmaril@408
  5061
insilmaril@408
  5062
		} else if (event->provides("application/x-moz-file-promise-url") && 
insilmaril@408
  5063
			 event->provides("application/x-moz-nativeimage")) 
insilmaril@408
  5064
		{
insilmaril@129
  5065
			// Contains url to the img src in unicode16
insilmaril@128
  5066
			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
insilmaril@128
  5067
			QString url = QString((const QChar*)d.data(),d.size()/2);
insilmaril@408
  5068
			fetchImage(url);
insilmaril@408
  5069
			event->accept();
insilmaril@128
  5070
			update=true;
insilmaril@408
  5071
		} else if (event->provides ("text/uri-list"))
insilmaril@408
  5072
		{	// Uris provided e.g. by konqueror
insilmaril@408
  5073
			Q3UriDrag::decode (event,uris);
insilmaril@408
  5074
		} else if (event->provides ("_NETSCAPE_URL"))
insilmaril@128
  5075
		{	// Uris provided by Mozilla
insilmaril@129
  5076
		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
insilmaril@129
  5077
		  uris.append(l[0]);
insilmaril@129
  5078
		  heading = l[1];
insilmaril@129
  5079
		} else if (event->provides("text/html")) {
insilmaril@129
  5080
insilmaril@129
  5081
		  // Handels text mime types
insilmaril@129
  5082
		  // Look like firefox allways handle text as unicode16 (2 bytes per char.)
insilmaril@129
  5083
		  QByteArray d = event->encodedData("text/html");
insilmaril@129
  5084
		  QString text;
insilmaril@129
  5085
		  if (isUnicode16(d)) 
insilmaril@129
  5086
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5087
		  else 
insilmaril@129
  5088
		    text = QString(d);
insilmaril@129
  5089
insilmaril@129
  5090
		  textEditor->setText(text);
insilmaril@129
  5091
insilmaril@129
  5092
		  event->accept();
insilmaril@129
  5093
		  update=true;
insilmaril@129
  5094
		} else if (event->provides("text/plain")) {
insilmaril@129
  5095
		  QByteArray d = event->encodedData("text/plain");
insilmaril@129
  5096
		  QString text;
insilmaril@129
  5097
		  if (isUnicode16(d))
insilmaril@129
  5098
		    text = QString((const QChar*)d.data(),d.size()/2);
insilmaril@129
  5099
		  else 
insilmaril@129
  5100
		    text = QString(d);
insilmaril@129
  5101
insilmaril@129
  5102
		  textEditor->setText(text);
insilmaril@129
  5103
		  
insilmaril@129
  5104
		  event->accept();
insilmaril@129
  5105
		  update= true;
insilmaril@128
  5106
		}
insilmaril@417
  5107
insilmaril@406
  5108
		*/
insilmaril@406
  5109
insilmaril@417
  5110
insilmaril@412
  5111
insilmaril@412
  5112
bool isUnicode16(const QByteArray &d) 
insilmaril@412
  5113
{
insilmaril@412
  5114
  // TODO: make more precise check for unicode 16.
insilmaril@412
  5115
  // Guess unicode16 if any of second bytes are zero
insilmaril@412
  5116
  unsigned int length = max(0,d.size()-2)/2;
insilmaril@412
  5117
  for (unsigned int i = 0; i<length ; i++)
insilmaril@412
  5118
    if (d.at(i*2+1)==0) return true;
insilmaril@412
  5119
  return false;
insilmaril@412
  5120
}
insilmaril@412
  5121
      
insilmaril@395
  5122
void MapEditor::addFloatImageInt (const QPixmap &img) 
insilmaril@119
  5123
{
insilmaril@424
  5124
	BranchObj *bo=xelection.getBranch();
insilmaril@424
  5125
	if (bo)
insilmaril@119
  5126
  {
insilmaril@395
  5127
	FloatImageObj *fio=bo->addFloatImage();
insilmaril@395
  5128
    fio->load(img);
insilmaril@505
  5129
    fio->setOriginalFilename("No original filename (image added by dropevent)");	
insilmaril@505
  5130
	QString s=bo->getSelectString();
insilmaril@505
  5131
	saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio  );
insilmaril@505
  5132
	saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
insilmaril@645
  5133
    model->reposition();
insilmaril@408
  5134
    scene()->update();
insilmaril@119
  5135
  }
insilmaril@119
  5136
}
insilmaril@119
  5137
insilmaril@412
  5138
/*
insilmaril@412
  5139
insilmaril@412
  5140
void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) 
insilmaril@119
  5141
{
insilmaril@119
  5142
  if (!imageBuffer) imageBuffer = new QBuffer();
insilmaril@119
  5143
  if (!imageBuffer->isOpen()) {
insilmaril@366
  5144
    imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
insilmaril@119
  5145
  }
insilmaril@119
  5146
  imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
insilmaril@119
  5147
}
insilmaril@119
  5148
insilmaril@119
  5149
insilmaril@366
  5150
void MapEditor::imageDataFinished(Q3NetworkOperation *nop) 
insilmaril@119
  5151
{
insilmaril@366
  5152
	if (nop->state()==Q3NetworkProtocol::StDone) {
insilmaril@129
  5153
		QPixmap img(imageBuffer->buffer());
insilmaril@395
  5154
		addFloatImageInt (img);
insilmaril@129
  5155
	}
insilmaril@129
  5156
insilmaril@129
  5157
	if (imageBuffer) {
insilmaril@129
  5158
		imageBuffer->close();
insilmaril@129
  5159
		if (imageBuffer) {
insilmaril@129
  5160
			imageBuffer->close();
insilmaril@129
  5161
			delete imageBuffer;
insilmaril@129
  5162
			imageBuffer = 0;
insilmaril@129
  5163
		}
insilmaril@129
  5164
	}
insilmaril@119
  5165
}
insilmaril@119
  5166
insilmaril@129
  5167
void MapEditor::fetchImage(const QString &url) 
insilmaril@119
  5168
{
insilmaril@119
  5169
  if (urlOperator) {
insilmaril@119
  5170
    urlOperator->stop();
insilmaril@119
  5171
    disconnect(urlOperator);
insilmaril@119
  5172
    delete urlOperator;
insilmaril@119
  5173
  }
insilmaril@119
  5174
  
insilmaril@366
  5175
  urlOperator = new Q3UrlOperator(url);
insilmaril@366
  5176
  connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), 
insilmaril@366
  5177
	  this, SLOT(imageDataFinished(Q3NetworkOperation*)));
insilmaril@366
  5178
insilmaril@366
  5179
  connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
insilmaril@366
  5180
	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
insilmaril@119
  5181
  urlOperator->get();
insilmaril@119
  5182
}
insilmaril@412
  5183
*/
insilmaril@412
  5184