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