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