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