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