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