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