mainwindow.cpp
author insilmaril
Wed Feb 15 12:54:55 2006 +0000 (2006-02-15)
changeset 205 30c4a6c7ff10
parent 200 451cab91e350
child 215 e211e2fc9d54
permissions -rw-r--r--
1.7.9 Import of KDE bookmarks, some _de translations
insilmaril@0
     1
#include "mainwindow.h"
insilmaril@0
     2
insilmaril@0
     3
#include <qstatusbar.h>
insilmaril@0
     4
#include <qmessagebox.h>
insilmaril@0
     5
#include <qmenubar.h>
insilmaril@0
     6
#include <qapplication.h>
insilmaril@0
     7
#include <qpainter.h>
insilmaril@0
     8
#include <qprinter.h>
insilmaril@0
     9
#include <qfile.h>
insilmaril@0
    10
#include <qfiledialog.h>
insilmaril@0
    11
#include <qcolor.h>
insilmaril@0
    12
#include <qcolordialog.h>
insilmaril@0
    13
#include <qbitmap.h>
insilmaril@0
    14
#include <qinputdialog.h>
insilmaril@175
    15
//#include <qdatetime.h>			// for random seed
insilmaril@0
    16
insilmaril@0
    17
insilmaril@0
    18
#include <iostream>
insilmaril@95
    19
#include <cstdlib>
insilmaril@0
    20
#include <typeinfo>
insilmaril@0
    21
insilmaril@0
    22
#include "icons/filenew.xpm"
insilmaril@0
    23
#include "icons/fileopen.xpm"
insilmaril@0
    24
#include "icons/filesave.xpm"
insilmaril@0
    25
#include "icons/fileprint.xpm"
insilmaril@0
    26
#include "icons/editundo.xpm"
insilmaril@163
    27
#include "icons/editredo.xpm"	
insilmaril@0
    28
#include "icons/editcopy.xpm"
insilmaril@0
    29
#include "icons/editcut.xpm"
insilmaril@0
    30
#include "icons/editpaste.xpm"
insilmaril@0
    31
#include "icons/editmoveup.xpm"
insilmaril@0
    32
#include "icons/editmovedown.xpm"
insilmaril@0
    33
#include "icons/formatcoloritem.xpm"
insilmaril@0
    34
#include "icons/formatcolorbranch.xpm"
insilmaril@0
    35
#include "icons/formatcolorpicker.xpm"
insilmaril@0
    36
#include "icons/viewzoomreset.xpm"
insilmaril@0
    37
#include "icons/viewzoomin.xpm"
insilmaril@0
    38
#include "icons/viewzoomout.xpm"
insilmaril@89
    39
#include "icons/modecolor.xpm"
insilmaril@89
    40
#include "icons/modelink.xpm"
insilmaril@93
    41
#include "icons/modecopy.xpm"
insilmaril@166
    42
#include "icons/flag-questionmark.xpm"
insilmaril@166
    43
#include "icons/flag-exclamationmark.xpm"
insilmaril@166
    44
#include "icons/flag-hook-green.xpm"
insilmaril@166
    45
#include "icons/flag-cross-red.xpm"
insilmaril@166
    46
#include "icons/flag-stopsign.xpm"
insilmaril@166
    47
#include "icons/flag-smiley-good.xpm"
insilmaril@166
    48
#include "icons/flag-smiley-sad.xpm"
insilmaril@166
    49
#include "icons/flag-clock.xpm"
insilmaril@166
    50
#include "icons/flag-lamp.xpm"
insilmaril@166
    51
#include "icons/flag-arrow-up.xpm"
insilmaril@166
    52
#include "icons/flag-arrow-down.xpm"
insilmaril@166
    53
#include "icons/flag-thumb-up.xpm"
insilmaril@166
    54
#include "icons/flag-thumb-down.xpm"
insilmaril@166
    55
#include "icons/flag-heart.xpm"
insilmaril@166
    56
#include "icons/flag-flash.xpm"
insilmaril@166
    57
#include "icons/flag-lifebelt.xpm"
insilmaril@0
    58
#include "icons/flag-note.xpm"
insilmaril@0
    59
#include "icons/flag-url.xpm"
insilmaril@0
    60
#include "icons/flag-vymlink.xpm"	
insilmaril@0
    61
#include "icons/flag-scrolled-right.xpm"
insilmaril@166
    62
#include "icons/flag-tmpUnscrolled-right.xpm"
insilmaril@0
    63
insilmaril@205
    64
#include "aboutdialog.h"
insilmaril@205
    65
#include "exporthtmldialog.h"
insilmaril@205
    66
#include "exportoofiledialog.h"
insilmaril@205
    67
#include "exportxhtmldialog.h"
insilmaril@205
    68
#include "file.h"
insilmaril@0
    69
#include "flagrowobj.h"
insilmaril@205
    70
#include "imports.h"
insilmaril@0
    71
#include "mapeditor.h"
insilmaril@205
    72
#include "misc.h"
insilmaril@205
    73
#include "options.h"
insilmaril@0
    74
#include "process.h"
insilmaril@0
    75
#include "settings.h"
insilmaril@205
    76
#include "showtextdialog.h"
insilmaril@205
    77
#include "texteditor.h"
insilmaril@205
    78
#include "version.h"
insilmaril@0
    79
insilmaril@0
    80
extern TextEditor *textEditor;
insilmaril@0
    81
extern Main *mainWindow;
insilmaril@164
    82
extern QString tmpVymDir;
insilmaril@166
    83
extern QString clipboardDir;
insilmaril@166
    84
extern bool clipboardEmpty;
insilmaril@0
    85
extern int statusbarTime;
insilmaril@0
    86
extern FlagRowObj* standardFlagsDefault;
insilmaril@166
    87
extern FlagRowObj* systemFlagsDefault;
insilmaril@0
    88
insilmaril@98
    89
extern QPtrList <QAction> actionListBranches;
insilmaril@98
    90
insilmaril@0
    91
extern QAction* actionFileSave;
insilmaril@0
    92
extern QAction* actionFilePrint;
insilmaril@0
    93
extern QAction* actionEditUndo;
insilmaril@163
    94
extern QAction* actionEditRedo;
insilmaril@0
    95
extern QAction *actionEditCopy;
insilmaril@0
    96
extern QAction *actionEditCut;
insilmaril@0
    97
extern QAction *actionEditPaste;
insilmaril@0
    98
extern QAction *actionEditMoveUp;
insilmaril@0
    99
extern QAction *actionEditMoveDown;
insilmaril@0
   100
extern QAction *actionEditToggleScroll;
insilmaril@0
   101
extern QAction* actionEditOpenURL;
insilmaril@0
   102
extern QAction* actionEditURL;
insilmaril@0
   103
extern QAction* actionEditHeading2URL;
insilmaril@0
   104
extern QAction* actionEditBugzilla2URL;
insilmaril@175
   105
extern QAction* actionEditFATE2URL;
insilmaril@0
   106
extern QAction *actionEditOpenVymLink;
insilmaril@0
   107
extern QAction *actionEditVymLink;
insilmaril@0
   108
extern QAction *actionEditDeleteVymLink;
insilmaril@0
   109
extern QAction *actionEditMapInfo;
insilmaril@0
   110
extern QAction *actionEditHeading;
insilmaril@0
   111
extern QAction *actionEditDelete;
insilmaril@0
   112
extern QAction *actionEditAddBranch;
insilmaril@98
   113
extern QAction *actionEditAddBranchHere;
insilmaril@0
   114
extern QAction *actionEditAddBranchAbove;
insilmaril@0
   115
extern QAction *actionEditAddBranchBelow;
insilmaril@98
   116
extern QAction *actionEditRemoveBranchHere;
insilmaril@98
   117
extern QAction *actionEditRemoveChilds;
insilmaril@0
   118
extern QAction *actionEditImportAdd;
insilmaril@0
   119
extern QAction *actionEditImportReplace;
insilmaril@0
   120
extern QAction *actionEditSaveBranch;
insilmaril@0
   121
extern QAction *actionEditSelectFirst;
insilmaril@0
   122
extern QAction *actionEditSelectLast;
insilmaril@0
   123
extern QAction *actionEditLoadImage;
insilmaril@0
   124
extern QAction *actionEditToggleFloatExport;
insilmaril@0
   125
insilmaril@0
   126
extern QAction* actionFormatColor;
insilmaril@0
   127
extern QAction* actionFormatPickColor;
insilmaril@0
   128
extern QAction* actionFormatColorBranch;
insilmaril@0
   129
extern QAction* actionFormatColorSubtree;
insilmaril@0
   130
extern QAction* actionFormatLinkColorHint;
insilmaril@0
   131
extern QAction* actionFormatBackColor;
insilmaril@0
   132
extern QAction* actionFormatLinkColor;
insilmaril@175
   133
extern QAction *actionFormatIncludeImagesVer;
insilmaril@175
   134
extern QAction *actionFormatIncludeImagesHor;
insilmaril@0
   135
insilmaril@89
   136
extern QActionGroup* actionGroupModModes;
insilmaril@89
   137
extern QAction* actionModModeColor;
insilmaril@89
   138
extern QAction* actionModModeLink;
insilmaril@93
   139
extern QAction* actionModModeCopy;
insilmaril@89
   140
insilmaril@0
   141
extern QActionGroup *actionGroupFormatFrameTypes;
insilmaril@0
   142
extern QAction *actionFormatFrameNone;
insilmaril@0
   143
extern QAction *actionFormatFrameRectangle;
insilmaril@0
   144
insilmaril@0
   145
extern QActionGroup *actionGroupFormatLinkStyles;
insilmaril@0
   146
extern QAction *actionFormatLinkStyleLine;
insilmaril@0
   147
extern QAction *actionFormatLinkStyleParabel;
insilmaril@0
   148
extern QAction *actionFormatLinkStylePolyLine;
insilmaril@0
   149
extern QAction *actionFormatLinkStylePolyParabel;
insilmaril@160
   150
extern QAction *actionFormatHideLinkUnselected;
insilmaril@0
   151
insilmaril@0
   152
extern QAction *actionViewToggleNoteEditor;
insilmaril@0
   153
insilmaril@0
   154
extern QAction* actionSettingsAutoedit;
insilmaril@0
   155
extern QAction* actionSettingsAutoselectHeading;
insilmaril@0
   156
extern QAction* actionSettingsAutoselectHeading;
insilmaril@0
   157
extern QAction* actionSettingsAutoselectText;
insilmaril@0
   158
extern QAction* actionSettingsPasteNewHeading;
insilmaril@0
   159
extern QAction* actionSettingsUseDelKey;
insilmaril@103
   160
extern QAction* actionSettingsUseFlagGroups;
insilmaril@0
   161
insilmaril@0
   162
extern QPopupMenu* branchContextMenu;
insilmaril@98
   163
extern QPopupMenu* branchAddContextMenu;
insilmaril@98
   164
extern QPopupMenu* branchRemoveContextMenu;
insilmaril@89
   165
extern QPopupMenu* branchLinksContextMenu;
insilmaril@94
   166
extern QPopupMenu* branchLinksContextMenuDup;
insilmaril@0
   167
extern QPopupMenu* floatimageContextMenu;
insilmaril@0
   168
extern QPopupMenu* saveImageFormatMenu;
insilmaril@0
   169
extern QPopupMenu* canvasContextMenu;
insilmaril@0
   170
extern QPopupMenu* lastMapsMenu;
insilmaril@205
   171
extern QPopupMenu* importMenu;
insilmaril@0
   172
extern QPopupMenu* exportMenu;
insilmaril@0
   173
extern QPopupMenu* exportImageFormatMenu;
insilmaril@0
   174
insilmaril@0
   175
insilmaril@0
   176
extern Settings settings;
insilmaril@0
   177
extern Options options;
insilmaril@0
   178
insilmaril@0
   179
#if defined(Q_OS_LINUX)
insilmaril@0
   180
extern void qt_wait_for_window_manager( QWidget* w );
insilmaril@0
   181
#endif
insilmaril@0
   182
insilmaril@0
   183
Main::Main(QWidget* parent, const char* name, WFlags f) :
insilmaril@0
   184
    QMainWindow(parent,name,f)
insilmaril@0
   185
{
insilmaril@0
   186
	mainWindow=this;
insilmaril@0
   187
insilmaril@0
   188
	setCaption ("VYM - View Your Mind");
insilmaril@0
   189
insilmaril@0
   190
	// Load window settings
insilmaril@0
   191
	resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
insilmaril@0
   192
	        settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
insilmaril@0
   193
	move   (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
insilmaril@0
   194
	        settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
insilmaril@0
   195
insilmaril@0
   196
insilmaril@164
   197
	// Create unique temporary directory
insilmaril@164
   198
	tmpVymDir=makeUniqueDir ("/tmp/vym-XXXXXX");
insilmaril@164
   199
insilmaril@166
   200
	// Create direcctory for clipboard
insilmaril@166
   201
	clipboardDir=tmpVymDir+"/clipboard";
insilmaril@166
   202
	QDir d(clipboardDir);
insilmaril@166
   203
	d.mkdir (clipboardDir,true);
insilmaril@166
   204
	makeSubDirs (clipboardDir);
insilmaril@166
   205
	clipboardEmpty=true;
insilmaril@164
   206
insilmaril@166
   207
	// FIXME not used currently
insilmaril@93
   208
	// Set random seed (random used for object IDs)
insilmaril@166
   209
    // QTime t = QTime::currentTime();		// set random seed
insilmaril@166
   210
    // srand( t.hour()*12+t.minute()*60+t.second()*60 );
insilmaril@93
   211
insilmaril@93
   212
insilmaril@0
   213
	// Initialize some settings, which are platform dependant
insilmaril@0
   214
	QString p,s;
insilmaril@0
   215
insilmaril@0
   216
		// application to open URLs
insilmaril@0
   217
		p="/vym/mainwindow/readerURL";
insilmaril@0
   218
		#if defined(Q_OS_LINUX)
insilmaril@0
   219
			s=settings.readEntry (p,"konqueror");
insilmaril@0
   220
		#else
insilmaril@0
   221
			#if defined(Q_OS_MACX)
insilmaril@104
   222
				s=settings.readEntry (p,"/usr/bin/open");
insilmaril@0
   223
			#else
insilmaril@0
   224
				s=settings.readEntry (p,"mozilla");
insilmaril@0
   225
			#endif
insilmaril@0
   226
		#endif
insilmaril@0
   227
		settings.writeEntry( p,s);
insilmaril@0
   228
insilmaril@0
   229
		// application to open PDFs
insilmaril@0
   230
		p="/vym/mainwindow/readerPDF";
insilmaril@0
   231
		#if defined(Q_OS_LINUX)
insilmaril@0
   232
			s=settings.readEntry (p,"acroread");
insilmaril@0
   233
		#else
insilmaril@0
   234
			#if defined(Q_OS_MACX)
insilmaril@104
   235
				s=settings.readEntry (p,"/usr/bin/open");
insilmaril@0
   236
			#else
insilmaril@0
   237
				s=settings.readEntry (p,"acroread");
insilmaril@0
   238
			#endif
insilmaril@0
   239
		#endif
insilmaril@0
   240
		settings.writeEntry( p,s);
insilmaril@0
   241
insilmaril@0
   242
	
insilmaril@0
   243
	maxLastMaps=9;
insilmaril@0
   244
insilmaril@0
   245
	// Create tab widget which holds the maps
insilmaril@0
   246
	tabWidget= new QTabWidget (this);
insilmaril@0
   247
	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
insilmaril@0
   248
		this, SLOT( editorChanged( QWidget * ) ) );
insilmaril@0
   249
insilmaril@0
   250
	setCentralWidget(tabWidget);	
insilmaril@0
   251
insilmaril@0
   252
    setupFileActions();
insilmaril@0
   253
    setupEditActions();
insilmaril@0
   254
    setupFormatActions();
insilmaril@0
   255
    setupViewActions();
insilmaril@89
   256
    setupModeActions();
insilmaril@0
   257
	setupFlagActions();
insilmaril@0
   258
    setupSettingsActions();
insilmaril@0
   259
	setupContextMenus();
insilmaril@0
   260
    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
insilmaril@0
   261
    setupHelpActions();
insilmaril@0
   262
    
insilmaril@0
   263
	// After menu is created, we can enable some actions
insilmaril@0
   264
	actionFilePrint->setEnabled (true);
insilmaril@0
   265
insilmaril@0
   266
    statusBar();
insilmaril@0
   267
insilmaril@0
   268
insilmaril@0
   269
	// Initialize Find window
insilmaril@0
   270
	findWindow=new FindWindow(NULL,"findwindow");
insilmaril@0
   271
	connect (findWindow, SIGNAL( findButton(QString) ), 
insilmaril@0
   272
		this, SLOT(editFind(QString) ) );	
insilmaril@0
   273
	connect (findWindow, SIGNAL( somethingChanged() ), 
insilmaril@0
   274
		this, SLOT(editFindChanged() ) );	
insilmaril@0
   275
insilmaril@160
   276
	// Connect TextEditor, so that we can update flags if text changes
insilmaril@160
   277
	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
insilmaril@160
   278
insilmaril@0
   279
	updateGeometry();
insilmaril@0
   280
}
insilmaril@0
   281
insilmaril@0
   282
Main::~Main()
insilmaril@0
   283
{
insilmaril@0
   284
	// Save Settings
insilmaril@0
   285
	settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
insilmaril@0
   286
	settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
insilmaril@0
   287
	settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
insilmaril@0
   288
	settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
insilmaril@0
   289
insilmaril@185
   290
	settings.writeEntry( "/vym/version/version", __VYM_VERSION );
insilmaril@185
   291
	settings.writeEntry( "/vym/version/builddate", __BUILD_DATE );
insilmaril@0
   292
insilmaril@0
   293
	settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
insilmaril@0
   294
	settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
insilmaril@0
   295
	settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
insilmaril@0
   296
	settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
insilmaril@0
   297
	settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
insilmaril@103
   298
	settings.writeEntry( "/vym/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
insilmaril@0
   299
insilmaril@0
   300
	QString s;
insilmaril@0
   301
	int maps=lastMaps.count();
insilmaril@0
   302
	settings.writeEntry( "/vym/lastMaps/number",maps );
insilmaril@0
   303
	for (int i=1;i<=maps;i++)
insilmaril@0
   304
	{
insilmaril@0
   305
		QStringList::Iterator it = lastMaps.at(i-1);
insilmaril@0
   306
		s=QString("/vym/lastMaps/map-%1").arg(i);
insilmaril@0
   307
		if (!s.isEmpty() && i<=maxLastMaps) 
insilmaril@0
   308
			settings.writeEntry (s, *it);
insilmaril@0
   309
	}
insilmaril@0
   310
insilmaril@0
   311
insilmaril@0
   312
	// To make the texteditor save its settings, call the destructor
insilmaril@0
   313
	delete (textEditor);
insilmaril@164
   314
insilmaril@164
   315
	// Remove temporary directory
insilmaril@164
   316
	removeDir (QDir(tmpVymDir));
insilmaril@0
   317
}
insilmaril@0
   318
insilmaril@0
   319
void Main::loadCmdLine()
insilmaril@0
   320
{
insilmaril@0
   321
	/* TODO draw some kind of splashscreen while loading...
insilmaril@0
   322
	if (qApp->argc()>1)
insilmaril@0
   323
	{
insilmaril@0
   324
	}
insilmaril@0
   325
	*/
insilmaril@0
   326
	
insilmaril@0
   327
	QStringList flist=options.getFileList();
insilmaril@0
   328
	QStringList::Iterator it=flist.begin();
insilmaril@0
   329
insilmaril@0
   330
	while (it !=flist.end() )
insilmaril@0
   331
	{
insilmaril@0
   332
		fileLoad (*it, NewMap);
insilmaril@0
   333
		*it++;
insilmaril@0
   334
	}	
insilmaril@0
   335
}
insilmaril@0
   336
insilmaril@0
   337
insilmaril@0
   338
void Main::statusMessage(const QString &s)
insilmaril@0
   339
{
insilmaril@0
   340
	statusBar()->message (s);
insilmaril@0
   341
}
insilmaril@0
   342
insilmaril@0
   343
void Main::closeEvent (QCloseEvent* )
insilmaril@0
   344
{
insilmaril@0
   345
	fileExitVYM();
insilmaril@0
   346
}
insilmaril@0
   347
insilmaril@0
   348
// File Actions
insilmaril@0
   349
void Main::setupFileActions()
insilmaril@0
   350
{
insilmaril@0
   351
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   352
    tb->setLabel( "File Actions" );
insilmaril@0
   353
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   354
    menuBar()->insertItem( tr( "&File" ), menu );
insilmaril@0
   355
insilmaril@0
   356
	// Keycodes:  /usr/lib64/qt3/include/qnamespace.h
insilmaril@0
   357
insilmaril@0
   358
    QAction *a;
insilmaril@91
   359
    a = new QAction( tr( "New map","File menu" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
insilmaril@0
   360
    connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
insilmaril@0
   361
    a->addTo( tb );
insilmaril@0
   362
    a->addTo( menu );
insilmaril@0
   363
	
insilmaril@91
   364
    a = new QAction( tr( "Open","File menu" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
insilmaril@0
   365
    connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
insilmaril@0
   366
    a->addTo( tb );
insilmaril@0
   367
    a->addTo( menu );
insilmaril@0
   368
	
insilmaril@0
   369
	lastMapsMenu = new QPopupMenu (this);
insilmaril@0
   370
insilmaril@0
   371
    menu->insertItem (tr("Open Recent"),lastMapsMenu );
insilmaril@0
   372
    menu->insertSeparator();
insilmaril@0
   373
	
insilmaril@0
   374
    a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
insilmaril@0
   375
    connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
insilmaril@0
   376
    a->addTo( tb );
insilmaril@0
   377
    a->addTo( menu );
insilmaril@0
   378
	actionFileSave=a;
insilmaril@0
   379
	
insilmaril@0
   380
    a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
insilmaril@0
   381
    connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
insilmaril@0
   382
    a->addTo( menu );
insilmaril@0
   383
insilmaril@0
   384
    menu->insertSeparator();
insilmaril@0
   385
insilmaril@205
   386
	importMenu = new QPopupMenu (this);
insilmaril@205
   387
    menu->insertItem (tr("Import"),importMenu );
insilmaril@205
   388
insilmaril@205
   389
	a = new QAction( tr( "Import")+" "+tr("KDE Bookmarks" ), QPixmap(), tr("KDE Bookmarks"), 0, this, "importKDEBookmarks" );
insilmaril@205
   390
	connect( a, SIGNAL( activated() ), this, SLOT( fileImportKDEBookmarks() ) );
insilmaril@205
   391
	a->addTo (importMenu);
insilmaril@205
   392
insilmaril@151
   393
    a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir"+QString("...") ), 0, this, "export" );
insilmaril@0
   394
    connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
insilmaril@205
   395
    a->addTo( importMenu);
insilmaril@0
   396
insilmaril@0
   397
	exportMenu = new QPopupMenu (this);
insilmaril@0
   398
    menu->insertItem (tr("Export"),exportMenu );
insilmaril@0
   399
insilmaril@0
   400
    menu->insertSeparator();
insilmaril@0
   401
insilmaril@0
   402
insilmaril@0
   403
    a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
insilmaril@0
   404
    connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
insilmaril@0
   405
    a->addTo( tb );
insilmaril@0
   406
    a->addTo( menu );
insilmaril@0
   407
	actionFilePrint=a;
insilmaril@0
   408
insilmaril@0
   409
    a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
insilmaril@0
   410
    connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
insilmaril@0
   411
    a->addTo( menu );
insilmaril@0
   412
insilmaril@185
   413
    a = new QAction( tr( "Exit")+" "+__VYM, QPixmap(), tr( "E&xit")+" "+__VYM, CTRL + Key_Q, this, "fileExitVYM" );
insilmaril@0
   414
    connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
insilmaril@0
   415
    a->addTo( menu );
insilmaril@0
   416
}
insilmaril@0
   417
insilmaril@0
   418
insilmaril@0
   419
//Edit Actions
insilmaril@0
   420
void Main::setupEditActions()
insilmaril@0
   421
{
insilmaril@0
   422
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   423
    tb->setLabel( "Edit Actions" );
insilmaril@0
   424
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   425
    menuBar()->insertItem( tr( "&Edit" ), menu );
insilmaril@0
   426
insilmaril@0
   427
    QAction *a;
insilmaril@102
   428
	QAction *alt;
insilmaril@0
   429
    a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
insilmaril@0
   430
    connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
insilmaril@0
   431
	a->setEnabled (false);
insilmaril@0
   432
    a->addTo( tb );
insilmaril@0
   433
    a->addTo( menu );
insilmaril@0
   434
	actionEditUndo=a;
insilmaril@163
   435
    
insilmaril@163
   436
    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
insilmaril@163
   437
	{
insilmaril@163
   438
		a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); 
insilmaril@163
   439
		connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
insilmaril@163
   440
		a->addTo( tb );
insilmaril@163
   441
		a->addTo( menu );
insilmaril@163
   442
	}
insilmaril@163
   443
   
insilmaril@0
   444
    menu->insertSeparator();
insilmaril@0
   445
    a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
insilmaril@0
   446
    connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
insilmaril@0
   447
	a->setEnabled (false);
insilmaril@0
   448
    a->addTo( tb );
insilmaril@0
   449
    a->addTo( menu );
insilmaril@0
   450
	actionEditCopy=a;
insilmaril@0
   451
    a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
insilmaril@0
   452
    connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
insilmaril@0
   453
	a->setEnabled (false);
insilmaril@0
   454
    a->addTo( tb );
insilmaril@0
   455
    a->addTo( menu );
insilmaril@0
   456
	actionEditCut=a;
insilmaril@0
   457
    a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
insilmaril@0
   458
    connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
insilmaril@0
   459
	a->setEnabled (false);
insilmaril@0
   460
    a->addTo( tb );
insilmaril@0
   461
    a->addTo( menu );
insilmaril@0
   462
	actionEditPaste=a;
insilmaril@98
   463
insilmaril@0
   464
    a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
insilmaril@0
   465
    connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
insilmaril@0
   466
	a->setEnabled (false);
insilmaril@0
   467
    a->addTo( tb );
insilmaril@0
   468
    a->addTo( menu );
insilmaril@98
   469
	actionListBranches.append(a);
insilmaril@0
   470
	actionEditMoveUp=a;
insilmaril@98
   471
insilmaril@0
   472
    a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
insilmaril@0
   473
    connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
insilmaril@0
   474
	a->setEnabled (false);
insilmaril@0
   475
    a->addTo( tb );
insilmaril@0
   476
    a->addTo( menu );
insilmaril@98
   477
	actionListBranches.append(a);
insilmaril@0
   478
	actionEditMoveDown=a;
insilmaril@98
   479
	
insilmaril@0
   480
insilmaril@102
   481
	a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
insilmaril@0
   482
    connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
insilmaril@102
   483
	alt = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_S, this, "scroll" );
insilmaril@102
   484
    connect( alt, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
insilmaril@102
   485
	#if defined(Q_OS_MACX)
insilmaril@102
   486
		actionEditToggleScroll=alt;
insilmaril@102
   487
	#else	
insilmaril@102
   488
		actionEditToggleScroll=a;
insilmaril@102
   489
	#endif	
insilmaril@102
   490
	actionEditToggleScroll->setEnabled (false);
insilmaril@102
   491
    actionEditToggleScroll->addTo( tb );
insilmaril@102
   492
    actionEditToggleScroll->addTo( menu );
insilmaril@102
   493
	actionListBranches.append(actionEditToggleScroll);
insilmaril@0
   494
	
insilmaril@0
   495
    a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
insilmaril@0
   496
    connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
insilmaril@0
   497
    a->addTo( menu );
insilmaril@0
   498
	
insilmaril@0
   499
    menu->insertSeparator();
insilmaril@0
   500
insilmaril@151
   501
	a = new QAction( tr( "Find" ), QPixmap(), tr( "Find"+QString("...") ), CTRL + Key_F, this, "find" );
insilmaril@0
   502
    connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
insilmaril@0
   503
    a->addTo( menu );
insilmaril@0
   504
    
insilmaril@0
   505
	menu->insertSeparator();
insilmaril@0
   506
insilmaril@0
   507
	a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
insilmaril@0
   508
    connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
insilmaril@0
   509
    a->addTo( tb );
insilmaril@0
   510
	a->setEnabled (false);
insilmaril@0
   511
	actionEditOpenURL=a;
insilmaril@0
   512
insilmaril@151
   513
	a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL"+QString("...") ), SHIFT + CTRL + Key_U, this, "url" );
insilmaril@0
   514
    connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
insilmaril@0
   515
	a->setEnabled (false);
insilmaril@98
   516
	actionListBranches.append(a);
insilmaril@0
   517
	actionEditURL=a;
insilmaril@0
   518
	
insilmaril@0
   519
	a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
insilmaril@0
   520
    connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
insilmaril@0
   521
	a->setEnabled (false);
insilmaril@98
   522
	actionListBranches.append(a);
insilmaril@0
   523
	actionEditHeading2URL=a;
insilmaril@0
   524
    
insilmaril@0
   525
	a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
insilmaril@0
   526
    connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
insilmaril@0
   527
	a->setEnabled (false);
insilmaril@98
   528
	actionListBranches.append(a);
insilmaril@0
   529
	actionEditBugzilla2URL=a;
insilmaril@0
   530
    
insilmaril@175
   531
	a = new QAction( tr( "Create URL to FATE" ), QPixmap(), tr( "Create URL to FATE" ), 0, this, "FATE2url" );
insilmaril@175
   532
    connect( a, SIGNAL( activated() ), this, SLOT( editFATE2URL() ) );
insilmaril@175
   533
	a->setEnabled (false);
insilmaril@175
   534
	actionListBranches.append(a);
insilmaril@175
   535
	actionEditFATE2URL=a;
insilmaril@0
   536
	
insilmaril@0
   537
    a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" );
insilmaril@0
   538
    connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
insilmaril@0
   539
    a->addTo( tb );
insilmaril@0
   540
	a->setEnabled (false);
insilmaril@0
   541
	actionEditOpenVymLink=a;
insilmaril@0
   542
	
insilmaril@151
   543
    a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link"+QString("...") ), 0, this, "editLinkMap" );
insilmaril@0
   544
    connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
insilmaril@0
   545
	a->setEnabled (false);
insilmaril@98
   546
	actionListBranches.append(a);
insilmaril@0
   547
	actionEditVymLink=a;
insilmaril@0
   548
insilmaril@0
   549
    a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
insilmaril@0
   550
    connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
insilmaril@0
   551
	a->setEnabled (false);
insilmaril@0
   552
	actionEditDeleteVymLink=a;
insilmaril@0
   553
insilmaril@151
   554
    a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info"+QString("...") ), 0, this, "editMapInfo" );
insilmaril@0
   555
    connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
insilmaril@0
   556
	a->setEnabled (true);
insilmaril@0
   557
	actionEditMapInfo=a;
insilmaril@0
   558
insilmaril@0
   559
	menu->insertSeparator();
insilmaril@0
   560
insilmaril@0
   561
    // Shortcuts to modify heading:
insilmaril@0
   562
    a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
insilmaril@0
   563
    connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
insilmaril@98
   564
	actionListBranches.append(a);
insilmaril@0
   565
    a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
insilmaril@0
   566
    connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
insilmaril@98
   567
	actionListBranches.append(a);
insilmaril@89
   568
	actionEditHeading=a;
insilmaril@89
   569
    a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_F2, this, "editHeading" );
insilmaril@89
   570
    connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
insilmaril@102
   571
	a->setEnabled (false);
insilmaril@102
   572
	actionEditHeading=a;
insilmaril@98
   573
	actionListBranches.append(a);
insilmaril@0
   574
    
insilmaril@0
   575
    // Shortcut to delete selection
insilmaril@0
   576
    a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
insilmaril@0
   577
    connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
insilmaril@0
   578
	a->setEnabled (false);
insilmaril@0
   579
	actionEditDelete=a;
insilmaril@0
   580
    
insilmaril@0
   581
    // Shortcut to add branch
insilmaril@102
   582
	alt = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_A, this, "newBranch" );
insilmaril@102
   583
    connect( alt, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
insilmaril@0
   584
		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
insilmaril@0
   585
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
insilmaril@0
   586
	a->setEnabled (false);
insilmaril@98
   587
	actionListBranches.append(a);
insilmaril@102
   588
	#if defined (Q_OS_MACX)
insilmaril@175
   589
		// In OSX show different shortcut in menues, the keys work independtly always			
insilmaril@102
   590
		actionEditAddBranch=alt;
insilmaril@102
   591
	#else	
insilmaril@102
   592
		actionEditAddBranch=a;
insilmaril@102
   593
	#endif	
insilmaril@0
   594
insilmaril@98
   595
    // Add branch by inserting it at selection
insilmaril@98
   596
	a = new QAction( tr( "Add a branch by inserting and making selection its child" ),tr( "Add branch (insert)" ), ALT + Key_Insert, this, "newBranchHere" );
insilmaril@98
   597
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchHere() ) );
insilmaril@98
   598
	a->setEnabled (false);
insilmaril@98
   599
	actionListBranches.append(a);
insilmaril@98
   600
	actionEditAddBranchHere=a;
insilmaril@175
   601
	a = new QAction( tr( "Add a branch by inserting and making selection its child" ),tr( "Add branch (insert)" ), ALT + Key_A, this, "newBranchHere" );
insilmaril@175
   602
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchHere() ) );
insilmaril@175
   603
	actionListBranches.append(a);
insilmaril@98
   604
insilmaril@0
   605
	// Add branch above
insilmaril@0
   606
    a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
insilmaril@0
   607
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
insilmaril@0
   608
	a->setEnabled (false);
insilmaril@98
   609
	actionListBranches.append(a);
insilmaril@0
   610
	actionEditAddBranchAbove=a;
insilmaril@175
   611
    a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_A, this, "newBranch" );
insilmaril@175
   612
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
insilmaril@175
   613
	actionListBranches.append(a);
insilmaril@0
   614
insilmaril@0
   615
	// Add branch below 
insilmaril@0
   616
    a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
insilmaril@0
   617
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
insilmaril@0
   618
	a->setEnabled (false);
insilmaril@98
   619
	actionListBranches.append(a);
insilmaril@0
   620
	actionEditAddBranchBelow=a;
insilmaril@175
   621
    a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_A, this, "newBranch" );
insilmaril@175
   622
    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
insilmaril@175
   623
	actionListBranches.append(a);
insilmaril@0
   624
insilmaril@0
   625
	// Import at selection (adding to selection)
insilmaril@0
   626
    a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
insilmaril@0
   627
    connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
insilmaril@0
   628
	a->setEnabled (false);
insilmaril@98
   629
	actionListBranches.append(a);
insilmaril@0
   630
	actionEditImportAdd=a;
insilmaril@0
   631
insilmaril@0
   632
	// Import at selection (replacing selection)
insilmaril@0
   633
    a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
insilmaril@0
   634
    connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
insilmaril@0
   635
	a->setEnabled (false);
insilmaril@98
   636
	actionListBranches.append(a);
insilmaril@0
   637
	actionEditImportReplace=a;
insilmaril@0
   638
insilmaril@0
   639
	// Save selection 
insilmaril@98
   640
    a = new QAction( tr( "Save selection" ),tr( "Save selection" ), 0, this, "saveSelection" );
insilmaril@0
   641
    connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
insilmaril@0
   642
	a->setEnabled (false);
insilmaril@98
   643
	actionListBranches.append(a);
insilmaril@0
   644
	actionEditSaveBranch=a;
insilmaril@0
   645
insilmaril@98
   646
	// Only remove branch, not its childs
insilmaril@98
   647
    a = new QAction( tr( "Remove only branch and keep its childs" ),tr( "Remove only branch " ), ALT + Key_Delete, this, "removeBranchHere" );
insilmaril@98
   648
    connect( a, SIGNAL( activated() ), this, SLOT( editRemoveBranchHere() ) );
insilmaril@98
   649
	a->setEnabled (false);
insilmaril@98
   650
	actionListBranches.append(a);
insilmaril@98
   651
	actionEditRemoveBranchHere=a;
insilmaril@98
   652
insilmaril@98
   653
	// Only remove childs of a branch
insilmaril@98
   654
    a = new QAction( tr( "Remove childs of branch" ),tr( "Remove childs" ), SHIFT + Key_Delete, this, "removeBranchChilds" );
insilmaril@98
   655
    connect( a, SIGNAL( activated() ), this, SLOT( editRemoveChilds() ) );
insilmaril@98
   656
	a->setEnabled (false);
insilmaril@98
   657
	actionListBranches.append(a);
insilmaril@98
   658
	actionEditRemoveChilds=a;
insilmaril@98
   659
insilmaril@0
   660
    // Shortcuts for navigating with cursor:
insilmaril@0
   661
    a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
insilmaril@0
   662
    connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
insilmaril@0
   663
    a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
insilmaril@0
   664
    connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
insilmaril@0
   665
    a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
insilmaril@0
   666
    connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
insilmaril@0
   667
    a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
insilmaril@0
   668
    connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
insilmaril@0
   669
    a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
insilmaril@0
   670
	a->setEnabled (false);
insilmaril@0
   671
    a->addTo ( menu );
insilmaril@98
   672
	actionListBranches.append(a);
insilmaril@0
   673
	actionEditSelectFirst=a;
insilmaril@0
   674
    connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
insilmaril@0
   675
    a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
insilmaril@0
   676
    connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
insilmaril@0
   677
	a->setEnabled (false);
insilmaril@0
   678
    a->addTo ( menu );
insilmaril@98
   679
	actionListBranches.append(a);
insilmaril@0
   680
	actionEditSelectLast=a;
insilmaril@0
   681
insilmaril@151
   682
    a = new QAction( tr( "Add Image" ),tr( "Add Image" )+QString("..."), 0, this, "loadImage" );
insilmaril@0
   683
    connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
insilmaril@0
   684
	actionEditLoadImage=a;
insilmaril@89
   685
insilmaril@0
   686
}
insilmaril@0
   687
insilmaril@0
   688
// Format Actions
insilmaril@0
   689
void Main::setupFormatActions()
insilmaril@0
   690
{
insilmaril@0
   691
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   692
    menuBar()->insertItem( tr( "&Format" ), menu );
insilmaril@0
   693
insilmaril@0
   694
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   695
    QAction *a;
insilmaril@0
   696
    QPixmap pix( 16,16);
insilmaril@0
   697
    pix.fill (black);
insilmaril@151
   698
    actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" )+QString("..."), 0, this, "formatColor" );
insilmaril@0
   699
    connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
insilmaril@0
   700
    actionFormatColor->addTo( tb );
insilmaril@0
   701
    actionFormatColor->addTo( menu );
insilmaril@0
   702
    a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" );
insilmaril@0
   703
    connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
insilmaril@0
   704
	a->setEnabled (false);
insilmaril@0
   705
    a->addTo( tb );
insilmaril@0
   706
    a->addTo( menu );
insilmaril@98
   707
	actionListBranches.append(a);
insilmaril@0
   708
	actionFormatPickColor=a;
insilmaril@0
   709
    a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
insilmaril@0
   710
    connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
insilmaril@0
   711
	a->setEnabled (false);
insilmaril@0
   712
    a->addTo( tb );
insilmaril@0
   713
    a->addTo( menu );
insilmaril@98
   714
	actionListBranches.append(a);
insilmaril@0
   715
	actionFormatColorBranch=a;
insilmaril@0
   716
    a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
insilmaril@0
   717
    connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
insilmaril@0
   718
	a->setEnabled (false);
insilmaril@0
   719
    a->addTo( menu );
insilmaril@0
   720
    a->addTo( tb );
insilmaril@98
   721
	actionListBranches.append(a);
insilmaril@0
   722
	actionFormatColorSubtree=a;
insilmaril@0
   723
insilmaril@0
   724
    menu->insertSeparator();
insilmaril@0
   725
	actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
insilmaril@0
   726
	actionGroupFormatLinkStyles->setExclusive (true);
insilmaril@0
   727
    a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
insilmaril@0
   728
	a->setToggleAction(true);
insilmaril@0
   729
    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
insilmaril@0
   730
	actionFormatLinkStyleLine=a;
insilmaril@0
   731
    a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
insilmaril@0
   732
	a->setToggleAction(true);
insilmaril@0
   733
    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
insilmaril@0
   734
	actionFormatLinkStyleParabel=a;
insilmaril@0
   735
    a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
insilmaril@0
   736
	a->setToggleAction(true);
insilmaril@0
   737
    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
insilmaril@0
   738
	actionFormatLinkStylePolyLine=a;
insilmaril@0
   739
    a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
insilmaril@0
   740
	a->setToggleAction(true);
insilmaril@0
   741
    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
insilmaril@0
   742
	actionFormatLinkStylePolyParabel=a;
insilmaril@0
   743
	actionGroupFormatLinkStyles->addTo (menu);
insilmaril@0
   744
	
insilmaril@0
   745
	actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
insilmaril@0
   746
	actionGroupFormatFrameTypes->setExclusive (true);
insilmaril@0
   747
    a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
insilmaril@0
   748
	a->setToggleAction(true);
insilmaril@0
   749
    connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
insilmaril@0
   750
	actionFormatFrameNone=a;
insilmaril@0
   751
    a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
insilmaril@0
   752
	a->setToggleAction(true);
insilmaril@0
   753
    connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
insilmaril@0
   754
	actionFormatFrameRectangle=a;
insilmaril@0
   755
insilmaril@175
   756
    a = new QAction( tr ("Include top and bottom position of images into branch"), tr( "Include images vertically" ), 0, actionFormatIncludeImagesVer, "includeImagesVer" );
insilmaril@175
   757
	a->setToggleAction(true);
insilmaril@175
   758
    connect( a, SIGNAL( activated() ), this, SLOT( formatIncludeImagesVer() ) );
insilmaril@175
   759
	actionFormatIncludeImagesVer=a;
insilmaril@175
   760
insilmaril@175
   761
    a = new QAction( tr ("Include left and right position of images into branch"), tr( "Include images horizontally" ), 0, actionFormatIncludeImagesHor, "includeImagesHor" );
insilmaril@175
   762
	a->setToggleAction(true);
insilmaril@175
   763
    connect( a, SIGNAL( activated() ), this, SLOT( formatIncludeImagesHor() ) );
insilmaril@175
   764
	actionFormatIncludeImagesHor=a;
insilmaril@175
   765
insilmaril@160
   766
    a = new QAction( tr( "Hide link" ),tr( "Hide link if object is not selected" ), 0, actionFormatHideLinkUnselected, "hideLinkUnselected" );
insilmaril@160
   767
	a->setToggleAction(true);
insilmaril@160
   768
    connect( a, SIGNAL( activated() ), this, SLOT( formatHideLinkUnselected() ) );
insilmaril@160
   769
	actionFormatHideLinkUnselected=a;
insilmaril@160
   770
insilmaril@0
   771
    menu->insertSeparator();
insilmaril@0
   772
    a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
insilmaril@0
   773
	a->setToggleAction(true);
insilmaril@0
   774
    connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
insilmaril@0
   775
	a->addTo( menu );
insilmaril@0
   776
	actionFormatLinkColorHint=a;
insilmaril@0
   777
    pix.fill (white);
insilmaril@151
   778
    actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color"+QString("...") ), 0, this, "formatLinkColor" );
insilmaril@0
   779
    connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
insilmaril@0
   780
    actionFormatLinkColor->addTo( menu );
insilmaril@151
   781
    actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" )+QString("..."), 0, this, "formatBackColor" );
insilmaril@0
   782
    connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
insilmaril@0
   783
    actionFormatBackColor->addTo( menu );
insilmaril@0
   784
}
insilmaril@0
   785
insilmaril@0
   786
// View Actions
insilmaril@0
   787
void Main::setupViewActions()
insilmaril@0
   788
{
insilmaril@0
   789
    QToolBar *tb = new QToolBar( this );
insilmaril@0
   790
    tb->setLabel( "View Actions" );
insilmaril@0
   791
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   792
    menuBar()->insertItem( tr( "&View" ), menu );
insilmaril@0
   793
insilmaril@0
   794
    QAction *a;
insilmaril@151
   795
    a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), CTRL + Key_0, this, "zoomReset" );
insilmaril@0
   796
    connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
insilmaril@0
   797
    a->addTo( tb );
insilmaril@0
   798
    a->addTo( menu );
insilmaril@0
   799
    a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
insilmaril@0
   800
    connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
insilmaril@0
   801
    a->addTo( tb );
insilmaril@0
   802
    a->addTo( menu );
insilmaril@0
   803
    a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
insilmaril@0
   804
    connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
insilmaril@0
   805
    a->addTo( tb );
insilmaril@0
   806
    a->addTo( menu );
insilmaril@0
   807
    a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
insilmaril@0
   808
    connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
insilmaril@0
   809
	a->setToggleAction(true);
insilmaril@0
   810
	if (textEditor->showWithMain())
insilmaril@0
   811
		a->setOn(true);
insilmaril@0
   812
	else	
insilmaril@0
   813
		a->setOn(false);
insilmaril@0
   814
    a->addTo( tb );
insilmaril@0
   815
    a->addTo( menu );
insilmaril@0
   816
	actionViewToggleNoteEditor=a;
insilmaril@0
   817
    a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
insilmaril@0
   818
    connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
insilmaril@0
   819
    a->addTo( menu );
insilmaril@0
   820
    a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
insilmaril@0
   821
    connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
insilmaril@0
   822
    a->addTo( menu );
insilmaril@0
   823
}
insilmaril@0
   824
insilmaril@89
   825
// Mode Actions
insilmaril@89
   826
void Main::setupModeActions()
insilmaril@89
   827
{
insilmaril@89
   828
    //QPopupMenu *menu = new QPopupMenu( this );
insilmaril@89
   829
    //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
insilmaril@89
   830
insilmaril@89
   831
    QToolBar *tb = new QToolBar( this );
insilmaril@91
   832
    tb->setLabel( tr ("Modes when using modifiers") );
insilmaril@89
   833
    QAction *a;
insilmaril@89
   834
	actionGroupModModes=new QActionGroup ( this, "formatLinkStyles");
insilmaril@89
   835
	actionGroupModModes->setExclusive (true);
insilmaril@125
   836
    a= new QAction( tr( "Use modifier to color branches" ), QPixmap(modecolor_xpm), 0, Key_J, actionGroupModModes, "modModeColor" );
insilmaril@89
   837
	a->setToggleAction(true);
insilmaril@89
   838
	a->addTo (tb);
insilmaril@89
   839
	a->setOn(true);
insilmaril@89
   840
	actionModModeColor=a;
insilmaril@104
   841
	
insilmaril@125
   842
    a= new QAction( tr( "Use modifier to copy" ), QPixmap(modecopy_xpm), 0, Key_K, actionGroupModModes, "modModeCopy" );
insilmaril@104
   843
	a->setToggleAction(true);
insilmaril@104
   844
	a->addTo (tb);
insilmaril@104
   845
	actionModModeCopy=a;
insilmaril@104
   846
insilmaril@125
   847
    a= new QAction( tr( "Use modifier to draw xLinks" ), QPixmap(modelink_xpm), 0, Key_L, actionGroupModModes, "modModeLink" );
insilmaril@89
   848
	a->setToggleAction(true);
insilmaril@89
   849
	a->addTo (tb);
insilmaril@89
   850
	actionModModeLink=a;
insilmaril@89
   851
}
insilmaril@89
   852
insilmaril@0
   853
// Flag Actions
insilmaril@0
   854
void Main::setupFlagActions()
insilmaril@0
   855
{
insilmaril@166
   856
	// Create System Flags
insilmaril@166
   857
	systemFlagsDefault = new FlagRowObj ();
insilmaril@166
   858
	systemFlagsDefault->setVisibility (false);
insilmaril@166
   859
	systemFlagsDefault->setName ("systemFlagsDef");
insilmaril@166
   860
insilmaril@166
   861
	FlagObj *fo = new FlagObj ();
insilmaril@166
   862
	fo->load(QPixmap(flag_note_xpm));
insilmaril@166
   863
	fo->setName("note");
insilmaril@166
   864
	fo->setToolTip(tr("Note","Systemflag"));
insilmaril@166
   865
	systemFlagsDefault->addFlag (fo);	// makes deep copy
insilmaril@166
   866
insilmaril@166
   867
	fo->load(QPixmap(flag_url_xpm));
insilmaril@166
   868
	fo->setName("url");
insilmaril@166
   869
	fo->setToolTip(tr("WWW Document (external)","Systemflag"));
insilmaril@166
   870
	systemFlagsDefault->addFlag (fo);
insilmaril@166
   871
	
insilmaril@166
   872
	fo->load(QPixmap(flag_vymlink_xpm));
insilmaril@166
   873
	fo->setName("vymLink");
insilmaril@166
   874
	fo->setToolTip(tr("Link to another vym map","Systemflag"));
insilmaril@166
   875
	systemFlagsDefault->addFlag (fo);	
insilmaril@166
   876
insilmaril@166
   877
	fo->load(QPixmap(flag_scrolled_right_xpm));
insilmaril@166
   878
	fo->setName("scrolledright");
insilmaril@166
   879
	fo->setToolTip(tr("subtree is scrolled","Systemflag"));
insilmaril@166
   880
	systemFlagsDefault->addFlag (fo);
insilmaril@166
   881
	
insilmaril@166
   882
	fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
insilmaril@166
   883
	fo->setName("tmpUnscrolledright");
insilmaril@166
   884
	fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
insilmaril@166
   885
	systemFlagsDefault->addFlag (fo);
insilmaril@166
   886
insilmaril@166
   887
	// Create Standard Flags
insilmaril@166
   888
	standardFlagsDefault = new FlagRowObj ();
insilmaril@166
   889
	standardFlagsDefault->setVisibility (false);
insilmaril@166
   890
	standardFlagsDefault->setName ("standardFlagsDef");
insilmaril@166
   891
insilmaril@166
   892
	fo->load(QPixmap(flag_exclamationmark_xpm));
insilmaril@166
   893
	fo->setName ("exclamationmark");
insilmaril@166
   894
	fo->setGroup("standard-mark");
insilmaril@166
   895
	fo->setToolTip(tr("Take care!","Standardflag"));
insilmaril@166
   896
	standardFlagsDefault->addFlag (fo);	// makes deep copy
insilmaril@166
   897
	
insilmaril@166
   898
	fo->load(QPixmap(flag_questionmark_xpm));
insilmaril@166
   899
	fo->setName("questionmark");
insilmaril@166
   900
	fo->setGroup("standard-mark");
insilmaril@166
   901
	fo->setToolTip(tr("Really?","Standardflag"));
insilmaril@166
   902
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   903
insilmaril@166
   904
	fo->load(QPixmap(flag_hook_green_xpm));
insilmaril@166
   905
	fo->setName("hook-green");
insilmaril@166
   906
	fo->setGroup("standard-hook");
insilmaril@166
   907
	fo->setToolTip(tr("ok!","Standardflag"));
insilmaril@166
   908
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   909
insilmaril@166
   910
	fo->load(QPixmap(flag_cross_red_xpm));
insilmaril@166
   911
	fo->setName("cross-red");
insilmaril@166
   912
	fo->setGroup("standard-hook");
insilmaril@166
   913
	fo->setToolTip(tr("Not ok!","Standardflag"));
insilmaril@166
   914
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   915
insilmaril@166
   916
	fo->load(QPixmap(flag_stopsign_xpm));
insilmaril@166
   917
	fo->setName("stopsign");
insilmaril@166
   918
	fo->setToolTip(tr("This won't work!","Standardflag"));
insilmaril@166
   919
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   920
insilmaril@166
   921
	fo->load(QPixmap(flag_smiley_good_xpm));
insilmaril@166
   922
	fo->setName("smiley-good");
insilmaril@166
   923
	fo->setGroup("standard-smiley");
insilmaril@166
   924
	fo->setToolTip(tr("Good","Standardflag"));
insilmaril@166
   925
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   926
insilmaril@166
   927
	fo->load(QPixmap(flag_smiley_sad_xpm));
insilmaril@166
   928
	fo->setName("smiley-sad");
insilmaril@166
   929
	fo->setGroup("standard-smiley");
insilmaril@166
   930
	fo->setToolTip(tr("Bad","Standardflag"));
insilmaril@166
   931
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   932
insilmaril@166
   933
	fo->load(QPixmap(flag_clock_xpm));
insilmaril@166
   934
	fo->setName("clock");
insilmaril@166
   935
	fo->setToolTip(tr("Time critical","Standardflag"));
insilmaril@166
   936
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   937
insilmaril@166
   938
	fo->load(QPixmap(flag_lamp_xpm));
insilmaril@166
   939
	fo->setName("lamp");
insilmaril@166
   940
	fo->setToolTip(tr("Idea!","Standardflag"));
insilmaril@166
   941
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   942
insilmaril@166
   943
	fo->load(QPixmap(flag_arrow_up_xpm));
insilmaril@166
   944
	fo->setName("arrow-up");
insilmaril@166
   945
	fo->setGroup("standard-arrow");
insilmaril@166
   946
	fo->setToolTip(tr("Important","Standardflag"));
insilmaril@166
   947
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   948
insilmaril@166
   949
	fo->load(QPixmap(flag_arrow_down_xpm));
insilmaril@166
   950
	fo->setName("arrow-down");
insilmaril@166
   951
	fo->setGroup("standard-arrow");
insilmaril@166
   952
	fo->setToolTip(tr("Unimportant","Standardflag"));
insilmaril@166
   953
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   954
insilmaril@166
   955
	fo->load(QPixmap(flag_thumb_up_xpm));
insilmaril@166
   956
	fo->setName("thumb-up");
insilmaril@166
   957
	fo->setGroup("standard-thumb");
insilmaril@166
   958
	fo->setToolTip(tr("I like this","Standardflag"));
insilmaril@166
   959
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   960
insilmaril@166
   961
	fo->load(QPixmap(flag_thumb_down_xpm));
insilmaril@166
   962
	fo->setName("thumb-down");
insilmaril@166
   963
	fo->setGroup("standard-thumb");
insilmaril@166
   964
	fo->setToolTip(tr("I like this","Standardflag"));
insilmaril@166
   965
	fo->setToolTip(tr("I do not like this","Standardflag"));
insilmaril@166
   966
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   967
	
insilmaril@166
   968
	fo->load(QPixmap(flag_heart_xpm));
insilmaril@166
   969
	fo->setName("heart");
insilmaril@166
   970
	fo->setToolTip(tr("I just love... ","Standardflag"));
insilmaril@166
   971
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   972
insilmaril@166
   973
	fo->load(QPixmap(flag_flash_xpm));
insilmaril@166
   974
	fo->setName("flash");
insilmaril@166
   975
	fo->setToolTip(tr("Dangerous","Standardflag"));
insilmaril@166
   976
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   977
	
insilmaril@166
   978
	fo->load(QPixmap(flag_lifebelt_xpm));
insilmaril@166
   979
	fo->setName("lifebelt");
insilmaril@166
   980
	fo->setToolTip(tr("This will help","Standardflag"));
insilmaril@166
   981
	standardFlagsDefault->addFlag (fo);	
insilmaril@166
   982
	delete (fo);
insilmaril@166
   983
insilmaril@0
   984
	standardFlagsDefault->makeToolbar(this, "Standard Flags");
insilmaril@0
   985
}
insilmaril@0
   986
insilmaril@0
   987
// Settings Actions
insilmaril@0
   988
void Main::setupSettingsActions()
insilmaril@0
   989
{
insilmaril@0
   990
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
   991
    menuBar()->insertItem( tr( "&Settings" ), menu );
insilmaril@0
   992
insilmaril@0
   993
	QAction *a;
insilmaril@0
   994
insilmaril@0
   995
insilmaril@159
   996
    a = new QAction( tr( "Set application to open pdf files"), QPixmap(), tr( "Set application to open pdf files  ...") , 0, this, "setPDF" );
insilmaril@0
   997
    connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
insilmaril@0
   998
    a->addTo( menu );
insilmaril@0
   999
insilmaril@159
  1000
    a = new QAction( tr( "Set application to open external links"), QPixmap(), tr( "Set application to open external links..."), 0, this, "setURL" );
insilmaril@0
  1001
    connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
insilmaril@0
  1002
    a->addTo( menu );
insilmaril@0
  1003
insilmaril@0
  1004
    menu->insertSeparator();
insilmaril@0
  1005
    a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
insilmaril@0
  1006
	a->setToggleAction(true);
insilmaril@0
  1007
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
insilmaril@0
  1008
    a->addTo( menu );
insilmaril@0
  1009
	actionSettingsAutoedit=a;
insilmaril@0
  1010
insilmaril@0
  1011
    a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
insilmaril@0
  1012
	a->setToggleAction(true);
insilmaril@0
  1013
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
insilmaril@0
  1014
    a->addTo( menu );
insilmaril@0
  1015
	actionSettingsAutoselectHeading=a;
insilmaril@0
  1016
	
insilmaril@0
  1017
    a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
insilmaril@0
  1018
	a->setToggleAction(true);
insilmaril@0
  1019
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
insilmaril@0
  1020
    a->addTo( menu );
insilmaril@0
  1021
	actionSettingsAutoselectText=a;
insilmaril@0
  1022
	
insilmaril@151
  1023
    a= new QAction( tr( "Pasting into new branch" ), QPixmap(), tr( "pasting into new branch" ), 0, this, "pastenewheading" );
insilmaril@0
  1024
	a->setToggleAction(true);
insilmaril@0
  1025
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
insilmaril@0
  1026
    a->addTo( menu );
insilmaril@0
  1027
	actionSettingsPasteNewHeading=a;
insilmaril@0
  1028
	
insilmaril@151
  1029
    a= new QAction( tr( "Delete key for deleting branches" ), QPixmap(), tr( "Delete key" ), 0, this, "delkey" );
insilmaril@0
  1030
	a->setToggleAction(true);
insilmaril@0
  1031
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
insilmaril@0
  1032
    a->addTo( menu );
insilmaril@0
  1033
	actionSettingsUseDelKey=a;
insilmaril@103
  1034
insilmaril@151
  1035
    a= new QAction( tr( "Use exclusive flags in flag toolbars" ), QPixmap(), tr( "Exclusive flags" ), 0, this, "flaggroups" );
insilmaril@103
  1036
	a->setToggleAction(true);
insilmaril@103
  1037
	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useFlagGroups",true) );
insilmaril@103
  1038
    a->addTo( menu );
insilmaril@103
  1039
	actionSettingsUseFlagGroups=a;
insilmaril@0
  1040
}
insilmaril@0
  1041
insilmaril@0
  1042
// Test Actions
insilmaril@0
  1043
void Main::setupTestActions()
insilmaril@0
  1044
{
insilmaril@0
  1045
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
  1046
    menuBar()->insertItem( tr( "&Test" ), menu );
insilmaril@0
  1047
insilmaril@0
  1048
    QAction *a;
insilmaril@175
  1049
    a = new QAction( tr( "Call test function" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
insilmaril@0
  1050
    connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
insilmaril@0
  1051
    a->addTo( menu );
insilmaril@0
  1052
}
insilmaril@0
  1053
insilmaril@0
  1054
// Help Actions
insilmaril@0
  1055
void Main::setupHelpActions()
insilmaril@0
  1056
{
insilmaril@0
  1057
    QPopupMenu *menu = new QPopupMenu( this );
insilmaril@0
  1058
    menuBar()->insertItem( tr( "&Help" ), menu );
insilmaril@0
  1059
insilmaril@0
  1060
    QAction *a;
insilmaril@0
  1061
    a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
insilmaril@0
  1062
    connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
insilmaril@0
  1063
    a->addTo( menu );
insilmaril@0
  1064
insilmaril@205
  1065
    a = new QAction( tr( "About VYM")+" "__VYM, QPixmap(), tr( "About VYM" ), 0, this, "about" );
insilmaril@0
  1066
    connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
insilmaril@0
  1067
    a->addTo( menu );
insilmaril@0
  1068
insilmaril@0
  1069
    a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
insilmaril@0
  1070
    connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
insilmaril@0
  1071
    a->addTo( menu );
insilmaril@0
  1072
}
insilmaril@0
  1073
insilmaril@0
  1074
// Context Menus
insilmaril@0
  1075
void Main::setupContextMenus()
insilmaril@0
  1076
{
insilmaril@0
  1077
	QAction*a;
insilmaril@0
  1078
insilmaril@0
  1079
	// Context Menu for branch or mapcenter
insilmaril@0
  1080
	branchContextMenu =new QPopupMenu (this);
insilmaril@98
  1081
insilmaril@98
  1082
		// Submenu "Add"
insilmaril@98
  1083
		branchAddContextMenu =new QPopupMenu (this);
insilmaril@98
  1084
		actionEditPaste->addTo ( branchAddContextMenu );
insilmaril@98
  1085
		actionEditAddBranch->addTo ( branchAddContextMenu );
insilmaril@98
  1086
		actionEditAddBranchHere->addTo ( branchAddContextMenu );
insilmaril@98
  1087
		actionEditAddBranchAbove->addTo ( branchAddContextMenu );
insilmaril@98
  1088
		actionEditAddBranchBelow->addTo ( branchAddContextMenu );
insilmaril@98
  1089
		branchAddContextMenu->insertSeparator();	
insilmaril@98
  1090
		actionEditLoadImage->addTo( branchAddContextMenu );
insilmaril@98
  1091
		branchAddContextMenu->insertSeparator();	
insilmaril@98
  1092
		actionEditImportAdd->addTo ( branchAddContextMenu );
insilmaril@98
  1093
		actionEditImportReplace->addTo ( branchAddContextMenu );
insilmaril@98
  1094
insilmaril@98
  1095
		// Submenu "Remove"
insilmaril@98
  1096
		branchRemoveContextMenu =new QPopupMenu (this);
insilmaril@98
  1097
		actionEditCut->addTo ( branchRemoveContextMenu );
insilmaril@98
  1098
		actionEditDelete->addTo ( branchRemoveContextMenu );
insilmaril@98
  1099
		actionEditRemoveBranchHere->addTo( branchRemoveContextMenu );
insilmaril@98
  1100
		actionEditRemoveChilds->addTo( branchRemoveContextMenu );
insilmaril@98
  1101
		
insilmaril@98
  1102
	branchContextMenu->insertItem (tr("Add"),branchAddContextMenu);	
insilmaril@98
  1103
	branchContextMenu->insertItem (tr("Remove"),branchRemoveContextMenu);	
insilmaril@98
  1104
insilmaril@0
  1105
	actionEditSaveBranch->addTo( branchContextMenu );
insilmaril@98
  1106
insilmaril@0
  1107
	branchContextMenu->insertSeparator();	
insilmaril@0
  1108
	actionEditOpenURL->addTo ( branchContextMenu );
insilmaril@0
  1109
	actionEditURL->addTo ( branchContextMenu );
insilmaril@0
  1110
	actionEditHeading2URL->addTo ( branchContextMenu );
insilmaril@0
  1111
    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
insilmaril@175
  1112
	{
insilmaril@0
  1113
		actionEditBugzilla2URL->addTo( branchContextMenu );
insilmaril@175
  1114
		actionEditFATE2URL->addTo( branchContextMenu );
insilmaril@175
  1115
	}	
insilmaril@0
  1116
	branchContextMenu->insertSeparator();	
insilmaril@0
  1117
	actionEditOpenVymLink->addTo ( branchContextMenu );
insilmaril@0
  1118
	actionEditVymLink->addTo ( branchContextMenu );
insilmaril@0
  1119
	actionEditDeleteVymLink->addTo ( branchContextMenu );
insilmaril@98
  1120
	
insilmaril@0
  1121
	branchContextMenu->insertSeparator();	
insilmaril@0
  1122
	actionGroupFormatFrameTypes->addTo( branchContextMenu );
insilmaril@0
  1123
insilmaril@160
  1124
	branchContextMenu->insertSeparator();	
insilmaril@175
  1125
	actionFormatIncludeImagesVer->addTo( branchContextMenu );
insilmaril@200
  1126
	// FIXME not implemented yet actionFormatIncludeImagesHor->addTo( branchContextMenu );
insilmaril@160
  1127
	actionFormatHideLinkUnselected->addTo( branchContextMenu );
insilmaril@160
  1128
insilmaril@89
  1129
	// Context Menu for links in a branch menu
insilmaril@89
  1130
	// This will be populated "on demand" in MapEditor::updateActions
insilmaril@89
  1131
	branchContextMenu->insertSeparator();	
insilmaril@89
  1132
	branchLinksContextMenu =new QPopupMenu (this);
insilmaril@94
  1133
	branchLinksContextMenuDup =new QPopupMenu (this);
insilmaril@95
  1134
	branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup);
insilmaril@95
  1135
	connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) );
insilmaril@89
  1136
insilmaril@105
  1137
	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
insilmaril@105
  1138
	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
insilmaril@105
  1139
	
insilmaril@0
  1140
	// Context menu for floatimage
insilmaril@0
  1141
	floatimageContextMenu =new QPopupMenu (this);
insilmaril@0
  1142
	saveImageFormatMenu=new QPopupMenu (this);
insilmaril@0
  1143
	exportImageFormatMenu=new QPopupMenu (this);
insilmaril@0
  1144
insilmaril@0
  1145
	QStrList fmt = QImage::outputFormats();
insilmaril@0
  1146
	for (const char* f = fmt.first(); f; f = fmt.next()) 
insilmaril@0
  1147
	{
insilmaril@0
  1148
		saveImageFormatMenu->insertItem( f );
insilmaril@0
  1149
		exportImageFormatMenu->insertItem( f );
insilmaril@0
  1150
	}	
insilmaril@0
  1151
	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
insilmaril@0
  1152
	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
insilmaril@0
  1153
	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
insilmaril@0
  1154
	
insilmaril@0
  1155
	floatimageContextMenu->insertSeparator();	
insilmaril@0
  1156
	actionEditCopy->addTo( floatimageContextMenu );
insilmaril@0
  1157
	actionEditCut->addTo( floatimageContextMenu );
insilmaril@0
  1158
insilmaril@0
  1159
	floatimageContextMenu->insertSeparator();	
insilmaril@0
  1160
    a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
insilmaril@0
  1161
	a->setToggleAction(true);
insilmaril@0
  1162
    connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
insilmaril@0
  1163
    a->addTo( floatimageContextMenu);
insilmaril@0
  1164
	actionEditToggleFloatExport=a;
insilmaril@0
  1165
insilmaril@160
  1166
	floatimageContextMenu->insertSeparator();	
insilmaril@160
  1167
	actionFormatHideLinkUnselected->addTo( floatimageContextMenu );
insilmaril@0
  1168
insilmaril@205
  1169
	a = new QAction( tr( "Export in Open Document Format used e.g. in Open Office " ), QPixmap(), "Open Office"+QString("..."), 0, this, "exportOOPresentation" );
insilmaril@185
  1170
	connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) );
insilmaril@185
  1171
	a->addTo (exportMenu);
insilmaril@0
  1172
insilmaril@205
  1173
	exportMenu->insertItem ( tr("Export as Image"),exportImageFormatMenu);
insilmaril@185
  1174
insilmaril@205
  1175
    a = new QAction( tr( "Export as ASCII")+" "+tr("(still experimental)" ), QPixmap(), "ASCII...", 0, this, "exportASCII" );
insilmaril@0
  1176
    connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
insilmaril@143
  1177
	a->addTo( exportMenu );
insilmaril@0
  1178
insilmaril@205
  1179
    a = new QAction( tr( "Export as LaTeX")+" "+tr("(still experimental)" ), QPixmap(), "LaTeX...", 0, this, "exportLaTeX" );
insilmaril@163
  1180
    connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) );
insilmaril@163
  1181
	a->addTo( exportMenu );
insilmaril@163
  1182
insilmaril@205
  1183
	a = new QAction( tr( "Export as XML" ), QPixmap(), "XML...",  0, this, "exportXML" );
insilmaril@0
  1184
    connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
insilmaril@0
  1185
    a->addTo( exportMenu );
insilmaril@0
  1186
	
insilmaril@0
  1187
    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
insilmaril@0
  1188
	{
insilmaril@205
  1189
		a = new QAction( tr( "Export as HTML" ), QPixmap(), "HTML...", 0, this, "exportHTML");
insilmaril@0
  1190
		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
insilmaril@0
  1191
		a->addTo( exportMenu );
insilmaril@0
  1192
	}
insilmaril@0
  1193
insilmaril@205
  1194
	a = new QAction( tr( "Export as XHTML" ), QPixmap(), "XHTML...", ALT + Key_X, this, "exportXHTML" );
insilmaril@0
  1195
    connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
insilmaril@0
  1196
    a->addTo( exportMenu );
insilmaril@0
  1197
insilmaril@0
  1198
	
insilmaril@0
  1199
	// Context menu for canvas
insilmaril@0
  1200
	canvasContextMenu =new QPopupMenu (this);
insilmaril@0
  1201
	actionEditMapInfo->addTo( canvasContextMenu );
insilmaril@0
  1202
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1203
	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
insilmaril@0
  1204
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1205
	actionFormatLinkColorHint->addTo( canvasContextMenu );
insilmaril@0
  1206
	actionFormatLinkColor->addTo( canvasContextMenu );
insilmaril@0
  1207
	actionFormatBackColor->addTo( canvasContextMenu );
insilmaril@0
  1208
insilmaril@0
  1209
	// Menu for last opened files
insilmaril@0
  1210
	// Read settings initially
insilmaril@0
  1211
	QString s;
insilmaril@0
  1212
	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
insilmaril@0
  1213
	for (int i=1;i<=j;i++)
insilmaril@0
  1214
	{
insilmaril@0
  1215
		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
insilmaril@0
  1216
		if (!s.isEmpty() && j<=maxLastMaps) 
insilmaril@0
  1217
			lastMaps.append(s);
insilmaril@0
  1218
	}
insilmaril@0
  1219
	setupLastMapsMenu();
insilmaril@0
  1220
	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
insilmaril@0
  1221
}
insilmaril@0
  1222
insilmaril@0
  1223
void Main::setupLastMapsMenu()
insilmaril@0
  1224
{
insilmaril@0
  1225
	// Remove double entries
insilmaril@0
  1226
	QStringList::Iterator it=lastMaps.begin();
insilmaril@0
  1227
	QStringList::Iterator jt;
insilmaril@0
  1228
	while (it!=lastMaps.end() )
insilmaril@0
  1229
	{
insilmaril@0
  1230
		jt=it;
insilmaril@0
  1231
		++jt;
insilmaril@0
  1232
		while (jt!=lastMaps.end() )
insilmaril@0
  1233
		{
insilmaril@0
  1234
			if (*it == *jt)		
insilmaril@0
  1235
				jt=lastMaps.remove(jt);
insilmaril@0
  1236
			else	
insilmaril@0
  1237
				jt++;
insilmaril@0
  1238
		}
insilmaril@0
  1239
		it++;
insilmaril@0
  1240
	}	
insilmaril@0
  1241
insilmaril@0
  1242
	// Limit length of list to maxLastMaps
insilmaril@0
  1243
	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
insilmaril@0
  1244
	
insilmaril@0
  1245
	// build Menu from lastMaps string list
insilmaril@0
  1246
	lastMapsMenu->clear();
insilmaril@0
  1247
	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
insilmaril@0
  1248
		lastMapsMenu->insertItem (*it );
insilmaril@0
  1249
		
insilmaril@0
  1250
}
insilmaril@0
  1251
insilmaril@0
  1252
void Main::hideEvent (QHideEvent * )
insilmaril@0
  1253
{
insilmaril@0
  1254
	if (!textEditor->isMinimized() ) textEditor->hide();
insilmaril@0
  1255
}
insilmaril@0
  1256
insilmaril@0
  1257
void Main::showEvent (QShowEvent * )
insilmaril@0
  1258
{
insilmaril@117
  1259
	if (textEditor->showWithMain()) textEditor->showNormal();
insilmaril@0
  1260
}
insilmaril@0
  1261
insilmaril@0
  1262
bool Main::reallyWriteDirectory(const QString &dir)
insilmaril@0
  1263
{
insilmaril@0
  1264
	QStringList eList = QDir(dir).entryList();
insilmaril@0
  1265
	if (eList.first() ==".")  eList.pop_front();	// remove "."
insilmaril@0
  1266
	if (eList.first() =="..") eList.pop_front();	// remove "."
insilmaril@0
  1267
	if (!eList.isEmpty())
insilmaril@0
  1268
	{
insilmaril@185
  1269
		QMessageBox mb( __VYM,
insilmaril@159
  1270
			tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir),
insilmaril@0
  1271
		QMessageBox::Warning,
insilmaril@0
  1272
		QMessageBox::Yes ,
insilmaril@0
  1273
		QMessageBox::Cancel | QMessageBox::Default,
insilmaril@0
  1274
		QMessageBox::QMessageBox::NoButton );
insilmaril@0
  1275
insilmaril@0
  1276
		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  1277
		mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  1278
		switch( mb.exec() ) 
insilmaril@0
  1279
		{
insilmaril@0
  1280
			case QMessageBox::Yes:
insilmaril@0
  1281
				// save 
insilmaril@0
  1282
				return true;
insilmaril@0
  1283
			case QMessageBox::Cancel:
insilmaril@0
  1284
				// do nothing
insilmaril@0
  1285
				return false;
insilmaril@0
  1286
		}
insilmaril@0
  1287
	}
insilmaril@0
  1288
	return true;
insilmaril@0
  1289
}
insilmaril@0
  1290
insilmaril@0
  1291
QString Main::browseDirectory (const QString &caption)
insilmaril@0
  1292
{
insilmaril@0
  1293
	QFileDialog fd(this,caption);
insilmaril@0
  1294
	fd.setMode (QFileDialog::DirectoryOnly);
insilmaril@185
  1295
	fd.setCaption(__VYM " - "+caption);
insilmaril@0
  1296
	fd.show();
insilmaril@0
  1297
	
insilmaril@0
  1298
	if ( fd.exec() == QDialog::Accepted )
insilmaril@0
  1299
		return fd.selectedFile();
insilmaril@0
  1300
	else
insilmaril@0
  1301
		return "";
insilmaril@0
  1302
}
insilmaril@0
  1303
insilmaril@0
  1304
MapEditor* Main::currentMapEditor() const
insilmaril@0
  1305
{
insilmaril@0
  1306
    if ( tabWidget->currentPage() &&
insilmaril@0
  1307
	 tabWidget->currentPage()->inherits( "MapEditor" ) )
insilmaril@0
  1308
		return (MapEditor*)tabWidget->currentPage();
insilmaril@0
  1309
    return NULL;	
insilmaril@0
  1310
}
insilmaril@0
  1311
insilmaril@0
  1312
//TODO not used now, maybe use this for overview window later
insilmaril@0
  1313
void Main::newView() 
insilmaril@0
  1314
{
insilmaril@0
  1315
    // Open a new view... have it delete when closed.
insilmaril@0
  1316
    Main *m = new Main(0, 0, WDestructiveClose);
insilmaril@0
  1317
    qApp->setMainWidget(m);
insilmaril@0
  1318
    m->show();
insilmaril@0
  1319
    qApp->setMainWidget(0);
insilmaril@0
  1320
}
insilmaril@0
  1321
insilmaril@0
  1322
void Main::editorChanged(QWidget *)
insilmaril@0
  1323
{
insilmaril@0
  1324
	// Unselect all possibly selected objects
insilmaril@0
  1325
	// (Important to update note editor)
insilmaril@0
  1326
	int i;
insilmaril@0
  1327
	MapEditor *me;
insilmaril@0
  1328
	for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  1329
	{
insilmaril@0
  1330
		
insilmaril@0
  1331
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1332
		me->unselect();
insilmaril@0
  1333
	}	
insilmaril@0
  1334
	currentMapEditor()->reselect();
insilmaril@0
  1335
insilmaril@0
  1336
	// Update actions to in menus and toolbars according to editor
insilmaril@0
  1337
	currentMapEditor()->updateActions();
insilmaril@0
  1338
}
insilmaril@0
  1339
insilmaril@0
  1340
void Main::fileNew()
insilmaril@0
  1341
{
insilmaril@0
  1342
	QString fn="unnamed";
insilmaril@0
  1343
	MapEditor* medit = new MapEditor (tabWidget, true);
insilmaril@0
  1344
	tabWidget->addTab (medit,fn);
insilmaril@0
  1345
	tabWidget->showPage(medit);
insilmaril@0
  1346
	medit->viewport()->setFocus();
insilmaril@166
  1347
		// For the very first map we do not have flagrows yet...
insilmaril@166
  1348
		medit->select("mc:");
insilmaril@0
  1349
}
insilmaril@0
  1350
insilmaril@205
  1351
ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode)
insilmaril@0
  1352
{
insilmaril@205
  1353
	ErrorCode err=success;
insilmaril@0
  1354
	
insilmaril@0
  1355
	// fn is usually the archive, mapfile the file after uncompressing
insilmaril@0
  1356
	QString mapfile;
insilmaril@0
  1357
insilmaril@0
  1358
	// Make fn absolute (needed for unzip)
insilmaril@0
  1359
	fn=QDir (fn).absPath();
insilmaril@0
  1360
insilmaril@0
  1361
	MapEditor *me;
insilmaril@0
  1362
insilmaril@0
  1363
	if (lmode==NewMap)
insilmaril@0
  1364
	{
insilmaril@0
  1365
		// Check, if map is already loaded
insilmaril@0
  1366
		int i=0;
insilmaril@0
  1367
		while (i<=tabWidget->count() -1)
insilmaril@0
  1368
		{
insilmaril@0
  1369
			me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1370
			if (me->getFilePath() == fn)
insilmaril@0
  1371
			{
insilmaril@0
  1372
				// Already there, ask for confirmation
insilmaril@185
  1373
				QMessageBox mb( __VYM,
insilmaril@159
  1374
					tr("The map %1\nis already opened."
insilmaril@0
  1375
					"Opening the same map in multiple editors may lead \n"
insilmaril@0
  1376
					"to confusion when finishing working with vym."
insilmaril@159
  1377
					"Do you want to").arg(fn),
insilmaril@0
  1378
					QMessageBox::Warning,
insilmaril@0
  1379
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1380
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  1381
					QMessageBox::QMessageBox::NoButton);
insilmaril@0
  1382
				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
insilmaril@0
  1383
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1384
				switch( mb.exec() ) 
insilmaril@0
  1385
				{
insilmaril@0
  1386
					case QMessageBox::Yes:
insilmaril@0
  1387
						// load anyway
insilmaril@0
  1388
						i=tabWidget->count();
insilmaril@0
  1389
						break;
insilmaril@0
  1390
					case QMessageBox::Cancel:
insilmaril@0
  1391
						// do nothing
insilmaril@205
  1392
						return aborted;
insilmaril@0
  1393
						break;
insilmaril@0
  1394
				}
insilmaril@0
  1395
			}
insilmaril@0
  1396
			i++;
insilmaril@0
  1397
		}
insilmaril@0
  1398
	}
insilmaril@0
  1399
insilmaril@0
  1400
insilmaril@0
  1401
	// Try to load map
insilmaril@0
  1402
    if ( !fn.isEmpty() )
insilmaril@0
  1403
	{
insilmaril@0
  1404
		me = currentMapEditor();
insilmaril@0
  1405
		int tabIndex=tabWidget->currentPageIndex();
insilmaril@0
  1406
		// Check first, if mapeditor exists
insilmaril@0
  1407
		// If it is not default AND we want a new map, 
insilmaril@0
  1408
		// create a new mapeditor in a new tab
insilmaril@0
  1409
		if ( lmode==NewMap && (!me || !me->isDefault() ) )
insilmaril@0
  1410
		{
insilmaril@0
  1411
			me = new MapEditor (tabWidget,true);
insilmaril@0
  1412
			tabWidget->addTab (me,fn);
insilmaril@0
  1413
			tabIndex=tabWidget->indexOf (me);
insilmaril@0
  1414
			tabWidget->setCurrentPage (tabIndex);
insilmaril@0
  1415
		}
insilmaril@0
  1416
		
insilmaril@0
  1417
		// Check, if file exists (important for creating new files
insilmaril@0
  1418
		// from command line
insilmaril@0
  1419
		if (!QFile(fn).exists() )
insilmaril@0
  1420
		{
insilmaril@185
  1421
			QMessageBox mb( __VYM,
insilmaril@159
  1422
				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
insilmaril@0
  1423
				QMessageBox::Question,
insilmaril@0
  1424
				QMessageBox::Yes ,
insilmaril@0
  1425
				QMessageBox::Cancel | QMessageBox::Default,
insilmaril@0
  1426
				QMessageBox::QMessageBox::NoButton );
insilmaril@0
  1427
insilmaril@0
  1428
			mb.setButtonText( QMessageBox::Yes, tr("Create"));
insilmaril@0
  1429
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  1430
			switch( mb.exec() ) 
insilmaril@0
  1431
			{
insilmaril@0
  1432
				case QMessageBox::Yes:
insilmaril@0
  1433
					// Create new map
insilmaril@0
  1434
					currentMapEditor()->setFilePath(fn);
insilmaril@0
  1435
					tabWidget->setTabLabel (currentMapEditor(),
insilmaril@0
  1436
						currentMapEditor()->getFileName() );
insilmaril@0
  1437
					statusBar()->message( "Created " + fn , statusbarTime );
insilmaril@205
  1438
					return success;
insilmaril@0
  1439
						
insilmaril@0
  1440
				case QMessageBox::Cancel:
insilmaril@0
  1441
					// don't create new map
insilmaril@0
  1442
					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
insilmaril@0
  1443
					fileCloseMap();
insilmaril@205
  1444
					return aborted;
insilmaril@0
  1445
			}
insilmaril@0
  1446
		}	
insilmaril@0
  1447
insilmaril@0
  1448
insilmaril@0
  1449
		//tabWidget->currentPage() won't be NULL here, because of above...
insilmaril@0
  1450
		tabWidget->showPage(me);
insilmaril@0
  1451
		me->viewport()->setFocus();
insilmaril@0
  1452
insilmaril@0
  1453
		// Create temporary directory for packing
insilmaril@0
  1454
		char tmpdir1[]="/tmp/vym-XXXXXX";	
insilmaril@0
  1455
		QString tmpMapDir=mkdtemp(tmpdir1);
insilmaril@0
  1456
insilmaril@0
  1457
		// Try to unzip file
insilmaril@185
  1458
		err=unzipDir (tmpMapDir,fn);
insilmaril@185
  1459
		if (err==nozip)
insilmaril@0
  1460
		{
insilmaril@185
  1461
			mapfile=fn;
insilmaril@185
  1462
			me->setZipped(false);
insilmaril@0
  1463
		} else
insilmaril@0
  1464
		{
insilmaril@185
  1465
			me->setZipped(true);
insilmaril@185
  1466
			
insilmaril@185
  1467
			// Look for mapname.xml
insilmaril@185
  1468
			mapfile= fn.left(fn.findRev(".",-1,true));
insilmaril@185
  1469
			mapfile=mapfile.section( '/', -1 );
insilmaril@185
  1470
			QFile file( tmpMapDir + "/" + mapfile + ".xml");
insilmaril@185
  1471
			if (!file.exists() )
insilmaril@0
  1472
			{
insilmaril@185
  1473
				// mapname.xml does not exist, well, 
insilmaril@185
  1474
				// maybe some renamed the mapname.vym file...
insilmaril@185
  1475
				// Try to find any .xml in the toplevel 
insilmaril@185
  1476
				// directory of the .vym file
insilmaril@185
  1477
				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
insilmaril@185
  1478
				if (flist.count()==1) 
insilmaril@0
  1479
				{
insilmaril@185
  1480
					// Only one entry, take this one
insilmaril@185
  1481
					mapfile=tmpMapDir + "/"+flist.first();
insilmaril@0
  1482
				} else
insilmaril@185
  1483
				{
insilmaril@185
  1484
					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
insilmaril@185
  1485
						*it=tmpMapDir + "/" + *it;
insilmaril@185
  1486
					// TODO Multiple entries, load all (but only the first one into this ME)
insilmaril@185
  1487
					//mainWindow->fileLoadFromTmp (flist);
insilmaril@185
  1488
					//returnCode=1;	// Silently forget this attempt to load
insilmaril@185
  1489
					qWarning ("MainWindow::load (fn)  multimap found...");
insilmaril@185
  1490
				}	
insilmaril@0
  1491
					
insilmaril@185
  1492
				if (flist.isEmpty() )
insilmaril@185
  1493
				{
insilmaril@185
  1494
					QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@185
  1495
							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
insilmaril@185
  1496
					err=aborted;				   
insilmaril@185
  1497
				}	
insilmaril@185
  1498
			} //file doesn't exist	
insilmaril@185
  1499
			else
insilmaril@185
  1500
				mapfile=file.name();
insilmaril@0
  1501
		}
insilmaril@0
  1502
insilmaril@185
  1503
		if (err!=aborted)
insilmaril@185
  1504
		{
insilmaril@185
  1505
			// Save existing filename in case  we import
insilmaril@185
  1506
			QString fn_org=me->getFilePath();
insilmaril@106
  1507
insilmaril@185
  1508
			// Finally load map into mapEditor
insilmaril@185
  1509
			me->setFilePath (mapfile,fn);
insilmaril@205
  1510
			err=me->load(mapfile,lmode);
insilmaril@106
  1511
insilmaril@185
  1512
			// Restore old (maybe empty) filepath, if this is an import
insilmaril@185
  1513
			if (lmode!=NewMap)
insilmaril@185
  1514
				me->setFilePath (fn_org);
insilmaril@185
  1515
		}	
insilmaril@0
  1516
insilmaril@185
  1517
		// Finally check for errors and go home
insilmaril@185
  1518
		if (err==aborted) 
insilmaril@185
  1519
		{
insilmaril@185
  1520
			if (lmode==NewMap) fileCloseMap();
insilmaril@185
  1521
			statusBar()->message( "Could not load " + fn, statusbarTime );
insilmaril@185
  1522
		} else 
insilmaril@0
  1523
		{
insilmaril@0
  1524
			if (lmode==NewMap)
insilmaril@0
  1525
			{
insilmaril@0
  1526
				me->setFilePath (fn);
insilmaril@0
  1527
				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
insilmaril@205
  1528
				if (fn.left(9)!="/tmp/vym-")
insilmaril@205
  1529
				{
insilmaril@205
  1530
					// Only append to lastMaps if not loaded from a tmpDir
insilmaril@205
  1531
					// e.g. imported bookmarks are in a tmpDir
insilmaril@205
  1532
					lastMaps.prepend(me->getFilePath() );
insilmaril@205
  1533
					setupLastMapsMenu();
insilmaril@205
  1534
				}
insilmaril@0
  1535
				actionFilePrint->setEnabled (true);
insilmaril@0
  1536
			}	
insilmaril@0
  1537
			statusBar()->message( "Loaded " + fn, statusbarTime );
insilmaril@0
  1538
		}	
insilmaril@0
  1539
insilmaril@185
  1540
		// Delete tmpDir
insilmaril@185
  1541
		removeDir (QDir(tmpMapDir));
insilmaril@0
  1542
	}
insilmaril@205
  1543
	return err;
insilmaril@0
  1544
}
insilmaril@0
  1545
insilmaril@0
  1546
insilmaril@0
  1547
void Main::fileLoad(const LoadMode &lmode)
insilmaril@0
  1548
{
insilmaril@0
  1549
	QFileDialog *fd=new QFileDialog( this);
insilmaril@0
  1550
	if (!lastFileDir.isEmpty()) 
insilmaril@0
  1551
		fd->setDir (lastFileDir);
insilmaril@185
  1552
	fd->setMode (QFileDialog::ExistingFiles);
insilmaril@0
  1553
	fd->addFilter ("XML (*.xml)");
insilmaril@0
  1554
	fd->addFilter ("VYM map (*.vym *.vyp)");
insilmaril@0
  1555
	switch (lmode)
insilmaril@0
  1556
	{
insilmaril@0
  1557
		case NewMap:
insilmaril@0
  1558
			fd->setCaption(tr("Load vym map"));
insilmaril@0
  1559
			break;
insilmaril@0
  1560
		case ImportAdd:
insilmaril@0
  1561
			fd->setCaption(tr("Import: Add vym map to selection"));
insilmaril@0
  1562
			break;
insilmaril@0
  1563
		case ImportReplace:
insilmaril@0
  1564
			fd->setCaption(tr("Import: Replace selection with vym map"));
insilmaril@0
  1565
			break;
insilmaril@0
  1566
	}
insilmaril@0
  1567
	fd->show();
insilmaril@0
  1568
insilmaril@0
  1569
	QString fn;
insilmaril@0
  1570
	if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  1571
	{
insilmaril@0
  1572
		lastFileDir=fd->dirPath();
insilmaril@185
  1573
	    QStringList flist = fd->selectedFiles();
insilmaril@185
  1574
		QStringList::Iterator it = flist.begin();
insilmaril@185
  1575
		while( it != flist.end() ) 
insilmaril@185
  1576
		{
insilmaril@185
  1577
			fn = *it;
insilmaril@185
  1578
			fileLoad(*it, lmode);				   
insilmaril@185
  1579
			++it;
insilmaril@185
  1580
		}
insilmaril@0
  1581
	}
insilmaril@185
  1582
	delete (fd);
insilmaril@0
  1583
}
insilmaril@0
  1584
insilmaril@0
  1585
void Main::fileLoad()
insilmaril@0
  1586
{
insilmaril@0
  1587
	fileLoad (NewMap);
insilmaril@0
  1588
}
insilmaril@0
  1589
insilmaril@0
  1590
void Main::fileLoadLast(int i)
insilmaril@0
  1591
{
insilmaril@0
  1592
	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
insilmaril@0
  1593
}
insilmaril@0
  1594
insilmaril@0
  1595
void Main::fileSave(const SaveMode &savemode)
insilmaril@0
  1596
{
insilmaril@0
  1597
	// tmp dir for zipping 
insilmaril@0
  1598
	QString tmpMapDir;
insilmaril@0
  1599
	
insilmaril@0
  1600
	// Error codes
insilmaril@205
  1601
	ErrorCode err=success;
insilmaril@0
  1602
	
insilmaril@0
  1603
	QString safeFilePath;
insilmaril@0
  1604
insilmaril@0
  1605
	bool saveZipped=currentMapEditor()->saveZipped();
insilmaril@0
  1606
insilmaril@151
  1607
	MapEditor *	me=currentMapEditor();
insilmaril@151
  1608
	if (me)
insilmaril@0
  1609
	{
insilmaril@151
  1610
		QString fn=me->getFilePath();
insilmaril@0
  1611
		// filename=unnamed, filepath="" in constructor...
insilmaril@0
  1612
		if ( !fn.isEmpty() ) 
insilmaril@0
  1613
		{	
insilmaril@0
  1614
			// We have a filepath, go on saving			
insilmaril@0
  1615
			// First remove existing file, we 
insilmaril@0
  1616
			// don't want to add to old zip archives
insilmaril@0
  1617
			QFile f(fn);
insilmaril@0
  1618
			if (f.exists() ) 
insilmaril@0
  1619
				if (!f.remove())
insilmaril@0
  1620
					QMessageBox::warning( 0, tr( "Save Error" ),
insilmaril@0
  1621
						fn+   tr("\ncould not be removed before saving"));
insilmaril@0
  1622
insilmaril@0
  1623
			// Look, if we should zip the data:
insilmaril@0
  1624
			if (!saveZipped)
insilmaril@0
  1625
			{
insilmaril@185
  1626
				QMessageBox mb( __VYM,
insilmaril@159
  1627
					tr("The map %1\ndid not use the compressed "
insilmaril@0
  1628
					"vym file format.\nWriting it uncompressed will also write images \n"
insilmaril@0
  1629
					"and flags and thus may overwrite files in the "
insilmaril@159
  1630
					"given directory\n\nDo you want to write the map").arg(fn),
insilmaril@0
  1631
					QMessageBox::Warning,
insilmaril@0
  1632
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1633
					QMessageBox::No ,
insilmaril@0
  1634
					QMessageBox::Cancel | QMessageBox::Escape);
insilmaril@0
  1635
				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
insilmaril@0
  1636
				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
insilmaril@0
  1637
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1638
				switch( mb.exec() ) 
insilmaril@0
  1639
				{
insilmaril@0
  1640
					case QMessageBox::Yes:
insilmaril@0
  1641
						// save compressed (default file format)
insilmaril@0
  1642
						saveZipped=true;
insilmaril@0
  1643
						break;
insilmaril@0
  1644
					case QMessageBox::No:
insilmaril@0
  1645
						// save uncompressed
insilmaril@0
  1646
						saveZipped=false;
insilmaril@0
  1647
						break;
insilmaril@0
  1648
					case QMessageBox::Cancel:
insilmaril@0
  1649
						// do nothing
insilmaril@0
  1650
						return;
insilmaril@0
  1651
						break;
insilmaril@0
  1652
				}
insilmaril@0
  1653
			}
insilmaril@0
  1654
insilmaril@0
  1655
			if (saveZipped)
insilmaril@0
  1656
			{
insilmaril@0
  1657
				char tmpdir1[]="/tmp/vym-XXXXXX";	
insilmaril@0
  1658
				tmpMapDir=mkdtemp(tmpdir1);
insilmaril@0
  1659
			
insilmaril@151
  1660
				safeFilePath=me->getFilePath();
insilmaril@151
  1661
				me->setFilePath (tmpMapDir+"/"+
insilmaril@151
  1662
					me->getMapName()+ ".xml",
insilmaril@0
  1663
					safeFilePath);
insilmaril@151
  1664
				me->save (savemode);
insilmaril@151
  1665
				me->setFilePath (safeFilePath);
insilmaril@0
  1666
				
insilmaril@175
  1667
				zipDir (tmpMapDir,fn);
insilmaril@0
  1668
			} // save zipped
insilmaril@0
  1669
			else
insilmaril@0
  1670
			{
insilmaril@0
  1671
				// Save unzipped. 
insilmaril@151
  1672
				safeFilePath=me->getFilePath();
insilmaril@151
  1673
				me->setFilePath (fn, safeFilePath);
insilmaril@151
  1674
				me->save (savemode);
insilmaril@151
  1675
				me->setFilePath (safeFilePath);
insilmaril@0
  1676
			} // save zipped 	
insilmaril@0
  1677
		} // filepath available
insilmaril@0
  1678
		else
insilmaril@0
  1679
		{
insilmaril@0
  1680
			// We have  no filepath yet,
insilmaril@0
  1681
			// call fileSaveAs() now, this will call fileSave() 
insilmaril@0
  1682
			// again.
insilmaril@0
  1683
			fileSaveAs(savemode);
insilmaril@0
  1684
		}
insilmaril@0
  1685
    }
insilmaril@0
  1686
insilmaril@151
  1687
	if (me->saveZipped())
insilmaril@0
  1688
	{
insilmaril@0
  1689
		// Delete tmpDir
insilmaril@175
  1690
		removeDir (QDir(tmpMapDir));
insilmaril@0
  1691
	} 
insilmaril@0
  1692
insilmaril@0
  1693
	if (err==success)
insilmaril@151
  1694
	{
insilmaril@0
  1695
		statusBar()->message( 
insilmaril@159
  1696
			tr("Saved  %1").arg(me->getFilePath()), 
insilmaril@0
  1697
			statusbarTime );
insilmaril@151
  1698
		lastMaps.prepend(me->getFilePath() );
insilmaril@151
  1699
		setupLastMapsMenu();
insilmaril@151
  1700
	} else		
insilmaril@0
  1701
		statusBar()->message( 
insilmaril@159
  1702
			tr("Couldn't save ").arg(me->getFilePath()), 
insilmaril@0
  1703
			statusbarTime );
insilmaril@0
  1704
}
insilmaril@0
  1705
insilmaril@0
  1706
void Main::fileSave()
insilmaril@0
  1707
{
insilmaril@0
  1708
	fileSave (CompleteMap);
insilmaril@0
  1709
}
insilmaril@0
  1710
insilmaril@0
  1711
void Main::fileSaveAs(const SaveMode& savemode)
insilmaril@0
  1712
{
insilmaril@0
  1713
	QString tmpMapDir;
insilmaril@0
  1714
	QString fn;
insilmaril@0
  1715
insilmaril@0
  1716
	if (currentMapEditor())
insilmaril@0
  1717
	{
insilmaril@0
  1718
		if (savemode==CompleteMap)
insilmaril@0
  1719
			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
insilmaril@0
  1720
		else		
insilmaril@0
  1721
			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
insilmaril@0
  1722
		if ( !fn.isEmpty() ) 
insilmaril@0
  1723
		{
insilmaril@0
  1724
			// Check for existing file
insilmaril@0
  1725
			if (QFile (fn).exists())
insilmaril@0
  1726
			{
insilmaril@185
  1727
				QMessageBox mb( __VYM,
insilmaril@159
  1728
					tr("The file %1\nexists already. Do you want to").arg(fn),
insilmaril@0
  1729
					QMessageBox::Warning,
insilmaril@0
  1730
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1731
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@0
  1732
					QMessageBox::QMessageBox::NoButton);
insilmaril@0
  1733
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  1734
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1735
				switch( mb.exec() ) 
insilmaril@0
  1736
				{
insilmaril@0
  1737
					case QMessageBox::Yes:
insilmaril@0
  1738
						// save 
insilmaril@0
  1739
						break;
insilmaril@0
  1740
					case QMessageBox::Cancel:
insilmaril@0
  1741
						// do nothing
insilmaril@0
  1742
						return;
insilmaril@0
  1743
						break;
insilmaril@0
  1744
				}
insilmaril@0
  1745
			} else
insilmaril@0
  1746
			{
insilmaril@0
  1747
				// New file, add extension to filename, if missing
insilmaril@0
  1748
				// This is always .vym or .vyp, depending on savemode
insilmaril@0
  1749
				if (savemode==CompleteMap)
insilmaril@0
  1750
				{
insilmaril@0
  1751
					if (!fn.contains (".vym") && !fn.contains (".xml"))
insilmaril@0
  1752
						fn +=".vym";
insilmaril@0
  1753
				} else		
insilmaril@0
  1754
				{
insilmaril@0
  1755
					if (!fn.contains (".vyp") && !fn.contains (".xml"))
insilmaril@0
  1756
						fn +=".vyp";
insilmaril@0
  1757
				}
insilmaril@0
  1758
			}
insilmaril@0
  1759
	
insilmaril@0
  1760
insilmaril@0
  1761
insilmaril@0
  1762
insilmaril@0
  1763
			// Save now
insilmaril@0
  1764
			currentMapEditor()->setFilePath(fn);
insilmaril@0
  1765
			fileSave(savemode);
insilmaril@0
  1766
insilmaril@0
  1767
			// Set name of tab
insilmaril@94
  1768
			if (savemode==CompleteMap)
insilmaril@94
  1769
				tabWidget->setTabLabel (currentMapEditor(),
insilmaril@94
  1770
					currentMapEditor()->getFileName() );
insilmaril@0
  1771
			return;
insilmaril@0
  1772
		} 
insilmaril@0
  1773
	}
insilmaril@0
  1774
}
insilmaril@0
  1775
insilmaril@0
  1776
void Main::fileSaveAs()
insilmaril@0
  1777
{
insilmaril@0
  1778
	fileSaveAs (CompleteMap);
insilmaril@0
  1779
}
insilmaril@0
  1780
insilmaril@0
  1781
void Main::fileImportDir()
insilmaril@0
  1782
{
insilmaril@0
  1783
	if (currentMapEditor())
insilmaril@0
  1784
		currentMapEditor()->importDir();	
insilmaril@0
  1785
}
insilmaril@0
  1786
insilmaril@205
  1787
void Main::fileImportKDEBookmarks()
insilmaril@205
  1788
{
insilmaril@205
  1789
	ImportKDEBookmarks im;
insilmaril@205
  1790
	im.transform();
insilmaril@205
  1791
	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
insilmaril@205
  1792
		currentMapEditor()->setFilePath ("");
insilmaril@205
  1793
}
insilmaril@205
  1794
insilmaril@0
  1795
void Main::fileExportXML()
insilmaril@0
  1796
{
insilmaril@0
  1797
	if (currentMapEditor())
insilmaril@0
  1798
	{
insilmaril@0
  1799
		QString dir=browseDirectory(tr("Export XML to directory"));
insilmaril@0
  1800
		if (dir !="" && reallyWriteDirectory(dir) )
insilmaril@0
  1801
			currentMapEditor()->exportXML(dir);
insilmaril@0
  1802
	}	
insilmaril@0
  1803
}
insilmaril@0
  1804
insilmaril@0
  1805
void Main::fileExportHTML()
insilmaril@0
  1806
{
insilmaril@0
  1807
	if (currentMapEditor())
insilmaril@0
  1808
	{
insilmaril@0
  1809
		ExportHTMLDialog dia(this);
insilmaril@0
  1810
		
insilmaril@0
  1811
		if (dia.exec()==QDialog::Accepted)
insilmaril@0
  1812
		{
insilmaril@0
  1813
			QString dir=dia.getDir();
insilmaril@0
  1814
			if (reallyWriteDirectory(dir) )
insilmaril@0
  1815
			{
insilmaril@0
  1816
				currentMapEditor()->exportXML (dia.getDir() );
insilmaril@0
  1817
				dia.doExport(currentMapEditor()->getMapName() );
insilmaril@0
  1818
			}	
insilmaril@0
  1819
		}
insilmaril@0
  1820
	}	
insilmaril@0
  1821
}
insilmaril@0
  1822
insilmaril@0
  1823
void Main::fileExportXHTML()
insilmaril@0
  1824
{
insilmaril@0
  1825
	QString dir;
insilmaril@0
  1826
	if (currentMapEditor())
insilmaril@0
  1827
	{
insilmaril@0
  1828
		ExportXHTMLDialog dia(this);
insilmaril@0
  1829
		dia.setFilePath (currentMapEditor()->getFilePath() );
insilmaril@0
  1830
		dia.setMapName (currentMapEditor()->getMapName() );
insilmaril@0
  1831
		dia.readSettings();
insilmaril@0
  1832
		
insilmaril@0
  1833
		if (dia.exec()==QDialog::Accepted)
insilmaril@0
  1834
		{
insilmaril@0
  1835
			QString dir=dia.getDir();
insilmaril@0
  1836
			// Check, if warnings should be used before overwriting
insilmaril@0
  1837
			// the output directory
insilmaril@0
  1838
			bool ok;
insilmaril@0
  1839
			if (dia.warnings()) 
insilmaril@0
  1840
				ok=reallyWriteDirectory(dir);
insilmaril@0
  1841
			else
insilmaril@0
  1842
				ok=true;
insilmaril@0
  1843
insilmaril@0
  1844
			if (ok)
insilmaril@0
  1845
			{
insilmaril@0
  1846
				currentMapEditor()->exportXML (dia.getDir() );
insilmaril@0
  1847
				dia.doExport(currentMapEditor()->getMapName() );
insilmaril@0
  1848
				if (dia.hasChanged())
insilmaril@0
  1849
					currentMapEditor()->setChanged();
insilmaril@0
  1850
			}	
insilmaril@0
  1851
		}
insilmaril@0
  1852
	}	
insilmaril@0
  1853
}
insilmaril@0
  1854
insilmaril@0
  1855
void Main::fileExportImage(int item)
insilmaril@0
  1856
{
insilmaril@0
  1857
	if (currentMapEditor())
insilmaril@0
  1858
	{
insilmaril@0
  1859
		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
insilmaril@0
  1860
							   this );
insilmaril@0
  1861
		if ( !fn.isEmpty() ) 
insilmaril@0
  1862
			currentMapEditor()->exportImage(fn,item);
insilmaril@194
  1863
		else 
insilmaril@159
  1864
			statusBar()->message( tr("Couldn't save %1").arg(fn), statusbarTime );
insilmaril@194
  1865
		
insilmaril@0
  1866
	}
insilmaril@0
  1867
}
insilmaril@0
  1868
insilmaril@0
  1869
void Main::fileExportASCII()
insilmaril@0
  1870
{
insilmaril@0
  1871
	if (currentMapEditor())
insilmaril@0
  1872
		currentMapEditor()->exportASCII();	
insilmaril@0
  1873
}
insilmaril@0
  1874
insilmaril@163
  1875
void Main::fileExportLaTeX()
insilmaril@163
  1876
{
insilmaril@163
  1877
	if (currentMapEditor())
insilmaril@163
  1878
		currentMapEditor()->exportLaTeX();	
insilmaril@163
  1879
}
insilmaril@163
  1880
insilmaril@163
  1881
void Main::fileExportOOPresentation()
insilmaril@163
  1882
{
insilmaril@185
  1883
	ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to Open Office"));
insilmaril@185
  1884
	// FIXME add extra info in dialog
insilmaril@185
  1885
	//ImagePreview *p =new ImagePreview (fd);
insilmaril@185
  1886
	//fd->setContentsPreviewEnabled( TRUE );
insilmaril@185
  1887
	//fd->setContentsPreview( p, p );
insilmaril@185
  1888
	//fd->setPreviewMode( QFileDialog::Contents );
insilmaril@185
  1889
	fd->setCaption(__VYM " - " +tr("Export to Open Office"));
insilmaril@185
  1890
	//fd->setDir (lastImageDir);
insilmaril@185
  1891
	fd->show();
insilmaril@185
  1892
insilmaril@185
  1893
	if ( fd->exec() == QDialog::Accepted )
insilmaril@185
  1894
	{
insilmaril@185
  1895
		QString fn=fd->selectedFile();
insilmaril@185
  1896
		//lastImageDir=fn.left(fn.findRev ("/"));
insilmaril@185
  1897
		if (currentMapEditor())
insilmaril@185
  1898
			currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
insilmaril@185
  1899
	}
insilmaril@163
  1900
}
insilmaril@163
  1901
insilmaril@0
  1902
void Main::fileCloseMap()
insilmaril@0
  1903
{
insilmaril@0
  1904
	if (currentMapEditor())
insilmaril@0
  1905
	{
insilmaril@0
  1906
		if (currentMapEditor()->hasChanged())
insilmaril@0
  1907
		{
insilmaril@185
  1908
			QMessageBox mb( __VYM,
insilmaril@159
  1909
				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
insilmaril@0
  1910
				QMessageBox::Warning,
insilmaril@0
  1911
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1912
				QMessageBox::No,
insilmaril@0
  1913
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  1914
			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
insilmaril@0
  1915
			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
insilmaril@0
  1916
			switch( mb.exec() ) 
insilmaril@0
  1917
			{
insilmaril@0
  1918
				case QMessageBox::Yes:
insilmaril@0
  1919
					// save and close
insilmaril@0
  1920
					fileSave(CompleteMap);
insilmaril@0
  1921
					break;
insilmaril@0
  1922
				case QMessageBox::No:
insilmaril@0
  1923
				// close  without saving
insilmaril@0
  1924
					break;
insilmaril@0
  1925
				case QMessageBox::Cancel:
insilmaril@0
  1926
					// do nothing
insilmaril@0
  1927
				return;
insilmaril@0
  1928
			}
insilmaril@0
  1929
		} 
insilmaril@0
  1930
		currentMapEditor()->closeMap();
insilmaril@0
  1931
		tabWidget->removePage(currentMapEditor());
insilmaril@0
  1932
		if (tabWidget->count()==0)
insilmaril@0
  1933
			actionFilePrint->setEnabled (false);
insilmaril@0
  1934
	}	
insilmaril@0
  1935
}
insilmaril@0
  1936
insilmaril@0
  1937
void Main::filePrint()
insilmaril@0
  1938
{
insilmaril@0
  1939
	if (currentMapEditor())
insilmaril@0
  1940
		currentMapEditor()->print();
insilmaril@0
  1941
}
insilmaril@0
  1942
insilmaril@0
  1943
void Main::fileExitVYM()
insilmaril@0
  1944
{
insilmaril@0
  1945
	// Check if one or more editors have changed
insilmaril@0
  1946
	MapEditor *me;
insilmaril@0
  1947
	int i;
insilmaril@0
  1948
	for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  1949
	{
insilmaril@0
  1950
		
insilmaril@0
  1951
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1952
insilmaril@0
  1953
		// If something changed, ask what to do
insilmaril@0
  1954
		if (me->isUnsaved())
insilmaril@0
  1955
		{
insilmaril@0
  1956
			tabWidget->setCurrentPage(i);
insilmaril@185
  1957
			QMessageBox mb( __VYM,
insilmaril@0
  1958
				tr("This map is not saved yet. Do you want to"),
insilmaril@0
  1959
				QMessageBox::Warning,
insilmaril@0
  1960
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1961
				QMessageBox::No,
insilmaril@0
  1962
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  1963
			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
insilmaril@0
  1964
			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
insilmaril@0
  1965
			mb.show();
insilmaril@0
  1966
			// Call undocumented function: setActiveWindow is only
insilmaril@0
  1967
			// possible, if widget is visible. This depends on
insilmaril@0
  1968
			// windowmanager...
insilmaril@0
  1969
#if defined(Q_OS_LINUX)
insilmaril@0
  1970
			qt_wait_for_window_manager( this);
insilmaril@0
  1971
#endif			
insilmaril@0
  1972
			mb.setActiveWindow();
insilmaril@0
  1973
			switch( mb.exec() ) {
insilmaril@0
  1974
				case QMessageBox::Yes:
insilmaril@0
  1975
					// save (the changed editors) and exit
insilmaril@0
  1976
					fileSave(CompleteMap);
insilmaril@0
  1977
					break;
insilmaril@0
  1978
				case QMessageBox::No:
insilmaril@0
  1979
					// exit without saving
insilmaril@0
  1980
					break;
insilmaril@0
  1981
				case QMessageBox::Cancel:
insilmaril@0
  1982
					// don't save and don't exit
insilmaril@0
  1983
				return;
insilmaril@0
  1984
			}
insilmaril@0
  1985
		}
insilmaril@0
  1986
	} // loop over all MEs	
insilmaril@0
  1987
    qApp->quit();
insilmaril@0
  1988
}
insilmaril@0
  1989
insilmaril@0
  1990
void Main::editUndo()
insilmaril@0
  1991
{
insilmaril@0
  1992
	if (currentMapEditor())
insilmaril@0
  1993
		currentMapEditor()->undo();
insilmaril@0
  1994
}
insilmaril@0
  1995
insilmaril@163
  1996
void Main::editRedo()	   
insilmaril@0
  1997
{
insilmaril@163
  1998
	if (currentMapEditor())
insilmaril@163
  1999
		currentMapEditor()->redo();
insilmaril@0
  2000
}
insilmaril@0
  2001
insilmaril@0
  2002
void Main::editCopy()
insilmaril@0
  2003
{
insilmaril@0
  2004
	if (currentMapEditor())
insilmaril@0
  2005
		currentMapEditor()->copy();
insilmaril@0
  2006
}
insilmaril@0
  2007
insilmaril@0
  2008
void Main::editPaste()
insilmaril@0
  2009
{
insilmaril@0
  2010
	if (currentMapEditor())
insilmaril@0
  2011
		currentMapEditor()->paste();
insilmaril@0
  2012
}
insilmaril@0
  2013
insilmaril@0
  2014
void Main::editCut()
insilmaril@0
  2015
{
insilmaril@0
  2016
	if (currentMapEditor())
insilmaril@0
  2017
		currentMapEditor()->cut();
insilmaril@0
  2018
}
insilmaril@0
  2019
insilmaril@0
  2020
void Main::editOpenFindWindow()
insilmaril@0
  2021
{
insilmaril@0
  2022
	findWindow->popup();
insilmaril@0
  2023
	findWindow->raise();
insilmaril@0
  2024
insilmaril@0
  2025
	// Call undocumented function: setActiveWindow is only
insilmaril@0
  2026
	// possible, if widget is visible. This depends on
insilmaril@0
  2027
	// windowmanager...
insilmaril@0
  2028
#if defined(Q_OS_LINUX)
insilmaril@0
  2029
	qt_wait_for_window_manager( this);
insilmaril@0
  2030
#endif	
insilmaril@0
  2031
	findWindow->setActiveWindow();
insilmaril@0
  2032
}
insilmaril@0
  2033
insilmaril@0
  2034
void Main::editFind(QString s)
insilmaril@0
  2035
{
insilmaril@0
  2036
	bool cs=false;
insilmaril@0
  2037
	BranchObj *bo=currentMapEditor()->findText(s, cs);
insilmaril@0
  2038
	if (bo)
insilmaril@0
  2039
	{	
insilmaril@0
  2040
		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
insilmaril@0
  2041
	} else
insilmaril@0
  2042
	{
insilmaril@0
  2043
		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
insilmaril@159
  2044
							   tr("No matches found for <b>%1</b>").arg(s));
insilmaril@0
  2045
	}	
insilmaril@0
  2046
}
insilmaril@0
  2047
insilmaril@0
  2048
void Main::editFindChanged()
insilmaril@0
  2049
{	// Notify editor, to abort the current find process
insilmaril@0
  2050
	currentMapEditor()->findReset();
insilmaril@0
  2051
}
insilmaril@0
  2052
insilmaril@0
  2053
void Main::editOpenURL()
insilmaril@0
  2054
{
insilmaril@0
  2055
	if (currentMapEditor())
insilmaril@0
  2056
	    currentMapEditor()->openURL();
insilmaril@0
  2057
}
insilmaril@0
  2058
insilmaril@0
  2059
void Main::editURL()
insilmaril@0
  2060
{
insilmaril@0
  2061
	if (currentMapEditor())
insilmaril@0
  2062
	    currentMapEditor()->editURL();
insilmaril@0
  2063
}
insilmaril@0
  2064
insilmaril@0
  2065
void Main::editHeading2URL()
insilmaril@0
  2066
{
insilmaril@0
  2067
	if (currentMapEditor())
insilmaril@0
  2068
	    currentMapEditor()->editHeading2URL();
insilmaril@0
  2069
}
insilmaril@0
  2070
insilmaril@0
  2071
void Main::editBugzilla2URL()
insilmaril@0
  2072
{
insilmaril@0
  2073
	if (currentMapEditor())
insilmaril@0
  2074
	    currentMapEditor()->editBugzilla2URL();
insilmaril@0
  2075
}
insilmaril@0
  2076
insilmaril@175
  2077
void Main::editFATE2URL()
insilmaril@175
  2078
{
insilmaril@175
  2079
	if (currentMapEditor())
insilmaril@175
  2080
	    currentMapEditor()->editFATE2URL();
insilmaril@175
  2081
}
insilmaril@175
  2082
insilmaril@0
  2083
void Main::editOpenVymLink()
insilmaril@0
  2084
{
insilmaril@0
  2085
	// Get current path to map
insilmaril@0
  2086
	QString currentVymLink;
insilmaril@0
  2087
	if (currentMapEditor())
insilmaril@0
  2088
	{
insilmaril@0
  2089
		currentVymLink=currentMapEditor()->getVymLink();	
insilmaril@0
  2090
		// compare path with already loaded maps
insilmaril@0
  2091
		int index=-1;
insilmaril@0
  2092
		int i;
insilmaril@0
  2093
		MapEditor *me;
insilmaril@0
  2094
		for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  2095
		{
insilmaril@0
  2096
			me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  2097
			if (currentVymLink==me->getFilePath() )
insilmaril@0
  2098
			{
insilmaril@0
  2099
				index=i;
insilmaril@0
  2100
				break;
insilmaril@0
  2101
			}
insilmaril@0
  2102
		}	
insilmaril@0
  2103
		if (index<0)
insilmaril@0
  2104
		// Load map
insilmaril@0
  2105
		{
insilmaril@0
  2106
			if (!QFile(currentVymLink).exists() )
insilmaril@0
  2107
				QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@159
  2108
				   tr("Couldn't open map %1").arg(currentVymLink));
insilmaril@0
  2109
			else
insilmaril@0
  2110
			{
insilmaril@0
  2111
				fileLoad (currentVymLink, NewMap);
insilmaril@0
  2112
				tabWidget->setCurrentPage (tabWidget->count()-1);	
insilmaril@0
  2113
			}
insilmaril@0
  2114
		} else
insilmaril@0
  2115
			// Go to tab containing the map
insilmaril@0
  2116
			tabWidget->setCurrentPage (index);	
insilmaril@0
  2117
	}
insilmaril@0
  2118
}
insilmaril@0
  2119
insilmaril@0
  2120
void Main::editVymLink()
insilmaril@0
  2121
{
insilmaril@0
  2122
	if (currentMapEditor())
insilmaril@0
  2123
		currentMapEditor()->editVymLink();	
insilmaril@0
  2124
}
insilmaril@0
  2125
insilmaril@0
  2126
void Main::editDeleteVymLink()
insilmaril@0
  2127
{
insilmaril@0
  2128
	if (currentMapEditor())
insilmaril@0
  2129
		currentMapEditor()->deleteVymLink();	
insilmaril@0
  2130
}
insilmaril@0
  2131
insilmaril@0
  2132
void Main::editMapInfo()
insilmaril@0
  2133
{
insilmaril@0
  2134
	if (currentMapEditor())
insilmaril@0
  2135
		currentMapEditor()->editMapInfo();	
insilmaril@0
  2136
}
insilmaril@0
  2137
insilmaril@0
  2138
void Main::editMoveUp()
insilmaril@0
  2139
{
insilmaril@0
  2140
	if (currentMapEditor())
insilmaril@0
  2141
	    currentMapEditor()->moveBranchUp();
insilmaril@0
  2142
}
insilmaril@0
  2143
insilmaril@0
  2144
void Main::editMoveDown()
insilmaril@0
  2145
{
insilmaril@0
  2146
	if (currentMapEditor())
insilmaril@0
  2147
		currentMapEditor()->moveBranchDown();
insilmaril@0
  2148
}
insilmaril@0
  2149
insilmaril@0
  2150
void Main::editToggleScroll()
insilmaril@0
  2151
{
insilmaril@0
  2152
	if (currentMapEditor())
insilmaril@0
  2153
	{
insilmaril@0
  2154
		currentMapEditor()->toggleScroll();	
insilmaril@0
  2155
	}	
insilmaril@0
  2156
}
insilmaril@0
  2157
insilmaril@0
  2158
void Main::editUnScrollAll()
insilmaril@0
  2159
{
insilmaril@0
  2160
	if (currentMapEditor())
insilmaril@0
  2161
	{
insilmaril@0
  2162
		currentMapEditor()->unScrollAll();	
insilmaril@0
  2163
	}	
insilmaril@0
  2164
}
insilmaril@0
  2165
insilmaril@0
  2166
void Main::editHeading()
insilmaril@0
  2167
{
insilmaril@0
  2168
	if (currentMapEditor())
insilmaril@0
  2169
		currentMapEditor()->editHeading();
insilmaril@0
  2170
}
insilmaril@0
  2171
insilmaril@0
  2172
void Main::editNewBranch()
insilmaril@0
  2173
{
insilmaril@0
  2174
	if (currentMapEditor())
insilmaril@0
  2175
		currentMapEditor()->addNewBranch(0);
insilmaril@0
  2176
}
insilmaril@0
  2177
insilmaril@98
  2178
void Main::editNewBranchHere()
insilmaril@98
  2179
{
insilmaril@98
  2180
	if (currentMapEditor())
insilmaril@98
  2181
		currentMapEditor()->addNewBranchHere();
insilmaril@98
  2182
}
insilmaril@98
  2183
insilmaril@0
  2184
void Main::editNewBranchAbove()
insilmaril@0
  2185
{
insilmaril@0
  2186
	if (currentMapEditor())
insilmaril@0
  2187
		currentMapEditor()->addNewBranch(-1);
insilmaril@0
  2188
}
insilmaril@0
  2189
insilmaril@0
  2190
void Main::editNewBranchBelow()
insilmaril@0
  2191
{
insilmaril@0
  2192
	if (currentMapEditor())
insilmaril@0
  2193
		currentMapEditor()->addNewBranch(1);
insilmaril@0
  2194
}
insilmaril@0
  2195
insilmaril@0
  2196
void Main::editImportAdd()
insilmaril@0
  2197
{
insilmaril@0
  2198
	fileLoad (ImportAdd);
insilmaril@0
  2199
}
insilmaril@0
  2200
insilmaril@0
  2201
void Main::editImportReplace()
insilmaril@0
  2202
{
insilmaril@0
  2203
	fileLoad (ImportReplace);
insilmaril@0
  2204
}
insilmaril@0
  2205
insilmaril@0
  2206
void Main::editSaveBranch()
insilmaril@0
  2207
{
insilmaril@0
  2208
	fileSaveAs (PartOfMap);
insilmaril@0
  2209
}
insilmaril@0
  2210
insilmaril@98
  2211
void Main::editRemoveBranchHere()
insilmaril@98
  2212
{
insilmaril@98
  2213
	if (currentMapEditor())
insilmaril@98
  2214
		currentMapEditor()->removeBranchHere();
insilmaril@98
  2215
}
insilmaril@98
  2216
insilmaril@98
  2217
void Main::editRemoveChilds()
insilmaril@98
  2218
{
insilmaril@98
  2219
	if (currentMapEditor())
insilmaril@98
  2220
		currentMapEditor()->removeChilds();
insilmaril@98
  2221
}
insilmaril@98
  2222
insilmaril@0
  2223
void Main::editDeleteSelection()
insilmaril@0
  2224
{
insilmaril@151
  2225
	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
insilmaril@0
  2226
		currentMapEditor()->deleteSelection();
insilmaril@0
  2227
}
insilmaril@0
  2228
insilmaril@0
  2229
void Main::editUpperBranch()
insilmaril@0
  2230
{
insilmaril@0
  2231
	if (currentMapEditor())
insilmaril@0
  2232
		currentMapEditor()->selectUpperBranch();
insilmaril@0
  2233
}
insilmaril@0
  2234
insilmaril@0
  2235
void Main::editLowerBranch()
insilmaril@0
  2236
{
insilmaril@0
  2237
	if (currentMapEditor())
insilmaril@0
  2238
		currentMapEditor()->selectLowerBranch();
insilmaril@0
  2239
}
insilmaril@0
  2240
insilmaril@0
  2241
void Main::editLeftBranch()
insilmaril@0
  2242
{
insilmaril@0
  2243
	if (currentMapEditor())
insilmaril@0
  2244
		currentMapEditor()->selectLeftBranch();
insilmaril@0
  2245
}
insilmaril@0
  2246
insilmaril@0
  2247
void Main::editRightBranch()
insilmaril@0
  2248
{
insilmaril@0
  2249
	if (currentMapEditor())
insilmaril@0
  2250
		currentMapEditor()->selectRightBranch();
insilmaril@0
  2251
}
insilmaril@0
  2252
insilmaril@0
  2253
void Main::editFirstBranch()
insilmaril@0
  2254
{
insilmaril@0
  2255
	if (currentMapEditor())
insilmaril@0
  2256
		currentMapEditor()->selectFirstBranch();
insilmaril@0
  2257
}
insilmaril@0
  2258
insilmaril@0
  2259
void Main::editLastBranch()
insilmaril@0
  2260
{
insilmaril@0
  2261
	if (currentMapEditor())
insilmaril@0
  2262
		currentMapEditor()->selectLastBranch();
insilmaril@0
  2263
}
insilmaril@0
  2264
insilmaril@0
  2265
void Main::editLoadImage()
insilmaril@0
  2266
{
insilmaril@0
  2267
	if (currentMapEditor())
insilmaril@0
  2268
		currentMapEditor()->loadFloatImage();
insilmaril@0
  2269
}
insilmaril@0
  2270
insilmaril@0
  2271
void Main::editSaveImage(int item)
insilmaril@0
  2272
{
insilmaril@0
  2273
	if (currentMapEditor())
insilmaril@0
  2274
		currentMapEditor()->saveFloatImage(item);
insilmaril@0
  2275
}
insilmaril@0
  2276
insilmaril@0
  2277
void Main::editToggleFloatExport()
insilmaril@0
  2278
{
insilmaril@0
  2279
	if (currentMapEditor())
insilmaril@0
  2280
		currentMapEditor()->toggleFloatExport();
insilmaril@0
  2281
}
insilmaril@0
  2282
insilmaril@95
  2283
void Main::editFollowXLink(int item)
insilmaril@89
  2284
{
insilmaril@89
  2285
	if (currentMapEditor())
insilmaril@95
  2286
		currentMapEditor()->followXLink(branchLinksContextMenu->indexOf(item));
insilmaril@89
  2287
}
insilmaril@89
  2288
insilmaril@95
  2289
void Main::editEditXLink(int item)
insilmaril@94
  2290
{
insilmaril@94
  2291
	if (currentMapEditor())
insilmaril@95
  2292
		currentMapEditor()->editXLink(branchLinksContextMenuDup->indexOf(item));
insilmaril@94
  2293
}
insilmaril@94
  2294
insilmaril@0
  2295
void Main::formatSelectColor()
insilmaril@0
  2296
{
insilmaril@0
  2297
	if (currentMapEditor())
insilmaril@0
  2298
	{
insilmaril@0
  2299
		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
insilmaril@0
  2300
		if ( !col.isValid() ) return;
insilmaril@0
  2301
		currentMapEditor()->setColor( col );
insilmaril@0
  2302
		colorChanged( col );
insilmaril@0
  2303
	}	
insilmaril@0
  2304
}
insilmaril@0
  2305
insilmaril@0
  2306
void Main::formatPickColor()
insilmaril@0
  2307
{
insilmaril@0
  2308
	if (currentMapEditor())
insilmaril@0
  2309
		colorChanged( currentMapEditor()->pickColor() );
insilmaril@0
  2310
}
insilmaril@0
  2311
insilmaril@0
  2312
void Main::colorChanged(QColor c)
insilmaril@0
  2313
{
insilmaril@0
  2314
    QPixmap pix( 16, 16 );
insilmaril@0
  2315
    pix.fill( c );
insilmaril@0
  2316
    actionFormatColor->setIconSet( pix );
insilmaril@0
  2317
}
insilmaril@0
  2318
insilmaril@0
  2319
void Main::formatColorItem()
insilmaril@0
  2320
{
insilmaril@0
  2321
	if (currentMapEditor())
insilmaril@0
  2322
		currentMapEditor()->colorItem();
insilmaril@0
  2323
}
insilmaril@0
  2324
insilmaril@0
  2325
void Main::formatColorBranch()
insilmaril@0
  2326
{
insilmaril@0
  2327
	if (currentMapEditor())
insilmaril@0
  2328
		currentMapEditor()->colorBranch();
insilmaril@0
  2329
}
insilmaril@0
  2330
insilmaril@0
  2331
void Main::formatLinkStyleLine()
insilmaril@0
  2332
{
insilmaril@0
  2333
	if (currentMapEditor())
insilmaril@0
  2334
		currentMapEditor()->setLinkStyle(StyleLine);
insilmaril@0
  2335
}
insilmaril@0
  2336
insilmaril@0
  2337
void Main::formatLinkStyleParabel()
insilmaril@0
  2338
{
insilmaril@0
  2339
	if (currentMapEditor())
insilmaril@0
  2340
		currentMapEditor()->setLinkStyle(StyleParabel);
insilmaril@0
  2341
}
insilmaril@0
  2342
insilmaril@0
  2343
void Main::formatLinkStylePolyLine()
insilmaril@0
  2344
{
insilmaril@0
  2345
	if (currentMapEditor())
insilmaril@0
  2346
		currentMapEditor()->setLinkStyle(StylePolyLine);
insilmaril@0
  2347
}
insilmaril@0
  2348
insilmaril@0
  2349
void Main::formatLinkStylePolyParabel()
insilmaril@0
  2350
{
insilmaril@0
  2351
	if (currentMapEditor())
insilmaril@0
  2352
		currentMapEditor()->setLinkStyle(StylePolyParabel);
insilmaril@0
  2353
}
insilmaril@0
  2354
insilmaril@0
  2355
void Main::formatSelectBackColor()
insilmaril@0
  2356
{
insilmaril@0
  2357
	if (currentMapEditor())
insilmaril@0
  2358
		currentMapEditor()->selectBackgroundColor();
insilmaril@0
  2359
}
insilmaril@0
  2360
insilmaril@0
  2361
void Main::formatSelectLinkColor()
insilmaril@0
  2362
{
insilmaril@0
  2363
	if (currentMapEditor())
insilmaril@0
  2364
		currentMapEditor()->selectLinkColor();
insilmaril@0
  2365
}
insilmaril@0
  2366
insilmaril@0
  2367
void Main::formatToggleLinkColorHint()
insilmaril@0
  2368
{
insilmaril@0
  2369
	currentMapEditor()->toggleLinkColorHint();
insilmaril@0
  2370
}
insilmaril@0
  2371
insilmaril@0
  2372
void Main::formatFrameNone()
insilmaril@0
  2373
{
insilmaril@0
  2374
	if (currentMapEditor())
insilmaril@0
  2375
		currentMapEditor()->setFrame(NoFrame);
insilmaril@0
  2376
}
insilmaril@0
  2377
insilmaril@0
  2378
void Main::formatFrameRectangle()
insilmaril@0
  2379
{
insilmaril@0
  2380
	if (currentMapEditor())
insilmaril@0
  2381
		currentMapEditor()->setFrame(Rectangle);
insilmaril@0
  2382
}
insilmaril@0
  2383
insilmaril@175
  2384
void Main::formatIncludeImagesVer()
insilmaril@175
  2385
{
insilmaril@175
  2386
	if (currentMapEditor())
insilmaril@175
  2387
		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
insilmaril@175
  2388
}
insilmaril@175
  2389
insilmaril@175
  2390
void Main::formatIncludeImagesHor()
insilmaril@175
  2391
{
insilmaril@175
  2392
	if (currentMapEditor())
insilmaril@175
  2393
		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
insilmaril@175
  2394
}
insilmaril@175
  2395
insilmaril@160
  2396
void Main::formatHideLinkUnselected()
insilmaril@160
  2397
{
insilmaril@160
  2398
	if (currentMapEditor())
insilmaril@160
  2399
		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
insilmaril@160
  2400
}
insilmaril@160
  2401
insilmaril@0
  2402
void Main::viewZoomReset()
insilmaril@0
  2403
{
insilmaril@0
  2404
	if (currentMapEditor())
insilmaril@0
  2405
	{
insilmaril@0
  2406
		QWMatrix m;
insilmaril@0
  2407
		m.reset();
insilmaril@0
  2408
		currentMapEditor()->setWorldMatrix( m );
insilmaril@0
  2409
		currentMapEditor()->setViewCenter();
insilmaril@0
  2410
		currentMapEditor()->adjustCanvasSize();
insilmaril@0
  2411
	}	
insilmaril@0
  2412
}
insilmaril@0
  2413
insilmaril@0
  2414
void Main::viewZoomIn()
insilmaril@0
  2415
{
insilmaril@0
  2416
	if (currentMapEditor())
insilmaril@0
  2417
	{
insilmaril@0
  2418
		QWMatrix m = currentMapEditor()->worldMatrix();
insilmaril@0
  2419
		m.scale( 1.25, 1.25 );
insilmaril@0
  2420
		currentMapEditor()->setWorldMatrix( m );
insilmaril@0
  2421
		currentMapEditor()->setViewCenter();
insilmaril@0
  2422
		currentMapEditor()->adjustCanvasSize();
insilmaril@0
  2423
	}	
insilmaril@0
  2424
}
insilmaril@0
  2425
insilmaril@0
  2426
void Main::viewZoomOut()
insilmaril@0
  2427
{
insilmaril@0
  2428
	if (currentMapEditor())
insilmaril@0
  2429
	{
insilmaril@0
  2430
		QWMatrix m = currentMapEditor()->worldMatrix();
insilmaril@0
  2431
		m.scale( 0.8, 0.8 );
insilmaril@0
  2432
		currentMapEditor()->setWorldMatrix( m );
insilmaril@0
  2433
		currentMapEditor()->setViewCenter();
insilmaril@0
  2434
		currentMapEditor()->adjustCanvasSize();
insilmaril@0
  2435
	}	
insilmaril@0
  2436
}
insilmaril@89
  2437
insilmaril@89
  2438
void Main::modModeColor()
insilmaril@89
  2439
{
insilmaril@89
  2440
}
insilmaril@89
  2441
insilmaril@89
  2442
void Main::modModeLink()
insilmaril@89
  2443
{
insilmaril@89
  2444
}
insilmaril@89
  2445
insilmaril@0
  2446
bool Main::settingsPDF()
insilmaril@0
  2447
{
insilmaril@0
  2448
	// Default browser is set in constructor
insilmaril@0
  2449
	bool ok;
insilmaril@0
  2450
	QString text = QInputDialog::getText(
insilmaril@0
  2451
		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
insilmaril@0
  2452
		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
insilmaril@0
  2453
	if (ok)
insilmaril@0
  2454
		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
insilmaril@0
  2455
	return ok;
insilmaril@0
  2456
}
insilmaril@0
  2457
insilmaril@0
  2458
insilmaril@0
  2459
bool Main::settingsURL()
insilmaril@0
  2460
{
insilmaril@0
  2461
	// Default browser is set in constructor
insilmaril@0
  2462
	bool ok;
insilmaril@0
  2463
	QString text = QInputDialog::getText(
insilmaril@0
  2464
		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
insilmaril@0
  2465
		settings.readEntry("/vym/mainwindow/readerURL")
insilmaril@0
  2466
		, &ok, this );
insilmaril@0
  2467
	if (ok)
insilmaril@0
  2468
		settings.writeEntry ("/vym/mainwindow/readerURL",text);
insilmaril@0
  2469
	return ok;
insilmaril@0
  2470
}
insilmaril@0
  2471
insilmaril@0
  2472
void Main::windowToggleNoteEditor()
insilmaril@0
  2473
{
insilmaril@0
  2474
	if (textEditor->showWithMain() )
insilmaril@0
  2475
		windowHideNoteEditor();
insilmaril@0
  2476
	else	
insilmaril@0
  2477
		windowShowNoteEditor();
insilmaril@0
  2478
}
insilmaril@0
  2479
insilmaril@160
  2480
void Main::updateNoteFlag()
insilmaril@160
  2481
{
insilmaril@160
  2482
	if (currentMapEditor())
insilmaril@160
  2483
		currentMapEditor()->updateNoteFlag();
insilmaril@160
  2484
}
insilmaril@160
  2485
insilmaril@0
  2486
void Main::windowShowNoteEditor()
insilmaril@0
  2487
{
insilmaril@0
  2488
	textEditor->setShowWithMain(true);
insilmaril@0
  2489
	textEditor->show();
insilmaril@0
  2490
	actionViewToggleNoteEditor->setOn (true);
insilmaril@0
  2491
}
insilmaril@0
  2492
insilmaril@0
  2493
void Main::windowHideNoteEditor()
insilmaril@0
  2494
{
insilmaril@0
  2495
	textEditor->setShowWithMain(false);
insilmaril@0
  2496
	textEditor->hide();
insilmaril@0
  2497
	actionViewToggleNoteEditor->setOn (false);
insilmaril@0
  2498
}
insilmaril@0
  2499
insilmaril@0
  2500
void Main::windowNextEditor()
insilmaril@0
  2501
{
insilmaril@0
  2502
	if (tabWidget->currentPageIndex() < tabWidget->count())
insilmaril@0
  2503
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
insilmaril@0
  2504
}
insilmaril@0
  2505
insilmaril@0
  2506
void Main::windowPreviousEditor()
insilmaril@0
  2507
{
insilmaril@0
  2508
	if (tabWidget->currentPageIndex() >0)
insilmaril@0
  2509
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
insilmaril@0
  2510
}
insilmaril@0
  2511
insilmaril@0
  2512
void Main::standardFlagChanged()
insilmaril@0
  2513
{
insilmaril@0
  2514
	currentMapEditor()->toggleStandardFlag(sender()->name());
insilmaril@0
  2515
}
insilmaril@0
  2516
insilmaril@0
  2517
void Main::testFunction()
insilmaril@0
  2518
{
insilmaril@205
  2519
	currentMapEditor()->testFunction();
insilmaril@0
  2520
}
insilmaril@0
  2521
insilmaril@0
  2522
void Main::helpDoc()
insilmaril@0
  2523
{
insilmaril@0
  2524
	QString docpath;
insilmaril@103
  2525
	#if defined(Q_OS_MACX)
insilmaril@103
  2526
		docpath="./vym.app/Contents/vym.pdf";
insilmaril@103
  2527
	#else
insilmaril@103
  2528
		// default path in SUSE LINUX
insilmaril@103
  2529
		docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
insilmaril@103
  2530
	#endif
insilmaril@0
  2531
insilmaril@0
  2532
	if (!QFile (docpath).exists() )
insilmaril@0
  2533
	{
insilmaril@0
  2534
		// relative path for easy testing in tarball
insilmaril@0
  2535
		docpath="doc/vym.pdf";
insilmaril@0
  2536
		if (!QFile (docpath).exists() )
insilmaril@0
  2537
		{
insilmaril@0
  2538
			// relative path for testing while still writing vym.tex
insilmaril@0
  2539
			docpath="doc/tex/vym.pdf";
insilmaril@0
  2540
			if (!QFile (docpath).exists() )
insilmaril@0
  2541
			{
insilmaril@175
  2542
				// Try yet another one for Knoppix
insilmaril@175
  2543
				docpath="/usr/share/doc/packages/vym/vym.pdf";
insilmaril@175
  2544
				if (!QFile (docpath).exists() )
insilmaril@175
  2545
				{
insilmaril@175
  2546
					QMessageBox::critical(0, 
insilmaril@175
  2547
					tr("Critcal error"),
insilmaril@175
  2548
					tr("Couldn't find the documentation\n"
insilmaril@175
  2549
					"vym.pdf in various places."));
insilmaril@175
  2550
					return;
insilmaril@175
  2551
				}	
insilmaril@0
  2552
			}	
insilmaril@0
  2553
		}
insilmaril@0
  2554
	}
insilmaril@0
  2555
	
insilmaril@0
  2556
	Process *pdfProc = new Process();
insilmaril@0
  2557
	pdfProc->clearArguments();
insilmaril@0
  2558
	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
insilmaril@0
  2559
	pdfProc->addArgument( docpath);
insilmaril@0
  2560
insilmaril@0
  2561
	if ( !pdfProc->start() ) 
insilmaril@0
  2562
	{
insilmaril@0
  2563
		// error handling
insilmaril@0
  2564
		QMessageBox::critical(0, 
insilmaril@0
  2565
		tr("Critcal error"),
insilmaril@0
  2566
		tr("Couldn't find a viewer to read vym.pdf.\n"
insilmaril@0
  2567
		"Please use Settings->")+tr("Set application to open pdf files"));
insilmaril@0
  2568
		return;
insilmaril@0
  2569
	}
insilmaril@0
  2570
}
insilmaril@0
  2571
insilmaril@0
  2572
insilmaril@0
  2573
void Main::helpAbout()
insilmaril@0
  2574
{
insilmaril@148
  2575
	AboutDialog ad;
insilmaril@150
  2576
	ad.setName ("aboutwindow");
insilmaril@148
  2577
	ad.setMinimumSize(500,500);
insilmaril@148
  2578
	ad.resize (QSize (500,500));
insilmaril@148
  2579
	ad.exec();
insilmaril@0
  2580
}
insilmaril@0
  2581
insilmaril@0
  2582
void Main::helpAboutQT()
insilmaril@0
  2583
{
insilmaril@0
  2584
	QMessageBox::aboutQt( this, "Qt Application Example" );
insilmaril@0
  2585
}
insilmaril@0
  2586