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