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