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