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