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