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