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