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