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