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