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