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