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