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