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