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