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