mainwindow.cpp
author insilmaril
Sun, 26 Aug 2007 12:16:26 +0000
changeset 587 83d00d979f16
parent 585 a8e9eae855f4
child 595 0bd62e09d061
permissions -rw-r--r--
changed searchpath for documentation SUSE Linux
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@585
  1135
	setupFlag (fo,tb,avis,"smiley-sad",tr("Bad","Standardflag"));
insilmaril@166
  1136
insilmaril@408
  1137
	fo->load(flagsPath+"flag-smiley-omg.png");
insilmaril@582
  1138
	fo->setGroup("standard-smiley");
insilmaril@582
  1139
	setupFlag (fo,tb,avis,"smiley-omb",tr("Oh no!","Standardflag"));
insilmaril@269
  1140
	// Original omg.png (in KDE emoticons)
insilmaril@582
  1141
	fo->unsetGroup();
insilmaril@269
  1142
insilmaril@408
  1143
	fo->load(flagsPath+"flag-kalarm.png");
insilmaril@582
  1144
	setupFlag (fo,tb,avis,"clock",tr("Time critical","Standardflag"));
insilmaril@166
  1145
insilmaril@408
  1146
	fo->load(flagsPath+"flag-phone.png");
insilmaril@582
  1147
	setupFlag (fo,tb,avis,"phone",tr("Call...","Standardflag"));
insilmaril@269
  1148
insilmaril@408
  1149
	fo->load(flagsPath+"flag-lamp.png");
insilmaril@582
  1150
	setupFlag (fo,tb,avis,"lamp",tr("Idea!","Standardflag"));
insilmaril@166
  1151
insilmaril@408
  1152
	fo->load(flagsPath+"flag-arrow-up.png");
insilmaril@166
  1153
	fo->setGroup("standard-arrow");
insilmaril@582
  1154
	setupFlag (fo,tb,avis,"arrow-up",tr("Important","Standardflag"));
insilmaril@166
  1155
insilmaril@408
  1156
	fo->load(flagsPath+"flag-arrow-down.png");
insilmaril@166
  1157
	fo->setGroup("standard-arrow");
insilmaril@582
  1158
	setupFlag (fo,tb,avis,"arrow-down",tr("Unimportant","Standardflag"));
insilmaril@166
  1159
insilmaril@408
  1160
	fo->load(flagsPath+"flag-arrow-2up.png");
insilmaril@269
  1161
	fo->setGroup("standard-arrow");
insilmaril@582
  1162
	setupFlag (fo,tb,avis,"2arrow-up",tr("Very important!","Standardflag"));
insilmaril@269
  1163
insilmaril@408
  1164
	fo->load(flagsPath+"flag-arrow-2down.png");
insilmaril@269
  1165
	fo->setGroup("standard-arrow");
insilmaril@582
  1166
	setupFlag (fo,tb,avis,"present",tr("Very unimportant!","Standardflag"));
insilmaril@582
  1167
	fo->unsetGroup();
insilmaril@269
  1168
insilmaril@408
  1169
	fo->load(flagsPath+"flag-thumb-up.png");
insilmaril@166
  1170
	fo->setGroup("standard-thumb");
insilmaril@582
  1171
	setupFlag (fo,tb,avis,"thumb-up",tr("I like this","Standardflag"));
insilmaril@166
  1172
insilmaril@408
  1173
	fo->load(flagsPath+"flag-thumb-down.png");
insilmaril@166
  1174
	fo->setGroup("standard-thumb");
insilmaril@582
  1175
	setupFlag (fo,tb,avis,"thumb-down",tr("I do not like this","Standardflag"));
insilmaril@582
  1176
	fo->unsetGroup();
insilmaril@166
  1177
	
insilmaril@408
  1178
	fo->load(flagsPath+"flag-rose.png");
insilmaril@582
  1179
	setupFlag (fo,tb,avis,"rose",tr("Rose","Standardflag"));
insilmaril@269
  1180
insilmaril@408
  1181
	fo->load(flagsPath+"flag-heart.png");
insilmaril@582
  1182
	setupFlag (fo,tb,avis,"heart",tr("I just love...","Standardflag"));
insilmaril@564
  1183
insilmaril@408
  1184
	fo->load(flagsPath+"flag-present.png");
insilmaril@582
  1185
	setupFlag (fo,tb,avis,"present",tr("Surprise!","Standardflag"));
insilmaril@564
  1186
insilmaril@564
  1187
	fo->load(flagsPath+"flag-flash.png");
insilmaril@582
  1188
	setupFlag (fo,tb,avis,"flash",tr("Dangerous","Standardflag"));
insilmaril@564
  1189
	
insilmaril@564
  1190
	// Original: xsldbg_output.png
insilmaril@564
  1191
	fo->load(flagsPath+"flag-info.png");
insilmaril@582
  1192
	setupFlag (fo,tb,avis,"info",tr("Info","Standardflag"));
insilmaril@564
  1193
insilmaril@564
  1194
	// Original khelpcenter.png
insilmaril@564
  1195
	fo->load(flagsPath+"flag-lifebelt.png");
insilmaril@582
  1196
	setupFlag (fo,tb,avis,"lifebelt",tr("This will help","Standardflag"));
insilmaril@564
  1197
insilmaril@564
  1198
	// Freemind flags
insilmaril@564
  1199
insilmaril@582
  1200
	avis=false;
insilmaril@582
  1201
insilmaril@564
  1202
	fo->load(flagsPath+"freemind/warning.png");
insilmaril@582
  1203
	setupFlag (fo,tb, avis, "freemind-warning",tr("Important","Freemind-Flag"));
insilmaril@564
  1204
insilmaril@564
  1205
	for (int i=1; i<8; i++)
insilmaril@564
  1206
	{
insilmaril@564
  1207
		fo->load(flagsPath+QString("freemind/priority-%1.png").arg(i));
insilmaril@582
  1208
		setupFlag (fo,tb, avis,QString("freemind-priority-%1").arg(i),tr("Priority","Freemind-Flag"));
insilmaril@564
  1209
	}
insilmaril@564
  1210
insilmaril@564
  1211
	fo->load(flagsPath+"freemind/back.png");
insilmaril@582
  1212
	setupFlag (fo,tb,avis,"freemind-back",tr("Back","Freemind-Flag"));
insilmaril@564
  1213
insilmaril@564
  1214
	fo->load(flagsPath+"freemind/forward.png");
insilmaril@582
  1215
	setupFlag (fo,tb,avis,"freemind-forward",tr("Forward","Freemind-Flag"));
insilmaril@564
  1216
insilmaril@564
  1217
	fo->load(flagsPath+"freemind/attach.png");
insilmaril@582
  1218
	setupFlag (fo,tb,avis,"freemind-attach",tr("Look here","Freemind-Flag"));
insilmaril@564
  1219
insilmaril@564
  1220
	fo->load(flagsPath+"freemind/clanbomber.png");
insilmaril@582
  1221
	setupFlag (fo,tb,avis,"freemind-clanbomber",tr("Dangerous","Freemind-Flag"));
insilmaril@564
  1222
insilmaril@564
  1223
	fo->load(flagsPath+"freemind/desktopnew.png");
insilmaril@582
  1224
	setupFlag (fo,tb,avis,"freemind-desktopnew",tr("Don't forget","Freemind-Flag"));
insilmaril@564
  1225
insilmaril@564
  1226
	fo->load(flagsPath+"freemind/flag.png");
insilmaril@582
  1227
	setupFlag (fo,tb,avis,"freemind-flag",tr("Flag","Freemind-Flag"));
insilmaril@564
  1228
insilmaril@564
  1229
insilmaril@564
  1230
	fo->load(flagsPath+"freemind/gohome.png");
insilmaril@582
  1231
	setupFlag (fo,tb,avis,"freemind-gohome",tr("Home","Freemind-Flag"));
insilmaril@564
  1232
insilmaril@564
  1233
insilmaril@564
  1234
	fo->load(flagsPath+"freemind/kaddressbook.png");
insilmaril@582
  1235
	setupFlag (fo,tb,avis,"freemind-kaddressbook",tr("Telephone","Freemind-Flag"));
insilmaril@564
  1236
insilmaril@564
  1237
	fo->load(flagsPath+"freemind/knotify.png");
insilmaril@582
  1238
	setupFlag (fo,tb,avis,"freemind-knotify",tr("Music","Freemind-Flag"));
insilmaril@564
  1239
insilmaril@564
  1240
	fo->load(flagsPath+"freemind/korn.png");
insilmaril@582
  1241
	setupFlag (fo,tb,avis,"freemind-korn",tr("Mailbox","Freemind-Flag"));
insilmaril@564
  1242
insilmaril@564
  1243
	fo->load(flagsPath+"freemind/mail.png");
insilmaril@582
  1244
	setupFlag (fo,tb,avis,"freemind-mail",tr("Maix","Freemind-Flag"));
insilmaril@564
  1245
insilmaril@564
  1246
	fo->load(flagsPath+"freemind/password.png");
insilmaril@582
  1247
	setupFlag (fo,tb,avis,"freemind-password",tr("Password","Freemind-Flag"));
insilmaril@564
  1248
insilmaril@564
  1249
	fo->load(flagsPath+"freemind/pencil.png");
insilmaril@582
  1250
	setupFlag (fo,tb,avis,"freemind-pencil",tr("To be improved","Freemind-Flag"));
insilmaril@564
  1251
insilmaril@564
  1252
	fo->load(flagsPath+"freemind/stop.png");
insilmaril@582
  1253
	setupFlag (fo,tb,avis,"freemind-stop",tr("Stop","Freemind-Flag"));
insilmaril@564
  1254
insilmaril@564
  1255
	fo->load(flagsPath+"freemind/wizard.png");
insilmaril@582
  1256
	setupFlag (fo,tb,avis,"freemind-wizard",tr("Magic","Freemind-Flag"));
insilmaril@564
  1257
insilmaril@564
  1258
	fo->load(flagsPath+"freemind/xmag.png");
insilmaril@582
  1259
	setupFlag (fo,tb,avis,"freemind-xmag",tr("To be discussed","Freemind-Flag"));
insilmaril@564
  1260
insilmaril@564
  1261
	fo->load(flagsPath+"freemind/bell.png");
insilmaril@582
  1262
	setupFlag (fo,tb,avis,"freemind-bell",tr("Reminder","Freemind-Flag"));
insilmaril@564
  1263
insilmaril@564
  1264
	fo->load(flagsPath+"freemind/bookmark.png");
insilmaril@582
  1265
	setupFlag (fo,tb,avis,"freemind-bookmark",tr("Excellent","Freemind-Flag"));
insilmaril@564
  1266
insilmaril@564
  1267
	fo->load(flagsPath+"freemind/penguin.png");
insilmaril@582
  1268
	setupFlag (fo,tb,avis,"freemind-penguin",tr("Linux","Freemind-Flag"));
insilmaril@564
  1269
insilmaril@564
  1270
	fo->load(flagsPath+"freemind/licq.png");
insilmaril@582
  1271
	setupFlag (fo,tb,avis,"freemind-licq",tr("Sweet","Freemind-Flag"));
insilmaril@564
  1272
insilmaril@564
  1273
	delete (fo);
insilmaril@564
  1274
}
insilmaril@564
  1275
insilmaril@582
  1276
void Main::setupFlag (FlagObj *fo, QToolBar *tb, bool aw, const QString &name, const QString &tooltip)
insilmaril@564
  1277
{
insilmaril@564
  1278
	fo->setName(name);
insilmaril@582
  1279
	fo->setToolTip (tooltip);
insilmaril@564
  1280
	QAction *a=new QAction (fo->getPixmap(),fo->getName(),this);
insilmaril@582
  1281
	if (tb)
insilmaril@582
  1282
	{
insilmaril@582
  1283
		// StandardFlag
insilmaril@582
  1284
		tb->addAction (a);
insilmaril@582
  1285
		fo->setAction (a);
insilmaril@582
  1286
		fo->setAlwaysVisible(aw);
insilmaril@582
  1287
		a->setCheckable(true);
insilmaril@582
  1288
		a->setObjectName(fo->getName());
insilmaril@582
  1289
		a->setToolTip(tooltip);
insilmaril@582
  1290
		connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
insilmaril@582
  1291
		standardFlagsDefault->addFlag (fo);	
insilmaril@582
  1292
	} else
insilmaril@582
  1293
	{
insilmaril@582
  1294
		// SystemFlag
insilmaril@582
  1295
		systemFlagsDefault->addFlag (fo);	
insilmaril@582
  1296
	}
insilmaril@0
  1297
}
insilmaril@528
  1298
// Network Actions
insilmaril@528
  1299
void Main::setupNetworkActions()
insilmaril@528
  1300
{
insilmaril@528
  1301
	if (!settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
insilmaril@528
  1302
		return;
insilmaril@528
  1303
    QMenu *netMenu = menuBar()->addMenu(  "&Network" );
insilmaril@528
  1304
insilmaril@528
  1305
	QAction *a;
insilmaril@528
  1306
insilmaril@528
  1307
    a = new QAction(  "Start TCPserver for MapEditor",this);
insilmaril@528
  1308
    //a->setStatusTip ( "Set application to open pdf files"));
insilmaril@528
  1309
	a->setShortcut ( Qt::Key_T );		//New TCP server
insilmaril@528
  1310
    connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
insilmaril@528
  1311
	netMenu->addAction (a);
insilmaril@528
  1312
insilmaril@528
  1313
    a = new QAction(  "Connect MapEditor to server",this);
insilmaril@528
  1314
    //a->setStatusTip ( "Set application to open pdf files"));
insilmaril@528
  1315
	a->setShortcut ( Qt::Key_C );		// Connect to server
insilmaril@528
  1316
    connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
insilmaril@528
  1317
	netMenu->addAction (a);
insilmaril@528
  1318
}
insilmaril@528
  1319
	
insilmaril@0
  1320
// Settings Actions
insilmaril@0
  1321
void Main::setupSettingsActions()
insilmaril@0
  1322
{
insilmaril@366
  1323
    QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ));
insilmaril@0
  1324
insilmaril@0
  1325
	QAction *a;
insilmaril@0
  1326
insilmaril@395
  1327
    a = new QAction( tr( "Set application to open pdf files","Settings action"), this);
insilmaril@366
  1328
    a->setStatusTip ( tr( "Set application to open pdf files"));
insilmaril@366
  1329
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsPDF() ) );
insilmaril@366
  1330
	settingsMenu->addAction (a);
insilmaril@366
  1331
insilmaril@395
  1332
    a = new QAction( tr( "Set application to open external links","Settings action"), this);
insilmaril@366
  1333
    a->setStatusTip( tr( "Set application to open external links"));
insilmaril@366
  1334
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
insilmaril@366
  1335
	settingsMenu->addAction (a);
insilmaril@366
  1336
insilmaril@473
  1337
    a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
insilmaril@450
  1338
    a->setStatusTip( tr( "Set path for macros"));
insilmaril@450
  1339
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
insilmaril@450
  1340
	settingsMenu->addAction (a);
insilmaril@450
  1341
insilmaril@473
  1342
    a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
insilmaril@473
  1343
    a->setStatusTip( tr( "Set number of undo levels"));
insilmaril@473
  1344
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
insilmaril@473
  1345
	settingsMenu->addAction (a);
insilmaril@473
  1346
insilmaril@366
  1347
	settingsMenu->addSeparator();
insilmaril@473
  1348
insilmaril@473
  1349
    a = new QAction( tr( "Autosave","Settings action"), this);
insilmaril@473
  1350
    a->setStatusTip( tr( "Autosave"));
insilmaril@473
  1351
	a->setToggleAction(true);
insilmaril@473
  1352
	a->setOn ( settings.value ("/mapeditor/autosave/use",true).toBool());
insilmaril@473
  1353
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveToggle() ) );
insilmaril@473
  1354
	settingsMenu->addAction (a);
insilmaril@473
  1355
	actionSettingsAutosaveToggle=a;
insilmaril@473
  1356
insilmaril@473
  1357
    a = new QAction( tr( "Autosave time","Settings action")+"...", this);
insilmaril@473
  1358
    a->setStatusTip( tr( "Autosave time"));
insilmaril@473
  1359
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
insilmaril@473
  1360
	settingsMenu->addAction (a);
insilmaril@473
  1361
	actionSettingsAutosaveTime=a;
insilmaril@473
  1362
insilmaril@473
  1363
	settingsMenu->addSeparator();
insilmaril@473
  1364
insilmaril@395
  1365
    a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
insilmaril@366
  1366
    a->setStatusTip( tr( "Edit branch after adding it" ));
insilmaril@0
  1367
	a->setToggleAction(true);
insilmaril@537
  1368
	a->setOn ( settings.value ("/mapeditor/editmode/autoEditNewBranch",true).toBool());
insilmaril@366
  1369
	settingsMenu->addAction (a);
insilmaril@537
  1370
	actionSettingsAutoEditNewBranch=a;
insilmaril@0
  1371
insilmaril@395
  1372
    a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
insilmaril@366
  1373
    a->setStatusTip( tr( "Select branch after adding it" ));
insilmaril@0
  1374
	a->setToggleAction(true);
insilmaril@537
  1375
	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectNewBranch",false).toBool() );
insilmaril@366
  1376
	settingsMenu->addAction (a);
insilmaril@537
  1377
	actionSettingsAutoSelectNewBranch=a;
insilmaril@0
  1378
	
insilmaril@395
  1379
    a= new QAction(tr( "Select existing heading","Settings action" ), this);
insilmaril@366
  1380
    a->setStatusTip( tr( "Select heading before editing" ));
insilmaril@0
  1381
	a->setToggleAction(true);
insilmaril@366
  1382
	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
insilmaril@366
  1383
	settingsMenu->addAction (a);
insilmaril@390
  1384
	actionSettingsAutoSelectText=a;
insilmaril@0
  1385
	
insilmaril@395
  1386
    a= new QAction( tr( "Delete key","Settings action" ), this);
insilmaril@366
  1387
    a->setStatusTip( tr( "Delete key for deleting branches" ));
insilmaril@0
  1388
	a->setToggleAction(true);
insilmaril@505
  1389
	a->setOn ( settings.value ("/mapeditor/editmode/useDelKey",true).toBool() );
insilmaril@366
  1390
	settingsMenu->addAction (a);
insilmaril@366
  1391
    connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
insilmaril@366
  1392
	actionSettingsUseDelKey=a;
insilmaril@366
  1393
insilmaril@395
  1394
    a= new QAction( tr( "Exclusive flags","Settings action" ), this);
insilmaril@366
  1395
    a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
insilmaril@0
  1396
	a->setToggleAction(true);
insilmaril@366
  1397
	a->setOn ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
insilmaril@366
  1398
	settingsMenu->addAction (a);
insilmaril@103
  1399
	actionSettingsUseFlagGroups=a;
insilmaril@260
  1400
	
insilmaril@395
  1401
    a= new QAction( tr( "Use hide flags","Settings action" ), this);
insilmaril@366
  1402
    a->setStatusTip( tr( "Use hide flag during exports " ));
insilmaril@260
  1403
	a->setToggleAction(true);
insilmaril@366
  1404
	a->setOn ( settings.value ("/export/useHideExport",true).toBool() );
insilmaril@366
  1405
	settingsMenu->addAction (a);
insilmaril@260
  1406
	actionSettingsUseHideExport=a;
insilmaril@0
  1407
}
insilmaril@0
  1408
insilmaril@0
  1409
// Test Actions
insilmaril@0
  1410
void Main::setupTestActions()
insilmaril@0
  1411
{
insilmaril@366
  1412
    QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
insilmaril@0
  1413
insilmaril@0
  1414
    QAction *a;
insilmaril@527
  1415
    a = new QAction( "Test function 1" , this);
insilmaril@527
  1416
    a->setStatusTip( "Call test function 1" );
insilmaril@527
  1417
	testMenu->addAction (a);
insilmaril@445
  1418
	//a->setShortcut (Qt::Key_F4 );
insilmaril@527
  1419
    connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
insilmaril@527
  1420
insilmaril@527
  1421
    a = new QAction( "Test function 2" , this);
insilmaril@527
  1422
    a->setStatusTip( "Call test function 2" );
insilmaril@527
  1423
	//a->setShortcut (Qt::Key_F4 );
insilmaril@366
  1424
	testMenu->addAction (a);
insilmaril@527
  1425
    connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
insilmaril@527
  1426
insilmaril@395
  1427
    a = new QAction( "Command" , this);
insilmaril@395
  1428
    a->setStatusTip( "Enter command to call in editor" );
insilmaril@445
  1429
	//a->setShortcut (Qt::Key_F5 );
insilmaril@393
  1430
    connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
insilmaril@393
  1431
	testMenu->addAction (a);
insilmaril@0
  1432
}
insilmaril@0
  1433
insilmaril@0
  1434
// Help Actions
insilmaril@0
  1435
void Main::setupHelpActions()
insilmaril@0
  1436
{
insilmaril@395
  1437
    QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
insilmaril@0
  1438
insilmaril@0
  1439
    QAction *a;
insilmaril@395
  1440
    a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
insilmaril@366
  1441
    a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
insilmaril@366
  1442
    connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
insilmaril@366
  1443
	helpMenu->addAction (a);
insilmaril@366
  1444
insilmaril@505
  1445
    a = new QAction(  tr( "Open VYM example maps ","Help action" ), this );
insilmaril@505
  1446
    a->setStatusTip( tr( "Open VYM example maps " ));
insilmaril@505
  1447
    connect( a, SIGNAL( triggered() ), this, SLOT( helpDemo() ) );
insilmaril@505
  1448
	helpMenu->addAction (a);
insilmaril@505
  1449
insilmaril@395
  1450
    a = new QAction( tr( "About VYM","Help action" ), this);
insilmaril@404
  1451
    a->setStatusTip( tr( "About VYM")+vymName);
insilmaril@366
  1452
    connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
insilmaril@366
  1453
	helpMenu->addAction (a);
insilmaril@366
  1454
insilmaril@395
  1455
    a = new QAction( tr( "About QT","Help action" ), this);
insilmaril@366
  1456
    a->setStatusTip( tr( "Information about QT toolkit" ));
insilmaril@366
  1457
    connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
insilmaril@366
  1458
	helpMenu->addAction (a);
insilmaril@0
  1459
}
insilmaril@0
  1460
insilmaril@0
  1461
// Context Menus
insilmaril@0
  1462
void Main::setupContextMenus()
insilmaril@0
  1463
{
insilmaril@0
  1464
	QAction*a;
insilmaril@0
  1465
insilmaril@0
  1466
	// Context Menu for branch or mapcenter
insilmaril@366
  1467
	branchContextMenu =new QMenu (this);
insilmaril@486
  1468
	branchContextMenu->addAction (actionViewTogglePropertyWindow);
insilmaril@421
  1469
	branchContextMenu->addSeparator();	
insilmaril@421
  1470
insilmaril@98
  1471
		// Submenu "Add"
insilmaril@366
  1472
		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
insilmaril@366
  1473
		branchAddContextMenu->addAction (actionEditPaste );
insilmaril@366
  1474
		branchAddContextMenu->addAction ( actionEditAddBranch );
insilmaril@394
  1475
		branchAddContextMenu->addAction ( actionEditAddBranchBefore );
insilmaril@366
  1476
		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
insilmaril@366
  1477
		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
insilmaril@366
  1478
		branchAddContextMenu->addSeparator();	
insilmaril@366
  1479
		branchAddContextMenu->addAction ( actionEditImportAdd );
insilmaril@366
  1480
		branchAddContextMenu->addAction ( actionEditImportReplace );
insilmaril@98
  1481
insilmaril@98
  1482
		// Submenu "Remove"
insilmaril@395
  1483
		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
insilmaril@366
  1484
		branchRemoveContextMenu->addAction (actionEditCut);
insilmaril@366
  1485
		branchRemoveContextMenu->addAction ( actionEditDelete );
insilmaril@395
  1486
		branchRemoveContextMenu->addAction ( actionEditDeleteKeepChilds );
insilmaril@395
  1487
		branchRemoveContextMenu->addAction ( actionEditDeleteChilds );
insilmaril@98
  1488
		
insilmaril@98
  1489
insilmaril@0
  1490
	actionEditSaveBranch->addTo( branchContextMenu );
insilmaril@98
  1491
insilmaril@366
  1492
	branchContextMenu->addSeparator();	
insilmaril@398
  1493
	branchContextMenu->addAction ( actionEditLoadImage);
insilmaril@366
  1494
insilmaril@366
  1495
	// Submenu for Links (URLs, vymLinks)
insilmaril@366
  1496
	branchLinksContextMenu =new QMenu (this);
insilmaril@366
  1497
insilmaril@366
  1498
		branchContextMenu->addSeparator();	
insilmaril@473
  1499
		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
insilmaril@366
  1500
		branchLinksContextMenu->addAction ( actionEditOpenURL );
insilmaril@366
  1501
		branchLinksContextMenu->addAction ( actionEditOpenURLTab );
insilmaril@366
  1502
		branchLinksContextMenu->addAction ( actionEditOpenMultipleURLTabs );
insilmaril@366
  1503
		branchLinksContextMenu->addAction ( actionEditURL );
insilmaril@366
  1504
		branchLinksContextMenu->addAction ( actionEditHeading2URL );
insilmaril@366
  1505
		branchLinksContextMenu->addAction ( actionEditBugzilla2URL );
insilmaril@528
  1506
		if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
insilmaril@366
  1507
		{
insilmaril@366
  1508
			branchLinksContextMenu->addAction ( actionEditFATE2URL );
insilmaril@366
  1509
		}	
insilmaril@366
  1510
		branchLinksContextMenu->addSeparator();	
insilmaril@366
  1511
		branchLinksContextMenu->addAction ( actionEditOpenVymLink );
insilmaril@366
  1512
		branchLinksContextMenu->addAction ( actionEditOpenMultipleVymLinks );
insilmaril@366
  1513
		branchLinksContextMenu->addAction ( actionEditVymLink );
insilmaril@366
  1514
		branchLinksContextMenu->addAction ( actionEditDeleteVymLink );
insilmaril@366
  1515
		
insilmaril@366
  1516
insilmaril@366
  1517
	// Context Menu for XLinks in a branch menu
insilmaril@89
  1518
	// This will be populated "on demand" in MapEditor::updateActions
insilmaril@366
  1519
	branchContextMenu->addSeparator();	
insilmaril@395
  1520
	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
insilmaril@395
  1521
	branchXLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink","Context menu name"));
insilmaril@366
  1522
	connect( branchXLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), this, SLOT( editFollowXLink(QAction * ) ) );
insilmaril@366
  1523
	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
insilmaril@366
  1524
 	
insilmaril@105
  1525
	
insilmaril@0
  1526
	// Context menu for floatimage
insilmaril@366
  1527
	floatimageContextMenu =new QMenu (this);
insilmaril@395
  1528
	a= new QAction (tr ("Save image","Context action"),this);
insilmaril@366
  1529
	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
insilmaril@366
  1530
	floatimageContextMenu->addAction (a);
insilmaril@366
  1531
insilmaril@366
  1532
	floatimageContextMenu->addSeparator();	
insilmaril@0
  1533
	actionEditCopy->addTo( floatimageContextMenu );
insilmaril@0
  1534
	actionEditCut->addTo( floatimageContextMenu );
insilmaril@0
  1535
insilmaril@366
  1536
	floatimageContextMenu->addSeparator();	
insilmaril@366
  1537
	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
insilmaril@366
  1538
insilmaril@0
  1539
	
insilmaril@0
  1540
	// Context menu for canvas
insilmaril@366
  1541
	canvasContextMenu =new QMenu (this);
insilmaril@0
  1542
	actionEditMapInfo->addTo( canvasContextMenu );
insilmaril@0
  1543
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1544
	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
insilmaril@0
  1545
	canvasContextMenu->insertSeparator();	
insilmaril@0
  1546
	actionFormatLinkColorHint->addTo( canvasContextMenu );
insilmaril@0
  1547
	actionFormatLinkColor->addTo( canvasContextMenu );
insilmaril@442
  1548
	actionFormatSelectionColor->addTo( canvasContextMenu );
insilmaril@0
  1549
	actionFormatBackColor->addTo( canvasContextMenu );
insilmaril@505
  1550
	// actionFormatBackImage->addTo( canvasContextMenu );  //FIXME makes vym too slow: postponed for later version 
insilmaril@0
  1551
insilmaril@0
  1552
	// Menu for last opened files
insilmaril@401
  1553
	// Create actions
insilmaril@401
  1554
	for (int i = 0; i < MaxRecentFiles; ++i) 
insilmaril@0
  1555
	{
insilmaril@445
  1556
        recentFileActions[i] = new QAction(this);
insilmaril@445
  1557
        recentFileActions[i]->setVisible(false);
insilmaril@445
  1558
        fileLastMapsMenu->addAction(recentFileActions[i]);
insilmaril@445
  1559
        connect(recentFileActions[i], SIGNAL(triggered()),
insilmaril@401
  1560
                this, SLOT(fileLoadRecent()));
insilmaril@401
  1561
    }
insilmaril@401
  1562
	setupRecentMapsMenu();
insilmaril@0
  1563
}
insilmaril@0
  1564
insilmaril@401
  1565
void Main::setupRecentMapsMenu()
insilmaril@0
  1566
{
insilmaril@401
  1567
    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
insilmaril@401
  1568
insilmaril@401
  1569
    int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
insilmaril@401
  1570
insilmaril@401
  1571
    for (int i = 0; i < numRecentFiles; ++i) {
insilmaril@401
  1572
        QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
insilmaril@445
  1573
        recentFileActions[i]->setText(text);
insilmaril@445
  1574
        recentFileActions[i]->setData(files[i]);
insilmaril@445
  1575
        recentFileActions[i]->setVisible(true);
insilmaril@401
  1576
    }
insilmaril@401
  1577
    for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
insilmaril@445
  1578
        recentFileActions[j]->setVisible(false);
insilmaril@445
  1579
}
insilmaril@445
  1580
insilmaril@445
  1581
void Main::setupMacros()
insilmaril@445
  1582
{
insilmaril@445
  1583
    for (int i = 0; i <= 11; i++) 
insilmaril@445
  1584
	{
insilmaril@445
  1585
        macroActions[i] = new QAction(this);
insilmaril@445
  1586
        macroActions[i]->setData(i);
insilmaril@445
  1587
        addAction (macroActions[i]);
insilmaril@445
  1588
        connect(macroActions[i], SIGNAL(triggered()),
insilmaril@445
  1589
                this, SLOT(callMacro()));
insilmaril@445
  1590
	}			
insilmaril@445
  1591
	macroActions[0]->setShortcut ( Qt::Key_F1 );
insilmaril@445
  1592
	macroActions[1]->setShortcut ( Qt::Key_F2 );
insilmaril@445
  1593
	macroActions[2]->setShortcut ( Qt::Key_F3 );
insilmaril@445
  1594
	macroActions[3]->setShortcut ( Qt::Key_F4 );
insilmaril@445
  1595
	macroActions[4]->setShortcut ( Qt::Key_F5 );
insilmaril@445
  1596
	macroActions[5]->setShortcut ( Qt::Key_F6 );
insilmaril@445
  1597
	macroActions[6]->setShortcut ( Qt::Key_F7 );
insilmaril@445
  1598
	macroActions[7]->setShortcut ( Qt::Key_F8 );
insilmaril@445
  1599
	macroActions[8]->setShortcut ( Qt::Key_F9 );
insilmaril@445
  1600
	macroActions[9]->setShortcut ( Qt::Key_F10 );
insilmaril@445
  1601
	macroActions[10]->setShortcut ( Qt::Key_F11 );
insilmaril@445
  1602
	macroActions[11]->setShortcut ( Qt::Key_F12 );
insilmaril@0
  1603
}
insilmaril@0
  1604
insilmaril@0
  1605
void Main::hideEvent (QHideEvent * )
insilmaril@0
  1606
{
insilmaril@0
  1607
	if (!textEditor->isMinimized() ) textEditor->hide();
insilmaril@0
  1608
}
insilmaril@0
  1609
insilmaril@0
  1610
void Main::showEvent (QShowEvent * )
insilmaril@0
  1611
{
insilmaril@491
  1612
	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
insilmaril@0
  1613
}
insilmaril@0
  1614
insilmaril@0
  1615
insilmaril@0
  1616
MapEditor* Main::currentMapEditor() const
insilmaril@0
  1617
{
insilmaril@0
  1618
    if ( tabWidget->currentPage() &&
insilmaril@0
  1619
	 tabWidget->currentPage()->inherits( "MapEditor" ) )
insilmaril@0
  1620
		return (MapEditor*)tabWidget->currentPage();
insilmaril@0
  1621
    return NULL;	
insilmaril@0
  1622
}
insilmaril@0
  1623
insilmaril@0
  1624
insilmaril@0
  1625
void Main::editorChanged(QWidget *)
insilmaril@0
  1626
{
insilmaril@0
  1627
	// Unselect all possibly selected objects
insilmaril@0
  1628
	// (Important to update note editor)
insilmaril@0
  1629
	MapEditor *me;
insilmaril@473
  1630
	for (int i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  1631
	{
insilmaril@0
  1632
		
insilmaril@0
  1633
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1634
		me->unselect();
insilmaril@0
  1635
	}	
insilmaril@0
  1636
	currentMapEditor()->reselect();
insilmaril@0
  1637
insilmaril@0
  1638
	// Update actions to in menus and toolbars according to editor
insilmaril@407
  1639
	updateActions();
insilmaril@0
  1640
}
insilmaril@0
  1641
insilmaril@0
  1642
void Main::fileNew()
insilmaril@0
  1643
{
insilmaril@0
  1644
	QString fn="unnamed";
insilmaril@408
  1645
	MapEditor* me = new MapEditor ( NULL);
insilmaril@408
  1646
	tabWidget->addTab (me,fn);
insilmaril@408
  1647
	tabWidget->showPage(me);
insilmaril@408
  1648
	me->viewport()->setFocus();
insilmaril@408
  1649
	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@408
  1650
	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@408
  1651
	
insilmaril@366
  1652
	// For the very first map we do not have flagrows yet...
insilmaril@408
  1653
	me->select("mc:");
insilmaril@0
  1654
}
insilmaril@0
  1655
insilmaril@491
  1656
void Main::fileNewCopy()
insilmaril@491
  1657
{
insilmaril@491
  1658
	QString fn="unnamed";
insilmaril@491
  1659
	MapEditor* oldME =currentMapEditor();
insilmaril@491
  1660
	if (oldME)
insilmaril@491
  1661
	{
insilmaril@491
  1662
		oldME->copy();
insilmaril@491
  1663
		MapEditor* newME = new MapEditor ( NULL);
insilmaril@491
  1664
		if (newME)
insilmaril@491
  1665
		{
insilmaril@491
  1666
			tabWidget->addTab (newME,fn);
insilmaril@491
  1667
			tabWidget->showPage(newME);
insilmaril@491
  1668
			newME->viewport()->setFocus();
insilmaril@491
  1669
			newME->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@491
  1670
			newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@491
  1671
			// For the very first map we do not have flagrows yet...
insilmaril@491
  1672
			newME->select("mc:");
insilmaril@571
  1673
			newME->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
insilmaril@491
  1674
		}
insilmaril@491
  1675
insilmaril@491
  1676
	}
insilmaril@491
  1677
}
insilmaril@491
  1678
insilmaril@571
  1679
ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype)
insilmaril@0
  1680
{
insilmaril@205
  1681
	ErrorCode err=success;
insilmaril@0
  1682
	
insilmaril@0
  1683
	// fn is usually the archive, mapfile the file after uncompressing
insilmaril@0
  1684
	QString mapfile;
insilmaril@0
  1685
insilmaril@0
  1686
	// Make fn absolute (needed for unzip)
insilmaril@0
  1687
	fn=QDir (fn).absPath();
insilmaril@0
  1688
insilmaril@0
  1689
	MapEditor *me;
insilmaril@0
  1690
insilmaril@0
  1691
	if (lmode==NewMap)
insilmaril@0
  1692
	{
insilmaril@0
  1693
		// Check, if map is already loaded
insilmaril@0
  1694
		int i=0;
insilmaril@0
  1695
		while (i<=tabWidget->count() -1)
insilmaril@0
  1696
		{
insilmaril@0
  1697
			me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  1698
			if (me->getFilePath() == fn)
insilmaril@0
  1699
			{
insilmaril@0
  1700
				// Already there, ask for confirmation
insilmaril@404
  1701
				QMessageBox mb( vymName,
insilmaril@159
  1702
					tr("The map %1\nis already opened."
insilmaril@0
  1703
					"Opening the same map in multiple editors may lead \n"
insilmaril@0
  1704
					"to confusion when finishing working with vym."
insilmaril@159
  1705
					"Do you want to").arg(fn),
insilmaril@0
  1706
					QMessageBox::Warning,
insilmaril@0
  1707
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1708
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
  1709
					QMessageBox::NoButton);
insilmaril@0
  1710
				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
insilmaril@0
  1711
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1712
				switch( mb.exec() ) 
insilmaril@0
  1713
				{
insilmaril@0
  1714
					case QMessageBox::Yes:
insilmaril@0
  1715
						// load anyway
insilmaril@0
  1716
						i=tabWidget->count();
insilmaril@0
  1717
						break;
insilmaril@0
  1718
					case QMessageBox::Cancel:
insilmaril@0
  1719
						// do nothing
insilmaril@205
  1720
						return aborted;
insilmaril@0
  1721
						break;
insilmaril@0
  1722
				}
insilmaril@0
  1723
			}
insilmaril@0
  1724
			i++;
insilmaril@0
  1725
		}
insilmaril@0
  1726
	}
insilmaril@0
  1727
insilmaril@0
  1728
insilmaril@0
  1729
	// Try to load map
insilmaril@0
  1730
    if ( !fn.isEmpty() )
insilmaril@0
  1731
	{
insilmaril@0
  1732
		me = currentMapEditor();
insilmaril@0
  1733
		int tabIndex=tabWidget->currentPageIndex();
insilmaril@0
  1734
		// Check first, if mapeditor exists
insilmaril@0
  1735
		// If it is not default AND we want a new map, 
insilmaril@0
  1736
		// create a new mapeditor in a new tab
insilmaril@0
  1737
		if ( lmode==NewMap && (!me || !me->isDefault() ) )
insilmaril@0
  1738
		{
insilmaril@390
  1739
			me= new MapEditor ( NULL);
insilmaril@0
  1740
			tabWidget->addTab (me,fn);
insilmaril@0
  1741
			tabIndex=tabWidget->indexOf (me);
insilmaril@0
  1742
			tabWidget->setCurrentPage (tabIndex);
insilmaril@408
  1743
			me->setAntiAlias (actionViewToggleAntiAlias->isOn());
insilmaril@408
  1744
			me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
insilmaril@0
  1745
		}
insilmaril@0
  1746
		
insilmaril@0
  1747
		// Check, if file exists (important for creating new files
insilmaril@0
  1748
		// from command line
insilmaril@0
  1749
		if (!QFile(fn).exists() )
insilmaril@0
  1750
		{
insilmaril@404
  1751
			QMessageBox mb( vymName,
insilmaril@159
  1752
				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
insilmaril@0
  1753
				QMessageBox::Question,
insilmaril@0
  1754
				QMessageBox::Yes ,
insilmaril@0
  1755
				QMessageBox::Cancel | QMessageBox::Default,
insilmaril@366
  1756
				QMessageBox::NoButton );
insilmaril@0
  1757
insilmaril@0
  1758
			mb.setButtonText( QMessageBox::Yes, tr("Create"));
insilmaril@0
  1759
			mb.setButtonText( QMessageBox::No, tr("Cancel"));
insilmaril@0
  1760
			switch( mb.exec() ) 
insilmaril@0
  1761
			{
insilmaril@0
  1762
				case QMessageBox::Yes:
insilmaril@0
  1763
					// Create new map
insilmaril@0
  1764
					currentMapEditor()->setFilePath(fn);
insilmaril@0
  1765
					tabWidget->setTabLabel (currentMapEditor(),
insilmaril@0
  1766
						currentMapEditor()->getFileName() );
insilmaril@0
  1767
					statusBar()->message( "Created " + fn , statusbarTime );
insilmaril@205
  1768
					return success;
insilmaril@0
  1769
						
insilmaril@0
  1770
				case QMessageBox::Cancel:
insilmaril@0
  1771
					// don't create new map
insilmaril@0
  1772
					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
insilmaril@0
  1773
					fileCloseMap();
insilmaril@205
  1774
					return aborted;
insilmaril@0
  1775
			}
insilmaril@0
  1776
		}	
insilmaril@0
  1777
insilmaril@0
  1778
insilmaril@0
  1779
		//tabWidget->currentPage() won't be NULL here, because of above...
insilmaril@0
  1780
		tabWidget->showPage(me);
insilmaril@0
  1781
		me->viewport()->setFocus();
insilmaril@0
  1782
insilmaril@0
  1783
		// Create temporary directory for packing
insilmaril@377
  1784
		bool ok;
insilmaril@377
  1785
		QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
insilmaril@377
  1786
		if (!ok)
insilmaril@377
  1787
		{
insilmaril@377
  1788
			QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@377
  1789
			   tr("Couldn't create temporary directory before load\n"));
insilmaril@377
  1790
			return aborted; 
insilmaril@377
  1791
		}
insilmaril@0
  1792
insilmaril@0
  1793
		// Try to unzip file
insilmaril@185
  1794
		err=unzipDir (tmpMapDir,fn);
insilmaril@185
  1795
		if (err==nozip)
insilmaril@0
  1796
		{
insilmaril@185
  1797
			mapfile=fn;
insilmaril@185
  1798
			me->setZipped(false);
insilmaril@0
  1799
		} else
insilmaril@0
  1800
		{
insilmaril@185
  1801
			me->setZipped(true);
insilmaril@185
  1802
			
insilmaril@185
  1803
			// Look for mapname.xml
insilmaril@185
  1804
			mapfile= fn.left(fn.findRev(".",-1,true));
insilmaril@185
  1805
			mapfile=mapfile.section( '/', -1 );
insilmaril@185
  1806
			QFile file( tmpMapDir + "/" + mapfile + ".xml");
insilmaril@185
  1807
			if (!file.exists() )
insilmaril@0
  1808
			{
insilmaril@185
  1809
				// mapname.xml does not exist, well, 
insilmaril@428
  1810
				// maybe someone renamed the mapname.vym file...
insilmaril@185
  1811
				// Try to find any .xml in the toplevel 
insilmaril@185
  1812
				// directory of the .vym file
insilmaril@185
  1813
				QStringList flist=QDir (tmpMapDir).entryList("*.xml");
insilmaril@185
  1814
				if (flist.count()==1) 
insilmaril@0
  1815
				{
insilmaril@185
  1816
					// Only one entry, take this one
insilmaril@185
  1817
					mapfile=tmpMapDir + "/"+flist.first();
insilmaril@0
  1818
				} else
insilmaril@185
  1819
				{
insilmaril@185
  1820
					for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
insilmaril@185
  1821
						*it=tmpMapDir + "/" + *it;
insilmaril@185
  1822
					// TODO Multiple entries, load all (but only the first one into this ME)
insilmaril@185
  1823
					//mainWindow->fileLoadFromTmp (flist);
insilmaril@185
  1824
					//returnCode=1;	// Silently forget this attempt to load
insilmaril@185
  1825
					qWarning ("MainWindow::load (fn)  multimap found...");
insilmaril@185
  1826
				}	
insilmaril@0
  1827
					
insilmaril@185
  1828
				if (flist.isEmpty() )
insilmaril@185
  1829
				{
insilmaril@185
  1830
					QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@185
  1831
							   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
insilmaril@185
  1832
					err=aborted;				   
insilmaril@185
  1833
				}	
insilmaril@185
  1834
			} //file doesn't exist	
insilmaril@185
  1835
			else
insilmaril@185
  1836
				mapfile=file.name();
insilmaril@0
  1837
		}
insilmaril@0
  1838
insilmaril@185
  1839
		if (err!=aborted)
insilmaril@185
  1840
		{
insilmaril@185
  1841
			// Save existing filename in case  we import
insilmaril@185
  1842
			QString fn_org=me->getFilePath();
insilmaril@106
  1843
insilmaril@185
  1844
			// Finally load map into mapEditor
insilmaril@185
  1845
			me->setFilePath (mapfile,fn);
insilmaril@571
  1846
			err=me->load(mapfile,lmode,ftype);
insilmaril@106
  1847
insilmaril@185
  1848
			// Restore old (maybe empty) filepath, if this is an import
insilmaril@185
  1849
			if (lmode!=NewMap)
insilmaril@185
  1850
				me->setFilePath (fn_org);
insilmaril@185
  1851
		}	
insilmaril@0
  1852
insilmaril@185
  1853
		// Finally check for errors and go home
insilmaril@185
  1854
		if (err==aborted) 
insilmaril@185
  1855
		{
insilmaril@185
  1856
			if (lmode==NewMap) fileCloseMap();
insilmaril@185
  1857
			statusBar()->message( "Could not load " + fn, statusbarTime );
insilmaril@185
  1858
		} else 
insilmaril@0
  1859
		{
insilmaril@0
  1860
			if (lmode==NewMap)
insilmaril@0
  1861
			{
insilmaril@0
  1862
				me->setFilePath (fn);
insilmaril@0
  1863
				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
insilmaril@205
  1864
				if (fn.left(9)!="/tmp/vym-")
insilmaril@205
  1865
				{
insilmaril@205
  1866
					// Only append to lastMaps if not loaded from a tmpDir
insilmaril@205
  1867
					// e.g. imported bookmarks are in a tmpDir
insilmaril@401
  1868
					addRecentMap(me->getFilePath() );
insilmaril@205
  1869
				}
insilmaril@0
  1870
				actionFilePrint->setEnabled (true);
insilmaril@0
  1871
			}	
insilmaril@0
  1872
			statusBar()->message( "Loaded " + fn, statusbarTime );
insilmaril@0
  1873
		}	
insilmaril@0
  1874
insilmaril@185
  1875
		// Delete tmpDir
insilmaril@185
  1876
		removeDir (QDir(tmpMapDir));
insilmaril@0
  1877
	}
insilmaril@205
  1878
	return err;
insilmaril@0
  1879
}
insilmaril@0
  1880
insilmaril@0
  1881
insilmaril@0
  1882
void Main::fileLoad(const LoadMode &lmode)
insilmaril@0
  1883
{
insilmaril@377
  1884
	QStringList filters;
insilmaril@389
  1885
	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
insilmaril@377
  1886
	QFileDialog *fd=new QFileDialog( this);
insilmaril@366
  1887
	fd->setDir (lastFileDir);
insilmaril@377
  1888
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@377
  1889
	fd->setFilters (filters);
insilmaril@0
  1890
	switch (lmode)
insilmaril@0
  1891
	{
insilmaril@0
  1892
		case NewMap:
insilmaril@404
  1893
			fd->setCaption(vymName+ " - " +tr("Load vym map"));
insilmaril@0
  1894
			break;
insilmaril@0
  1895
		case ImportAdd:
insilmaril@404
  1896
			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
insilmaril@0
  1897
			break;
insilmaril@0
  1898
		case ImportReplace:
insilmaril@404
  1899
			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
insilmaril@0
  1900
			break;
insilmaril@0
  1901
	}
insilmaril@0
  1902
	fd->show();
insilmaril@0
  1903
insilmaril@0
  1904
	QString fn;
insilmaril@0
  1905
	if ( fd->exec() == QDialog::Accepted )
insilmaril@0
  1906
	{
insilmaril@377
  1907
		lastFileDir=fd->directory().path();
insilmaril@185
  1908
	    QStringList flist = fd->selectedFiles();
insilmaril@185
  1909
		QStringList::Iterator it = flist.begin();
insilmaril@185
  1910
		while( it != flist.end() ) 
insilmaril@185
  1911
		{
insilmaril@185
  1912
			fn = *it;
insilmaril@185
  1913
			fileLoad(*it, lmode);				   
insilmaril@185
  1914
			++it;
insilmaril@185
  1915
		}
insilmaril@0
  1916
	}
insilmaril@185
  1917
	delete (fd);
insilmaril@0
  1918
}
insilmaril@0
  1919
insilmaril@0
  1920
void Main::fileLoad()
insilmaril@0
  1921
{
insilmaril@0
  1922
	fileLoad (NewMap);
insilmaril@0
  1923
}
insilmaril@0
  1924
insilmaril@401
  1925
void Main::fileLoadRecent()
insilmaril@0
  1926
{
insilmaril@401
  1927
    QAction *action = qobject_cast<QAction *>(sender());
insilmaril@401
  1928
    if (action)
insilmaril@401
  1929
        fileLoad (action->data().toString(), NewMap);
insilmaril@401
  1930
}
insilmaril@401
  1931
insilmaril@401
  1932
void Main::addRecentMap (const QString &fileName)
insilmaril@401
  1933
{
insilmaril@401
  1934
insilmaril@401
  1935
    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
insilmaril@401
  1936
    files.removeAll(fileName);
insilmaril@401
  1937
    files.prepend(fileName);
insilmaril@401
  1938
    while (files.size() > MaxRecentFiles)
insilmaril@401
  1939
        files.removeLast();
insilmaril@401
  1940
insilmaril@401
  1941
    settings.setValue("/mainwindow/recentFileList", files);
insilmaril@401
  1942
insilmaril@401
  1943
	setupRecentMapsMenu();
insilmaril@0
  1944
}
insilmaril@0
  1945
insilmaril@473
  1946
void Main::fileSave(MapEditor *me, const SaveMode &savemode)
insilmaril@0
  1947
{
insilmaril@0
  1948
	// tmp dir for zipping 
insilmaril@0
  1949
	QString tmpMapDir;
insilmaril@0
  1950
	
insilmaril@0
  1951
	// Error codes
insilmaril@205
  1952
	ErrorCode err=success;
insilmaril@0
  1953
	
insilmaril@0
  1954
	QString safeFilePath;
insilmaril@0
  1955
insilmaril@473
  1956
	bool saveZipped=me->saveZipped();
insilmaril@473
  1957
insilmaril@151
  1958
	if (me)
insilmaril@0
  1959
	{
insilmaril@151
  1960
		QString fn=me->getFilePath();
insilmaril@473
  1961
		// filename=unnamed, filepath="" in constructor of mapEditor
insilmaril@0
  1962
		if ( !fn.isEmpty() ) 
insilmaril@0
  1963
		{	
insilmaril@0
  1964
			// We have a filepath, go on saving			
insilmaril@0
  1965
			// First remove existing file, we 
insilmaril@0
  1966
			// don't want to add to old zip archives
insilmaril@0
  1967
			QFile f(fn);
insilmaril@0
  1968
			if (f.exists() ) 
insilmaril@0
  1969
				if (!f.remove())
insilmaril@0
  1970
					QMessageBox::warning( 0, tr( "Save Error" ),
insilmaril@0
  1971
						fn+   tr("\ncould not be removed before saving"));
insilmaril@0
  1972
insilmaril@0
  1973
			// Look, if we should zip the data:
insilmaril@0
  1974
			if (!saveZipped)
insilmaril@0
  1975
			{
insilmaril@404
  1976
				QMessageBox mb( vymName,
insilmaril@159
  1977
					tr("The map %1\ndid not use the compressed "
insilmaril@0
  1978
					"vym file format.\nWriting it uncompressed will also write images \n"
insilmaril@0
  1979
					"and flags and thus may overwrite files in the "
insilmaril@159
  1980
					"given directory\n\nDo you want to write the map").arg(fn),
insilmaril@0
  1981
					QMessageBox::Warning,
insilmaril@0
  1982
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  1983
					QMessageBox::No ,
insilmaril@0
  1984
					QMessageBox::Cancel | QMessageBox::Escape);
insilmaril@0
  1985
				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
insilmaril@0
  1986
				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
insilmaril@0
  1987
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  1988
				switch( mb.exec() ) 
insilmaril@0
  1989
				{
insilmaril@0
  1990
					case QMessageBox::Yes:
insilmaril@0
  1991
						// save compressed (default file format)
insilmaril@0
  1992
						saveZipped=true;
insilmaril@0
  1993
						break;
insilmaril@0
  1994
					case QMessageBox::No:
insilmaril@0
  1995
						// save uncompressed
insilmaril@0
  1996
						saveZipped=false;
insilmaril@0
  1997
						break;
insilmaril@0
  1998
					case QMessageBox::Cancel:
insilmaril@0
  1999
						// do nothing
insilmaril@0
  2000
						return;
insilmaril@0
  2001
						break;
insilmaril@0
  2002
				}
insilmaril@0
  2003
			}
insilmaril@0
  2004
insilmaril@0
  2005
			if (saveZipped)
insilmaril@0
  2006
			{
insilmaril@377
  2007
				// Create temporary directory for packing
insilmaril@377
  2008
				bool ok;
insilmaril@377
  2009
				QString tmpMapDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
insilmaril@377
  2010
				if (!ok)
insilmaril@377
  2011
				{
insilmaril@377
  2012
					QMessageBox::critical( 0, tr( "Critical Load Error" ),
insilmaril@377
  2013
					   tr("Couldn't create temporary directory before save\n"));
insilmaril@377
  2014
					return; 
insilmaril@377
  2015
				}
insilmaril@377
  2016
insilmaril@151
  2017
				safeFilePath=me->getFilePath();
insilmaril@151
  2018
				me->setFilePath (tmpMapDir+"/"+
insilmaril@151
  2019
					me->getMapName()+ ".xml",
insilmaril@0
  2020
					safeFilePath);
insilmaril@151
  2021
				me->save (savemode);
insilmaril@151
  2022
				me->setFilePath (safeFilePath);
insilmaril@0
  2023
				
insilmaril@175
  2024
				zipDir (tmpMapDir,fn);
insilmaril@0
  2025
			} // save zipped
insilmaril@0
  2026
			else
insilmaril@0
  2027
			{
insilmaril@0
  2028
				// Save unzipped. 
insilmaril@151
  2029
				safeFilePath=me->getFilePath();
insilmaril@151
  2030
				me->setFilePath (fn, safeFilePath);
insilmaril@151
  2031
				me->save (savemode);
insilmaril@151
  2032
				me->setFilePath (safeFilePath);
insilmaril@0
  2033
			} // save zipped 	
insilmaril@0
  2034
		} // filepath available
insilmaril@0
  2035
		else
insilmaril@0
  2036
		{
insilmaril@0
  2037
			// We have  no filepath yet,
insilmaril@0
  2038
			// call fileSaveAs() now, this will call fileSave() 
insilmaril@0
  2039
			// again.
insilmaril@473
  2040
			// First switch to editor
insilmaril@473
  2041
			tabWidget->setCurrentWidget (me);
insilmaril@0
  2042
			fileSaveAs(savemode);
insilmaril@0
  2043
		}
insilmaril@0
  2044
    }
insilmaril@0
  2045
insilmaril@250
  2046
	if (saveZipped && !tmpMapDir.isEmpty())
insilmaril@0
  2047
		// Delete tmpDir
insilmaril@175
  2048
		removeDir (QDir(tmpMapDir));
insilmaril@0
  2049
insilmaril@0
  2050
	if (err==success)
insilmaril@151
  2051
	{
insilmaril@0
  2052
		statusBar()->message( 
insilmaril@159
  2053
			tr("Saved  %1").arg(me->getFilePath()), 
insilmaril@0
  2054
			statusbarTime );
insilmaril@401
  2055
		addRecentMap (me->getFilePath() );
insilmaril@151
  2056
	} else		
insilmaril@0
  2057
		statusBar()->message( 
insilmaril@159
  2058
			tr("Couldn't save ").arg(me->getFilePath()), 
insilmaril@0
  2059
			statusbarTime );
insilmaril@0
  2060
}
insilmaril@0
  2061
insilmaril@0
  2062
void Main::fileSave()
insilmaril@0
  2063
{
insilmaril@473
  2064
	fileSave (currentMapEditor(), CompleteMap);
insilmaril@473
  2065
}
insilmaril@473
  2066
insilmaril@473
  2067
void Main::fileSave(MapEditor *me)
insilmaril@473
  2068
{
insilmaril@473
  2069
	fileSave (me,CompleteMap);
insilmaril@0
  2070
}
insilmaril@0
  2071
insilmaril@0
  2072
void Main::fileSaveAs(const SaveMode& savemode)
insilmaril@0
  2073
{
insilmaril@0
  2074
	QString fn;
insilmaril@0
  2075
insilmaril@0
  2076
	if (currentMapEditor())
insilmaril@0
  2077
	{
insilmaril@0
  2078
		if (savemode==CompleteMap)
insilmaril@366
  2079
			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
insilmaril@0
  2080
		else		
insilmaril@366
  2081
			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
insilmaril@0
  2082
		if ( !fn.isEmpty() ) 
insilmaril@0
  2083
		{
insilmaril@0
  2084
			// Check for existing file
insilmaril@0
  2085
			if (QFile (fn).exists())
insilmaril@0
  2086
			{
insilmaril@404
  2087
				QMessageBox mb( vymName,
insilmaril@159
  2088
					tr("The file %1\nexists already. Do you want to").arg(fn),
insilmaril@0
  2089
					QMessageBox::Warning,
insilmaril@0
  2090
					QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2091
					QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
  2092
					QMessageBox::NoButton);
insilmaril@0
  2093
				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
insilmaril@0
  2094
				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
insilmaril@0
  2095
				switch( mb.exec() ) 
insilmaril@0
  2096
				{
insilmaril@0
  2097
					case QMessageBox::Yes:
insilmaril@0
  2098
						// save 
insilmaril@0
  2099
						break;
insilmaril@0
  2100
					case QMessageBox::Cancel:
insilmaril@0
  2101
						// do nothing
insilmaril@0
  2102
						return;
insilmaril@0
  2103
						break;
insilmaril@0
  2104
				}
insilmaril@0
  2105
			} else
insilmaril@0
  2106
			{
insilmaril@0
  2107
				// New file, add extension to filename, if missing
insilmaril@0
  2108
				// This is always .vym or .vyp, depending on savemode
insilmaril@0
  2109
				if (savemode==CompleteMap)
insilmaril@0
  2110
				{
insilmaril@0
  2111
					if (!fn.contains (".vym") && !fn.contains (".xml"))
insilmaril@0
  2112
						fn +=".vym";
insilmaril@0
  2113
				} else		
insilmaril@0
  2114
				{
insilmaril@0
  2115
					if (!fn.contains (".vyp") && !fn.contains (".xml"))
insilmaril@0
  2116
						fn +=".vyp";
insilmaril@0
  2117
				}
insilmaril@0
  2118
			}
insilmaril@0
  2119
	
insilmaril@0
  2120
insilmaril@0
  2121
insilmaril@0
  2122
insilmaril@0
  2123
			// Save now
insilmaril@0
  2124
			currentMapEditor()->setFilePath(fn);
insilmaril@473
  2125
			fileSave(currentMapEditor(), savemode);
insilmaril@0
  2126
insilmaril@0
  2127
			// Set name of tab
insilmaril@94
  2128
			if (savemode==CompleteMap)
insilmaril@94
  2129
				tabWidget->setTabLabel (currentMapEditor(),
insilmaril@94
  2130
					currentMapEditor()->getFileName() );
insilmaril@0
  2131
			return;
insilmaril@0
  2132
		} 
insilmaril@0
  2133
	}
insilmaril@0
  2134
}
insilmaril@0
  2135
insilmaril@0
  2136
void Main::fileSaveAs()
insilmaril@0
  2137
{
insilmaril@0
  2138
	fileSaveAs (CompleteMap);
insilmaril@0
  2139
}
insilmaril@0
  2140
insilmaril@205
  2141
void Main::fileImportKDEBookmarks()
insilmaril@205
  2142
{
insilmaril@205
  2143
	ImportKDEBookmarks im;
insilmaril@205
  2144
	im.transform();
insilmaril@205
  2145
	if (success==fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
insilmaril@205
  2146
		currentMapEditor()->setFilePath ("");
insilmaril@205
  2147
}
insilmaril@205
  2148
insilmaril@314
  2149
void Main::fileImportFirefoxBookmarks()
insilmaril@314
  2150
{
insilmaril@366
  2151
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@327
  2152
	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
insilmaril@366
  2153
	fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@327
  2154
	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
insilmaril@327
  2155
	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
insilmaril@327
  2156
	fd->show();
insilmaril@327
  2157
insilmaril@327
  2158
	if ( fd->exec() == QDialog::Accepted )
insilmaril@327
  2159
	{
insilmaril@327
  2160
		ImportFirefoxBookmarks im;
insilmaril@327
  2161
	    QStringList flist = fd->selectedFiles();
insilmaril@327
  2162
		QStringList::Iterator it = flist.begin();
insilmaril@327
  2163
		while( it != flist.end() ) 
insilmaril@327
  2164
		{
insilmaril@327
  2165
			im.setFile (*it);
insilmaril@327
  2166
			if (im.transform() && 
insilmaril@571
  2167
				success==fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
insilmaril@327
  2168
				currentMapEditor() )
insilmaril@327
  2169
				currentMapEditor()->setFilePath ("");
insilmaril@327
  2170
			++it;
insilmaril@327
  2171
		}
insilmaril@327
  2172
	}
insilmaril@327
  2173
	delete (fd);
insilmaril@314
  2174
}
insilmaril@314
  2175
insilmaril@571
  2176
void Main::fileImportFreemind()
insilmaril@571
  2177
{
insilmaril@571
  2178
	QStringList filters;
insilmaril@571
  2179
	filters <<"Freemind map (*.mm)"<<"All files (*)";
insilmaril@571
  2180
	QFileDialog *fd=new QFileDialog( this);
insilmaril@571
  2181
	fd->setDir (lastFileDir);
insilmaril@571
  2182
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@571
  2183
	fd->setFilters (filters);
insilmaril@571
  2184
	fd->setCaption(vymName+ " - " +tr("Load Freemind map"));
insilmaril@571
  2185
	fd->show();
insilmaril@571
  2186
insilmaril@571
  2187
	QString fn;
insilmaril@571
  2188
	if ( fd->exec() == QDialog::Accepted )
insilmaril@571
  2189
	{
insilmaril@571
  2190
		lastFileDir=fd->directory().path();
insilmaril@571
  2191
	    QStringList flist = fd->selectedFiles();
insilmaril@571
  2192
		QStringList::Iterator it = flist.begin();
insilmaril@571
  2193
		while( it != flist.end() ) 
insilmaril@571
  2194
		{
insilmaril@571
  2195
			fn = *it;
insilmaril@571
  2196
			if ( fileLoad (fn,NewMap, FreemindMap)  )
insilmaril@571
  2197
			{	
insilmaril@571
  2198
				currentMapEditor()->setFilePath ("");
insilmaril@571
  2199
			}	
insilmaril@571
  2200
			++it;
insilmaril@571
  2201
		}
insilmaril@571
  2202
	}
insilmaril@571
  2203
	delete (fd);
insilmaril@571
  2204
}
insilmaril@571
  2205
insilmaril@571
  2206
insilmaril@215
  2207
void Main::fileImportMM()
insilmaril@215
  2208
{
insilmaril@215
  2209
	ImportMM im;
insilmaril@215
  2210
insilmaril@366
  2211
	Q3FileDialog *fd=new Q3FileDialog( this);
insilmaril@366
  2212
	fd->setDir (lastFileDir);
insilmaril@366
  2213
	fd->setMode (Q3FileDialog::ExistingFiles);
insilmaril@215
  2214
	fd->addFilter ("Mind Manager (*.mmap)");
insilmaril@215
  2215
	fd->setCaption(tr("Import")+" "+"Mind Manager");
insilmaril@215
  2216
	fd->show();
insilmaril@215
  2217
insilmaril@215
  2218
	if ( fd->exec() == QDialog::Accepted )
insilmaril@215
  2219
	{
insilmaril@215
  2220
		lastFileDir=fd->dirPath();
insilmaril@215
  2221
	    QStringList flist = fd->selectedFiles();
insilmaril@215
  2222
		QStringList::Iterator it = flist.begin();
insilmaril@215
  2223
		while( it != flist.end() ) 
insilmaril@215
  2224
		{
insilmaril@215
  2225
			im.setFile (*it);
insilmaril@215
  2226
			if (im.transform() && 
insilmaril@215
  2227
				success==fileLoad (im.getTransformedFile(),NewMap) && 
insilmaril@215
  2228
				currentMapEditor() )
insilmaril@215
  2229
				currentMapEditor()->setFilePath ("");
insilmaril@215
  2230
insilmaril@215
  2231
			++it;
insilmaril@215
  2232
		}
insilmaril@215
  2233
	}
insilmaril@215
  2234
	delete (fd);
insilmaril@215
  2235
insilmaril@215
  2236
}
insilmaril@215
  2237
insilmaril@215
  2238
void Main::fileImportDir()
insilmaril@215
  2239
{
insilmaril@215
  2240
	if (currentMapEditor())
insilmaril@215
  2241
		currentMapEditor()->importDir();	
insilmaril@215
  2242
}
insilmaril@215
  2243
insilmaril@526
  2244
void Main::fileExportXML()	
insilmaril@0
  2245
{
insilmaril@526
  2246
	MapEditor *me=currentMapEditor();
insilmaril@526
  2247
	if (me) me->exportXML();
insilmaril@0
  2248
}
insilmaril@0
  2249
insilmaril@0
  2250
insilmaril@517
  2251
void Main::fileExportXHTML()	
insilmaril@0
  2252
{
insilmaril@260
  2253
	MapEditor *me=currentMapEditor();
insilmaril@517
  2254
	if (me) me->exportXHTML();
insilmaril@0
  2255
}
insilmaril@0
  2256
insilmaril@517
  2257
void Main::fileExportImage()	
insilmaril@0
  2258
{
insilmaril@260
  2259
	MapEditor *me=currentMapEditor();
insilmaril@514
  2260
	if (me) me->exportImage();
insilmaril@0
  2261
}
insilmaril@0
  2262
insilmaril@0
  2263
void Main::fileExportASCII()
insilmaril@0
  2264
{
insilmaril@260
  2265
	MapEditor *me=currentMapEditor();
insilmaril@514
  2266
	if (me) me->exportASCII();
insilmaril@0
  2267
}
insilmaril@0
  2268
insilmaril@517
  2269
void Main::fileExportCSV()	//FIXME not scriptable yet
insilmaril@497
  2270
{
insilmaril@497
  2271
	MapEditor *me=currentMapEditor();
insilmaril@497
  2272
	if (me)
insilmaril@497
  2273
	{
insilmaril@497
  2274
		ExportCSV ex;
insilmaril@497
  2275
		ex.setMapCenter(me->getMapCenter());
insilmaril@497
  2276
		ex.addFilter ("CSV (*.csv)");
insilmaril@497
  2277
		ex.setDir(lastImageDir);
insilmaril@497
  2278
		ex.setCaption(vymName+ " -" +tr("Export as CSV")+" "+tr("(still experimental)"));
insilmaril@497
  2279
		if (ex.execDialog() ) 
insilmaril@497
  2280
		{
insilmaril@497
  2281
			me->setExportMode(true);
insilmaril@497
  2282
			ex.doExport();
insilmaril@497
  2283
			me->setExportMode(false);
insilmaril@497
  2284
		}
insilmaril@497
  2285
	}
insilmaril@497
  2286
}
insilmaril@497
  2287
insilmaril@517
  2288
void Main::fileExportLaTeX()	//FIXME not scriptable yet
insilmaril@163
  2289
{
insilmaril@260
  2290
	MapEditor *me=currentMapEditor();
insilmaril@260
  2291
	if (me)
insilmaril@228
  2292
	{
insilmaril@228
  2293
		ExportLaTeX ex;
insilmaril@260
  2294
		ex.setMapCenter(me->getMapCenter());
insilmaril@228
  2295
		ex.addFilter ("Tex (*.tex)");
insilmaril@424
  2296
		ex.setDir(lastImageDir);
insilmaril@404
  2297
		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
insilmaril@260
  2298
		if (ex.execDialog() ) 
insilmaril@260
  2299
		{
insilmaril@260
  2300
			me->setExportMode(true);
insilmaril@260
  2301
			ex.doExport();
insilmaril@260
  2302
			me->setExportMode(false);
insilmaril@260
  2303
		}
insilmaril@228
  2304
	}
insilmaril@228
  2305
}
insilmaril@228
  2306
insilmaril@517
  2307
void Main::fileExportKDEBookmarks()	//FIXME not scriptable yet
insilmaril@243
  2308
{
insilmaril@243
  2309
	ExportKDEBookmarks ex;
insilmaril@260
  2310
	MapEditor *me=currentMapEditor();
insilmaril@260
  2311
	if (me)
insilmaril@243
  2312
	{
insilmaril@260
  2313
		ex.setMapCenter (me->getMapCenter() );
insilmaril@243
  2314
		ex.doExport();
insilmaril@243
  2315
	}	
insilmaril@243
  2316
}
insilmaril@243
  2317
insilmaril@517
  2318
void Main::fileExportTaskjuggler()	//FIXME not scriptable yet
insilmaril@228
  2319
{
insilmaril@228
  2320
	ExportTaskjuggler ex;
insilmaril@260
  2321
	MapEditor *me=currentMapEditor();
insilmaril@260
  2322
	if (me)
insilmaril@228
  2323
	{
insilmaril@260
  2324
		ex.setMapCenter (me->getMapCenter() );
insilmaril@404
  2325
		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
insilmaril@424
  2326
		ex.setDir(lastImageDir);
insilmaril@243
  2327
		ex.addFilter ("Taskjuggler (*.tjp)");
insilmaril@260
  2328
		if (ex.execDialog() ) 
insilmaril@260
  2329
		{
insilmaril@260
  2330
			me->setExportMode(true);
insilmaril@260
  2331
			ex.doExport();
insilmaril@260
  2332
			me->setExportMode(false);
insilmaril@260
  2333
		}
insilmaril@228
  2334
	}	
insilmaril@163
  2335
}
insilmaril@163
  2336
insilmaril@517
  2337
void Main::fileExportOOPresentation()	//FIXME not scriptable yet
insilmaril@163
  2338
{
insilmaril@404
  2339
	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
insilmaril@366
  2340
	// TODO add preview in dialog
insilmaril@185
  2341
	//ImagePreview *p =new ImagePreview (fd);
insilmaril@185
  2342
	//fd->setContentsPreviewEnabled( TRUE );
insilmaril@185
  2343
	//fd->setContentsPreview( p, p );
insilmaril@185
  2344
	//fd->setPreviewMode( QFileDialog::Contents );
insilmaril@404
  2345
	fd->setCaption(vymName+" - " +tr("Export to")+" Open Office");
insilmaril@366
  2346
	fd->setDir (QDir().current());
insilmaril@357
  2347
	if (fd->foundConfig())
insilmaril@357
  2348
	{
insilmaril@357
  2349
		fd->show();
insilmaril@185
  2350
insilmaril@357
  2351
		if ( fd->exec() == QDialog::Accepted )
insilmaril@357
  2352
		{
insilmaril@357
  2353
			QString fn=fd->selectedFile();
insilmaril@366
  2354
			if (!fn.contains (".odp"))
insilmaril@366
  2355
				fn +=".odp";
insilmaril@366
  2356
insilmaril@357
  2357
			//lastImageDir=fn.left(fn.findRev ("/"));
insilmaril@357
  2358
			if (currentMapEditor())
insilmaril@357
  2359
				currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());	
insilmaril@357
  2360
		}
insilmaril@357
  2361
	} else
insilmaril@185
  2362
	{
insilmaril@357
  2363
		QMessageBox::warning(0, 
insilmaril@366
  2364
		tr("Warning"),
insilmaril@366
  2365
		tr("Couldn't find configuration for export to Open Office\n"));
insilmaril@185
  2366
	}
insilmaril@163
  2367
}
insilmaril@163
  2368
insilmaril@0
  2369
void Main::fileCloseMap()
insilmaril@0
  2370
{
insilmaril@0
  2371
	if (currentMapEditor())
insilmaril@0
  2372
	{
insilmaril@0
  2373
		if (currentMapEditor()->hasChanged())
insilmaril@0
  2374
		{
insilmaril@404
  2375
			QMessageBox mb( vymName,
insilmaril@159
  2376
				tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
insilmaril@0
  2377
				QMessageBox::Warning,
insilmaril@0
  2378
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2379
				QMessageBox::No,
insilmaril@0
  2380
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  2381
			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
insilmaril@0
  2382
			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
insilmaril@0
  2383
			switch( mb.exec() ) 
insilmaril@0
  2384
			{
insilmaril@0
  2385
				case QMessageBox::Yes:
insilmaril@0
  2386
					// save and close
insilmaril@473
  2387
					fileSave(currentMapEditor(), CompleteMap);
insilmaril@0
  2388
					break;
insilmaril@0
  2389
				case QMessageBox::No:
insilmaril@0
  2390
				// close  without saving
insilmaril@0
  2391
					break;
insilmaril@0
  2392
				case QMessageBox::Cancel:
insilmaril@0
  2393
					// do nothing
insilmaril@0
  2394
				return;
insilmaril@0
  2395
			}
insilmaril@0
  2396
		} 
insilmaril@0
  2397
		currentMapEditor()->closeMap();
insilmaril@0
  2398
		tabWidget->removePage(currentMapEditor());
insilmaril@0
  2399
		if (tabWidget->count()==0)
insilmaril@0
  2400
			actionFilePrint->setEnabled (false);
insilmaril@0
  2401
	}	
insilmaril@0
  2402
}
insilmaril@0
  2403
insilmaril@0
  2404
void Main::filePrint()
insilmaril@0
  2405
{
insilmaril@0
  2406
	if (currentMapEditor())
insilmaril@0
  2407
		currentMapEditor()->print();
insilmaril@0
  2408
}
insilmaril@0
  2409
insilmaril@0
  2410
void Main::fileExitVYM()
insilmaril@0
  2411
{
insilmaril@0
  2412
	// Check if one or more editors have changed
insilmaril@0
  2413
	MapEditor *me;
insilmaril@0
  2414
	int i;
insilmaril@0
  2415
	for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  2416
	{
insilmaril@0
  2417
		
insilmaril@0
  2418
		me=(MapEditor*)tabWidget->page(i);
insilmaril@0
  2419
insilmaril@0
  2420
		// If something changed, ask what to do
insilmaril@486
  2421
		if (me->hasChanged())
insilmaril@0
  2422
		{
insilmaril@0
  2423
			tabWidget->setCurrentPage(i);
insilmaril@404
  2424
			QMessageBox mb( vymName,
insilmaril@0
  2425
				tr("This map is not saved yet. Do you want to"),
insilmaril@0
  2426
				QMessageBox::Warning,
insilmaril@0
  2427
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@0
  2428
				QMessageBox::No,
insilmaril@0
  2429
				QMessageBox::Cancel | QMessageBox::Escape );
insilmaril@0
  2430
			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
insilmaril@0
  2431
			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
insilmaril@366
  2432
			mb.setModal (true);
insilmaril@0
  2433
			mb.show();
insilmaril@0
  2434
			mb.setActiveWindow();
insilmaril@0
  2435
			switch( mb.exec() ) {
insilmaril@0
  2436
				case QMessageBox::Yes:
insilmaril@0
  2437
					// save (the changed editors) and exit
insilmaril@473
  2438
					fileSave(currentMapEditor(), CompleteMap);
insilmaril@0
  2439
					break;
insilmaril@0
  2440
				case QMessageBox::No:
insilmaril@0
  2441
					// exit without saving
insilmaril@0
  2442
					break;
insilmaril@0
  2443
				case QMessageBox::Cancel:
insilmaril@0
  2444
					// don't save and don't exit
insilmaril@0
  2445
				return;
insilmaril@0
  2446
			}
insilmaril@0
  2447
		}
insilmaril@0
  2448
	} // loop over all MEs	
insilmaril@0
  2449
    qApp->quit();
insilmaril@0
  2450
}
insilmaril@0
  2451
insilmaril@0
  2452
void Main::editUndo()
insilmaril@0
  2453
{
insilmaril@0
  2454
	if (currentMapEditor())
insilmaril@0
  2455
		currentMapEditor()->undo();
insilmaril@0
  2456
}
insilmaril@0
  2457
insilmaril@163
  2458
void Main::editRedo()	   
insilmaril@0
  2459
{
insilmaril@163
  2460
	if (currentMapEditor())
insilmaril@163
  2461
		currentMapEditor()->redo();
insilmaril@0
  2462
}
insilmaril@0
  2463
insilmaril@404
  2464
void Main::gotoHistoryStep (int i)	   
insilmaril@404
  2465
{
insilmaril@404
  2466
	if (currentMapEditor())
insilmaril@404
  2467
		currentMapEditor()->gotoHistoryStep (i);
insilmaril@404
  2468
}
insilmaril@404
  2469
insilmaril@0
  2470
void Main::editCopy()
insilmaril@0
  2471
{
insilmaril@0
  2472
	if (currentMapEditor())
insilmaril@0
  2473
		currentMapEditor()->copy();
insilmaril@0
  2474
}
insilmaril@0
  2475
insilmaril@0
  2476
void Main::editPaste()
insilmaril@0
  2477
{
insilmaril@0
  2478
	if (currentMapEditor())
insilmaril@0
  2479
		currentMapEditor()->paste();
insilmaril@0
  2480
}
insilmaril@0
  2481
insilmaril@0
  2482
void Main::editCut()
insilmaril@0
  2483
{
insilmaril@0
  2484
	if (currentMapEditor())
insilmaril@0
  2485
		currentMapEditor()->cut();
insilmaril@0
  2486
}
insilmaril@0
  2487
insilmaril@0
  2488
void Main::editOpenFindWindow()
insilmaril@0
  2489
{
insilmaril@0
  2490
	findWindow->popup();
insilmaril@0
  2491
	findWindow->raise();
insilmaril@0
  2492
	findWindow->setActiveWindow();
insilmaril@0
  2493
}
insilmaril@0
  2494
insilmaril@0
  2495
void Main::editFind(QString s)
insilmaril@0
  2496
{
insilmaril@0
  2497
	bool cs=false;
insilmaril@0
  2498
	BranchObj *bo=currentMapEditor()->findText(s, cs);
insilmaril@0
  2499
	if (bo)
insilmaril@0
  2500
	{	
insilmaril@0
  2501
		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
insilmaril@0
  2502
	} else
insilmaril@0
  2503
	{
insilmaril@0
  2504
		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
insilmaril@349
  2505
							   tr("No matches found for \"%1\"").arg(s));
insilmaril@0
  2506
	}	
insilmaril@0
  2507
}
insilmaril@0
  2508
insilmaril@0
  2509
void Main::editFindChanged()
insilmaril@0
  2510
{	// Notify editor, to abort the current find process
insilmaril@0
  2511
	currentMapEditor()->findReset();
insilmaril@0
  2512
}
insilmaril@0
  2513
insilmaril@366
  2514
void Main::openTabs(QStringList urls)
insilmaril@366
  2515
{
insilmaril@366
  2516
	if (!urls.isEmpty())
insilmaril@366
  2517
	{	
insilmaril@366
  2518
		bool success=true;
insilmaril@366
  2519
		QStringList args;
insilmaril@366
  2520
		QString browser=settings.value("/mainwindow/readerURL" ).toString();
insilmaril@366
  2521
		QProcess *p;
insilmaril@366
  2522
		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
insilmaril@366
  2523
		{
insilmaril@366
  2524
			QString u=urls.takeFirst();
insilmaril@366
  2525
			procBrowser = new QProcess( this );
insilmaril@366
  2526
			args<<u;
insilmaril@366
  2527
			procBrowser->start(browser,args);
insilmaril@366
  2528
			if ( !procBrowser->waitForStarted())
insilmaril@366
  2529
			{
insilmaril@366
  2530
				// try to set path to browser
insilmaril@366
  2531
				QMessageBox::warning(0, 
insilmaril@366
  2532
					tr("Warning"),
insilmaril@366
  2533
					tr("Couldn't find a viewer to open %1.\n").arg(u)+
insilmaril@366
  2534
					tr("Please use Settings->")+tr("Set application to open an URL"));
insilmaril@366
  2535
				return;
insilmaril@366
  2536
			}
insilmaril@366
  2537
			sleep (3);
insilmaril@366
  2538
		}
insilmaril@366
  2539
		if (browser.contains("konqueror"))
insilmaril@366
  2540
		{
insilmaril@366
  2541
			for (int i=0; i<urls.size(); i++)
insilmaril@366
  2542
			{
insilmaril@366
  2543
				// Open new browser
insilmaril@366
  2544
				// Try to open new tab in existing konqueror started previously by vym
insilmaril@366
  2545
				p=new QProcess (this);
insilmaril@366
  2546
				args.clear();
insilmaril@366
  2547
				args<< QString("konqueror-%1").arg(procBrowser->pid())<< 
insilmaril@366
  2548
					"konqueror-mainwindow#1"<< 
insilmaril@366
  2549
					"newTab" << 
insilmaril@366
  2550
					urls.at(i);
insilmaril@366
  2551
				p->start ("dcop",args);
insilmaril@366
  2552
				if ( !p->waitForStarted() ) success=false;
insilmaril@366
  2553
			}
insilmaril@366
  2554
			if (!success)
insilmaril@366
  2555
				QMessageBox::warning(0, 
insilmaril@366
  2556
					tr("Warning"),
insilmaril@366
  2557
					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
insilmaril@366
  2558
			return;		
insilmaril@366
  2559
		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
insilmaril@366
  2560
		{
insilmaril@366
  2561
			for (int i=0; i<urls.size(); i++)
insilmaril@366
  2562
			{
insilmaril@366
  2563
				// Try to open new tab in firefox
insilmaril@366
  2564
				p=new QProcess (this);
insilmaril@366
  2565
				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
insilmaril@366
  2566
				p->start (browser,args);
insilmaril@366
  2567
				if ( !p->waitForStarted() ) success=false;
insilmaril@366
  2568
			}			
insilmaril@366
  2569
			if (!success)
insilmaril@366
  2570
				QMessageBox::warning(0, 
insilmaril@366
  2571
					tr("Warning"),
insilmaril@366
  2572
					tr("Couldn't start %1 to open a new tab").arg(browser));
insilmaril@366
  2573
			return;		
insilmaril@366
  2574
		}			
insilmaril@366
  2575
		QMessageBox::warning(0, 
insilmaril@366
  2576
			tr("Warning"),
insilmaril@366
  2577
			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
insilmaril@366
  2578
	}	
insilmaril@366
  2579
}
insilmaril@366
  2580
insilmaril@0
  2581
void Main::editOpenURL()
insilmaril@0
  2582
{
insilmaril@266
  2583
	// Open new browser
insilmaril@0
  2584
	if (currentMapEditor())
insilmaril@266
  2585
	{	
insilmaril@266
  2586
	    QString url=currentMapEditor()->getURL();
insilmaril@366
  2587
		QStringList args;
insilmaril@266
  2588
		if (url=="") return;
insilmaril@366
  2589
		QString browser=settings.value("/mainwindow/readerURL" ).toString();
insilmaril@266
  2590
		procBrowser = new QProcess( this );
insilmaril@366
  2591
		args<<url;
insilmaril@366
  2592
		procBrowser->start(browser,args);
insilmaril@366
  2593
		if ( !procBrowser->waitForStarted())
insilmaril@266
  2594
		{
insilmaril@266
  2595
			// try to set path to browser
insilmaril@266
  2596
			QMessageBox::warning(0, 
insilmaril@266
  2597
				tr("Warning"),
insilmaril@266
  2598
				tr("Couldn't find a viewer to open %1.\n").arg(url)+
insilmaril@266
  2599
				tr("Please use Settings->")+tr("Set application to open an URL"));
insilmaril@266
  2600
			settingsURL() ; 
insilmaril@266
  2601
		}	
insilmaril@266
  2602
	}	
insilmaril@266
  2603
}
insilmaril@266
  2604
void Main::editOpenURLTab()
insilmaril@266
  2605
{
insilmaril@266
  2606
	if (currentMapEditor())
insilmaril@266
  2607
	{	
insilmaril@366
  2608
	    QStringList urls;
insilmaril@366
  2609
		urls.append(currentMapEditor()->getURL());
insilmaril@366
  2610
		openTabs (urls);
insilmaril@266
  2611
	}	
insilmaril@0
  2612
}
insilmaril@366
  2613
void Main::editOpenMultipleURLTabs()
insilmaril@366
  2614
{
insilmaril@366
  2615
	if (currentMapEditor())
insilmaril@366
  2616
	{	
insilmaril@366
  2617
	    QStringList urls;
insilmaril@366
  2618
		urls=currentMapEditor()->getURLs();
insilmaril@366
  2619
		openTabs (urls);
insilmaril@366
  2620
	}	
insilmaril@366
  2621
}
insilmaril@366
  2622
insilmaril@0
  2623
insilmaril@0
  2624
void Main::editURL()
insilmaril@0
  2625
{
insilmaril@0
  2626
	if (currentMapEditor())
insilmaril@0
  2627
	    currentMapEditor()->editURL();
insilmaril@0
  2628
}
insilmaril@0
  2629
insilmaril@528
  2630
void Main::editLocalURL()
insilmaril@528
  2631
{
insilmaril@528
  2632
	if (currentMapEditor())
insilmaril@528
  2633
	    currentMapEditor()->editLocalURL();
insilmaril@528
  2634
}
insilmaril@528
  2635
insilmaril@0
  2636
void Main::editHeading2URL()
insilmaril@0
  2637
{
insilmaril@0
  2638
	if (currentMapEditor())
insilmaril@0
  2639
	    currentMapEditor()->editHeading2URL();
insilmaril@0
  2640
}
insilmaril@0
  2641
insilmaril@0
  2642
void Main::editBugzilla2URL()
insilmaril@0
  2643
{
insilmaril@0
  2644
	if (currentMapEditor())
insilmaril@0
  2645
	    currentMapEditor()->editBugzilla2URL();
insilmaril@0
  2646
}
insilmaril@0
  2647
insilmaril@175
  2648
void Main::editFATE2URL()
insilmaril@175
  2649
{
insilmaril@175
  2650
	if (currentMapEditor())
insilmaril@175
  2651
	    currentMapEditor()->editFATE2URL();
insilmaril@175
  2652
}
insilmaril@175
  2653
insilmaril@394
  2654
void Main::editHeadingFinished()
insilmaril@394
  2655
{
insilmaril@394
  2656
	// only called from editHeading(), so there is a currentME
insilmaril@394
  2657
	MapEditor *me=currentMapEditor();
insilmaril@421
  2658
	if (me)
insilmaril@421
  2659
	{
insilmaril@491
  2660
		me->setStateEditHeading (false);
insilmaril@421
  2661
		QPoint p;	//Not used here, only to find out pos of branch
insilmaril@421
  2662
		bool ok;
insilmaril@421
  2663
		QString s=me->getHeading(ok,p);
insilmaril@394
  2664
insilmaril@394
  2665
#if defined(Q_OS_MACX)
insilmaril@394
  2666
#else
insilmaril@421
  2667
		if (ok && s!=lineedit->text())
insilmaril@421
  2668
			me->setHeading(lineedit->text());
insilmaril@421
  2669
			
insilmaril@421
  2670
		lineedit->releaseKeyboard();
insilmaril@421
  2671
		lineedit->hide();
insilmaril@421
  2672
		setFocus();
insilmaril@394
  2673
#endif	
insilmaril@537
  2674
		if (!actionSettingsAutoSelectNewBranch->isOn() && 
insilmaril@537
  2675
			!prevSelection.isEmpty()) 
insilmaril@537
  2676
			me->select(prevSelection);
insilmaril@421
  2677
		prevSelection="";
insilmaril@421
  2678
	}
insilmaril@394
  2679
}
insilmaril@394
  2680
insilmaril@366
  2681
void Main::editHeading()
insilmaril@0
  2682
{
insilmaril@394
  2683
	if (currentMapEditor())
insilmaril@0
  2684
	{
insilmaril@394
  2685
		MapEditor *me=currentMapEditor();
insilmaril@394
  2686
		QString oldSel=me->getSelectString();
insilmaril@394
  2687
insilmaril@394
  2688
		if (lineedit->isVisible())
insilmaril@394
  2689
			editHeadingFinished();
insilmaril@394
  2690
		else
insilmaril@366
  2691
		{
insilmaril@366
  2692
			bool ok;
insilmaril@366
  2693
			QPoint p;
insilmaril@531
  2694
			QString s=me->getHeading(ok,p);
insilmaril@366
  2695
insilmaril@366
  2696
			if (ok)
insilmaril@366
  2697
			{
insilmaril@491
  2698
				me->setStateEditHeading (true);
insilmaril@366
  2699
#if defined(Q_OS_MACX)
insilmaril@531
  2700
				p=me->mapToGlobal (p);
insilmaril@366
  2701
				QDialog *d =new QDialog(NULL);
insilmaril@366
  2702
				QLineEdit *le=new QLineEdit (d);
insilmaril@366
  2703
				d->setWindowFlags (Qt::FramelessWindowHint);
insilmaril@394
  2704
				d->setGeometry(p.x(),p.y(),230,25);
insilmaril@394
  2705
				le->resize (d->width()-10,d->height());
insilmaril@366
  2706
				le->setText (s);
insilmaril@366
  2707
				le->selectAll();
insilmaril@366
  2708
				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
insilmaril@366
  2709
				d->activateWindow();
insilmaril@366
  2710
				d->exec();
insilmaril@531
  2711
				me->setHeading (le->text());
insilmaril@394
  2712
				delete (le);
insilmaril@394
  2713
				delete (d);
insilmaril@394
  2714
				editHeadingFinished();
insilmaril@366
  2715
#else
insilmaril@531
  2716
				p=me->mapTo (this,p);
insilmaril@394
  2717
				lineedit->setGeometry(p.x(),p.y(),230,25);
insilmaril@366
  2718
				lineedit->setText(s);
insilmaril@366
  2719
				lineedit->setCursorPosition(1);
insilmaril@366
  2720
				lineedit->selectAll();
insilmaril@366
  2721
				lineedit->show();
insilmaril@366
  2722
				lineedit->grabKeyboard();
insilmaril@366
  2723
				lineedit->setFocus();
insilmaril@366
  2724
#endif
insilmaril@366
  2725
			}
insilmaril@366
  2726
		}
insilmaril@394
  2727
	} // currentMapEditor()	
insilmaril@366
  2728
}
insilmaril@366
  2729
insilmaril@366
  2730
void Main::openVymLinks(const QStringList &vl)
insilmaril@366
  2731
{
insilmaril@366
  2732
	for (int j=0; j<vl.size(); j++)
insilmaril@366
  2733
	{
insilmaril@0
  2734
		// compare path with already loaded maps
insilmaril@0
  2735
		int index=-1;
insilmaril@0
  2736
		int i;
insilmaril@0
  2737
		MapEditor *me;
insilmaril@0
  2738
		for (i=0;i<=tabWidget->count() -1;i++)
insilmaril@0
  2739
		{
insilmaril@0
  2740
			me=(MapEditor*)tabWidget->page(i);
insilmaril@366
  2741
			if (vl.at(j)==me->getFilePath() )
insilmaril@0
  2742
			{
insilmaril@0
  2743
				index=i;
insilmaril@0
  2744
				break;
insilmaril@0
  2745
			}
insilmaril@0
  2746
		}	
insilmaril@0
  2747
		if (index<0)
insilmaril@0
  2748
		// Load map
insilmaril@0
  2749
		{
insilmaril@366
  2750
			if (!QFile(vl.at(j)).exists() )
insilmaril@0
  2751
				QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@366
  2752
				   tr("Couldn't open map %1").arg(vl.at(j)));
insilmaril@0
  2753
			else
insilmaril@0
  2754
			{
insilmaril@366
  2755
				fileLoad (vl.at(j), NewMap);
insilmaril@0
  2756
				tabWidget->setCurrentPage (tabWidget->count()-1);	
insilmaril@0
  2757
			}
insilmaril@0
  2758
		} else
insilmaril@0
  2759
			// Go to tab containing the map
insilmaril@0
  2760
			tabWidget->setCurrentPage (index);	
insilmaril@0
  2761
	}
insilmaril@0
  2762
}
insilmaril@0
  2763
insilmaril@366
  2764
void Main::editOpenVymLink()
insilmaril@366
  2765
{
insilmaril@366
  2766
	if (currentMapEditor())
insilmaril@366
  2767
	{
insilmaril@366
  2768
		QStringList vl;
insilmaril@366
  2769
		vl.append(currentMapEditor()->getVymLink());	
insilmaril@366
  2770
		openVymLinks (vl);
insilmaril@366
  2771
	}
insilmaril@366
  2772
}
insilmaril@366
  2773
insilmaril@366
  2774
void Main::editOpenMultipleVymLinks()
insilmaril@366
  2775
{
insilmaril@366
  2776
	QString currentVymLink;
insilmaril@366
  2777
	if (currentMapEditor())
insilmaril@366
  2778
	{
insilmaril@366
  2779
		QStringList vl=currentMapEditor()->getVymLinks();
insilmaril@366
  2780
		openVymLinks (vl);
insilmaril@366
  2781
	}
insilmaril@366
  2782
}
insilmaril@366
  2783
insilmaril@0
  2784
void Main::editVymLink()
insilmaril@0
  2785
{
insilmaril@0
  2786
	if (currentMapEditor())
insilmaril@0
  2787
		currentMapEditor()->editVymLink();	
insilmaril@0
  2788
}
insilmaril@0
  2789
insilmaril@0
  2790
void Main::editDeleteVymLink()
insilmaril@0
  2791
{
insilmaril@0
  2792
	if (currentMapEditor())
insilmaril@0
  2793
		currentMapEditor()->deleteVymLink();	
insilmaril@0
  2794
}
insilmaril@0
  2795
insilmaril@243
  2796
void Main::editToggleHideExport()
insilmaril@243
  2797
{
insilmaril@243
  2798
	if (currentMapEditor())
insilmaril@294
  2799
		currentMapEditor()->toggleHideExport();	
insilmaril@243
  2800
}
insilmaril@243
  2801
insilmaril@0
  2802
void Main::editMapInfo()
insilmaril@0
  2803
{
insilmaril@0
  2804
	if (currentMapEditor())
insilmaril@0
  2805
		currentMapEditor()->editMapInfo();	
insilmaril@0
  2806
}
insilmaril@0
  2807
insilmaril@0
  2808
void Main::editMoveUp()
insilmaril@0
  2809
{
insilmaril@0
  2810
	if (currentMapEditor())
insilmaril@0
  2811
	    currentMapEditor()->moveBranchUp();
insilmaril@0
  2812
}
insilmaril@0
  2813
insilmaril@0
  2814
void Main::editMoveDown()
insilmaril@0
  2815
{
insilmaril@0
  2816
	if (currentMapEditor())
insilmaril@0
  2817
		currentMapEditor()->moveBranchDown();
insilmaril@0
  2818
}
insilmaril@0
  2819
insilmaril@0
  2820
void Main::editToggleScroll()
insilmaril@0
  2821
{
insilmaril@0
  2822
	if (currentMapEditor())
insilmaril@0
  2823
	{
insilmaril@0
  2824
		currentMapEditor()->toggleScroll();	
insilmaril@0
  2825
	}	
insilmaril@0
  2826
}
insilmaril@0
  2827
insilmaril@473
  2828
void Main::editUnscrollChilds()
insilmaril@0
  2829
{
insilmaril@0
  2830
	if (currentMapEditor())
insilmaril@428
  2831
		currentMapEditor()->unscrollChilds();	
insilmaril@394
  2832
}
insilmaril@394
  2833
insilmaril@394
  2834
void Main::editNewBranch()
insilmaril@394
  2835
{
insilmaril@394
  2836
	MapEditor *me=currentMapEditor();
insilmaril@394
  2837
	if (!lineedit->isVisible() && me)
insilmaril@0
  2838
	{
insilmaril@394
  2839
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2840
		BranchObj *newbo=me->addNewBranch(0);
insilmaril@394
  2841
insilmaril@534
  2842
		prevSelection=bo->getSelectString();
insilmaril@394
  2843
		if (newbo) 
insilmaril@394
  2844
			me->select (newbo->getSelectString());
insilmaril@394
  2845
		else
insilmaril@394
  2846
			return;
insilmaril@394
  2847
insilmaril@537
  2848
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2849
		{
insilmaril@394
  2850
			editHeading();
insilmaril@534
  2851
			return;
insilmaril@534
  2852
		}	
insilmaril@534
  2853
		if (!prevSelection.isEmpty()) 
insilmaril@534
  2854
		{
insilmaril@534
  2855
			me->select(prevSelection);
insilmaril@534
  2856
			prevSelection="";
insilmaril@394
  2857
		}
insilmaril@534
  2858
insilmaril@0
  2859
	}	
insilmaril@0
  2860
}
insilmaril@0
  2861
insilmaril@394
  2862
void Main::editNewBranchBefore()
insilmaril@0
  2863
{
insilmaril@394
  2864
	MapEditor *me=currentMapEditor();
insilmaril@394
  2865
	if (!lineedit->isVisible() && me)
insilmaril@394
  2866
	{
insilmaril@394
  2867
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2868
		BranchObj *newbo=me->addNewBranchBefore();
insilmaril@394
  2869
insilmaril@394
  2870
		if (newbo) 
insilmaril@394
  2871
			me->select (newbo->getSelectString());
insilmaril@394
  2872
		else
insilmaril@394
  2873
			return;
insilmaril@394
  2874
insilmaril@537
  2875
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2876
		{
insilmaril@537
  2877
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2878
				prevSelection=bo->getSelectString();
insilmaril@394
  2879
			editHeading();
insilmaril@394
  2880
		}
insilmaril@394
  2881
	}	
insilmaril@98
  2882
}
insilmaril@98
  2883
insilmaril@0
  2884
void Main::editNewBranchAbove()
insilmaril@0
  2885
{
insilmaril@394
  2886
	MapEditor *me=currentMapEditor();
insilmaril@394
  2887
	if (!lineedit->isVisible() && me)
insilmaril@394
  2888
	{
insilmaril@394
  2889
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2890
		BranchObj *newbo=me->addNewBranch (-1);
insilmaril@394
  2891
insilmaril@394
  2892
		if (newbo) 
insilmaril@394
  2893
			me->select (newbo->getSelectString());
insilmaril@394
  2894
		else
insilmaril@394
  2895
			return;
insilmaril@394
  2896
insilmaril@537
  2897
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2898
		{
insilmaril@537
  2899
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2900
				prevSelection=bo->getSelectString();
insilmaril@394
  2901
			editHeading();
insilmaril@394
  2902
		}
insilmaril@394
  2903
	}	
insilmaril@0
  2904
}
insilmaril@0
  2905
insilmaril@0
  2906
void Main::editNewBranchBelow()
insilmaril@0
  2907
{
insilmaril@394
  2908
	MapEditor *me=currentMapEditor();
insilmaril@394
  2909
	if (!lineedit->isVisible() && me)
insilmaril@394
  2910
	{
insilmaril@394
  2911
		BranchObj *bo=(BranchObj*)me->getSelection();
insilmaril@394
  2912
		BranchObj *newbo=me->addNewBranch (1);
insilmaril@394
  2913
insilmaril@394
  2914
		if (newbo) 
insilmaril@394
  2915
			me->select (newbo->getSelectString());
insilmaril@394
  2916
		else
insilmaril@394
  2917
			return;
insilmaril@394
  2918
insilmaril@537
  2919
		if (actionSettingsAutoEditNewBranch->isOn())
insilmaril@394
  2920
		{
insilmaril@537
  2921
			if (!actionSettingsAutoSelectNewBranch->isOn())
insilmaril@394
  2922
				prevSelection=bo->getSelectString();
insilmaril@394
  2923
			editHeading();
insilmaril@394
  2924
		}
insilmaril@394
  2925
	}	
insilmaril@0
  2926
}
insilmaril@0
  2927
insilmaril@0
  2928
void Main::editImportAdd()
insilmaril@0
  2929
{
insilmaril@0
  2930
	fileLoad (ImportAdd);
insilmaril@0
  2931
}
insilmaril@0
  2932
insilmaril@0
  2933
void Main::editImportReplace()
insilmaril@0
  2934
{
insilmaril@0
  2935
	fileLoad (ImportReplace);
insilmaril@0
  2936
}
insilmaril@0
  2937
insilmaril@0
  2938
void Main::editSaveBranch()
insilmaril@0
  2939
{
insilmaril@0
  2940
	fileSaveAs (PartOfMap);
insilmaril@0
  2941
}
insilmaril@0
  2942
insilmaril@395
  2943
void Main::editDeleteKeepChilds()
insilmaril@98
  2944
{
insilmaril@98
  2945
	if (currentMapEditor())
insilmaril@395
  2946
		currentMapEditor()->deleteKeepChilds();
insilmaril@98
  2947
}
insilmaril@98
  2948
insilmaril@395
  2949
void Main::editDeleteChilds()
insilmaril@98
  2950
{
insilmaril@98
  2951
	if (currentMapEditor())
insilmaril@395
  2952
		currentMapEditor()->deleteChilds();
insilmaril@98
  2953
}
insilmaril@98
  2954
insilmaril@0
  2955
void Main::editDeleteSelection()
insilmaril@0
  2956
{
insilmaril@151
  2957
	if (currentMapEditor() && actionSettingsUseDelKey->isOn())
insilmaril@0
  2958
		currentMapEditor()->deleteSelection();
insilmaril@0
  2959
}
insilmaril@0
  2960
insilmaril@0
  2961
void Main::editUpperBranch()
insilmaril@0
  2962
{
insilmaril@0
  2963
	if (currentMapEditor())
insilmaril@0
  2964
		currentMapEditor()->selectUpperBranch();
insilmaril@0
  2965
}
insilmaril@0
  2966
insilmaril@0
  2967
void Main::editLowerBranch()
insilmaril@0
  2968
{
insilmaril@0
  2969
	if (currentMapEditor())
insilmaril@0
  2970
		currentMapEditor()->selectLowerBranch();
insilmaril@0
  2971
}
insilmaril@0
  2972
insilmaril@0
  2973
void Main::editLeftBranch()
insilmaril@0
  2974
{
insilmaril@0
  2975
	if (currentMapEditor())
insilmaril@0
  2976
		currentMapEditor()->selectLeftBranch();
insilmaril@0
  2977
}
insilmaril@0
  2978
insilmaril@0
  2979
void Main::editRightBranch()
insilmaril@0
  2980
{
insilmaril@0
  2981
	if (currentMapEditor())
insilmaril@0
  2982
		currentMapEditor()->selectRightBranch();
insilmaril@0
  2983
}
insilmaril@0
  2984
insilmaril@0
  2985
void Main::editFirstBranch()
insilmaril@0
  2986
{
insilmaril@0
  2987
	if (currentMapEditor())
insilmaril@0
  2988
		currentMapEditor()->selectFirstBranch();
insilmaril@0
  2989
}
insilmaril@0
  2990
insilmaril@0
  2991
void Main::editLastBranch()
insilmaril@0
  2992
{
insilmaril@0
  2993
	if (currentMapEditor())
insilmaril@0
  2994
		currentMapEditor()->selectLastBranch();
insilmaril@0
  2995
}
insilmaril@0
  2996
insilmaril@0
  2997
void Main::editLoadImage()
insilmaril@0
  2998
{
insilmaril@0
  2999
	if (currentMapEditor())
insilmaril@0
  3000
		currentMapEditor()->loadFloatImage();
insilmaril@0
  3001
}
insilmaril@0
  3002
insilmaril@366
  3003
void Main::editSaveImage()
insilmaril@0
  3004
{
insilmaril@0
  3005
	if (currentMapEditor())
insilmaril@366
  3006
		currentMapEditor()->saveFloatImage();
insilmaril@0
  3007
}
insilmaril@0
  3008
insilmaril@366
  3009
void Main::editFollowXLink(QAction *a)
insilmaril@366
  3010
{
insilmaril@366
  3011
insilmaril@366
  3012
	if (currentMapEditor())
insilmaril@366
  3013
		currentMapEditor()->followXLink(branchXLinksContextMenuFollow->actions().indexOf(a));
insilmaril@366
  3014
}
insilmaril@366
  3015
insilmaril@366
  3016
void Main::editEditXLink(QAction *a)
insilmaril@89
  3017
{
insilmaril@89
  3018
	if (currentMapEditor())
insilmaril@366
  3019
		currentMapEditor()->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
insilmaril@94
  3020
}
insilmaril@94
  3021
insilmaril@0
  3022
void Main::formatSelectColor()
insilmaril@0
  3023
{
insilmaril@0
  3024
	if (currentMapEditor())
insilmaril@0
  3025
	{
insilmaril@395
  3026
		QColor col = QColorDialog::getColor((currentColor ), this );
insilmaril@0
  3027
		if ( !col.isValid() ) return;
insilmaril@0
  3028
		colorChanged( col );
insilmaril@0
  3029
	}	
insilmaril@0
  3030
}
insilmaril@0
  3031
insilmaril@0
  3032
void Main::formatPickColor()
insilmaril@0
  3033
{
insilmaril@0
  3034
	if (currentMapEditor())
insilmaril@395
  3035
		colorChanged( currentMapEditor()->getCurrentHeadingColor() );
insilmaril@0
  3036
}
insilmaril@0
  3037
insilmaril@0
  3038
void Main::colorChanged(QColor c)
insilmaril@0
  3039
{
insilmaril@0
  3040
    QPixmap pix( 16, 16 );
insilmaril@0
  3041
    pix.fill( c );
insilmaril@0
  3042
    actionFormatColor->setIconSet( pix );
insilmaril@395
  3043
	currentColor=c;
insilmaril@0
  3044
}
insilmaril@0
  3045
insilmaril@0
  3046
void Main::formatColorBranch()
insilmaril@0
  3047
{
insilmaril@0
  3048
	if (currentMapEditor())
insilmaril@395
  3049
		currentMapEditor()->colorBranch(currentColor);
insilmaril@0
  3050
}
insilmaril@0
  3051
insilmaril@417
  3052
void Main::formatColorSubtree()
insilmaril@417
  3053
{
insilmaril@417
  3054
	if (currentMapEditor())
insilmaril@417
  3055
		currentMapEditor()->colorSubtree (currentColor);
insilmaril@417
  3056
}
insilmaril@417
  3057
insilmaril@0
  3058
void Main::formatLinkStyleLine()
insilmaril@0
  3059
{
insilmaril@0
  3060
	if (currentMapEditor())
insilmaril@398
  3061
		currentMapEditor()->setMapLinkStyle("StyleLine");
insilmaril@0
  3062
}
insilmaril@0
  3063
insilmaril@0
  3064
void Main::formatLinkStyleParabel()
insilmaril@0
  3065
{
insilmaril@0
  3066
	if (currentMapEditor())
insilmaril@398
  3067
		currentMapEditor()->setMapLinkStyle("StyleParabel");
insilmaril@0
  3068
}
insilmaril@0
  3069
insilmaril@0
  3070
void Main::formatLinkStylePolyLine()
insilmaril@0
  3071
{
insilmaril@0
  3072
	if (currentMapEditor())
insilmaril@398
  3073
		currentMapEditor()->setMapLinkStyle("StylePolyLine");
insilmaril@0
  3074
}
insilmaril@0
  3075
insilmaril@0
  3076
void Main::formatLinkStylePolyParabel()
insilmaril@0
  3077
{
insilmaril@0
  3078
	if (currentMapEditor())
insilmaril@398
  3079
		currentMapEditor()->setMapLinkStyle("StylePolyParabel");
insilmaril@0
  3080
}
insilmaril@0
  3081
insilmaril@0
  3082
void Main::formatSelectBackColor()
insilmaril@0
  3083
{
insilmaril@0
  3084
	if (currentMapEditor())
insilmaril@398
  3085
		currentMapEditor()->selectMapBackgroundColor();
insilmaril@0
  3086
}
insilmaril@0
  3087
insilmaril@408
  3088
void Main::formatSelectBackImage()
insilmaril@408
  3089
{
insilmaril@408
  3090
	if (currentMapEditor())
insilmaril@408
  3091
		currentMapEditor()->selectMapBackgroundImage();
insilmaril@408
  3092
}
insilmaril@408
  3093
insilmaril@0
  3094
void Main::formatSelectLinkColor()
insilmaril@0
  3095
{
insilmaril@0
  3096
	if (currentMapEditor())
insilmaril@398
  3097
		currentMapEditor()->selectMapLinkColor();
insilmaril@0
  3098
}
insilmaril@0
  3099
insilmaril@442
  3100
void Main::formatSelectSelectionColor()
insilmaril@442
  3101
{
insilmaril@442
  3102
	if (currentMapEditor())
insilmaril@442
  3103
		currentMapEditor()->selectMapSelectionColor();
insilmaril@442
  3104
}
insilmaril@442
  3105
insilmaril@0
  3106
void Main::formatToggleLinkColorHint()
insilmaril@0
  3107
{
insilmaril@398
  3108
	currentMapEditor()->toggleMapLinkColorHint();
insilmaril@0
  3109
}
insilmaril@0
  3110
insilmaril@0
  3111
insilmaril@421
  3112
void Main::formatHideLinkUnselected()	//FIXME get rid of this with imagepropertydialog
insilmaril@160
  3113
{
insilmaril@160
  3114
	if (currentMapEditor())
insilmaril@160
  3115
		currentMapEditor()->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
insilmaril@160
  3116
}
insilmaril@160
  3117
insilmaril@0
  3118
void Main::viewZoomReset()
insilmaril@0
  3119
{
insilmaril@0
  3120
	if (currentMapEditor())
insilmaril@0
  3121
	{
insilmaril@366
  3122
		QMatrix m;
insilmaril@0
  3123
		m.reset();
insilmaril@408
  3124
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3125
	}	
insilmaril@0
  3126
}
insilmaril@0
  3127
insilmaril@0
  3128
void Main::viewZoomIn()
insilmaril@0
  3129
{
insilmaril@0
  3130
	if (currentMapEditor())
insilmaril@0
  3131
	{
insilmaril@408
  3132
		QMatrix m = currentMapEditor()->matrix();
insilmaril@0
  3133
		m.scale( 1.25, 1.25 );
insilmaril@408
  3134
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3135
	}	
insilmaril@0
  3136
}
insilmaril@0
  3137
insilmaril@0
  3138
void Main::viewZoomOut()
insilmaril@0
  3139
{
insilmaril@0
  3140
	if (currentMapEditor())
insilmaril@0
  3141
	{
insilmaril@408
  3142
		QMatrix m = currentMapEditor()->matrix();
insilmaril@0
  3143
		m.scale( 0.8, 0.8 );
insilmaril@408
  3144
		currentMapEditor()->setMatrix( m );
insilmaril@0
  3145
	}	
insilmaril@0
  3146
}
insilmaril@89
  3147
insilmaril@526
  3148
void Main::viewCenter()
insilmaril@526
  3149
{
insilmaril@526
  3150
	MapEditor *me=currentMapEditor();
insilmaril@526
  3151
	if (me)
insilmaril@526
  3152
	{
insilmaril@526
  3153
		me->ensureSelectionVisible();
insilmaril@526
  3154
	}	
insilmaril@526
  3155
}
insilmaril@526
  3156
insilmaril@528
  3157
void Main::networkStartServer()
insilmaril@528
  3158
{
insilmaril@528
  3159
	MapEditor *me=currentMapEditor();
insilmaril@528
  3160
	if (me) me->newServer();
insilmaril@528
  3161
}
insilmaril@528
  3162
insilmaril@528
  3163
void Main::networkConnect()
insilmaril@528
  3164
{
insilmaril@528
  3165
	MapEditor *me=currentMapEditor();
insilmaril@531
  3166
	if (me) me->connectToServer();
insilmaril@528
  3167
}
insilmaril@528
  3168
insilmaril@0
  3169
bool Main::settingsPDF()
insilmaril@0
  3170
{
insilmaril@0
  3171
	// Default browser is set in constructor
insilmaril@0
  3172
	bool ok;
insilmaril@0
  3173
	QString text = QInputDialog::getText(
insilmaril@266
  3174
		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
insilmaril@366
  3175
		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
insilmaril@0
  3176
	if (ok)
insilmaril@366
  3177
		settings.setValue ("/mainwindow/readerPDF",text);
insilmaril@0
  3178
	return ok;
insilmaril@0
  3179
}
insilmaril@0
  3180
insilmaril@0
  3181
insilmaril@0
  3182
bool Main::settingsURL()
insilmaril@0
  3183
{
insilmaril@0
  3184
	// Default browser is set in constructor
insilmaril@0
  3185
	bool ok;
insilmaril@0
  3186
	QString text = QInputDialog::getText(
insilmaril@266
  3187
		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
insilmaril@366
  3188
		settings.value("/mainwindow/readerURL").toString()
insilmaril@0
  3189
		, &ok, this );
insilmaril@0
  3190
	if (ok)
insilmaril@366
  3191
		settings.setValue ("/mainwindow/readerURL",text);
insilmaril@0
  3192
	return ok;
insilmaril@0
  3193
}
insilmaril@0
  3194
insilmaril@450
  3195
void Main::settingsMacroDir()
insilmaril@450
  3196
{
insilmaril@450
  3197
	QDir defdir=vymBaseDir;
insilmaril@450
  3198
	defdir.cd("macros");
insilmaril@450
  3199
	if (!defdir.exists())
insilmaril@450
  3200
		defdir=vymBaseDir;
insilmaril@450
  3201
	QDir dir=QFileDialog::getExistingDirectory (
insilmaril@450
  3202
		this,
insilmaril@450
  3203
		tr ("Directory with vym macros:"), 
insilmaril@450
  3204
		settings.value ("/macros/macroDir",defdir.path()).toString()
insilmaril@450
  3205
	);
insilmaril@450
  3206
	if (dir.exists())
insilmaril@450
  3207
		settings.setValue ("/macros/macroDir",dir.path());
insilmaril@450
  3208
}
insilmaril@450
  3209
insilmaril@473
  3210
void Main::settingsUndoLevels()
insilmaril@473
  3211
{
insilmaril@473
  3212
	bool ok;
insilmaril@473
  3213
	int i = QInputDialog::getInteger(
insilmaril@473
  3214
		this, 
insilmaril@473
  3215
		tr("QInputDialog::getInteger()"),
insilmaril@473
  3216
	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
insilmaril@473
  3217
	if (ok)
insilmaril@473
  3218
	{
insilmaril@473
  3219
		settings.setValue ("/mapeditor/stepsTotal",i);
insilmaril@473
  3220
		QMessageBox::information( this, tr( "VYM -Information:" ),
insilmaril@473
  3221
		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
insilmaril@473
  3222
   }	
insilmaril@473
  3223
}
insilmaril@473
  3224
insilmaril@473
  3225
void Main::settingsAutosaveToggle()
insilmaril@473
  3226
{
insilmaril@531
  3227
	settings.setValue ("/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
insilmaril@473
  3228
}
insilmaril@473
  3229
insilmaril@473
  3230
void Main::settingsAutosaveTime()
insilmaril@473
  3231
{
insilmaril@473
  3232
	bool ok;
insilmaril@473
  3233
	int i = QInputDialog::getInteger(
insilmaril@473
  3234
		this, 
insilmaril@473
  3235
		tr("QInputDialog::getInteger()"),
insilmaril@473
  3236
	    tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
insilmaril@473
  3237
	if (ok)
insilmaril@473
  3238
	{
insilmaril@473
  3239
		settings.setValue ("/mapeditor/autosave/ms",i * 1000);
insilmaril@473
  3240
    }	
insilmaril@473
  3241
}
insilmaril@473
  3242
insilmaril@327
  3243
void Main::settingsToggleDelKey()
insilmaril@327
  3244
{
insilmaril@327
  3245
	if (actionSettingsUseDelKey->isOn())
insilmaril@327
  3246
	{
insilmaril@366
  3247
		actionEditDelete->setAccel (QKeySequence (Qt::Key_Delete));
insilmaril@327
  3248
	} else
insilmaril@327
  3249
	{
insilmaril@327
  3250
		actionEditDelete->setAccel (QKeySequence (""));
insilmaril@327
  3251
	}
insilmaril@327
  3252
}
insilmaril@327
  3253
insilmaril@0
  3254
void Main::windowToggleNoteEditor()
insilmaril@0
  3255
{
insilmaril@502
  3256
	if (textEditor->isVisible() )
insilmaril@497
  3257
		windowHideNoteEditor();
insilmaril@497
  3258
	else
insilmaril@497
  3259
		windowShowNoteEditor();
insilmaril@0
  3260
}
insilmaril@0
  3261
insilmaril@294
  3262
void Main::windowToggleHistory()
insilmaril@294
  3263
{
insilmaril@404
  3264
	if (historyWindow->isVisible())
insilmaril@404
  3265
		historyWindow->hide();
insilmaril@404
  3266
	else	
insilmaril@404
  3267
		historyWindow->show();
insilmaril@404
  3268
insilmaril@404
  3269
}
insilmaril@404
  3270
insilmaril@473
  3271
void Main::windowToggleProperty()
insilmaril@473
  3272
{
insilmaril@473
  3273
	if (branchPropertyWindow->isVisible())
insilmaril@473
  3274
		branchPropertyWindow->hide();
insilmaril@473
  3275
	else	
insilmaril@473
  3276
		branchPropertyWindow->show();
insilmaril@486
  3277
insilmaril@473
  3278
	if(currentMapEditor())
insilmaril@473
  3279
	{
insilmaril@473
  3280
		LinkableMapObj *sel=currentMapEditor()->getSelection();
insilmaril@473
  3281
		if (sel && (typeid(*sel) == typeid(BranchObj) ||
insilmaril@473
  3282
		           typeid(*sel) == typeid(MapCenterObj)))
insilmaril@473
  3283
		{
insilmaril@473
  3284
			branchPropertyWindow->setMapEditor(currentMapEditor());
insilmaril@473
  3285
			branchPropertyWindow->setBranch((BranchObj*)sel);
insilmaril@473
  3286
			return;
insilmaril@473
  3287
		}
insilmaril@473
  3288
		
insilmaril@473
  3289
	}	
insilmaril@473
  3290
	branchPropertyWindow->setBranch(NULL);
insilmaril@473
  3291
}
insilmaril@473
  3292
insilmaril@408
  3293
void Main::windowToggleAntiAlias()
insilmaril@408
  3294
{
insilmaril@408
  3295
	bool b=actionViewToggleAntiAlias->isOn();
insilmaril@408
  3296
	MapEditor *me;
insilmaril@408
  3297
	for (int i=0;i<tabWidget->count();i++)
insilmaril@408
  3298
	{
insilmaril@408
  3299
		
insilmaril@408
  3300
		me=(MapEditor*)tabWidget->page(i);
insilmaril@408
  3301
		me->setAntiAlias(b);
insilmaril@408
  3302
	}	
insilmaril@408
  3303
insilmaril@408
  3304
}
insilmaril@408
  3305
insilmaril@408
  3306
void Main::windowToggleSmoothPixmap()
insilmaril@408
  3307
{
insilmaril@408
  3308
	bool b=actionViewToggleSmoothPixmapTransform->isOn();
insilmaril@408
  3309
	MapEditor *me;
insilmaril@408
  3310
	for (int i=0;i<tabWidget->count();i++)
insilmaril@408
  3311
	{
insilmaril@408
  3312
		
insilmaril@408
  3313
		me=(MapEditor*)tabWidget->page(i);
insilmaril@408
  3314
		me->setSmoothPixmap(b);
insilmaril@408
  3315
	}	
insilmaril@408
  3316
}
insilmaril@408
  3317
insilmaril@404
  3318
void Main::updateHistory(SimpleSettings &undoSet)
insilmaril@404
  3319
{
insilmaril@404
  3320
	historyWindow->update (undoSet);
insilmaril@294
  3321
}
insilmaril@294
  3322
insilmaril@160
  3323
void Main::updateNoteFlag()
insilmaril@160
  3324
{
insilmaril@160
  3325
	if (currentMapEditor())
insilmaril@160
  3326
		currentMapEditor()->updateNoteFlag();
insilmaril@160
  3327
}
insilmaril@160
  3328
insilmaril@442
  3329
void Main::updateSatellites(MapEditor *me)
insilmaril@442
  3330
{
insilmaril@442
  3331
	branchPropertyWindow->setMapEditor (me);
insilmaril@442
  3332
}
insilmaril@442
  3333
insilmaril@390
  3334
void Main::updateActions()
insilmaril@390
  3335
{
insilmaril@390
  3336
	MapEditor *me=currentMapEditor();
insilmaril@390
  3337
	if (!me) return;
insilmaril@390
  3338
insilmaril@491
  3339
	historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(currentMapEditor()->getFileName()));
insilmaril@407
  3340
insilmaril@390
  3341
	// updateActions is also called when NoteEditor is closed
insilmaril@486
  3342
	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
insilmaril@486
  3343
	actionViewToggleHistoryWindow->setOn (historyWindow->isVisible());
insilmaril@486
  3344
	actionViewTogglePropertyWindow->setOn (branchPropertyWindow->isVisible());
insilmaril@390
  3345
insilmaril@473
  3346
	if (me->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
insilmaril@390
  3347
		actionFormatLinkColorHint->setOn(true);
insilmaril@390
  3348
	else	
insilmaril@390
  3349
		actionFormatLinkColorHint->setOn(false);
insilmaril@390
  3350
insilmaril@398
  3351
	switch (me->getMapLinkStyle())
insilmaril@390
  3352
	{
insilmaril@473
  3353
		case LinkableMapObj::Line: 
insilmaril@390
  3354
			actionFormatLinkStyleLine->setOn(true);
insilmaril@390
  3355
			break;
insilmaril@473
  3356
		case LinkableMapObj::Parabel:
insilmaril@390
  3357
			actionFormatLinkStyleParabel->setOn(true);
insilmaril@390
  3358
			break;
insilmaril@473
  3359
		case LinkableMapObj::PolyLine:	
insilmaril@390
  3360
			actionFormatLinkStylePolyLine->setOn(true);
insilmaril@390
  3361
			break;
insilmaril@473
  3362
		case LinkableMapObj::PolyParabel:	
insilmaril@390
  3363
			actionFormatLinkStylePolyParabel->setOn(true);
insilmaril@390
  3364
			break;
insilmaril@390
  3365
		default:
insilmaril@390
  3366
			break;
insilmaril@390
  3367
	}	
insilmaril@390
  3368
insilmaril@442
  3369
	// Update colors
insilmaril@390
  3370
	QPixmap pix( 16, 16 );
insilmaril@398
  3371
    pix.fill( me->getMapBackgroundColor() );
insilmaril@390
  3372
    actionFormatBackColor->setIconSet( pix );
insilmaril@442
  3373
    pix.fill( me->getSelectionColor() );
insilmaril@442
  3374
    actionFormatSelectionColor->setIconSet( pix );
insilmaril@398
  3375
    pix.fill( me->getMapDefLinkColor() );
insilmaril@390
  3376
    actionFormatLinkColor->setIconSet( pix );
insilmaril@390
  3377
insilmaril@442
  3378
insilmaril@486
  3379
	actionFileSave->setEnabled( me->hasChanged() );
insilmaril@390
  3380
	if (me->isUndoAvailable())
insilmaril@390
  3381
		actionEditUndo->setEnabled( true);
insilmaril@390
  3382
	else	
insilmaril@390
  3383
		actionEditUndo->setEnabled( false);
insilmaril@390
  3384
insilmaril@390
  3385
	if (me->isRedoAvailable())
insilmaril@390
  3386
		actionEditRedo->setEnabled( true);
insilmaril@390
  3387
	else	
insilmaril@390
  3388
		actionEditRedo->setEnabled( false);
insilmaril@390
  3389
insilmaril@390
  3390
	LinkableMapObj *selection=me->getSelection();
insilmaril@390
  3391
	if (selection)
insilmaril@390
  3392
	{
insilmaril@390
  3393
		if ( (typeid(*selection) == typeid(BranchObj)) || 
insilmaril@390
  3394
			(typeid(*selection) == typeid(MapCenterObj))  )
insilmaril@390
  3395
		{
insilmaril@390
  3396
			BranchObj *bo=(BranchObj*)selection;
insilmaril@390
  3397
			// Take care of links
insilmaril@390
  3398
			if (bo->countXLinks()==0)
insilmaril@390
  3399
			{
insilmaril@390
  3400
				branchXLinksContextMenuEdit->clear();
insilmaril@390
  3401
				branchXLinksContextMenuFollow->clear();
insilmaril@390
  3402
			} else
insilmaril@390
  3403
			{
insilmaril@390
  3404
				BranchObj *bot;
insilmaril@390
  3405
				QString s;
insilmaril@390
  3406
				branchXLinksContextMenuEdit->clear();
insilmaril@390
  3407
				branchXLinksContextMenuFollow->clear();
insilmaril@390
  3408
				for (int i=0; i<=bo->countXLinks();i++)
insilmaril@390
  3409
				{
insilmaril@390
  3410
					bot=bo->XLinkTargetAt(i);
insilmaril@390
  3411
					if (bot)
insilmaril@390
  3412
					{
insilmaril@390
  3413
						s=bot->getHeading();
insilmaril@390
  3414
						if (s.length()>25)
insilmaril@390
  3415
							s=s.left(25)+"...";
insilmaril@390
  3416
						branchXLinksContextMenuFollow->addAction (s);
insilmaril@390
  3417
						branchXLinksContextMenuEdit->addAction (s);
insilmaril@390
  3418
					}	
insilmaril@390
  3419
				}
insilmaril@390
  3420
			}
insilmaril@390
  3421
insilmaril@390
  3422
			standardFlagsDefault->setEnabled (true);
insilmaril@390
  3423
insilmaril@390
  3424
			actionEditToggleScroll->setEnabled (true);
insilmaril@390
  3425
			if ( bo->isScrolled() )
insilmaril@390
  3426
				actionEditToggleScroll->setOn(true);
insilmaril@390
  3427
			else	
insilmaril@390
  3428
				actionEditToggleScroll->setOn(false);
insilmaril@390
  3429
insilmaril@390
  3430
			if ( bo->getURL().isEmpty() )
insilmaril@390
  3431
			{
insilmaril@390
  3432
				actionEditOpenURL->setEnabled (false);
insilmaril@390
  3433
				actionEditOpenURLTab->setEnabled (false);
insilmaril@390
  3434
			}	
insilmaril@390
  3435
			else	
insilmaril@390
  3436
			{
insilmaril@390
  3437
				actionEditOpenURL->setEnabled (true);
insilmaril@390
  3438
				actionEditOpenURLTab->setEnabled (true);
insilmaril@390
  3439
			}
insilmaril@390
  3440
			if ( bo->getVymLink().isEmpty() )
insilmaril@390
  3441
			{
insilmaril@390
  3442
				actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3443
				actionEditDeleteVymLink->setEnabled (false);
insilmaril@390
  3444
			} else	
insilmaril@390
  3445
			{
insilmaril@390
  3446
				actionEditOpenVymLink->setEnabled (true);
insilmaril@390
  3447
				actionEditDeleteVymLink->setEnabled (true);
insilmaril@390
  3448
			}	
insilmaril@390
  3449
insilmaril@390
  3450
			if (bo->canMoveBranchUp()) 
insilmaril@390
  3451
				actionEditMoveUp->setEnabled (true);
insilmaril@390
  3452
			else	
insilmaril@390
  3453
				actionEditMoveUp->setEnabled (false);
insilmaril@390
  3454
			if (bo->canMoveBranchDown()) 
insilmaril@390
  3455
				actionEditMoveDown->setEnabled (true);
insilmaril@390
  3456
			else	
insilmaril@390
  3457
				actionEditMoveDown->setEnabled (false);
insilmaril@390
  3458
insilmaril@390
  3459
insilmaril@390
  3460
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@390
  3461
			actionEditToggleHideExport->setOn (bo->hideInExport() );	
insilmaril@390
  3462
insilmaril@390
  3463
			actionEditCopy->setEnabled (true);	
insilmaril@390
  3464
			actionEditCut->setEnabled (true);	
insilmaril@390
  3465
			if (!clipboardEmpty)
insilmaril@390
  3466
				actionEditPaste->setEnabled (true);	
insilmaril@390
  3467
			else	
insilmaril@390
  3468
				actionEditPaste->setEnabled (false);	
insilmaril@406
  3469
			for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3470
				actionListBranches.at(i)->setEnabled(true);
insilmaril@390
  3471
			actionEditDelete->setEnabled (true);
insilmaril@390
  3472
			actionFormatHideLinkUnselected->setOn
insilmaril@390
  3473
				(selection->getHideLinkUnselected());
insilmaril@390
  3474
		}
insilmaril@390
  3475
		if ( (typeid(*selection) == typeid(FloatImageObj)) )
insilmaril@390
  3476
		{
insilmaril@390
  3477
			FloatObj *fo=(FloatImageObj*)selection;
insilmaril@390
  3478
insilmaril@390
  3479
			actionEditOpenURL->setEnabled (false);
insilmaril@390
  3480
			actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3481
			actionEditDeleteVymLink->setEnabled (false);	
insilmaril@390
  3482
			actionEditToggleHideExport->setEnabled (true);	
insilmaril@390
  3483
			actionEditToggleHideExport->setOn (fo->hideInExport() );	
insilmaril@390
  3484
insilmaril@390
  3485
insilmaril@390
  3486
			actionEditCopy->setEnabled (true);
insilmaril@390
  3487
			actionEditCut->setEnabled (true);	
insilmaril@390
  3488
			actionEditPaste->setEnabled (false);
insilmaril@406
  3489
			for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3490
				actionListBranches.at(i)->setEnabled(false);
insilmaril@390
  3491
			actionEditDelete->setEnabled (true);
insilmaril@390
  3492
			actionFormatHideLinkUnselected->setOn
insilmaril@390
  3493
				( selection->getHideLinkUnselected());
insilmaril@390
  3494
			actionEditMoveUp->setEnabled (false);
insilmaril@390
  3495
			actionEditMoveDown->setEnabled (false);
insilmaril@390
  3496
		}
insilmaril@390
  3497
insilmaril@390
  3498
	} else
insilmaril@390
  3499
	{
insilmaril@390
  3500
		actionEditCopy->setEnabled (false);	
insilmaril@390
  3501
		actionEditCut->setEnabled (false);	
insilmaril@390
  3502
		actionEditPaste->setEnabled (false);	
insilmaril@406
  3503
		for (int i=0; i<actionListBranches.size(); ++i)	
insilmaril@406
  3504
			actionListBranches.at(i)->setEnabled(false);
insilmaril@390
  3505
insilmaril@390
  3506
		actionEditToggleScroll->setEnabled (false);
insilmaril@390
  3507
		actionEditOpenURL->setEnabled (false);
insilmaril@390
  3508
		actionEditOpenVymLink->setEnabled (false);
insilmaril@390
  3509
		actionEditDeleteVymLink->setEnabled (false);	
insilmaril@390
  3510
		actionEditHeading2URL->setEnabled (false);	
insilmaril@390
  3511
		actionEditDelete->setEnabled (false);
insilmaril@390
  3512
		actionEditMoveUp->setEnabled (false);
insilmaril@390
  3513
		actionEditMoveDown->setEnabled (false);
insilmaril@390
  3514
		actionEditToggleHideExport->setEnabled (false);	
insilmaril@390
  3515
	}	
insilmaril@390
  3516
}
insilmaril@390
  3517
insilmaril@473
  3518
Main::ModMode Main::getModMode()
insilmaril@390
  3519
{
insilmaril@390
  3520
	if (actionModModeColor->isOn()) return ModModeColor;
insilmaril@390
  3521
	if (actionModModeCopy->isOn()) return ModModeCopy;
insilmaril@390
  3522
	if (actionModModeXLink->isOn()) return ModModeXLink;
insilmaril@390
  3523
	return ModModeNone;
insilmaril@390
  3524
}
insilmaril@390
  3525
insilmaril@537
  3526
bool Main::autoEditNewBranch()
insilmaril@390
  3527
{
insilmaril@537
  3528
	return actionSettingsAutoEditNewBranch->isOn();
insilmaril@390
  3529
}
insilmaril@390
  3530
insilmaril@537
  3531
bool Main::autoSelectNewBranch()
insilmaril@390
  3532
{
insilmaril@537
  3533
	return actionSettingsAutoSelectNewBranch->isOn();
insilmaril@390
  3534
}
insilmaril@390
  3535
insilmaril@390
  3536
bool Main::useFlagGroups()
insilmaril@390
  3537
{
insilmaril@390
  3538
	return actionSettingsUseFlagGroups->isOn();
insilmaril@390
  3539
}
insilmaril@390
  3540
insilmaril@0
  3541
void Main::windowShowNoteEditor()
insilmaril@0
  3542
{
insilmaril@497
  3543
	textEditor->setShowWithMain(true);
insilmaril@0
  3544
	textEditor->show();
insilmaril@0
  3545
	actionViewToggleNoteEditor->setOn (true);
insilmaril@0
  3546
}
insilmaril@0
  3547
insilmaril@0
  3548
void Main::windowHideNoteEditor()
insilmaril@0
  3549
{
insilmaril@497
  3550
	textEditor->setShowWithMain(false);
insilmaril@0
  3551
	textEditor->hide();
insilmaril@0
  3552
	actionViewToggleNoteEditor->setOn (false);
insilmaril@0
  3553
}
insilmaril@0
  3554
insilmaril@434
  3555
void Main::setScript (const QString &script)
insilmaril@434
  3556
{
insilmaril@434
  3557
	scriptEditor->setScript (script);
insilmaril@434
  3558
}
insilmaril@434
  3559
insilmaril@434
  3560
void Main::runScript (const QString &script)
insilmaril@432
  3561
{
insilmaril@432
  3562
	if (currentMapEditor())
insilmaril@432
  3563
		currentMapEditor()->runScript (script);
insilmaril@432
  3564
}
insilmaril@432
  3565
insilmaril@514
  3566
void Main::runScriptEverywhere (const QString &script)
insilmaril@514
  3567
{
insilmaril@514
  3568
	MapEditor *me;
insilmaril@514
  3569
	for (int i=0;i<=tabWidget->count() -1;i++)
insilmaril@514
  3570
	{
insilmaril@514
  3571
		me=(MapEditor*)tabWidget->page(i);
insilmaril@514
  3572
		if (me) me->runScript (script);
insilmaril@514
  3573
	}	
insilmaril@514
  3574
}
insilmaril@514
  3575
insilmaril@0
  3576
void Main::windowNextEditor()
insilmaril@0
  3577
{
insilmaril@0
  3578
	if (tabWidget->currentPageIndex() < tabWidget->count())
insilmaril@0
  3579
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
insilmaril@0
  3580
}
insilmaril@0
  3581
insilmaril@0
  3582
void Main::windowPreviousEditor()
insilmaril@0
  3583
{
insilmaril@0
  3584
	if (tabWidget->currentPageIndex() >0)
insilmaril@0
  3585
		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
insilmaril@0
  3586
}
insilmaril@0
  3587
insilmaril@0
  3588
void Main::standardFlagChanged()
insilmaril@0
  3589
{
insilmaril@421
  3590
	if (currentMapEditor())
insilmaril@421
  3591
		currentMapEditor()->toggleStandardFlag(sender()->name());
insilmaril@0
  3592
}
insilmaril@0
  3593
insilmaril@527
  3594
void Main::testFunction1()
insilmaril@0
  3595
{
insilmaril@393
  3596
	if (!currentMapEditor()) return;
insilmaril@564
  3597
	currentMapEditor()->testFunction1();
insilmaril@527
  3598
}
insilmaril@527
  3599
insilmaril@527
  3600
void Main::testFunction2()
insilmaril@527
  3601
{
insilmaril@527
  3602
	if (!currentMapEditor()) return;
insilmaril@564
  3603
	currentMapEditor()->testFunction2();
insilmaril@0
  3604
}
insilmaril@0
  3605
insilmaril@393
  3606
void Main::testCommand()
insilmaril@393
  3607
{
insilmaril@393
  3608
	if (!currentMapEditor()) return;
insilmaril@432
  3609
	scriptEditor->show();
insilmaril@432
  3610
	/*
insilmaril@393
  3611
	bool ok;
insilmaril@393
  3612
	QString com = QInputDialog::getText(
insilmaril@404
  3613
			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
insilmaril@393
  3614
	if (ok) currentMapEditor()->parseAtom(com);
insilmaril@432
  3615
	*/
insilmaril@393
  3616
}
insilmaril@393
  3617
insilmaril@0
  3618
void Main::helpDoc()
insilmaril@0
  3619
{
insilmaril@395
  3620
	QString locale = QLocale::system().name();
insilmaril@395
  3621
	QString docname;
insilmaril@395
  3622
	if (locale.left(2)=="es")
insilmaril@395
  3623
		docname="vym_es.pdf";
insilmaril@395
  3624
	else	
insilmaril@395
  3625
		docname="vym.pdf";
insilmaril@420
  3626
insilmaril@420
  3627
	QStringList searchList;
insilmaril@395
  3628
	QDir docdir;
insilmaril@103
  3629
	#if defined(Q_OS_MACX)
insilmaril@537
  3630
		searchList << "./vym.app/Contents/Resources/doc";
insilmaril@103
  3631
	#else
insilmaril@103
  3632
		// default path in SUSE LINUX
insilmaril@587
  3633
		searchList <<"/usr/share/doc/packages/vym";
insilmaril@103
  3634
	#endif
insilmaril@0
  3635
insilmaril@420
  3636
	searchList << "doc";	// relative path for easy testing in tarball
insilmaril@420
  3637
	searchList << "doc/tex";	// Easy testing working on vym.tex
insilmaril@420
  3638
	searchList << "/usr/share/doc/vym";	// Debian
insilmaril@420
  3639
	searchList << "/usr/share/doc/packages";// Knoppix
insilmaril@420
  3640
insilmaril@420
  3641
	bool found=false;
insilmaril@420
  3642
	QFile docfile;
insilmaril@420
  3643
	for (int i=0; i<searchList.count(); ++i)
insilmaril@0
  3644
	{
insilmaril@420
  3645
		docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
insilmaril@420
  3646
		if (docfile.exists() )
insilmaril@0
  3647
		{
insilmaril@420
  3648
			found=true;
insilmaril@420
  3649
			break;
insilmaril@420
  3650
		}	
insilmaril@420
  3651
insilmaril@0
  3652
	}
insilmaril@420
  3653
	if (!found)
insilmaril@420
  3654
	{
insilmaril@420
  3655
		QMessageBox::critical(0, 
insilmaril@420
  3656
			tr("Critcal error"),
insilmaril@420
  3657
			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
insilmaril@420
  3658
		return;
insilmaril@420
  3659
	}	
insilmaril@420
  3660
insilmaril@408
  3661
	QStringList args;
insilmaril@0
  3662
	Process *pdfProc = new Process();
insilmaril@420
  3663
	args <<docfile.fileName();
insilmaril@420
  3664
insilmaril@420
  3665
	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
insilmaril@408
  3666
	if ( !pdfProc->waitForStarted() ) 
insilmaril@0
  3667
	{
insilmaril@0
  3668
		// error handling
insilmaril@266
  3669
		QMessageBox::warning(0, 
insilmaril@266
  3670
			tr("Warning"),
insilmaril@420
  3671
			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
insilmaril@266
  3672
			tr("Please use Settings->")+tr("Set application to open PDF files"));
insilmaril@266
  3673
		settingsPDF();	
insilmaril@0
  3674
		return;
insilmaril@0
  3675
	}
insilmaril@0
  3676
}
insilmaril@0
  3677
insilmaril@0
  3678
insilmaril@505
  3679
void Main::helpDemo()
insilmaril@505
  3680
{
insilmaril@505
  3681
	QStringList filters;
insilmaril@505
  3682
	filters <<"VYM example map (*.vym)";
insilmaril@505
  3683
	QFileDialog *fd=new QFileDialog( this);
insilmaril@505
  3684
	fd->setDir (QDir(vymBaseDir.path()+"/demos"));
insilmaril@505
  3685
	fd->setFileMode (QFileDialog::ExistingFiles);
insilmaril@505
  3686
	fd->setFilters (filters);
insilmaril@505
  3687
	fd->setCaption(vymName+ " - " +tr("Load vym example map"));
insilmaril@505
  3688
	fd->show();
insilmaril@505
  3689
insilmaril@505
  3690
	QString fn;
insilmaril@505
  3691
	if ( fd->exec() == QDialog::Accepted )
insilmaril@505
  3692
	{
insilmaril@505
  3693
		lastFileDir=fd->directory().path();
insilmaril@505
  3694
	    QStringList flist = fd->selectedFiles();
insilmaril@505
  3695
		QStringList::Iterator it = flist.begin();
insilmaril@505
  3696
		while( it != flist.end() ) 
insilmaril@505
  3697
		{
insilmaril@505
  3698
			fn = *it;
insilmaril@505
  3699
			fileLoad(*it, NewMap);				   
insilmaril@505
  3700
			++it;
insilmaril@505
  3701
		}
insilmaril@505
  3702
	}
insilmaril@505
  3703
	delete (fd);
insilmaril@505
  3704
}
insilmaril@505
  3705
insilmaril@505
  3706
insilmaril@0
  3707
void Main::helpAbout()
insilmaril@0
  3708
{
insilmaril@148
  3709
	AboutDialog ad;
insilmaril@150
  3710
	ad.setName ("aboutwindow");
insilmaril@148
  3711
	ad.setMinimumSize(500,500);
insilmaril@148
  3712
	ad.resize (QSize (500,500));
insilmaril@148
  3713
	ad.exec();
insilmaril@0
  3714
}
insilmaril@0
  3715
insilmaril@0
  3716
void Main::helpAboutQT()
insilmaril@0
  3717
{
insilmaril@0
  3718
	QMessageBox::aboutQt( this, "Qt Application Example" );
insilmaril@0
  3719
}
insilmaril@0
  3720
insilmaril@445
  3721
void Main::callMacro ()
insilmaril@445
  3722
{
insilmaril@445
  3723
    QAction *action = qobject_cast<QAction *>(sender());
insilmaril@445
  3724
	int i=-1;
insilmaril@445
  3725
    if (action)
insilmaril@445
  3726
	{
insilmaril@445
  3727
        i=action->data().toInt();
insilmaril@447
  3728
		QString mDir (settings.value ("macros/macroDir").toString() );
insilmaril@447
  3729
insilmaril@447
  3730
		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
insilmaril@447
  3731
		QFile f (fn);
insilmaril@447
  3732
		if ( !f.open( QIODevice::ReadOnly ) )
insilmaril@447
  3733
		{
insilmaril@447
  3734
			QMessageBox::warning(0, 
insilmaril@447
  3735
				tr("Warning"),
insilmaril@447
  3736
				tr("Couldn't find a macro at  %1.\n").arg(fn)+
insilmaril@447
  3737
				tr("Please use Settings->")+tr("Set directory for vym macros"));
insilmaril@447
  3738
			return;
insilmaril@447
  3739
		}	
insilmaril@447
  3740
insilmaril@447
  3741
		QTextStream ts( &f );
insilmaril@447
  3742
		QString m= ts.read();
insilmaril@447
  3743
insilmaril@445
  3744
		if (! m.isEmpty())
insilmaril@445
  3745
		{
insilmaril@447
  3746
			//cout <<"Main::callMacro  m="<<m.ascii()<<endl;
insilmaril@445
  3747
			currentMapEditor()->runScript (m);
insilmaril@445
  3748
		}	
insilmaril@445
  3749
	}	
insilmaril@445
  3750
}
insilmaril@445
  3751