mapeditor.cpp
author insilmaril
Wed, 29 Mar 2006 09:11:09 +0000
changeset 267 5d0cbeb02bf3
parent 266 7d91b35c1b6f
child 269 4c3e9fa0093b
permissions -rw-r--r--
Use CTRL-Click to open URL in a tab (instead of ALT)
insilmaril@0
     1
#include "mapeditor.h"
insilmaril@0
     2
insilmaril@0
     3
#include <qstatusbar.h>
insilmaril@0
     4
#include <qmessagebox.h>
insilmaril@0
     5
#include <qapplication.h>
insilmaril@0
     6
#include <qpainter.h>
insilmaril@0
     7
#include <qpopupmenu.h>
insilmaril@0
     8
#include <qprinter.h>
insilmaril@0
     9
#include <qpaintdevicemetrics.h>
insilmaril@0
    10
#include <qfile.h>
insilmaril@0
    11
#include <qfiledialog.h>
insilmaril@0
    12
#include <qdir.h>
insilmaril@0
    13
#include <qcolor.h>
insilmaril@0
    14
#include <qcolordialog.h>
insilmaril@0
    15
#include <qbitmap.h>
insilmaril@0
    16
#include <qprocess.h>
insilmaril@0
    17
#include <qinputdialog.h>
insilmaril@119
    18
#include <qdragobject.h>
insilmaril@119
    19
#include <qurloperator.h>
insilmaril@119
    20
#include <qnetworkprotocol.h>
insilmaril@129
    21
#include <qregexp.h>
insilmaril@0
    22
insilmaril@0
    23
#include <iostream>
insilmaril@95
    24
#include <cstdlib>
insilmaril@0
    25
#include <typeinfo>
insilmaril@0
    26
insilmaril@0
    27
#include "version.h"
insilmaril@0
    28
insilmaril@105
    29
#include "api.h"
insilmaril@175
    30
#include "editxlinkdialog.h"
insilmaril@175
    31
#include "exports.h"
insilmaril@175
    32
#include "extrainfodialog.h"
insilmaril@236
    33
#include "file.h"
insilmaril@175
    34
#include "linkablemapobj.h"
insilmaril@175
    35
#include "mainwindow.h"
insilmaril@175
    36
#include "misc.h"
insilmaril@175
    37
#include "settings.h"
insilmaril@175
    38
#include "texteditor.h"
insilmaril@0
    39
#include "xml.h"
insilmaril@0
    40
insilmaril@0
    41
insilmaril@0
    42
extern TextEditor *textEditor;
insilmaril@0
    43
extern int statusbarTime;
insilmaril@0
    44
extern Main *mainWindow;
insilmaril@164
    45
extern QString tmpVymDir;
insilmaril@166
    46
extern QString clipboardDir;
insilmaril@166
    47
extern bool clipboardEmpty;
insilmaril@0
    48
extern FlagRowObj *systemFlagsDefault;
insilmaril@0
    49
extern FlagRowObj *standardFlagsDefault;
insilmaril@0
    50
insilmaril@98
    51
extern QPtrList <QAction> actionListBranches;
insilmaril@98
    52
insilmaril@0
    53
extern QAction *actionFileSave;
insilmaril@0
    54
extern QAction *actionEditUndo;
insilmaril@0
    55
extern QAction *actionEditCopy;
insilmaril@0
    56
extern QAction *actionEditCut;
insilmaril@0
    57
extern QAction *actionEditPaste;
insilmaril@0
    58
extern QAction *actionEditMoveUp;
insilmaril@0
    59
extern QAction *actionEditMoveDown;
insilmaril@0
    60
extern QAction *actionEditToggleScroll;
insilmaril@0
    61
extern QAction *actionEditOpenURL;
insilmaril@266
    62
extern QAction *actionEditOpenURLTab;
insilmaril@0
    63
extern QAction *actionEditURL;
insilmaril@0
    64
extern QAction *actionEditHeading2URL;
insilmaril@0
    65
extern QAction *actionEditBugzilla2URL;
insilmaril@175
    66
extern QAction *actionEditFATE2URL;
insilmaril@0
    67
extern QAction *actionEditOpenVymLink;
insilmaril@0
    68
extern QAction *actionEditVymLink;
insilmaril@0
    69
extern QAction *actionEditDeleteVymLink;
insilmaril@243
    70
extern QAction *actionEditToggleHideExport;
insilmaril@0
    71
extern QAction *actionEditHeading;
insilmaril@0
    72
extern QAction *actionEditDelete;
insilmaril@0
    73
extern QAction *actionEditAddBranch;
insilmaril@0
    74
extern QAction *actionEditAddBranchAbove;
insilmaril@0
    75
extern QAction *actionEditAddBranchBelow;
insilmaril@98
    76
extern QAction *actionEditRemoveBranchHere;
insilmaril@98
    77
extern QAction *actionEditRemoveChilds;
insilmaril@0
    78
extern QAction *actionEditImportAdd;
insilmaril@0
    79
extern QAction *actionEditImportReplace;
insilmaril@0
    80
extern QAction *actionEditSaveBranch;
insilmaril@0
    81
extern QAction *actionEditSelectFirst;
insilmaril@0
    82
extern QAction *actionEditSelectLast;
insilmaril@0
    83
extern QAction *actionEditLoadImage;
insilmaril@0
    84
insilmaril@0
    85
extern QAction* actionFormatPickColor;
insilmaril@0
    86
extern QAction* actionFormatColorBranch;
insilmaril@0
    87
extern QAction* actionFormatColorSubtree;
insilmaril@0
    88
extern QAction *actionFormatLinkColorHint;
insilmaril@0
    89
extern QAction *actionFormatBackColor;
insilmaril@0
    90
extern QAction *actionFormatLinkColor;
insilmaril@0
    91
insilmaril@89
    92
extern QActionGroup* actionGroupModModes;
insilmaril@89
    93
extern QAction* actionModModeColor;
insilmaril@89
    94
extern QAction* actionModModeLink;
insilmaril@93
    95
extern QAction* actionModModeCopy;
insilmaril@89
    96
insilmaril@0
    97
extern QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
    98
extern QAction *actionFormatFrameNone;
insilmaril@0
    99
extern QAction *actionFormatFrameRectangle;
insilmaril@0
   100
insilmaril@0
   101
extern QActionGroup *actionGroupFormatLinkStyles;
insilmaril@175
   102
extern QAction *actionFormatIncludeImagesVer;
insilmaril@175
   103
extern QAction *actionFormatIncludeImagesHor;
insilmaril@160
   104
extern QAction *actionFormatHideLinkUnselected;
insilmaril@0
   105
extern QAction *actionFormatLinkStyleLine;
insilmaril@0
   106
extern QAction *actionFormatLinkStyleParabel;
insilmaril@0
   107
extern QAction *actionFormatLinkStylePolyLine;
insilmaril@0
   108
extern QAction *actionFormatLinkStylePolyParabel;
insilmaril@0
   109
insilmaril@0
   110
extern QAction *actionViewToggleNoteEditor;
insilmaril@0
   111
insilmaril@0
   112
extern QAction *actionSettingsAutoedit;
insilmaril@0
   113
extern QAction *actionSettingsAutoselectHeading;
insilmaril@0
   114
extern QAction *actionSettingsAutoselectText;
insilmaril@0
   115
extern QAction *actionSettingsPasteNewHeading;
insilmaril@103
   116
extern QAction *actionSettingsUseFlagGroups;
insilmaril@0
   117
insilmaril@0
   118
extern QPopupMenu *branchContextMenu;
insilmaril@89
   119
extern QPopupMenu *branchLinksContextMenu;
insilmaril@94
   120
extern QPopupMenu *branchLinksContextMenuDup;
insilmaril@0
   121
extern QPopupMenu *floatimageContextMenu;
insilmaril@0
   122
extern QPopupMenu *saveImageFormatMenu;
insilmaril@0
   123
extern QPopupMenu *exportImageFormatMenu;
insilmaril@0
   124
extern QPopupMenu *canvasContextMenu;
insilmaril@0
   125
insilmaril@0
   126
extern Settings settings;
insilmaril@0
   127
insilmaril@164
   128
int MapEditor::mapNum=0;	// make instance
insilmaril@0
   129
insilmaril@0
   130
///////////////////////////////////////////////////////////////////////
insilmaril@0
   131
///////////////////////////////////////////////////////////////////////
insilmaril@0
   132
MapEditor::MapEditor(
insilmaril@0
   133
	QWidget* parent, bool interactive, const char* name, WFlags f) :
insilmaril@119
   134
  QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
insilmaril@0
   135
{
insilmaril@0
   136
	//cout << "Constructor ME "<<this<<endl;
insilmaril@164
   137
	mapNum++;
insilmaril@0
   138
insilmaril@119
   139
    viewport()->setAcceptDrops(true);
insilmaril@119
   140
insilmaril@0
   141
    mapCanvas = new QCanvas(1000,800);
insilmaril@0
   142
	mapCanvas->setAdvancePeriod(30);
insilmaril@166
   143
	mapCanvas->setBackgroundColor (white);
insilmaril@0
   144
insilmaril@0
   145
    setCanvas (mapCanvas);
insilmaril@0
   146
	
insilmaril@160
   147
	// Always show scroll bars (automatic would flicker sometimes)
insilmaril@0
   148
	setVScrollBarMode ( QScrollView::AlwaysOn );
insilmaril@0
   149
	setHScrollBarMode ( QScrollView::AlwaysOn );
insilmaril@0
   150
insilmaril@0
   151
    mapCenter = new MapCenterObj(mapCanvas);
insilmaril@0
   152
    mapCenter->setVisibility (true);
insilmaril@0
   153
	mapCenter->setMapEditor (this);
insilmaril@93
   154
	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
insilmaril@175
   155
	mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
insilmaril@0
   156
insilmaril@0
   157
    printer=NULL;
insilmaril@0
   158
insilmaril@0
   159
    lineedit = new QLineEdit(this, "lineedit"  );
insilmaril@0
   160
    connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
insilmaril@0
   161
    lineedit->hide();
insilmaril@0
   162
insilmaril@0
   163
    actColor=black; setColor (actColor);
insilmaril@97
   164
	defLinkColor=QColor (0,0,255);
insilmaril@97
   165
	defXLinkColor=QColor (180,180,180);
insilmaril@0
   166
	linkcolorhint=DefaultColor;
insilmaril@0
   167
	linkstyle=StylePolyParabel;
insilmaril@0
   168
insilmaril@0
   169
	// Create bitmap cursors, patform dependant
insilmaril@0
   170
	#if defined(Q_OS_MACX)
insilmaril@0
   171
		#include "icons/cursorhandopen16.xpm"
insilmaril@0
   172
		#include "icons/cursorcolorpicker16.xpm"
insilmaril@0
   173
		QBitmap cb( 16, 16, chandopen, TRUE );
insilmaril@0
   174
		QBitmap cm( 16, 16, chandopenmask, TRUE );
insilmaril@0
   175
		handOpenCursor=QCursor ( cb, cm );		
insilmaril@0
   176
		// set hot spot to tip of picker			
insilmaril@0
   177
		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 ); 
insilmaril@0
   178
	#else
insilmaril@0
   179
		#include "icons/cursorhandopen.xpm"
insilmaril@0
   180
		#include "icons/cursorcolorpicker.xpm"
insilmaril@0
   181
insilmaril@0
   182
		QBitmap cb( 32, 32, chandopen, TRUE );
insilmaril@0
   183
		QBitmap cm( 32, 32, chandopenmask, TRUE );
insilmaril@0
   184
		handOpenCursor=QCursor ( cb, cm );		
insilmaril@0
   185
		// set hot spot to tip of picker			
insilmaril@0
   186
		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); 
insilmaril@0
   187
	#endif
insilmaril@0
   188
insilmaril@0
   189
	pickingColor=false;
insilmaril@91
   190
	drawingLink=false;
insilmaril@93
   191
	copyingObj=false;
insilmaril@0
   192
insilmaril@0
   193
    editingBO=NULL;
insilmaril@0
   194
    selection=NULL;
insilmaril@0
   195
    selectionLast=NULL;
insilmaril@0
   196
    movingObj=NULL;
insilmaril@0
   197
insilmaril@102
   198
	defXLinkWidth=1;
insilmaril@102
   199
	defXLinkColor=QColor (230,230,230);
insilmaril@102
   200
insilmaril@0
   201
    mapChanged=false;
insilmaril@0
   202
	mapDefault=true;
insilmaril@0
   203
	mapUnsaved=false;
insilmaril@0
   204
	
insilmaril@0
   205
	zipped=true;
insilmaril@0
   206
	filePath="";
insilmaril@0
   207
	fileName="unnamed";
insilmaril@0
   208
	mapName="";
insilmaril@0
   209
insilmaril@164
   210
	undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
insilmaril@163
   211
	undosAvail=0;	
insilmaril@163
   212
	undoNum=0;
insilmaril@163
   213
	
insilmaril@0
   214
	// Initialize find routine
insilmaril@0
   215
	itFind=NULL;				
insilmaril@0
   216
	EOFind=false;
insilmaril@0
   217
insilmaril@0
   218
	printFrame=true;
insilmaril@0
   219
	printFooter=true;
insilmaril@0
   220
insilmaril@139
   221
	blockReposition=false;
insilmaril@139
   222
	blockSaveState=false;
insilmaril@260
   223
insilmaril@260
   224
	hidemode=HideNone;
insilmaril@260
   225
insilmaril@0
   226
	isInteractive=interactive;
insilmaril@0
   227
	if (isInteractive)
insilmaril@0
   228
		// Create temporary files
insilmaril@0
   229
		makeTmpDirs();
insilmaril@0
   230
insilmaril@0
   231
	// Initially set movingCentre
insilmaril@0
   232
	updateViewCenter();
insilmaril@0
   233
insilmaril@0
   234
	mapCenter->reposition();	//	for positioning heading
insilmaril@0
   235
}
insilmaril@0
   236
insilmaril@0
   237
MapEditor::~MapEditor()
insilmaril@0
   238
{
insilmaril@119
   239
  if (imageBuffer) delete imageBuffer;
insilmaril@119
   240
  if (urlOperator) {
insilmaril@119
   241
    urlOperator->stop();
insilmaril@119
   242
    delete urlOperator;
insilmaril@119
   243
  }
insilmaril@119
   244
insilmaril@0
   245
	//cout <<"Destructor MapEditor\n";
insilmaril@0
   246
insilmaril@0
   247
	// Save Settings
insilmaril@0
   248
	//settings.writeEntry( "/vym/mapeditor/editmode/autoselect",  );
insilmaril@0
   249
insilmaril@0
   250
}
insilmaril@0
   251
insilmaril@0
   252
QColor MapEditor::color()
insilmaril@0
   253
{
insilmaril@0
   254
    return actColor;
insilmaril@0
   255
}
insilmaril@0
   256
insilmaril@0
   257
QColor MapEditor::backgroundColor()
insilmaril@0
   258
{
insilmaril@0
   259
    return mapCanvas->backgroundColor();
insilmaril@0
   260
}
insilmaril@0
   261
insilmaril@0
   262
MapCenterObj* MapEditor::getMapCenter()
insilmaril@0
   263
{
insilmaril@0
   264
    return mapCenter;
insilmaril@0
   265
}
insilmaril@0
   266
insilmaril@0
   267
QCanvas* MapEditor::getCanvas()
insilmaril@0
   268
{
insilmaril@0
   269
    return mapCanvas;
insilmaril@0
   270
}
insilmaril@0
   271
insilmaril@0
   272
void MapEditor::adjustCanvasSize()
insilmaril@0
   273
{
insilmaril@0
   274
	// To adjust the canvas to map, viewport size and position, we have to
insilmaril@0
   275
	// do some coordinate magic...
insilmaril@0
   276
	//
insilmaril@0
   277
	// Get rectangle of (scroll-)view. 
insilmaril@0
   278
	// We want to be in canvas coords, so
insilmaril@0
   279
	// we map. Important if view is zoomed...
insilmaril@0
   280
	QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
insilmaril@0
   281
												visibleWidth(), visibleHeight()) );	
insilmaril@0
   282
												
insilmaril@0
   283
	// Now we need the bounding box of view AND map to calc the correct canvas size.
insilmaril@0
   284
	// Why? Because if the map itself is moved out of view, the view has to be enlarged
insilmaril@0
   285
	// to avoid jumping aroung...
insilmaril@0
   286
	QRect map=mapCenter->getTotalBBox();
insilmaril@0
   287
insilmaril@0
   288
	// right edge - left edge
insilmaril@0
   289
	int cw= max(map.x() + map.width(),  view.x() + view.width())  - min(map.x(), view.x());
insilmaril@0
   290
	int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
insilmaril@0
   291
insilmaril@0
   292
insilmaril@0
   293
	if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
insilmaril@0
   294
		!mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
insilmaril@0
   295
	)	
insilmaril@0
   296
	{	
insilmaril@0
   297
		// move the map on canvas (in order to not move it on screen) this is neccessary
insilmaril@0
   298
		// a) if topleft corner of canvas is left or above topleft corner of view and also left of
insilmaril@0
   299
		//    above topleft corner of map. E.g. if map is completly inside view, but it would be possible 
insilmaril@0
   300
		//    to scroll to an empty area of canvas to the left.
insilmaril@0
   301
		// b) if topleft corner of map left of or above topleft of canvas
insilmaril@0
   302
		int dx=0;
insilmaril@0
   303
		int dy=0;
insilmaril@0
   304
insilmaril@0
   305
		if (cw > mapCanvas->width() )
insilmaril@0
   306
		{
insilmaril@0
   307
			if (map.x()<0) dx=-map.x();	
insilmaril@0
   308
		}
insilmaril@0
   309
		if (cw <  mapCanvas->width() )
insilmaril@0
   310
			dx=-min (view.x(),map.x());
insilmaril@0
   311
		if (ch > mapCanvas->height() )
insilmaril@0
   312
		{
insilmaril@0
   313
			if (map.y()<0) dy=-map.y();	
insilmaril@0
   314
		}
insilmaril@0
   315
		if (ch <  mapCanvas->height() )
insilmaril@0
   316
		{
insilmaril@0
   317
			dy=-min (view.y(),map.y());
insilmaril@0
   318
		}
insilmaril@0
   319
		// We really have to resize now. Let's go...
insilmaril@0
   320
		mapCanvas->resize (cw,ch);
insilmaril@0
   321
		if ( (dx!=0) || (dy!=0) ) 
insilmaril@0
   322
		{
insilmaril@0
   323
			mapCenter->moveAllBy(dx,dy);
insilmaril@0
   324
			mapCenter->reposition();
insilmaril@0
   325
insilmaril@0
   326
			// scroll the view (in order to not move map on screen)
insilmaril@0
   327
			scrollBy (dx,dy);
insilmaril@0
   328
		}	
insilmaril@0
   329
	}
insilmaril@0
   330
}
insilmaril@0
   331
insilmaril@139
   332
bool MapEditor::isRepositionBlocked()
insilmaril@0
   333
{
insilmaril@139
   334
	return blockReposition;
insilmaril@0
   335
}
insilmaril@0
   336
insilmaril@0
   337
void MapEditor::makeTmpDirs()
insilmaril@0
   338
{
insilmaril@0
   339
	// Create unique temporary directories
insilmaril@164
   340
	tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
insilmaril@164
   341
	QDir d;
insilmaril@164
   342
	d.mkdir (tmpMapDir,true);
insilmaril@0
   343
}
insilmaril@0
   344
insilmaril@106
   345
QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
insilmaril@0
   346
{
insilmaril@163
   347
	// tmpdir		temporary directory to which data will be written
insilmaril@0
   348
	// prefix		mapname, which will be appended to images etc.
insilmaril@0
   349
	// writeflags	Only write flags for "real" save of map, not undo
insilmaril@0
   350
	// offset		offset of bbox of whole map in canvas. 
insilmaril@0
   351
	//				Needed for XML export
insilmaril@0
   352
	
insilmaril@0
   353
	// Save Header
insilmaril@0
   354
	QString ls;
insilmaril@0
   355
	switch (linkstyle)
insilmaril@0
   356
	{
insilmaril@0
   357
		case StyleLine: 
insilmaril@0
   358
			ls="StyleLine";
insilmaril@0
   359
			break;
insilmaril@0
   360
		case StyleParabel:
insilmaril@0
   361
			ls="StyleParabel";
insilmaril@0
   362
			break;
insilmaril@0
   363
		case StylePolyLine:	
insilmaril@0
   364
			ls="StylePolyLine";
insilmaril@0
   365
			break;
insilmaril@0
   366
		default:
insilmaril@0
   367
			ls="StylePolyParabel";
insilmaril@0
   368
			break;
insilmaril@0
   369
	}	
insilmaril@0
   370
insilmaril@0
   371
	QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
insilmaril@0
   372
	QString colhint="";
insilmaril@0
   373
	if (linkcolorhint==HeadingColor) 
insilmaril@0
   374
		colhint=attribut("linkColorHint","HeadingColor");
insilmaril@0
   375
insilmaril@185
   376
	QString mapAttr=attribut("version",__VYM_VERSION);
insilmaril@106
   377
	if (!saveSelection)
insilmaril@0
   378
		mapAttr+= attribut("author",mapCenter->getAuthor()) +
insilmaril@0
   379
				  attribut("comment",mapCenter->getComment()) +
insilmaril@0
   380
			      attribut("date",mapCenter->getDate()) +
insilmaril@0
   381
		          attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
insilmaril@0
   382
		          attribut("linkStyle", ls ) +
insilmaril@97
   383
		          attribut("linkColor", defLinkColor.name() ) +
insilmaril@102
   384
		          attribut("defXLinkColor", defXLinkColor.name() ) +
insilmaril@102
   385
		          attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
insilmaril@0
   386
		          colhint; 
insilmaril@0
   387
	s+=beginElement("vymmap",mapAttr);
insilmaril@0
   388
	incIndent();
insilmaril@0
   389
insilmaril@0
   390
	// Find the used flags while traversing the tree
insilmaril@0
   391
	standardFlagsDefault->resetUsedCounter();
insilmaril@0
   392
	
insilmaril@166
   393
	// Reset the counters before saving
insilmaril@166
   394
	FloatImageObj (mapCanvas).resetSaveCounter();
insilmaril@166
   395
insilmaril@0
   396
	// Build xml recursivly
insilmaril@106
   397
	if (!saveSelection)
insilmaril@0
   398
		s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
insilmaril@0
   399
	else
insilmaril@0
   400
	{
insilmaril@106
   401
		if ( typeid(*saveSelection) == typeid(BranchObj) )
insilmaril@106
   402
			s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
insilmaril@166
   403
		else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
insilmaril@166
   404
			s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
insilmaril@166
   405
			
insilmaril@166
   406
		else if (selection && typeid(*selection)==typeid(BranchObj))
insilmaril@106
   407
				// This is used if selected branch is saved from mainwindow
insilmaril@163
   408
				s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
insilmaril@0
   409
	}
insilmaril@0
   410
insilmaril@0
   411
	// Save local settings
insilmaril@0
   412
	s+=settings.getXMLData (destPath);
insilmaril@0
   413
insilmaril@0
   414
	// Save selection
insilmaril@139
   415
	if (selection && !saveSelection ) 
insilmaril@0
   416
		s+=valueElement("select",selection->getSelectString());
insilmaril@0
   417
insilmaril@0
   418
	decIndent();
insilmaril@0
   419
	s+=endElement("vymmap");
insilmaril@0
   420
insilmaril@0
   421
	if (writeflags)
insilmaril@0
   422
		standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
insilmaril@0
   423
	return s;
insilmaril@0
   424
}
insilmaril@0
   425
insilmaril@0
   426
void MapEditor::saveState()
insilmaril@0
   427
{
insilmaril@163
   428
	// Save complete map
insilmaril@163
   429
	saveState (CompleteMap,"",NULL,"",NULL);
insilmaril@0
   430
}
insilmaril@0
   431
insilmaril@106
   432
void MapEditor::saveState(LinkableMapObj *undoSel)
insilmaril@0
   433
{
insilmaril@163
   434
	// save the given part of the map 
insilmaril@163
   435
	saveState (PartOfMap,"",undoSel,"",NULL);
insilmaril@105
   436
}
insilmaril@105
   437
insilmaril@163
   438
void MapEditor::saveState(const QString &uc, const QString &rc)
insilmaril@105
   439
{
insilmaril@163
   440
	// selection does not change during action,
insilmaril@163
   441
	// so just save commands for undo and redo
insilmaril@163
   442
	LinkableMapObj *unsel;
insilmaril@136
   443
	if (selection)
insilmaril@163
   444
		unsel=selection;
insilmaril@136
   445
	else
insilmaril@163
   446
		unsel=NULL;
insilmaril@163
   447
	saveState (UndoCommand,uc,unsel,rc,unsel);
insilmaril@106
   448
}
insilmaril@106
   449
insilmaril@163
   450
void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel) 
insilmaril@106
   451
{
insilmaril@163
   452
	saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
insilmaril@163
   453
}
insilmaril@163
   454
insilmaril@163
   455
void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
insilmaril@163
   456
{
insilmaril@163
   457
	// Main saveState
insilmaril@163
   458
insilmaril@139
   459
	if (blockSaveState) return;
insilmaril@139
   460
insilmaril@163
   461
	/* TODO remove after testing
insilmaril@163
   462
	cout << "ME::saveState()  begin\n"<<endl;
insilmaril@163
   463
	cout << "    undosTotal="<<undosTotal<<endl;
insilmaril@163
   464
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
   465
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
   466
	cout << "    ---------------------------"<<endl;
insilmaril@163
   467
	*/
insilmaril@131
   468
	setChanged();
insilmaril@136
   469
insilmaril@163
   470
	// Find out current undo directory
insilmaril@163
   471
	if (undosAvail<undosTotal) undosAvail++;
insilmaril@163
   472
	undoNum++;
insilmaril@163
   473
	if (undoNum>undosTotal) undoNum=1;
insilmaril@163
   474
	
insilmaril@163
   475
	QString backupXML;
insilmaril@163
   476
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
insilmaril@164
   477
	QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
insilmaril@164
   478
insilmaril@164
   479
	// Create bakMapDir if not available
insilmaril@164
   480
	QDir d(bakMapDir);
insilmaril@164
   481
	if (!d.exists()) 
insilmaril@164
   482
		makeSubDirs (bakMapDir);
insilmaril@163
   483
insilmaril@139
   484
	// Save current selection 
insilmaril@163
   485
	QString redoSelection="";
insilmaril@163
   486
	if (redoSel)
insilmaril@163
   487
		redoSelection=redoSel->getSelectString();
insilmaril@139
   488
insilmaril@139
   489
	// Save the object, which should be undone
insilmaril@163
   490
	QString undoSelection="";
insilmaril@136
   491
	if (undoSel)
insilmaril@136
   492
		undoSelection=undoSel->getSelectString();
insilmaril@136
   493
		
insilmaril@136
   494
	// Save depending on how much needs to be saved	
insilmaril@163
   495
	QString undoCommand="";
insilmaril@106
   496
	if (savemode==UndoCommand)
insilmaril@0
   497
	{
insilmaril@105
   498
		undoCommand=undoCom;
insilmaril@106
   499
		backupXML="";
insilmaril@106
   500
	}	
insilmaril@106
   501
	else if (savemode==PartOfMap && undoSel)
insilmaril@0
   502
	{
insilmaril@163
   503
		undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
insilmaril@106
   504
		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
insilmaril@106
   505
	} else
insilmaril@106
   506
	{
insilmaril@163
   507
		undoCommand="undoMap (\""+bakMapPath+"\")";
insilmaril@106
   508
		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
insilmaril@139
   509
		undoSelection="";
insilmaril@106
   510
	}
insilmaril@163
   511
	if (!backupXML.isEmpty())
insilmaril@163
   512
		// Write XML Data to disk
insilmaril@163
   513
		saveStringToDisk (QString(bakMapPath),backupXML);
insilmaril@163
   514
insilmaril@163
   515
	SimpleSettings set;
insilmaril@163
   516
	set.setEntry (QString("undoCommand"),undoCommand);
insilmaril@163
   517
	set.setEntry (QString("undoSelection"),undoSelection);
insilmaril@163
   518
	set.setEntry (QString("redoCommand"),redoCom);
insilmaril@163
   519
	set.setEntry (QString("redoSelection"),redoSelection);
insilmaril@163
   520
	set.writeSettings(QString(bakMapDir+"/commands"));
insilmaril@163
   521
insilmaril@163
   522
	/* TODO remove after testing
insilmaril@163
   523
	cout << "          into="<< bakMapDir<<endl;
insilmaril@163
   524
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
   525
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
   526
	cout << "    ---------------------------"<<endl;
insilmaril@163
   527
	cout << "    undoCom="<<undoCommand<<endl;
insilmaril@163
   528
	cout << "    undoSel="<<undoSelection<<endl;
insilmaril@163
   529
	cout << "    ---------------------------"<<endl;
insilmaril@163
   530
	cout << "    redoCom="<<redoCom<<endl;
insilmaril@163
   531
	cout << "    redoSel="<<redoSelection<<endl;
insilmaril@163
   532
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@106
   533
	*/
insilmaril@106
   534
}
insilmaril@106
   535
insilmaril@129
   536
void MapEditor::parseAtom(const QString &atom)
insilmaril@106
   537
{
insilmaril@106
   538
	API api;
insilmaril@163
   539
	QString s,t;
insilmaril@129
   540
	int x,y;
insilmaril@129
   541
	bool ok;
insilmaril@129
   542
insilmaril@129
   543
	// Split string s into command and parameters
insilmaril@129
   544
	api.parseCommand (atom);
insilmaril@129
   545
	QString com=api.command();
insilmaril@129
   546
	
insilmaril@106
   547
	// External commands
insilmaril@163
   548
	if (com=="moveBranchUp")
insilmaril@106
   549
		moveBranchUp();
insilmaril@129
   550
	else if (com=="moveBranchDown")
insilmaril@106
   551
		moveBranchDown();
insilmaril@129
   552
	else if (com=="move")
insilmaril@129
   553
	{
insilmaril@139
   554
		if (api.checkParamCount(2) && selection )
insilmaril@129
   555
		{	
insilmaril@129
   556
			x=api.parInt (ok,0);
insilmaril@129
   557
			if (ok)
insilmaril@129
   558
			{
insilmaril@129
   559
				y=api.parInt (ok,1);
insilmaril@130
   560
				if (ok) move (x,y);
insilmaril@129
   561
			}
insilmaril@129
   562
		}	
insilmaril@129
   563
	}
insilmaril@129
   564
	else if (com=="linkBranchToPos")
insilmaril@129
   565
	{
insilmaril@129
   566
		if (selection && typeid(*selection) == typeid(BranchObj) ) 
insilmaril@129
   567
		{
insilmaril@129
   568
			if (api.checkParamCount(4))
insilmaril@129
   569
			{
insilmaril@129
   570
				s=api.parString(ok,0);
insilmaril@129
   571
				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
insilmaril@129
   572
				if (dst)
insilmaril@129
   573
				{	
insilmaril@129
   574
					if (typeid(*dst) == typeid(BranchObj) ) 
insilmaril@139
   575
					{
insilmaril@139
   576
						// Get number in parent
insilmaril@139
   577
						x=api.parInt (ok,1);
insilmaril@139
   578
						if (ok)
insilmaril@163
   579
							((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
insilmaril@139
   580
					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
insilmaril@129
   581
					{
insilmaril@163
   582
						((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
insilmaril@139
   583
						// Get coordinates of mainbranch
insilmaril@129
   584
						x=api.parInt (ok,2);
insilmaril@129
   585
						if (ok)
insilmaril@129
   586
						{
insilmaril@129
   587
							y=api.parInt (ok,3);
insilmaril@163
   588
							if (ok) ((BranchObj*)selection)->move (x,y);
insilmaril@129
   589
						}
insilmaril@129
   590
					}	
insilmaril@129
   591
				}	
insilmaril@129
   592
			}
insilmaril@129
   593
		}
insilmaril@129
   594
	} else if (com=="setHeading")
insilmaril@129
   595
	{
insilmaril@129
   596
		if (api.checkParamCount(1))
insilmaril@129
   597
		{
insilmaril@129
   598
			s=api.parString (ok,0);
insilmaril@129
   599
			if (ok) setHeading (s);
insilmaril@129
   600
		}	
insilmaril@143
   601
	} else if (com=="setURL")
insilmaril@143
   602
	{
insilmaril@143
   603
		if (api.checkParamCount(1))
insilmaril@143
   604
		{
insilmaril@143
   605
			s=api.parString (ok,0);
insilmaril@143
   606
			if (ok) setURL(s);
insilmaril@143
   607
		}	
insilmaril@143
   608
	} else if (com=="setVymLink")
insilmaril@143
   609
	{
insilmaril@143
   610
		if (api.checkParamCount(1))
insilmaril@143
   611
		{
insilmaril@143
   612
			s=api.parString (ok,0);
insilmaril@143
   613
			if (ok) setVymLink(s);
insilmaril@143
   614
		}	
insilmaril@143
   615
	}
insilmaril@106
   616
	// Internal commands, used for undo etc.	
insilmaril@129
   617
	else if (com==QString("undoMap"))
insilmaril@139
   618
	{
insilmaril@163
   619
		if (api.checkParamCount(1))
insilmaril@163
   620
			undoXML("",api.parString (ok,0));
insilmaril@139
   621
	} else if (com==QString("undoPart"))
insilmaril@129
   622
	{
insilmaril@163
   623
		if (api.checkParamCount(2))
insilmaril@129
   624
		{
insilmaril@129
   625
			s=api.parString (ok,0);
insilmaril@163
   626
			t=api.parString (ok,1);
insilmaril@163
   627
			undoXML(s,t);	
insilmaril@129
   628
		}
insilmaril@129
   629
	} else if (com=="select")
insilmaril@129
   630
		if (api.checkParamCount(1))
insilmaril@129
   631
		{
insilmaril@129
   632
			s=api.parString(ok,0);
insilmaril@129
   633
			if (ok) select (s);
insilmaril@129
   634
		}	
insilmaril@106
   635
	else
insilmaril@163
   636
	{
insilmaril@129
   637
		api.setError ("Unknown command in: "+atom);
insilmaril@163
   638
		cout << "ME::parse   api should have error now...\n";
insilmaril@163
   639
	}
insilmaril@129
   640
insilmaril@129
   641
	// Any errors?
insilmaril@129
   642
	if (api.error())
insilmaril@106
   643
	{
insilmaril@106
   644
		cout << "MapEditor::parseAtom: Error!\n";
insilmaril@129
   645
		cout << "  "<<api.errorDesc()<<endl;
insilmaril@0
   646
	}	
insilmaril@0
   647
}
insilmaril@0
   648
insilmaril@106
   649
insilmaril@0
   650
void MapEditor::finishedLineEditNoSave()
insilmaril@0
   651
{
insilmaril@0
   652
	// This is called by finishedLineEdit or any MapEditor method,
insilmaril@0
   653
	// which wants to assure, that lineedits finish, before e.g. a branch is 
insilmaril@0
   654
	// deleted
insilmaril@0
   655
    
insilmaril@0
   656
	// After calling LineEdit and using the clipboard, the 
insilmaril@0
   657
    // focus is not any longer on the main widget, we
insilmaril@0
   658
    // have to restore it using parentWidget()->setFocus()
insilmaril@0
   659
insilmaril@0
   660
    if (editingBO!=NULL) 
insilmaril@0
   661
	{
insilmaril@0
   662
		editingBO->setHeading(lineedit->text() );
insilmaril@0
   663
		editingBO=NULL;
insilmaril@0
   664
		lineedit->releaseKeyboard();
insilmaril@0
   665
		lineedit->hide();
insilmaril@0
   666
		parentWidget()->setFocus();
insilmaril@0
   667
		mapCenter->reposition();
insilmaril@0
   668
		adjustCanvasSize();
insilmaril@0
   669
		ensureSelectionVisible();
insilmaril@0
   670
    }		
insilmaril@0
   671
}
insilmaril@0
   672
insilmaril@0
   673
insilmaril@0
   674
bool MapEditor::isDefault()
insilmaril@0
   675
{
insilmaril@0
   676
    return mapDefault;
insilmaril@0
   677
}
insilmaril@0
   678
insilmaril@0
   679
bool MapEditor::isUnsaved()
insilmaril@0
   680
{
insilmaril@0
   681
    return mapUnsaved;
insilmaril@0
   682
}
insilmaril@0
   683
insilmaril@0
   684
bool MapEditor::hasChanged()
insilmaril@0
   685
{
insilmaril@0
   686
    return mapChanged;
insilmaril@0
   687
}
insilmaril@0
   688
insilmaril@0
   689
void MapEditor::setChanged()
insilmaril@0
   690
{
insilmaril@0
   691
	mapChanged=true;
insilmaril@0
   692
	mapDefault=false;
insilmaril@0
   693
	mapUnsaved=true;
insilmaril@0
   694
	actionEditUndo->setEnabled (true);
insilmaril@0
   695
	actionFileSave->setEnabled (true);
insilmaril@0
   696
	findReset();
insilmaril@0
   697
}
insilmaril@0
   698
insilmaril@0
   699
void MapEditor::closeMap()
insilmaril@0
   700
{
insilmaril@0
   701
	// Finish open lineEdits
insilmaril@0
   702
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
   703
insilmaril@0
   704
	// Unselect before disabling the toolbar actions
insilmaril@0
   705
	if (selection) selection->unselect();
insilmaril@0
   706
	selection=NULL;
insilmaril@0
   707
	updateActions();
insilmaril@0
   708
insilmaril@0
   709
    clear();
insilmaril@0
   710
	close();
insilmaril@0
   711
}
insilmaril@0
   712
insilmaril@0
   713
void MapEditor::setFilePath(QString fname)
insilmaril@0
   714
{
insilmaril@0
   715
	setFilePath (fname,fname);
insilmaril@0
   716
}
insilmaril@0
   717
insilmaril@0
   718
void MapEditor::setFilePath(QString fname, QString destname)
insilmaril@0
   719
{
insilmaril@205
   720
	if (fname.isEmpty() || fname=="")
insilmaril@106
   721
	{
insilmaril@106
   722
		filePath="";
insilmaril@106
   723
		fileName="";
insilmaril@106
   724
		destPath="";
insilmaril@106
   725
	} else
insilmaril@106
   726
	{
insilmaril@106
   727
		filePath=fname;		// becomes absolute path
insilmaril@106
   728
		fileName=fname;		// gets stripped of path
insilmaril@106
   729
		destPath=destname;	// needed for vymlinks
insilmaril@106
   730
insilmaril@106
   731
		// If fname is not an absolute path, complete it
insilmaril@106
   732
		filePath=QDir(fname).absPath();
insilmaril@106
   733
		fileDir=filePath.left (1+filePath.findRev ("/"));
insilmaril@106
   734
insilmaril@106
   735
		// Set short name, too. Search from behind:
insilmaril@106
   736
		int i=fileName.findRev("/");
insilmaril@106
   737
		if (i>=0) fileName=fileName.remove (0,i+1);
insilmaril@106
   738
insilmaril@106
   739
		// Forget the .vym (or .xml) for name of map
insilmaril@106
   740
		mapName=fileName.left(fileName.findRev(".",-1,true) );
insilmaril@106
   741
	}
insilmaril@0
   742
}
insilmaril@0
   743
insilmaril@0
   744
QString MapEditor::getFilePath()
insilmaril@0
   745
{
insilmaril@0
   746
	return filePath;
insilmaril@0
   747
}
insilmaril@0
   748
insilmaril@0
   749
QString MapEditor::getFileName()
insilmaril@0
   750
{
insilmaril@0
   751
	return fileName;
insilmaril@0
   752
}
insilmaril@0
   753
insilmaril@0
   754
QString MapEditor::getMapName()
insilmaril@0
   755
{
insilmaril@0
   756
	return mapName;
insilmaril@0
   757
}
insilmaril@0
   758
insilmaril@0
   759
QString MapEditor::getDestPath()
insilmaril@0
   760
{
insilmaril@0
   761
	return destPath;
insilmaril@0
   762
}
insilmaril@0
   763
insilmaril@205
   764
ErrorCode MapEditor::load (QString fname, LoadMode lmode)
insilmaril@0
   765
{
insilmaril@0
   766
	// Finish open lineEdits
insilmaril@0
   767
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
   768
insilmaril@205
   769
	ErrorCode err=success;
insilmaril@0
   770
insilmaril@0
   771
	if (lmode==NewMap)
insilmaril@0
   772
	{
insilmaril@0
   773
		if (selection) selection->unselect();
insilmaril@0
   774
		selection=NULL;
insilmaril@0
   775
		mapCenter->clear();
insilmaril@0
   776
		mapCenter->setMapEditor(this);
insilmaril@0
   777
		// (map state is set later at end of load...)
insilmaril@0
   778
	} else
insilmaril@0
   779
	{
insilmaril@106
   780
		saveState(selection);
insilmaril@0
   781
	}	
insilmaril@0
   782
	
insilmaril@0
   783
    
insilmaril@0
   784
    mapBuilderHandler handler;
insilmaril@0
   785
	QFile file( fname );
insilmaril@0
   786
insilmaril@0
   787
	// I am paranoid: file should exist anyway
insilmaril@0
   788
	// according to check in mainwindow.
insilmaril@0
   789
	if (!file.exists() )
insilmaril@0
   790
	{
insilmaril@0
   791
		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
   792
				   tr("Couldn't open map " +fname)+".");
insilmaril@205
   793
		err=aborted;	
insilmaril@0
   794
	} else
insilmaril@0
   795
	{
insilmaril@139
   796
		blockReposition=true;
insilmaril@0
   797
		QXmlInputSource source( file);
insilmaril@0
   798
		QXmlSimpleReader reader;
insilmaril@0
   799
		reader.setContentHandler( &handler );
insilmaril@0
   800
		reader.setErrorHandler( &handler );
insilmaril@0
   801
		handler.setMapEditor( this );
insilmaril@0
   802
		handler.setTmpDir (filePath.left(filePath.findRev("/",-1)));	// needed to load files with rel. path
insilmaril@243
   803
		handler.setInputFile (file.name());
insilmaril@0
   804
		handler.setLoadMode (lmode);
insilmaril@163
   805
		blockSaveState=true;
insilmaril@0
   806
		bool ok = reader.parse( source );
insilmaril@139
   807
		blockReposition=false;
insilmaril@163
   808
		blockSaveState=false;
insilmaril@0
   809
		file.close();
insilmaril@0
   810
		if ( ok ) 
insilmaril@0
   811
		{
insilmaril@0
   812
			mapCenter->reposition();
insilmaril@0
   813
			adjustCanvasSize();
insilmaril@0
   814
			if (lmode==NewMap)
insilmaril@0
   815
			{
insilmaril@0
   816
				mapDefault=false;
insilmaril@0
   817
				mapChanged=false;
insilmaril@0
   818
				mapUnsaved=false;
insilmaril@0
   819
			}
insilmaril@0
   820
		} else 
insilmaril@0
   821
		{
insilmaril@0
   822
			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
insilmaril@0
   823
					   tr( handler.errorProtocol() ) );
insilmaril@0
   824
			// returnCode=1;	
insilmaril@0
   825
			// Still return "success": the map maybe at least
insilmaril@0
   826
			// partially read by the parser
insilmaril@0
   827
		}	
insilmaril@0
   828
	}	
insilmaril@0
   829
	updateActions();
insilmaril@205
   830
	return err;
insilmaril@0
   831
}
insilmaril@0
   832
insilmaril@0
   833
int MapEditor::save (const SaveMode &savemode)
insilmaril@0
   834
{
insilmaril@0
   835
	// Finish open lineEdits
insilmaril@0
   836
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
   837
insilmaril@0
   838
	int returnCode=0;
insilmaril@0
   839
insilmaril@106
   840
	// The SaveMode UndoCommand is not supported here
insilmaril@106
   841
	if (savemode==UndoCommand) return 1;
insilmaril@106
   842
insilmaril@0
   843
	// Create mapName and fileDir
insilmaril@0
   844
	makeSubDirs (fileDir);
insilmaril@0
   845
	QString fname;
insilmaril@0
   846
	if (saveZipped())
insilmaril@0
   847
		// save as .xml
insilmaril@0
   848
		fname=mapName+".xml";
insilmaril@0
   849
	else
insilmaril@0
   850
		// use name given by user, even if he chooses .doc
insilmaril@0
   851
		fname=fileName;
insilmaril@0
   852
insilmaril@0
   853
insilmaril@0
   854
	QString saveFile;
insilmaril@106
   855
	if (savemode==CompleteMap || selection==NULL)
insilmaril@106
   856
		saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
insilmaril@106
   857
	else	
insilmaril@106
   858
		saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
insilmaril@0
   859
insilmaril@163
   860
	if (!saveStringToDisk(fileDir+fname,saveFile))
insilmaril@0
   861
		return 1;
insilmaril@0
   862
insilmaril@0
   863
	if (returnCode==0)
insilmaril@0
   864
	{
insilmaril@0
   865
		mapChanged=false;
insilmaril@0
   866
		mapUnsaved=false;
insilmaril@0
   867
		actionFileSave->setEnabled(false);
insilmaril@0
   868
	}
insilmaril@0
   869
insilmaril@0
   870
	return returnCode;
insilmaril@0
   871
}
insilmaril@0
   872
insilmaril@0
   873
void MapEditor::setZipped (bool z)
insilmaril@0
   874
{
insilmaril@0
   875
	zipped=z;
insilmaril@0
   876
}
insilmaril@0
   877
insilmaril@0
   878
bool MapEditor::saveZipped ()
insilmaril@0
   879
{
insilmaril@0
   880
	return zipped;
insilmaril@0
   881
}
insilmaril@0
   882
insilmaril@0
   883
void MapEditor::print()
insilmaril@0
   884
{
insilmaril@0
   885
	// Finish open lineEdits
insilmaril@0
   886
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
   887
insilmaril@0
   888
	if ( !printer ) 
insilmaril@0
   889
	{
insilmaril@0
   890
		printer = new QPrinter;
insilmaril@0
   891
		printer->setColorMode (QPrinter::Color);
insilmaril@119
   892
		printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
insilmaril@0
   893
	}
insilmaril@0
   894
insilmaril@0
   895
	QRect totalBBox=mapCenter->getTotalBBox();
insilmaril@0
   896
insilmaril@0
   897
	// Try to set orientation automagically
insilmaril@0
   898
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
   899
	// there are problems with landscape mode, see
insilmaril@0
   900
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
   901
insilmaril@0
   902
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
   903
		// recommend landscape
insilmaril@0
   904
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
   905
	else	
insilmaril@0
   906
		// recommend portrait
insilmaril@0
   907
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
   908
insilmaril@0
   909
	if ( printer->setup(this) ) 
insilmaril@0
   910
	// returns false, if printing is canceled
insilmaril@0
   911
	{
insilmaril@0
   912
		QPainter pp(printer);
insilmaril@0
   913
insilmaril@0
   914
		// Don't print the visualisation of selection
insilmaril@0
   915
		LinkableMapObj *oldselection=NULL;
insilmaril@0
   916
		if (selection) 
insilmaril@0
   917
		{
insilmaril@0
   918
			oldselection=selection;
insilmaril@0
   919
			selection->unselect();
insilmaril@0
   920
		}
insilmaril@0
   921
insilmaril@0
   922
		// Handle sizes of map and paper:
insilmaril@0
   923
		//
insilmaril@0
   924
		// setWindow defines which part of the canvas will be transformed 
insilmaril@0
   925
		// setViewport defines area on paper in device coordinates (dpi)
insilmaril@0
   926
		// e.g. (0,50,700,700) is upper part on A4
insilmaril@0
   927
		// see also /usr/lib/qt3/doc/html/coordsys.html
insilmaril@0
   928
insilmaril@0
   929
		QPaintDeviceMetrics metrics (printer);
insilmaril@0
   930
insilmaril@0
   931
		double paperAspect = (double)metrics.width()   / (double)metrics.height();
insilmaril@0
   932
		double   mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
insilmaril@0
   933
insilmaril@102
   934
		QRect mapRect=totalBBox;
insilmaril@0
   935
		QCanvasRectangle *frame=NULL;
insilmaril@0
   936
		QCanvasText *footerFN=NULL;
insilmaril@0
   937
		QCanvasText *footerDate=NULL;
insilmaril@0
   938
		if (printFrame || printFooter)
insilmaril@0
   939
		{
insilmaril@0
   940
			
insilmaril@0
   941
			if (printFrame) 
insilmaril@0
   942
			{
insilmaril@0
   943
				// Print frame around map
insilmaril@102
   944
				mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@102
   945
					totalBBox.width()+20, totalBBox.height()+20);
insilmaril@0
   946
				frame=new QCanvasRectangle (mapRect,mapCanvas);
insilmaril@0
   947
				frame->setBrush (QColor(white));
insilmaril@0
   948
				frame->setPen (QColor(black));
insilmaril@0
   949
				frame->setZ(0);
insilmaril@0
   950
				frame->show();    
insilmaril@0
   951
			}		
insilmaril@163
   952
			/* TODO remove after testing 
insilmaril@102
   953
			QCanvasLine *l=new QCanvasLine (mapCanvas);
insilmaril@102
   954
			l->setPoints (0,0,mapRect.width(),mapRect.height());
insilmaril@102
   955
			l->setPen (QPen(QColor(black), 1));
insilmaril@102
   956
			l->setZ (200);
insilmaril@102
   957
			l->show();
insilmaril@131
   958
			*/
insilmaril@102
   959
insilmaril@0
   960
			if (printFooter) 
insilmaril@0
   961
			{
insilmaril@0
   962
				// Print footer below map
insilmaril@0
   963
				QFont font;		
insilmaril@0
   964
				font.setPointSize(10);
insilmaril@0
   965
				footerFN=new QCanvasText (mapCanvas);
insilmaril@0
   966
				footerFN->setText ("VYM - " + fileName);
insilmaril@0
   967
				footerFN->setFont(font);
insilmaril@0
   968
				footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
insilmaril@0
   969
				footerFN->setZ(Z_TEXT);
insilmaril@0
   970
				footerFN->show();    
insilmaril@0
   971
				footerDate=new QCanvasText (mapCanvas);
insilmaril@0
   972
				footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
insilmaril@0
   973
				footerDate->setFont(font);
insilmaril@0
   974
				footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
insilmaril@0
   975
				footerDate->setZ(Z_TEXT);
insilmaril@0
   976
				footerDate->show();    
insilmaril@0
   977
			}
insilmaril@102
   978
			pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
insilmaril@0
   979
		}	else	
insilmaril@0
   980
		{
insilmaril@0
   981
			pp.setWindow (mapRect);
insilmaril@0
   982
		}	
insilmaril@0
   983
insilmaril@0
   984
		if (mapAspect>=paperAspect)
insilmaril@0
   985
		{
insilmaril@0
   986
			// Fit horizontally to paper width
insilmaril@0
   987
			pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );	
insilmaril@0
   988
		}	else
insilmaril@0
   989
		{
insilmaril@0
   990
			// Fit vertically to paper height
insilmaril@0
   991
			pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());	
insilmaril@0
   992
		}	
insilmaril@0
   993
insilmaril@0
   994
		mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to printer
insilmaril@0
   995
insilmaril@0
   996
		// Delete Frame and footer
insilmaril@0
   997
		if (footerFN) 
insilmaril@0
   998
		{
insilmaril@0
   999
			delete (footerFN);
insilmaril@0
  1000
			delete (footerDate);
insilmaril@0
  1001
		}	
insilmaril@0
  1002
		if (frame)  delete (frame);
insilmaril@0
  1003
insilmaril@0
  1004
		// Restore selection
insilmaril@0
  1005
		if (oldselection) 
insilmaril@0
  1006
		{
insilmaril@0
  1007
			selection=oldselection;
insilmaril@0
  1008
			selection->select();
insilmaril@0
  1009
		}	
insilmaril@119
  1010
insilmaril@119
  1011
		// Save settings in vymrc
insilmaril@119
  1012
		settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
insilmaril@0
  1013
	}
insilmaril@0
  1014
}
insilmaril@0
  1015
insilmaril@0
  1016
QPixmap MapEditor::getPixmap()
insilmaril@0
  1017
{
insilmaril@0
  1018
	QRect mapRect=mapCenter->getTotalBBox();
insilmaril@0
  1019
	QPixmap pix (mapRect.size());
insilmaril@0
  1020
	QPainter pp (&pix);
insilmaril@0
  1021
insilmaril@0
  1022
	// Don't print the visualisation of selection
insilmaril@0
  1023
	LinkableMapObj *oldselection=NULL;
insilmaril@0
  1024
	if (selection) 
insilmaril@0
  1025
	{
insilmaril@0
  1026
		oldselection=selection;
insilmaril@0
  1027
		selection->unselect();
insilmaril@0
  1028
	}
insilmaril@0
  1029
insilmaril@0
  1030
	pp.setWindow (mapRect);
insilmaril@0
  1031
insilmaril@0
  1032
	mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to painter
insilmaril@0
  1033
insilmaril@0
  1034
insilmaril@0
  1035
	// Restore selection
insilmaril@0
  1036
	if (oldselection) 
insilmaril@0
  1037
	{
insilmaril@0
  1038
		selection=oldselection;
insilmaril@0
  1039
		selection->select();
insilmaril@0
  1040
	}	
insilmaril@0
  1041
	
insilmaril@0
  1042
	return pix;
insilmaril@0
  1043
}
insilmaril@0
  1044
insilmaril@260
  1045
void MapEditor::setHideTmpMode (HideTmpMode mode)
insilmaril@260
  1046
{
insilmaril@260
  1047
	hidemode=mode;
insilmaril@260
  1048
	mapCenter->setHideTmp (hidemode);
insilmaril@260
  1049
	mapCenter->reposition();
insilmaril@260
  1050
	adjustCanvasSize();
insilmaril@260
  1051
	canvas()->update();
insilmaril@260
  1052
}
insilmaril@260
  1053
insilmaril@260
  1054
HideTmpMode MapEditor::getHideTmpMode()
insilmaril@260
  1055
{
insilmaril@260
  1056
	return hidemode;
insilmaril@260
  1057
}
insilmaril@260
  1058
insilmaril@0
  1059
void MapEditor::exportImage(QString fn)
insilmaril@0
  1060
{
insilmaril@0
  1061
	// Finish open lineEdits
insilmaril@0
  1062
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1063
insilmaril@260
  1064
	setExportMode (true);
insilmaril@0
  1065
	QPixmap pix (getPixmap());
insilmaril@0
  1066
	pix.save(fn, "PNG");
insilmaril@260
  1067
	setExportMode (false);
insilmaril@260
  1068
}
insilmaril@260
  1069
insilmaril@260
  1070
void MapEditor::setExportMode (bool b)
insilmaril@260
  1071
{
insilmaril@260
  1072
	// should be called before and after exports
insilmaril@260
  1073
	// depending on the settings
insilmaril@260
  1074
	if (b && settings.readEntry("/vym/export/useHideExport","yes"))
insilmaril@260
  1075
		setHideTmpMode (HideExport);
insilmaril@260
  1076
	else	
insilmaril@260
  1077
		setHideTmpMode (HideNone);
insilmaril@0
  1078
}
insilmaril@0
  1079
insilmaril@0
  1080
void MapEditor::exportImage(QString fn, int item)
insilmaril@0
  1081
{
insilmaril@0
  1082
	// Finish open lineEdits
insilmaril@0
  1083
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1084
insilmaril@260
  1085
	setExportMode (true);
insilmaril@0
  1086
	QPixmap pix (getPixmap());
insilmaril@0
  1087
	pix.save(fn, exportImageFormatMenu->text(item) );
insilmaril@260
  1088
	setExportMode (false);
insilmaril@0
  1089
}
insilmaril@0
  1090
insilmaril@185
  1091
void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
insilmaril@163
  1092
{
insilmaril@185
  1093
	ExportOO ex;
insilmaril@199
  1094
	ex.setFile (fn);
insilmaril@185
  1095
	ex.setMapCenter(mapCenter);
insilmaril@260
  1096
	if (ex.setConfigFile(cf)) 
insilmaril@260
  1097
	{
insilmaril@260
  1098
		setExportMode (true);
insilmaril@260
  1099
		ex.exportPresentation();
insilmaril@260
  1100
		setExportMode (false);
insilmaril@260
  1101
	}
insilmaril@163
  1102
}
insilmaril@163
  1103
insilmaril@163
  1104
insilmaril@0
  1105
insilmaril@0
  1106
void MapEditor::exportXML(const QString &dir)
insilmaril@0
  1107
{
insilmaril@260
  1108
	// Hide stuff during export, if settings want this
insilmaril@260
  1109
	setExportMode (true);
insilmaril@260
  1110
insilmaril@0
  1111
	// Create subdirectories
insilmaril@0
  1112
	makeSubDirs (dir);
insilmaril@0
  1113
insilmaril@0
  1114
	// write to directory
insilmaril@106
  1115
	QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
insilmaril@0
  1116
	QFile file;
insilmaril@0
  1117
insilmaril@0
  1118
	file.setName ( dir + "/"+mapName+".xml");
insilmaril@0
  1119
	if ( !file.open( IO_WriteOnly ) )
insilmaril@0
  1120
	{
insilmaril@0
  1121
		// This should neverever happen
insilmaril@159
  1122
		QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
insilmaril@0
  1123
		return;
insilmaril@0
  1124
	}	
insilmaril@0
  1125
insilmaril@0
  1126
	// Write it finally, and write in UTF8, no matter what 
insilmaril@0
  1127
	QTextStream ts( &file );
insilmaril@0
  1128
	ts.setEncoding (QTextStream::UnicodeUTF8);
insilmaril@0
  1129
	ts << saveFile;
insilmaril@0
  1130
	file.close();
insilmaril@0
  1131
insilmaril@0
  1132
	// Now write image, too
insilmaril@0
  1133
	exportImage (dir+"/images/"+mapName+".png");
insilmaril@260
  1134
insilmaril@260
  1135
	setExportMode (false);
insilmaril@0
  1136
}
insilmaril@0
  1137
insilmaril@0
  1138
void MapEditor::clear()
insilmaril@0
  1139
{
insilmaril@0
  1140
	if (selection)
insilmaril@0
  1141
	{
insilmaril@0
  1142
		selection->unselect();
insilmaril@0
  1143
		selection=NULL;
insilmaril@0
  1144
	}	
insilmaril@0
  1145
insilmaril@0
  1146
	mapCenter->clear();
insilmaril@0
  1147
}
insilmaril@0
  1148
insilmaril@0
  1149
void MapEditor::copy()
insilmaril@0
  1150
{
insilmaril@0
  1151
	// Finish open lineEdits
insilmaril@0
  1152
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1153
insilmaril@0
  1154
	if (selection) 
insilmaril@0
  1155
	{
insilmaril@166
  1156
		// write to directory
insilmaril@166
  1157
		QString clipfile="part";
insilmaril@166
  1158
		QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
insilmaril@166
  1159
		QFile file;
insilmaril@166
  1160
insilmaril@166
  1161
		file.setName ( clipboardDir + "/"+clipfile+".xml");
insilmaril@166
  1162
		if ( !file.open( IO_WriteOnly ) )
insilmaril@0
  1163
		{
insilmaril@166
  1164
			// This should neverever happen
insilmaril@166
  1165
			QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
insilmaril@166
  1166
			return;
insilmaril@166
  1167
		}	
insilmaril@166
  1168
insilmaril@166
  1169
		// Write it finally, and write in UTF8, no matter what 
insilmaril@166
  1170
		QTextStream ts( &file );
insilmaril@166
  1171
		ts.setEncoding (QTextStream::UnicodeUTF8);
insilmaril@166
  1172
		ts << saveFile;
insilmaril@166
  1173
		file.close();
insilmaril@166
  1174
insilmaril@166
  1175
		clipboardEmpty=false;
insilmaril@166
  1176
		updateActions();
insilmaril@0
  1177
	}	    
insilmaril@0
  1178
}
insilmaril@0
  1179
insilmaril@163
  1180
void MapEditor::redo()
insilmaril@163
  1181
{
insilmaril@163
  1182
	// Finish open lineEdits
insilmaril@163
  1183
	if (lineedit) finishedLineEditNoSave();
insilmaril@163
  1184
insilmaril@163
  1185
	blockSaveState=true;
insilmaril@163
  1186
	
insilmaril@163
  1187
	// Find out current undo directory
insilmaril@163
  1188
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
insilmaril@163
  1189
insilmaril@163
  1190
	// Restore variables
insilmaril@163
  1191
	QString undoCommand;
insilmaril@163
  1192
	QString undoSelection;
insilmaril@163
  1193
	QString redoCommand;
insilmaril@163
  1194
	QString redoSelection;
insilmaril@163
  1195
	SimpleSettings set;
insilmaril@163
  1196
	set.readSettings(QString(bakMapDir+"/commands"));
insilmaril@163
  1197
	undoCommand=set.readEntry ("undoCommand");
insilmaril@163
  1198
	undoSelection=set.readEntry ("undoSelection");
insilmaril@163
  1199
	redoCommand=set.readEntry ("redoCommand");
insilmaril@163
  1200
	redoSelection=set.readEntry ("redoSelection");
insilmaril@163
  1201
insilmaril@163
  1202
	// select  object before redo
insilmaril@163
  1203
	if (!redoSelection.isEmpty())
insilmaril@163
  1204
		select (redoSelection);
insilmaril@163
  1205
insilmaril@163
  1206
/* TODO remove testing
insilmaril@163
  1207
	cout << "ME::redo() begin\n";
insilmaril@163
  1208
	cout << "    undosTotal="<<undosTotal<<endl;
insilmaril@163
  1209
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
  1210
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
  1211
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1212
	cout << "    undoCom="<<undoCommand<<endl;
insilmaril@163
  1213
	cout << "    undoSel="<<undoSelection<<endl;
insilmaril@163
  1214
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1215
	cout << "    redoCom="<<redoCommand<<endl;
insilmaril@163
  1216
	cout << "    redoSel="<<redoSelection<<endl;
insilmaril@163
  1217
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1218
*/
insilmaril@163
  1219
	parseAtom (undoCommand);
insilmaril@163
  1220
	mapCenter->reposition();
insilmaril@163
  1221
insilmaril@163
  1222
	//if (!redoSelection.isEmpty())
insilmaril@163
  1223
	//	select (redoSelection);
insilmaril@163
  1224
insilmaril@163
  1225
	undosAvail--;
insilmaril@163
  1226
	if (undosAvail<1)
insilmaril@163
  1227
		// Undo not longer available now
insilmaril@163
  1228
		actionEditUndo->setEnabled (false);
insilmaril@163
  1229
	else	
insilmaril@163
  1230
		undoNum--; if (undoNum<1) undoNum=undosTotal;
insilmaril@163
  1231
insilmaril@163
  1232
	blockSaveState=false;
insilmaril@163
  1233
/* TODO remove testing
insilmaril@163
  1234
	cout << "ME::redo() end\n";
insilmaril@163
  1235
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
  1236
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
  1237
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@163
  1238
*/	
insilmaril@163
  1239
}
insilmaril@163
  1240
insilmaril@106
  1241
void MapEditor::undo()
insilmaril@106
  1242
{
insilmaril@106
  1243
	// Finish open lineEdits
insilmaril@106
  1244
	if (lineedit) finishedLineEditNoSave();
insilmaril@106
  1245
insilmaril@163
  1246
	blockSaveState=true;
insilmaril@163
  1247
	
insilmaril@163
  1248
	// Find out current undo directory
insilmaril@163
  1249
	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
insilmaril@163
  1250
insilmaril@163
  1251
	// Restore variables
insilmaril@163
  1252
	QString undoCommand;
insilmaril@163
  1253
	QString undoSelection;
insilmaril@163
  1254
	QString redoCommand;
insilmaril@163
  1255
	QString redoSelection;
insilmaril@163
  1256
	SimpleSettings set;
insilmaril@163
  1257
	set.readSettings(QString(bakMapDir+"/commands"));
insilmaril@163
  1258
	undoCommand=  set.readEntry ("undoCommand");
insilmaril@163
  1259
	undoSelection=set.readEntry ("undoSelection");
insilmaril@163
  1260
	redoCommand=  set.readEntry ("redoCommand");
insilmaril@163
  1261
	redoSelection=set.readEntry ("redoSelection");
insilmaril@163
  1262
insilmaril@136
  1263
	// select  object before undo
insilmaril@136
  1264
	if (!undoSelection.isEmpty())
insilmaril@136
  1265
		select (undoSelection);
insilmaril@136
  1266
insilmaril@164
  1267
/* TODO testing
insilmaril@163
  1268
	cout << "ME::undo() begin\n";
insilmaril@163
  1269
	cout << "    undosTotal="<<undosTotal<<endl;
insilmaril@163
  1270
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
  1271
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
  1272
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1273
	cout << "    undoCom="<<undoCommand<<endl;
insilmaril@163
  1274
	cout << "    undoSel="<<undoSelection<<endl;
insilmaril@163
  1275
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1276
	cout << "    redoCom="<<redoCommand<<endl;
insilmaril@163
  1277
	cout << "    redoSel="<<redoSelection<<endl;
insilmaril@163
  1278
	cout << "    ---------------------------"<<endl;
insilmaril@163
  1279
*/	
insilmaril@106
  1280
	parseAtom (undoCommand);
insilmaril@106
  1281
	mapCenter->reposition();
insilmaril@106
  1282
insilmaril@163
  1283
	//if (!redoSelection.isEmpty())
insilmaril@163
  1284
	//	select (redoSelection);
insilmaril@163
  1285
insilmaril@163
  1286
	undosAvail--;
insilmaril@163
  1287
	if (undosAvail<1)
insilmaril@163
  1288
		// Undo not longer available now
insilmaril@163
  1289
		actionEditUndo->setEnabled (false);
insilmaril@163
  1290
	else	
insilmaril@163
  1291
		undoNum--; if (undoNum<1) undoNum=undosTotal;
insilmaril@163
  1292
insilmaril@163
  1293
	blockSaveState=false;
insilmaril@163
  1294
/* TODO remove testing
insilmaril@163
  1295
	cout << "ME::undo() end\n";
insilmaril@163
  1296
	cout << "    undosAvail="<<undosAvail<<endl;
insilmaril@163
  1297
	cout << "       undoNum="<<undoNum<<endl;
insilmaril@163
  1298
	cout << "    ---------------------------"<<endl<<endl;
insilmaril@163
  1299
*/
insilmaril@106
  1300
}
insilmaril@106
  1301
insilmaril@163
  1302
void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
insilmaril@106
  1303
{
insilmaril@163
  1304
	QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
insilmaril@163
  1305
	QDir d(bakMapDir);
insilmaril@163
  1306
	QFile file (bakMapPath);
insilmaril@163
  1307
insilmaril@106
  1308
	if (d.exists() )
insilmaril@106
  1309
	{
insilmaril@106
  1310
		// We need to parse saved XML data
insilmaril@106
  1311
		mapBuilderHandler handler;
insilmaril@163
  1312
		QXmlInputSource source( file);
insilmaril@106
  1313
		QXmlSimpleReader reader;
insilmaril@106
  1314
		reader.setContentHandler( &handler );
insilmaril@106
  1315
		reader.setErrorHandler( &handler );
insilmaril@106
  1316
		handler.setMapEditor( this );
insilmaril@106
  1317
		handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
insilmaril@106
  1318
		if (undoSel.isEmpty())
insilmaril@106
  1319
		{
insilmaril@139
  1320
			unselect();
insilmaril@106
  1321
			mapCenter->clear();
insilmaril@106
  1322
			handler.setLoadMode (NewMap);
insilmaril@106
  1323
		} else	
insilmaril@106
  1324
		{
insilmaril@106
  1325
			select (undoSel);
insilmaril@106
  1326
			handler.setLoadMode (ImportReplace);
insilmaril@106
  1327
		}	
insilmaril@139
  1328
		blockReposition=true;
insilmaril@106
  1329
		bool ok = reader.parse( source );
insilmaril@139
  1330
		blockReposition=false;
insilmaril@106
  1331
		if (! ok ) 
insilmaril@106
  1332
		{	
insilmaril@106
  1333
			// This should never ever happen
insilmaril@106
  1334
			QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
insilmaril@163
  1335
								   tr( handler.errorProtocol() )+" in "+bakMapDir );
insilmaril@106
  1336
		}
insilmaril@106
  1337
	} else	
insilmaril@106
  1338
	{
insilmaril@106
  1339
		QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@159
  1340
			tr("Temporary directory %1 used for undo is gone. \n"
insilmaril@106
  1341
			"I will create a new one, but at the moment no undo is available.\n"
insilmaril@106
  1342
			"Maybe you want to reload your original data.\n\n"
insilmaril@159
  1343
			"Sorry for any inconveniences.").arg(bakMapDir) );
insilmaril@106
  1344
		makeTmpDirs();	
insilmaril@106
  1345
	}							
insilmaril@106
  1346
}
insilmaril@106
  1347
insilmaril@166
  1348
void MapEditor::pasteNoSave()
insilmaril@0
  1349
{
insilmaril@0
  1350
	// Finish open lineEdits
insilmaril@0
  1351
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1352
insilmaril@166
  1353
	load (clipboardDir+"/part.xml",ImportAdd);
insilmaril@0
  1354
}
insilmaril@0
  1355
insilmaril@0
  1356
void MapEditor::cutNoSave()
insilmaril@0
  1357
{
insilmaril@166
  1358
	copy();
insilmaril@166
  1359
	deleteSelection();
insilmaril@0
  1360
}
insilmaril@0
  1361
insilmaril@0
  1362
void MapEditor::paste()
insilmaril@0
  1363
{   
insilmaril@166
  1364
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@166
  1365
				      typeid(*selection) == typeid(MapCenterObj))) 
insilmaril@166
  1366
	{
insilmaril@166
  1367
		saveState(selection);
insilmaril@166
  1368
		pasteNoSave();
insilmaril@166
  1369
		mapCenter->reposition();
insilmaril@166
  1370
		adjustCanvasSize();
insilmaril@166
  1371
	}
insilmaril@0
  1372
}
insilmaril@0
  1373
insilmaril@0
  1374
void MapEditor::cut()
insilmaril@0
  1375
{
insilmaril@106
  1376
	saveState(selection->getParObj());
insilmaril@0
  1377
	copy();
insilmaril@0
  1378
	cutNoSave();
insilmaril@0
  1379
	mapCenter->reposition();
insilmaril@0
  1380
	adjustCanvasSize();
insilmaril@0
  1381
}
insilmaril@0
  1382
insilmaril@130
  1383
void MapEditor::move(const int &x, const int &y)
insilmaril@130
  1384
{
insilmaril@164
  1385
	// TODO no saveState, because this is only internal at undo so far
insilmaril@130
  1386
	if (selection) selection->move(x,y);
insilmaril@130
  1387
	if (typeid(*selection) == typeid(FloatImageObj))
insilmaril@163
  1388
		((FloatImageObj*)selection)->setRelPos();
insilmaril@130
  1389
}
insilmaril@130
  1390
insilmaril@0
  1391
void MapEditor::moveBranchUp()
insilmaril@0
  1392
{
insilmaril@0
  1393
	// Finish open lineEdits
insilmaril@0
  1394
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1395
insilmaril@0
  1396
	BranchObj* bo;
insilmaril@0
  1397
	BranchObj* par;
insilmaril@0
  1398
	if (typeid(*selection) == typeid(BranchObj)  ) 
insilmaril@0
  1399
	{
insilmaril@163
  1400
		bo=(BranchObj*)selection;
insilmaril@0
  1401
		par=(BranchObj*)(bo->getParObj());
insilmaril@0
  1402
		selection->unselect();
insilmaril@0
  1403
		selection=par->moveBranchUp (bo);
insilmaril@0
  1404
		selection->select();
insilmaril@163
  1405
		saveState("moveBranchDown ()",bo);
insilmaril@0
  1406
		mapCenter->reposition();
insilmaril@0
  1407
		ensureSelectionVisible();
insilmaril@0
  1408
	}
insilmaril@0
  1409
}
insilmaril@0
  1410
insilmaril@0
  1411
void MapEditor::moveBranchDown()
insilmaril@0
  1412
{
insilmaril@0
  1413
	// Finish open lineEdits
insilmaril@0
  1414
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1415
insilmaril@0
  1416
	BranchObj* bo;
insilmaril@0
  1417
	BranchObj* par;
insilmaril@0
  1418
	if (typeid(*selection) == typeid(BranchObj)  ) 
insilmaril@0
  1419
	{
insilmaril@163
  1420
		bo=(BranchObj*)selection;
insilmaril@0
  1421
		par=(BranchObj*)(bo->getParObj());
insilmaril@0
  1422
		selection->unselect(); 
insilmaril@0
  1423
		selection=par->moveBranchDown(bo);
insilmaril@0
  1424
		selection->select();
insilmaril@163
  1425
		saveState("moveBranchUp ()",bo);
insilmaril@0
  1426
		mapCenter->reposition();
insilmaril@0
  1427
		ensureSelectionVisible();
insilmaril@0
  1428
	}	
insilmaril@0
  1429
}
insilmaril@0
  1430
insilmaril@0
  1431
void MapEditor::editHeading()
insilmaril@0
  1432
{
insilmaril@0
  1433
	// Finish open lineEdits
insilmaril@0
  1434
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1435
insilmaril@0
  1436
	if (selection  &&  
insilmaril@0
  1437
		 (typeid(*selection) == typeid(BranchObj) || 
insilmaril@0
  1438
		  typeid(*selection) == typeid(MapCenterObj) ) ) 
insilmaril@0
  1439
	{
insilmaril@163
  1440
		editingBO=(BranchObj*)selection;
insilmaril@163
  1441
		saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
insilmaril@0
  1442
insilmaril@0
  1443
		ensureSelectionVisible();
insilmaril@93
  1444
		QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
insilmaril@0
  1445
		lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
insilmaril@93
  1446
		QString s=editingBO->getHeading();
insilmaril@0
  1447
		lineedit->setText(s);
insilmaril@0
  1448
		lineedit->setCursorPosition(1);
insilmaril@0
  1449
		if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
insilmaril@0
  1450
			lineedit->selectAll();
insilmaril@0
  1451
		lineedit->show();
insilmaril@0
  1452
		lineedit->grabKeyboard();
insilmaril@0
  1453
		lineedit->setFocus();
insilmaril@0
  1454
	}				
insilmaril@0
  1455
}
insilmaril@0
  1456
insilmaril@106
  1457
void MapEditor::setHeading(const QString &s)
insilmaril@106
  1458
{
insilmaril@106
  1459
	// Internal function, no saveState needed
insilmaril@106
  1460
	if (selection  &&  
insilmaril@106
  1461
		 (typeid(*selection) == typeid(BranchObj) || 
insilmaril@106
  1462
		  typeid(*selection) == typeid(MapCenterObj) ) ) 
insilmaril@106
  1463
	{
insilmaril@163
  1464
		((BranchObj*)selection)->setHeading(s);
insilmaril@106
  1465
		mapCenter->reposition();
insilmaril@106
  1466
		adjustCanvasSize();
insilmaril@106
  1467
		ensureSelectionVisible();
insilmaril@106
  1468
	}
insilmaril@106
  1469
}
insilmaril@106
  1470
insilmaril@143
  1471
void MapEditor::setURL (const QString &s)
insilmaril@143
  1472
{
insilmaril@143
  1473
	// Internal function, no saveState needed
insilmaril@143
  1474
	if (selection  &&  
insilmaril@143
  1475
		 (typeid(*selection) == typeid(BranchObj) || 
insilmaril@143
  1476
		  typeid(*selection) == typeid(MapCenterObj) ) ) 
insilmaril@143
  1477
	{
insilmaril@163
  1478
		((BranchObj*)selection)->setURL(s);
insilmaril@143
  1479
		mapCenter->reposition();
insilmaril@143
  1480
		adjustCanvasSize();
insilmaril@143
  1481
		ensureSelectionVisible();
insilmaril@143
  1482
	}
insilmaril@143
  1483
}
insilmaril@143
  1484
insilmaril@143
  1485
void MapEditor::setVymLink (const QString &s)
insilmaril@143
  1486
{
insilmaril@143
  1487
	// Internal function, no saveState needed
insilmaril@143
  1488
	if (selection  &&  
insilmaril@143
  1489
		 (typeid(*selection) == typeid(BranchObj) || 
insilmaril@143
  1490
		  typeid(*selection) == typeid(MapCenterObj) ) ) 
insilmaril@143
  1491
	{
insilmaril@163
  1492
		((BranchObj*)selection)->setVymLink(s);
insilmaril@143
  1493
		mapCenter->reposition();
insilmaril@143
  1494
		adjustCanvasSize();
insilmaril@143
  1495
		ensureSelectionVisible();
insilmaril@143
  1496
	}
insilmaril@143
  1497
}
insilmaril@143
  1498
insilmaril@0
  1499
void MapEditor::addNewBranch(int pos)
insilmaril@0
  1500
{
insilmaril@0
  1501
	// Finish open lineEdits
insilmaril@0
  1502
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1503
insilmaril@0
  1504
	if (selection  &&  
insilmaril@0
  1505
		 (typeid(*selection) == typeid(BranchObj) || 
insilmaril@0
  1506
		  typeid(*selection) == typeid(MapCenterObj) ) ) 
insilmaril@0
  1507
	{
insilmaril@164
  1508
		saveState(selection);	//TODO undoCommand
insilmaril@0
  1509
insilmaril@163
  1510
		BranchObj* bo1 = (BranchObj*) selection;
insilmaril@0
  1511
		bool wasScrolled=false;
insilmaril@0
  1512
		BranchObj *newbo=NULL;
insilmaril@0
  1513
		if (pos==0)
insilmaril@0
  1514
		{
insilmaril@0
  1515
			// save scroll state. If scrolled, automatically select
insilmaril@0
  1516
			// new branch in order to tmp unscroll parent...
insilmaril@0
  1517
			wasScrolled=bo1->isScrolled();
insilmaril@0
  1518
			newbo=bo1->addBranch();
insilmaril@0
  1519
		}	else 
insilmaril@0
  1520
		{
insilmaril@0
  1521
			BranchObj *parbo=(BranchObj*)(selection->getParObj());
insilmaril@0
  1522
			if (parbo)
insilmaril@0
  1523
			{
insilmaril@0
  1524
				if (pos<0)
insilmaril@0
  1525
					// add above selection
insilmaril@0
  1526
					newbo=parbo->insertBranch(bo1->getNum());
insilmaril@0
  1527
				else
insilmaril@0
  1528
					// add below selection
insilmaril@0
  1529
					newbo=parbo->insertBranch(bo1->getNum()+1);
insilmaril@0
  1530
			} else
insilmaril@0
  1531
				// This should not happen...
insilmaril@0
  1532
				return;
insilmaril@0
  1533
			
insilmaril@0
  1534
		}	
insilmaril@0
  1535
insilmaril@0
  1536
		LinkableMapObj *oldselection=selection;
insilmaril@0
  1537
insilmaril@0
  1538
		mapCenter->reposition();
insilmaril@0
  1539
		adjustCanvasSize();
insilmaril@0
  1540
		if (actionSettingsAutoedit->isOn() ||
insilmaril@0
  1541
			actionSettingsAutoselectHeading->isOn() )
insilmaril@0
  1542
		{
insilmaril@0
  1543
			selection->unselect();
insilmaril@0
  1544
			selection=newbo;
insilmaril@0
  1545
			selection->select();
insilmaril@0
  1546
			if (actionSettingsPasteNewHeading->isOn() )
insilmaril@0
  1547
			{
insilmaril@163
  1548
				BranchObj *bo2= (BranchObj*)selection;
insilmaril@0
  1549
				bo2->setHeading("");
insilmaril@0
  1550
			}	
insilmaril@0
  1551
			if (actionSettingsAutoedit->isOn() )
insilmaril@0
  1552
				editHeading();
insilmaril@0
  1553
			if (!actionSettingsAutoselectHeading->isOn()
insilmaril@0
  1554
				&& !wasScrolled)
insilmaril@0
  1555
			{
insilmaril@0
  1556
				selection->unselect();
insilmaril@0
  1557
				selection=oldselection;
insilmaril@0
  1558
				selection->select();
insilmaril@0
  1559
			}
insilmaril@0
  1560
		}	
insilmaril@0
  1561
	}	
insilmaril@0
  1562
}
insilmaril@0
  1563
insilmaril@98
  1564
insilmaril@98
  1565
void MapEditor::addNewBranchHere()
insilmaril@98
  1566
{
insilmaril@98
  1567
	// Finish open lineEdits
insilmaril@98
  1568
	if (lineedit) finishedLineEditNoSave();
insilmaril@98
  1569
insilmaril@98
  1570
	if (selection  &&  
insilmaril@98
  1571
		 (typeid(*selection) == typeid(BranchObj) ) )
insilmaril@98
  1572
	{
insilmaril@106
  1573
		saveState(selection);
insilmaril@98
  1574
insilmaril@163
  1575
		BranchObj* bo1 = (BranchObj*) selection;
insilmaril@98
  1576
		bool wasScrolled=false;
insilmaril@98
  1577
		BranchObj *newbo=NULL;
insilmaril@98
  1578
		BranchObj *parbo=(BranchObj*)(selection->getParObj());
insilmaril@98
  1579
		if (parbo)
insilmaril@98
  1580
		{
insilmaril@98
  1581
			// add below selection
insilmaril@98
  1582
			newbo=parbo->insertBranch(bo1->getNum()+1);
insilmaril@98
  1583
		} 
insilmaril@98
  1584
insilmaril@98
  1585
		LinkableMapObj *oldselection=selection;
insilmaril@163
  1586
		((BranchObj*)selection)->moveBranchTo (newbo,-1);
insilmaril@98
  1587
insilmaril@98
  1588
		mapCenter->reposition();
insilmaril@98
  1589
		adjustCanvasSize();
insilmaril@98
  1590
		if (actionSettingsAutoedit->isOn() ||
insilmaril@98
  1591
			actionSettingsAutoselectHeading->isOn() )
insilmaril@98
  1592
		{
insilmaril@98
  1593
			selection->unselect();
insilmaril@98
  1594
			selection=newbo;
insilmaril@98
  1595
			selection->select();
insilmaril@98
  1596
			if (actionSettingsPasteNewHeading->isOn() )
insilmaril@98
  1597
			{
insilmaril@163
  1598
				BranchObj *bo2= (BranchObj*)selection;
insilmaril@98
  1599
				bo2->setHeading("");
insilmaril@98
  1600
			}	
insilmaril@98
  1601
			if (actionSettingsAutoedit->isOn() )
insilmaril@98
  1602
				editHeading();
insilmaril@98
  1603
			if (!actionSettingsAutoselectHeading->isOn()
insilmaril@98
  1604
				&& !wasScrolled)
insilmaril@98
  1605
			{
insilmaril@98
  1606
				selection->unselect();
insilmaril@98
  1607
				selection=oldselection;
insilmaril@98
  1608
				selection->select();
insilmaril@98
  1609
			}
insilmaril@98
  1610
		}	
insilmaril@98
  1611
	}	
insilmaril@98
  1612
}
insilmaril@98
  1613
insilmaril@0
  1614
void MapEditor::deleteSelection()
insilmaril@0
  1615
{
insilmaril@0
  1616
	// Finish open lineEdits
insilmaril@0
  1617
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1618
insilmaril@0
  1619
	if (selection  && typeid(*selection) ==typeid(BranchObj) ) 
insilmaril@0
  1620
	{
insilmaril@139
  1621
		if (selection->getDepth()>1)
insilmaril@139
  1622
			// Normal branch, save parent with childs
insilmaril@139
  1623
			saveState(selection->getParObj());
insilmaril@139
  1624
		else
insilmaril@139
  1625
			// Mainbranch, save whole map
insilmaril@164
  1626
			// TODO Better would be to insert mainbranch again at pos
insilmaril@139
  1627
			// But undoCommand is missing right now
insilmaril@139
  1628
			saveState();
insilmaril@0
  1629
		BranchObj* bo=dynamic_cast <BranchObj*> (selection);
insilmaril@0
  1630
		BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@0
  1631
		bo->unselect();
insilmaril@0
  1632
		selection=NULL;
insilmaril@0
  1633
		par->removeBranch(bo);
insilmaril@0
  1634
		selection=par;
insilmaril@0
  1635
		selection->select();
insilmaril@0
  1636
		ensureSelectionVisible();
insilmaril@0
  1637
		mapCenter->reposition();
insilmaril@0
  1638
		adjustCanvasSize();
insilmaril@0
  1639
	}
insilmaril@0
  1640
	if (selection  && typeid(*selection) ==typeid(FloatImageObj) ) 
insilmaril@0
  1641
	{
insilmaril@106
  1642
		saveState(selection->getParObj());
insilmaril@0
  1643
		FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
insilmaril@0
  1644
		BranchObj* par=(BranchObj*)(fio->getParObj());
insilmaril@0
  1645
		fio->unselect();
insilmaril@0
  1646
		selection=NULL;
insilmaril@0
  1647
		par->removeFloatImage(fio);
insilmaril@0
  1648
		selection=par;
insilmaril@0
  1649
		selection->select();
insilmaril@0
  1650
		ensureSelectionVisible();
insilmaril@0
  1651
		mapCenter->reposition();
insilmaril@0
  1652
		adjustCanvasSize();
insilmaril@0
  1653
	}
insilmaril@0
  1654
}
insilmaril@0
  1655
insilmaril@0
  1656
LinkableMapObj* MapEditor::getSelection()
insilmaril@0
  1657
{
insilmaril@0
  1658
	return selection;
insilmaril@0
  1659
}
insilmaril@0
  1660
insilmaril@267
  1661
void MapEditor::unselect()
insilmaril@267
  1662
{
insilmaril@267
  1663
	if (selection) 
insilmaril@267
  1664
	{
insilmaril@267
  1665
		selectionLast=selection;
insilmaril@267
  1666
		selection->unselect();
insilmaril@267
  1667
		selection=NULL;
insilmaril@267
  1668
	}
insilmaril@267
  1669
}	
insilmaril@267
  1670
insilmaril@267
  1671
void MapEditor::reselect()
insilmaril@267
  1672
{
insilmaril@267
  1673
	if (selectionLast)
insilmaril@267
  1674
	{
insilmaril@267
  1675
		selection=selectionLast;
insilmaril@267
  1676
		selection->select();
insilmaril@267
  1677
		selectionLast=NULL;
insilmaril@267
  1678
	}
insilmaril@267
  1679
}	
insilmaril@267
  1680
insilmaril@83
  1681
bool MapEditor::select (const QString &s)
insilmaril@83
  1682
{
insilmaril@106
  1683
	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
insilmaril@0
  1684
insilmaril@0
  1685
	// Finally select the found object
insilmaril@0
  1686
	if (lmo)
insilmaril@0
  1687
	{
insilmaril@98
  1688
		if (selection) unselect();
insilmaril@0
  1689
		selection=lmo;
insilmaril@0
  1690
		selection->select();
insilmaril@0
  1691
		adjustCanvasSize();
insilmaril@0
  1692
		ensureSelectionVisible();
insilmaril@0
  1693
		return true;
insilmaril@139
  1694
	} 
insilmaril@139
  1695
	return false;
insilmaril@0
  1696
}
insilmaril@0
  1697
insilmaril@267
  1698
void MapEditor::select (LinkableMapObj *lmo)
insilmaril@0
  1699
{
insilmaril@267
  1700
	if (lmo && selection != lmo)
insilmaril@0
  1701
	{
insilmaril@267
  1702
		// select the MapObj
insilmaril@267
  1703
		if (selection) selection->unselect();
insilmaril@267
  1704
		selection=lmo;
insilmaril@267
  1705
		selection->select();
insilmaril@267
  1706
			
insilmaril@267
  1707
		adjustCanvasSize();
insilmaril@0
  1708
	}
insilmaril@267
  1709
insilmaril@267
  1710
}
insilmaril@0
  1711
insilmaril@0
  1712
void MapEditor::selectNextBranch()
insilmaril@0
  1713
{
insilmaril@0
  1714
	// Increase number of branch
insilmaril@0
  1715
	if (selection)
insilmaril@0
  1716
	{
insilmaril@0
  1717
		QString s=selection->getSelectString();
insilmaril@0
  1718
		QString part;
insilmaril@0
  1719
		QString typ;
insilmaril@0
  1720
		QString num;
insilmaril@0
  1721
insilmaril@0
  1722
		// Where am I? 
insilmaril@0
  1723
		part=s.section(",",-1);
insilmaril@0
  1724
		typ=part.left (3);
insilmaril@0
  1725
		num=part.right(part.length() - 3);
insilmaril@0
  1726
insilmaril@0
  1727
		s=s.left (s.length() -num.length());
insilmaril@0
  1728
insilmaril@0
  1729
		// Go to next lmo
insilmaril@0
  1730
		num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  1731
insilmaril@0
  1732
		s=s+num;
insilmaril@0
  1733
		
insilmaril@0
  1734
		// Try to select this one
insilmaril@0
  1735
		if (select (s)) return;
insilmaril@0
  1736
insilmaril@0
  1737
		// We have no direct successor, 
insilmaril@0
  1738
		// try to increase the parental number in order to
insilmaril@0
  1739
		// find a successor with same depth
insilmaril@0
  1740
insilmaril@0
  1741
		int d=selection->getDepth();
insilmaril@0
  1742
		int oldDepth=d;
insilmaril@0
  1743
		int i;
insilmaril@0
  1744
		bool found=false;
insilmaril@0
  1745
		bool b;
insilmaril@0
  1746
		while (!found && d>0)
insilmaril@0
  1747
		{
insilmaril@0
  1748
			s=s.section (",",0,d-1);
insilmaril@0
  1749
			// replace substring of current depth in s with "1"
insilmaril@0
  1750
			part=s.section(",",-1);
insilmaril@0
  1751
			typ=part.left (3);
insilmaril@0
  1752
			num=part.right(part.length() - 3);
insilmaril@0
  1753
insilmaril@0
  1754
			if (d>1)
insilmaril@0
  1755
			{	
insilmaril@0
  1756
				// increase number of parent
insilmaril@0
  1757
				num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  1758
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  1759
			} else
insilmaril@0
  1760
			{
insilmaril@0
  1761
				// Special case, look at orientation
insilmaril@0
  1762
				if (selection->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1763
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  1764
				else	
insilmaril@0
  1765
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  1766
				s=typ+num;
insilmaril@0
  1767
			}	
insilmaril@0
  1768
insilmaril@0
  1769
			if (select (s))
insilmaril@0
  1770
				// pad to oldDepth, select the first branch for each depth
insilmaril@0
  1771
				for (i=d;i<oldDepth;i++)
insilmaril@0
  1772
				{
insilmaril@0
  1773
					b=select (s);
insilmaril@0
  1774
					if (b)
insilmaril@0
  1775
					{	
insilmaril@163
  1776
						if ( ((BranchObj*)selection)->countBranches()>0)
insilmaril@0
  1777
							s+=",bo:0";
insilmaril@0
  1778
						else	
insilmaril@0
  1779
							break;
insilmaril@0
  1780
					} else
insilmaril@0
  1781
						break;
insilmaril@0
  1782
				}	
insilmaril@0
  1783
insilmaril@0
  1784
			// try to select the freshly built string
insilmaril@0
  1785
			found=select(s);
insilmaril@0
  1786
			d--;
insilmaril@0
  1787
		}
insilmaril@0
  1788
		return;
insilmaril@0
  1789
	}	
insilmaril@0
  1790
}
insilmaril@0
  1791
insilmaril@0
  1792
void MapEditor::selectPrevBranch()
insilmaril@0
  1793
{
insilmaril@0
  1794
	// Decrease number of branch
insilmaril@0
  1795
	if (selection)
insilmaril@0
  1796
	{
insilmaril@0
  1797
		QString s=selection->getSelectString();
insilmaril@0
  1798
		QString part;
insilmaril@0
  1799
		QString typ;
insilmaril@0
  1800
		QString num;
insilmaril@0
  1801
insilmaril@0
  1802
		// Where am I? 
insilmaril@0
  1803
		part=s.section(",",-1);
insilmaril@0
  1804
		typ=part.left (3);
insilmaril@0
  1805
		num=part.right(part.length() - 3);
insilmaril@0
  1806
insilmaril@0
  1807
		s=s.left (s.length() -num.length());
insilmaril@0
  1808
insilmaril@0
  1809
		// Go to next lmo
insilmaril@0
  1810
		num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  1811
insilmaril@0
  1812
		s=s+num;
insilmaril@0
  1813
		
insilmaril@0
  1814
		// Try to select this one
insilmaril@0
  1815
		if (select (s)) return;
insilmaril@0
  1816
insilmaril@0
  1817
		// We have no direct precessor, 
insilmaril@0
  1818
		// try to decrease the parental number in order to
insilmaril@0
  1819
		// find a precessor with same depth
insilmaril@0
  1820
insilmaril@0
  1821
		int d=selection->getDepth();
insilmaril@0
  1822
		int oldDepth=d;
insilmaril@0
  1823
		int i;
insilmaril@0
  1824
		bool found=false;
insilmaril@0
  1825
		bool b;
insilmaril@0
  1826
		while (!found && d>0)
insilmaril@0
  1827
		{
insilmaril@0
  1828
			s=s.section (",",0,d-1);
insilmaril@0
  1829
			// replace substring of current depth in s with "1"
insilmaril@0
  1830
			part=s.section(",",-1);
insilmaril@0
  1831
			typ=part.left (3);
insilmaril@0
  1832
			num=part.right(part.length() - 3);
insilmaril@0
  1833
insilmaril@0
  1834
			if (d>1)
insilmaril@0
  1835
			{
insilmaril@0
  1836
				// decrease number of parent
insilmaril@0
  1837
				num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  1838
				s=s.section (",",0,d-2) + ","+ typ+num;
insilmaril@0
  1839
			} else
insilmaril@0
  1840
			{
insilmaril@0
  1841
				// Special case, look at orientation
insilmaril@0
  1842
				if (selection->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1843
					num=QString ("%1").arg(num.toUInt()-1);
insilmaril@0
  1844
				else	
insilmaril@0
  1845
					num=QString ("%1").arg(num.toUInt()+1);
insilmaril@0
  1846
				s=typ+num;
insilmaril@0
  1847
			}	
insilmaril@0
  1848
insilmaril@0
  1849
			if (select(s))
insilmaril@0
  1850
				// pad to oldDepth, select the last branch for each depth
insilmaril@0
  1851
				for (i=d;i<oldDepth;i++)
insilmaril@0
  1852
				{
insilmaril@0
  1853
					b=select (s);
insilmaril@0
  1854
					if (b)
insilmaril@163
  1855
						if ( ((BranchObj*)selection)->countBranches()>0)
insilmaril@163
  1856
							s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
insilmaril@0
  1857
						else	
insilmaril@0
  1858
							break;
insilmaril@0
  1859
					else
insilmaril@0
  1860
						break;
insilmaril@0
  1861
				}	
insilmaril@0
  1862
			
insilmaril@0
  1863
			// try to select the freshly built string
insilmaril@0
  1864
			found=select(s);
insilmaril@0
  1865
			d--;
insilmaril@0
  1866
		}
insilmaril@0
  1867
		return;
insilmaril@0
  1868
	}	
insilmaril@0
  1869
}
insilmaril@0
  1870
insilmaril@0
  1871
void MapEditor::selectUpperBranch()
insilmaril@0
  1872
{
insilmaril@0
  1873
	// Finish open lineEdits
insilmaril@0
  1874
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1875
insilmaril@0
  1876
	if (selection) 
insilmaril@0
  1877
	{
insilmaril@0
  1878
		if (typeid(*selection) == typeid(BranchObj))
insilmaril@0
  1879
		{
insilmaril@0
  1880
			if (selection->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1881
				selectPrevBranch();
insilmaril@0
  1882
			else
insilmaril@0
  1883
				if (selection->getDepth()==1)
insilmaril@0
  1884
					selectNextBranch();
insilmaril@0
  1885
				else
insilmaril@0
  1886
					selectPrevBranch();
insilmaril@0
  1887
		}		
insilmaril@0
  1888
	}
insilmaril@0
  1889
}
insilmaril@0
  1890
insilmaril@0
  1891
void MapEditor::selectLowerBranch()
insilmaril@0
  1892
{
insilmaril@0
  1893
	// Finish open lineEdits
insilmaril@0
  1894
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1895
insilmaril@0
  1896
	if (selection) 
insilmaril@0
  1897
	{
insilmaril@0
  1898
		if (typeid(*selection) == typeid(BranchObj))
insilmaril@0
  1899
		{
insilmaril@0
  1900
			if (selection->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1901
				selectNextBranch();
insilmaril@0
  1902
			else
insilmaril@0
  1903
				if (selection->getDepth()==1)
insilmaril@0
  1904
					selectPrevBranch();
insilmaril@0
  1905
				else
insilmaril@0
  1906
					selectNextBranch();
insilmaril@0
  1907
		}		
insilmaril@0
  1908
	}
insilmaril@0
  1909
}
insilmaril@0
  1910
insilmaril@0
  1911
insilmaril@0
  1912
void MapEditor::selectLeftBranch()
insilmaril@0
  1913
{
insilmaril@0
  1914
	// Finish open lineEdits
insilmaril@0
  1915
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1916
insilmaril@0
  1917
	BranchObj* bo;
insilmaril@0
  1918
	BranchObj* par;
insilmaril@0
  1919
	if (selection) 
insilmaril@0
  1920
	{
insilmaril@0
  1921
		if (typeid(*selection) == typeid(MapCenterObj))
insilmaril@0
  1922
		{
insilmaril@163
  1923
			par=  (BranchObj*) selection;
insilmaril@0
  1924
			bo=par->getLastSelectedBranch();
insilmaril@0
  1925
			if (bo)
insilmaril@0
  1926
			{
insilmaril@0
  1927
				// Workaround for reselecting on left and right side
insilmaril@0
  1928
				if (bo->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1929
				{
insilmaril@0
  1930
					bo=par->getLastBranch();
insilmaril@0
  1931
				}	
insilmaril@0
  1932
				if (bo)
insilmaril@0
  1933
				{
insilmaril@0
  1934
					par->unselect();
insilmaril@0
  1935
					selection=bo;
insilmaril@0
  1936
					selection->select();
insilmaril@0
  1937
					adjustCanvasSize();
insilmaril@0
  1938
					ensureSelectionVisible();
insilmaril@0
  1939
				}
insilmaril@0
  1940
			}	
insilmaril@0
  1941
		} else
insilmaril@0
  1942
		{
insilmaril@0
  1943
			par=(BranchObj*)(selection->getParObj());
insilmaril@0
  1944
			if (selection->getOrientation()==OrientRightOfCenter)
insilmaril@0
  1945
			{
insilmaril@0
  1946
				if (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  1947
					typeid(*selection) == typeid(FloatImageObj))
insilmaril@0
  1948
				{
insilmaril@0
  1949
					selection->unselect();
insilmaril@0
  1950
					selection=par;
insilmaril@0
  1951
					selection->select();
insilmaril@0
  1952
					adjustCanvasSize();
insilmaril@0
  1953
					ensureSelectionVisible();
insilmaril@0
  1954
				}
insilmaril@0
  1955
			} else
insilmaril@0
  1956
			{
insilmaril@0
  1957
				if (typeid(*selection) == typeid(BranchObj) )
insilmaril@0
  1958
				{
insilmaril@163
  1959
					bo=((BranchObj*)selection)->getLastSelectedBranch();
insilmaril@0
  1960
					if (bo) 
insilmaril@0
  1961
					{
insilmaril@0
  1962
						selection->unselect();
insilmaril@0
  1963
						selection=bo;
insilmaril@0
  1964
						selection->select();
insilmaril@0
  1965
						adjustCanvasSize();
insilmaril@0
  1966
						ensureSelectionVisible();
insilmaril@0
  1967
					}
insilmaril@0
  1968
				}
insilmaril@0
  1969
			}
insilmaril@0
  1970
		}	
insilmaril@0
  1971
	}
insilmaril@0
  1972
}
insilmaril@0
  1973
insilmaril@0
  1974
void MapEditor::selectRightBranch()
insilmaril@0
  1975
{
insilmaril@0
  1976
	// Finish open lineEdits
insilmaril@0
  1977
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  1978
insilmaril@0
  1979
	BranchObj* bo;
insilmaril@0
  1980
	BranchObj* par;
insilmaril@0
  1981
insilmaril@0
  1982
	if (selection) 
insilmaril@0
  1983
	{
insilmaril@0
  1984
		if (typeid(*selection) == typeid(MapCenterObj))
insilmaril@0
  1985
		{
insilmaril@163
  1986
			par=  (BranchObj*) selection;
insilmaril@0
  1987
			bo=par->getLastSelectedBranch();
insilmaril@0
  1988
			if (bo)
insilmaril@0
  1989
			{
insilmaril@0
  1990
				// Workaround for relecting on left and right side
insilmaril@0
  1991
				if (bo->getOrientation()==OrientLeftOfCenter)
insilmaril@0
  1992
					bo=par->getFirstBranch();
insilmaril@0
  1993
				if (bo)
insilmaril@0
  1994
				{
insilmaril@0
  1995
					par->unselect();
insilmaril@0
  1996
					selection=bo;
insilmaril@0
  1997
					selection->select();
insilmaril@0
  1998
					ensureSelectionVisible();
insilmaril@0
  1999
				}
insilmaril@0
  2000
			}
insilmaril@0
  2001
		} else
insilmaril@0
  2002
		{
insilmaril@0
  2003
			par=(BranchObj*)(selection->getParObj());
insilmaril@0
  2004
			if (selection->getOrientation()==OrientLeftOfCenter)
insilmaril@0
  2005
			{
insilmaril@0
  2006
				if (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2007
					typeid(*selection) == typeid(FloatImageObj))
insilmaril@0
  2008
				{
insilmaril@0
  2009
					selection->unselect();
insilmaril@0
  2010
					selection=par;
insilmaril@0
  2011
					selection->select();
insilmaril@0
  2012
					adjustCanvasSize();
insilmaril@0
  2013
					ensureSelectionVisible();
insilmaril@0
  2014
				}
insilmaril@0
  2015
			} else
insilmaril@0
  2016
			{
insilmaril@0
  2017
				if (typeid(*selection) == typeid(BranchObj) )
insilmaril@0
  2018
				{
insilmaril@163
  2019
					bo=((BranchObj*)selection)->getLastSelectedBranch();
insilmaril@0
  2020
					if (bo) 
insilmaril@0
  2021
					{
insilmaril@0
  2022
						selection->unselect();
insilmaril@0
  2023
						selection=bo;
insilmaril@0
  2024
						selection->select();
insilmaril@0
  2025
						adjustCanvasSize();
insilmaril@0
  2026
						ensureSelectionVisible();
insilmaril@0
  2027
					}
insilmaril@0
  2028
				}
insilmaril@0
  2029
			}
insilmaril@0
  2030
		}
insilmaril@0
  2031
	}
insilmaril@0
  2032
}
insilmaril@0
  2033
insilmaril@0
  2034
void MapEditor::selectFirstBranch()
insilmaril@0
  2035
{
insilmaril@0
  2036
	// Finish open lineEdits
insilmaril@0
  2037
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  2038
insilmaril@0
  2039
	BranchObj *bo1;
insilmaril@0
  2040
	BranchObj *bo2;
insilmaril@0
  2041
	BranchObj* par;
insilmaril@0
  2042
	if (selection) {
insilmaril@0
  2043
		if (typeid(*selection) == typeid(BranchObj))
insilmaril@0
  2044
		{
insilmaril@163
  2045
			bo1=  (BranchObj*) selection;
insilmaril@0
  2046
			par=(BranchObj*)(bo1->getParObj());
insilmaril@0
  2047
			bo2=par->getFirstBranch();
insilmaril@0
  2048
			if (bo2) {
insilmaril@0
  2049
				bo1->unselect();
insilmaril@0
  2050
				selection=bo2;
insilmaril@0
  2051
				selection->select();
insilmaril@0
  2052
				ensureSelectionVisible();
insilmaril@0
  2053
			}
insilmaril@0
  2054
		}		
insilmaril@0
  2055
		adjustCanvasSize();
insilmaril@0
  2056
	}
insilmaril@0
  2057
}
insilmaril@0
  2058
insilmaril@0
  2059
void MapEditor::selectLastBranch()
insilmaril@0
  2060
{
insilmaril@0
  2061
	// Finish open lineEdits
insilmaril@0
  2062
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  2063
insilmaril@0
  2064
	BranchObj *bo1;
insilmaril@0
  2065
	BranchObj *bo2;
insilmaril@0
  2066
	BranchObj* par;
insilmaril@0
  2067
	if (selection) {
insilmaril@0
  2068
		if (typeid(*selection) == typeid(BranchObj))
insilmaril@0
  2069
		{
insilmaril@163
  2070
			bo1=  (BranchObj*) selection;
insilmaril@0
  2071
			par=(BranchObj*)(bo1->getParObj());
insilmaril@0
  2072
			bo2=par->getLastBranch();
insilmaril@0
  2073
			if (bo2) {
insilmaril@0
  2074
				bo1->unselect();
insilmaril@0
  2075
				selection=bo2;
insilmaril@0
  2076
				selection->select();
insilmaril@0
  2077
				ensureSelectionVisible();
insilmaril@0
  2078
			}
insilmaril@0
  2079
		}		
insilmaril@0
  2080
		adjustCanvasSize();
insilmaril@0
  2081
	}
insilmaril@0
  2082
}
insilmaril@0
  2083
insilmaril@0
  2084
void MapEditor::setColor(QColor c)
insilmaril@0
  2085
{
insilmaril@0
  2086
	actColor=c;
insilmaril@0
  2087
}
insilmaril@0
  2088
insilmaril@0
  2089
void MapEditor::selectBackgroundColor()
insilmaril@0
  2090
{
insilmaril@0
  2091
	// Finish open lineEdits
insilmaril@0
  2092
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  2093
insilmaril@0
  2094
	QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
insilmaril@0
  2095
	if ( !col.isValid() ) return;
insilmaril@0
  2096
	setBackgroundColor( col );
insilmaril@131
  2097
	saveState();
insilmaril@0
  2098
}
insilmaril@0
  2099
insilmaril@0
  2100
void MapEditor::setBackgroundColor(QColor c)
insilmaril@0
  2101
{
insilmaril@0
  2102
	mapCanvas->setBackgroundColor (c);
insilmaril@0
  2103
}
insilmaril@0
  2104
insilmaril@0
  2105
QColor MapEditor::pickColor()
insilmaril@0
  2106
{
insilmaril@0
  2107
	if (selection) 
insilmaril@0
  2108
	{
insilmaril@0
  2109
		if (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2110
			typeid(*selection) == typeid(MapCenterObj))
insilmaril@0
  2111
		{
insilmaril@163
  2112
			BranchObj *bo=(BranchObj*)selection;
insilmaril@0
  2113
			actColor=bo->getColor(); 
insilmaril@0
  2114
		}    
insilmaril@0
  2115
	}
insilmaril@0
  2116
	return actColor;
insilmaril@0
  2117
}
insilmaril@0
  2118
insilmaril@0
  2119
void MapEditor::colorItem()
insilmaril@0
  2120
{
insilmaril@0
  2121
	if (selection) 
insilmaril@0
  2122
	{
insilmaril@0
  2123
		if (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2124
			typeid(*selection) == typeid(MapCenterObj))
insilmaril@0
  2125
		{
insilmaril@164
  2126
			saveState(selection);	//TODO undoCommand
insilmaril@163
  2127
			BranchObj *bo=(BranchObj*)selection;
insilmaril@243
  2128
			bo->setColor(actColor); // color branch
insilmaril@0
  2129
		}    
insilmaril@0
  2130
	}
insilmaril@0
  2131
}
insilmaril@0
  2132
insilmaril@0
  2133
void MapEditor::colorBranch()
insilmaril@0
  2134
{
insilmaril@0
  2135
	if (selection) 
insilmaril@0
  2136
	{
insilmaril@0
  2137
		if (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2138
			typeid(*selection) == typeid(MapCenterObj))
insilmaril@0
  2139
		{
insilmaril@185
  2140
			saveState(selection);	//TODO undoCommand
insilmaril@163
  2141
			BranchObj *bo=(BranchObj*)selection;
insilmaril@243
  2142
			bo->setColorChilds(actColor); // color links, color childs
insilmaril@0
  2143
		}    
insilmaril@0
  2144
	}
insilmaril@0
  2145
}
insilmaril@0
  2146
insilmaril@0
  2147
insilmaril@0
  2148
void MapEditor::toggleStandardFlag(QString f)
insilmaril@0
  2149
{
insilmaril@0
  2150
	if (selection)
insilmaril@0
  2151
	{
insilmaril@164
  2152
		saveState(selection);// TODO undoCommand	
insilmaril@163
  2153
		((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
insilmaril@228
  2154
		adjustCanvasSize();
insilmaril@0
  2155
	}	
insilmaril@0
  2156
}
insilmaril@0
  2157
insilmaril@0
  2158
void MapEditor::setViewCenter()
insilmaril@0
  2159
{
insilmaril@0
  2160
	// transform to CanvasView Coord:
insilmaril@0
  2161
	QPoint p=worldMatrix().map(movingCenter);
insilmaril@0
  2162
	center ( p.x(), p.y());
insilmaril@0
  2163
}
insilmaril@0
  2164
insilmaril@0
  2165
insilmaril@0
  2166
BranchObj* MapEditor::findText (QString s, bool cs)
insilmaril@0
  2167
{
insilmaril@0
  2168
	if (!itFind) 
insilmaril@0
  2169
	{	// Nothing found or new find process
insilmaril@0
  2170
		if (EOFind)
insilmaril@0
  2171
			// nothing found, start again
insilmaril@0
  2172
			EOFind=false;
insilmaril@0
  2173
		itFind=mapCenter->first();
insilmaril@0
  2174
	}	
insilmaril@0
  2175
	bool searching=true;
insilmaril@0
  2176
	bool foundNote=false;
insilmaril@0
  2177
	while (searching && !EOFind)
insilmaril@0
  2178
	{
insilmaril@0
  2179
		if (itFind)
insilmaril@0
  2180
		{
insilmaril@0
  2181
			// Searching in Note
insilmaril@0
  2182
			if (itFind->getNote().contains(s,cs))
insilmaril@0
  2183
			{
insilmaril@0
  2184
				if (selection!=itFind) 
insilmaril@0
  2185
				{
insilmaril@163
  2186
					if (selection) ((BranchObj*)selection)->unselect();
insilmaril@0
  2187
					selection=itFind;
insilmaril@0
  2188
					selection->select();
insilmaril@0
  2189
					adjustCanvasSize();
insilmaril@0
  2190
					ensureSelectionVisible();
insilmaril@0
  2191
				}
insilmaril@0
  2192
				if (textEditor->findText(s,cs)) 
insilmaril@0
  2193
				{
insilmaril@0
  2194
					searching=false;
insilmaril@0
  2195
					foundNote=true;
insilmaril@0
  2196
				}	
insilmaril@0
  2197
			}
insilmaril@0
  2198
			// Searching in Heading
insilmaril@0
  2199
			if (searching && itFind->getHeading().contains (s,cs) ) 
insilmaril@0
  2200
			{
insilmaril@163
  2201
				if (selection) ((BranchObj*)selection)->unselect();
insilmaril@0
  2202
				selection=itFind;
insilmaril@0
  2203
				selection->select();
insilmaril@0
  2204
				adjustCanvasSize();
insilmaril@0
  2205
				ensureSelectionVisible();
insilmaril@0
  2206
				searching=false;
insilmaril@0
  2207
			}
insilmaril@0
  2208
		}	
insilmaril@0
  2209
		if (!foundNote)
insilmaril@0
  2210
		{
insilmaril@0
  2211
			itFind=itFind->next();
insilmaril@0
  2212
			if (!itFind) EOFind=true;
insilmaril@0
  2213
		}
insilmaril@0
  2214
	}	
insilmaril@0
  2215
	if (!searching)
insilmaril@0
  2216
	{
insilmaril@0
  2217
		adjustCanvasSize();
insilmaril@163
  2218
		return (BranchObj*)selection;
insilmaril@0
  2219
	}	else
insilmaril@0
  2220
		return NULL;
insilmaril@0
  2221
}
insilmaril@0
  2222
insilmaril@0
  2223
void MapEditor::findReset()
insilmaril@0
  2224
{	// Necessary if text to find changes during a find process
insilmaril@0
  2225
	itFind=NULL;
insilmaril@0
  2226
	EOFind=false;
insilmaril@0
  2227
}
insilmaril@0
  2228
insilmaril@0
  2229
void MapEditor::editURL()
insilmaril@0
  2230
{
insilmaril@0
  2231
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2232
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2233
	{		
insilmaril@0
  2234
		bool ok;
insilmaril@163
  2235
		BranchObj *bo=(BranchObj*)selection;
insilmaril@0
  2236
		QString text = QInputDialog::getText(
insilmaril@0
  2237
				"VYM", tr("Enter URL:"), QLineEdit::Normal,
insilmaril@143
  2238
				bo->getURL(), &ok, this );
insilmaril@0
  2239
		if ( ok) 
insilmaril@0
  2240
		{
insilmaril@0
  2241
			// user entered something and pressed OK
insilmaril@143
  2242
			saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");	
insilmaril@143
  2243
			bo->setURL (text);
insilmaril@0
  2244
			updateActions();
insilmaril@0
  2245
		}	
insilmaril@0
  2246
	}
insilmaril@0
  2247
}
insilmaril@0
  2248
insilmaril@266
  2249
QString MapEditor::getURL()
insilmaril@266
  2250
{
insilmaril@266
  2251
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@266
  2252
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@266
  2253
		return ((BranchObj*)selection)->getURL();
insilmaril@266
  2254
	else
insilmaril@266
  2255
		return "";
insilmaril@266
  2256
}
insilmaril@266
  2257
insilmaril@0
  2258
void MapEditor::editHeading2URL()
insilmaril@0
  2259
{
insilmaril@0
  2260
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2261
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2262
	{		
insilmaril@163
  2263
		BranchObj *bo=(BranchObj*)selection;
insilmaril@143
  2264
		saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");	
insilmaril@143
  2265
		bo->setURL (bo->getHeading());
insilmaril@0
  2266
		updateActions();
insilmaril@0
  2267
	}
insilmaril@0
  2268
}	
insilmaril@0
  2269
insilmaril@0
  2270
void MapEditor::editBugzilla2URL()
insilmaril@0
  2271
{
insilmaril@0
  2272
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2273
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2274
	{		
insilmaril@163
  2275
		BranchObj *bo=(BranchObj*)selection;
insilmaril@143
  2276
		QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
insilmaril@143
  2277
		saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");	
insilmaril@143
  2278
		bo->setURL (url);
insilmaril@0
  2279
		updateActions();
insilmaril@0
  2280
	}
insilmaril@0
  2281
}	
insilmaril@0
  2282
insilmaril@175
  2283
void MapEditor::editFATE2URL()
insilmaril@175
  2284
{
insilmaril@175
  2285
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@175
  2286
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@175
  2287
	{		
insilmaril@175
  2288
		BranchObj *bo=(BranchObj*)selection;
insilmaril@175
  2289
		QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
insilmaril@175
  2290
		saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");	
insilmaril@175
  2291
		bo->setURL (url);
insilmaril@175
  2292
		updateActions();
insilmaril@175
  2293
	}
insilmaril@175
  2294
}	
insilmaril@175
  2295
insilmaril@0
  2296
void MapEditor::editVymLink()
insilmaril@0
  2297
{
insilmaril@0
  2298
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2299
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2300
	{		
insilmaril@163
  2301
		BranchObj *bo=(BranchObj*)selection;
insilmaril@185
  2302
		QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
insilmaril@0
  2303
		fd->addFilter (QString (tr("vym map") + " (*.vym)"));
insilmaril@185
  2304
		fd->setCaption(__VYM " - " +tr("Link to another map"));
insilmaril@143
  2305
		if (! bo->getVymLink().isEmpty() )
insilmaril@143
  2306
			fd->setSelection( bo->getVymLink() );
insilmaril@0
  2307
		fd->show();
insilmaril@0
  2308
insilmaril@0
  2309
		QString fn;
insilmaril@0
  2310
		if ( fd->exec() == QDialog::Accepted )
insilmaril@143
  2311
		{
insilmaril@143
  2312
			saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");	
insilmaril@143
  2313
			bo->setVymLink (fd->selectedFile() );
insilmaril@143
  2314
			updateActions();
insilmaril@143
  2315
			mapCenter->reposition();
insilmaril@143
  2316
			adjustCanvasSize();
insilmaril@143
  2317
			canvas()->update();
insilmaril@143
  2318
		}
insilmaril@0
  2319
	}
insilmaril@0
  2320
}
insilmaril@0
  2321
insilmaril@0
  2322
void MapEditor::deleteVymLink()
insilmaril@0
  2323
{
insilmaril@0
  2324
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2325
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2326
	{		
insilmaril@163
  2327
		BranchObj *bo=(BranchObj*)selection;
insilmaril@143
  2328
		saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");	
insilmaril@143
  2329
		bo->setVymLink ("" );
insilmaril@0
  2330
		updateActions();
insilmaril@0
  2331
		mapCenter->reposition();
insilmaril@0
  2332
		adjustCanvasSize();
insilmaril@0
  2333
		canvas()->update();
insilmaril@0
  2334
	}
insilmaril@0
  2335
}
insilmaril@0
  2336
insilmaril@250
  2337
void MapEditor::setHideExport()
insilmaril@250
  2338
{
insilmaril@250
  2339
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@250
  2340
			typeid(*selection) == typeid(MapCenterObj)) ||
insilmaril@250
  2341
			(typeid(*selection)==typeid(FloatImageObj))
insilmaril@250
  2342
			)
insilmaril@250
  2343
	{		
insilmaril@250
  2344
		saveState();	//TODO undoCommand
insilmaril@250
  2345
		OrnamentedObj *oo=(OrnamentedObj*)selection;
insilmaril@250
  2346
		oo->setHideInExport(actionEditToggleHideExport->isOn());
insilmaril@250
  2347
		updateActions();
insilmaril@250
  2348
		mapCenter->reposition();
insilmaril@250
  2349
		adjustCanvasSize();
insilmaril@250
  2350
		canvas()->update();
insilmaril@250
  2351
	}
insilmaril@250
  2352
}
insilmaril@250
  2353
insilmaril@243
  2354
void MapEditor::toggleHideExport()
insilmaril@243
  2355
{
insilmaril@243
  2356
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@250
  2357
			typeid(*selection) == typeid(MapCenterObj)) ||
insilmaril@250
  2358
			(typeid(*selection)==typeid(FloatImageObj))
insilmaril@243
  2359
			)
insilmaril@243
  2360
	{		
insilmaril@243
  2361
		saveState();	//TODO undoCommand
insilmaril@250
  2362
		OrnamentedObj *oo=(OrnamentedObj*)selection;
insilmaril@250
  2363
		if (oo->hideInExport())
insilmaril@250
  2364
			oo->setHideInExport(false);
insilmaril@250
  2365
		else	
insilmaril@250
  2366
			oo->setHideInExport(true);
insilmaril@250
  2367
		actionEditToggleHideExport->setOn (oo->hideInExport());	
insilmaril@243
  2368
		updateActions();
insilmaril@243
  2369
		mapCenter->reposition();
insilmaril@243
  2370
		adjustCanvasSize();
insilmaril@243
  2371
		canvas()->update();
insilmaril@243
  2372
	}
insilmaril@243
  2373
}
insilmaril@243
  2374
insilmaril@0
  2375
QString MapEditor::getVymLink()
insilmaril@0
  2376
{
insilmaril@0
  2377
	if (selection && (typeid(*selection) == typeid(BranchObj) ||
insilmaril@0
  2378
			typeid(*selection) == typeid(MapCenterObj)) )
insilmaril@0
  2379
	{		
insilmaril@163
  2380
		return ((BranchObj*)selection)->getVymLink();
insilmaril@0
  2381
	}
insilmaril@0
  2382
	return "";
insilmaril@0
  2383
	
insilmaril@0
  2384
}
insilmaril@0
  2385
insilmaril@98
  2386
void MapEditor::removeBranchHere()
insilmaril@98
  2387
{
insilmaril@98
  2388
	if (selection && (typeid(*selection) == typeid(BranchObj) ))
insilmaril@98
  2389
	{		
insilmaril@163
  2390
		BranchObj* bo=(BranchObj*)selection;
insilmaril@98
  2391
		BranchObj* par=(BranchObj*)(bo->getParObj());
insilmaril@139
  2392
		if (bo->getDepth()==1)
insilmaril@139
  2393
			saveState();
insilmaril@139
  2394
		else	
insilmaril@164
  2395
			saveState(selection->getParObj());	// TODO undoCommand
insilmaril@139
  2396
		QString sel=selection->getSelectString();
insilmaril@98
  2397
		unselect();
insilmaril@98
  2398
		par->removeBranchHere(bo);
insilmaril@98
  2399
		mapCenter->reposition();
insilmaril@98
  2400
		select (sel);
insilmaril@98
  2401
	}	
insilmaril@98
  2402
}
insilmaril@98
  2403
insilmaril@98
  2404
void MapEditor::removeChilds()
insilmaril@98
  2405
{
insilmaril@98
  2406
	if (selection && (typeid(*selection) == typeid(BranchObj) ))
insilmaril@98
  2407
	{		
insilmaril@106
  2408
		saveState(selection->getParObj());
insilmaril@163
  2409
		((BranchObj*)selection)->removeChilds();
insilmaril@98
  2410
		mapCenter->reposition();
insilmaril@98
  2411
	}	
insilmaril@98
  2412
}
insilmaril@98
  2413
insilmaril@0
  2414
void MapEditor::editMapInfo()
insilmaril@0
  2415
{
insilmaril@0
  2416
	ExtraInfoDialog dia;
insilmaril@0
  2417
	dia.setMapName (getFileName() );
insilmaril@0
  2418
	dia.setAuthor (mapCenter->getAuthor() );
insilmaril@0
  2419
	dia.setComment(mapCenter->getComment() );
insilmaril@0
  2420
insilmaril@0
  2421
	// Calc some stats
insilmaril@0
  2422
	QString stats;
insilmaril@0
  2423
    int i=0;
insilmaril@0
  2424
    QCanvasItemList l=canvas()->allItems();
insilmaril@0
  2425
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) 
insilmaril@0
  2426
        i++;
insilmaril@0
  2427
    stats+=QString ("%1 items on canvas\n").arg (i,6);
insilmaril@0
  2428
insilmaril@0
  2429
	uint b=0;
insilmaril@0
  2430
	uint f=0;
insilmaril@0
  2431
	uint n=0;
insilmaril@103
  2432
	uint xl=0;
insilmaril@0
  2433
	BranchObj *bo;
insilmaril@0
  2434
	bo=mapCenter->first();
insilmaril@0
  2435
	while (bo) 
insilmaril@0
  2436
	{
insilmaril@0
  2437
		if (!bo->getNote().isEmpty() ) n++;
insilmaril@0
  2438
		f+= bo->countFloatImages();
insilmaril@0
  2439
		b++;
insilmaril@103
  2440
		xl+=bo->countXLinks();
insilmaril@0
  2441
		bo=bo->next();
insilmaril@0
  2442
	}
insilmaril@0
  2443
    stats+=QString ("%1 branches\n").arg (b-1,6);
insilmaril@104
  2444
    stats+=QString ("%1 xLinks \n").arg (xl,6);
insilmaril@0
  2445
    stats+=QString ("%1 notes\n").arg (n,6);
insilmaril@0
  2446
    stats+=QString ("%1 images\n").arg (f,6);
insilmaril@0
  2447
	dia.setStats (stats);
insilmaril@0
  2448
insilmaril@0
  2449
	// Finally show dialog
insilmaril@0
  2450
	if (dia.exec() == QDialog::Accepted)
insilmaril@0
  2451
	{
insilmaril@164
  2452
		saveState();	//TODO undoCommand
insilmaril@0
  2453
		mapCenter->setAuthor (dia.getAuthor() );
insilmaril@0
  2454
		mapCenter->setComment (dia.getComment() );
insilmaril@0
  2455
	}
insilmaril@0
  2456
}
insilmaril@0
  2457
insilmaril@0
  2458
void MapEditor::updateActions()
insilmaril@0
  2459
{
insilmaril@98
  2460
	QAction *a;
insilmaril@0
  2461
	if (getLinkColorHint()==HeadingColor) 
insilmaril@0
  2462
		actionFormatLinkColorHint->setOn(true);
insilmaril@0
  2463
	else	
insilmaril@0
  2464
		actionFormatLinkColorHint->setOn(false);
insilmaril@0
  2465
insilmaril@0
  2466
	switch (linkstyle)
insilmaril@0
  2467
	{
insilmaril@0
  2468
		case StyleLine: 
insilmaril@0
  2469
			actionFormatLinkStyleLine->setOn(true);
insilmaril@0
  2470
			break;
insilmaril@0
  2471
		case StyleParabel:
insilmaril@0
  2472
			actionFormatLinkStyleParabel->setOn(true);
insilmaril@0
  2473
			break;
insilmaril@0
  2474
		case StylePolyLine:	
insilmaril@0
  2475
			actionFormatLinkStylePolyLine->setOn(true);
insilmaril@0
  2476
			break;
insilmaril@0
  2477
		case StylePolyParabel:	
insilmaril@0
  2478
			actionFormatLinkStylePolyParabel->setOn(true);
insilmaril@0
  2479
			break;
insilmaril@0
  2480
		default:
insilmaril@0
  2481
			break;
insilmaril@0
  2482
	}	
insilmaril@0
  2483
insilmaril@0
  2484
	QPixmap pix( 16, 16 );
insilmaril@0
  2485
    pix.fill( mapCanvas->backgroundColor() );
insilmaril@0
  2486
    actionFormatBackColor->setIconSet( pix );
insilmaril@97
  2487
    pix.fill( defLinkColor );
insilmaril@0
  2488
    actionFormatLinkColor->setIconSet( pix );
insilmaril@0
  2489
insilmaril@0
  2490
	actionEditUndo->setEnabled( mapChanged );
insilmaril@0
  2491
	actionFileSave->setEnabled( mapUnsaved );
insilmaril@0
  2492
insilmaril@0
  2493
	if (selection)
insilmaril@0
  2494
	{
insilmaril@0
  2495
		if ( (typeid(*selection) == typeid(BranchObj)) || 
insilmaril@0
  2496
			(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@0
  2497
		{
insilmaril@163
  2498
			BranchObj *bo=(BranchObj*)selection;
insilmaril@89
  2499
			// Take care of links
insilmaril@95
  2500
			if (bo->countXLinks()==0)
insilmaril@89
  2501
			{
insilmaril@89
  2502
				branchLinksContextMenu->clear();
insilmaril@125
  2503
				branchLinksContextMenu->insertItem ("No xLink available");
insilmaril@94
  2504
				branchLinksContextMenuDup->clear();
insilmaril@125
  2505
				branchLinksContextMenuDup->insertItem ("No xLink available");
insilmaril@89
  2506
				
insilmaril@89
  2507
			} else
insilmaril@89
  2508
			{
insilmaril@89
  2509
				BranchObj *bot;
insilmaril@89
  2510
				QString s;
insilmaril@89
  2511
				branchLinksContextMenu->clear();
insilmaril@94
  2512
				branchLinksContextMenuDup->clear();
insilmaril@95
  2513
				for (int i=0; i<=bo->countXLinks();i++)
insilmaril@89
  2514
				{
insilmaril@95
  2515
					bot=bo->XLinkTargetAt(i);
insilmaril@89
  2516
					if (bot)
insilmaril@89
  2517
					{
insilmaril@89
  2518
						s=bot->getHeading();
insilmaril@89
  2519
						if (s.length()>25)
insilmaril@89
  2520
							s=s.left(25)+"...";
insilmaril@89
  2521
						branchLinksContextMenu->insertItem (s);
insilmaril@94
  2522
						branchLinksContextMenuDup->insertItem (s);
insilmaril@89
  2523
					}	
insilmaril@89
  2524
				}
insilmaril@89
  2525
			}
insilmaril@89
  2526
insilmaril@0
  2527
			standardFlagsDefault->setEnabled (true);
insilmaril@0
  2528
insilmaril@250
  2529
			actionEditToggleScroll->setEnabled (true);
insilmaril@250
  2530
			if ( bo->isScrolled() )
insilmaril@250
  2531
				actionEditToggleScroll->setOn(true);
insilmaril@250
  2532
			else	
insilmaril@250
  2533
				actionEditToggleScroll->setOn(false);
insilmaril@250
  2534
insilmaril@89
  2535
			if ( bo->getURL().isEmpty() )
insilmaril@266
  2536
			{
insilmaril@0
  2537
				actionEditOpenURL->setEnabled (false);
insilmaril@266
  2538
				actionEditOpenURLTab->setEnabled (false);
insilmaril@266
  2539
			}	
insilmaril@0
  2540
			else	
insilmaril@266
  2541
			{
insilmaril@0
  2542
				actionEditOpenURL->setEnabled (true);
insilmaril@266
  2543
				actionEditOpenURLTab->setEnabled (true);
insilmaril@266
  2544
			}
insilmaril@89
  2545
			if ( bo->getVymLink().isEmpty() )
insilmaril@0
  2546
			{
insilmaril@0
  2547
				actionEditOpenVymLink->setEnabled (false);
insilmaril@0
  2548
				actionEditDeleteVymLink->setEnabled (false);
insilmaril@0
  2549
			} else	
insilmaril@0
  2550
			{
insilmaril@0
  2551
				actionEditOpenVymLink->setEnabled (true);
insilmaril@0
  2552
				actionEditDeleteVymLink->setEnabled (true);
insilmaril@0
  2553
			}	
insilmaril@243
  2554
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@243
  2555
			actionEditToggleHideExport->setOn (bo->hideInExport() );	
insilmaril@0
  2556
insilmaril@0
  2557
			actionEditCopy->setEnabled (true);	
insilmaril@0
  2558
			actionEditCut->setEnabled (true);	
insilmaril@166
  2559
			if (!clipboardEmpty)
insilmaril@119
  2560
				actionEditPaste->setEnabled (true);	
insilmaril@119
  2561
			else	
insilmaril@119
  2562
				actionEditPaste->setEnabled (false);	
insilmaril@119
  2563
			for (a=actionListBranches.first();a;a=actionListBranches.next())
insilmaril@119
  2564
				a->setEnabled(true);
insilmaril@0
  2565
			actionEditDelete->setEnabled (true);
insilmaril@0
  2566
			switch (selection->getFrameType())
insilmaril@0
  2567
			{
insilmaril@0
  2568
				case NoFrame: 
insilmaril@0
  2569
					actionFormatFrameNone->setOn(true);
insilmaril@0
  2570
					break;
insilmaril@0
  2571
				case Rectangle:
insilmaril@0
  2572
					actionFormatFrameRectangle->setOn(true);
insilmaril@0
  2573
					break;
insilmaril@0
  2574
				default:
insilmaril@0
  2575
					break;
insilmaril@0
  2576
			}	
insilmaril@175
  2577
			actionFormatIncludeImagesVer->setOn
insilmaril@175
  2578
				( ((BranchObj*)selection)->getIncludeImagesVer());
insilmaril@175
  2579
			actionFormatIncludeImagesHor->setOn
insilmaril@175
  2580
				( ((BranchObj*)selection)->getIncludeImagesHor());
insilmaril@160
  2581
			actionFormatHideLinkUnselected->setOn
insilmaril@175
  2582
				(selection->getHideLinkUnselected());
insilmaril@0
  2583
		}
insilmaril@0
  2584
		if ( (typeid(*selection) == typeid(FloatImageObj)) )
insilmaril@0
  2585
		{
insilmaril@250
  2586
			FloatObj *fo=(FloatImageObj*)selection;
insilmaril@0
  2587
			standardFlagsDefault->setEnabled (false);
insilmaril@0
  2588
insilmaril@0
  2589
			actionEditOpenURL->setEnabled (false);
insilmaril@0
  2590
			actionEditOpenVymLink->setEnabled (false);
insilmaril@0
  2591
			actionEditDeleteVymLink->setEnabled (false);	
insilmaril@250
  2592
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@250
  2593
			actionEditToggleHideExport->setOn (fo->hideInExport() );	
insilmaril@250
  2594
insilmaril@0
  2595
insilmaril@0
  2596
			actionEditCopy->setEnabled (true);
insilmaril@0
  2597
			actionEditCut->setEnabled (true);	
insilmaril@243
  2598
			actionEditPaste->setEnabled (false);
insilmaril@98
  2599
			for (a=actionListBranches.first();a;a=actionListBranches.next())
insilmaril@98
  2600
				a->setEnabled(false);
insilmaril@0
  2601
			actionEditDelete->setEnabled (true);
insilmaril@160
  2602
			actionFormatHideLinkUnselected->setOn
insilmaril@160
  2603
				( selection->getHideLinkUnselected());
insilmaril@0
  2604
		}
insilmaril@0
  2605
insilmaril@0
  2606
	} else
insilmaril@0
  2607
	{
insilmaril@0
  2608
		standardFlagsDefault->setEnabled (false);
insilmaril@0
  2609
insilmaril@0
  2610
		actionEditCopy->setEnabled (false);	
insilmaril@0
  2611
		actionEditCut->setEnabled (false);	
insilmaril@0
  2612
		actionEditPaste->setEnabled (false);	
insilmaril@98
  2613
		for (a=actionListBranches.first();a;a=actionListBranches.next())
insilmaril@98
  2614
			a->setEnabled(false);
insilmaril@98
  2615
insilmaril@250
  2616
		actionEditToggleScroll->setEnabled (true);
insilmaril@0
  2617
		actionEditOpenURL->setEnabled (false);
insilmaril@0
  2618
		actionEditOpenVymLink->setEnabled (false);
insilmaril@0
  2619
		actionEditDeleteVymLink->setEnabled (false);	
insilmaril@0
  2620
		actionEditHeading2URL->setEnabled (false);	
insilmaril@0
  2621
		actionEditDelete->setEnabled (false);
insilmaril@0
  2622
	}	
insilmaril@0
  2623
}
insilmaril@0
  2624
insilmaril@160
  2625
void MapEditor::updateNoteFlag()
insilmaril@160
  2626
{
insilmaril@160
  2627
	if (selection)
insilmaril@160
  2628
		if ( (typeid(*selection) == typeid(BranchObj)) || 
insilmaril@160
  2629
			(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@160
  2630
			((BranchObj*)selection)->updateNoteFlag();
insilmaril@160
  2631
}
insilmaril@160
  2632
insilmaril@0
  2633
void MapEditor::setLinkStyle (LinkStyle ls)
insilmaril@0
  2634
{
insilmaril@0
  2635
	linkstyle=ls;
insilmaril@0
  2636
insilmaril@164
  2637
	saveState();	// TODO undoCommand
insilmaril@0
  2638
	BranchObj *bo;
insilmaril@0
  2639
	bo=mapCenter->first();
insilmaril@0
  2640
	bo=bo->next();
insilmaril@0
  2641
	while (bo) 
insilmaril@0
  2642
	{
insilmaril@0
  2643
		bo->setLinkStyle(bo->getDefLinkStyle());
insilmaril@0
  2644
		bo=bo->next();
insilmaril@0
  2645
	}
insilmaril@102
  2646
	mapCenter->reposition();
insilmaril@0
  2647
}
insilmaril@0
  2648
insilmaril@0
  2649
LinkStyle MapEditor::getLinkStyle ()
insilmaril@0
  2650
{
insilmaril@0
  2651
	return linkstyle;
insilmaril@0
  2652
}	
insilmaril@0
  2653
insilmaril@0
  2654
void MapEditor::setLinkColor(QColor c)
insilmaril@0
  2655
{
insilmaril@97
  2656
	defLinkColor=c;
insilmaril@0
  2657
	updateActions();
insilmaril@0
  2658
}
insilmaril@0
  2659
insilmaril@0
  2660
void MapEditor::setLinkColorHint()
insilmaril@0
  2661
{
insilmaril@0
  2662
	// called from setLinkColorHint(lch) or at end of parse
insilmaril@0
  2663
	BranchObj *bo;
insilmaril@0
  2664
	bo=mapCenter->first();
insilmaril@0
  2665
	while (bo) 
insilmaril@0
  2666
	{
insilmaril@0
  2667
		bo->setLinkColor();
insilmaril@0
  2668
		bo=bo->next();
insilmaril@0
  2669
	}
insilmaril@0
  2670
}
insilmaril@0
  2671
insilmaril@0
  2672
void MapEditor::setLinkColorHint(LinkColorHint lch)
insilmaril@0
  2673
{
insilmaril@0
  2674
	linkcolorhint=lch;
insilmaril@0
  2675
	setLinkColorHint();
insilmaril@0
  2676
}
insilmaril@0
  2677
insilmaril@0
  2678
void MapEditor::toggleLinkColorHint()
insilmaril@0
  2679
{
insilmaril@0
  2680
	if (linkcolorhint==HeadingColor)
insilmaril@0
  2681
		linkcolorhint=DefaultColor;
insilmaril@0
  2682
	else	
insilmaril@0
  2683
		linkcolorhint=HeadingColor;
insilmaril@0
  2684
	BranchObj *bo;
insilmaril@0
  2685
	bo=mapCenter->first();
insilmaril@0
  2686
	while (bo) 
insilmaril@0
  2687
	{
insilmaril@0
  2688
		bo->setLinkColor();
insilmaril@0
  2689
		bo=bo->next();
insilmaril@0
  2690
	}
insilmaril@0
  2691
}
insilmaril@0
  2692
insilmaril@0
  2693
LinkColorHint MapEditor::getLinkColorHint()
insilmaril@0
  2694
{
insilmaril@0
  2695
	return linkcolorhint;
insilmaril@0
  2696
}
insilmaril@0
  2697
insilmaril@0
  2698
QColor MapEditor::getDefLinkColor()
insilmaril@0
  2699
{
insilmaril@97
  2700
	return defLinkColor;
insilmaril@97
  2701
}
insilmaril@97
  2702
insilmaril@97
  2703
void MapEditor::setDefXLinkColor(QColor col)
insilmaril@97
  2704
{
insilmaril@97
  2705
	defXLinkColor=col;
insilmaril@97
  2706
}
insilmaril@97
  2707
insilmaril@97
  2708
QColor MapEditor::getDefXLinkColor()
insilmaril@97
  2709
{
insilmaril@97
  2710
	return defXLinkColor;
insilmaril@97
  2711
}
insilmaril@97
  2712
insilmaril@97
  2713
void MapEditor::setDefXLinkWidth (int w)
insilmaril@97
  2714
{
insilmaril@97
  2715
	defXLinkWidth=w;
insilmaril@97
  2716
}
insilmaril@97
  2717
insilmaril@97
  2718
int MapEditor::getDefXLinkWidth()
insilmaril@97
  2719
{
insilmaril@97
  2720
	return defXLinkWidth;
insilmaril@0
  2721
}
insilmaril@0
  2722
insilmaril@0
  2723
void MapEditor::selectLinkColor()
insilmaril@0
  2724
{
insilmaril@0
  2725
	// Finish open lineEdits
insilmaril@0
  2726
	if (lineedit) finishedLineEditNoSave();
insilmaril@0
  2727
insilmaril@97
  2728
	QColor col = QColorDialog::getColor( defLinkColor, this );
insilmaril@0
  2729
	if ( !col.isValid() ) return;
insilmaril@0
  2730
	setLinkColor( col );
insilmaril@164
  2731
	saveState();	//TODO undoCommand
insilmaril@131
  2732
insilmaril@0
  2733
}
insilmaril@0
  2734
insilmaril@0
  2735
void MapEditor::toggleScroll()
insilmaril@0
  2736
{
insilmaril@0
  2737
	if (selection && (typeid(*selection) == typeid(BranchObj)) )
insilmaril@0
  2738
	{
insilmaril@163
  2739
		BranchObj *bo=((BranchObj*)selection);
insilmaril@0
  2740
		if (bo->countBranches()==0) return;
insilmaril@0
  2741
		if (bo->getDepth()==0) return;
insilmaril@106
  2742
		saveState(selection);
insilmaril@0
  2743
		bo->toggleScroll();
insilmaril@0
  2744
		adjustCanvasSize();
insilmaril@0
  2745
		canvas()->update();
insilmaril@0
  2746
	}
insilmaril@0
  2747
}
insilmaril@0
  2748
insilmaril@0
  2749
void MapEditor::unScrollAll()
insilmaril@0
  2750
{
insilmaril@0
  2751
	BranchObj *bo;
insilmaril@0
  2752
	bo=mapCenter->first();
insilmaril@0
  2753
	while (bo) 
insilmaril@0
  2754
	{
insilmaril@0
  2755
		if (bo->isScrolled()) bo->toggleScroll();
insilmaril@0
  2756
		bo=bo->next();
insilmaril@0
  2757
	}
insilmaril@0
  2758
}
insilmaril@0
  2759
insilmaril@0
  2760
void MapEditor::loadFloatImage ()
insilmaril@0
  2761
{
insilmaril@0
  2762
	if (selection && 
insilmaril@0
  2763
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@0
  2764
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@0
  2765
	{
insilmaril@163
  2766
		BranchObj *bo=((BranchObj*)selection);
insilmaril@0
  2767
insilmaril@236
  2768
		QFileDialog *fd=new QFileDialog( this);
insilmaril@185
  2769
		fd->setMode (QFileDialog::ExistingFiles);
insilmaril@0
  2770
		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@0
  2771
		ImagePreview *p =new ImagePreview (fd);
insilmaril@0
  2772
		fd->setContentsPreviewEnabled( TRUE );
insilmaril@0
  2773
		fd->setContentsPreview( p, p );
insilmaril@0
  2774
		fd->setPreviewMode( QFileDialog::Contents );
insilmaril@185
  2775
		fd->setCaption(__VYM " - " +tr("Load image"));
insilmaril@0
  2776
		fd->setDir (lastImageDir);
insilmaril@0
  2777
		fd->show();
insilmaril@0
  2778
insilmaril@0
  2779
		QString fn;
insilmaril@0
  2780
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  2781
		{
insilmaril@106
  2782
			saveState(selection);
insilmaril@0
  2783
			lastImageDir=fn.left(fn.findRev ("/"));
insilmaril@185
  2784
			QStringList flist = fd->selectedFiles();
insilmaril@185
  2785
			QStringList::Iterator it = flist.begin();
insilmaril@185
  2786
			while( it != flist.end() ) 
insilmaril@185
  2787
			{
insilmaril@185
  2788
				fn = *it;
insilmaril@185
  2789
				bo->addFloatImage();
insilmaril@185
  2790
				// TODO check if load was successful
insilmaril@185
  2791
				bo->getLastFloatImage()->load(*it);
insilmaril@185
  2792
				bo->getLastFloatImage()->setOriginalFilename(fn);
insilmaril@185
  2793
				++it;
insilmaril@185
  2794
			}
insilmaril@185
  2795
insilmaril@0
  2796
			mapCenter->reposition();
insilmaril@0
  2797
			adjustCanvasSize();
insilmaril@0
  2798
			canvas()->update();
insilmaril@0
  2799
		}
insilmaril@236
  2800
		delete (p);
insilmaril@236
  2801
		delete (fd);
insilmaril@0
  2802
	}
insilmaril@0
  2803
}
insilmaril@0
  2804
insilmaril@0
  2805
void MapEditor::saveFloatImage (int item)
insilmaril@0
  2806
{
insilmaril@0
  2807
	if (selection && 
insilmaril@0
  2808
		(typeid(*selection) == typeid(FloatImageObj)) )
insilmaril@0
  2809
	{
insilmaril@163
  2810
		FloatImageObj *fio=((FloatImageObj*)selection);
insilmaril@0
  2811
		const char* fmt = saveImageFormatMenu->text(item);
insilmaril@0
  2812
insilmaril@0
  2813
		QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
insilmaril@0
  2814
		fd->addFilter ("PNG (*.png)");
insilmaril@0
  2815
		fd->addFilter ("BMP (*.bmp)");
insilmaril@0
  2816
		fd->addFilter ("XBM (*.xbm)");
insilmaril@0
  2817
		fd->addFilter ("JPG (*.jpg)");
insilmaril@0
  2818
		fd->addFilter ("XPM (*.xpm)");
insilmaril@0
  2819
		fd->addFilter ("GIF (*.gif)");
insilmaril@0
  2820
		fd->addFilter ("PNM (*.pnm)");
insilmaril@0
  2821
		fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
insilmaril@185
  2822
		fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
insilmaril@0
  2823
		fd->setMode( QFileDialog::AnyFile );
insilmaril@0
  2824
		fd->setSelection (fio->getOriginalFilename());
insilmaril@0
  2825
		fd->show();
insilmaril@0
  2826
insilmaril@0
  2827
		QString fn;
insilmaril@0
  2828
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  2829
		{
insilmaril@0
  2830
			if (QFile (fd->selectedFile()).exists() )
insilmaril@0
  2831
			{
insilmaril@185
  2832
				QMessageBox mb( __VYM,
insilmaril@159
  2833
					tr("The file %1 exists already.\n"
insilmaril@159
  2834
					"Do you want to overwrite it?").arg(fd->selectedFile()),
insilmaril@0
  2835
				QMessageBox::Warning,
insilmaril@0
  2836
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2837
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  2838
				QMessageBox::QMessageBox::NoButton );
insilmaril@0
  2839
insilmaril@0
  2840
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  2841
				mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  2842
				switch( mb.exec() ) 
insilmaril@0
  2843
				{
insilmaril@0
  2844
					case QMessageBox::Yes:
insilmaril@0
  2845
						// save 
insilmaril@0
  2846
						break;;
insilmaril@0
  2847
					case QMessageBox::Cancel:
insilmaril@0
  2848
						// do nothing
insilmaril@0
  2849
						return;
insilmaril@0
  2850
						break;
insilmaril@0
  2851
				}
insilmaril@0
  2852
			}
insilmaril@0
  2853
			fio->save (fd->selectedFile(),fmt);
insilmaril@0
  2854
		}
insilmaril@0
  2855
	}
insilmaril@0
  2856
}
insilmaril@0
  2857
insilmaril@0
  2858
void MapEditor::setFrame(const FrameType &t)
insilmaril@0
  2859
{
insilmaril@0
  2860
	if (selection && 
insilmaril@0
  2861
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@0
  2862
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@0
  2863
	{
insilmaril@0
  2864
		selection->setFrameType (t);
insilmaril@0
  2865
		mapCenter->reposition();
insilmaril@0
  2866
		selection->updateLink();
insilmaril@0
  2867
	}
insilmaril@0
  2868
}
insilmaril@0
  2869
insilmaril@175
  2870
void MapEditor::setIncludeImagesVer(bool b)
insilmaril@175
  2871
{
insilmaril@175
  2872
	if (selection && 
insilmaril@175
  2873
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@175
  2874
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@175
  2875
		((BranchObj*)selection)->setIncludeImagesVer(b);
insilmaril@175
  2876
		mapCenter->reposition();
insilmaril@175
  2877
}
insilmaril@175
  2878
insilmaril@175
  2879
void MapEditor::setIncludeImagesHor(bool b)
insilmaril@175
  2880
{
insilmaril@175
  2881
	if (selection && 
insilmaril@175
  2882
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@175
  2883
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@175
  2884
		((BranchObj*)selection)->setIncludeImagesHor(b);
insilmaril@175
  2885
		mapCenter->reposition();
insilmaril@175
  2886
}
insilmaril@175
  2887
insilmaril@160
  2888
void MapEditor::setHideLinkUnselected (bool b)
insilmaril@160
  2889
{
insilmaril@160
  2890
	if (selection && 
insilmaril@160
  2891
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@160
  2892
		(typeid(*selection) == typeid(MapCenterObj))  ||
insilmaril@160
  2893
		(typeid(*selection) == typeid(FloatImageObj)) )
insilmaril@160
  2894
		selection->setHideLinkUnselected(b);
insilmaril@160
  2895
}
insilmaril@160
  2896
insilmaril@0
  2897
void MapEditor::importDir(BranchObj *dst, QDir d)
insilmaril@0
  2898
{
insilmaril@0
  2899
	if (selection && 
insilmaril@0
  2900
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@0
  2901
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@0
  2902
	{
insilmaril@0
  2903
		BranchObj *bo;
insilmaril@0
  2904
		
insilmaril@0
  2905
		// Traverse directories
insilmaril@0
  2906
		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
insilmaril@0
  2907
		const QFileInfoList *dirlist = d.entryInfoList();
insilmaril@0
  2908
		QFileInfoListIterator itdir( *dirlist );
insilmaril@0
  2909
		QFileInfo *fi;
insilmaril@0
  2910
insilmaril@0
  2911
		while ( (fi = itdir.current()) != 0 ) 
insilmaril@0
  2912
		{
insilmaril@0
  2913
			if (fi->fileName() != "." && fi->fileName() != ".." )
insilmaril@0
  2914
			{
insilmaril@0
  2915
				dst->addBranch();
insilmaril@0
  2916
				bo=dst->getLastBranch();
insilmaril@0
  2917
				bo->setHeading (fi->fileName() );
insilmaril@243
  2918
				bo->setColor (QColor("blue"));
insilmaril@0
  2919
				bo->toggleScroll();
insilmaril@0
  2920
				if ( !d.cd(fi->fileName()) ) 
insilmaril@159
  2921
					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
insilmaril@0
  2922
				else 
insilmaril@0
  2923
				{
insilmaril@103
  2924
					// Recursively add subdirs
insilmaril@0
  2925
					importDir (bo,d);
insilmaril@0
  2926
					d.cdUp();
insilmaril@0
  2927
				}
insilmaril@0
  2928
			}	
insilmaril@0
  2929
			++itdir;
insilmaril@0
  2930
		}		
insilmaril@0
  2931
		// Traverse files
insilmaril@0
  2932
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@0
  2933
		const QFileInfoList *filelist = d.entryInfoList();
insilmaril@0
  2934
		QFileInfoListIterator itfile( *filelist );
insilmaril@0
  2935
insilmaril@0
  2936
		while ( (fi = itfile.current()) != 0 ) 
insilmaril@0
  2937
		{
insilmaril@0
  2938
			dst->addBranch();
insilmaril@0
  2939
			bo=dst->getLastBranch();
insilmaril@0
  2940
			bo->setHeading (fi->fileName() );
insilmaril@243
  2941
			bo->setColor (QColor("black"));
insilmaril@103
  2942
			if (fi->fileName().right(4) == ".vym" )
insilmaril@103
  2943
				bo->setVymLink (fi->filePath());
insilmaril@103
  2944
insilmaril@0
  2945
			++itfile;
insilmaril@0
  2946
		}	
insilmaril@0
  2947
	}		
insilmaril@0
  2948
}
insilmaril@0
  2949
insilmaril@0
  2950
void MapEditor::importDir()
insilmaril@0
  2951
{
insilmaril@0
  2952
	if (selection && 
insilmaril@0
  2953
		(typeid(*selection) == typeid(BranchObj)) || 
insilmaril@0
  2954
		(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@0
  2955
	{
insilmaril@185
  2956
		QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
insilmaril@0
  2957
		fd->setMode (QFileDialog::DirectoryOnly);
insilmaril@0
  2958
		fd->addFilter (QString (tr("vym map") + " (*.vym)"));
insilmaril@185
  2959
		fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
insilmaril@0
  2960
		fd->show();
insilmaril@0
  2961
insilmaril@0
  2962
		QString fn;
insilmaril@0
  2963
		if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  2964
		{
insilmaril@163
  2965
			BranchObj *bo=((BranchObj*)selection);
insilmaril@0
  2966
			importDir (bo,QDir(fd->selectedFile()) );
insilmaril@0
  2967
			mapCenter->reposition();
insilmaril@0
  2968
			adjustCanvasSize();
insilmaril@0
  2969
			canvas()->update();
insilmaril@0
  2970
		}
insilmaril@0
  2971
	}	
insilmaril@0
  2972
}