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