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