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