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