mainwindow.cpp
author insilmaril
Thu Aug 09 18:34:08 2007 +0000 (2007-08-09)
changeset 584 95f1af9b525a
parent 571 bc9083a4a7fb
child 585 a8e9eae855f4
permissions -rw-r--r--
1.10.0
insilmaril@0
     1
#include "mainwindow.h"
insilmaril@0
     2
insilmaril@366
     3
#include <QtGui>
insilmaril@390
     4
insilmaril@0
     5
#include <iostream>
insilmaril@0
     6
insilmaril@205
     7
#include "aboutdialog.h"
insilmaril@421
     8
#include "branchpropwindow.h"
insilmaril@205
     9
#include "exportoofiledialog.h"
insilmaril@228
    10
#include "exports.h"
insilmaril@205
    11
#include "file.h"
insilmaril@0
    12
#include "flagrowobj.h"
insilmaril@377
    13
#include "historywindow.h"
insilmaril@205
    14
#include "imports.h"
insilmaril@0
    15
#include "mapeditor.h"
insilmaril@205
    16
#include "misc.h"
insilmaril@205
    17
#include "options.h"
insilmaril@0
    18
#include "process.h"
insilmaril@0
    19
#include "settings.h"
insilmaril@205
    20
#include "texteditor.h"
insilmaril@442
    21
#include "warningdialog.h"
insilmaril@0
    22
insilmaril@0
    23
extern TextEditor *textEditor;
insilmaril@0
    24
extern Main *mainWindow;
insilmaril@164
    25
extern QString tmpVymDir;
insilmaril@166
    26
extern QString clipboardDir;
insilmaril@491
    27
extern QString clipboardFile;
insilmaril@166
    28
extern bool clipboardEmpty;
insilmaril@0
    29
extern int statusbarTime;
insilmaril@0
    30
extern FlagRowObj* standardFlagsDefault;
insilmaril@166
    31
extern FlagRowObj* systemFlagsDefault;
insilmaril@404
    32
extern QString vymName;
insilmaril@404
    33
extern QString vymVersion;
insilmaril@404
    34
extern QString vymBuildDate;
insilmaril@502
    35
extern bool debug;
insilmaril@0
    36
insilmaril@390
    37
QMenu* branchContextMenu;
insilmaril@390
    38
QMenu* branchAddContextMenu;
insilmaril@390
    39
QMenu* branchRemoveContextMenu;
insilmaril@390
    40
QMenu* branchLinksContextMenu;
insilmaril@390
    41
QMenu* branchXLinksContextMenuEdit;
insilmaril@390
    42
QMenu* branchXLinksContextMenuFollow;
insilmaril@390
    43
QMenu* floatimageContextMenu;
insilmaril@390
    44
QMenu* canvasContextMenu;
insilmaril@390
    45
QMenu* fileLastMapsMenu;
insilmaril@390
    46
QMenu* fileImportMenu;
insilmaril@390
    47
QMenu* fileExportMenu;
insilmaril@0
    48
insilmaril@0
    49
insilmaril@0
    50
extern Settings settings;
insilmaril@0
    51
extern Options options;
insilmaril@366
    52
extern ImageIO imageIO;
insilmaril@366
    53
insilmaril@269
    54
extern QDir vymBaseDir;
insilmaril@366
    55
extern QDir lastImageDir;
insilmaril@366
    56
extern QDir lastFileDir;
insilmaril@269
    57
extern QString iconPath;
insilmaril@269
    58
extern QString flagsPath;
insilmaril@0
    59
insilmaril@366
    60
Main::Main(QWidget* parent, const char* name, Qt::WFlags f) :
insilmaril@0
    61
    QMainWindow(parent,name,f)
insilmaril@0
    62
{
insilmaril@0
    63
	mainWindow=this;
insilmaril@0
    64
insilmaril@0
    65
	setCaption ("VYM - View Your Mind");
insilmaril@0
    66
insilmaril@0
    67
	// Load window settings
insilmaril@366
    68
	resize (settings.value( "/mainwindow/geometry/size",QSize (800,600)).toSize());
insilmaril@366
    69
	move   (settings.value( "/mainwindow/geometry/pos", QPoint(300,100)).toPoint());
insilmaril@0
    70
insilmaril@0
    71
insilmaril@394
    72
	// Sometimes we may need to remember old selections
insilmaril@394
    73
	prevSelection="";
insilmaril@394
    74
insilmaril@395
    75
	// Default color
insilmaril@395
    76
	currentColor=Qt::black;
insilmaril@395
    77
insilmaril@164
    78
	// Create unique temporary directory
insilmaril@366
    79
	bool ok;
insilmaril@366
    80
	tmpVymDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
insilmaril@366
    81
	if (!ok)
insilmaril@366
    82
	{
insilmaril@366
    83
		qWarning ("Mainwindow: Could not create temporary directory, failed to start vym");
insilmaril@366
    84
		exit (1);
insilmaril@366
    85
	}
insilmaril@502
    86
	if (debug) qDebug (QString("vym tmpDir=%1").arg(tmpVymDir) );
insilmaril@164
    87
insilmaril@166
    88
	// Create direcctory for clipboard
insilmaril@166
    89
	clipboardDir=tmpVymDir+"/clipboard";
insilmaril@502
    90
	clipboardFile="map.xml";
insilmaril@166
    91
	QDir d(clipboardDir);
insilmaril@166
    92
	d.mkdir (clipboardDir,true);
insilmaril@166
    93
	makeSubDirs (clipboardDir);
insilmaril@166
    94
	clipboardEmpty=true;
insilmaril@164
    95
insilmaril@266
    96
	procBrowser=NULL;
insilmaril@266
    97
insilmaril@486
    98
	// Satellite windows //////////////////////////////////////////
insilmaril@486
    99
insilmaril@486
   100
	// history window
insilmaril@404
   101
	historyWindow=new HistoryWindow();
insilmaril@486
   102
	connect (historyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
insilmaril@486
   103
insilmaril@486
   104
	// properties window
insilmaril@421
   105
	branchPropertyWindow = new BranchPropertyWindow();
insilmaril@486
   106
	connect (branchPropertyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
insilmaril@486
   107
insilmaril@486
   108
	// Connect TextEditor, so that we can update flags if text changes
insilmaril@486
   109
	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
insilmaril@486
   110
	connect (textEditor, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
insilmaril@486
   111
insilmaril@486
   112
	// Connect HistoryWindow, so that we can update flags
insilmaril@486
   113
	connect (historyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
insilmaril@473
   114
insilmaril@421
   115
insilmaril@432
   116
	// Initialize script editor
insilmaril@432
   117
	scriptEditor = new SimpleScriptEditor();
insilmaril@432
   118
	scriptEditor->move (50,50);
insilmaril@432
   119
insilmaril@432
   120
	connect( scriptEditor, SIGNAL( runScript ( QString ) ), 
insilmaril@432
   121
		this, SLOT( runScript( QString ) ) );
insilmaril@432
   122
	
insilmaril@486
   123
insilmaril@486
   124
	// Initialize Find window
insilmaril@486
   125
	findWindow=new FindWindow(NULL);
insilmaril@486
   126
	findWindow->move (x(),y()+70);
insilmaril@486
   127
	connect (findWindow, SIGNAL( findButton(QString) ), 
insilmaril@486
   128
		this, SLOT(editFind(QString) ) );	
insilmaril@486
   129
	connect (findWindow, SIGNAL( somethingChanged() ), 
insilmaril@486
   130
		this, SLOT(editFindChanged() ) );	
insilmaril@486
   131
insilmaril@0
   132
	// Initialize some settings, which are platform dependant
insilmaril@0
   133
	QString p,s;
insilmaril@0
   134
insilmaril@0
   135
		// application to open URLs
insilmaril@366
   136
		p="/mainwindow/readerURL";
insilmaril@0
   137
		#if defined(Q_OS_LINUX)
insilmaril@366
   138
			s=settings.value (p,"konqueror").toString();
insilmaril@0
   139
		#else
insilmaril@0
   140
			#if defined(Q_OS_MACX)
insilmaril@366
   141
				s=settings.value (p,"/usr/bin/open").toString();
insilmaril@0
   142
			#else
insilmaril@366
   143
				s=settings.value (p,"mozilla");
insilmaril@0
   144
			#endif
insilmaril@0
   145
		#endif
insilmaril@366
   146
		settings.setValue( p,s);
insilmaril@0
   147
insilmaril@0
   148
		// application to open PDFs
insilmaril@366
   149
		p="/mainwindow/readerPDF";
insilmaril@0
   150
		#if defined(Q_OS_LINUX)
insilmaril@366
   151
			s=settings.value (p,"acroread").toString();
insilmaril@0
   152
		#else
insilmaril@0
   153
			#if defined(Q_OS_MACX)
insilmaril@366
   154
				s=settings.value (p,"/usr/bin/open").toString();
insilmaril@0
   155
			#else
insilmaril@366
   156
				s=settings.value (p,"acroread").toString();
insilmaril@0
   157
			#endif
insilmaril@0
   158
		#endif
insilmaril@366
   159
		settings.setValue( p,s);
insilmaril@0
   160
insilmaril@0
   161
	
insilmaril@0
   162
	// Create tab widget which holds the maps
insilmaril@0
   163
	tabWidget= new QTabWidget (this);
insilmaril@0
   164
	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
insilmaril@0
   165
		this, SLOT( editorChanged( QWidget * ) ) );
insilmaril@0
   166
insilmaril@366
   167
	lineedit=new QLineEdit (this);
insilmaril@366
   168
	lineedit->hide();
insilmaril@366
   169
insilmaril@0
   170
	setCentralWidget(tabWidget);	
insilmaril@0
   171
insilmaril@0
   172
    setupFileActions();
insilmaril@0
   173
    setupEditActions();
insilmaril@0
   174
    setupFormatActions();
insilmaril@0
   175
    setupViewActions();
insilmaril@89
   176
    setupModeActions();
insilmaril@0
   177
	setupFlagActions();
insilmaril@528
   178
    setupNetworkActions();
insilmaril@0
   179
    setupSettingsActions();
insilmaril@0
   180
	setupContextMenus();
insilmaril@445
   181
	setupMacros();
insilmaril@366
   182
    if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
insilmaril@0
   183
    setupHelpActions();
insilmaril@0
   184
    
insilmaril@0
   185
    statusBar();
insilmaril@0
   186
insilmaril@366
   187
	restoreState (settings.value("/mainwindow/state",0).toByteArray());
insilmaril@0
   188
insilmaril@0
   189
	updateGeometry();
insilmaril@0
   190
}
insilmaril@0
   191
insilmaril@0
   192
Main::~Main()
insilmaril@0
   193
{
insilmaril@0
   194
	// Save Settings
insilmaril@366
   195
	settings.setValue ( "/mainwindow/geometry/size", size() );
insilmaril@366
   196
	settings.setValue ( "/mainwindow/geometry/pos", pos() );
insilmaril@366
   197
	settings.setValue ("/mainwindow/state",saveState(0));
insilmaril@366
   198
insilmaril@408
   199
	settings.setValue ("/mainwindow/view/AntiAlias",actionViewToggleAntiAlias->isOn());
insilmaril@408
   200
	settings.setValue ("/mainwindow/view/SmoothPixmapTransform",actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@404
   201
	settings.setValue( "/version/version", vymVersion );
insilmaril@404
   202
	settings.setValue( "/version/builddate", vymBuildDate );
insilmaril@366
   203
insilmaril@491
   204
	settings.setValue( "/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
insilmaril@537
   205
	settings.setValue( "/mapeditor/editmode/autoSelectNewBranch",actionSettingsAutoSelectNewBranch->isOn() );
insilmaril@390
   206
	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
insilmaril@537
   207
	settings.setValue( "/mapeditor/editmode/autoEditNewBranch",actionSettingsAutoEditNewBranch->isOn() );
insilmaril@366
   208
	settings.setValue( "/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
insilmaril@366
   209
	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
insilmaril@366
   210
	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
insilmaril@0
   211
insilmaril@473
   212
	//TODO save scriptEditor settings
insilmaril@432
   213
insilmaril@404
   214
	// call the destructors
insilmaril@442
   215
	delete textEditor;
insilmaril@404
   216
	delete historyWindow;
insilmaril@473
   217
	delete branchPropertyWindow;
insilmaril@164
   218
insilmaril@164
   219
	// Remove temporary directory
insilmaril@164
   220
	removeDir (QDir(tmpVymDir));
insilmaril@0
   221
}
insilmaril@0
   222
insilmaril@0
   223
void Main::loadCmdLine()
insilmaril@0
   224
{
insilmaril@0
   225
	/* TODO draw some kind of splashscreen while loading...
insilmaril@0
   226
	if (qApp->argc()>1)
insilmaril@0
   227
	{
insilmaril@0
   228
	}
insilmaril@0
   229
	*/
insilmaril@0
   230
	
insilmaril@0
   231
	QStringList flist=options.getFileList();
insilmaril@0
   232
	QStringList::Iterator it=flist.begin();
insilmaril@0
   233
insilmaril@0
   234
	while (it !=flist.end() )
insilmaril@0
   235
	{
insilmaril@0
   236
		fileLoad (*it, NewMap);
insilmaril@0
   237
		*it++;
insilmaril@0
   238
	}	
insilmaril@0
   239
}
insilmaril@0
   240
insilmaril@0
   241
insilmaril@0
   242
void Main::statusMessage(const QString &s)
insilmaril@0
   243
{
insilmaril@502
   244
	statusBar()->message( s);
insilmaril@0
   245
}
insilmaril@0
   246
insilmaril@0
   247
void Main::closeEvent (QCloseEvent* )
insilmaril@0
   248
{
insilmaril@0
   249
	fileExitVYM();
insilmaril@0
   250
}
insilmaril@0
   251
insilmaril@0
   252
// File Actions
insilmaril@0
   253
void Main::setupFileActions()
insilmaril@0
   254
{
insilmaril@366
   255
	QMenu *fileMenu = menuBar()->addMenu ( tr ("&Map") );
insilmaril@366
   256
    QToolBar *tb = addToolBar( tr ("&Map") );
insilmaril@366
   257
	tb->setObjectName ("mapTB");
insilmaril@0
   258
insilmaril@0
   259
    QAction *a;
insilmaril@491
   260
    a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New map","File menu" ),this);
insilmaril@395
   261
	a->setStatusTip ( tr( "New map","Status tip File menu" ) );
insilmaril@442
   262
	a->setShortcut ( Qt::CTRL + Qt::Key_N );		//New map
insilmaril@0
   263
    a->addTo( tb );
insilmaril@366
   264
	fileMenu->addAction (a);
insilmaril@366
   265
    connect( a, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
insilmaril@0
   266
	
insilmaril@494
   267
    a = new QAction(QPixmap( iconPath+"filenewcopy.png"), tr( "&Copy to new map","File menu" ),this);
insilmaril@491
   268
	a->setStatusTip ( tr( "Copy selection to mapcenter of a new map","Status tip File menu" ) );
insilmaril@491
   269
	a->setShortcut ( Qt::CTRL +Qt::SHIFT + Qt::Key_N );		//New map
insilmaril@491
   270
	fileMenu->addAction (a);
insilmaril@491
   271
    connect( a, SIGNAL( triggered() ), this, SLOT( fileNewCopy() ) );
insilmaril@491
   272
	
insilmaril@395
   273
    a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Open..." ,"File menu"),this);
insilmaril@395
   274
	a->setStatusTip (tr( "Open","Status tip File menu" ) );
insilmaril@442
   275
	a->setShortcut ( Qt::CTRL + Qt::Key_O );		//Open map
insilmaril@0
   276
    a->addTo( tb );
insilmaril@366
   277
	fileMenu->addAction (a);
insilmaril@366
   278
    connect( a, SIGNAL( triggered() ), this, SLOT( fileLoad() ) );
insilmaril@0
   279
	
insilmaril@395
   280
	fileLastMapsMenu = fileMenu->addMenu (tr("Open Recent","File menu"));
insilmaril@366
   281
	fileMenu->addSeparator();
insilmaril@0
   282
	
insilmaril@395
   283
    a = new QAction( QPixmap( iconPath+"filesave.png"), tr( "&Save...","File menu" ), this);
insilmaril@395
   284
	a->setStatusTip ( tr( "Save","Status tip file menu" ));
insilmaril@442
   285
	a->setShortcut (Qt::CTRL + Qt::Key_S );			//Save map
insilmaril@0
   286
    a->addTo( tb );
insilmaril@366
   287
	fileMenu->addAction (a);
insilmaril@366
   288
    connect( a, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
insilmaril@0
   289
	actionFileSave=a;
insilmaril@0
   290
	
insilmaril@395
   291
    a = new QAction( QPixmap(iconPath+"filesaveas.png"), tr( "Save &As...","File menu" ), this);
insilmaril@395
   292
	a->setStatusTip (tr( "Save &As","Status tip file menu" ) );
insilmaril@366
   293
	fileMenu->addAction (a);
insilmaril@366
   294
    connect( a, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
insilmaril@366
   295
insilmaril@366
   296
	fileMenu->addSeparator();
insilmaril@366
   297
insilmaril@395
   298
	fileImportMenu = fileMenu->addMenu (tr("Import","File menu"));
insilmaril@366
   299
insilmaril@366
   300
	a = new QAction(tr("KDE Bookmarks"), this);
insilmaril@395
   301
	a->setStatusTip ( tr( "Import %1","Status tip file menu" ).arg(tr("KDE bookmarks")));
insilmaril@366
   302
	a->addTo (fileImportMenu);
insilmaril@366
   303
	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportKDEBookmarks() ) );
insilmaril@366
   304
insilmaril@366
   305
    if (settings.value( "/mainwindow/showTestMenu",false).toBool()) 
insilmaril@331
   306
	{
insilmaril@395
   307
		a = new QAction( QPixmap(), tr("Firefox Bookmarks","File menu"),this);
insilmaril@395
   308
		a->setStatusTip (tr( "Import %1","Status tip file menu").arg(tr("Firefox Bookmarks" ) ));
insilmaril@366
   309
		a->addTo (fileImportMenu);
insilmaril@366
   310
		connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFirefoxBookmarks() ) );
insilmaril@331
   311
	}	
insilmaril@314
   312
insilmaril@571
   313
	a = new QAction("Freemind...",this);
insilmaril@571
   314
	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Freemind")  );
insilmaril@571
   315
	fileImportMenu->addAction (a);
insilmaril@571
   316
	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFreemind() ) );
insilmaril@571
   317
insilmaril@366
   318
	a = new QAction("Mind Manager...",this);
insilmaril@395
   319
	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Mind Manager")  );
insilmaril@366
   320
	fileImportMenu->addAction (a);
insilmaril@366
   321
	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportMM() ) );
insilmaril@366
   322
insilmaril@395
   323
    a = new QAction( tr( "Import Dir%1","File menu").arg("..."), this);
insilmaril@395
   324
	a->setStatusTip (tr( "Import directory structure (experimental)","status tip file menu" ) );
insilmaril@366
   325
	fileImportMenu->addAction (a);
insilmaril@366
   326
    connect( a, SIGNAL( triggered() ), this, SLOT( fileImportDir() ) );
insilmaril@366
   327
insilmaril@395
   328
	fileExportMenu = fileMenu->addMenu (tr("Export","File menu"));
insilmaril@395
   329
insilmaril@395
   330
	a = new QAction( tr("Image%1","File export menu").arg("..."), this);
insilmaril@395
   331
	a->setStatusTip( tr( "Export map as image","status tip file menu" ));
insilmaril@366
   332
	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportImage() ) );
insilmaril@366
   333
	fileExportMenu->addAction (a);
insilmaril@366
   334
insilmaril@395
   335
	a = new QAction( "Open Office...", this);
insilmaril@395
   336
	a->setStatusTip( tr( "Export in Open Document Format used e.g. in Open Office ","status tip file menu" ));
insilmaril@366
   337
	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportOOPresentation() ) );
insilmaril@366
   338
	fileExportMenu->addAction (a);
insilmaril@366
   339
insilmaril@366
   340
	a = new QAction(  "Webpage (XHTML)...",this );
insilmaril@442
   341
	a->setShortcut (Qt::ALT + Qt::Key_X);			//Export XHTML
insilmaril@395
   342
	a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu")));
insilmaril@366
   343
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXHTML() ) );
insilmaril@366
   344
	fileExportMenu->addAction (a);
insilmaril@366
   345
insilmaril@366
   346
    a = new QAction( "Text (ASCII)...", this);
insilmaril@395
   347
	a->setStatusTip ( tr( "Export as %1").arg("ASCII "+tr("(still experimental)" )));
insilmaril@366
   348
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportASCII() ) );
insilmaril@366
   349
	fileExportMenu->addAction (a);
insilmaril@366
   350
insilmaril@497
   351
    a = new QAction( "Spreadsheet (CSV)...", this);
insilmaril@497
   352
	a->setStatusTip ( tr( "Export as %1").arg("CSV "+tr("(still experimental)" )));
insilmaril@497
   353
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportCSV() ) );
insilmaril@497
   354
	fileExportMenu->addAction (a);
insilmaril@497
   355
insilmaril@395
   356
	a = new QAction( tr("KDE Bookmarks","File menu"), this);
insilmaril@395
   357
	a->setStatusTip( tr( "Export as %1").arg(tr("KDE Bookmarks" )));
insilmaril@366
   358
	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportKDEBookmarks() ) );
insilmaril@366
   359
	fileExportMenu->addAction (a);
insilmaril@366
   360
insilmaril@366
   361
    a = new QAction( "Taskjuggler...", this );
insilmaril@395
   362
    a->setStatusTip( tr( "Export as %1").arg("Taskjuggler "+tr("(still experimental)" )));
insilmaril@366
   363
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportTaskjuggler() ) );
insilmaril@366
   364
	fileExportMenu->addAction (a);
insilmaril@366
   365
insilmaril@366
   366
    a = new QAction( "LaTeX...", this);
insilmaril@395
   367
    a->setStatusTip( tr( "Export as %1").arg("LaTeX "+tr("(still experimental)" )));
insilmaril@366
   368
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportLaTeX() ) );
insilmaril@366
   369
	fileExportMenu->addAction (a);
insilmaril@366
   370
insilmaril@366
   371
	a = new QAction( "XML..." , this );
insilmaril@395
   372
	a->setStatusTip (tr( "Export as %1").arg("XML"));
insilmaril@366
   373
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXML() ) );
insilmaril@366
   374
	fileExportMenu->addAction (a);
insilmaril@366
   375
insilmaril@366
   376
	fileMenu->addSeparator();
insilmaril@366
   377
insilmaril@366
   378
    a = new QAction(QPixmap( iconPath+"fileprint.png"), tr( "&Print")+QString("..."), this);
insilmaril@395
   379
	a->setStatusTip ( tr( "Print" ,"File menu") );
insilmaril@442
   380
	a->setShortcut (Qt::CTRL + Qt::Key_P );			//Print map
insilmaril@0
   381
    a->addTo( tb );
insilmaril@366
   382
	fileMenu->addAction (a);
insilmaril@366
   383
    connect( a, SIGNAL( triggered() ), this, SLOT( filePrint() ) );
insilmaril@0
   384
	actionFilePrint=a;
insilmaril@0
   385
insilmaril@395
   386
    a = new QAction( QPixmap(iconPath+"fileclose.png"), tr( "&Close Map","File menu" ), this);
insilmaril@366
   387
	a->setStatusTip (tr( "Close Map" ) );
insilmaril@473
   388
	a->setShortcut (Qt::CTRL + Qt::Key_W );			//Close map
insilmaril@366
   389
	fileMenu->addAction (a);
insilmaril@366
   390
    connect( a, SIGNAL( triggered() ), this, SLOT( fileCloseMap() ) );
insilmaril@366
   391
insilmaril@404
   392
    a = new QAction(QPixmap(iconPath+"exit.png"), tr( "E&xit","File menu")+" "+vymName, this);
insilmaril@404
   393
	a->setStatusTip ( tr( "Exit")+" "+vymName );
insilmaril@442
   394
	a->setShortcut (Qt::CTRL + Qt::Key_Q );			//Quit vym
insilmaril@366
   395
	fileMenu->addAction (a);
insilmaril@366
   396
    connect( a, SIGNAL( triggered() ), this, SLOT( fileExitVYM() ) );
insilmaril@0
   397
}
insilmaril@0
   398
insilmaril@0
   399
insilmaril@0
   400
//Edit Actions
insilmaril@0
   401
void Main::setupEditActions()
insilmaril@0
   402
{
insilmaril@395
   403
    QToolBar *tb = addToolBar( tr ("&Actions toolbar","Toolbar name") );
insilmaril@0
   404
    tb->setLabel( "Edit Actions" );
insilmaril@366
   405
	tb->setObjectName ("actionsTB");
insilmaril@395
   406
    QMenu *editMenu = menuBar()->addMenu( tr("&Edit","Edit menu") );
insilmaril@0
   407
insilmaril@0
   408
    QAction *a;
insilmaril@102
   409
	QAction *alt;
insilmaril@395
   410
    a = new QAction( QPixmap( iconPath+"undo.png"), tr( "&Undo","Edit menu" ),this);
insilmaril@366
   411
    connect( a, SIGNAL( triggered() ), this, SLOT( editUndo() ) );
insilmaril@366
   412
	a->setStatusTip (tr( "Undo" ) );
insilmaril@442
   413
	a->setShortcut ( Qt::CTRL + Qt::Key_Z );		//Undo last action
insilmaril@0
   414
	a->setEnabled (false);
insilmaril@366
   415
    tb->addAction (a);
insilmaril@366
   416
	editMenu->addAction (a);
insilmaril@0
   417
	actionEditUndo=a;
insilmaril@163
   418
    
insilmaril@395
   419
	a = new QAction( QPixmap( iconPath+"redo.png"), tr( "&Redo","Edit menu" ), this); 
insilmaril@366
   420
	a->setStatusTip (tr( "Redo" ));
insilmaril@442
   421
	a->setShortcut (Qt::CTRL + Qt::Key_Y );			//Redo last action
insilmaril@366
   422
    tb->addAction (a);
insilmaril@366
   423
	editMenu->addAction (a);
insilmaril@366
   424
	connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
insilmaril@366
   425
	actionEditRedo=a;
insilmaril@163
   426
   
insilmaril@366
   427
	editMenu->addSeparator();
insilmaril@395
   428
    a = new QAction(QPixmap( iconPath+"editcopy.png"), tr( "&Copy","Edit menu" ), this);
insilmaril@366
   429
	a->setStatusTip ( tr( "Copy" ) );
insilmaril@442
   430
	a->setShortcut (Qt::CTRL + Qt::Key_C );			//Copy
insilmaril@0
   431
	a->setEnabled (false);
insilmaril@366
   432
    tb->addAction (a);
insilmaril@366
   433
	editMenu->addAction (a);
insilmaril@366
   434
    connect( a, SIGNAL( triggered() ), this, SLOT( editCopy() ) );
insilmaril@0
   435
	actionEditCopy=a;
insilmaril@366
   436
	
insilmaril@395
   437
    a = new QAction(QPixmap( iconPath+"editcut.png" ), tr( "Cu&t","Edit menu" ), this);
insilmaril@366
   438
	a->setStatusTip ( tr( "Cut" ) );
insilmaril@442
   439
	a->setShortcut (Qt::CTRL + Qt::Key_X );			//Cut
insilmaril@0
   440
	a->setEnabled (false);
insilmaril@366
   441
    tb->addAction (a);
insilmaril@366
   442
	editMenu->addAction (a);
insilmaril@0
   443
	actionEditCut=a;
insilmaril@366
   444
    connect( a, SIGNAL( triggered() ), this, SLOT( editCut() ) );
insilmaril@366
   445
	
insilmaril@395
   446
    a = new QAction(QPixmap( iconPath+"editpaste.png"), tr( "&Paste","Edit menu" ),this);
insilmaril@366
   447
    connect( a, SIGNAL( triggered() ), this, SLOT( editPaste() ) );
insilmaril@366
   448
	a->setStatusTip ( tr( "Paste" ) );
insilmaril@442
   449
	a->setShortcut ( Qt::CTRL + Qt::Key_V );		//Paste
insilmaril@0
   450
	a->setEnabled (false);
insilmaril@366
   451
    tb->addAction (a);
insilmaril@366
   452
	editMenu->addAction (a);
insilmaril@0
   453
	actionEditPaste=a;
insilmaril@98
   454
insilmaril@351
   455
    // Shortcuts to modify heading:
insilmaril@395
   456
    a = new QAction(tr( "Edit heading","Edit menu" ),this);
insilmaril@366
   457
	a->setStatusTip ( tr( "edit Heading" ));
insilmaril@442
   458
	a->setShortcut ( Qt::Key_Enter);				//Edit heading
insilmaril@366
   459
//	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   460
	addAction (a);
insilmaril@366
   461
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@351
   462
	actionListBranches.append(a);
insilmaril@395
   463
    a = new QAction( tr( "Edit heading","Edit menu" ), this);
insilmaril@366
   464
	a->setStatusTip (tr( "edit Heading" ));
insilmaril@442
   465
	a->setShortcut (Qt::Key_Return );				//Edit heading
insilmaril@366
   466
	//a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   467
	addAction (a);
insilmaril@366
   468
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@351
   469
	actionListBranches.append(a);
insilmaril@366
   470
	editMenu->addAction (a);
insilmaril@351
   471
	actionEditHeading=a;
insilmaril@395
   472
    a = new QAction( tr( "Edit heading","Edit menu" ), this);
insilmaril@366
   473
	a->setStatusTip (tr( "edit Heading" ));
insilmaril@445
   474
	//a->setShortcut ( Qt::Key_F2 );					//Edit heading
insilmaril@366
   475
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   476
	addAction (a);
insilmaril@366
   477
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@351
   478
	actionListBranches.append(a);
insilmaril@351
   479
    
insilmaril@351
   480
    // Shortcut to delete selection
insilmaril@395
   481
    a = new QAction( tr( "Delete Selection","Edit menu" ),this);
insilmaril@366
   482
	a->setStatusTip (tr( "Delete Selection" ));
insilmaril@442
   483
	a->setShortcut ( Qt::Key_Delete);				//Delete selection
insilmaril@366
   484
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   485
	addAction (a);
insilmaril@366
   486
    connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteSelection() ) );
insilmaril@351
   487
	actionEditDelete=a;
insilmaril@351
   488
    
insilmaril@351
   489
    // Shortcut to add branch
insilmaril@395
   490
	alt = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
insilmaril@366
   491
	alt->setStatusTip ( tr( "Add a branch as child of selection" ));
insilmaril@442
   492
	alt->setShortcut (Qt::Key_A);					//Add branch
insilmaril@366
   493
	alt->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   494
	addAction (alt);
insilmaril@366
   495
	connect( alt, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
insilmaril@395
   496
	a = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
insilmaril@366
   497
	a->setStatusTip ( tr( "Add a branch as child of selection" ));
insilmaril@442
   498
	a->setShortcut (Qt::Key_Insert);				//Add branch
insilmaril@366
   499
	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
insilmaril@351
   500
	actionListBranches.append(a);
insilmaril@351
   501
	#if defined (Q_OS_MACX)
insilmaril@366
   502
		// In OSX show different shortcut in menues, the keys work indepently always			
insilmaril@351
   503
		actionEditAddBranch=alt;
insilmaril@351
   504
	#else	
insilmaril@351
   505
		actionEditAddBranch=a;
insilmaril@351
   506
	#endif	
insilmaril@366
   507
	editMenu->addAction (actionEditAddBranch);
insilmaril@366
   508
	tb->addAction (actionEditAddBranch);
insilmaril@366
   509
insilmaril@351
   510
insilmaril@351
   511
    // Add branch by inserting it at selection
insilmaril@395
   512
	a = new QAction(tr( "Add branch (insert)","Edit menu" ), this);
insilmaril@366
   513
	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
insilmaril@442
   514
	a->setShortcut (Qt::ALT + Qt::Key_Insert );		//Insert branch
insilmaril@366
   515
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   516
	addAction (a);
insilmaril@394
   517
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
insilmaril@351
   518
	a->setEnabled (false);
insilmaril@351
   519
	actionListBranches.append(a);
insilmaril@394
   520
	actionEditAddBranchBefore=a;
insilmaril@395
   521
	a = new QAction(tr( "Add branch (insert)","Edit menu" ),this);
insilmaril@366
   522
	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
insilmaril@442
   523
	a->setShortcut ( Qt::ALT + Qt::Key_A );			//Insert branch
insilmaril@366
   524
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   525
	addAction (a);
insilmaril@394
   526
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
insilmaril@351
   527
	actionListBranches.append(a);
insilmaril@351
   528
insilmaril@351
   529
	// Add branch above
insilmaril@395
   530
    a = new QAction(tr( "Add branch above","Edit menu" ), this);
insilmaril@366
   531
	a->setStatusTip ( tr( "Add a branch above selection" ));
insilmaril@442
   532
	a->setShortcut (Qt::SHIFT+Qt::Key_Insert );		//Add branch above
insilmaril@366
   533
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   534
	addAction (a);
insilmaril@366
   535
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
insilmaril@351
   536
	a->setEnabled (false);
insilmaril@351
   537
	actionListBranches.append(a);
insilmaril@351
   538
	actionEditAddBranchAbove=a;
insilmaril@395
   539
    a = new QAction(tr( "Add branch above","Edit menu" ), this);
insilmaril@366
   540
	a->setStatusTip ( tr( "Add a branch above selection" ));
insilmaril@442
   541
	a->setShortcut (Qt::SHIFT+Qt::Key_A );			//Add branch above
insilmaril@366
   542
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   543
	addAction (a);
insilmaril@366
   544
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
insilmaril@351
   545
	actionListBranches.append(a);
insilmaril@351
   546
insilmaril@351
   547
	// Add branch below 
insilmaril@395
   548
    a = new QAction(tr( "Add branch below","Edit menu" ), this);
insilmaril@366
   549
	a->setStatusTip ( tr( "Add a branch below selection" ));
insilmaril@442
   550
	a->setShortcut (Qt::CTRL +Qt::Key_Insert );		//Add branch below
insilmaril@366
   551
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   552
	addAction (a);
insilmaril@366
   553
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
insilmaril@351
   554
	a->setEnabled (false);
insilmaril@351
   555
	actionListBranches.append(a);
insilmaril@351
   556
	actionEditAddBranchBelow=a;
insilmaril@395
   557
    a = new QAction(tr( "Add branch below","Edit menu" ), this);
insilmaril@366
   558
	a->setStatusTip ( tr( "Add a branch below selection" ));
insilmaril@442
   559
	a->setShortcut (Qt::CTRL +Qt::Key_A );			// Add branch below
insilmaril@366
   560
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   561
	addAction (a);
insilmaril@366
   562
    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
insilmaril@351
   563
	actionListBranches.append(a);
insilmaril@351
   564
insilmaril@395
   565
    a = new QAction(QPixmap(iconPath+"up.png" ), tr( "Move up","Edit menu" ), this);
insilmaril@366
   566
	a->setStatusTip ( tr( "Move branch up" ) );
insilmaril@442
   567
	a->setShortcut (Qt::Key_PageUp );				// Move branch up
insilmaril@0
   568
	a->setEnabled (false);
insilmaril@366
   569
    tb->addAction (a);
insilmaril@366
   570
	editMenu->addAction (a);
insilmaril@366
   571
    connect( a, SIGNAL( triggered() ), this, SLOT( editMoveUp() ) );
insilmaril@0
   572
	actionEditMoveUp=a;
insilmaril@98
   573
insilmaril@395
   574
    a = new QAction( QPixmap( iconPath+"down.png"), tr( "Move down","Edit menu" ),this);
insilmaril@366
   575
    connect( a, SIGNAL( triggered() ), this, SLOT( editMoveDown() ) );
insilmaril@366
   576
	a->setStatusTip (tr( "Move branch down" ) );
insilmaril@442
   577
	a->setShortcut ( Qt::Key_PageDown );			// Move branch down
insilmaril@0
   578
	a->setEnabled (false);
insilmaril@366
   579
    tb->addAction (a);
insilmaril@366
   580
	editMenu->addAction (a);
insilmaril@0
   581
	actionEditMoveDown=a;
insilmaril@98
   582
	
insilmaril@0
   583
insilmaril@395
   584
	a = new QAction( QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ),this);
insilmaril@366
   585
	a->setShortcut ( Qt::Key_ScrollLock );
insilmaril@366
   586
	a->setStatusTip (tr( "Scroll branch" ) );
insilmaril@366
   587
    connect( a, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
insilmaril@375
   588
insilmaril@395
   589
	alt = new QAction( QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ), this);
insilmaril@442
   590
	alt->setShortcut ( Qt::Key_S );					// Scroll branch
insilmaril@366
   591
	alt->setStatusTip (tr( "Scroll branch" )); 
insilmaril@366
   592
    connect( alt, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
insilmaril@102
   593
	#if defined(Q_OS_MACX)
insilmaril@102
   594
		actionEditToggleScroll=alt;
insilmaril@102
   595
	#else	
insilmaril@102
   596
		actionEditToggleScroll=a;
insilmaril@102
   597
	#endif	
insilmaril@102
   598
	actionEditToggleScroll->setEnabled (false);
insilmaril@250
   599
	actionEditToggleScroll->setToggleAction(true);
insilmaril@366
   600
    tb->addAction (actionEditToggleScroll);
insilmaril@366
   601
    editMenu->addAction ( actionEditToggleScroll);
insilmaril@366
   602
	editMenu->addAction (actionEditToggleScroll);
insilmaril@375
   603
	addAction (a);
insilmaril@375
   604
	addAction (alt);
insilmaril@102
   605
	actionListBranches.append(actionEditToggleScroll);
insilmaril@0
   606
	
insilmaril@473
   607
    a = new QAction( tr( "Unscroll childs","Edit menu" ), this);
insilmaril@473
   608
	a->setStatusTip (tr( "Unscroll all scrolled branches in selected subtree" ));
insilmaril@366
   609
	editMenu->addAction (a);
insilmaril@473
   610
    connect( a, SIGNAL( triggered() ), this, SLOT( editUnscrollChilds() ) );
insilmaril@0
   611
	
insilmaril@366
   612
	editMenu->addSeparator();
insilmaril@366
   613
insilmaril@395
   614
	a = new QAction( QPixmap(iconPath+"find.png"), tr( "Find...","Edit menu"), this);
insilmaril@366
   615
	a->setStatusTip (tr( "Find" ) );
insilmaril@442
   616
	a->setShortcut (Qt::CTRL + Qt::Key_F );				//Find
insilmaril@366
   617
	editMenu->addAction (a);
insilmaril@366
   618
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenFindWindow() ) );
insilmaril@0
   619
    
insilmaril@366
   620
	editMenu->addSeparator();
insilmaril@366
   621
insilmaril@395
   622
	a = new QAction( QPixmap(flagsPath+"flag-url.png"), tr( "Open URL","Edit menu" ), this);
insilmaril@366
   623
	a->setShortcut (Qt::CTRL + Qt::Key_U );
insilmaril@366
   624
	a->setShortcut (tr( "Open URL" ));
insilmaril@366
   625
    tb->addAction (a);
insilmaril@366
   626
	addAction(a);
insilmaril@366
   627
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURL() ) );
insilmaril@0
   628
	actionEditOpenURL=a;
insilmaril@0
   629
insilmaril@395
   630
	a = new QAction( tr( "Open URL in new tab","Edit menu" ), this);
insilmaril@366
   631
	a->setStatusTip (tr( "Open URL in new tab" ));
insilmaril@528
   632
	//a->setShortcut (Qt::CTRL+Qt::Key_U );
insilmaril@366
   633
	addAction(a);
insilmaril@366
   634
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURLTab() ) );
insilmaril@266
   635
	actionEditOpenURLTab=a;
insilmaril@266
   636
insilmaril@395
   637
	a = new QAction( tr( "Open all URLs in subtree","Edit menu" ), this);
insilmaril@366
   638
	a->setStatusTip (tr( "Open all URLs in subtree" ));
insilmaril@366
   639
	addAction(a);
insilmaril@366
   640
	actionListBranches.append(a);
insilmaril@366
   641
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
insilmaril@366
   642
	actionEditOpenMultipleURLTabs=a;
insilmaril@366
   643
insilmaril@395
   644
	a = new QAction(QPixmap(), tr( "Edit URL...","Edit menu"), this);
insilmaril@366
   645
	a->setStatusTip ( tr( "Edit URL" ) );
insilmaril@528
   646
	//a->setShortcut (Qt::SHIFT + Qt::CTRL + Qt::Key_U );
insilmaril@528
   647
	a->setShortcut ( Qt::Key_U );
insilmaril@366
   648
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   649
	actionListBranches.append(a);
insilmaril@366
   650
	addAction(a);
insilmaril@366
   651
    connect( a, SIGNAL( triggered() ), this, SLOT( editURL() ) );
insilmaril@366
   652
	actionEditURL=a;
insilmaril@366
   653
	
insilmaril@528
   654
	a = new QAction(QPixmap(), tr( "Edit local URL...","Edit menu"), this);
insilmaril@528
   655
	a->setStatusTip ( tr( "Edit local URL" ) );
insilmaril@528
   656
	a->setShortcut (Qt::SHIFT +  Qt::Key_U );
insilmaril@528
   657
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@528
   658
	actionListBranches.append(a);
insilmaril@528
   659
	addAction(a);
insilmaril@528
   660
    connect( a, SIGNAL( triggered() ), this, SLOT( editLocalURL() ) );
insilmaril@528
   661
	actionEditURL=a;
insilmaril@528
   662
	
insilmaril@395
   663
	a = new QAction( tr( "Use heading for URL","Edit menu" ), this);
insilmaril@366
   664
	a->setStatusTip ( tr( "Use heading of selected branch as URL" ));
insilmaril@0
   665
	a->setEnabled (false);
insilmaril@98
   666
	actionListBranches.append(a);
insilmaril@366
   667
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading2URL() ) );
insilmaril@366
   668
	actionEditHeading2URL=a;
insilmaril@366
   669
    
insilmaril@486
   670
	a = new QAction(tr( "Create URL to Novell Bugzilla","Edit menu" ), this);
insilmaril@486
   671
	a->setStatusTip ( tr( "Create URL to Novell Bugzilla" ));
insilmaril@0
   672
	a->setEnabled (false);
insilmaril@98
   673
	actionListBranches.append(a);
insilmaril@366
   674
    connect( a, SIGNAL( triggered() ), this, SLOT( editBugzilla2URL() ) );
insilmaril@366
   675
	actionEditBugzilla2URL=a;
insilmaril@0
   676
    
insilmaril@486
   677
	a = new QAction(tr( "Create URL to Novell FATE","Edit menu" ), this);
insilmaril@486
   678
	a->setStatusTip ( tr( "Create URL to Novell FATE" ));
insilmaril@0
   679
	a->setEnabled (false);
insilmaril@98
   680
	actionListBranches.append(a);
insilmaril@366
   681
    connect( a, SIGNAL( triggered() ), this, SLOT( editFATE2URL() ) );
insilmaril@366
   682
	actionEditFATE2URL=a;
insilmaril@366
   683
	
insilmaril@395
   684
    a = new QAction(QPixmap(flagsPath+"flag-vymlink.png"), tr( "Open linked map","Edit menu" ), this);
insilmaril@366
   685
	a->setStatusTip ( tr( "Jump to another vym map, if needed load it first" ));
insilmaril@366
   686
    tb->addAction (a);
insilmaril@366
   687
	a->setEnabled (false);
insilmaril@366
   688
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenVymLink() ) );
insilmaril@366
   689
	actionEditOpenVymLink=a;
insilmaril@366
   690
	
insilmaril@395
   691
    a = new QAction(QPixmap(), tr( "Open all vym links in subtree","Edit menu" ), this);
insilmaril@366
   692
	a->setStatusTip ( tr( "Open all vym links in subtree" ));
insilmaril@175
   693
	a->setEnabled (false);
insilmaril@175
   694
	actionListBranches.append(a);
insilmaril@366
   695
    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVymLinks() ) );
insilmaril@366
   696
	actionEditOpenMultipleVymLinks=a;
insilmaril@0
   697
	
insilmaril@366
   698
insilmaril@395
   699
    a = new QAction(tr( "Edit vym link...","Edit menu" ), this);
insilmaril@0
   700
	a->setEnabled (false);
insilmaril@366
   701
	a->setStatusTip ( tr( "Edit link to another vym map" ));
insilmaril@366
   702
    connect( a, SIGNAL( triggered() ), this, SLOT( editVymLink() ) );
insilmaril@98
   703
	actionListBranches.append(a);
insilmaril@0
   704
	actionEditVymLink=a;
insilmaril@0
   705
insilmaril@395
   706
    a = new QAction(tr( "Delete vym link","Edit menu" ),this);
insilmaril@366
   707
	a->setStatusTip ( tr( "Delete link to another vym map" ));
insilmaril@0
   708
	a->setEnabled (false);
insilmaril@366
   709
    connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteVymLink() ) );
insilmaril@0
   710
	actionEditDeleteVymLink=a;
insilmaril@0
   711
insilmaril@395
   712
    a = new QAction(QPixmap(flagsPath+"flag-hideexport.png"), tr( "Hide in exports","Edit menu" ), this);
insilmaril@366
   713
	a->setStatusTip ( tr( "Hide object in exports" ) );
insilmaril@366
   714
	a->setShortcut (Qt::Key_H );
insilmaril@243
   715
	a->setToggleAction(true);
insilmaril@366
   716
    tb->addAction (a);
insilmaril@243
   717
	a->setEnabled (false);
insilmaril@366
   718
    connect( a, SIGNAL( triggered() ), this, SLOT( editToggleHideExport() ) );
insilmaril@243
   719
	actionEditToggleHideExport=a;
insilmaril@243
   720
insilmaril@395
   721
    a = new QAction(tr( "Edit Map Info...","Edit menu" ),this);
insilmaril@366
   722
	a->setStatusTip ( tr( "Edit Map Info" ));
insilmaril@0
   723
	a->setEnabled (true);
insilmaril@366
   724
    connect( a, SIGNAL( triggered() ), this, SLOT( editMapInfo() ) );
insilmaril@0
   725
	actionEditMapInfo=a;
insilmaril@0
   726
insilmaril@0
   727
	// Import at selection (adding to selection)
insilmaril@395
   728
    a = new QAction( tr( "Add map (insert)","Edit menu" ),this);
insilmaril@366
   729
	a->setStatusTip (tr( "Add map at selection" ));
insilmaril@366
   730
    connect( a, SIGNAL( triggered() ), this, SLOT( editImportAdd() ) );
insilmaril@0
   731
	a->setEnabled (false);
insilmaril@98
   732
	actionListBranches.append(a);
insilmaril@0
   733
	actionEditImportAdd=a;
insilmaril@0
   734
insilmaril@0
   735
	// Import at selection (replacing selection)
insilmaril@395
   736
    a = new QAction( tr( "Add map (replace)","Edit menu" ), this);
insilmaril@366
   737
	a->setStatusTip (tr( "Replace selection with map" ));
insilmaril@366
   738
    connect( a, SIGNAL( triggered() ), this, SLOT( editImportReplace() ) );
insilmaril@0
   739
	a->setEnabled (false);
insilmaril@98
   740
	actionListBranches.append(a);
insilmaril@0
   741
	actionEditImportReplace=a;
insilmaril@0
   742
insilmaril@0
   743
	// Save selection 
insilmaril@395
   744
    a = new QAction( tr( "Save selection","Edit menu" ), this);
insilmaril@366
   745
	a->setStatusTip (tr( "Save selection" ));
insilmaril@366
   746
    connect( a, SIGNAL( triggered() ), this, SLOT( editSaveBranch() ) );
insilmaril@0
   747
	a->setEnabled (false);
insilmaril@98
   748
	actionListBranches.append(a);
insilmaril@0
   749
	actionEditSaveBranch=a;
insilmaril@0
   750
insilmaril@98
   751
	// Only remove branch, not its childs
insilmaril@395
   752
    a = new QAction(tr( "Remove only branch ","Edit menu" ), this);
insilmaril@366
   753
	a->setStatusTip ( tr( "Remove only branch and keep its childs" ));
insilmaril@366
   754
	a->setShortcut (Qt::ALT + Qt::Key_Delete );
insilmaril@395
   755
    connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteKeepChilds() ) );
insilmaril@98
   756
	a->setEnabled (false);
insilmaril@375
   757
	addAction (a);
insilmaril@98
   758
	actionListBranches.append(a);
insilmaril@395
   759
	actionEditDeleteKeepChilds=a;
insilmaril@98
   760
insilmaril@98
   761
	// Only remove childs of a branch
insilmaril@395
   762
    a = new QAction( tr( "Remove childs","Edit menu" ), this);
insilmaril@366
   763
	a->setStatusTip (tr( "Remove childs of branch" ));
insilmaril@366
   764
	a->setShortcut (Qt::SHIFT + Qt::Key_Delete );
insilmaril@395
   765
    connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteChilds() ) );
insilmaril@98
   766
	a->setEnabled (false);
insilmaril@98
   767
	actionListBranches.append(a);
insilmaril@395
   768
	actionEditDeleteChilds=a;
insilmaril@98
   769
insilmaril@0
   770
    // Shortcuts for navigating with cursor:
insilmaril@395
   771
    a = new QAction(tr( "Select upper branch","Edit menu" ), this);
insilmaril@366
   772
	a->setStatusTip ( tr( "Select upper branch" ));
insilmaril@366
   773
	a->setShortcut (Qt::Key_Up );
insilmaril@366
   774
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   775
	addAction (a);
insilmaril@366
   776
    connect( a, SIGNAL( triggered() ), this, SLOT( editUpperBranch() ) );
insilmaril@395
   777
    a = new QAction( tr( "Select lower branch","Edit menu" ),this);
insilmaril@366
   778
	a->setStatusTip (tr( "Select lower branch" ));
insilmaril@366
   779
	a->setShortcut ( Qt::Key_Down );
insilmaril@366
   780
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   781
	addAction (a);
insilmaril@366
   782
    connect( a, SIGNAL( triggered() ), this, SLOT( editLowerBranch() ) );
insilmaril@395
   783
    a = new QAction(tr( "Select left branch","Edit menu" ), this);
insilmaril@366
   784
	a->setStatusTip ( tr( "Select left branch" ));
insilmaril@366
   785
	a->setShortcut (Qt::Key_Left );
insilmaril@366
   786
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   787
	addAction (a);
insilmaril@366
   788
    connect( a, SIGNAL( triggered() ), this, SLOT( editLeftBranch() ) );
insilmaril@395
   789
    a = new QAction( tr( "Select child branch","Edit menu" ), this);
insilmaril@366
   790
	a->setStatusTip (tr( "Select right branch" ));
insilmaril@366
   791
	a->setShortcut (Qt::Key_Right);
insilmaril@366
   792
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   793
	addAction (a);
insilmaril@366
   794
    connect( a, SIGNAL( triggered() ), this, SLOT( editRightBranch() ) );
insilmaril@395
   795
    a = new QAction( tr( "Select first branch","Edit menu" ), this);
insilmaril@366
   796
	a->setStatusTip (tr( "Select first branch" ));
insilmaril@366
   797
	a->setShortcut (Qt::Key_Home );
insilmaril@366
   798
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   799
	addAction (a);
insilmaril@0
   800
	a->setEnabled (false);
insilmaril@366
   801
	editMenu->addAction (a);
insilmaril@98
   802
	actionListBranches.append(a);
insilmaril@0
   803
	actionEditSelectFirst=a;
insilmaril@366
   804
    connect( a, SIGNAL( triggered() ), this, SLOT( editFirstBranch() ) );
insilmaril@395
   805
    a = new QAction( tr( "Select last branch","Edit menu" ),this);
insilmaril@366
   806
	a->setStatusTip (tr( "Select last branch" ));
insilmaril@366
   807
	a->setShortcut ( Qt::Key_End );
insilmaril@366
   808
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@366
   809
	addAction (a);
insilmaril@366
   810
    connect( a, SIGNAL( triggered() ), this, SLOT( editLastBranch() ) );
insilmaril@0
   811
	a->setEnabled (false);
insilmaril@366
   812
	editMenu->addAction (a);
insilmaril@98
   813
	actionListBranches.append(a);
insilmaril@0
   814
	actionEditSelectLast=a;
insilmaril@0
   815
insilmaril@395
   816
    a = new QAction( tr( "Add Image...","Edit menu" ), this);
insilmaril@366
   817
	a->setStatusTip (tr( "Add Image" ));
insilmaril@366
   818
    connect( a, SIGNAL( triggered() ), this, SLOT( editLoadImage() ) );
insilmaril@0
   819
	actionEditLoadImage=a;
insilmaril@89
   820
insilmaril@473
   821
    a = new QAction( tr( "Property window","Dialog to edit properties of selection" )+QString ("..."), this);
insilmaril@442
   822
	a->setStatusTip (tr( "Set properties for selection" ));
insilmaril@442
   823
	a->setShortcut ( Qt::CTRL + Qt::Key_I );		//Property window
insilmaril@442
   824
	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@486
   825
	a->setToggleAction (true);
insilmaril@442
   826
	addAction (a);
insilmaril@473
   827
    connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleProperty() ) );
insilmaril@486
   828
	actionViewTogglePropertyWindow=a;
insilmaril@0
   829
}
insilmaril@0
   830
insilmaril@0
   831
// Format Actions
insilmaril@0
   832
void Main::setupFormatActions()
insilmaril@0
   833
{
insilmaril@395
   834
    QMenu *formatMenu = menuBar()->addMenu (tr ("F&ormat","Format menu"));
insilmaril@395
   835
insilmaril@395
   836
    QToolBar *tb = addToolBar( tr("Format Actions","Format Toolbar name"));
insilmaril@366
   837
	tb->setObjectName ("formatTB");
insilmaril@0
   838
    QAction *a;
insilmaril@0
   839
    QPixmap pix( 16,16);
insilmaril@366
   840
    pix.fill (Qt::black);
insilmaril@366
   841
    a= new QAction(pix, tr( "Set &Color" )+QString("..."), this);
insilmaril@366
   842
	a->setStatusTip ( tr( "Set Color" ));
insilmaril@366
   843
    connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectColor() ) );
insilmaril@366
   844
    a->addTo( tb );
insilmaril@366
   845
	formatMenu->addAction (a);
insilmaril@366
   846
	actionFormatColor=a;
insilmaril@395
   847
    a= new QAction( QPixmap(iconPath+"formatcolorpicker.png"), tr( "Pic&k color","Edit menu" ), this);
insilmaril@366
   848
	a->setStatusTip (tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ) );
insilmaril@366
   849
	a->setShortcut (Qt::CTRL + Qt::Key_K );
insilmaril@366
   850
    connect( a, SIGNAL( triggered() ), this, SLOT( formatPickColor() ) );
insilmaril@0
   851
	a->setEnabled (false);
insilmaril@0
   852
    a->addTo( tb );
insilmaril@366
   853
	formatMenu->addAction (a);
insilmaril@98
   854
	actionListBranches.append(a);
insilmaril@0
   855
	actionFormatPickColor=a;
insilmaril@366
   856
insilmaril@417
   857
    a= new QAction(QPixmap(iconPath+"formatcolorbranch.png"), tr( "Color &branch","Edit menu" ), this);
insilmaril@366
   858
	a->setStatusTip ( tr( "Color branch" ) );
insilmaril@442
   859
	a->setShortcut (Qt::CTRL + Qt::Key_B);
insilmaril@417
   860
    connect( a, SIGNAL( triggered() ), this, SLOT( formatColorBranch() ) );
insilmaril@0
   861
	a->setEnabled (false);
insilmaril@0
   862
    a->addTo( tb );
insilmaril@366
   863
	formatMenu->addAction (a);
insilmaril@98
   864
	actionListBranches.append(a);
insilmaril@417
   865
	actionFormatColorSubtree=a;
insilmaril@417
   866
insilmaril@417
   867
    a= new QAction(QPixmap(iconPath+"formatcolorsubtree.png"), tr( "Color sub&tree","Edit menu" ), this);
insilmaril@366
   868
	a->setStatusTip ( tr( "Color Subtree" ));
insilmaril@366
   869
	a->setShortcut (Qt::CTRL + Qt::Key_T);
insilmaril@417
   870
    connect( a, SIGNAL( triggered() ), this, SLOT( formatColorSubtree() ) );
insilmaril@0
   871
	a->setEnabled (false);
insilmaril@366
   872
	formatMenu->addAction (a);
insilmaril@0
   873
    a->addTo( tb );
insilmaril@98
   874
	actionListBranches.append(a);
insilmaril@0
   875
	actionFormatColorSubtree=a;
insilmaril@0
   876
insilmaril@366
   877
	formatMenu->addSeparator();
insilmaril@366
   878
	actionGroupFormatLinkStyles=new QActionGroup ( this);
insilmaril@0
   879
	actionGroupFormatLinkStyles->setExclusive (true);
insilmaril@366
   880
    a= new QAction( tr( "Linkstyle Line" ), actionGroupFormatLinkStyles);
insilmaril@366
   881
	a->setStatusTip (tr( "Line" ));
insilmaril@0
   882
	a->setToggleAction(true);
insilmaril@366
   883
    connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleLine() ) );
insilmaril@366
   884
	formatMenu->addAction (a);
insilmaril@0
   885
	actionFormatLinkStyleLine=a;
insilmaril@505
   886
    a= new QAction( tr( "Linkstyle Curve" ), actionGroupFormatLinkStyles);
insilmaril@366
   887
	a->setStatusTip (tr( "Line" ));
insilmaril@0
   888
	a->setToggleAction(true);
insilmaril@366
   889
    connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleParabel() ) );
insilmaril@366
   890
	formatMenu->addAction (a);
insilmaril@0
   891
	actionFormatLinkStyleParabel=a;
insilmaril@366
   892
    a= new QAction( tr( "Linkstyle Thick Line" ), actionGroupFormatLinkStyles );
insilmaril@366
   893
	a->setStatusTip (tr( "PolyLine" ));
insilmaril@0
   894
	a->setToggleAction(true);
insilmaril@366
   895
    connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyLine() ) );
insilmaril@366
   896
	formatMenu->addAction (a);
insilmaril@0
   897
	actionFormatLinkStylePolyLine=a;
insilmaril@505
   898
    a= new QAction( tr( "Linkstyle Thick Curve" ), actionGroupFormatLinkStyles);
insilmaril@366
   899
	a->setStatusTip (tr( "PolyParabel" ) );
insilmaril@0
   900
	a->setToggleAction(true);
insilmaril@366
   901
	a->setChecked (true);
insilmaril@366
   902
    connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyParabel() ) );
insilmaril@366
   903
	formatMenu->addAction (a);
insilmaril@0
   904
	actionFormatLinkStylePolyParabel=a;
insilmaril@0
   905
	
insilmaril@395
   906
    a = new QAction( tr( "Hide link if object is not selected","Branch attribute" ), this);
insilmaril@366
   907
	a->setStatusTip (tr( "Hide link" ));
insilmaril@160
   908
	a->setToggleAction(true);
insilmaril@366
   909
    connect( a, SIGNAL( triggered() ), this, SLOT( formatHideLinkUnselected() ) );
insilmaril@160
   910
	actionFormatHideLinkUnselected=a;
insilmaril@160
   911
insilmaril@366
   912
	formatMenu->addSeparator();
insilmaril@395
   913
    a= new QAction( tr( "&Use color of heading for link","Branch attribute" ),  this);
insilmaril@366
   914
	a->setStatusTip (tr( "Use same color for links and headings" ));
insilmaril@0
   915
	a->setToggleAction(true);
insilmaril@366
   916
    connect( a, SIGNAL( triggered() ), this, SLOT( formatToggleLinkColorHint() ) );
insilmaril@366
   917
	formatMenu->addAction (a);
insilmaril@0
   918
	actionFormatLinkColorHint=a;
insilmaril@366
   919
insilmaril@366
   920
    pix.fill (Qt::white);
insilmaril@366
   921
    a= new QAction( pix, tr( "Set &Link Color"+QString("...") ), this  );
insilmaril@366
   922
	a->setStatusTip (tr( "Set Link Color" ));
insilmaril@366
   923
	formatMenu->addAction (a);
insilmaril@366
   924
    connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectLinkColor() ) );
insilmaril@366
   925
    actionFormatLinkColor=a;
insilmaril@366
   926
insilmaril@442
   927
    a= new QAction( pix, tr( "Set &Selection Color"+QString("...") ), this  );
insilmaril@442
   928
	a->setStatusTip (tr( "Set Selection Color" ));
insilmaril@442
   929
	formatMenu->addAction (a);
insilmaril@442
   930
    connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectSelectionColor() ) );
insilmaril@442
   931
    actionFormatSelectionColor=a;
insilmaril@442
   932
insilmaril@366
   933
    a= new QAction( pix, tr( "Set &Background Color" )+QString("..."), this );
insilmaril@366
   934
	a->setStatusTip (tr( "Set Background Color" ));
insilmaril@366
   935
	formatMenu->addAction (a);
insilmaril@366
   936
    connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackColor() ) );
insilmaril@366
   937
    actionFormatBackColor=a;
insilmaril@408
   938
insilmaril@408
   939
    a= new QAction( pix, tr( "Set &Background image" )+QString("..."), this );
insilmaril@408
   940
	a->setStatusTip (tr( "Set Background image" ));
insilmaril@408
   941
	formatMenu->addAction (a);
insilmaril@408
   942
    connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackImage() ) );
insilmaril@408
   943
    actionFormatBackImage=a;
insilmaril@0
   944
}
insilmaril@0
   945
insilmaril@0
   946
// View Actions
insilmaril@0
   947
void Main::setupViewActions()
insilmaril@0
   948
{
insilmaril@395
   949
    QToolBar *tb = addToolBar( tr("View Actions","View Toolbar name") );
insilmaril@0
   950
    tb->setLabel( "View Actions" );
insilmaril@366
   951
	tb->setObjectName ("viewTB");
insilmaril@366
   952
    QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" ));
insilmaril@0
   953
insilmaril@0
   954
    QAction *a;
insilmaril@395
   955
    a = new QAction(QPixmap(iconPath+"viewmag-reset.png"), tr( "reset Zoom","View action" ), this);
insilmaril@366
   956
	a->setStatusTip ( tr( "Zoom reset" ) );
insilmaril@366
   957
	a->setShortcut (Qt::CTRL + Qt::Key_0 );
insilmaril@0
   958
    a->addTo( tb );
insilmaril@366
   959
	viewMenu->addAction (a);
insilmaril@366
   960
    connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomReset() ) );
insilmaril@366
   961
	
insilmaril@395
   962
    a = new QAction( QPixmap(iconPath+"viewmag+.png"), tr( "Zoom in","View action" ), this);
insilmaril@366
   963
	a->setStatusTip (tr( "Zoom in" ));
insilmaril@366
   964
	a->setShortcut (Qt::CTRL + Qt::Key_Plus);
insilmaril@0
   965
    a->addTo( tb );
insilmaril@366
   966
	viewMenu->addAction (a);
insilmaril@366
   967
    connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomIn() ) );
insilmaril@366
   968
	
insilmaril@395
   969
    a = new QAction( QPixmap(iconPath+"viewmag-.png"), tr( "Zoom out","View action" ), this);
insilmaril@366
   970
	a->setStatusTip (tr( "Zoom out" ));
insilmaril@366
   971
	a->setShortcut (Qt::CTRL + Qt::Key_Minus );
insilmaril@0
   972
    a->addTo( tb );
insilmaril@366
   973
	viewMenu->addAction (a);
insilmaril@366
   974
    connect( a, SIGNAL( triggered() ), this, SLOT( viewZoomOut() ) );
insilmaril@366
   975
insilmaril@526
   976
    a = new QAction( QPixmap(iconPath+"viewshowsel.png"), tr( "Show selection","View action" ), this);
insilmaril@526
   977
	a->setStatusTip (tr( "Show selection" ));
insilmaril@526
   978
	a->setShortcut (Qt::Key_Period);
insilmaril@526
   979
    a->addTo( tb );
insilmaril@526
   980
	viewMenu->addAction (a);
insilmaril@526
   981
    connect( a, SIGNAL( triggered() ), this, SLOT( viewCenter() ) );
insilmaril@526
   982
insilmaril@486
   983
	viewMenu->addSeparator();	
insilmaril@366
   984
insilmaril@395
   985
    a = new QAction(QPixmap(flagsPath+"flag-note.png"), tr( "Show Note Editor","View action" ),this);
insilmaril@366
   986
	a->setStatusTip ( tr( "Show Note Editor" ));
insilmaril@366
   987
	a->setShortcut ( Qt::CTRL + Qt::Key_E );
insilmaril@0
   988
	a->setToggleAction(true);
insilmaril@0
   989
    a->addTo( tb );
insilmaril@366
   990
	viewMenu->addAction (a);
insilmaril@366
   991
    connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleNoteEditor() ) );
insilmaril@0
   992
	actionViewToggleNoteEditor=a;
insilmaril@294
   993
insilmaril@442
   994
    a = new QAction(QPixmap(iconPath+"history.png"),  tr( "History Window","View action" ),this );
insilmaril@442
   995
	a->setStatusTip ( tr( "Show History Window" ));
insilmaril@366
   996
	a->setShortcut ( Qt::CTRL + Qt::Key_H  );
insilmaril@407
   997
	a->setToggleAction(true);
insilmaril@404
   998
    a->addTo( tb );
insilmaril@366
   999
	viewMenu->addAction (a);
insilmaril@366
  1000
    connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHistory() ) );
insilmaril@294
  1001
	actionViewToggleHistoryWindow=a;
insilmaril@294
  1002
insilmaril@486
  1003
	viewMenu->addAction (actionViewTogglePropertyWindow);
insilmaril@486
  1004
insilmaril@486
  1005
	viewMenu->addSeparator();	
insilmaril@442
  1006
insilmaril@408
  1007
    a = new QAction(tr( "Antialiasing","View action" ),this );
insilmaril@408
  1008
	a->setStatusTip ( tr( "Antialiasing" ));
insilmaril@408
  1009
	a->setToggleAction(true);
insilmaril@408
  1010
	a->setOn (settings.value("/mainwindow/view/AntiAlias",true).toBool());
insilmaril@408
  1011
	viewMenu->addAction (a);
insilmaril@408
  1012
    connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleAntiAlias() ) );
insilmaril@408
  1013
	actionViewToggleAntiAlias=a;
insilmaril@408
  1014
insilmaril@408
  1015
    a = new QAction(tr( "Smooth pixmap transformations","View action" ),this );
insilmaril@408
  1016
	a->setStatusTip (a->text());
insilmaril@408
  1017
	a->setToggleAction(true);
insilmaril@408
  1018
	a->setOn (settings.value("/mainwindow/view/SmoothPixmapTransformation",true).toBool());
insilmaril@408
  1019
	viewMenu->addAction (a);
insilmaril@408
  1020
    connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSmoothPixmap() ) );
insilmaril@408
  1021
	actionViewToggleSmoothPixmapTransform=a;
insilmaril@408
  1022
insilmaril@473
  1023
    a = new QAction(tr( "Next Map","View action" ), this);
insilmaril@408
  1024
	a->setStatusTip (a->text());
insilmaril@366
  1025
	a->setShortcut (Qt::ALT + Qt::Key_N );
insilmaril@366
  1026
	viewMenu->addAction (a);
insilmaril@366
  1027
    connect( a, SIGNAL( triggered() ), this, SLOT(windowNextEditor() ) );
insilmaril@366
  1028
insilmaril@473
  1029
    a = new QAction (tr( "Previous Map","View action" ), this );
insilmaril@408
  1030
	a->setStatusTip (a->text());
insilmaril@366
  1031
	a->setShortcut (Qt::ALT + Qt::Key_P );
insilmaril@366
  1032
	viewMenu->addAction (a);
insilmaril@366
  1033
    connect( a, SIGNAL( triggered() ), this, SLOT(windowPreviousEditor() ) );
insilmaril@0
  1034
}
insilmaril@0
  1035
insilmaril@89
  1036
// Mode Actions
insilmaril@89
  1037
void Main::setupModeActions()
insilmaril@89
  1038
{
insilmaril@89
  1039
    //QPopupMenu *menu = new QPopupMenu( this );
insilmaril@89
  1040
    //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
insilmaril@89
  1041
insilmaril@395
  1042
    QToolBar *tb = addToolBar( tr ("Modes when using modifiers","Modifier Toolbar name") );
insilmaril@366
  1043
	tb->setObjectName ("modesTB");
insilmaril@89
  1044
    QAction *a;
insilmaril@366
  1045
	actionGroupModModes=new QActionGroup ( this);
insilmaril@89
  1046
	actionGroupModModes->setExclusive (true);
insilmaril@395
  1047
    a= new QAction( QPixmap(iconPath+"modecolor.png"), tr( "Use modifier to color branches","Mode modifier" ), actionGroupModModes);
insilmaril@366
  1048
	a->setShortcut (Qt::Key_J);
insilmaril@366
  1049
    a->setStatusTip ( tr( "Use modifier to color branches" ));
insilmaril@89
  1050
	a->setToggleAction(true);
insilmaril@89
  1051
	a->addTo (tb);
insilmaril@89
  1052
	a->setOn(true);
insilmaril@89
  1053
	actionModModeColor=a;
insilmaril@104
  1054
	
insilmaril@395
  1055
    a= new QAction( QPixmap(iconPath+"modecopy.png"), tr( "Use modifier to copy","Mode modifier" ), actionGroupModModes );
insilmaril@366
  1056
	a->setShortcut( Qt::Key_K); 
insilmaril@366
  1057
    a->setStatusTip( tr( "Use modifier to copy" ));
insilmaril@104
  1058
	a->setToggleAction(true);
insilmaril@104
  1059
	a->addTo (tb);
insilmaril@104
  1060
	actionModModeCopy=a;
insilmaril@104
  1061
insilmaril@395
  1062
    a= new QAction(QPixmap(iconPath+"modelink.png"), tr( "Use modifier to draw xLinks","Mode modifier" ), actionGroupModModes );
insilmaril@366
  1063
	a->setShortcut (Qt::Key_L);
insilmaril@366
  1064
    a->setStatusTip( tr( "Use modifier to draw xLinks" ));
insilmaril@89
  1065
	a->setToggleAction(true);
insilmaril@89
  1066
	a->addTo (tb);
insilmaril@390
  1067
	actionModModeXLink=a;
insilmaril@89
  1068
}
insilmaril@89
  1069
insilmaril@0
  1070
// Flag Actions
insilmaril@0
  1071
void Main::setupFlagActions()
insilmaril@0
  1072
{
insilmaril@166
  1073
	// Create System Flags
insilmaril@582
  1074
	QToolBar *tb=NULL;
insilmaril@582
  1075
	bool avis=true;
insilmaril@582
  1076
insilmaril@166
  1077
	systemFlagsDefault = new FlagRowObj ();
insilmaril@166
  1078
	systemFlagsDefault->setVisibility (false);
insilmaril@166
  1079
	systemFlagsDefault->setName ("systemFlagsDef");
insilmaril@166
  1080
insilmaril@166
  1081
	FlagObj *fo = new FlagObj ();
insilmaril@269
  1082
	fo->load(QPixmap(flagsPath+"flag-note.png"));
insilmaril@582
  1083
	setupFlag (fo,tb,avis,"note",tr("Note","SystemFlag"));
insilmaril@166
  1084
insilmaril@269
  1085
	fo->load(QPixmap(flagsPath+"flag-url.png"));
insilmaril@582
  1086
	setupFlag (fo,tb,avis,"url",tr("URL to Document ","SystemFlag"));
insilmaril@166
  1087
	
insilmaril@269
  1088
	fo->load(QPixmap(flagsPath+"flag-vymlink.png"));
insilmaril@582
  1089
	setupFlag (fo,tb,avis,"vymLink",tr("Link to another vym map","SystemFlag"));
insilmaril@166
  1090
insilmaril@269
  1091
	fo->load(QPixmap(flagsPath+"flag-scrolled-right.png"));
insilmaril@582
  1092
	setupFlag (fo,tb,avis,"scrolledright",tr("subtree is scrolled","SystemFlag"));
insilmaril@166
  1093
	
insilmaril@269
  1094
	fo->load(QPixmap(flagsPath+"flag-tmpUnscrolled-right.png"));
insilmaril@582
  1095
	setupFlag (fo,tb,avis,"tmpUnscrolledright",tr("subtree is temporary scrolled","SystemFlag"));
insilmaril@166
  1096
insilmaril@269
  1097
	fo->load(QPixmap(flagsPath+"flag-hideexport.png"));
insilmaril@582
  1098
	setupFlag (fo,tb,avis,"hideInExport",tr("Hide object in exported maps","SystemFlag"));
insilmaril@243
  1099
insilmaril@166
  1100
	// Create Standard Flags
insilmaril@582
  1101
	tb=addToolBar (tr ("Standard Flags","Standard Flag Toolbar"));
insilmaril@366
  1102
	tb->setObjectName ("standardFlagTB");
insilmaril@366
  1103
insilmaril@166
  1104
	standardFlagsDefault = new FlagRowObj ();
insilmaril@166
  1105
	standardFlagsDefault->setVisibility (false);
insilmaril@166
  1106
	standardFlagsDefault->setName ("standardFlagsDef");
insilmaril@366
  1107
	standardFlagsDefault->setToolBar (tb);
insilmaril@166
  1108
insilmaril@408
  1109
	fo->load(flagsPath+"flag-exclamationmark.png");
insilmaril@166
  1110
	fo->setGroup("standard-mark");
insilmaril@582
  1111
	setupFlag (fo,tb,avis,"exclamationmark",tr("Take care!","Standardflag"));
insilmaril@166
  1112
	
insilmaril@408
  1113
	fo->load(flagsPath+"flag-questionmark.png");
insilmaril@166
  1114
	fo->setGroup("standard-mark");
insilmaril@582
  1115
	setupFlag (fo,tb,avis,"questionmark",tr("Really?","Standardflag"));
insilmaril@166
  1116
insilmaril@408
  1117
	fo->load(flagsPath+"flag-hook-green.png");
insilmaril@166
  1118
	fo->setGroup("standard-hook");
insilmaril@582
  1119
	setupFlag (fo,tb,avis,"hook-green",tr("ok!","Standardflag"));
insilmaril@166
  1120
insilmaril@408
  1121
	fo->load(flagsPath+"flag-cross-red.png");
insilmaril@166
  1122
	fo->setGroup("standard-hook");
insilmaril@582
  1123
	setupFlag (fo,tb,avis,"cross-red",tr("Not ok!","Standardflag"));
insilmaril@582
  1124
	fo->unsetGroup();
insilmaril@166
  1125
insilmaril@408
  1126
	fo->load(flagsPath+"flag-stopsign.png");
insilmaril@582
  1127
	setupFlag (fo,tb,avis,"stopsign",tr("This won't work!","Standardflag"));
insilmaril@166
  1128
insilmaril@408
  1129
	fo->load(flagsPath+"flag-smiley-good.png");
insilmaril@166
  1130
	fo->setGroup("standard-smiley");
insilmaril@582
  1131
	setupFlag (fo,tb,avis,"smiley-good",tr("Good","Standardflag"));
insilmaril@166
  1132
insilmaril@408
  1133
	fo->load(flagsPath+"flag-smiley-sad.png");
insilmaril@166
  1134
	fo->setGroup("standard-smiley");
insilmaril@166
  1135
insilmaril@408
  1136
	fo->load(flagsPath+"flag-smiley-omg.png");
insilmaril@582
  1137
	fo->setGroup("standard-smiley");
insilmaril@582
  1138
	setupFlag (fo,tb,avis,"smiley-omb",tr("Oh no!","Standardflag"));
insilmaril@269
  1139
	// Original omg.png (in KDE emoticons)
insilmaril@582
  1140
	fo->unsetGroup();
insilmaril@269
  1141
insilmaril@408
  1142
	fo->load(flagsPath+"flag-kalarm.png");
insilmaril@582
  1143
	setupFlag (fo,tb,avis,"clock",tr("Time critical","Standardflag"));
insilmaril@166
  1144
insilmaril@408
  1145
	fo->load(flagsPath+"flag-phone.png");
insilmaril@582
  1146
	setupFlag (fo,tb,avis,"phone",tr("Call...","Standardflag"));
insilmaril@269
  1147
insilmaril@408
  1148
	fo->load(flagsPath+"flag-lamp.png");
insilmaril@582
  1149
	setupFlag (fo,tb,avis,"lamp",tr("Idea!","Standardflag"));
insilmaril@166
  1150
insilmaril@408
  1151
	fo->load(flagsPath+"flag-arrow-up.png");
insilmaril@166
  1152
	fo->setGroup("standard-arrow");
insilmaril@582
  1153
	setupFlag (fo,tb,avis,"arrow-up",tr("Important","Standardflag"));
insilmaril@166
  1154
insilmaril@408
  1155
	fo->load(flagsPath+"flag-arrow-down.png");
insilmaril@166
  1156
	fo->setGroup("standard-arrow");
insilmaril@582
  1157
	setupFlag (fo,tb,avis,"arrow-down",tr("Unimportant","Standardflag"));
insilmaril@166
  1158
insilmaril@408
  1159
	fo->load(flagsPath+"flag-arrow-2up.png");
insilmaril@269
  1160
	fo->setGroup("standard-arrow");
insilmaril@582
  1161
	setupFlag (fo,tb,avis,"2arrow-up",tr("Very important!","Standardflag"));
insilmaril@269
  1162
insilmaril@408
  1163
	fo->load(flagsPath+"flag-arrow-2down.png");
insilmaril@269
  1164
	fo->setGroup("standard-arrow");
insilmaril@582
  1165
	setupFlag (fo,tb,avis,"present",tr("Very unimportant!","Standardflag"));
insilmaril@582
  1166
	fo->unsetGroup();
insilmaril@269
  1167
insilmaril@408
  1168
	fo->load(flagsPath+"flag-thumb-up.png");
insilmaril@166
  1169
	fo->setGroup("standard-thumb");
insilmaril@582
  1170
	setupFlag (fo,tb,avis,"thumb-up",tr("I like this","Standardflag"));
insilmaril@166
  1171
insilmaril@408
  1172
	fo->load(flagsPath+"flag-thumb-down.png");
insilmaril@166
  1173
	fo->setGroup("standard-thumb");
insilmaril@582
  1174
	setupFlag (fo,tb,avis,"thumb-down",tr("I do not like this","Standardflag"));
insilmaril@582
  1175
	fo->unsetGroup();
insilmaril@166
  1176
	
insilmaril@408
  1177
	fo->load(flagsPath+"flag-rose.png");
insilmaril@582
  1178
	setupFlag (fo,tb,avis,"rose",tr("Rose","Standardflag"));
insilmaril@269
  1179
insilmaril@408
  1180
	fo->load(flagsPath+"flag-heart.png");
insilmaril@582
  1181
	setupFlag (fo,tb,avis,"heart",tr("I just love...","Standardflag"));
insilmaril@564
  1182
insilmaril@408
  1183
	fo->load(flagsPath+"flag-present.png");
insilmaril@582
  1184
	setupFlag (fo,tb,avis,"present",tr("Surprise!","Standardflag"));
insilmaril@564
  1185
insilmaril@564
  1186
	fo->load(flagsPath+"flag-flash.png");
insilmaril@582
  1187
	setupFlag (fo,tb,avis,"flash",tr("Dangerous","Standardflag"));
insilmaril@564
  1188
	
insilmaril@564
  1189
	// Original: xsldbg_output.png
insilmaril@564
  1190
	fo->load(flagsPath+"flag-info.png");
insilmaril@582
  1191
	setupFlag (fo,tb,avis,"info",tr("Info","Standardflag"));
insilmaril@564
  1192
insilmaril@564
  1193
	// Original khelpcenter.png
insilmaril@564
  1194
	fo->load(flagsPath+"flag-lifebelt.png");
insilmaril@582
  1195
	setupFlag (fo,tb,avis,"lifebelt",tr("This will help","Standardflag"));
insilmaril@564
  1196
insilmaril@564
  1197
	// Freemind flags
insilmaril@564
  1198
insilmaril@582
  1199
	avis=false;
insilmaril@582
  1200
insilmaril@564
  1201
	fo->load(flagsPath+"freemind/warning.png");
insilmaril@582
  1202
	setupFlag (fo,tb, avis, "freemind-warning",tr("Important","Freemind-Flag"));
insilmaril@564
  1203
insilmaril@564
  1204
	for (int i=1; i<8; i++)
insilmaril@564
  1205
	{
insilmaril@564
  1206
		fo->load(flagsPath+QString("freemind/priority-%1.png").arg(i));
insilmaril@582
  1207
		setupFlag (fo,tb, avis,QString("freemind-priority-%1").arg(i),tr("Priority","Freemind-Flag"));
insilmaril@564
  1208
	}
insilmaril@564
  1209
insilmaril@564
  1210
	fo->load(flagsPath+"freemind/back.png");
insilmaril@582
  1211
	setupFlag (fo,tb,avis,"freemind-back",tr("Back","Freemind-Flag"));
insilmaril@564
  1212
insilmaril@564
  1213
	fo->load(flagsPath+"freemind/forward.png");
insilmaril@582
  1214
	setupFlag (fo,tb,avis,"freemind-forward",tr("Forward","Freemind-Flag"));
insilmaril@564
  1215
insilmaril@564
  1216
	fo->load(flagsPath+"freemind/attach.png");
insilmaril@582
  1217
	setupFlag (fo,tb,avis,"freemind-attach",tr("Look here","Freemind-Flag"));
insilmaril@564
  1218
insilmaril@564
  1219
	fo->load(flagsPath+"freemind/clanbomber.png");
insilmaril@582
  1220
	setupFlag (fo,tb,avis,"freemind-clanbomber",tr("Dangerous","Freemind-Flag"));
insilmaril@564
  1221
insilmaril@564
  1222
	fo->load(flagsPath+"freemind/desktopnew.png");
insilmaril@582
  1223
	setupFlag (fo,tb,avis,"freemind-desktopnew",tr("Don't forget","Freemind-Flag"));
insilmaril@564
  1224
insilmaril@564
  1225
	fo->load(flagsPath+"freemind/flag.png");
insilmaril@582
  1226
	setupFlag (fo,tb,avis,"freemind-flag",tr("Flag","Freemind-Flag"));
insilmaril@564
  1227
insilmaril@564
  1228
insilmaril@564
  1229
	fo->load(flagsPath+"freemind/gohome.png");
insilmaril@582
  1230
	setupFlag (fo,tb,avis,"freemind-gohome",tr("Home","Freemind-Flag"));
insilmaril@564
  1231
insilmaril@564
  1232
insilmaril@564
  1233
	fo->load(flagsPath+"freemind/kaddressbook.png");
insilmaril@582
  1234
	setupFlag (fo,tb,avis,"freemind-kaddressbook",tr("Telephone","Freemind-Flag"));
insilmaril@564
  1235
insilmaril@564
  1236
	fo->load(flagsPath+"freemind/knotify.png");
insilmaril@582
  1237
	setupFlag (fo,tb,avis,"freemind-knotify",tr("Music","Freemind-Flag"));
insilmaril@564
  1238
insilmaril@564
  1239
	fo->load(flagsPath+"freemind/korn.png");
insilmaril@582
  1240
	setupFlag (fo,tb,avis,"freemind-korn",tr("Mailbox","Freemind-Flag"));
insilmaril@564
  1241
insilmaril@564
  1242
	fo->load(flagsPath+"freemind/mail.png");
insilmaril@582
  1243
	setupFlag (fo,tb,avis,"freemind-mail",tr("Maix","Freemind-Flag"));
insilmaril@564
  1244
insilmaril@564
  1245
	fo->load(flagsPath+"freemind/password.png");
insilmaril@582
  1246
	setupFlag (fo,tb,avis,"freemind-password",tr("Password","Freemind-Flag"));
insilmaril@564
  1247
insilmaril@564
  1248
	fo->load(flagsPath+"freemind/pencil.png");
insilmaril@582
  1249
	setupFlag (fo,tb,avis,"freemind-pencil",tr("To be improved","Freemind-Flag"));
insilmaril@564
  1250
insilmaril@564
  1251
	fo->load(flagsPath+"freemind/stop.png");
insilmaril@582
  1252
	setupFlag (fo,tb,avis,"freemind-stop",tr("Stop","Freemind-Flag"));
insilmaril@564
  1253
insilmaril@564
  1254
	fo->load(flagsPath+"freemind/wizard.png");
insilmaril@582
  1255
	setupFlag (fo,tb,avis,"freemind-wizard",tr("Magic","Freemind-Flag"));
insilmaril@564
  1256
insilmaril@564
  1257
	fo->load(flagsPath+"freemind/xmag.png");
insilmaril@582
  1258
	setupFlag (fo,tb,avis,"freemind-xmag",tr("To be discussed","Freemind-Flag"));
insilmaril@564
  1259
insilmaril@564
  1260
	fo->load(flagsPath+"freemind/bell.png");
insilmaril@582
  1261
	setupFlag (fo,tb,avis,"freemind-bell",tr("Reminder","Freemind-Flag"));
insilmaril@564
  1262
insilmaril@564
  1263
	fo->load(flagsPath+"freemind/bookmark.png");
insilmaril@582
  1264
	setupFlag (fo,tb,avis,"freemind-bookmark",tr("Excellent","Freemind-Flag"));
insilmaril@564
  1265
insilmaril@564
  1266
	fo->load(flagsPath+"freemind/penguin.png");
insilmaril@582
  1267
	setupFlag (fo,tb,avis,"freemind-penguin",tr("Linux","Freemind-Flag"));
insilmaril@564
  1268
insilmaril@564
  1269
	fo->load(flagsPath+"freemind/licq.png");
insilmaril@582
  1270
	setupFlag (fo,tb,avis,"freemind-licq",tr("Sweet","Freemind-Flag"));
insilmaril@564
  1271
insilmaril@564
  1272
	delete (fo);
insilmaril@564
  1273
}
insilmaril@564
  1274
insilmaril@582
  1275
void Main::setupFlag (FlagObj *fo, QToolBar *tb, bool aw, const QString &name, const QString &tooltip)
insilmaril@564
  1276
{
insilmaril@564
  1277
	fo->setName(name);
insilmaril@582
  1278
	fo->setToolTip (tooltip);
insilmaril@564
  1279
	QAction *a=new QAction (fo->getPixmap(),fo->getName(),this);
insilmaril@582
  1280
	if (tb)
insilmaril@582
  1281
	{
insilmaril@582
  1282
		// StandardFlag
insilmaril@582
  1283
		tb->addAction (a);
insilmaril@582
  1284
		fo->setAction (a);
insilmaril@582
  1285
		fo->setAlwaysVisible(aw);
insilmaril@582
  1286
		a->setCheckable(true);
insilmaril@582
  1287
		a->setObjectName(fo->getName());
insilmaril@582
  1288
		a->setToolTip(tooltip);
insilmaril@582
  1289
		connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
insilmaril@582
  1290
		standardFlagsDefault->addFlag (fo);	
insilmaril@582
  1291
	} else
insilmaril@582
  1292
	{
insilmaril@582
  1293
		// SystemFlag
insilmaril@582
  1294
		systemFlagsDefault->addFlag (fo);	
insilmaril@582
  1295
	}
insilmaril@0
  1296
}
insilmaril@528
  1297
// Network Actions
insilmaril@528
  1298
void Main::setupNetworkActions()
insilmaril@528
  1299
{
insilmaril@528
  1300
	if (!settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
insilmaril@528
  1301
		return;
insilmaril@528
  1302
    QMenu *netMenu = menuBar()->addMenu(  "&Network" );
insilmaril@528
  1303
insilmaril@528
  1304
	QAction *a;
insilmaril@528
  1305
insilmaril@528
  1306
    a = new QAction(  "Start TCPserver for MapEditor",this);
insilmaril@528
  1307
    //a->setStatusTip ( "Set application to open pdf files"));
insilmaril@528
  1308
	a->setShortcut ( Qt::Key_T );		//New TCP server
insilmaril@528
  1309
    connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
insilmaril@528
  1310
	netMenu->addAction (a);
insilmaril@528
  1311
insilmaril@528
  1312
    a = new QAction(  "Connect MapEditor to server",this);
insilmaril@528
  1313
    //a->setStatusTip ( "Set application to open pdf files"));
insilmaril@528
  1314
	a->setShortcut ( Qt::Key_C );		// Connect to server
insilmaril@528
  1315
    connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
insilmaril@528
  1316
	netMenu->addAction (a);
insilmaril@528
  1317
}
insilmaril@528
  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@473
  1336
    a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
insilmaril@450
  1337
    a->setStatusTip( tr( "Set path for macros"));
insilmaril@450
  1338
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
insilmaril@450
  1339
	settingsMenu->addAction (a);
insilmaril@450
  1340
insilmaril@473
  1341
    a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
insilmaril@473
  1342
    a->setStatusTip( tr( "Set number of undo levels"));
insilmaril@473
  1343
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
insilmaril@473
  1344
	settingsMenu->addAction (a);
insilmaril@473
  1345
insilmaril@366
  1346
	settingsMenu->addSeparator();
insilmaril@473
  1347
insilmaril@473
  1348
    a = new QAction( tr( "Autosave","Settings action"), this);
insilmaril@473
  1349
    a->setStatusTip( tr( "Autosave"));
insilmaril@473
  1350
	a->setToggleAction(true);
insilmaril@473
  1351
	a->setOn ( settings.value ("/mapeditor/autosave/use",true).toBool());
insilmaril@473
  1352
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveToggle() ) );
insilmaril@473
  1353
	settingsMenu->addAction (a);
insilmaril@473
  1354
	actionSettingsAutosaveToggle=a;
insilmaril@473
  1355
insilmaril@473
  1356
    a = new QAction( tr( "Autosave time","Settings action")+"...", this);
insilmaril@473
  1357
    a->setStatusTip( tr( "Autosave time"));
insilmaril@473
  1358
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
insilmaril@473
  1359
	settingsMenu->addAction (a);
insilmaril@473
  1360
	actionSettingsAutosaveTime=a;
insilmaril@473
  1361
insilmaril@473
  1362
	settingsMenu->addSeparator();
insilmaril@473
  1363
insilmaril@395
  1364
    a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
insilmaril@366
  1365
    a->setStatusTip( tr( "Edit branch after adding it" ));
insilmaril@0
  1366
	a->setToggleAction(true);
insilmaril@537
  1367
	a->setOn ( settings.value ("/mapeditor/editmode/autoEditNewBranch",true).toBool());
insilmaril@366
  1368
	settingsMenu->addAction (a);
insilmaril@537
  1369
	actionSettingsAutoEditNewBranch=a;
insilmaril@0
  1370
insilmaril@395
  1371
    a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
insilmaril@366
  1372
    a->setStatusTip( tr( "Select branch after adding it" ));
insilmaril@0
  1373
	a->setToggleAction(true);
insilmaril@537
  1374
	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectNewBranch",false).toBool() );
insilmaril@366
  1375
	settingsMenu->addAction (a);
insilmaril@537
  1376
	actionSettingsAutoSelectNewBranch=a;
insilmaril@0
  1377
	
insilmaril@395
  1378
    a= new QAction(tr( "Select existing heading","Settings action" ), this);
insilmaril@366
  1379
    a->setStatusTip( tr( "Select heading before editing" ));
insilmaril@0
  1380
	a->setToggleAction(true);
insilmaril@366
  1381
	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
insilmaril@366
  1382
	settingsMenu->addAction (a);
insilmaril@390
  1383
	actionSettingsAutoSelectText=a;
insilmaril@0
  1384
	
insilmaril@395
  1385
    a= new QAction( tr( "Delete key","Settings action" ), this);
insilmaril@366
  1386
    a->setStatusTip( tr( "Delete key for deleting branches" ));
insilmaril@0
  1387
	a->setToggleAction(true);
insilmaril@505
  1388
	a->setOn ( settings.value ("/mapeditor/editmode/useDelKey",true).toBool() );
insilmaril@366
  1389
	settingsMenu->addAction (a);
insilmaril@366
  1390
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
insilmaril@366
  1391
	actionSettingsUseDelKey=a;
insilmaril@366
  1392
insilmaril@395
  1393
    a= new QAction( tr( "Exclusive flags","Settings action" ), this);
insilmaril@366
  1394
    a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
insilmaril@0
  1395
	a->setToggleAction(true);
insilmaril@366
  1396
	a->setOn ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
insilmaril@366
  1397
	settingsMenu->addAction (a);
insilmaril@103
  1398
	actionSettingsUseFlagGroups=a;
insilmaril@260
  1399
	
insilmaril@395
  1400
    a= new QAction( tr( "Use hide flags","Settings action" ), this);
insilmaril@366
  1401
    a->setStatusTip( tr( "Use hide flag during exports " ));
insilmaril@260
  1402
	a->setToggleAction(true);
insilmaril@366
  1403
	a->setOn ( settings.value ("/export/useHideExport",true).toBool() );
insilmaril@366
  1404
	settingsMenu->addAction (a);
insilmaril@260
  1405
	actionSettingsUseHideExport=a;
insilmaril@0
  1406
}
insilmaril@0
  1407
insilmaril@0
  1408
// Test Actions
insilmaril@0
  1409
void Main::setupTestActions()
insilmaril@0
  1410
{
insilmaril@366
  1411
    QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
insilmaril@0
  1412
insilmaril@0
  1413
    QAction *a;
insilmaril@527
  1414
    a = new QAction( "Test function 1" , this);
insilmaril@527
  1415
    a->setStatusTip( "Call test function 1" );
insilmaril@527
  1416
	testMenu->addAction (a);
insilmaril@445
  1417
	//a->setShortcut (Qt::Key_F4 );
insilmaril@527
  1418
    connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
insilmaril@527
  1419
insilmaril@527
  1420
    a = new QAction( "Test function 2" , this);
insilmaril@527
  1421
    a->setStatusTip( "Call test function 2" );
insilmaril@527
  1422
	//a->setShortcut (Qt::Key_F4 );
insilmaril@366
  1423
	testMenu->addAction (a);
insilmaril@527
  1424
    connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
insilmaril@527
  1425
insilmaril@395
  1426
    a = new QAction( "Command" , this);
insilmaril@395
  1427
    a->setStatusTip( "Enter command to call in editor" );
insilmaril@445
  1428
	//a->setShortcut (Qt::Key_F5 );
insilmaril@393
  1429
    connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
insilmaril@393
  1430
	testMenu->addAction (a);
insilmaril@0
  1431
}
insilmaril@0
  1432
insilmaril@0
  1433
// Help Actions
insilmaril@0
  1434
void Main::setupHelpActions()
insilmaril@0
  1435
{
insilmaril@395
  1436
    QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
insilmaril@0
  1437
insilmaril@0
  1438
    QAction *a;
insilmaril@395
  1439
    a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
insilmaril@366
  1440
    a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
insilmaril@366
  1441
    connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
insilmaril@366
  1442
	helpMenu->addAction (a);
insilmaril@366
  1443
insilmaril@505
  1444
    a = new QAction(  tr( "Open VYM example maps ","Help action" ), this );
insilmaril@505
  1445
    a->setStatusTip( tr( "Open VYM example maps " ));
insilmaril@505
  1446
    connect( a, SIGNAL( triggered() ), this, SLOT( helpDemo() ) );
insilmaril@505
  1447
	helpMenu->addAction (a);
insilmaril@505
  1448
insilmaril@395
  1449
    a = new QAction( tr( "About VYM","Help action" ), this);
insilmaril@404
  1450
    a->setStatusTip( tr( "About VYM")+vymName);
insilmaril@366
  1451
    connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
insilmaril@366
  1452
	helpMenu->addAction (a);
insilmaril@366
  1453
insilmaril@395
  1454
    a = new QAction( tr( "About QT","Help action" ), this);
insilmaril@366
  1455
    a->setStatusTip( tr( "Information about QT toolkit" ));
insilmaril@366
  1456
    connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
insilmaril@366
  1457
	helpMenu->addAction (a);
insilmaril@0
  1458
}
insilmaril@0
  1459
insilmaril@0
  1460
// Context Menus
insilmaril@0
  1461
void Main::setupContextMenus()
insilmaril@0
  1462
{
insilmaril@0
  1463
	QAction*a;
insilmaril@0
  1464
insilmaril@0
  1465
	// Context Menu for branch or mapcenter
insilmaril@366
  1466
	branchContextMenu =new QMenu (this);
insilmaril@486
  1467
	branchContextMenu->addAction (actionViewTogglePropertyWindow);
insilmaril@421
  1468
	branchContextMenu->addSeparator();	
insilmaril@421
  1469
insilmaril@98
  1470
		// Submenu "Add"
insilmaril@366
  1471
		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
insilmaril@366
  1472
		branchAddContextMenu->addAction (actionEditPaste );
insilmaril@366
  1473
		branchAddContextMenu->addAction ( actionEditAddBranch );
insilmaril@394
  1474
		branchAddContextMenu->addAction ( actionEditAddBranchBefore );
insilmaril@366
  1475
		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
insilmaril@366
  1476
		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
insilmaril@366
  1477
		branchAddContextMenu->addSeparator();	
insilmaril@366
  1478
		branchAddContextMenu->addAction ( actionEditImportAdd );
insilmaril@366
  1479
		branchAddContextMenu->addAction ( actionEditImportReplace );
insilmaril@98
  1480
insilmaril@98
  1481
		// Submenu "Remove"
insilmaril@395
  1482
		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
insilmaril@366
  1483
		branchRemoveContextMenu->addAction (actionEditCut);
insilmaril@366
  1484
		branchRemoveContextMenu->addAction ( actionEditDelete );
insilmaril@395
  1485
		branchRemoveContextMenu->addAction ( actionEditDeleteKeepChilds );
insilmaril@395
  1486
		branchRemoveContextMenu->addAction ( actionEditDeleteChilds );
insilmaril@98
  1487
		
insilmaril@98
  1488
insilmaril@0
  1489
	actionEditSaveBranch->addTo( branchContextMenu );
insilmaril@98
  1490
insilmaril@366
  1491
	branchContextMenu->addSeparator();	
insilmaril@398
  1492
	branchContextMenu->addAction ( actionEditLoadImage);
insilmaril@366
  1493
insilmaril@366
  1494
	// Submenu for Links (URLs, vymLinks)
insilmaril@366
  1495
	branchLinksContextMenu =new QMenu (this);
insilmaril@366
  1496
insilmaril@366
  1497
		branchContextMenu->addSeparator();	
insilmaril@473
  1498
		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
insilmaril@366
  1499
		branchLinksContextMenu->addAction ( actionEditOpenURL );
insilmaril@366
  1500
		branchLinksContextMenu->addAction ( actionEditOpenURLTab );
insilmaril@366
  1501
		branchLinksContextMenu->addAction ( actionEditOpenMultipleURLTabs );
insilmaril@366
  1502
		branchLinksContextMenu->addAction ( actionEditURL );
insilmaril@366
  1503
		branchLinksContextMenu->addAction ( actionEditHeading2URL );
insilmaril@366
  1504
		branchLinksContextMenu->addAction ( actionEditBugzilla2URL );
insilmaril@528
  1505
		if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
insilmaril@366
  1506
		{
insilmaril@366
  1507
			branchLinksContextMenu->addAction ( actionEditFATE2URL );
insilmaril@366
  1508
		}	
insilmaril@366
  1509
		branchLinksContextMenu->addSeparator();	
insilmaril@366
  1510
		branchLinksContextMenu->addAction ( actionEditOpenVymLink );
insilmaril@366
  1511
		branchLinksContextMenu->addAction ( actionEditOpenMultipleVymLinks );
insilmaril@366
  1512
		branchLinksContextMenu->addAction ( actionEditVymLink );
insilmaril@366
  1513
		branchLinksContextMenu->addAction ( actionEditDeleteVymLink );
insilmaril@366
  1514
		
insilmaril@366
  1515
insilmaril@366
  1516
	// Context Menu for XLinks in a branch menu
insilmaril@89
  1517
	// This will be populated "on demand" in MapEditor::updateActions
insilmaril@366
  1518
	branchContextMenu->addSeparator();	
insilmaril@395
  1519
	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
insilmaril@395
  1520
	branchXLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink","Context menu name"));
insilmaril@366
  1521
	connect( branchXLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), this, SLOT( editFollowXLink(QAction * ) ) );
insilmaril@366
  1522
	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
insilmaril@366
  1523
 	
insilmaril@105
  1524
	
insilmaril@0
  1525
	// Context menu for floatimage
insilmaril@366
  1526
	floatimageContextMenu =new QMenu (this);
insilmaril@395
  1527
	a= new QAction (tr ("Save image","Context action"),this);
insilmaril@366
  1528
	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
insilmaril@366
  1529
	floatimageContextMenu->addAction (a);
insilmaril@366
  1530
insilmaril@366
  1531
	floatimageContextMenu->addSeparator();	
insilmaril@0
  1532
	actionEditCopy->addTo( floatimageContextMenu );
insilmaril@0
  1533
	actionEditCut->addTo( floatimageContextMenu );
insilmaril@0
  1534
insilmaril@366
  1535
	floatimageContextMenu->addSeparator();	
insilmaril@366
  1536
	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
insilmaril@366
  1537
insilmaril@0
  1538
	
insilmaril@0
  1539
	// Context menu for canvas
insilmaril@366
  1540
	canvasContextMenu =new QMenu (this);
insilmaril@0
  1541
	actionEditMapInfo->addTo( canvasContextMenu );
insilmaril@0
  1542
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1543
	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
insilmaril@0
  1544
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1545
	actionFormatLinkColorHint->addTo( canvasContextMenu );
insilmaril@0
  1546
	actionFormatLinkColor->addTo( canvasContextMenu );
insilmaril@442
  1547
	actionFormatSelectionColor->addTo( canvasContextMenu );
insilmaril@0
  1548
	actionFormatBackColor->addTo( canvasContextMenu );
insilmaril@505
  1549
	// actionFormatBackImage->addTo( canvasContextMenu );  //FIXME makes vym too slow: postponed for later version 
insilmaril@0
  1550
insilmaril@0
  1551
	// Menu for last opened files
insilmaril@401
  1552
	// Create actions
insilmaril@401
  1553
	for (int i = 0; i < MaxRecentFiles; ++i) 
insilmaril@0
  1554
	{
insilmaril@445
  1555
        recentFileActions[i] = new QAction(this);
insilmaril@445
  1556
        recentFileActions[i]->setVisible(false);
insilmaril@445
  1557
        fileLastMapsMenu->addAction(recentFileActions[i]);
insilmaril@445
  1558
        connect(recentFileActions[i], SIGNAL(triggered()),
insilmaril@401
  1559
                this, SLOT(fileLoadRecent()));
insilmaril@401
  1560
    }
insilmaril@401
  1561
	setupRecentMapsMenu();
insilmaril@0
  1562
}
insilmaril@0
  1563
insilmaril@401
  1564
void Main::setupRecentMapsMenu()
insilmaril@0
  1565
{
insilmaril@401
  1566
    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
insilmaril@401
  1567
insilmaril@401
  1568
    int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
insilmaril@401
  1569
insilmaril@401
  1570
    for (int i = 0; i < numRecentFiles; ++i) {
insilmaril@401
  1571
        QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
insilmaril@445
  1572
        recentFileActions[i]->setText(text);
insilmaril@445
  1573
        recentFileActions[i]->setData(files[i]);
insilmaril@445
  1574
        recentFileActions[i]->setVisible(true);
insilmaril@401
  1575
    }
insilmaril@401
  1576
    for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
insilmaril@445
  1577
        recentFileActions[j]->setVisible(false);
insilmaril@445
  1578
}
insilmaril@445
  1579
insilmaril@445
  1580
void Main::setupMacros()
insilmaril@445
  1581
{
insilmaril@445
  1582
    for (int i = 0; i <= 11; i++) 
insilmaril@445
  1583
	{
insilmaril@445
  1584
        macroActions[i] = new QAction(this);
insilmaril@445
  1585
        macroActions[i]->setData(i);
insilmaril@445
  1586
        addAction (macroActions[i]);
insilmaril@445
  1587
        connect(macroActions[i], SIGNAL(triggered()),
insilmaril@445
  1588
                this, SLOT(callMacro()));
insilmaril@445
  1589
	}			
insilmaril@445
  1590
	macroActions[0]->setShortcut ( Qt::Key_F1 );
insilmaril@445
  1591
	macroActions[1]->setShortcut ( Qt::Key_F2 );
insilmaril@445
  1592
	macroActions[2]->setShortcut ( Qt::Key_F3 );
insilmaril@445
  1593
	macroActions[3]->setShortcut ( Qt::Key_F4 );
insilmaril@445
  1594
	macroActions[4]->setShortcut ( Qt::Key_F5 );
insilmaril@445
  1595
	macroActions[5]->setShortcut ( Qt::Key_F6 );
insilmaril@445
  1596
	macroActions[6]->setShortcut ( Qt::Key_F7 );
insilmaril@445
  1597
	macroActions[7]->setShortcut ( Qt::Key_F8 );
insilmaril@445
  1598
	macroActions[8]->setShortcut ( Qt::Key_F9 );
insilmaril@445
  1599
	macroActions[9]->setShortcut ( Qt::Key_F10 );
insilmaril@445
  1600
	macroActions[10]->setShortcut ( Qt::Key_F11 );
insilmaril@445
  1601
	macroActions[11]->setShortcut ( Qt::Key_F12 );
insilmaril@0
  1602
}
insilmaril@0
  1603
insilmaril@0
  1604
void Main::hideEvent (QHideEvent * )
insilmaril@0
  1605
{
insilmaril@0
  1606
	if (!textEditor->isMinimized() ) textEditor->hide();
insilmaril@0
  1607
}
insilmaril@0
  1608
insilmaril@0
  1609
void Main::showEvent (QShowEvent * )
insilmaril@0
  1610
{
insilmaril@491
  1611
	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
insilmaril@0
  1612
}
insilmaril@0
  1613
insilmaril@0
  1614
insilmaril@0
  1615
MapEditor* Main::currentMapEditor() const
insilmaril@0
  1616
{
insilmaril@0
  1617
    if ( tabWidget->currentPage() &&
insilmaril@0
  1618
	 tabWidget->currentPage()->inherits( "MapEditor" ) )
insilmaril@0
  1619
		return (MapEditor*)tabWidget->currentPage();
insilmaril@0
  1620
    return NULL;	
insilmaril@0
  1621
}
insilmaril@0
  1622
insilmaril@0
  1623
insilmaril@0
  1624
void Main::editorChanged(QWidget *)
insilmaril@0
  1625
{
insilmaril@0
  1626
	// Unselect all possibly selected objects
insilmaril@0
  1627
	// (Important to update note editor)
insilmaril@0
  1628
	MapEditor *me;
insilmaril@473
  1629
	for (int i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  1630
	{
insilmaril@0
  1631
		
insilmaril@0
  1632
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1633
		me->unselect();
insilmaril@0
  1634
	}	
insilmaril@0
  1635
	currentMapEditor()->reselect();
insilmaril@0
  1636
insilmaril@0
  1637
	// Update actions to in menus and toolbars according to editor
insilmaril@407
  1638
	updateActions();
insilmaril@0
  1639
}
insilmaril@0
  1640
insilmaril@0
  1641
void Main::fileNew()
insilmaril@0
  1642
{
insilmaril@0
  1643
	QString fn="unnamed";
insilmaril@408
  1644
	MapEditor* me = new MapEditor ( NULL);
insilmaril@408
  1645
	tabWidget->addTab (me,fn);
insilmaril@408
  1646
	tabWidget->showPage(me);
insilmaril@408
  1647
	me->viewport()->setFocus();
insilmaril@408
  1648
	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@408
  1649
	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@408
  1650
	
insilmaril@366
  1651
	// For the very first map we do not have flagrows yet...
insilmaril@408
  1652
	me->select("mc:");
insilmaril@0
  1653
}
insilmaril@0
  1654
insilmaril@491
  1655
void Main::fileNewCopy()
insilmaril@491
  1656
{
insilmaril@491
  1657
	QString fn="unnamed";
insilmaril@491
  1658
	MapEditor* oldME =currentMapEditor();
insilmaril@491
  1659
	if (oldME)
insilmaril@491
  1660
	{
insilmaril@491
  1661
		oldME->copy();
insilmaril@491
  1662
		MapEditor* newME = new MapEditor ( NULL);
insilmaril@491
  1663
		if (newME)
insilmaril@491
  1664
		{
insilmaril@491
  1665
			tabWidget->addTab (newME,fn);
insilmaril@491
  1666
			tabWidget->showPage(newME);
insilmaril@491
  1667
			newME->viewport()->setFocus();
insilmaril@491
  1668
			newME->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@491
  1669
			newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@491
  1670
			// For the very first map we do not have flagrows yet...
insilmaril@491
  1671
			newME->select("mc:");
insilmaril@571
  1672
			newME->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
insilmaril@491
  1673
		}
insilmaril@491
  1674
insilmaril@491
  1675
	}
insilmaril@491
  1676
}
insilmaril@491
  1677
insilmaril@571
  1678
ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype)
insilmaril@0
  1679
{
insilmaril@205
  1680
	ErrorCode err=success;
insilmaril@0
  1681
	
insilmaril@0
  1682
	// fn is usually the archive, mapfile the file after uncompressing
insilmaril@0
  1683
	QString mapfile;
insilmaril@0
  1684
insilmaril@0
  1685
	// Make fn absolute (needed for unzip)
insilmaril@0
  1686
	fn=QDir (fn).absPath();
insilmaril@0
  1687
insilmaril@0
  1688
	MapEditor *me;
insilmaril@0
  1689
insilmaril@0
  1690
	if (lmode==NewMap)
insilmaril@0
  1691
	{
insilmaril@0
  1692
		// Check, if map is already loaded
insilmaril@0
  1693
		int i=0;
insilmaril@0
  1694
		while (i<=tabWidget->count() -1)
insilmaril@0
  1695
		{
insilmaril@0
  1696
			me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1697
			if (me->getFilePath() == fn)
insilmaril@0
  1698
			{
insilmaril@0
  1699
				// Already there, ask for confirmation
insilmaril@404
  1700
				QMessageBox mb( vymName,
insilmaril@159
  1701
					tr("The map %1\nis already opened."
insilmaril@0
  1702
					"Opening the same map in multiple editors may lead \n"
insilmaril@0
  1703
					"to confusion when finishing working with vym."
insilmaril@159
  1704
					"Do you want to").arg(fn),
insilmaril@0
  1705
					QMessageBox::Warning,
insilmaril@0
  1706
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1707
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
  1708
					QMessageBox::NoButton);
insilmaril@0
  1709
				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
insilmaril@0
  1710
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1711
				switch( mb.exec() ) 
insilmaril@0
  1712
				{
insilmaril@0
  1713
					case QMessageBox::Yes:
insilmaril@0
  1714
						// load anyway
insilmaril@0
  1715
						i=tabWidget->count();
insilmaril@0
  1716
						break;
insilmaril@0
  1717
					case QMessageBox::Cancel:
insilmaril@0
  1718
						// do nothing
insilmaril@205
  1719
						return aborted;
insilmaril@0
  1720
						break;
insilmaril@0
  1721
				}
insilmaril@0
  1722
			}
insilmaril@0
  1723
			i++;
insilmaril@0
  1724
		}
insilmaril@0
  1725
	}
insilmaril@0
  1726
insilmaril@0
  1727
insilmaril@0
  1728
	// Try to load map
insilmaril@0
  1729
    if ( !fn.isEmpty() )
insilmaril@0
  1730
	{
insilmaril@0
  1731
		me = currentMapEditor();
insilmaril@0
  1732
		int tabIndex=tabWidget->currentPageIndex();
insilmaril@0
  1733
		// Check first, if mapeditor exists
insilmaril@0
  1734
		// If it is not default AND we want a new map, 
insilmaril@0
  1735
		// create a new mapeditor in a new tab
insilmaril@0
  1736
		if ( lmode==NewMap && (!me || !me->isDefault() ) )
insilmaril@0
  1737
		{
insilmaril@390
  1738
			me= new MapEditor ( NULL);
insilmaril@0
  1739
			tabWidget->addTab (me,fn);
insilmaril@0
  1740
			tabIndex=tabWidget->indexOf (me);
insilmaril@0
  1741
			tabWidget->setCurrentPage (tabIndex);
insilmaril@408
  1742
			me->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@408
  1743
			me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@0
  1744
		}
insilmaril@0
  1745
		
insilmaril@0
  1746
		// Check, if file exists (important for creating new files
insilmaril@0
  1747
		// from command line
insilmaril@0
  1748
		if (!QFile(fn).exists() )
insilmaril@0
  1749
		{
insilmaril@404
  1750
			QMessageBox mb( vymName,
insilmaril@159
  1751
				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
insilmaril@0
  1752
				QMessageBox::Question,
insilmaril@0
  1753
				QMessageBox::Yes ,
insilmaril@0
  1754
				QMessageBox::Cancel | QMessageBox::Default,
insilmaril@366
  1755
				QMessageBox::NoButton );
insilmaril@0
  1756
insilmaril@0
  1757
			mb.setButtonText( QMessageBox::Yes, tr("Create"));
insilmaril@0
  1758
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  1759
			switch( mb.exec() ) 
insilmaril@0
  1760
			{
insilmaril@0
  1761
				case QMessageBox::Yes:
insilmaril@0
  1762
					// Create new map
insilmaril@0
  1763
					currentMapEditor()->setFilePath(fn);
insilmaril@0
  1764
					tabWidget->setTabLabel (currentMapEditor(),
insilmaril@0
  1765
						currentMapEditor()->getFileName() );
insilmaril@0
  1766
					statusBar()->message( "Created " + fn , statusbarTime );
insilmaril@205
  1767
					return success;
insilmaril@0
  1768
						
insilmaril@0
  1769
				case QMessageBox::Cancel:
insilmaril@0
  1770
					// don't create new map
insilmaril@0
  1771
					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
insilmaril@0
  1772
					fileCloseMap();
insilmaril@205
  1773
					return aborted;
insilmaril@0
  1774
			}
insilmaril@0
  1775
		}	
insilmaril@0
  1776
insilmaril@0
  1777
insilmaril@0
  1778
		//tabWidget->currentPage() won't be NULL here, because of above...
insilmaril@0
  1779
		tabWidget->showPage(me);
insilmaril@0
  1780
		me->viewport()->setFocus();
insilmaril@0
  1781
insilmaril@0
  1782
		// Create temporary directory for packing
insilmaril@377
  1783
		bool ok;
insilmaril@377
  1784
		QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
insilmaril@377
  1785
		if (!ok)
insilmaril@377
  1786
		{
insilmaril@377
  1787
			QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@377
  1788
			   tr("Couldn't create temporary directory before load\n"));
insilmaril@377
  1789
			return aborted; 
insilmaril@377
  1790
		}
insilmaril@0
  1791
insilmaril@0
  1792
		// Try to unzip file
insilmaril@185
  1793
		err=unzipDir (tmpMapDir,fn);
insilmaril@185
  1794
		if (err==nozip)
insilmaril@0
  1795
		{
insilmaril@185
  1796
			mapfile=fn;
insilmaril@185
  1797
			me->setZipped(false);
insilmaril@0
  1798
		} else
insilmaril@0
  1799
		{
insilmaril@185
  1800
			me->setZipped(true);
insilmaril@185
  1801
			
insilmaril@185
  1802
			// Look for mapname.xml
insilmaril@185
  1803
			mapfile= fn.left(fn.findRev(".",-1,true));
insilmaril@185
  1804
			mapfile=mapfile.section( '/', -1 );
insilmaril@185
  1805
			QFile file( tmpMapDir + "/" + mapfile + ".xml");
insilmaril@185
  1806
			if (!file.exists() )
insilmaril@0
  1807
			{
insilmaril@185
  1808
				// mapname.xml does not exist, well, 
insilmaril@428
  1809
				// maybe someone renamed the mapname.vym file...
insilmaril@185
  1810
				// Try to find any .xml in the toplevel 
insilmaril@185
  1811
				// directory of the .vym file
insilmaril@185
  1812
				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
insilmaril@185
  1813
				if (flist.count()==1) 
insilmaril@0
  1814
				{
insilmaril@185
  1815
					// Only one entry, take this one
insilmaril@185
  1816
					mapfile=tmpMapDir + "/"+flist.first();
insilmaril@0
  1817
				} else
insilmaril@185
  1818
				{
insilmaril@185
  1819
					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
insilmaril@185
  1820
						*it=tmpMapDir + "/" + *it;
insilmaril@185
  1821
					// TODO Multiple entries, load all (but only the first one into this ME)
insilmaril@185
  1822
					//mainWindow->fileLoadFromTmp (flist);
insilmaril@185
  1823
					//returnCode=1;	// Silently forget this attempt to load
insilmaril@185
  1824
					qWarning ("MainWindow::load (fn)  multimap found...");
insilmaril@185
  1825
				}	
insilmaril@0
  1826
					
insilmaril@185
  1827
				if (flist.isEmpty() )
insilmaril@185
  1828
				{
insilmaril@185
  1829
					QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@185
  1830
							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
insilmaril@185
  1831
					err=aborted;				   
insilmaril@185
  1832
				}	
insilmaril@185
  1833
			} //file doesn't exist	
insilmaril@185
  1834
			else
insilmaril@185
  1835
				mapfile=file.name();
insilmaril@0
  1836
		}
insilmaril@0
  1837
insilmaril@185
  1838
		if (err!=aborted)
insilmaril@185
  1839
		{
insilmaril@185
  1840
			// Save existing filename in case  we import
insilmaril@185
  1841
			QString fn_org=me->getFilePath();
insilmaril@106
  1842
insilmaril@185
  1843
			// Finally load map into mapEditor
insilmaril@185
  1844
			me->setFilePath (mapfile,fn);
insilmaril@571
  1845
			err=me->load(mapfile,lmode,ftype);
insilmaril@106
  1846
insilmaril@185
  1847
			// Restore old (maybe empty) filepath, if this is an import
insilmaril@185
  1848
			if (lmode!=NewMap)
insilmaril@185
  1849
				me->setFilePath (fn_org);
insilmaril@185
  1850
		}	
insilmaril@0
  1851
insilmaril@185
  1852
		// Finally check for errors and go home
insilmaril@185
  1853
		if (err==aborted) 
insilmaril@185
  1854
		{
insilmaril@185
  1855
			if (lmode==NewMap) fileCloseMap();
insilmaril@185
  1856
			statusBar()->message( "Could not load " + fn, statusbarTime );
insilmaril@185
  1857
		} else 
insilmaril@0
  1858
		{
insilmaril@0
  1859
			if (lmode==NewMap)
insilmaril@0
  1860
			{
insilmaril@0
  1861
				me->setFilePath (fn);
insilmaril@0
  1862
				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
insilmaril@205
  1863
				if (fn.left(9)!="/tmp/vym-")
insilmaril@205
  1864
				{
insilmaril@205
  1865
					// Only append to lastMaps if not loaded from a tmpDir
insilmaril@205
  1866
					// e.g. imported bookmarks are in a tmpDir
insilmaril@401
  1867
					addRecentMap(me->getFilePath() );
insilmaril@205
  1868
				}
insilmaril@0
  1869
				actionFilePrint->setEnabled (true);
insilmaril@0
  1870
			}	
insilmaril@0
  1871
			statusBar()->message( "Loaded " + fn, statusbarTime );
insilmaril@0
  1872
		}	
insilmaril@0
  1873
insilmaril@185
  1874
		// Delete tmpDir
insilmaril@185
  1875
		removeDir (QDir(tmpMapDir));
insilmaril@0
  1876
	}
insilmaril@205
  1877
	return err;
insilmaril@0
  1878
}
insilmaril@0
  1879
insilmaril@0
  1880
insilmaril@0
  1881
void Main::fileLoad(const LoadMode &lmode)
insilmaril@0
  1882
{
insilmaril@377
  1883
	QStringList filters;
insilmaril@389
  1884
	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
insilmaril@377
  1885
	QFileDialog *fd=new QFileDialog( this);
insilmaril@366
  1886
	fd->setDir (lastFileDir);
insilmaril@377
  1887
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@377
  1888
	fd->setFilters (filters);
insilmaril@0
  1889
	switch (lmode)
insilmaril@0
  1890
	{
insilmaril@0
  1891
		case NewMap:
insilmaril@404
  1892
			fd->setCaption(vymName+ " - " +tr("Load vym map"));
insilmaril@0
  1893
			break;
insilmaril@0
  1894
		case ImportAdd:
insilmaril@404
  1895
			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
insilmaril@0
  1896
			break;
insilmaril@0
  1897
		case ImportReplace:
insilmaril@404
  1898
			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
insilmaril@0
  1899
			break;
insilmaril@0
  1900
	}
insilmaril@0
  1901
	fd->show();
insilmaril@0
  1902
insilmaril@0
  1903
	QString fn;
insilmaril@0
  1904
	if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  1905
	{
insilmaril@377
  1906
		lastFileDir=fd->directory().path();
insilmaril@185
  1907
	    QStringList flist = fd->selectedFiles();
insilmaril@185
  1908
		QStringList::Iterator it = flist.begin();
insilmaril@185
  1909
		while( it != flist.end() ) 
insilmaril@185
  1910
		{
insilmaril@185
  1911
			fn = *it;
insilmaril@185
  1912
			fileLoad(*it, lmode);				   
insilmaril@185
  1913
			++it;
insilmaril@185
  1914
		}
insilmaril@0
  1915
	}
insilmaril@185
  1916
	delete (fd);
insilmaril@0
  1917
}
insilmaril@0
  1918
insilmaril@0
  1919
void Main::fileLoad()
insilmaril@0
  1920
{
insilmaril@0
  1921
	fileLoad (NewMap);
insilmaril@0
  1922
}
insilmaril@0
  1923
insilmaril@401
  1924
void Main::fileLoadRecent()
insilmaril@0
  1925
{
insilmaril@401
  1926
    QAction *action = qobject_cast<QAction *>(sender());
insilmaril@401
  1927
    if (action)
insilmaril@401
  1928
        fileLoad (action->data().toString(), NewMap);
insilmaril@401
  1929
}
insilmaril@401
  1930
insilmaril@401
  1931
void Main::addRecentMap (const QString &fileName)
insilmaril@401
  1932
{
insilmaril@401
  1933
insilmaril@401
  1934
    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
insilmaril@401
  1935
    files.removeAll(fileName);
insilmaril@401
  1936
    files.prepend(fileName);
insilmaril@401
  1937
    while (files.size() > MaxRecentFiles)
insilmaril@401
  1938
        files.removeLast();
insilmaril@401
  1939
insilmaril@401
  1940
    settings.setValue("/mainwindow/recentFileList", files);
insilmaril@401
  1941
insilmaril@401
  1942
	setupRecentMapsMenu();
insilmaril@0
  1943
}
insilmaril@0
  1944
insilmaril@473
  1945
void Main::fileSave(MapEditor *me, const SaveMode &savemode)
insilmaril@0
  1946
{
insilmaril@0
  1947
	// tmp dir for zipping 
insilmaril@0
  1948
	QString tmpMapDir;
insilmaril@0
  1949
	
insilmaril@0
  1950
	// Error codes
insilmaril@205
  1951
	ErrorCode err=success;
insilmaril@0
  1952
	
insilmaril@0
  1953
	QString safeFilePath;
insilmaril@0
  1954
insilmaril@473
  1955
	bool saveZipped=me->saveZipped();
insilmaril@473
  1956
insilmaril@151
  1957
	if (me)
insilmaril@0
  1958
	{
insilmaril@151
  1959
		QString fn=me->getFilePath();
insilmaril@473
  1960
		// filename=unnamed, filepath="" in constructor of mapEditor
insilmaril@0
  1961
		if ( !fn.isEmpty() ) 
insilmaril@0
  1962
		{	
insilmaril@0
  1963
			// We have a filepath, go on saving			
insilmaril@0
  1964
			// First remove existing file, we 
insilmaril@0
  1965
			// don't want to add to old zip archives
insilmaril@0
  1966
			QFile f(fn);
insilmaril@0
  1967
			if (f.exists() ) 
insilmaril@0
  1968
				if (!f.remove())
insilmaril@0
  1969
					QMessageBox::warning( 0, tr( "Save Error" ),
insilmaril@0
  1970
						fn+   tr("\ncould not be removed before saving"));
insilmaril@0
  1971
insilmaril@0
  1972
			// Look, if we should zip the data:
insilmaril@0
  1973
			if (!saveZipped)
insilmaril@0
  1974
			{
insilmaril@404
  1975
				QMessageBox mb( vymName,
insilmaril@159
  1976
					tr("The map %1\ndid not use the compressed "
insilmaril@0
  1977
					"vym file format.\nWriting it uncompressed will also write images \n"
insilmaril@0
  1978
					"and flags and thus may overwrite files in the "
insilmaril@159
  1979
					"given directory\n\nDo you want to write the map").arg(fn),
insilmaril@0
  1980
					QMessageBox::Warning,
insilmaril@0
  1981
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1982
					QMessageBox::No ,
insilmaril@0
  1983
					QMessageBox::Cancel | QMessageBox::Escape);
insilmaril@0
  1984
				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
insilmaril@0
  1985
				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
insilmaril@0
  1986
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1987
				switch( mb.exec() ) 
insilmaril@0
  1988
				{
insilmaril@0
  1989
					case QMessageBox::Yes:
insilmaril@0
  1990
						// save compressed (default file format)
insilmaril@0
  1991
						saveZipped=true;
insilmaril@0
  1992
						break;
insilmaril@0
  1993
					case QMessageBox::No:
insilmaril@0
  1994
						// save uncompressed
insilmaril@0
  1995
						saveZipped=false;
insilmaril@0
  1996
						break;
insilmaril@0
  1997
					case QMessageBox::Cancel:
insilmaril@0
  1998
						// do nothing
insilmaril@0
  1999
						return;
insilmaril@0
  2000
						break;
insilmaril@0
  2001
				}
insilmaril@0
  2002
			}
insilmaril@0
  2003
insilmaril@0
  2004
			if (saveZipped)
insilmaril@0
  2005
			{
insilmaril@377
  2006
				// Create temporary directory for packing
insilmaril@377
  2007
				bool ok;
insilmaril@377
  2008
				QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
insilmaril@377
  2009
				if (!ok)
insilmaril@377
  2010
				{
insilmaril@377
  2011
					QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@377
  2012
					   tr("Couldn't create temporary directory before save\n"));
insilmaril@377
  2013
					return; 
insilmaril@377
  2014
				}
insilmaril@377
  2015
insilmaril@151
  2016
				safeFilePath=me->getFilePath();
insilmaril@151
  2017
				me->setFilePath (tmpMapDir+"/"+
insilmaril@151
  2018
					me->getMapName()+ ".xml",
insilmaril@0
  2019
					safeFilePath);
insilmaril@151
  2020
				me->save (savemode);
insilmaril@151
  2021
				me->setFilePath (safeFilePath);
insilmaril@0
  2022
				
insilmaril@175
  2023
				zipDir (tmpMapDir,fn);
insilmaril@0
  2024
			} // save zipped
insilmaril@0
  2025
			else
insilmaril@0
  2026
			{
insilmaril@0
  2027
				// Save unzipped. 
insilmaril@151
  2028
				safeFilePath=me->getFilePath();
insilmaril@151
  2029
				me->setFilePath (fn, safeFilePath);
insilmaril@151
  2030
				me->save (savemode);
insilmaril@151
  2031
				me->setFilePath (safeFilePath);
insilmaril@0
  2032
			} // save zipped 	
insilmaril@0
  2033
		} // filepath available
insilmaril@0
  2034
		else
insilmaril@0
  2035
		{
insilmaril@0
  2036
			// We have  no filepath yet,
insilmaril@0
  2037
			// call fileSaveAs() now, this will call fileSave() 
insilmaril@0
  2038
			// again.
insilmaril@473
  2039
			// First switch to editor
insilmaril@473
  2040
			tabWidget->setCurrentWidget (me);
insilmaril@0
  2041
			fileSaveAs(savemode);
insilmaril@0
  2042
		}
insilmaril@0
  2043
    }
insilmaril@0
  2044
insilmaril@250
  2045
	if (saveZipped && !tmpMapDir.isEmpty())
insilmaril@0
  2046
		// Delete tmpDir
insilmaril@175
  2047
		removeDir (QDir(tmpMapDir));
insilmaril@0
  2048
insilmaril@0
  2049
	if (err==success)
insilmaril@151
  2050
	{
insilmaril@0
  2051
		statusBar()->message( 
insilmaril@159
  2052
			tr("Saved  %1").arg(me->getFilePath()), 
insilmaril@0
  2053
			statusbarTime );
insilmaril@401
  2054
		addRecentMap (me->getFilePath() );
insilmaril@151
  2055
	} else		
insilmaril@0
  2056
		statusBar()->message( 
insilmaril@159
  2057
			tr("Couldn't save ").arg(me->getFilePath()), 
insilmaril@0
  2058
			statusbarTime );
insilmaril@0
  2059
}
insilmaril@0
  2060
insilmaril@0
  2061
void Main::fileSave()
insilmaril@0
  2062
{
insilmaril@473
  2063
	fileSave (currentMapEditor(), CompleteMap);
insilmaril@473
  2064
}
insilmaril@473
  2065
insilmaril@473
  2066
void Main::fileSave(MapEditor *me)
insilmaril@473
  2067
{
insilmaril@473
  2068
	fileSave (me,CompleteMap);
insilmaril@0
  2069
}
insilmaril@0
  2070
insilmaril@0
  2071
void Main::fileSaveAs(const SaveMode& savemode)
insilmaril@0
  2072
{
insilmaril@0
  2073
	QString fn;
insilmaril@0
  2074
insilmaril@0
  2075
	if (currentMapEditor())
insilmaril@0
  2076
	{
insilmaril@0
  2077
		if (savemode==CompleteMap)
insilmaril@366
  2078
			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
insilmaril@0
  2079
		else		
insilmaril@366
  2080
			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
insilmaril@0
  2081
		if ( !fn.isEmpty() ) 
insilmaril@0
  2082
		{
insilmaril@0
  2083
			// Check for existing file
insilmaril@0
  2084
			if (QFile (fn).exists())
insilmaril@0
  2085
			{
insilmaril@404
  2086
				QMessageBox mb( vymName,
insilmaril@159
  2087
					tr("The file %1\nexists already. Do you want to").arg(fn),
insilmaril@0
  2088
					QMessageBox::Warning,
insilmaril@0
  2089
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2090
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
  2091
					QMessageBox::NoButton);
insilmaril@0
  2092
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  2093
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  2094
				switch( mb.exec() ) 
insilmaril@0
  2095
				{
insilmaril@0
  2096
					case QMessageBox::Yes:
insilmaril@0
  2097
						// save 
insilmaril@0
  2098
						break;
insilmaril@0
  2099
					case QMessageBox::Cancel:
insilmaril@0
  2100
						// do nothing
insilmaril@0
  2101
						return;
insilmaril@0
  2102
						break;
insilmaril@0
  2103
				}
insilmaril@0
  2104
			} else
insilmaril@0
  2105
			{
insilmaril@0
  2106
				// New file, add extension to filename, if missing
insilmaril@0
  2107
				// This is always .vym or .vyp, depending on savemode
insilmaril@0
  2108
				if (savemode==CompleteMap)
insilmaril@0
  2109
				{
insilmaril@0
  2110
					if (!fn.contains (".vym") && !fn.contains (".xml"))
insilmaril@0
  2111
						fn +=".vym";
insilmaril@0
  2112
				} else		
insilmaril@0
  2113
				{
insilmaril@0
  2114
					if (!fn.contains (".vyp") && !fn.contains (".xml"))
insilmaril@0
  2115
						fn +=".vyp";
insilmaril@0
  2116
				}
insilmaril@0
  2117
			}
insilmaril@0
  2118
	
insilmaril@0
  2119
insilmaril@0
  2120
insilmaril@0
  2121
insilmaril@0
  2122
			// Save now
insilmaril@0
  2123
			currentMapEditor()->setFilePath(fn);
insilmaril@473
  2124
			fileSave(currentMapEditor(), savemode);
insilmaril@0
  2125
insilmaril@0
  2126
			// Set name of tab
insilmaril@94
  2127
			if (savemode==CompleteMap)
insilmaril@94
  2128
				tabWidget->setTabLabel (currentMapEditor(),
insilmaril@94
  2129
					currentMapEditor()->getFileName() );
insilmaril@0
  2130
			return;
insilmaril@0
  2131
		} 
insilmaril@0
  2132
	}
insilmaril@0
  2133
}
insilmaril@0
  2134
insilmaril@0
  2135
void Main::fileSaveAs()
insilmaril@0
  2136
{
insilmaril@0
  2137
	fileSaveAs (CompleteMap);
insilmaril@0
  2138
}
insilmaril@0
  2139
insilmaril@205
  2140
void Main::fileImportKDEBookmarks()
insilmaril@205
  2141
{
insilmaril@205
  2142
	ImportKDEBookmarks im;
insilmaril@205
  2143
	im.transform();
insilmaril@205
  2144
	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
insilmaril@205
  2145
		currentMapEditor()->setFilePath ("");
insilmaril@205
  2146
}
insilmaril@205
  2147
insilmaril@314
  2148
void Main::fileImportFirefoxBookmarks()
insilmaril@314
  2149
{
insilmaril@366
  2150
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@327
  2151
	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
insilmaril@366
  2152
	fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@327
  2153
	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
insilmaril@327
  2154
	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
insilmaril@327
  2155
	fd->show();
insilmaril@327
  2156
insilmaril@327
  2157
	if ( fd->exec() == QDialog::Accepted )
insilmaril@327
  2158
	{
insilmaril@327
  2159
		ImportFirefoxBookmarks im;
insilmaril@327
  2160
	    QStringList flist = fd->selectedFiles();
insilmaril@327
  2161
		QStringList::Iterator it = flist.begin();
insilmaril@327
  2162
		while( it != flist.end() ) 
insilmaril@327
  2163
		{
insilmaril@327
  2164
			im.setFile (*it);
insilmaril@327
  2165
			if (im.transform() && 
insilmaril@571
  2166
				success==fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
insilmaril@327
  2167
				currentMapEditor() )
insilmaril@327
  2168
				currentMapEditor()->setFilePath ("");
insilmaril@327
  2169
			++it;
insilmaril@327
  2170
		}
insilmaril@327
  2171
	}
insilmaril@327
  2172
	delete (fd);
insilmaril@314
  2173
}
insilmaril@314
  2174
insilmaril@571
  2175
void Main::fileImportFreemind()
insilmaril@571
  2176
{
insilmaril@571
  2177
	QStringList filters;
insilmaril@571
  2178
	filters <<"Freemind map (*.mm)"<<"All files (*)";
insilmaril@571
  2179
	QFileDialog *fd=new QFileDialog( this);
insilmaril@571
  2180
	fd->setDir (lastFileDir);
insilmaril@571
  2181
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@571
  2182
	fd->setFilters (filters);
insilmaril@571
  2183
	fd->setCaption(vymName+ " - " +tr("Load Freemind map"));
insilmaril@571
  2184
	fd->show();
insilmaril@571
  2185
insilmaril@571
  2186
	QString fn;
insilmaril@571
  2187
	if ( fd->exec() == QDialog::Accepted )
insilmaril@571
  2188
	{
insilmaril@571
  2189
		lastFileDir=fd->directory().path();
insilmaril@571
  2190
	    QStringList flist = fd->selectedFiles();
insilmaril@571
  2191
		QStringList::Iterator it = flist.begin();
insilmaril@571
  2192
		while( it != flist.end() ) 
insilmaril@571
  2193
		{
insilmaril@571
  2194
			fn = *it;
insilmaril@571
  2195
			if ( fileLoad (fn,NewMap, FreemindMap)  )
insilmaril@571
  2196
			{	
insilmaril@571
  2197
				currentMapEditor()->setFilePath ("");
insilmaril@571
  2198
			}	
insilmaril@571
  2199
			++it;
insilmaril@571
  2200
		}
insilmaril@571
  2201
	}
insilmaril@571
  2202
	delete (fd);
insilmaril@571
  2203
}
insilmaril@571
  2204
insilmaril@571
  2205
insilmaril@215
  2206
void Main::fileImportMM()
insilmaril@215
  2207
{
insilmaril@215
  2208
	ImportMM im;
insilmaril@215
  2209
insilmaril@366
  2210
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@366
  2211
	fd->setDir (lastFileDir);
insilmaril@366
  2212
	fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@215
  2213
	fd->addFilter ("Mind Manager (*.mmap)");
insilmaril@215
  2214
	fd->setCaption(tr("Import")+" "+"Mind Manager");
insilmaril@215
  2215
	fd->show();
insilmaril@215
  2216
insilmaril@215
  2217
	if ( fd->exec() == QDialog::Accepted )
insilmaril@215
  2218
	{
insilmaril@215
  2219
		lastFileDir=fd->dirPath();
insilmaril@215
  2220
	    QStringList flist = fd->selectedFiles();
insilmaril@215
  2221
		QStringList::Iterator it = flist.begin();
insilmaril@215
  2222
		while( it != flist.end() ) 
insilmaril@215
  2223
		{
insilmaril@215
  2224
			im.setFile (*it);
insilmaril@215
  2225
			if (im.transform() && 
insilmaril@215
  2226
				success==fileLoad (im.getTransformedFile(),NewMap) && 
insilmaril@215
  2227
				currentMapEditor() )
insilmaril@215
  2228
				currentMapEditor()->setFilePath ("");
insilmaril@215
  2229
insilmaril@215
  2230
			++it;
insilmaril@215
  2231
		}
insilmaril@215
  2232
	}
insilmaril@215
  2233
	delete (fd);
insilmaril@215
  2234
insilmaril@215
  2235
}
insilmaril@215
  2236
insilmaril@215
  2237
void Main::fileImportDir()
insilmaril@215
  2238
{
insilmaril@215
  2239
	if (currentMapEditor())
insilmaril@215
  2240
		currentMapEditor()->importDir();	
insilmaril@215
  2241
}
insilmaril@215
  2242
insilmaril@526
  2243
void Main::fileExportXML()	
insilmaril@0
  2244
{
insilmaril@526
  2245
	MapEditor *me=currentMapEditor();
insilmaril@526
  2246
	if (me) me->exportXML();
insilmaril@0
  2247
}
insilmaril@0
  2248
insilmaril@0
  2249
insilmaril@517
  2250
void Main::fileExportXHTML()	
insilmaril@0
  2251
{
insilmaril@260
  2252
	MapEditor *me=currentMapEditor();
insilmaril@517
  2253
	if (me) me->exportXHTML();
insilmaril@0
  2254
}
insilmaril@0
  2255
insilmaril@517
  2256
void Main::fileExportImage()	
insilmaril@0
  2257
{
insilmaril@260
  2258
	MapEditor *me=currentMapEditor();
insilmaril@514
  2259
	if (me) me->exportImage();
insilmaril@0
  2260
}
insilmaril@0
  2261
insilmaril@0
  2262
void Main::fileExportASCII()
insilmaril@0
  2263
{
insilmaril@260
  2264
	MapEditor *me=currentMapEditor();
insilmaril@514
  2265
	if (me) me->exportASCII();
insilmaril@0
  2266
}
insilmaril@0
  2267
insilmaril@517
  2268
void Main::fileExportCSV()	//FIXME not scriptable yet
insilmaril@497
  2269
{
insilmaril@497
  2270
	MapEditor *me=currentMapEditor();
insilmaril@497
  2271
	if (me)
insilmaril@497
  2272
	{
insilmaril@497
  2273
		ExportCSV ex;
insilmaril@497
  2274
		ex.setMapCenter(me->getMapCenter());
insilmaril@497
  2275
		ex.addFilter ("CSV (*.csv)");
insilmaril@497
  2276
		ex.setDir(lastImageDir);
insilmaril@497
  2277
		ex.setCaption(vymName+ " -" +tr("Export as CSV")+" "+tr("(still experimental)"));
insilmaril@497
  2278
		if (ex.execDialog() ) 
insilmaril@497
  2279
		{
insilmaril@497
  2280
			me->setExportMode(true);
insilmaril@497
  2281
			ex.doExport();
insilmaril@497
  2282
			me->setExportMode(false);
insilmaril@497
  2283
		}
insilmaril@497
  2284
	}
insilmaril@497
  2285
}
insilmaril@497
  2286
insilmaril@517
  2287
void Main::fileExportLaTeX()	//FIXME not scriptable yet
insilmaril@163
  2288
{
insilmaril@260
  2289
	MapEditor *me=currentMapEditor();
insilmaril@260
  2290
	if (me)
insilmaril@228
  2291
	{
insilmaril@228
  2292
		ExportLaTeX ex;
insilmaril@260
  2293
		ex.setMapCenter(me->getMapCenter());
insilmaril@228
  2294
		ex.addFilter ("Tex (*.tex)");
insilmaril@424
  2295
		ex.setDir(lastImageDir);
insilmaril@404
  2296
		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
insilmaril@260
  2297
		if (ex.execDialog() ) 
insilmaril@260
  2298
		{
insilmaril@260
  2299
			me->setExportMode(true);
insilmaril@260
  2300
			ex.doExport();
insilmaril@260
  2301
			me->setExportMode(false);
insilmaril@260
  2302
		}
insilmaril@228
  2303
	}
insilmaril@228
  2304
}
insilmaril@228
  2305
insilmaril@517
  2306
void Main::fileExportKDEBookmarks()	//FIXME not scriptable yet
insilmaril@243
  2307
{
insilmaril@243
  2308
	ExportKDEBookmarks ex;
insilmaril@260
  2309
	MapEditor *me=currentMapEditor();
insilmaril@260
  2310
	if (me)
insilmaril@243
  2311
	{
insilmaril@260
  2312
		ex.setMapCenter (me->getMapCenter() );
insilmaril@243
  2313
		ex.doExport();
insilmaril@243
  2314
	}	
insilmaril@243
  2315
}
insilmaril@243
  2316
insilmaril@517
  2317
void Main::fileExportTaskjuggler()	//FIXME not scriptable yet
insilmaril@228
  2318
{
insilmaril@228
  2319
	ExportTaskjuggler ex;
insilmaril@260
  2320
	MapEditor *me=currentMapEditor();
insilmaril@260
  2321
	if (me)
insilmaril@228
  2322
	{
insilmaril@260
  2323
		ex.setMapCenter (me->getMapCenter() );
insilmaril@404
  2324
		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
insilmaril@424
  2325
		ex.setDir(lastImageDir);
insilmaril@243
  2326
		ex.addFilter ("Taskjuggler (*.tjp)");
insilmaril@260
  2327
		if (ex.execDialog() ) 
insilmaril@260
  2328
		{
insilmaril@260
  2329
			me->setExportMode(true);
insilmaril@260
  2330
			ex.doExport();
insilmaril@260
  2331
			me->setExportMode(false);
insilmaril@260
  2332
		}
insilmaril@228
  2333
	}	
insilmaril@163
  2334
}
insilmaril@163
  2335
insilmaril@517
  2336
void Main::fileExportOOPresentation()	//FIXME not scriptable yet
insilmaril@163
  2337
{
insilmaril@404
  2338
	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
insilmaril@366
  2339
	// TODO add preview in dialog
insilmaril@185
  2340
	//ImagePreview *p =new ImagePreview (fd);
insilmaril@185
  2341
	//fd->setContentsPreviewEnabled( TRUE );
insilmaril@185
  2342
	//fd->setContentsPreview( p, p );
insilmaril@185
  2343
	//fd->setPreviewMode( QFileDialog::Contents );
insilmaril@404
  2344
	fd->setCaption(vymName+" - " +tr("Export to")+" Open Office");
insilmaril@366
  2345
	fd->setDir (QDir().current());
insilmaril@357
  2346
	if (fd->foundConfig())
insilmaril@357
  2347
	{
insilmaril@357
  2348
		fd->show();
insilmaril@185
  2349
insilmaril@357
  2350
		if ( fd->exec() == QDialog::Accepted )
insilmaril@357
  2351
		{
insilmaril@357
  2352
			QString fn=fd->selectedFile();
insilmaril@366
  2353
			if (!fn.contains (".odp"))
insilmaril@366
  2354
				fn +=".odp";
insilmaril@366
  2355
insilmaril@357
  2356
			//lastImageDir=fn.left(fn.findRev ("/"));
insilmaril@357
  2357
			if (currentMapEditor())
insilmaril@357
  2358
				currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
insilmaril@357
  2359
		}
insilmaril@357
  2360
	} else
insilmaril@185
  2361
	{
insilmaril@357
  2362
		QMessageBox::warning(0, 
insilmaril@366
  2363
		tr("Warning"),
insilmaril@366
  2364
		tr("Couldn't find configuration for export to Open Office\n"));
insilmaril@185
  2365
	}
insilmaril@163
  2366
}
insilmaril@163
  2367
insilmaril@0
  2368
void Main::fileCloseMap()
insilmaril@0
  2369
{
insilmaril@0
  2370
	if (currentMapEditor())
insilmaril@0
  2371
	{
insilmaril@0
  2372
		if (currentMapEditor()->hasChanged())
insilmaril@0
  2373
		{
insilmaril@404
  2374
			QMessageBox mb( vymName,
insilmaril@159
  2375
				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
insilmaril@0
  2376
				QMessageBox::Warning,
insilmaril@0
  2377
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2378
				QMessageBox::No,
insilmaril@0
  2379
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  2380
			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
insilmaril@0
  2381
			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
insilmaril@0
  2382
			switch( mb.exec() ) 
insilmaril@0
  2383
			{
insilmaril@0
  2384
				case QMessageBox::Yes:
insilmaril@0
  2385
					// save and close
insilmaril@473
  2386
					fileSave(currentMapEditor(), CompleteMap);
insilmaril@0
  2387
					break;
insilmaril@0
  2388
				case QMessageBox::No:
insilmaril@0
  2389
				// close  without saving
insilmaril@0
  2390
					break;
insilmaril@0
  2391
				case QMessageBox::Cancel:
insilmaril@0
  2392
					// do nothing
insilmaril@0
  2393
				return;
insilmaril@0
  2394
			}
insilmaril@0
  2395
		} 
insilmaril@0
  2396
		currentMapEditor()->closeMap();
insilmaril@0
  2397
		tabWidget->removePage(currentMapEditor());
insilmaril@0
  2398
		if (tabWidget->count()==0)
insilmaril@0
  2399
			actionFilePrint->setEnabled (false);
insilmaril@0
  2400
	}	
insilmaril@0
  2401
}
insilmaril@0
  2402
insilmaril@0
  2403
void Main::filePrint()
insilmaril@0
  2404
{
insilmaril@0
  2405
	if (currentMapEditor())
insilmaril@0
  2406
		currentMapEditor()->print();
insilmaril@0
  2407
}
insilmaril@0
  2408
insilmaril@0
  2409
void Main::fileExitVYM()
insilmaril@0
  2410
{
insilmaril@0
  2411
	// Check if one or more editors have changed
insilmaril@0
  2412
	MapEditor *me;
insilmaril@0
  2413
	int i;
insilmaril@0
  2414
	for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  2415
	{
insilmaril@0
  2416
		
insilmaril@0
  2417
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  2418
insilmaril@0
  2419
		// If something changed, ask what to do
insilmaril@486
  2420
		if (me->hasChanged())
insilmaril@0
  2421
		{
insilmaril@0
  2422
			tabWidget->setCurrentPage(i);
insilmaril@404
  2423
			QMessageBox mb( vymName,
insilmaril@0
  2424
				tr("This map is not saved yet. Do you want to"),
insilmaril@0
  2425
				QMessageBox::Warning,
insilmaril@0
  2426
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2427
				QMessageBox::No,
insilmaril@0
  2428
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  2429
			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
insilmaril@0
  2430
			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
insilmaril@366
  2431
			mb.setModal (true);
insilmaril@0
  2432
			mb.show();
insilmaril@0
  2433
			mb.setActiveWindow();
insilmaril@0
  2434
			switch( mb.exec() ) {
insilmaril@0
  2435
				case QMessageBox::Yes:
insilmaril@0
  2436
					// save (the changed editors) and exit
insilmaril@473
  2437
					fileSave(currentMapEditor(), CompleteMap);
insilmaril@0
  2438
					break;
insilmaril@0
  2439
				case QMessageBox::No:
insilmaril@0
  2440
					// exit without saving
insilmaril@0
  2441
					break;
insilmaril@0
  2442
				case QMessageBox::Cancel:
insilmaril@0
  2443
					// don't save and don't exit
insilmaril@0
  2444
				return;
insilmaril@0
  2445
			}
insilmaril@0
  2446
		}
insilmaril@0
  2447
	} // loop over all MEs	
insilmaril@0
  2448
    qApp->quit();
insilmaril@0
  2449
}
insilmaril@0
  2450
insilmaril@0
  2451
void Main::editUndo()
insilmaril@0
  2452
{
insilmaril@0
  2453
	if (currentMapEditor())
insilmaril@0
  2454
		currentMapEditor()->undo();
insilmaril@0
  2455
}
insilmaril@0
  2456
insilmaril@163
  2457
void Main::editRedo()	   
insilmaril@0
  2458
{
insilmaril@163
  2459
	if (currentMapEditor())
insilmaril@163
  2460
		currentMapEditor()->redo();
insilmaril@0
  2461
}
insilmaril@0
  2462
insilmaril@404
  2463
void Main::gotoHistoryStep (int i)	   
insilmaril@404
  2464
{
insilmaril@404
  2465
	if (currentMapEditor())
insilmaril@404
  2466
		currentMapEditor()->gotoHistoryStep (i);
insilmaril@404
  2467
}
insilmaril@404
  2468
insilmaril@0
  2469
void Main::editCopy()
insilmaril@0
  2470
{
insilmaril@0
  2471
	if (currentMapEditor())
insilmaril@0
  2472
		currentMapEditor()->copy();
insilmaril@0
  2473
}
insilmaril@0
  2474
insilmaril@0
  2475
void Main::editPaste()
insilmaril@0
  2476
{
insilmaril@0
  2477
	if (currentMapEditor())
insilmaril@0
  2478
		currentMapEditor()->paste();
insilmaril@0
  2479
}
insilmaril@0
  2480
insilmaril@0
  2481
void Main::editCut()
insilmaril@0
  2482
{
insilmaril@0
  2483
	if (currentMapEditor())
insilmaril@0
  2484
		currentMapEditor()->cut();
insilmaril@0
  2485
}
insilmaril@0
  2486
insilmaril@0
  2487
void Main::editOpenFindWindow()
insilmaril@0
  2488
{
insilmaril@0
  2489
	findWindow->popup();
insilmaril@0
  2490
	findWindow->raise();
insilmaril@0
  2491
	findWindow->setActiveWindow();
insilmaril@0
  2492
}
insilmaril@0
  2493
insilmaril@0
  2494
void Main::editFind(QString s)
insilmaril@0
  2495
{
insilmaril@0
  2496
	bool cs=false;
insilmaril@0
  2497
	BranchObj *bo=currentMapEditor()->findText(s, cs);
insilmaril@0
  2498
	if (bo)
insilmaril@0
  2499
	{	
insilmaril@0
  2500
		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
insilmaril@0
  2501
	} else
insilmaril@0
  2502
	{
insilmaril@0
  2503
		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
insilmaril@349
  2504
							   tr("No matches found for \"%1\"").arg(s));
insilmaril@0
  2505
	}	
insilmaril@0
  2506
}
insilmaril@0
  2507
insilmaril@0
  2508
void Main::editFindChanged()
insilmaril@0
  2509
{	// Notify editor, to abort the current find process
insilmaril@0
  2510
	currentMapEditor()->findReset();
insilmaril@0
  2511
}
insilmaril@0
  2512
insilmaril@366
  2513
void Main::openTabs(QStringList urls)
insilmaril@366
  2514
{
insilmaril@366
  2515
	if (!urls.isEmpty())
insilmaril@366
  2516
	{	
insilmaril@366
  2517
		bool success=true;
insilmaril@366
  2518
		QStringList args;
insilmaril@366
  2519
		QString browser=settings.value("/mainwindow/readerURL" ).toString();
insilmaril@366
  2520
		QProcess *p;
insilmaril@366
  2521
		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
insilmaril@366
  2522
		{
insilmaril@366
  2523
			QString u=urls.takeFirst();
insilmaril@366
  2524
			procBrowser = new QProcess( this );
insilmaril@366
  2525
			args<<u;
insilmaril@366
  2526
			procBrowser->start(browser,args);
insilmaril@366
  2527
			if ( !procBrowser->waitForStarted())
insilmaril@366
  2528
			{
insilmaril@366
  2529
				// try to set path to browser
insilmaril@366
  2530
				QMessageBox::warning(0, 
insilmaril@366
  2531
					tr("Warning"),
insilmaril@366
  2532
					tr("Couldn't find a viewer to open %1.\n").arg(u)+
insilmaril@366
  2533
					tr("Please use Settings->")+tr("Set application to open an URL"));
insilmaril@366
  2534
				return;
insilmaril@366
  2535
			}
insilmaril@366
  2536
			sleep (3);
insilmaril@366
  2537
		}
insilmaril@366
  2538
		if (browser.contains("konqueror"))
insilmaril@366
  2539
		{
insilmaril@366
  2540
			for (int i=0; i<urls.size(); i++)
insilmaril@366
  2541
			{
insilmaril@366
  2542
				// Open new browser
insilmaril@366
  2543
				// Try to open new tab in existing konqueror started previously by vym
insilmaril@366
  2544
				p=new QProcess (this);
insilmaril@366
  2545
				args.clear();
insilmaril@366
  2546
				args<< QString("konqueror-%1").arg(procBrowser->pid())<< 
insilmaril@366
  2547
					"konqueror-mainwindow#1"<< 
insilmaril@366
  2548
					"newTab" << 
insilmaril@366
  2549
					urls.at(i);
insilmaril@366
  2550
				p->start ("dcop",args);
insilmaril@366
  2551
				if ( !p->waitForStarted() ) success=false;
insilmaril@366
  2552
			}
insilmaril@366
  2553
			if (!success)
insilmaril@366
  2554
				QMessageBox::warning(0, 
insilmaril@366
  2555
					tr("Warning"),
insilmaril@366
  2556
					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
insilmaril@366
  2557
			return;		
insilmaril@366
  2558
		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
insilmaril@366
  2559
		{
insilmaril@366
  2560
			for (int i=0; i<urls.size(); i++)
insilmaril@366
  2561
			{
insilmaril@366
  2562
				// Try to open new tab in firefox
insilmaril@366
  2563
				p=new QProcess (this);
insilmaril@366
  2564
				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
insilmaril@366
  2565
				p->start (browser,args);
insilmaril@366
  2566
				if ( !p->waitForStarted() ) success=false;
insilmaril@366
  2567
			}			
insilmaril@366
  2568
			if (!success)
insilmaril@366
  2569
				QMessageBox::warning(0, 
insilmaril@366
  2570
					tr("Warning"),
insilmaril@366
  2571
					tr("Couldn't start %1 to open a new tab").arg(browser));
insilmaril@366
  2572
			return;		
insilmaril@366
  2573
		}			
insilmaril@366
  2574
		QMessageBox::warning(0, 
insilmaril@366
  2575
			tr("Warning"),
insilmaril@366
  2576
			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
insilmaril@366
  2577
	}	
insilmaril@366
  2578
}
insilmaril@366
  2579
insilmaril@0
  2580
void Main::editOpenURL()
insilmaril@0
  2581
{
insilmaril@266
  2582
	// Open new browser
insilmaril@0
  2583
	if (currentMapEditor())
insilmaril@266
  2584
	{	
insilmaril@266
  2585
	    QString url=currentMapEditor()->getURL();
insilmaril@366
  2586
		QStringList args;
insilmaril@266
  2587
		if (url=="") return;
insilmaril@366
  2588
		QString browser=settings.value("/mainwindow/readerURL" ).toString();
insilmaril@266
  2589
		procBrowser = new QProcess( this );
insilmaril@366
  2590
		args<<url;
insilmaril@366
  2591
		procBrowser->start(browser,args);
insilmaril@366
  2592
		if ( !procBrowser->waitForStarted())
insilmaril@266
  2593
		{
insilmaril@266
  2594
			// try to set path to browser
insilmaril@266
  2595
			QMessageBox::warning(0, 
insilmaril@266
  2596
				tr("Warning"),
insilmaril@266
  2597
				tr("Couldn't find a viewer to open %1.\n").arg(url)+
insilmaril@266
  2598
				tr("Please use Settings->")+tr("Set application to open an URL"));
insilmaril@266
  2599
			settingsURL() ; 
insilmaril@266
  2600
		}	
insilmaril@266
  2601
	}	
insilmaril@266
  2602
}
insilmaril@266
  2603
void Main::editOpenURLTab()
insilmaril@266
  2604
{
insilmaril@266
  2605
	if (currentMapEditor())
insilmaril@266
  2606
	{	
insilmaril@366
  2607
	    QStringList urls;
insilmaril@366
  2608
		urls.append(currentMapEditor()->getURL());
insilmaril@366
  2609
		openTabs (urls);
insilmaril@266
  2610
	}	
insilmaril@0
  2611
}
insilmaril@366
  2612
void Main::editOpenMultipleURLTabs()
insilmaril@366
  2613
{
insilmaril@366
  2614
	if (currentMapEditor())
insilmaril@366
  2615
	{	
insilmaril@366
  2616
	    QStringList urls;
insilmaril@366
  2617
		urls=currentMapEditor()->getURLs();
insilmaril@366
  2618
		openTabs (urls);
insilmaril@366
  2619
	}	
insilmaril@366
  2620
}
insilmaril@366
  2621
insilmaril@0
  2622
insilmaril@0
  2623
void Main::editURL()
insilmaril@0
  2624
{
insilmaril@0
  2625
	if (currentMapEditor())
insilmaril@0
  2626
	    currentMapEditor()->editURL();
insilmaril@0
  2627
}
insilmaril@0
  2628
insilmaril@528
  2629
void Main::editLocalURL()
insilmaril@528
  2630
{
insilmaril@528
  2631
	if (currentMapEditor())
insilmaril@528
  2632
	    currentMapEditor()->editLocalURL();
insilmaril@528
  2633
}
insilmaril@528
  2634
insilmaril@0
  2635
void Main::editHeading2URL()
insilmaril@0
  2636
{
insilmaril@0
  2637
	if (currentMapEditor())
insilmaril@0
  2638
	    currentMapEditor()->editHeading2URL();
insilmaril@0
  2639
}
insilmaril@0
  2640
insilmaril@0
  2641
void Main::editBugzilla2URL()
insilmaril@0
  2642
{
insilmaril@0
  2643
	if (currentMapEditor())
insilmaril@0
  2644
	    currentMapEditor()->editBugzilla2URL();
insilmaril@0
  2645
}
insilmaril@0
  2646
insilmaril@175
  2647
void Main::editFATE2URL()
insilmaril@175
  2648
{
insilmaril@175
  2649
	if (currentMapEditor())
insilmaril@175
  2650
	    currentMapEditor()->editFATE2URL();
insilmaril@175
  2651
}
insilmaril@175
  2652
insilmaril@394
  2653
void Main::editHeadingFinished()
insilmaril@394
  2654
{
insilmaril@394
  2655
	// only called from editHeading(), so there is a currentME
insilmaril@394
  2656
	MapEditor *me=currentMapEditor();
insilmaril@421
  2657
	if (me)
insilmaril@421
  2658
	{
insilmaril@491
  2659
		me->setStateEditHeading (false);
insilmaril@421
  2660
		QPoint p;	//Not used here, only to find out pos of branch
insilmaril@421
  2661
		bool ok;
insilmaril@421
  2662
		QString s=me->getHeading(ok,p);
insilmaril@394
  2663
insilmaril@394
  2664
#if defined(Q_OS_MACX)
insilmaril@394
  2665
#else
insilmaril@421
  2666
		if (ok && s!=lineedit->text())
insilmaril@421
  2667
			me->setHeading(lineedit->text());
insilmaril@421
  2668
			
insilmaril@421
  2669
		lineedit->releaseKeyboard();
insilmaril@421
  2670
		lineedit->hide();
insilmaril@421
  2671
		setFocus();
insilmaril@394
  2672
#endif	
insilmaril@537
  2673
		if (!actionSettingsAutoSelectNewBranch->isOn() && 
insilmaril@537
  2674
			!prevSelection.isEmpty()) 
insilmaril@537
  2675
			me->select(prevSelection);
insilmaril@421
  2676
		prevSelection="";
insilmaril@421
  2677
	}
insilmaril@394
  2678
}
insilmaril@394
  2679
insilmaril@366
  2680
void Main::editHeading()
insilmaril@0
  2681
{
insilmaril@394
  2682
	if (currentMapEditor())
insilmaril@0
  2683
	{
insilmaril@394
  2684
		MapEditor *me=currentMapEditor();
insilmaril@394
  2685
		QString oldSel=me->getSelectString();
insilmaril@394
  2686
insilmaril@394
  2687
		if (lineedit->isVisible())
insilmaril@394
  2688
			editHeadingFinished();
insilmaril@394
  2689
		else
insilmaril@366
  2690
		{
insilmaril@366
  2691
			bool ok;
insilmaril@366
  2692
			QPoint p;
insilmaril@531
  2693
			QString s=me->getHeading(ok,p);
insilmaril@366
  2694
insilmaril@366
  2695
			if (ok)
insilmaril@366
  2696
			{
insilmaril@491
  2697
				me->setStateEditHeading (true);
insilmaril@366
  2698
#if defined(Q_OS_MACX)
insilmaril@531
  2699
				p=me->mapToGlobal (p);
insilmaril@366
  2700
				QDialog *d =new QDialog(NULL);
insilmaril@366
  2701
				QLineEdit *le=new QLineEdit (d);
insilmaril@366
  2702
				d->setWindowFlags (Qt::FramelessWindowHint);
insilmaril@394
  2703
				d->setGeometry(p.x(),p.y(),230,25);
insilmaril@394
  2704
				le->resize (d->width()-10,d->height());
insilmaril@366
  2705
				le->setText (s);
insilmaril@366
  2706
				le->selectAll();
insilmaril@366
  2707
				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
insilmaril@366
  2708
				d->activateWindow();
insilmaril@366
  2709
				d->exec();
insilmaril@531
  2710
				me->setHeading (le->text());
insilmaril@394
  2711
				delete (le);
insilmaril@394
  2712
				delete (d);
insilmaril@394
  2713
				editHeadingFinished();
insilmaril@366
  2714
#else
insilmaril@531
  2715
				p=me->mapTo (this,p);
insilmaril@394
  2716
				lineedit->setGeometry(p.x(),p.y(),230,25);
insilmaril@366
  2717
				lineedit->setText(s);
insilmaril@366
  2718
				lineedit->setCursorPosition(1);
insilmaril@366
  2719
				lineedit->selectAll();
insilmaril@366
  2720
				lineedit->show();
insilmaril@366
  2721
				lineedit->grabKeyboard();
insilmaril@366
  2722
				lineedit->setFocus();
insilmaril@366
  2723
#endif
insilmaril@366
  2724
			}
insilmaril@366
  2725
		}
insilmaril@394
  2726
	} // currentMapEditor()	
insilmaril@366
  2727
}
insilmaril@366
  2728
insilmaril@366
  2729
void Main::openVymLinks(const QStringList &vl)
insilmaril@366
  2730
{
insilmaril@366
  2731
	for (int j=0; j<vl.size(); j++)
insilmaril@366
  2732
	{
insilmaril@0
  2733
		// compare path with already loaded maps
insilmaril@0
  2734
		int index=-1;
insilmaril@0
  2735
		int i;
insilmaril@0
  2736
		MapEditor *me;
insilmaril@0
  2737
		for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  2738
		{
insilmaril@0
  2739
			me=(MapEditor*)tabWidget->page(i);
insilmaril@366
  2740
			if (vl.at(j)==me->getFilePath() )
insilmaril@0
  2741
			{
insilmaril@0
  2742
				index=i;
insilmaril@0
  2743
				break;
insilmaril@0
  2744
			}
insilmaril@0
  2745
		}	
insilmaril@0
  2746
		if (index<0)
insilmaril@0
  2747
		// Load map
insilmaril@0
  2748
		{
insilmaril@366
  2749
			if (!QFile(vl.at(j)).exists() )
insilmaril@0
  2750
				QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@366
  2751
				   tr("Couldn't open map %1").arg(vl.at(j)));
insilmaril@0
  2752
			else
insilmaril@0
  2753
			{
insilmaril@366
  2754
				fileLoad (vl.at(j), NewMap);
insilmaril@0
  2755
				tabWidget->setCurrentPage (tabWidget->count()-1);	
insilmaril@0
  2756
			}
insilmaril@0
  2757
		} else
insilmaril@0
  2758
			// Go to tab containing the map
insilmaril@0
  2759
			tabWidget->setCurrentPage (index);	
insilmaril@0
  2760
	}
insilmaril@0
  2761
}
insilmaril@0
  2762
insilmaril@366
  2763
void Main::editOpenVymLink()
insilmaril@366
  2764
{
insilmaril@366
  2765
	if (currentMapEditor())
insilmaril@366
  2766
	{
insilmaril@366
  2767
		QStringList vl;
insilmaril@366
  2768
		vl.append(currentMapEditor()->getVymLink());	
insilmaril@366
  2769
		openVymLinks (vl);
insilmaril@366
  2770
	}
insilmaril@366
  2771
}
insilmaril@366
  2772
insilmaril@366
  2773
void Main::editOpenMultipleVymLinks()
insilmaril@366
  2774
{
insilmaril@366
  2775
	QString currentVymLink;
insilmaril@366
  2776
	if (currentMapEditor())
insilmaril@366
  2777
	{
insilmaril@366
  2778
		QStringList vl=currentMapEditor()->getVymLinks();
insilmaril@366
  2779
		openVymLinks (vl);
insilmaril@366
  2780
	}
insilmaril@366
  2781
}
insilmaril@366
  2782
insilmaril@0
  2783
void Main::editVymLink()
insilmaril@0
  2784
{
insilmaril@0
  2785
	if (currentMapEditor())
insilmaril@0
  2786
		currentMapEditor()->editVymLink();	
insilmaril@0
  2787
}
insilmaril@0
  2788
insilmaril@0
  2789
void Main::editDeleteVymLink()
insilmaril@0
  2790
{
insilmaril@0
  2791
	if (currentMapEditor())
insilmaril@0
  2792
		currentMapEditor()->deleteVymLink();	
insilmaril@0
  2793
}
insilmaril@0
  2794
insilmaril@243
  2795
void Main::editToggleHideExport()
insilmaril@243
  2796
{
insilmaril@243
  2797
	if (currentMapEditor())
insilmaril@294
  2798
		currentMapEditor()->toggleHideExport();	
insilmaril@243
  2799
}
insilmaril@243
  2800
insilmaril@0
  2801
void Main::editMapInfo()
insilmaril@0
  2802
{
insilmaril@0
  2803
	if (currentMapEditor())
insilmaril@0
  2804
		currentMapEditor()->editMapInfo();	
insilmaril@0
  2805
}
insilmaril@0
  2806
insilmaril@0
  2807
void Main::editMoveUp()
insilmaril@0
  2808
{
insilmaril@0
  2809
	if (currentMapEditor())
insilmaril@0
  2810
	    currentMapEditor()->moveBranchUp();
insilmaril@0
  2811
}
insilmaril@0
  2812
insilmaril@0
  2813
void Main::editMoveDown()
insilmaril@0
  2814
{
insilmaril@0
  2815
	if (currentMapEditor())
insilmaril@0
  2816
		currentMapEditor()->moveBranchDown();
insilmaril@0
  2817
}
insilmaril@0
  2818
insilmaril@0
  2819
void Main::editToggleScroll()
insilmaril@0
  2820
{
insilmaril@0
  2821
	if (currentMapEditor())
insilmaril@0
  2822
	{
insilmaril@0
  2823
		currentMapEditor()->toggleScroll();	
insilmaril@0
  2824
	}	
insilmaril@0
  2825
}
insilmaril@0
  2826
insilmaril@473
  2827
void Main::editUnscrollChilds()
insilmaril@0
  2828
{
insilmaril@0
  2829
	if (currentMapEditor())
insilmaril@428
  2830
		currentMapEditor()->unscrollChilds();	
insilmaril@394
  2831
}
insilmaril@394
  2832
insilmaril@394
  2833
void Main::editNewBranch()
insilmaril@394
  2834
{
insilmaril@394
  2835
	MapEditor *me=currentMapEditor();
insilmaril@394
  2836
	if (!lineedit->isVisible() && me)
insilmaril@0
  2837
	{
insilmaril@394
  2838
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2839
		BranchObj *newbo=me->addNewBranch(0);
insilmaril@394
  2840
insilmaril@534
  2841
		prevSelection=bo->getSelectString();
insilmaril@394
  2842
		if (newbo) 
insilmaril@394
  2843
			me->select (newbo->getSelectString());
insilmaril@394
  2844
		else
insilmaril@394
  2845
			return;
insilmaril@394
  2846
insilmaril@537
  2847
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2848
		{
insilmaril@394
  2849
			editHeading();
insilmaril@534
  2850
			return;
insilmaril@534
  2851
		}	
insilmaril@534
  2852
		if (!prevSelection.isEmpty()) 
insilmaril@534
  2853
		{
insilmaril@534
  2854
			me->select(prevSelection);
insilmaril@534
  2855
			prevSelection="";
insilmaril@394
  2856
		}
insilmaril@534
  2857
insilmaril@0
  2858
	}	
insilmaril@0
  2859
}
insilmaril@0
  2860
insilmaril@394
  2861
void Main::editNewBranchBefore()
insilmaril@0
  2862
{
insilmaril@394
  2863
	MapEditor *me=currentMapEditor();
insilmaril@394
  2864
	if (!lineedit->isVisible() && me)
insilmaril@394
  2865
	{
insilmaril@394
  2866
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2867
		BranchObj *newbo=me->addNewBranchBefore();
insilmaril@394
  2868
insilmaril@394
  2869
		if (newbo) 
insilmaril@394
  2870
			me->select (newbo->getSelectString());
insilmaril@394
  2871
		else
insilmaril@394
  2872
			return;
insilmaril@394
  2873
insilmaril@537
  2874
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2875
		{
insilmaril@537
  2876
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2877
				prevSelection=bo->getSelectString();
insilmaril@394
  2878
			editHeading();
insilmaril@394
  2879
		}
insilmaril@394
  2880
	}	
insilmaril@98
  2881
}
insilmaril@98
  2882
insilmaril@0
  2883
void Main::editNewBranchAbove()
insilmaril@0
  2884
{
insilmaril@394
  2885
	MapEditor *me=currentMapEditor();
insilmaril@394
  2886
	if (!lineedit->isVisible() && me)
insilmaril@394
  2887
	{
insilmaril@394
  2888
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2889
		BranchObj *newbo=me->addNewBranch (-1);
insilmaril@394
  2890
insilmaril@394
  2891
		if (newbo) 
insilmaril@394
  2892
			me->select (newbo->getSelectString());
insilmaril@394
  2893
		else
insilmaril@394
  2894
			return;
insilmaril@394
  2895
insilmaril@537
  2896
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2897
		{
insilmaril@537
  2898
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2899
				prevSelection=bo->getSelectString();
insilmaril@394
  2900
			editHeading();
insilmaril@394
  2901
		}
insilmaril@394
  2902
	}	
insilmaril@0
  2903
}
insilmaril@0
  2904
insilmaril@0
  2905
void Main::editNewBranchBelow()
insilmaril@0
  2906
{
insilmaril@394
  2907
	MapEditor *me=currentMapEditor();
insilmaril@394
  2908
	if (!lineedit->isVisible() && me)
insilmaril@394
  2909
	{
insilmaril@394
  2910
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2911
		BranchObj *newbo=me->addNewBranch (1);
insilmaril@394
  2912
insilmaril@394
  2913
		if (newbo) 
insilmaril@394
  2914
			me->select (newbo->getSelectString());
insilmaril@394
  2915
		else
insilmaril@394
  2916
			return;
insilmaril@394
  2917
insilmaril@537
  2918
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2919
		{
insilmaril@537
  2920
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2921
				prevSelection=bo->getSelectString();
insilmaril@394
  2922
			editHeading();
insilmaril@394
  2923
		}
insilmaril@394
  2924
	}	
insilmaril@0
  2925
}
insilmaril@0
  2926
insilmaril@0
  2927
void Main::editImportAdd()
insilmaril@0
  2928
{
insilmaril@0
  2929
	fileLoad (ImportAdd);
insilmaril@0
  2930
}
insilmaril@0
  2931
insilmaril@0
  2932
void Main::editImportReplace()
insilmaril@0
  2933
{
insilmaril@0
  2934
	fileLoad (ImportReplace);
insilmaril@0
  2935
}
insilmaril@0
  2936
insilmaril@0
  2937
void Main::editSaveBranch()
insilmaril@0
  2938
{
insilmaril@0
  2939
	fileSaveAs (PartOfMap);
insilmaril@0
  2940
}
insilmaril@0
  2941
insilmaril@395
  2942
void Main::editDeleteKeepChilds()
insilmaril@98
  2943
{
insilmaril@98
  2944
	if (currentMapEditor())
insilmaril@395
  2945
		currentMapEditor()->deleteKeepChilds();
insilmaril@98
  2946
}
insilmaril@98
  2947
insilmaril@395
  2948
void Main::editDeleteChilds()
insilmaril@98
  2949
{
insilmaril@98
  2950
	if (currentMapEditor())
insilmaril@395
  2951
		currentMapEditor()->deleteChilds();
insilmaril@98
  2952
}
insilmaril@98
  2953
insilmaril@0
  2954
void Main::editDeleteSelection()
insilmaril@0
  2955
{
insilmaril@151
  2956
	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
insilmaril@0
  2957
		currentMapEditor()->deleteSelection();
insilmaril@0
  2958
}
insilmaril@0
  2959
insilmaril@0
  2960
void Main::editUpperBranch()
insilmaril@0
  2961
{
insilmaril@0
  2962
	if (currentMapEditor())
insilmaril@0
  2963
		currentMapEditor()->selectUpperBranch();
insilmaril@0
  2964
}
insilmaril@0
  2965
insilmaril@0
  2966
void Main::editLowerBranch()
insilmaril@0
  2967
{
insilmaril@0
  2968
	if (currentMapEditor())
insilmaril@0
  2969
		currentMapEditor()->selectLowerBranch();
insilmaril@0
  2970
}
insilmaril@0
  2971
insilmaril@0
  2972
void Main::editLeftBranch()
insilmaril@0
  2973
{
insilmaril@0
  2974
	if (currentMapEditor())
insilmaril@0
  2975
		currentMapEditor()->selectLeftBranch();
insilmaril@0
  2976
}
insilmaril@0
  2977
insilmaril@0
  2978
void Main::editRightBranch()
insilmaril@0
  2979
{
insilmaril@0
  2980
	if (currentMapEditor())
insilmaril@0
  2981
		currentMapEditor()->selectRightBranch();
insilmaril@0
  2982
}
insilmaril@0
  2983
insilmaril@0
  2984
void Main::editFirstBranch()
insilmaril@0
  2985
{
insilmaril@0
  2986
	if (currentMapEditor())
insilmaril@0
  2987
		currentMapEditor()->selectFirstBranch();
insilmaril@0
  2988
}
insilmaril@0
  2989
insilmaril@0
  2990
void Main::editLastBranch()
insilmaril@0
  2991
{
insilmaril@0
  2992
	if (currentMapEditor())
insilmaril@0
  2993
		currentMapEditor()->selectLastBranch();
insilmaril@0
  2994
}
insilmaril@0
  2995
insilmaril@0
  2996
void Main::editLoadImage()
insilmaril@0
  2997
{
insilmaril@0
  2998
	if (currentMapEditor())
insilmaril@0
  2999
		currentMapEditor()->loadFloatImage();
insilmaril@0
  3000
}
insilmaril@0
  3001
insilmaril@366
  3002
void Main::editSaveImage()
insilmaril@0
  3003
{
insilmaril@0
  3004
	if (currentMapEditor())
insilmaril@366
  3005
		currentMapEditor()->saveFloatImage();
insilmaril@0
  3006
}
insilmaril@0
  3007
insilmaril@366
  3008
void Main::editFollowXLink(QAction *a)
insilmaril@366
  3009
{
insilmaril@366
  3010
insilmaril@366
  3011
	if (currentMapEditor())
insilmaril@366
  3012
		currentMapEditor()->followXLink(branchXLinksContextMenuFollow->actions().indexOf(a));
insilmaril@366
  3013
}
insilmaril@366
  3014
insilmaril@366
  3015
void Main::editEditXLink(QAction *a)
insilmaril@89
  3016
{
insilmaril@89
  3017
	if (currentMapEditor())
insilmaril@366
  3018
		currentMapEditor()->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
insilmaril@94
  3019
}
insilmaril@94
  3020
insilmaril@0
  3021
void Main::formatSelectColor()
insilmaril@0
  3022
{
insilmaril@0
  3023
	if (currentMapEditor())
insilmaril@0
  3024
	{
insilmaril@395
  3025
		QColor col = QColorDialog::getColor((currentColor ), this );
insilmaril@0
  3026
		if ( !col.isValid() ) return;
insilmaril@0
  3027
		colorChanged( col );
insilmaril@0
  3028
	}	
insilmaril@0
  3029
}
insilmaril@0
  3030
insilmaril@0
  3031
void Main::formatPickColor()
insilmaril@0
  3032
{
insilmaril@0
  3033
	if (currentMapEditor())
insilmaril@395
  3034
		colorChanged( currentMapEditor()->getCurrentHeadingColor() );
insilmaril@0
  3035
}
insilmaril@0
  3036
insilmaril@0
  3037
void Main::colorChanged(QColor c)
insilmaril@0
  3038
{
insilmaril@0
  3039
    QPixmap pix( 16, 16 );
insilmaril@0
  3040
    pix.fill( c );
insilmaril@0
  3041
    actionFormatColor->setIconSet( pix );
insilmaril@395
  3042
	currentColor=c;
insilmaril@0
  3043
}
insilmaril@0
  3044
insilmaril@0
  3045
void Main::formatColorBranch()
insilmaril@0
  3046
{
insilmaril@0
  3047
	if (currentMapEditor())
insilmaril@395
  3048
		currentMapEditor()->colorBranch(currentColor);
insilmaril@0
  3049
}
insilmaril@0
  3050
insilmaril@417
  3051
void Main::formatColorSubtree()
insilmaril@417
  3052
{
insilmaril@417
  3053
	if (currentMapEditor())
insilmaril@417
  3054
		currentMapEditor()->colorSubtree (currentColor);
insilmaril@417
  3055
}
insilmaril@417
  3056
insilmaril@0
  3057
void Main::formatLinkStyleLine()
insilmaril@0
  3058
{
insilmaril@0
  3059
	if (currentMapEditor())
insilmaril@398
  3060
		currentMapEditor()->setMapLinkStyle("StyleLine");
insilmaril@0
  3061
}
insilmaril@0
  3062
insilmaril@0
  3063
void Main::formatLinkStyleParabel()
insilmaril@0
  3064
{
insilmaril@0
  3065
	if (currentMapEditor())
insilmaril@398
  3066
		currentMapEditor()->setMapLinkStyle("StyleParabel");
insilmaril@0
  3067
}
insilmaril@0
  3068
insilmaril@0
  3069
void Main::formatLinkStylePolyLine()
insilmaril@0
  3070
{
insilmaril@0
  3071
	if (currentMapEditor())
insilmaril@398
  3072
		currentMapEditor()->setMapLinkStyle("StylePolyLine");
insilmaril@0
  3073
}
insilmaril@0
  3074
insilmaril@0
  3075
void Main::formatLinkStylePolyParabel()
insilmaril@0
  3076
{
insilmaril@0
  3077
	if (currentMapEditor())
insilmaril@398
  3078
		currentMapEditor()->setMapLinkStyle("StylePolyParabel");
insilmaril@0
  3079
}
insilmaril@0
  3080
insilmaril@0
  3081
void Main::formatSelectBackColor()
insilmaril@0
  3082
{
insilmaril@0
  3083
	if (currentMapEditor())
insilmaril@398
  3084
		currentMapEditor()->selectMapBackgroundColor();
insilmaril@0
  3085
}
insilmaril@0
  3086
insilmaril@408
  3087
void Main::formatSelectBackImage()
insilmaril@408
  3088
{
insilmaril@408
  3089
	if (currentMapEditor())
insilmaril@408
  3090
		currentMapEditor()->selectMapBackgroundImage();
insilmaril@408
  3091
}
insilmaril@408
  3092
insilmaril@0
  3093
void Main::formatSelectLinkColor()
insilmaril@0
  3094
{
insilmaril@0
  3095
	if (currentMapEditor())
insilmaril@398
  3096
		currentMapEditor()->selectMapLinkColor();
insilmaril@0
  3097
}
insilmaril@0
  3098
insilmaril@442
  3099
void Main::formatSelectSelectionColor()
insilmaril@442
  3100
{
insilmaril@442
  3101
	if (currentMapEditor())
insilmaril@442
  3102
		currentMapEditor()->selectMapSelectionColor();
insilmaril@442
  3103
}
insilmaril@442
  3104
insilmaril@0
  3105
void Main::formatToggleLinkColorHint()
insilmaril@0
  3106
{
insilmaril@398
  3107
	currentMapEditor()->toggleMapLinkColorHint();
insilmaril@0
  3108
}
insilmaril@0
  3109
insilmaril@0
  3110
insilmaril@421
  3111
void Main::formatHideLinkUnselected()	//FIXME get rid of this with imagepropertydialog
insilmaril@160
  3112
{
insilmaril@160
  3113
	if (currentMapEditor())
insilmaril@160
  3114
		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
insilmaril@160
  3115
}
insilmaril@160
  3116
insilmaril@0
  3117
void Main::viewZoomReset()
insilmaril@0
  3118
{
insilmaril@0
  3119
	if (currentMapEditor())
insilmaril@0
  3120
	{
insilmaril@366
  3121
		QMatrix m;
insilmaril@0
  3122
		m.reset();
insilmaril@408
  3123
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3124
	}	
insilmaril@0
  3125
}
insilmaril@0
  3126
insilmaril@0
  3127
void Main::viewZoomIn()
insilmaril@0
  3128
{
insilmaril@0
  3129
	if (currentMapEditor())
insilmaril@0
  3130
	{
insilmaril@408
  3131
		QMatrix m = currentMapEditor()->matrix();
insilmaril@0
  3132
		m.scale( 1.25, 1.25 );
insilmaril@408
  3133
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3134
	}	
insilmaril@0
  3135
}
insilmaril@0
  3136
insilmaril@0
  3137
void Main::viewZoomOut()
insilmaril@0
  3138
{
insilmaril@0
  3139
	if (currentMapEditor())
insilmaril@0
  3140
	{
insilmaril@408
  3141
		QMatrix m = currentMapEditor()->matrix();
insilmaril@0
  3142
		m.scale( 0.8, 0.8 );
insilmaril@408
  3143
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3144
	}	
insilmaril@0
  3145
}
insilmaril@89
  3146
insilmaril@526
  3147
void Main::viewCenter()
insilmaril@526
  3148
{
insilmaril@526
  3149
	MapEditor *me=currentMapEditor();
insilmaril@526
  3150
	if (me)
insilmaril@526
  3151
	{
insilmaril@526
  3152
		me->ensureSelectionVisible();
insilmaril@526
  3153
	}	
insilmaril@526
  3154
}
insilmaril@526
  3155
insilmaril@528
  3156
void Main::networkStartServer()
insilmaril@528
  3157
{
insilmaril@528
  3158
	MapEditor *me=currentMapEditor();
insilmaril@528
  3159
	if (me) me->newServer();
insilmaril@528
  3160
}
insilmaril@528
  3161
insilmaril@528
  3162
void Main::networkConnect()
insilmaril@528
  3163
{
insilmaril@528
  3164
	MapEditor *me=currentMapEditor();
insilmaril@531
  3165
	if (me) me->connectToServer();
insilmaril@528
  3166
}
insilmaril@528
  3167
insilmaril@0
  3168
bool Main::settingsPDF()
insilmaril@0
  3169
{
insilmaril@0
  3170
	// Default browser is set in constructor
insilmaril@0
  3171
	bool ok;
insilmaril@0
  3172
	QString text = QInputDialog::getText(
insilmaril@266
  3173
		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
insilmaril@366
  3174
		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
insilmaril@0
  3175
	if (ok)
insilmaril@366
  3176
		settings.setValue ("/mainwindow/readerPDF",text);
insilmaril@0
  3177
	return ok;
insilmaril@0
  3178
}
insilmaril@0
  3179
insilmaril@0
  3180
insilmaril@0
  3181
bool Main::settingsURL()
insilmaril@0
  3182
{
insilmaril@0
  3183
	// Default browser is set in constructor
insilmaril@0
  3184
	bool ok;
insilmaril@0
  3185
	QString text = QInputDialog::getText(
insilmaril@266
  3186
		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
insilmaril@366
  3187
		settings.value("/mainwindow/readerURL").toString()
insilmaril@0
  3188
		, &ok, this );
insilmaril@0
  3189
	if (ok)
insilmaril@366
  3190
		settings.setValue ("/mainwindow/readerURL",text);
insilmaril@0
  3191
	return ok;
insilmaril@0
  3192
}
insilmaril@0
  3193
insilmaril@450
  3194
void Main::settingsMacroDir()
insilmaril@450
  3195
{
insilmaril@450
  3196
	QDir defdir=vymBaseDir;
insilmaril@450
  3197
	defdir.cd("macros");
insilmaril@450
  3198
	if (!defdir.exists())
insilmaril@450
  3199
		defdir=vymBaseDir;
insilmaril@450
  3200
	QDir dir=QFileDialog::getExistingDirectory (
insilmaril@450
  3201
		this,
insilmaril@450
  3202
		tr ("Directory with vym macros:"), 
insilmaril@450
  3203
		settings.value ("/macros/macroDir",defdir.path()).toString()
insilmaril@450
  3204
	);
insilmaril@450
  3205
	if (dir.exists())
insilmaril@450
  3206
		settings.setValue ("/macros/macroDir",dir.path());
insilmaril@450
  3207
}
insilmaril@450
  3208
insilmaril@473
  3209
void Main::settingsUndoLevels()
insilmaril@473
  3210
{
insilmaril@473
  3211
	bool ok;
insilmaril@473
  3212
	int i = QInputDialog::getInteger(
insilmaril@473
  3213
		this, 
insilmaril@473
  3214
		tr("QInputDialog::getInteger()"),
insilmaril@473
  3215
	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
insilmaril@473
  3216
	if (ok)
insilmaril@473
  3217
	{
insilmaril@473
  3218
		settings.setValue ("/mapeditor/stepsTotal",i);
insilmaril@473
  3219
		QMessageBox::information( this, tr( "VYM -Information:" ),
insilmaril@473
  3220
		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
insilmaril@473
  3221
   }	
insilmaril@473
  3222
}
insilmaril@473
  3223
insilmaril@473
  3224
void Main::settingsAutosaveToggle()
insilmaril@473
  3225
{
insilmaril@531
  3226
	settings.setValue ("/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
insilmaril@473
  3227
}
insilmaril@473
  3228
insilmaril@473
  3229
void Main::settingsAutosaveTime()
insilmaril@473
  3230
{
insilmaril@473
  3231
	bool ok;
insilmaril@473
  3232
	int i = QInputDialog::getInteger(
insilmaril@473
  3233
		this, 
insilmaril@473
  3234
		tr("QInputDialog::getInteger()"),
insilmaril@473
  3235
	    tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
insilmaril@473
  3236
	if (ok)
insilmaril@473
  3237
	{
insilmaril@473
  3238
		settings.setValue ("/mapeditor/autosave/ms",i * 1000);
insilmaril@473
  3239
    }	
insilmaril@473
  3240
}
insilmaril@473
  3241
insilmaril@327
  3242
void Main::settingsToggleDelKey()
insilmaril@327
  3243
{
insilmaril@327
  3244
	if (actionSettingsUseDelKey->isOn())
insilmaril@327
  3245
	{
insilmaril@366
  3246
		actionEditDelete->setAccel (QKeySequence (Qt::Key_Delete));
insilmaril@327
  3247
	} else
insilmaril@327
  3248
	{
insilmaril@327
  3249
		actionEditDelete->setAccel (QKeySequence (""));
insilmaril@327
  3250
	}
insilmaril@327
  3251
}
insilmaril@327
  3252
insilmaril@0
  3253
void Main::windowToggleNoteEditor()
insilmaril@0
  3254
{
insilmaril@502
  3255
	if (textEditor->isVisible() )
insilmaril@497
  3256
		windowHideNoteEditor();
insilmaril@497
  3257
	else
insilmaril@497
  3258
		windowShowNoteEditor();
insilmaril@0
  3259
}
insilmaril@0
  3260
insilmaril@294
  3261
void Main::windowToggleHistory()
insilmaril@294
  3262
{
insilmaril@404
  3263
	if (historyWindow->isVisible())
insilmaril@404
  3264
		historyWindow->hide();
insilmaril@404
  3265
	else	
insilmaril@404
  3266
		historyWindow->show();
insilmaril@404
  3267
insilmaril@404
  3268
}
insilmaril@404
  3269
insilmaril@473
  3270
void Main::windowToggleProperty()
insilmaril@473
  3271
{
insilmaril@473
  3272
	if (branchPropertyWindow->isVisible())
insilmaril@473
  3273
		branchPropertyWindow->hide();
insilmaril@473
  3274
	else	
insilmaril@473
  3275
		branchPropertyWindow->show();
insilmaril@486
  3276
insilmaril@473
  3277
	if(currentMapEditor())
insilmaril@473
  3278
	{
insilmaril@473
  3279
		LinkableMapObj *sel=currentMapEditor()->getSelection();
insilmaril@473
  3280
		if (sel && (typeid(*sel) == typeid(BranchObj) ||
insilmaril@473
  3281
		           typeid(*sel) == typeid(MapCenterObj)))
insilmaril@473
  3282
		{
insilmaril@473
  3283
			branchPropertyWindow->setMapEditor(currentMapEditor());
insilmaril@473
  3284
			branchPropertyWindow->setBranch((BranchObj*)sel);
insilmaril@473
  3285
			return;
insilmaril@473
  3286
		}
insilmaril@473
  3287
		
insilmaril@473
  3288
	}	
insilmaril@473
  3289
	branchPropertyWindow->setBranch(NULL);
insilmaril@473
  3290
}
insilmaril@473
  3291
insilmaril@408
  3292
void Main::windowToggleAntiAlias()
insilmaril@408
  3293
{
insilmaril@408
  3294
	bool b=actionViewToggleAntiAlias->isOn();
insilmaril@408
  3295
	MapEditor *me;
insilmaril@408
  3296
	for (int i=0;i<tabWidget->count();i++)
insilmaril@408
  3297
	{
insilmaril@408
  3298
		
insilmaril@408
  3299
		me=(MapEditor*)tabWidget->page(i);
insilmaril@408
  3300
		me->setAntiAlias(b);
insilmaril@408
  3301
	}	
insilmaril@408
  3302
insilmaril@408
  3303
}
insilmaril@408
  3304
insilmaril@408
  3305
void Main::windowToggleSmoothPixmap()
insilmaril@408
  3306
{
insilmaril@408
  3307
	bool b=actionViewToggleSmoothPixmapTransform->isOn();
insilmaril@408
  3308
	MapEditor *me;
insilmaril@408
  3309
	for (int i=0;i<tabWidget->count();i++)
insilmaril@408
  3310
	{
insilmaril@408
  3311
		
insilmaril@408
  3312
		me=(MapEditor*)tabWidget->page(i);
insilmaril@408
  3313
		me->setSmoothPixmap(b);
insilmaril@408
  3314
	}	
insilmaril@408
  3315
}
insilmaril@408
  3316
insilmaril@404
  3317
void Main::updateHistory(SimpleSettings &undoSet)
insilmaril@404
  3318
{
insilmaril@404
  3319
	historyWindow->update (undoSet);
insilmaril@294
  3320
}
insilmaril@294
  3321
insilmaril@160
  3322
void Main::updateNoteFlag()
insilmaril@160
  3323
{
insilmaril@160
  3324
	if (currentMapEditor())
insilmaril@160
  3325
		currentMapEditor()->updateNoteFlag();
insilmaril@160
  3326
}
insilmaril@160
  3327
insilmaril@442
  3328
void Main::updateSatellites(MapEditor *me)
insilmaril@442
  3329
{
insilmaril@442
  3330
	branchPropertyWindow->setMapEditor (me);
insilmaril@442
  3331
}
insilmaril@442
  3332
insilmaril@390
  3333
void Main::updateActions()
insilmaril@390
  3334
{
insilmaril@390
  3335
	MapEditor *me=currentMapEditor();
insilmaril@390
  3336
	if (!me) return;
insilmaril@390
  3337
insilmaril@491
  3338
	historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(currentMapEditor()->getFileName()));
insilmaril@407
  3339
insilmaril@390
  3340
	// updateActions is also called when NoteEditor is closed
insilmaril@486
  3341
	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
insilmaril@486
  3342
	actionViewToggleHistoryWindow->setOn (historyWindow->isVisible());
insilmaril@486
  3343
	actionViewTogglePropertyWindow->setOn (branchPropertyWindow->isVisible());
insilmaril@390
  3344
insilmaril@473
  3345
	if (me->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
insilmaril@390
  3346
		actionFormatLinkColorHint->setOn(true);
insilmaril@390
  3347
	else	
insilmaril@390
  3348
		actionFormatLinkColorHint->setOn(false);
insilmaril@390
  3349
insilmaril@398
  3350
	switch (me->getMapLinkStyle())
insilmaril@390
  3351
	{
insilmaril@473
  3352
		case LinkableMapObj::Line: 
insilmaril@390
  3353
			actionFormatLinkStyleLine->setOn(true);
insilmaril@390
  3354
			break;
insilmaril@473
  3355
		case LinkableMapObj::Parabel:
insilmaril@390
  3356
			actionFormatLinkStyleParabel->setOn(true);
insilmaril@390
  3357
			break;
insilmaril@473
  3358
		case LinkableMapObj::PolyLine:	
insilmaril@390
  3359
			actionFormatLinkStylePolyLine->setOn(true);
insilmaril@390
  3360
			break;
insilmaril@473
  3361
		case LinkableMapObj::PolyParabel:	
insilmaril@390
  3362
			actionFormatLinkStylePolyParabel->setOn(true);
insilmaril@390
  3363
			break;
insilmaril@390
  3364
		default:
insilmaril@390
  3365
			break;
insilmaril@390
  3366
	}	
insilmaril@390
  3367
insilmaril@442
  3368
	// Update colors
insilmaril@390
  3369
	QPixmap pix( 16, 16 );
insilmaril@398
  3370
    pix.fill( me->getMapBackgroundColor() );
insilmaril@390
  3371
    actionFormatBackColor->setIconSet( pix );
insilmaril@442
  3372
    pix.fill( me->getSelectionColor() );
insilmaril@442
  3373
    actionFormatSelectionColor->setIconSet( pix );
insilmaril@398
  3374
    pix.fill( me->getMapDefLinkColor() );
insilmaril@390
  3375
    actionFormatLinkColor->setIconSet( pix );
insilmaril@390
  3376
insilmaril@442
  3377
insilmaril@486
  3378
	actionFileSave->setEnabled( me->hasChanged() );
insilmaril@390
  3379
	if (me->isUndoAvailable())
insilmaril@390
  3380
		actionEditUndo->setEnabled( true);
insilmaril@390
  3381
	else	
insilmaril@390
  3382
		actionEditUndo->setEnabled( false);
insilmaril@390
  3383
insilmaril@390
  3384
	if (me->isRedoAvailable())
insilmaril@390
  3385
		actionEditRedo->setEnabled( true);
insilmaril@390
  3386
	else	
insilmaril@390
  3387
		actionEditRedo->setEnabled( false);
insilmaril@390
  3388
insilmaril@390
  3389
	LinkableMapObj *selection=me->getSelection();
insilmaril@390
  3390
	if (selection)
insilmaril@390
  3391
	{
insilmaril@390
  3392
		if ( (typeid(*selection) == typeid(BranchObj)) || 
insilmaril@390
  3393
			(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@390
  3394
		{
insilmaril@390
  3395
			BranchObj *bo=(BranchObj*)selection;
insilmaril@390
  3396
			// Take care of links
insilmaril@390
  3397
			if (bo->countXLinks()==0)
insilmaril@390
  3398
			{
insilmaril@390
  3399
				branchXLinksContextMenuEdit->clear();
insilmaril@390
  3400
				branchXLinksContextMenuFollow->clear();
insilmaril@390
  3401
			} else
insilmaril@390
  3402
			{
insilmaril@390
  3403
				BranchObj *bot;
insilmaril@390
  3404
				QString s;
insilmaril@390
  3405
				branchXLinksContextMenuEdit->clear();
insilmaril@390
  3406
				branchXLinksContextMenuFollow->clear();
insilmaril@390
  3407
				for (int i=0; i<=bo->countXLinks();i++)
insilmaril@390
  3408
				{
insilmaril@390
  3409
					bot=bo->XLinkTargetAt(i);
insilmaril@390
  3410
					if (bot)
insilmaril@390
  3411
					{
insilmaril@390
  3412
						s=bot->getHeading();
insilmaril@390
  3413
						if (s.length()>25)
insilmaril@390
  3414
							s=s.left(25)+"...";
insilmaril@390
  3415
						branchXLinksContextMenuFollow->addAction (s);
insilmaril@390
  3416
						branchXLinksContextMenuEdit->addAction (s);
insilmaril@390
  3417
					}	
insilmaril@390
  3418
				}
insilmaril@390
  3419
			}
insilmaril@390
  3420
insilmaril@390
  3421
			standardFlagsDefault->setEnabled (true);
insilmaril@390
  3422
insilmaril@390
  3423
			actionEditToggleScroll->setEnabled (true);
insilmaril@390
  3424
			if ( bo->isScrolled() )
insilmaril@390
  3425
				actionEditToggleScroll->setOn(true);
insilmaril@390
  3426
			else	
insilmaril@390
  3427
				actionEditToggleScroll->setOn(false);
insilmaril@390
  3428
insilmaril@390
  3429
			if ( bo->getURL().isEmpty() )
insilmaril@390
  3430
			{
insilmaril@390
  3431
				actionEditOpenURL->setEnabled (false);
insilmaril@390
  3432
				actionEditOpenURLTab->setEnabled (false);
insilmaril@390
  3433
			}	
insilmaril@390
  3434
			else	
insilmaril@390
  3435
			{
insilmaril@390
  3436
				actionEditOpenURL->setEnabled (true);
insilmaril@390
  3437
				actionEditOpenURLTab->setEnabled (true);
insilmaril@390
  3438
			}
insilmaril@390
  3439
			if ( bo->getVymLink().isEmpty() )
insilmaril@390
  3440
			{
insilmaril@390
  3441
				actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3442
				actionEditDeleteVymLink->setEnabled (false);
insilmaril@390
  3443
			} else	
insilmaril@390
  3444
			{
insilmaril@390
  3445
				actionEditOpenVymLink->setEnabled (true);
insilmaril@390
  3446
				actionEditDeleteVymLink->setEnabled (true);
insilmaril@390
  3447
			}	
insilmaril@390
  3448
insilmaril@390
  3449
			if (bo->canMoveBranchUp()) 
insilmaril@390
  3450
				actionEditMoveUp->setEnabled (true);
insilmaril@390
  3451
			else	
insilmaril@390
  3452
				actionEditMoveUp->setEnabled (false);
insilmaril@390
  3453
			if (bo->canMoveBranchDown()) 
insilmaril@390
  3454
				actionEditMoveDown->setEnabled (true);
insilmaril@390
  3455
			else	
insilmaril@390
  3456
				actionEditMoveDown->setEnabled (false);
insilmaril@390
  3457
insilmaril@390
  3458
insilmaril@390
  3459
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@390
  3460
			actionEditToggleHideExport->setOn (bo->hideInExport() );	
insilmaril@390
  3461
insilmaril@390
  3462
			actionEditCopy->setEnabled (true);	
insilmaril@390
  3463
			actionEditCut->setEnabled (true);	
insilmaril@390
  3464
			if (!clipboardEmpty)
insilmaril@390
  3465
				actionEditPaste->setEnabled (true);	
insilmaril@390
  3466
			else	
insilmaril@390
  3467
				actionEditPaste->setEnabled (false);	
insilmaril@406
  3468
			for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3469
				actionListBranches.at(i)->setEnabled(true);
insilmaril@390
  3470
			actionEditDelete->setEnabled (true);
insilmaril@390
  3471
			actionFormatHideLinkUnselected->setOn
insilmaril@390
  3472
				(selection->getHideLinkUnselected());
insilmaril@390
  3473
		}
insilmaril@390
  3474
		if ( (typeid(*selection) == typeid(FloatImageObj)) )
insilmaril@390
  3475
		{
insilmaril@390
  3476
			FloatObj *fo=(FloatImageObj*)selection;
insilmaril@390
  3477
insilmaril@390
  3478
			actionEditOpenURL->setEnabled (false);
insilmaril@390
  3479
			actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3480
			actionEditDeleteVymLink->setEnabled (false);	
insilmaril@390
  3481
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@390
  3482
			actionEditToggleHideExport->setOn (fo->hideInExport() );	
insilmaril@390
  3483
insilmaril@390
  3484
insilmaril@390
  3485
			actionEditCopy->setEnabled (true);
insilmaril@390
  3486
			actionEditCut->setEnabled (true);	
insilmaril@390
  3487
			actionEditPaste->setEnabled (false);
insilmaril@406
  3488
			for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3489
				actionListBranches.at(i)->setEnabled(false);
insilmaril@390
  3490
			actionEditDelete->setEnabled (true);
insilmaril@390
  3491
			actionFormatHideLinkUnselected->setOn
insilmaril@390
  3492
				( selection->getHideLinkUnselected());
insilmaril@390
  3493
			actionEditMoveUp->setEnabled (false);
insilmaril@390
  3494
			actionEditMoveDown->setEnabled (false);
insilmaril@390
  3495
		}
insilmaril@390
  3496
insilmaril@390
  3497
	} else
insilmaril@390
  3498
	{
insilmaril@390
  3499
		actionEditCopy->setEnabled (false);	
insilmaril@390
  3500
		actionEditCut->setEnabled (false);	
insilmaril@390
  3501
		actionEditPaste->setEnabled (false);	
insilmaril@406
  3502
		for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3503
			actionListBranches.at(i)->setEnabled(false);
insilmaril@390
  3504
insilmaril@390
  3505
		actionEditToggleScroll->setEnabled (false);
insilmaril@390
  3506
		actionEditOpenURL->setEnabled (false);
insilmaril@390
  3507
		actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3508
		actionEditDeleteVymLink->setEnabled (false);	
insilmaril@390
  3509
		actionEditHeading2URL->setEnabled (false);	
insilmaril@390
  3510
		actionEditDelete->setEnabled (false);
insilmaril@390
  3511
		actionEditMoveUp->setEnabled (false);
insilmaril@390
  3512
		actionEditMoveDown->setEnabled (false);
insilmaril@390
  3513
		actionEditToggleHideExport->setEnabled (false);	
insilmaril@390
  3514
	}	
insilmaril@390
  3515
}
insilmaril@390
  3516
insilmaril@473
  3517
Main::ModMode Main::getModMode()
insilmaril@390
  3518
{
insilmaril@390
  3519
	if (actionModModeColor->isOn()) return ModModeColor;
insilmaril@390
  3520
	if (actionModModeCopy->isOn()) return ModModeCopy;
insilmaril@390
  3521
	if (actionModModeXLink->isOn()) return ModModeXLink;
insilmaril@390
  3522
	return ModModeNone;
insilmaril@390
  3523
}
insilmaril@390
  3524
insilmaril@537
  3525
bool Main::autoEditNewBranch()
insilmaril@390
  3526
{
insilmaril@537
  3527
	return actionSettingsAutoEditNewBranch->isOn();
insilmaril@390
  3528
}
insilmaril@390
  3529
insilmaril@537
  3530
bool Main::autoSelectNewBranch()
insilmaril@390
  3531
{
insilmaril@537
  3532
	return actionSettingsAutoSelectNewBranch->isOn();
insilmaril@390
  3533
}
insilmaril@390
  3534
insilmaril@390
  3535
bool Main::useFlagGroups()
insilmaril@390
  3536
{
insilmaril@390
  3537
	return actionSettingsUseFlagGroups->isOn();
insilmaril@390
  3538
}
insilmaril@390
  3539
insilmaril@0
  3540
void Main::windowShowNoteEditor()
insilmaril@0
  3541
{
insilmaril@497
  3542
	textEditor->setShowWithMain(true);
insilmaril@0
  3543
	textEditor->show();
insilmaril@0
  3544
	actionViewToggleNoteEditor->setOn (true);
insilmaril@0
  3545
}
insilmaril@0
  3546
insilmaril@0
  3547
void Main::windowHideNoteEditor()
insilmaril@0
  3548
{
insilmaril@497
  3549
	textEditor->setShowWithMain(false);
insilmaril@0
  3550
	textEditor->hide();
insilmaril@0
  3551
	actionViewToggleNoteEditor->setOn (false);
insilmaril@0
  3552
}
insilmaril@0
  3553
insilmaril@434
  3554
void Main::setScript (const QString &script)
insilmaril@434
  3555
{
insilmaril@434
  3556
	scriptEditor->setScript (script);
insilmaril@434
  3557
}
insilmaril@434
  3558
insilmaril@434
  3559
void Main::runScript (const QString &script)
insilmaril@432
  3560
{
insilmaril@432
  3561
	if (currentMapEditor())
insilmaril@432
  3562
		currentMapEditor()->runScript (script);
insilmaril@432
  3563
}
insilmaril@432
  3564
insilmaril@514
  3565
void Main::runScriptEverywhere (const QString &script)
insilmaril@514
  3566
{
insilmaril@514
  3567
	MapEditor *me;
insilmaril@514
  3568
	for (int i=0;i<=tabWidget->count() -1;i++)
insilmaril@514
  3569
	{
insilmaril@514
  3570
		me=(MapEditor*)tabWidget->page(i);
insilmaril@514
  3571
		if (me) me->runScript (script);
insilmaril@514
  3572
	}	
insilmaril@514
  3573
}
insilmaril@514
  3574
insilmaril@0
  3575
void Main::windowNextEditor()
insilmaril@0
  3576
{
insilmaril@0
  3577
	if (tabWidget->currentPageIndex() < tabWidget->count())
insilmaril@0
  3578
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
insilmaril@0
  3579
}
insilmaril@0
  3580
insilmaril@0
  3581
void Main::windowPreviousEditor()
insilmaril@0
  3582
{
insilmaril@0
  3583
	if (tabWidget->currentPageIndex() >0)
insilmaril@0
  3584
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
insilmaril@0
  3585
}
insilmaril@0
  3586
insilmaril@0
  3587
void Main::standardFlagChanged()
insilmaril@0
  3588
{
insilmaril@421
  3589
	if (currentMapEditor())
insilmaril@421
  3590
		currentMapEditor()->toggleStandardFlag(sender()->name());
insilmaril@0
  3591
}
insilmaril@0
  3592
insilmaril@527
  3593
void Main::testFunction1()
insilmaril@0
  3594
{
insilmaril@393
  3595
	if (!currentMapEditor()) return;
insilmaril@564
  3596
	currentMapEditor()->testFunction1();
insilmaril@527
  3597
}
insilmaril@527
  3598
insilmaril@527
  3599
void Main::testFunction2()
insilmaril@527
  3600
{
insilmaril@527
  3601
	if (!currentMapEditor()) return;
insilmaril@564
  3602
	currentMapEditor()->testFunction2();
insilmaril@0
  3603
}
insilmaril@0
  3604
insilmaril@393
  3605
void Main::testCommand()
insilmaril@393
  3606
{
insilmaril@393
  3607
	if (!currentMapEditor()) return;
insilmaril@432
  3608
	scriptEditor->show();
insilmaril@432
  3609
	/*
insilmaril@393
  3610
	bool ok;
insilmaril@393
  3611
	QString com = QInputDialog::getText(
insilmaril@404
  3612
			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
insilmaril@393
  3613
	if (ok) currentMapEditor()->parseAtom(com);
insilmaril@432
  3614
	*/
insilmaril@393
  3615
}
insilmaril@393
  3616
insilmaril@0
  3617
void Main::helpDoc()
insilmaril@0
  3618
{
insilmaril@395
  3619
	QString locale = QLocale::system().name();
insilmaril@395
  3620
	QString docname;
insilmaril@395
  3621
	if (locale.left(2)=="es")
insilmaril@395
  3622
		docname="vym_es.pdf";
insilmaril@395
  3623
	else	
insilmaril@395
  3624
		docname="vym.pdf";
insilmaril@420
  3625
insilmaril@420
  3626
	QStringList searchList;
insilmaril@395
  3627
	QDir docdir;
insilmaril@103
  3628
	#if defined(Q_OS_MACX)
insilmaril@537
  3629
		searchList << "./vym.app/Contents/Resources/doc";
insilmaril@103
  3630
	#else
insilmaril@103
  3631
		// default path in SUSE LINUX
insilmaril@420
  3632
		searchList <<"/usr/share/doc/packages/vym/doc";
insilmaril@103
  3633
	#endif
insilmaril@0
  3634
insilmaril@420
  3635
	searchList << "doc";	// relative path for easy testing in tarball
insilmaril@420
  3636
	searchList << "doc/tex";	// Easy testing working on vym.tex
insilmaril@420
  3637
	searchList << "/usr/share/doc/vym";	// Debian
insilmaril@420
  3638
	searchList << "/usr/share/doc/packages";// Knoppix
insilmaril@420
  3639
insilmaril@420
  3640
	bool found=false;
insilmaril@420
  3641
	QFile docfile;
insilmaril@420
  3642
	for (int i=0; i<searchList.count(); ++i)
insilmaril@0
  3643
	{
insilmaril@420
  3644
		docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
insilmaril@420
  3645
		if (docfile.exists() )
insilmaril@0
  3646
		{
insilmaril@420
  3647
			found=true;
insilmaril@420
  3648
			break;
insilmaril@420
  3649
		}	
insilmaril@420
  3650
insilmaril@0
  3651
	}
insilmaril@420
  3652
	if (!found)
insilmaril@420
  3653
	{
insilmaril@420
  3654
		QMessageBox::critical(0, 
insilmaril@420
  3655
			tr("Critcal error"),
insilmaril@420
  3656
			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
insilmaril@420
  3657
		return;
insilmaril@420
  3658
	}	
insilmaril@420
  3659
insilmaril@408
  3660
	QStringList args;
insilmaril@0
  3661
	Process *pdfProc = new Process();
insilmaril@420
  3662
	args <<docfile.fileName();
insilmaril@420
  3663
insilmaril@420
  3664
	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
insilmaril@408
  3665
	if ( !pdfProc->waitForStarted() ) 
insilmaril@0
  3666
	{
insilmaril@0
  3667
		// error handling
insilmaril@266
  3668
		QMessageBox::warning(0, 
insilmaril@266
  3669
			tr("Warning"),
insilmaril@420
  3670
			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
insilmaril@266
  3671
			tr("Please use Settings->")+tr("Set application to open PDF files"));
insilmaril@266
  3672
		settingsPDF();	
insilmaril@0
  3673
		return;
insilmaril@0
  3674
	}
insilmaril@0
  3675
}
insilmaril@0
  3676
insilmaril@0
  3677
insilmaril@505
  3678
void Main::helpDemo()
insilmaril@505
  3679
{
insilmaril@505
  3680
	QStringList filters;
insilmaril@505
  3681
	filters <<"VYM example map (*.vym)";
insilmaril@505
  3682
	QFileDialog *fd=new QFileDialog( this);
insilmaril@505
  3683
	fd->setDir (QDir(vymBaseDir.path()+"/demos"));
insilmaril@505
  3684
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@505
  3685
	fd->setFilters (filters);
insilmaril@505
  3686
	fd->setCaption(vymName+ " - " +tr("Load vym example map"));
insilmaril@505
  3687
	fd->show();
insilmaril@505
  3688
insilmaril@505
  3689
	QString fn;
insilmaril@505
  3690
	if ( fd->exec() == QDialog::Accepted )
insilmaril@505
  3691
	{
insilmaril@505
  3692
		lastFileDir=fd->directory().path();
insilmaril@505
  3693
	    QStringList flist = fd->selectedFiles();
insilmaril@505
  3694
		QStringList::Iterator it = flist.begin();
insilmaril@505
  3695
		while( it != flist.end() ) 
insilmaril@505
  3696
		{
insilmaril@505
  3697
			fn = *it;
insilmaril@505
  3698
			fileLoad(*it, NewMap);				   
insilmaril@505
  3699
			++it;
insilmaril@505
  3700
		}
insilmaril@505
  3701
	}
insilmaril@505
  3702
	delete (fd);
insilmaril@505
  3703
}
insilmaril@505
  3704
insilmaril@505
  3705
insilmaril@0
  3706
void Main::helpAbout()
insilmaril@0
  3707
{
insilmaril@148
  3708
	AboutDialog ad;
insilmaril@150
  3709
	ad.setName ("aboutwindow");
insilmaril@148
  3710
	ad.setMinimumSize(500,500);
insilmaril@148
  3711
	ad.resize (QSize (500,500));
insilmaril@148
  3712
	ad.exec();
insilmaril@0
  3713
}
insilmaril@0
  3714
insilmaril@0
  3715
void Main::helpAboutQT()
insilmaril@0
  3716
{
insilmaril@0
  3717
	QMessageBox::aboutQt( this, "Qt Application Example" );
insilmaril@0
  3718
}
insilmaril@0
  3719
insilmaril@445
  3720
void Main::callMacro ()
insilmaril@445
  3721
{
insilmaril@445
  3722
    QAction *action = qobject_cast<QAction *>(sender());
insilmaril@445
  3723
	int i=-1;
insilmaril@445
  3724
    if (action)
insilmaril@445
  3725
	{
insilmaril@445
  3726
        i=action->data().toInt();
insilmaril@447
  3727
		QString mDir (settings.value ("macros/macroDir").toString() );
insilmaril@447
  3728
insilmaril@447
  3729
		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
insilmaril@447
  3730
		QFile f (fn);
insilmaril@447
  3731
		if ( !f.open( QIODevice::ReadOnly ) )
insilmaril@447
  3732
		{
insilmaril@447
  3733
			QMessageBox::warning(0, 
insilmaril@447
  3734
				tr("Warning"),
insilmaril@447
  3735
				tr("Couldn't find a macro at  %1.\n").arg(fn)+
insilmaril@447
  3736
				tr("Please use Settings->")+tr("Set directory for vym macros"));
insilmaril@447
  3737
			return;
insilmaril@447
  3738
		}	
insilmaril@447
  3739
insilmaril@447
  3740
		QTextStream ts( &f );
insilmaril@447
  3741
		QString m= ts.read();
insilmaril@447
  3742
insilmaril@445
  3743
		if (! m.isEmpty())
insilmaril@445
  3744
		{
insilmaril@447
  3745
			//cout <<"Main::callMacro  m="<<m.ascii()<<endl;
insilmaril@445
  3746
			currentMapEditor()->runScript (m);
insilmaril@445
  3747
		}	
insilmaril@445
  3748
	}	
insilmaril@445
  3749
}
insilmaril@445
  3750