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