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