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