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