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