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