mainwindow.cpp
changeset 82 920e6ed5889b
parent 0 7a96bd401351
child 2 608f976aa7bb
child 59 1c550f80c43b
child 89 9db3eaa21237
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mainwindow.cpp	Sun Jan 30 12:59:10 2005 +0000
     1.3 @@ -0,0 +1,2213 @@
     1.4 +#include "mainwindow.h"
     1.5 +
     1.6 +#include <qstatusbar.h>
     1.7 +#include <qmessagebox.h>
     1.8 +#include <qmenubar.h>
     1.9 +#include <qapplication.h>
    1.10 +#include <qpainter.h>
    1.11 +#include <qprinter.h>
    1.12 +#include <qfile.h>
    1.13 +#include <qfiledialog.h>
    1.14 +#include <qcolor.h>
    1.15 +#include <qcolordialog.h>
    1.16 +#include <qbitmap.h>
    1.17 +#include <qinputdialog.h>
    1.18 +
    1.19 +
    1.20 +#include <iostream>
    1.21 +#include <stdlib.h>
    1.22 +#include <typeinfo>
    1.23 +
    1.24 +#include "version.h"
    1.25 +
    1.26 +#include "icons/filenew.xpm"
    1.27 +#include "icons/fileopen.xpm"
    1.28 +#include "icons/filesave.xpm"
    1.29 +#include "icons/fileprint.xpm"
    1.30 +#include "icons/editundo.xpm"
    1.31 +//#include "icons/editredo.xpm"	// TODO
    1.32 +#include "icons/editcopy.xpm"
    1.33 +#include "icons/editcut.xpm"
    1.34 +#include "icons/editpaste.xpm"
    1.35 +#include "icons/editmoveup.xpm"
    1.36 +#include "icons/editmovedown.xpm"
    1.37 +#include "icons/formatcoloritem.xpm"
    1.38 +#include "icons/formatcolorbranch.xpm"
    1.39 +#include "icons/formatcolorpicker.xpm"
    1.40 +#include "icons/viewzoomreset.xpm"
    1.41 +#include "icons/viewzoomin.xpm"
    1.42 +#include "icons/viewzoomout.xpm"
    1.43 +#include "icons/vym-48x48.xpm"
    1.44 +#include "icons/flag-note.xpm"
    1.45 +#include "icons/flag-url.xpm"
    1.46 +#include "icons/flag-vymlink.xpm"	
    1.47 +#include "icons/flag-scrolled-right.xpm"
    1.48 +
    1.49 +#include "flagrowobj.h"
    1.50 +#include "texteditor.h"
    1.51 +#include "mapeditor.h"
    1.52 +#include "exporthtmldialog.h"
    1.53 +#include "exportxhtmldialog.h"
    1.54 +#include "showtextdialog.h"
    1.55 +#include "process.h"
    1.56 +#include "settings.h"
    1.57 +#include "options.h"
    1.58 +
    1.59 +extern TextEditor *textEditor;
    1.60 +extern Main *mainWindow;
    1.61 +extern int statusbarTime;
    1.62 +extern MapEditor *clipboardME;
    1.63 +extern FlagRowObj* standardFlagsDefault;
    1.64 +
    1.65 +extern QAction* actionFileSave;
    1.66 +extern QAction* actionFilePrint;
    1.67 +extern QAction* actionEditUndo;
    1.68 +extern QAction *actionEditCopy;
    1.69 +extern QAction *actionEditCut;
    1.70 +extern QAction *actionEditPaste;
    1.71 +extern QAction *actionEditMoveUp;
    1.72 +extern QAction *actionEditMoveDown;
    1.73 +extern QAction *actionEditToggleScroll;
    1.74 +extern QAction* actionEditOpenURL;
    1.75 +extern QAction* actionEditURL;
    1.76 +extern QAction* actionEditHeading2URL;
    1.77 +extern QAction* actionEditBugzilla2URL;
    1.78 +extern QAction *actionEditOpenVymLink;
    1.79 +extern QAction *actionEditVymLink;
    1.80 +extern QAction *actionEditDeleteVymLink;
    1.81 +extern QAction *actionEditMapInfo;
    1.82 +extern QAction *actionEditHeading;
    1.83 +extern QAction *actionEditDelete;
    1.84 +extern QAction *actionEditAddBranch;
    1.85 +extern QAction *actionEditAddBranchAbove;
    1.86 +extern QAction *actionEditAddBranchBelow;
    1.87 +extern QAction *actionEditImportAdd;
    1.88 +extern QAction *actionEditImportReplace;
    1.89 +extern QAction *actionEditSaveBranch;
    1.90 +extern QAction *actionEditSelectFirst;
    1.91 +extern QAction *actionEditSelectLast;
    1.92 +extern QAction *actionEditLoadImage;
    1.93 +extern QAction *actionEditToggleFloatExport;
    1.94 +
    1.95 +extern QAction* actionFormatColor;
    1.96 +extern QAction* actionFormatPickColor;
    1.97 +extern QAction* actionFormatColorBranch;
    1.98 +extern QAction* actionFormatColorSubtree;
    1.99 +extern QAction* actionFormatLinkColorHint;
   1.100 +extern QAction* actionFormatBackColor;
   1.101 +extern QAction* actionFormatLinkColor;
   1.102 +
   1.103 +extern QActionGroup *actionGroupFormatFrameTypes;
   1.104 +extern QAction *actionFormatFrameNone;
   1.105 +extern QAction *actionFormatFrameRectangle;
   1.106 +
   1.107 +extern QActionGroup *actionGroupFormatLinkStyles;
   1.108 +extern QAction *actionFormatLinkStyleLine;
   1.109 +extern QAction *actionFormatLinkStyleParabel;
   1.110 +extern QAction *actionFormatLinkStylePolyLine;
   1.111 +extern QAction *actionFormatLinkStylePolyParabel;
   1.112 +
   1.113 +extern QAction *actionViewToggleNoteEditor;
   1.114 +
   1.115 +extern QAction* actionSettingsAutoedit;
   1.116 +extern QAction* actionSettingsAutoselectHeading;
   1.117 +extern QAction* actionSettingsAutoselectHeading;
   1.118 +extern QAction* actionSettingsAutoselectText;
   1.119 +extern QAction* actionSettingsPasteNewHeading;
   1.120 +extern QAction* actionSettingsUseDelKey;
   1.121 +
   1.122 +extern QPopupMenu* branchContextMenu;
   1.123 +extern QPopupMenu* floatimageContextMenu;
   1.124 +extern QPopupMenu* saveImageFormatMenu;
   1.125 +extern QPopupMenu* canvasContextMenu;
   1.126 +extern QPopupMenu* lastMapsMenu;
   1.127 +extern QPopupMenu* exportMenu;
   1.128 +extern QPopupMenu* exportImageFormatMenu;
   1.129 +
   1.130 +
   1.131 +extern Settings settings;
   1.132 +extern Options options;
   1.133 +
   1.134 +#if defined(Q_OS_LINUX)
   1.135 +extern void qt_wait_for_window_manager( QWidget* w );
   1.136 +#endif
   1.137 +
   1.138 +Main::Main(QWidget* parent, const char* name, WFlags f) :
   1.139 +    QMainWindow(parent,name,f)
   1.140 +{
   1.141 +	mainWindow=this;
   1.142 +
   1.143 +	setCaption ("VYM - View Your Mind");
   1.144 +
   1.145 +	// Load window settings
   1.146 +	resize (settings.readNumEntry( "/vym/mainwindow/geometry/width", 800),
   1.147 +	        settings.readNumEntry( "/vym/mainwindow/geometry/height",600));
   1.148 +	move   (settings.readNumEntry( "/vym/mainwindow/geometry/posX", 100),
   1.149 +	        settings.readNumEntry( "/vym/mainwindow/geometry/posY", 100));
   1.150 +
   1.151 +
   1.152 +	// Initialize some settings, which are platform dependant
   1.153 +	QString p,s;
   1.154 +
   1.155 +		// application to open URLs
   1.156 +		p="/vym/mainwindow/readerURL";
   1.157 +		#if defined(Q_OS_LINUX)
   1.158 +			s=settings.readEntry (p,"konqueror");
   1.159 +		#else
   1.160 +			#if defined(Q_OS_MACX)
   1.161 +				s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
   1.162 +			#else
   1.163 +				s=settings.readEntry (p,"mozilla");
   1.164 +			#endif
   1.165 +		#endif
   1.166 +		settings.writeEntry( p,s);
   1.167 +
   1.168 +		// application to open PDFs
   1.169 +		p="/vym/mainwindow/readerPDF";
   1.170 +		#if defined(Q_OS_LINUX)
   1.171 +			s=settings.readEntry (p,"acroread");
   1.172 +		#else
   1.173 +			#if defined(Q_OS_MACX)
   1.174 +				s=settings.readEntry (p,"/Applications/Safari.app/Contents/MacOS/Safari");
   1.175 +			#else
   1.176 +				s=settings.readEntry (p,"acroread");
   1.177 +			#endif
   1.178 +		#endif
   1.179 +		settings.writeEntry( p,s);
   1.180 +
   1.181 +	
   1.182 +	maxLastMaps=9;
   1.183 +
   1.184 +	// Create tab widget which holds the maps
   1.185 +	tabWidget= new QTabWidget (this);
   1.186 +	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
   1.187 +		this, SLOT( editorChanged( QWidget * ) ) );
   1.188 +
   1.189 +	setCentralWidget(tabWidget);	
   1.190 +
   1.191 +    setupFileActions();
   1.192 +    setupEditActions();
   1.193 +    setupFormatActions();
   1.194 +    setupViewActions();
   1.195 +	setupFlagActions();
   1.196 +    setupSettingsActions();
   1.197 +	setupContextMenus();
   1.198 +    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) setupTestActions();
   1.199 +    setupHelpActions();
   1.200 +    
   1.201 +	// After menu is created, we can enable some actions
   1.202 +	actionFilePrint->setEnabled (true);
   1.203 +
   1.204 +    statusBar();
   1.205 +
   1.206 +	// Create the default map into first tab
   1.207 +//	fileNew();
   1.208 +//	tabWidget->addTab (new MapEditor(tabWidget,true), "unnamed");
   1.209 +//	currentMapEditor()->show();
   1.210 +
   1.211 +	// Initialize Find window
   1.212 +	findWindow=new FindWindow(NULL,"findwindow");
   1.213 +	connect (findWindow, SIGNAL( findButton(QString) ), 
   1.214 +		this, SLOT(editFind(QString) ) );	
   1.215 +	connect (findWindow, SIGNAL( somethingChanged() ), 
   1.216 +		this, SLOT(editFindChanged() ) );	
   1.217 +
   1.218 +	updateGeometry();
   1.219 +}
   1.220 +
   1.221 +Main::~Main()
   1.222 +{
   1.223 +	// Save Settings
   1.224 +	settings.writeEntry( "/vym/mainwindow/geometry/width", width() );
   1.225 +	settings.writeEntry( "/vym/mainwindow/geometry/height", height() );
   1.226 +	settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
   1.227 +	settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
   1.228 +
   1.229 +	settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
   1.230 +	settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
   1.231 +
   1.232 +	settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
   1.233 +	settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
   1.234 +	settings.writeEntry( "/vym/mapeditor/editmode/pastenewheading",actionSettingsPasteNewHeading->isOn() );
   1.235 +	settings.writeEntry( "/vym/mapeditor/editmode/autoedit",actionSettingsAutoedit->isOn() );
   1.236 +	settings.writeEntry( "/vym/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   1.237 +
   1.238 +	QString s;
   1.239 +	int maps=lastMaps.count();
   1.240 +	settings.writeEntry( "/vym/lastMaps/number",maps );
   1.241 +	for (int i=1;i<=maps;i++)
   1.242 +	{
   1.243 +		QStringList::Iterator it = lastMaps.at(i-1);
   1.244 +		s=QString("/vym/lastMaps/map-%1").arg(i);
   1.245 +		if (!s.isEmpty() && i<=maxLastMaps) 
   1.246 +			settings.writeEntry (s, *it);
   1.247 +	}
   1.248 +
   1.249 +
   1.250 +	// To make the texteditor save its settings, call the destructor
   1.251 +	delete (textEditor);
   1.252 +}
   1.253 +
   1.254 +void Main::loadCmdLine()
   1.255 +{
   1.256 +	/* TODO draw some kind of splashscreen while loading...
   1.257 +	if (qApp->argc()>1)
   1.258 +	{
   1.259 +	}
   1.260 +	*/
   1.261 +	
   1.262 +	QStringList flist=options.getFileList();
   1.263 +	QStringList::Iterator it=flist.begin();
   1.264 +
   1.265 +	while (it !=flist.end() )
   1.266 +	{
   1.267 +		fileLoad (*it, NewMap);
   1.268 +		*it++;
   1.269 +	}	
   1.270 +}
   1.271 +
   1.272 +
   1.273 +void Main::statusMessage(const QString &s)
   1.274 +{
   1.275 +	statusBar()->message (s);
   1.276 +}
   1.277 +
   1.278 +void Main::closeEvent (QCloseEvent* )
   1.279 +{
   1.280 +	fileExitVYM();
   1.281 +}
   1.282 +
   1.283 +// File Actions
   1.284 +void Main::setupFileActions()
   1.285 +{
   1.286 +    QToolBar *tb = new QToolBar( this );
   1.287 +    tb->setLabel( "File Actions" );
   1.288 +    QPopupMenu *menu = new QPopupMenu( this );
   1.289 +    menuBar()->insertItem( tr( "&File" ), menu );
   1.290 +
   1.291 +	// Keycodes:  /usr/lib64/qt3/include/qnamespace.h
   1.292 +
   1.293 +    QAction *a;
   1.294 +    a = new QAction( tr( "New map" ), QPixmap( filenew_xpm ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" );
   1.295 +    connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
   1.296 +    a->addTo( tb );
   1.297 +    a->addTo( menu );
   1.298 +	
   1.299 +    a = new QAction( tr( "Open" ), QPixmap( fileopen_xpm), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" );
   1.300 +    connect( a, SIGNAL( activated() ), this, SLOT( fileLoad() ) );
   1.301 +    a->addTo( tb );
   1.302 +    a->addTo( menu );
   1.303 +	
   1.304 +	lastMapsMenu = new QPopupMenu (this);
   1.305 +
   1.306 +    menu->insertItem (tr("Open Recent"),lastMapsMenu );
   1.307 +    menu->insertSeparator();
   1.308 +	
   1.309 +    a = new QAction( tr( "Save" ), QPixmap( filesave_xpm ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" );
   1.310 +    connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
   1.311 +    a->addTo( tb );
   1.312 +    a->addTo( menu );
   1.313 +	actionFileSave=a;
   1.314 +	
   1.315 +    a = new QAction( tr( "Save &As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" );
   1.316 +    connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
   1.317 +    a->addTo( menu );
   1.318 +
   1.319 +    menu->insertSeparator();
   1.320 +
   1.321 +    a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir" ), 0, this, "export" );
   1.322 +    connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
   1.323 +    a->addTo( menu );
   1.324 +
   1.325 +	exportMenu = new QPopupMenu (this);
   1.326 +    menu->insertItem (tr("Export"),exportMenu );
   1.327 +
   1.328 +    menu->insertSeparator();
   1.329 +
   1.330 +
   1.331 +    a = new QAction( tr( "Print" ), QPixmap( fileprint_xpm ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" );
   1.332 +    connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) );
   1.333 +    a->addTo( tb );
   1.334 +    a->addTo( menu );
   1.335 +	actionFilePrint=a;
   1.336 +
   1.337 +    a = new QAction( tr( "Close Map" ), QPixmap(), tr( "&Close Map" ), ALT + Key_C, this, "fileCloseMap" );
   1.338 +    connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
   1.339 +    a->addTo( menu );
   1.340 +
   1.341 +    a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
   1.342 +    connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
   1.343 +    a->addTo( menu );
   1.344 +}
   1.345 +
   1.346 +
   1.347 +//Edit Actions
   1.348 +void Main::setupEditActions()
   1.349 +{
   1.350 +    QToolBar *tb = new QToolBar( this );
   1.351 +    tb->setLabel( "Edit Actions" );
   1.352 +    QPopupMenu *menu = new QPopupMenu( this );
   1.353 +    menuBar()->insertItem( tr( "&Edit" ), menu );
   1.354 +
   1.355 +    QAction *a;
   1.356 +    a = new QAction( tr( "Undo" ), QPixmap( editundo_xpm ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" );
   1.357 +    connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
   1.358 +	a->setEnabled (false);
   1.359 +    a->addTo( tb );
   1.360 +    a->addTo( menu );
   1.361 +	actionEditUndo=a;
   1.362 +    /*
   1.363 +    a = new QAction( tr( "Redo" ), QPixmap( editredo_xpm ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); 
   1.364 +    connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
   1.365 +    a->addTo( tb );
   1.366 +    a->addTo( menu );
   1.367 +    */
   1.368 +    menu->insertSeparator();
   1.369 +    a = new QAction( tr( "Copy" ), QPixmap( editcopy_xpm ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" );
   1.370 +    connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
   1.371 +	a->setEnabled (false);
   1.372 +    a->addTo( tb );
   1.373 +    a->addTo( menu );
   1.374 +	actionEditCopy=a;
   1.375 +    a = new QAction( tr( "Cut" ), QPixmap( editcut_xpm ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" );
   1.376 +    connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
   1.377 +	a->setEnabled (false);
   1.378 +    a->addTo( tb );
   1.379 +    a->addTo( menu );
   1.380 +	actionEditCut=a;
   1.381 +    a = new QAction( tr( "Paste" ), QPixmap( editpaste_xpm ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" );
   1.382 +    connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
   1.383 +	a->setEnabled (false);
   1.384 +    a->addTo( tb );
   1.385 +    a->addTo( menu );
   1.386 +	actionEditPaste=a;
   1.387 +    a = new QAction( tr( "Move branch up" ), QPixmap( editmoveup_xpm ), tr( "Move up" ), Key_PageUp, this, "editMoveUp" );
   1.388 +    connect( a, SIGNAL( activated() ), this, SLOT( editMoveUp() ) );
   1.389 +	a->setEnabled (false);
   1.390 +    a->addTo( tb );
   1.391 +    a->addTo( menu );
   1.392 +	actionEditMoveUp=a;
   1.393 +    a = new QAction( tr( "Move branch down" ), QPixmap( editmovedown_xpm ), tr( "Move down" ), Key_PageDown, this, "editMoveDown" );
   1.394 +    connect( a, SIGNAL( activated() ), this, SLOT( editMoveDown() ) );
   1.395 +	a->setEnabled (false);
   1.396 +    a->addTo( tb );
   1.397 +    a->addTo( menu );
   1.398 +	actionEditMoveDown=a;
   1.399 +
   1.400 +    a = new QAction( tr( "Scroll branch" ), QPixmap(flag_scrolled_right_xpm), tr( "Scroll branch" ), Key_ScrollLock, this, "scroll" );
   1.401 +    connect( a, SIGNAL( activated() ), this, SLOT( editToggleScroll() ) );
   1.402 +	a->setEnabled (false);
   1.403 +    a->addTo( tb );
   1.404 +    a->addTo( menu );
   1.405 +	actionEditToggleScroll=a;
   1.406 +	
   1.407 +    a = new QAction( tr( "Unscroll all" ), QPixmap(), tr( "Unscroll all scrolled branches" ), 0, this, "scroll" );
   1.408 +    connect( a, SIGNAL( activated() ), this, SLOT( editUnScrollAll() ) );
   1.409 +    a->addTo( menu );
   1.410 +	
   1.411 +    menu->insertSeparator();
   1.412 +
   1.413 +	a = new QAction( tr( "Find" ), QPixmap(), tr( "Find" ), CTRL + Key_F, this, "find" );
   1.414 +    connect( a, SIGNAL( activated() ), this, SLOT( editOpenFindWindow() ) );
   1.415 +    a->addTo( menu );
   1.416 +    
   1.417 +	menu->insertSeparator();
   1.418 +
   1.419 +	a = new QAction( tr( "Open URL" ), QPixmap(flag_url_xpm), tr( "Open URL" ), CTRL + Key_U, this, "url" );
   1.420 +    connect( a, SIGNAL( activated() ), this, SLOT( editOpenURL() ) );
   1.421 +    a->addTo( menu );
   1.422 +    a->addTo( tb );
   1.423 +	a->setEnabled (false);
   1.424 +	actionEditOpenURL=a;
   1.425 +
   1.426 +	a = new QAction( tr( "Edit URL" ), QPixmap(), tr( "Edit URL" ), SHIFT + CTRL + Key_U, this, "url" );
   1.427 +    connect( a, SIGNAL( activated() ), this, SLOT( editURL() ) );
   1.428 +    a->addTo( menu );
   1.429 +	a->setEnabled (false);
   1.430 +	actionEditURL=a;
   1.431 +	
   1.432 +	a = new QAction( tr( "Use heading of selected branch as URL" ), QPixmap(), tr( "Use heading for URL" ), 0, this, "heading2url" );
   1.433 +    connect( a, SIGNAL( activated() ), this, SLOT( editHeading2URL() ) );
   1.434 +    a->addTo( menu );
   1.435 +	a->setEnabled (false);
   1.436 +	actionEditHeading2URL=a;
   1.437 +    
   1.438 +	a = new QAction( tr( "Create URL to Bugzilla" ), QPixmap(), tr( "Create URL to Bugzilla" ), 0, this, "bugzilla2url" );
   1.439 +    connect( a, SIGNAL( activated() ), this, SLOT( editBugzilla2URL() ) );
   1.440 +	a->setEnabled (false);
   1.441 +	actionEditBugzilla2URL=a;
   1.442 +    
   1.443 +	menu->insertSeparator();
   1.444 +	
   1.445 +    a = new QAction( tr( "Jump to another vym map, if needed load it first" ), QPixmap(flag_vymlink_xpm), tr( "Jump to map" ), 0, this, "jumpMap" );
   1.446 +    connect( a, SIGNAL( activated() ), this, SLOT( editOpenVymLink() ) );
   1.447 +    a->addTo( menu );
   1.448 +    a->addTo( tb );
   1.449 +	a->setEnabled (false);
   1.450 +	actionEditOpenVymLink=a;
   1.451 +	
   1.452 +    a = new QAction( tr( "Edit link to another vym map" ), QPixmap(), tr( "Edit vym link" ), 0, this, "editLinkMap" );
   1.453 +    connect( a, SIGNAL( activated() ), this, SLOT( editVymLink() ) );
   1.454 +    a->addTo( menu );
   1.455 +	a->setEnabled (false);
   1.456 +	actionEditVymLink=a;
   1.457 +
   1.458 +    a = new QAction( tr( "Delete link to another vym map" ), QPixmap(), tr( "Delete vym link" ), 0, this, "deleteLinkMap" );
   1.459 +    connect( a, SIGNAL( activated() ), this, SLOT( editDeleteVymLink() ) );
   1.460 +    a->addTo( menu );
   1.461 +	a->setEnabled (false);
   1.462 +	actionEditDeleteVymLink=a;
   1.463 +
   1.464 +	menu->insertSeparator();
   1.465 +
   1.466 +    a = new QAction( tr( "Edit Map Info" ), QPixmap(), tr( "Edit Map Info" ), 0, this, "editMapInfo" );
   1.467 +    connect( a, SIGNAL( activated() ), this, SLOT( editMapInfo() ) );
   1.468 +    a->addTo( menu );
   1.469 +	a->setEnabled (true);
   1.470 +	actionEditMapInfo=a;
   1.471 +
   1.472 +	menu->insertSeparator();
   1.473 +
   1.474 +    // Shortcuts to modify heading:
   1.475 +    a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Enter, this, "editHeading" );
   1.476 +    connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   1.477 +	a->setEnabled (false);
   1.478 +    a->addTo ( menu );
   1.479 +	actionEditHeading=a;
   1.480 +    a = new QAction( tr( "edit Heading" ),tr( "Edit heading" ), Key_Return, this, "editHeading" );
   1.481 +    connect( a, SIGNAL( activated() ), this, SLOT( editHeading() ) );
   1.482 +    //a->addTo ( menu );
   1.483 +    
   1.484 +    // Shortcut to delete selection
   1.485 +    a = new QAction( tr( "Delete Selection" ),tr( "Delete Selection" ), Key_Delete, this, "deleteBranch" );
   1.486 +    connect( a, SIGNAL( activated() ), this, SLOT( editDeleteSelection() ) );
   1.487 +	a->setEnabled (false);
   1.488 +    a->addTo ( menu );
   1.489 +	actionEditDelete=a;
   1.490 +    
   1.491 +    // Shortcut to add branch
   1.492 +	#if defined (Q_OS_MACX)
   1.493 +		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), CTRL + Key_I, this, "newBranch" );
   1.494 +	#else
   1.495 +		a = new QAction( tr( "Add a branch as child of selection" ),tr( "Add branch as child" ), Key_Insert, this, "newBranch" );
   1.496 +	#endif
   1.497 +    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranch() ) );
   1.498 +	a->setEnabled (false);
   1.499 +    a->addTo ( menu );
   1.500 +	actionEditAddBranch=a;
   1.501 +
   1.502 +	// Add branch above
   1.503 +    a = new QAction( tr( "Add a branch above selection" ),tr( "Add branch above" ), SHIFT+Key_Insert, this, "newBranch" );
   1.504 +    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchAbove() ) );
   1.505 +	a->setEnabled (false);
   1.506 +    a->addTo ( menu );
   1.507 +	actionEditAddBranchAbove=a;
   1.508 +
   1.509 +	// Add branch below 
   1.510 +    a = new QAction( tr( "Add a branch below selection" ),tr( "Add branch below" ), CTRL +Key_Insert, this, "newBranch" );
   1.511 +    connect( a, SIGNAL( activated() ), this, SLOT( editNewBranchBelow() ) );
   1.512 +	a->setEnabled (false);
   1.513 +    a->addTo ( menu );
   1.514 +	actionEditAddBranchBelow=a;
   1.515 +
   1.516 +	// Import at selection (adding to selection)
   1.517 +    a = new QAction( tr( "Add map at selection" ),tr( "Import (add)" ), 0, this, "importAdd" );
   1.518 +    connect( a, SIGNAL( activated() ), this, SLOT( editImportAdd() ) );
   1.519 +	a->setEnabled (false);
   1.520 +    a->addTo ( menu );
   1.521 +	actionEditImportAdd=a;
   1.522 +
   1.523 +	// Import at selection (replacing selection)
   1.524 +    a = new QAction( tr( "Replace selection with map" ),tr( "Import (replace)" ), 0, this, "importReplace" );
   1.525 +    connect( a, SIGNAL( activated() ), this, SLOT( editImportReplace() ) );
   1.526 +	a->setEnabled (false);
   1.527 +    a->addTo ( menu );
   1.528 +	actionEditImportReplace=a;
   1.529 +
   1.530 +	// Save selection 
   1.531 +    a = new QAction( tr( "Save selction" ),tr( "Save selection" ), 0, this, "saveSelection" );
   1.532 +    connect( a, SIGNAL( activated() ), this, SLOT( editSaveBranch() ) );
   1.533 +	a->setEnabled (false);
   1.534 +    a->addTo ( menu );
   1.535 +	actionEditSaveBranch=a;
   1.536 +
   1.537 +    // Shortcuts for navigating with cursor:
   1.538 +    a = new QAction( tr( "Select upper branch" ),tr( "Select upper branch" ), Key_Up, this, "upperBranch" );
   1.539 +    connect( a, SIGNAL( activated() ), this, SLOT( editUpperBranch() ) );
   1.540 +    a = new QAction( tr( "Select lower branch" ),tr( "Select lower branch" ), Key_Down, this, "lowerBranch" );
   1.541 +    connect( a, SIGNAL( activated() ), this, SLOT( editLowerBranch() ) );
   1.542 +    a = new QAction( tr( "Select left branch" ),tr( "Select left branch" ), Key_Left, this, "upperBranch" );
   1.543 +    connect( a, SIGNAL( activated() ), this, SLOT( editLeftBranch() ) );
   1.544 +    a = new QAction( tr( "Select right branch" ),tr( "Select child branch" ), Key_Right, this, "rightBranch" );
   1.545 +    connect( a, SIGNAL( activated() ), this, SLOT( editRightBranch() ) );
   1.546 +    a = new QAction( tr( "Select first branch" ),tr( "Select first branch" ), Key_Home, this, "firstBranch" );
   1.547 +	a->setEnabled (false);
   1.548 +    a->addTo ( menu );
   1.549 +	actionEditSelectFirst=a;
   1.550 +    connect( a, SIGNAL( activated() ), this, SLOT( editFirstBranch() ) );
   1.551 +    a = new QAction( tr( "Select last branch" ),tr( "Select last branch" ), Key_End, this, "lastBranch" );
   1.552 +    connect( a, SIGNAL( activated() ), this, SLOT( editLastBranch() ) );
   1.553 +	a->setEnabled (false);
   1.554 +    a->addTo ( menu );
   1.555 +	actionEditSelectLast=a;
   1.556 +
   1.557 +    a = new QAction( tr( "Add Image" ),tr( "Add Image" ), 0, this, "loadImage" );
   1.558 +    connect( a, SIGNAL( activated() ), this, SLOT( editLoadImage() ) );
   1.559 +	actionEditLoadImage=a;
   1.560 +}
   1.561 +
   1.562 +// Format Actions
   1.563 +void Main::setupFormatActions()
   1.564 +{
   1.565 +    QPopupMenu *menu = new QPopupMenu( this );
   1.566 +    menuBar()->insertItem( tr( "&Format" ), menu );
   1.567 +
   1.568 +    QToolBar *tb = new QToolBar( this );
   1.569 +    QAction *a;
   1.570 +    QPixmap pix( 16,16);
   1.571 +    pix.fill (black);
   1.572 +    actionFormatColor= new QAction( tr( "Set Color" ), pix, tr( "Set &Color" ), 0, this, "formatColor" );
   1.573 +    connect( actionFormatColor, SIGNAL( activated() ), this, SLOT( formatSelectColor() ) );
   1.574 +    actionFormatColor->addTo( tb );
   1.575 +    actionFormatColor->addTo( menu );
   1.576 +    a= new QAction( tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ), QPixmap(formatcolorpicker_xpm), tr( "Pic&k color" ), CTRL + Key_K, this, "pickColor" );
   1.577 +    connect( a, SIGNAL( activated() ), this, SLOT( formatPickColor() ) );
   1.578 +	a->setEnabled (false);
   1.579 +    a->addTo( tb );
   1.580 +    a->addTo( menu );
   1.581 +	actionFormatPickColor=a;
   1.582 +    a= new QAction( tr( "Color branch" ), QPixmap(formatcoloritem_xpm), tr( "Color &branch" ), CTRL + Key_I, this, "colorItem" );
   1.583 +    connect( a, SIGNAL( activated() ), this, SLOT( formatColorItem() ) );
   1.584 +	a->setEnabled (false);
   1.585 +    a->addTo( tb );
   1.586 +    a->addTo( menu );
   1.587 +	actionFormatColorBranch=a;
   1.588 +    a= new QAction( tr( "Color Subtree" ), QPixmap(formatcolorbranch_xpm), tr( "Color sub&tree" ), CTRL + Key_T, this, "colorBranch" );
   1.589 +    connect( a, SIGNAL( activated() ), this, SLOT( formatColorBranch() ) );
   1.590 +	a->setEnabled (false);
   1.591 +    a->addTo( menu );
   1.592 +    a->addTo( tb );
   1.593 +	actionFormatColorSubtree=a;
   1.594 +
   1.595 +    menu->insertSeparator();
   1.596 +	actionGroupFormatLinkStyles=new QActionGroup ( this, "formatLinkStyles");
   1.597 +	actionGroupFormatLinkStyles->setExclusive (true);
   1.598 +    a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   1.599 +	a->setToggleAction(true);
   1.600 +    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleLine() ) );
   1.601 +	actionFormatLinkStyleLine=a;
   1.602 +    a= new QAction( tr( "Line" ), QPixmap(), tr( "Linkstyle Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   1.603 +	a->setToggleAction(true);
   1.604 +    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStyleParabel() ) );
   1.605 +	actionFormatLinkStyleParabel=a;
   1.606 +    a= new QAction( tr( "PolyLine" ), QPixmap(), tr( "Linkstyle Thick Line" ), 0, actionGroupFormatLinkStyles, "formatLinkStyleLine" );
   1.607 +	a->setToggleAction(true);
   1.608 +    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyLine() ) );
   1.609 +	actionFormatLinkStylePolyLine=a;
   1.610 +    a= new QAction( tr( "PolyParabel" ), QPixmap(), tr( "Linkstyle Thick Parabel" ), 0, actionGroupFormatLinkStyles, "formatLinkStylePolyParabel" );
   1.611 +	a->setToggleAction(true);
   1.612 +    connect( a, SIGNAL( activated() ), this, SLOT( formatLinkStylePolyParabel() ) );
   1.613 +	actionFormatLinkStylePolyParabel=a;
   1.614 +	actionGroupFormatLinkStyles->addTo (menu);
   1.615 +	
   1.616 +	actionGroupFormatFrameTypes=new QActionGroup ( this, "formatFrameTypes");
   1.617 +	actionGroupFormatFrameTypes->setExclusive (true);
   1.618 +    a = new QAction( tr( "No Frame" ),tr( "No Frame" ), 0, actionGroupFormatFrameTypes, "frameNone" );
   1.619 +	a->setToggleAction(true);
   1.620 +    connect( a, SIGNAL( activated() ), this, SLOT( formatFrameNone() ) );
   1.621 +	actionFormatFrameNone=a;
   1.622 +    a = new QAction( tr( "Rectangle" ),tr( "Rectangle" ), 0, actionGroupFormatFrameTypes, "frameRectangle" );
   1.623 +	a->setToggleAction(true);
   1.624 +    connect( a, SIGNAL( activated() ), this, SLOT( formatFrameRectangle() ) );
   1.625 +	actionFormatFrameRectangle=a;
   1.626 +
   1.627 +    menu->insertSeparator();
   1.628 +    a= new QAction( tr( "Use same color for links and headings" ), QPixmap(), tr( "&Use color of heading for link" ), 0, this, "formatLinkColorHint" );
   1.629 +	a->setToggleAction(true);
   1.630 +    connect( a, SIGNAL( activated() ), this, SLOT( formatToggleLinkColorHint() ) );
   1.631 +	a->addTo( menu );
   1.632 +	actionFormatLinkColorHint=a;
   1.633 +    pix.fill (white);
   1.634 +    actionFormatLinkColor= new QAction( tr( "Set Link Color" ), pix, tr( "Set &Link Color" ), 0, this, "formatLinkColor" );
   1.635 +    connect( actionFormatLinkColor, SIGNAL( activated() ), this, SLOT( formatSelectLinkColor() ) );
   1.636 +    actionFormatLinkColor->addTo( menu );
   1.637 +    actionFormatBackColor= new QAction( tr( "Set Background Color" ), pix, tr( "Set &Background Color" ), 0, this, "formatBackColor" );
   1.638 +    connect( actionFormatBackColor, SIGNAL( activated() ), this, SLOT( formatSelectBackColor() ) );
   1.639 +    actionFormatBackColor->addTo( menu );
   1.640 +}
   1.641 +
   1.642 +// View Actions
   1.643 +void Main::setupViewActions()
   1.644 +{
   1.645 +    QToolBar *tb = new QToolBar( this );
   1.646 +    tb->setLabel( "View Actions" );
   1.647 +    QPopupMenu *menu = new QPopupMenu( this );
   1.648 +    menuBar()->insertItem( tr( "&View" ), menu );
   1.649 +
   1.650 +    QAction *a;
   1.651 +    a = new QAction( tr( "Zoom reset" ), QPixmap(viewzoomreset_xpm), tr( "reset Zoom" ), 0, this, "zoomReset" );
   1.652 +    connect( a, SIGNAL( activated() ), this, SLOT(viewZoomReset() ) );
   1.653 +    a->addTo( tb );
   1.654 +    a->addTo( menu );
   1.655 +    a = new QAction( tr( "Zoom in" ), QPixmap(viewzoomin_xpm), tr( "Zoom in" ), CTRL + Key_Plus, this, "zoomIn" );
   1.656 +    connect( a, SIGNAL( activated() ), this, SLOT(viewZoomIn() ) );
   1.657 +    a->addTo( tb );
   1.658 +    a->addTo( menu );
   1.659 +    a = new QAction( tr( "Zoom out" ), QPixmap(viewzoomout_xpm), tr( "Zoom out" ), CTRL + Key_Minus, this, "zoomOut" );
   1.660 +    connect( a, SIGNAL( activated() ), this, SLOT( viewZoomOut() ) );
   1.661 +    a->addTo( tb );
   1.662 +    a->addTo( menu );
   1.663 +    a = new QAction( tr( "Toggle Note Editor" ), QPixmap(flag_note_xpm), tr( "Toggle Note Editor" ), CTRL + Key_E , this, "noteEditor" );
   1.664 +    connect( a, SIGNAL( activated() ), this, SLOT(windowToggleNoteEditor() ) );
   1.665 +	a->setToggleAction(true);
   1.666 +	if (textEditor->showWithMain())
   1.667 +		a->setOn(true);
   1.668 +	else	
   1.669 +		a->setOn(false);
   1.670 +    a->addTo( tb );
   1.671 +    a->addTo( menu );
   1.672 +	actionViewToggleNoteEditor=a;
   1.673 +    a = new QAction( tr( "&Next Window" ), QPixmap(), tr( "Next Window" ), ALT + Key_N , this, "nextWindow" );
   1.674 +    connect( a, SIGNAL( activated() ), this, SLOT(windowNextEditor() ) );
   1.675 +    a->addTo( menu );
   1.676 +    a = new QAction( tr( "&Previous Window" ), QPixmap(), tr( "Previous Window" ), ALT + Key_P , this, "previousWindow" );
   1.677 +    connect( a, SIGNAL( activated() ), this, SLOT(windowPreviousEditor() ) );
   1.678 +    a->addTo( menu );
   1.679 +}
   1.680 +
   1.681 +// Flag Actions
   1.682 +void Main::setupFlagActions()
   1.683 +{
   1.684 +	standardFlagsDefault->makeToolbar(this, "Standard Flags");
   1.685 +}
   1.686 +
   1.687 +// Settings Actions
   1.688 +void Main::setupSettingsActions()
   1.689 +{
   1.690 +    QPopupMenu *menu = new QPopupMenu( this );
   1.691 +    menuBar()->insertItem( tr( "&Settings" ), menu );
   1.692 +
   1.693 +	QAction *a;
   1.694 +
   1.695 +
   1.696 +    a = new QAction( tr( "Set application to open pdf files" ), QPixmap(), tr( "Set application to open pdf files" ), 0, this, "setPDF" );
   1.697 +    connect( a, SIGNAL( activated() ), this, SLOT( settingsPDF() ) );
   1.698 +    a->addTo( menu );
   1.699 +
   1.700 +    a = new QAction( tr( "Set application to open an URL" ), QPixmap(), tr( "Set application to open an URL" ), 0, this, "setURL" );
   1.701 +    connect( a, SIGNAL( activated() ), this, SLOT( settingsURL() ) );
   1.702 +    a->addTo( menu );
   1.703 +
   1.704 +    menu->insertSeparator();
   1.705 +    a = new QAction( tr( "Edit branch after adding it" ), QPixmap(), tr( "Edit branch after adding it" ), 0, this, "autoedit" );
   1.706 +	a->setToggleAction(true);
   1.707 +	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoedit",true) );
   1.708 +    a->addTo( menu );
   1.709 +	actionSettingsAutoedit=a;
   1.710 +
   1.711 +    a= new QAction( tr( "Select branch after adding it" ), QPixmap(), tr( "Select branch after adding it" ), 0, this, "autoselectheading" );
   1.712 +	a->setToggleAction(true);
   1.713 +	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselect",false) );
   1.714 +    a->addTo( menu );
   1.715 +	actionSettingsAutoselectHeading=a;
   1.716 +	
   1.717 +    a= new QAction( tr( "Select heading before editing" ), QPixmap(), tr( "Select existing heading" ), 0, this, "autoselectexistingtext" );
   1.718 +	a->setToggleAction(true);
   1.719 +	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/autoselectexistingtext",true) );
   1.720 +    a->addTo( menu );
   1.721 +	actionSettingsAutoselectText=a;
   1.722 +	
   1.723 +    a= new QAction( tr( "Enable pasting into new branch" ), QPixmap(), tr( "Enable pasting into new branch" ), 0, this, "pastenewheading" );
   1.724 +	a->setToggleAction(true);
   1.725 +	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/newheadingisempty",true) );
   1.726 +    a->addTo( menu );
   1.727 +	actionSettingsPasteNewHeading=a;
   1.728 +	
   1.729 +    a= new QAction( tr( "Enable Delete key for deleting branches" ), QPixmap(), tr( "Enable Delete key" ), 0, this, "delkey" );
   1.730 +	a->setToggleAction(true);
   1.731 +	a->setOn ( settings.readBoolEntry ("/vym/mapeditor/editmode/useDelKey",false) );
   1.732 +    a->addTo( menu );
   1.733 +	actionSettingsUseDelKey=a;
   1.734 +}
   1.735 +
   1.736 +// Test Actions
   1.737 +void Main::setupTestActions()
   1.738 +{
   1.739 +    QPopupMenu *menu = new QPopupMenu( this );
   1.740 +    menuBar()->insertItem( tr( "&Test" ), menu );
   1.741 +
   1.742 +    QAction *a;
   1.743 +    a = new QAction( tr( "Test Flag" ), QPixmap(), tr( "test flag" ), 0, this, "flag" );
   1.744 +    connect( a, SIGNAL( activated() ), this, SLOT( testFunction() ) );
   1.745 +    a->addTo( menu );
   1.746 +
   1.747 +	a = new QAction( tr( "Show Clipboard" ), QPixmap(), tr( "Show clipboard" ), 0, this, "clipboard" );
   1.748 +    connect( a, SIGNAL( activated() ), this, SLOT( testShowClipboard() ) );
   1.749 +    a->addTo( menu );
   1.750 +}
   1.751 +
   1.752 +// Help Actions
   1.753 +void Main::setupHelpActions()
   1.754 +{
   1.755 +    QPopupMenu *menu = new QPopupMenu( this );
   1.756 +    menuBar()->insertItem( tr( "&Help" ), menu );
   1.757 +
   1.758 +    QAction *a;
   1.759 +    a = new QAction( tr( "Open VYM Documentation (pdf)" ), QPixmap(), tr( "Open VYM Documentation (pdf) " ), 0, this, "about" );
   1.760 +    connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
   1.761 +    a->addTo( menu );
   1.762 +
   1.763 +    a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
   1.764 +    connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
   1.765 +    a->addTo( menu );
   1.766 +
   1.767 +    a = new QAction( tr( "Information about QT toolkit" ), QPixmap(), tr( "About QT" ), 0, this, "about" );
   1.768 +    connect( a, SIGNAL( activated() ), this, SLOT( helpAboutQT() ) );
   1.769 +    a->addTo( menu );
   1.770 +}
   1.771 +
   1.772 +// Context Menus
   1.773 +void Main::setupContextMenus()
   1.774 +{
   1.775 +	QAction*a;
   1.776 +
   1.777 +	// Context Menu for branch or mapcenter
   1.778 +	branchContextMenu =new QPopupMenu (this);
   1.779 +	actionEditAddBranch->addTo ( branchContextMenu );
   1.780 +	actionEditAddBranchAbove->addTo ( branchContextMenu );
   1.781 +	actionEditAddBranchBelow->addTo ( branchContextMenu );
   1.782 +	actionEditSaveBranch->addTo( branchContextMenu );
   1.783 +	branchContextMenu->insertSeparator();	
   1.784 +	actionEditImportAdd->addTo ( branchContextMenu );
   1.785 +	actionEditImportReplace->addTo ( branchContextMenu );
   1.786 +	branchContextMenu->insertSeparator();	
   1.787 +	actionEditOpenURL->addTo ( branchContextMenu );
   1.788 +	actionEditURL->addTo ( branchContextMenu );
   1.789 +	actionEditHeading2URL->addTo ( branchContextMenu );
   1.790 +    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   1.791 +		actionEditBugzilla2URL->addTo( branchContextMenu );
   1.792 +	branchContextMenu->insertSeparator();	
   1.793 +	actionEditOpenVymLink->addTo ( branchContextMenu );
   1.794 +	actionEditVymLink->addTo ( branchContextMenu );
   1.795 +	actionEditDeleteVymLink->addTo ( branchContextMenu );
   1.796 +	branchContextMenu->insertSeparator();	
   1.797 +	actionEditLoadImage->addTo( branchContextMenu );
   1.798 +	branchContextMenu->insertSeparator();	
   1.799 +	actionEditCopy->addTo( branchContextMenu );
   1.800 +	actionEditCut->addTo( branchContextMenu );
   1.801 +	actionEditPaste->addTo( branchContextMenu );
   1.802 +	branchContextMenu->insertSeparator();	
   1.803 +	actionGroupFormatFrameTypes->addTo( branchContextMenu );
   1.804 +
   1.805 +	// Context menu for floatimage
   1.806 +	floatimageContextMenu =new QPopupMenu (this);
   1.807 +	saveImageFormatMenu=new QPopupMenu (this);
   1.808 +	exportImageFormatMenu=new QPopupMenu (this);
   1.809 +
   1.810 +	QStrList fmt = QImage::outputFormats();
   1.811 +	for (const char* f = fmt.first(); f; f = fmt.next()) 
   1.812 +	{
   1.813 +		saveImageFormatMenu->insertItem( f );
   1.814 +		exportImageFormatMenu->insertItem( f );
   1.815 +	}	
   1.816 +	connect( saveImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( editSaveImage(int ) ) );
   1.817 +	connect( exportImageFormatMenu, SIGNAL( activated(int) ), this, SLOT( fileExportImage(int ) ) );
   1.818 +	floatimageContextMenu->insertItem( tr("Save image"),saveImageFormatMenu );
   1.819 +	
   1.820 +	floatimageContextMenu->insertSeparator();	
   1.821 +	actionEditCopy->addTo( floatimageContextMenu );
   1.822 +	actionEditCut->addTo( floatimageContextMenu );
   1.823 +
   1.824 +	floatimageContextMenu->insertSeparator();	
   1.825 +    a = new QAction( tr( "Use for Export" ), QPixmap(), tr( "Use for Export"), 0, this, "useForExport" );
   1.826 +	a->setToggleAction(true);
   1.827 +    connect( a, SIGNAL( activated() ), this, SLOT( editToggleFloatExport() ) );
   1.828 +    a->addTo( floatimageContextMenu);
   1.829 +	actionEditToggleFloatExport=a;
   1.830 +
   1.831 +
   1.832 +
   1.833 +	// Context menu for exports
   1.834 +	exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
   1.835 +
   1.836 +    a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" ), 0, this, "exportASCII" );
   1.837 +    connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
   1.838 +    a->addTo( exportMenu );
   1.839 +
   1.840 +	a = new QAction( tr( "Export XML" ), QPixmap(), tr( "Export XML" ),  0, this, "exportXML" );
   1.841 +    connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
   1.842 +    a->addTo( exportMenu );
   1.843 +	
   1.844 +    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
   1.845 +	{
   1.846 +		a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export HTML" ), 0, this, "exportHTML" );
   1.847 +		connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
   1.848 +		a->addTo( exportMenu );
   1.849 +	}
   1.850 +
   1.851 +	a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" ), ALT + Key_X, this, "exportXHTML" );
   1.852 +    connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
   1.853 +    a->addTo( exportMenu );
   1.854 +
   1.855 +	
   1.856 +	// Context menu for canvas
   1.857 +	canvasContextMenu =new QPopupMenu (this);
   1.858 +	actionEditMapInfo->addTo( canvasContextMenu );
   1.859 +	canvasContextMenu->insertSeparator();	
   1.860 +	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
   1.861 +	canvasContextMenu->insertSeparator();	
   1.862 +	actionFormatLinkColorHint->addTo( canvasContextMenu );
   1.863 +	actionFormatLinkColor->addTo( canvasContextMenu );
   1.864 +	actionFormatBackColor->addTo( canvasContextMenu );
   1.865 +
   1.866 +	// Menu for last opened files
   1.867 +	// Read settings initially
   1.868 +	QString s;
   1.869 +	int j=settings.readNumEntry( "/vym/lastMaps/number",0);
   1.870 +	for (int i=1;i<=j;i++)
   1.871 +	{
   1.872 +		s=settings.readEntry(QString("/vym/lastMaps/map-%1").arg(i),"");
   1.873 +		if (!s.isEmpty() && j<=maxLastMaps) 
   1.874 +			lastMaps.append(s);
   1.875 +	}
   1.876 +	setupLastMapsMenu();
   1.877 +	connect( lastMapsMenu, SIGNAL( activated(int) ), this, SLOT( fileLoadLast(int ) ) );
   1.878 +}
   1.879 +
   1.880 +void Main::setupLastMapsMenu()
   1.881 +{
   1.882 +	// Remove double entries
   1.883 +	QStringList::Iterator it=lastMaps.begin();
   1.884 +	QStringList::Iterator jt;
   1.885 +	while (it!=lastMaps.end() )
   1.886 +	{
   1.887 +		jt=it;
   1.888 +		++jt;
   1.889 +		while (jt!=lastMaps.end() )
   1.890 +		{
   1.891 +			if (*it == *jt)		
   1.892 +				jt=lastMaps.remove(jt);
   1.893 +			else	
   1.894 +				jt++;
   1.895 +		}
   1.896 +		it++;
   1.897 +	}	
   1.898 +
   1.899 +	// Limit length of list to maxLastMaps
   1.900 +	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
   1.901 +	
   1.902 +	// build Menu from lastMaps string list
   1.903 +	lastMapsMenu->clear();
   1.904 +	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
   1.905 +		lastMapsMenu->insertItem (*it );
   1.906 +		
   1.907 +}
   1.908 +
   1.909 +void Main::hideEvent (QHideEvent * )
   1.910 +{
   1.911 +	if (!textEditor->isMinimized() ) textEditor->hide();
   1.912 +}
   1.913 +
   1.914 +void Main::showEvent (QShowEvent * )
   1.915 +{
   1.916 +	if (textEditor->showWithMain()) textEditor->show();
   1.917 +}
   1.918 +
   1.919 +bool Main::reallyWriteDirectory(const QString &dir)
   1.920 +{
   1.921 +	QStringList eList = QDir(dir).entryList();
   1.922 +	if (eList.first() ==".")  eList.pop_front();	// remove "."
   1.923 +	if (eList.first() =="..") eList.pop_front();	// remove "."
   1.924 +	if (!eList.isEmpty())
   1.925 +	{
   1.926 +		QMessageBox mb( "VYM",
   1.927 +			tr("The directory ") + dir + 
   1.928 +			tr(" is not empty. Do you risk to overwrite its contents?"),
   1.929 +		QMessageBox::Warning,
   1.930 +		QMessageBox::Yes ,
   1.931 +		QMessageBox::Cancel | QMessageBox::Default,
   1.932 +		QMessageBox::QMessageBox::NoButton );
   1.933 +
   1.934 +		mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
   1.935 +		mb.setButtonText( QMessageBox::No, tr("Cancel"));
   1.936 +		switch( mb.exec() ) 
   1.937 +		{
   1.938 +			case QMessageBox::Yes:
   1.939 +				// save 
   1.940 +				return true;
   1.941 +			case QMessageBox::Cancel:
   1.942 +				// do nothing
   1.943 +				return false;
   1.944 +		}
   1.945 +	}
   1.946 +	return true;
   1.947 +}
   1.948 +
   1.949 +QString Main::browseDirectory (const QString &caption)
   1.950 +{
   1.951 +	QFileDialog fd(this,caption);
   1.952 +	fd.setMode (QFileDialog::DirectoryOnly);
   1.953 +	fd.setCaption("VYM - "+caption);
   1.954 +	fd.show();
   1.955 +	
   1.956 +	if ( fd.exec() == QDialog::Accepted )
   1.957 +		return fd.selectedFile();
   1.958 +	else
   1.959 +		return "";
   1.960 +}
   1.961 +
   1.962 +MapEditor* Main::currentMapEditor() const
   1.963 +{
   1.964 +    if ( tabWidget->currentPage() &&
   1.965 +	 tabWidget->currentPage()->inherits( "MapEditor" ) )
   1.966 +		return (MapEditor*)tabWidget->currentPage();
   1.967 +    return NULL;	
   1.968 +}
   1.969 +
   1.970 +//TODO not used now, maybe use this for overview window later
   1.971 +void Main::newView() 
   1.972 +{
   1.973 +    // Open a new view... have it delete when closed.
   1.974 +    Main *m = new Main(0, 0, WDestructiveClose);
   1.975 +    qApp->setMainWidget(m);
   1.976 +    m->show();
   1.977 +    qApp->setMainWidget(0);
   1.978 +}
   1.979 +
   1.980 +void Main::editorChanged(QWidget *)
   1.981 +{
   1.982 +	// Unselect all possibly selected objects
   1.983 +	// (Important to update note editor)
   1.984 +	int i;
   1.985 +	MapEditor *me;
   1.986 +	for (i=0;i<=tabWidget->count() -1;i++)
   1.987 +	{
   1.988 +		
   1.989 +		me=(MapEditor*)tabWidget->page(i);
   1.990 +		me->unselect();
   1.991 +	}	
   1.992 +	currentMapEditor()->reselect();
   1.993 +
   1.994 +	// Update actions to in menus and toolbars according to editor
   1.995 +	currentMapEditor()->updateActions();
   1.996 +}
   1.997 +
   1.998 +void Main::fileNew()
   1.999 +{
  1.1000 +	QString fn="unnamed";
  1.1001 +	MapEditor* medit = new MapEditor (tabWidget, true);
  1.1002 +	tabWidget->addTab (medit,fn);
  1.1003 +	tabWidget->showPage(medit);
  1.1004 +	medit->viewport()->setFocus();
  1.1005 +	medit->select("mc:");
  1.1006 +}
  1.1007 +
  1.1008 +void Main::fileLoad(QString fn, const LoadMode &lmode)
  1.1009 +{
  1.1010 +	// Error codes
  1.1011 +	enum errorCode {success,aborted};
  1.1012 +	errorCode err=success;
  1.1013 +	
  1.1014 +	// fn is usually the archive, mapfile the file after uncompressing
  1.1015 +	QString mapfile;
  1.1016 +
  1.1017 +	// Make fn absolute (needed for unzip)
  1.1018 +	fn=QDir (fn).absPath();
  1.1019 +
  1.1020 +	MapEditor *me;
  1.1021 +
  1.1022 +	if (lmode==NewMap)
  1.1023 +	{
  1.1024 +		// Check, if map is already loaded
  1.1025 +		int i=0;
  1.1026 +		while (i<=tabWidget->count() -1)
  1.1027 +		{
  1.1028 +			me=(MapEditor*)tabWidget->page(i);
  1.1029 +			if (me->getFilePath() == fn)
  1.1030 +			{
  1.1031 +				// Already there, ask for confirmation
  1.1032 +				QMessageBox mb( "VYM",
  1.1033 +					tr("The map ") + fn + tr ("\n is already opened."
  1.1034 +					"Opening the same map in multiple editors may lead \n"
  1.1035 +					"to confusion when finishing working with vym."
  1.1036 +					"Do you want to"),
  1.1037 +					QMessageBox::Warning,
  1.1038 +					QMessageBox::Yes | QMessageBox::Default,
  1.1039 +					QMessageBox::Cancel | QMessageBox::Escape,
  1.1040 +					QMessageBox::QMessageBox::NoButton);
  1.1041 +				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1.1042 +				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1.1043 +				switch( mb.exec() ) 
  1.1044 +				{
  1.1045 +					case QMessageBox::Yes:
  1.1046 +						// load anyway
  1.1047 +						i=tabWidget->count();
  1.1048 +						break;
  1.1049 +					case QMessageBox::Cancel:
  1.1050 +						// do nothing
  1.1051 +						return;
  1.1052 +						break;
  1.1053 +				}
  1.1054 +			}
  1.1055 +			i++;
  1.1056 +		}
  1.1057 +	}
  1.1058 +
  1.1059 +
  1.1060 +	// Try to load map
  1.1061 +    if ( !fn.isEmpty() )
  1.1062 +	{
  1.1063 +		me = currentMapEditor();
  1.1064 +		int tabIndex=tabWidget->currentPageIndex();
  1.1065 +		// Check first, if mapeditor exists
  1.1066 +		// If it is not default AND we want a new map, 
  1.1067 +		// create a new mapeditor in a new tab
  1.1068 +		if ( lmode==NewMap && (!me || !me->isDefault() ) )
  1.1069 +		{
  1.1070 +			me = new MapEditor (tabWidget,true);
  1.1071 +			tabWidget->addTab (me,fn);
  1.1072 +			tabIndex=tabWidget->indexOf (me);
  1.1073 +			tabWidget->setCurrentPage (tabIndex);
  1.1074 +		}
  1.1075 +		
  1.1076 +		// Check, if file exists (important for creating new files
  1.1077 +		// from command line
  1.1078 +		if (!QFile(fn).exists() )
  1.1079 +		{
  1.1080 +			QMessageBox mb( "VYM",
  1.1081 +				tr("The map") + fn + 
  1.1082 +				tr(" does not exist.\n Do you want to create a new one?"),
  1.1083 +				QMessageBox::Question,
  1.1084 +				QMessageBox::Yes ,
  1.1085 +				QMessageBox::Cancel | QMessageBox::Default,
  1.1086 +				QMessageBox::QMessageBox::NoButton );
  1.1087 +
  1.1088 +			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1.1089 +			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1.1090 +			switch( mb.exec() ) 
  1.1091 +			{
  1.1092 +				case QMessageBox::Yes:
  1.1093 +					// Create new map
  1.1094 +					currentMapEditor()->setFilePath(fn);
  1.1095 +					tabWidget->setTabLabel (currentMapEditor(),
  1.1096 +						currentMapEditor()->getFileName() );
  1.1097 +					statusBar()->message( "Created " + fn , statusbarTime );
  1.1098 +					return;
  1.1099 +						
  1.1100 +				case QMessageBox::Cancel:
  1.1101 +					// don't create new map
  1.1102 +					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1.1103 +					fileCloseMap();
  1.1104 +					return;
  1.1105 +			}
  1.1106 +		}	
  1.1107 +
  1.1108 +
  1.1109 +		//tabWidget->currentPage() won't be NULL here, because of above...
  1.1110 +		tabWidget->showPage(me);
  1.1111 +		me->viewport()->setFocus();
  1.1112 +
  1.1113 +		// Create temporary directory for packing
  1.1114 +		char tmpdir1[]="/tmp/vym-XXXXXX";	
  1.1115 +		QString tmpMapDir=mkdtemp(tmpdir1);
  1.1116 +
  1.1117 +		// Try to unzip file
  1.1118 +		Process *zipProc=new Process ();
  1.1119 +		zipProc->clearArguments();
  1.1120 +		zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1.1121 +		zipProc->addArgument ("unzip");
  1.1122 +		zipProc->addArgument (fn );
  1.1123 +		zipProc->addArgument ("-d");
  1.1124 +		zipProc->addArgument (tmpMapDir);
  1.1125 +
  1.1126 +		if (!zipProc->start() )
  1.1127 +		{
  1.1128 +			QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1.1129 +						   tr("Couldn't start unzip to decompress data."));
  1.1130 +			err=aborted;
  1.1131 +			
  1.1132 +		} else
  1.1133 +		{
  1.1134 +			zipProc->waitFinished();
  1.1135 +			if (!zipProc->normalExit() )
  1.1136 +			{
  1.1137 +				QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1.1138 +							   tr("unzip didn't exit normally") +
  1.1139 +							   zipProc->getErrout() );
  1.1140 +				err=aborted;
  1.1141 +			} else
  1.1142 +			{
  1.1143 +				if (zipProc->exitStatus()>0)
  1.1144 +				{
  1.1145 +					if (zipProc->exitStatus()==9)
  1.1146 +					{
  1.1147 +						// no zipped file, but maybe .xml or old version? Try again.
  1.1148 +						mapfile=fn;
  1.1149 +						me->setZipped(false);
  1.1150 +					}	
  1.1151 +					else	
  1.1152 +					{
  1.1153 +						QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1.1154 +									   QString("unzip exit code:  %1").arg(zipProc->exitStatus() ) +
  1.1155 +									   zipProc->getErrout() );
  1.1156 +						err=aborted;
  1.1157 +					}
  1.1158 +				} else
  1.1159 +				{	// Uncompressing was successfull,
  1.1160 +					// load from uncompressed temporary directory
  1.1161 +
  1.1162 +					me->setZipped(true);
  1.1163 +
  1.1164 +					
  1.1165 +					// Look for mapname.xml
  1.1166 +					mapfile= fn.left(fn.findRev(".",-1,true));
  1.1167 +					mapfile=mapfile.section( '/', -1 );
  1.1168 +					QFile file( tmpMapDir + "/" + mapfile + ".xml");
  1.1169 +					if (!file.exists() )
  1.1170 +					{
  1.1171 +						// mapname.xml does not exist, well, 
  1.1172 +						// maybe some renamed the mapname.vym file...
  1.1173 +						// Try to find any .xml in the toplevel 
  1.1174 +						// directory of the .vym file
  1.1175 +						QStringList flist=QDir (tmpMapDir).entryList("*.xml");
  1.1176 +						if (flist.count()==1) 
  1.1177 +						{
  1.1178 +							// Only one entry, take this one
  1.1179 +							mapfile=tmpMapDir + "/"+flist.first();
  1.1180 +						} else
  1.1181 +						{
  1.1182 +							for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) 
  1.1183 +								*it=tmpMapDir + "/" + *it;
  1.1184 +							// FIXME	
  1.1185 +							// Multiple entries, load all (but only the first one into this ME)
  1.1186 +							//mainWindow->fileLoadFromTmp (flist);
  1.1187 +							//returnCode=1;	// Silently forget this attempt to load
  1.1188 +							qWarning ("MainWindow::load (fn)  multimap found...");
  1.1189 +						}	
  1.1190 +							
  1.1191 +						if (flist.isEmpty() )
  1.1192 +						{
  1.1193 +							QMessageBox::critical( 0, tr( "Critical Load Error" ),
  1.1194 +									   tr("Couldn't find a map (*.xml) in .vym archive.\n"));
  1.1195 +							err=aborted;				   
  1.1196 +						}	
  1.1197 +					} //file doesn't exist	
  1.1198 +					else
  1.1199 +						mapfile=file.name();
  1.1200 +				} // Uncompressing successfull
  1.1201 +			}
  1.1202 +		}
  1.1203 +
  1.1204 +		// Finally load map into mapEditor
  1.1205 +		me->setFilePath (mapfile,fn);
  1.1206 +		if (me->load(mapfile,lmode))
  1.1207 +			err=aborted;
  1.1208 +
  1.1209 +		// Delete tmpDir
  1.1210 +		system ( "rm -rf "+tmpMapDir);
  1.1211 +
  1.1212 +		// Check for errors
  1.1213 +		if (err==success) 
  1.1214 +		{
  1.1215 +			if (lmode==NewMap)
  1.1216 +			{
  1.1217 +				me->setFilePath (fn);
  1.1218 +				tabWidget->changeTab(tabWidget->page(tabIndex), me->getFileName());
  1.1219 +				lastMaps.prepend(me->getFilePath() );
  1.1220 +				setupLastMapsMenu();
  1.1221 +				actionFilePrint->setEnabled (true);
  1.1222 +			}	
  1.1223 +			statusBar()->message( "Loaded " + fn, statusbarTime );
  1.1224 +			return;
  1.1225 +		} else 
  1.1226 +		{
  1.1227 +			if (lmode==NewMap)
  1.1228 +				fileCloseMap();
  1.1229 +		}	
  1.1230 +
  1.1231 +
  1.1232 +	}
  1.1233 +	statusBar()->message( "Could not load " + fn, statusbarTime );
  1.1234 +}
  1.1235 +
  1.1236 +
  1.1237 +void Main::fileLoad(const LoadMode &lmode)
  1.1238 +{
  1.1239 +	QFileDialog *fd=new QFileDialog( this);
  1.1240 +	if (!lastFileDir.isEmpty()) 
  1.1241 +		fd->setDir (lastFileDir);
  1.1242 +	fd->addFilter ("XML (*.xml)");
  1.1243 +	fd->addFilter ("VYM map (*.vym *.vyp)");
  1.1244 +	switch (lmode)
  1.1245 +	{
  1.1246 +		case NewMap:
  1.1247 +			fd->setCaption(tr("Load vym map"));
  1.1248 +			break;
  1.1249 +		case ImportAdd:
  1.1250 +			fd->setCaption(tr("Import: Add vym map to selection"));
  1.1251 +			break;
  1.1252 +		case ImportReplace:
  1.1253 +			fd->setCaption(tr("Import: Replace selection with vym map"));
  1.1254 +			break;
  1.1255 +	}
  1.1256 +	fd->show();
  1.1257 +
  1.1258 +	QString fn;
  1.1259 +	if ( fd->exec() == QDialog::Accepted )
  1.1260 +	{
  1.1261 +		lastFileDir=fd->dirPath();
  1.1262 +        fn = fd->selectedFile();
  1.1263 +		fileLoad(fn, lmode);				   
  1.1264 +	}
  1.1265 +}
  1.1266 +
  1.1267 +void Main::fileLoad()
  1.1268 +{
  1.1269 +	fileLoad (NewMap);
  1.1270 +}
  1.1271 +
  1.1272 +void Main::fileLoadLast(int i)
  1.1273 +{
  1.1274 +	fileLoad(*lastMaps.at(lastMapsMenu->indexOf (i) ),NewMap);			   
  1.1275 +}
  1.1276 +
  1.1277 +void Main::fileSave(const SaveMode &savemode)
  1.1278 +{
  1.1279 +	// tmp dir for zipping 
  1.1280 +	QString tmpMapDir;
  1.1281 +	
  1.1282 +	// Error codes
  1.1283 +	enum errorCode {success,aborted};
  1.1284 +	errorCode err=success;
  1.1285 +	
  1.1286 +	QString safeFilePath;
  1.1287 +
  1.1288 +	bool saveZipped=currentMapEditor()->saveZipped();
  1.1289 +
  1.1290 +	if (currentMapEditor())
  1.1291 +	{
  1.1292 +		QString fn=currentMapEditor()->getFilePath();
  1.1293 +		// filename=unnamed, filepath="" in constructor...
  1.1294 +		if ( !fn.isEmpty() ) 
  1.1295 +		{	
  1.1296 +			// We have a filepath, go on saving			
  1.1297 +			// First remove existing file, we 
  1.1298 +			// don't want to add to old zip archives
  1.1299 +			QFile f(fn);
  1.1300 +			if (f.exists() ) 
  1.1301 +				if (!f.remove())
  1.1302 +					QMessageBox::warning( 0, tr( "Save Error" ),
  1.1303 +						fn+   tr("\ncould not be removed before saving"));
  1.1304 +
  1.1305 +			// Look, if we should zip the data:
  1.1306 +			if (!saveZipped)
  1.1307 +			{
  1.1308 +				QMessageBox mb( "VYM",
  1.1309 +					tr("The map ") + fn + 
  1.1310 +					tr ("\ndid not use the compressed "
  1.1311 +					"vym file format.\nWriting it uncompressed will also write images \n"
  1.1312 +					"and flags and thus may overwrite files in the "
  1.1313 +					"given directory\n\nDo you want to write the map"),
  1.1314 +					QMessageBox::Warning,
  1.1315 +					QMessageBox::Yes | QMessageBox::Default,
  1.1316 +					QMessageBox::No ,
  1.1317 +					QMessageBox::Cancel | QMessageBox::Escape);
  1.1318 +				mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
  1.1319 +				mb.setButtonText( QMessageBox::No, tr("uncompressed") );
  1.1320 +				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1.1321 +				switch( mb.exec() ) 
  1.1322 +				{
  1.1323 +					case QMessageBox::Yes:
  1.1324 +						// save compressed (default file format)
  1.1325 +						saveZipped=true;
  1.1326 +						break;
  1.1327 +					case QMessageBox::No:
  1.1328 +						// save uncompressed
  1.1329 +						saveZipped=false;
  1.1330 +						break;
  1.1331 +					case QMessageBox::Cancel:
  1.1332 +						// do nothing
  1.1333 +						return;
  1.1334 +						break;
  1.1335 +				}
  1.1336 +			}
  1.1337 +
  1.1338 +			if (saveZipped)
  1.1339 +			{
  1.1340 +				char tmpdir1[]="/tmp/vym-XXXXXX";	
  1.1341 +				tmpMapDir=mkdtemp(tmpdir1);
  1.1342 +			
  1.1343 +				safeFilePath=currentMapEditor()->getFilePath();
  1.1344 +				currentMapEditor()->setFilePath (tmpMapDir+"/"+
  1.1345 +					currentMapEditor()->getMapName()+ ".xml",
  1.1346 +					safeFilePath);
  1.1347 +				currentMapEditor()->save (savemode);
  1.1348 +				currentMapEditor()->setFilePath (safeFilePath);
  1.1349 +				
  1.1350 +				// zip the temporary directory
  1.1351 +				Process *zipProc=new Process ();
  1.1352 +				zipProc->clearArguments();
  1.1353 +				zipProc->setWorkingDirectory (QDir(tmpMapDir));
  1.1354 +				zipProc->addArgument ("zip");
  1.1355 +				zipProc->addArgument ("-r");
  1.1356 +				zipProc->addArgument (fn);
  1.1357 +				zipProc->addArgument (".");
  1.1358 +
  1.1359 +				if (!zipProc->start() )
  1.1360 +				{	
  1.1361 +					// zip could not be started
  1.1362 +					QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1.1363 +								   tr("Couldn't start zip to compress data."));
  1.1364 +					err=aborted;
  1.1365 +				} else
  1.1366 +				{
  1.1367 +					// zip could be started
  1.1368 +					zipProc->waitFinished();
  1.1369 +					if (!zipProc->normalExit() )
  1.1370 +					{
  1.1371 +						QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1.1372 +									   tr("zip didn't exit normally")+
  1.1373 +									   "\n" + zipProc->getErrout());
  1.1374 +						err=aborted;
  1.1375 +					} else
  1.1376 +					{
  1.1377 +						if (zipProc->exitStatus()>0)
  1.1378 +						{
  1.1379 +							QMessageBox::critical( 0, tr( "Critical Save Error" ),
  1.1380 +									   QString("zip exit code:  %1").arg(zipProc->exitStatus() )+
  1.1381 +									   "\n" + zipProc->getErrout() );
  1.1382 +							err=aborted;
  1.1383 +						}
  1.1384 +					}
  1.1385 +				}	// zip could be started
  1.1386 +			} // save zipped
  1.1387 +			else
  1.1388 +			{
  1.1389 +				// Save unzipped. 
  1.1390 +				safeFilePath=currentMapEditor()->getFilePath();
  1.1391 +				currentMapEditor()->setFilePath (fn, safeFilePath);
  1.1392 +				currentMapEditor()->save (savemode);
  1.1393 +				currentMapEditor()->setFilePath (safeFilePath);
  1.1394 +			} // save zipped 	
  1.1395 +		} // filepath available
  1.1396 +		else
  1.1397 +		{
  1.1398 +			// We have  no filepath yet,
  1.1399 +			// call fileSaveAs() now, this will call fileSave() 
  1.1400 +			// again.
  1.1401 +			fileSaveAs(savemode);
  1.1402 +		}
  1.1403 +    }
  1.1404 +
  1.1405 +	if (currentMapEditor()->saveZipped())
  1.1406 +	{
  1.1407 +		// Delete tmpDir
  1.1408 +		system ( "rm -rf "+ tmpMapDir );
  1.1409 +	} 
  1.1410 +
  1.1411 +	if (err==success)
  1.1412 +		statusBar()->message( 
  1.1413 +			tr("Saved")+" " + currentMapEditor()->getFilePath(), 
  1.1414 +			statusbarTime );
  1.1415 +	else		
  1.1416 +		statusBar()->message( 
  1.1417 +			tr("Couldn't save")+" " + currentMapEditor()->getFilePath(), 
  1.1418 +			statusbarTime );
  1.1419 +}
  1.1420 +
  1.1421 +void Main::fileSave()
  1.1422 +{
  1.1423 +	fileSave (CompleteMap);
  1.1424 +}
  1.1425 +
  1.1426 +void Main::fileSaveAs(const SaveMode& savemode)
  1.1427 +{
  1.1428 +	QString tmpMapDir;
  1.1429 +	QString fn;
  1.1430 +
  1.1431 +	if (currentMapEditor())
  1.1432 +	{
  1.1433 +		if (savemode==CompleteMap)
  1.1434 +			fn = QFileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  1.1435 +		else		
  1.1436 +			fn = QFileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  1.1437 +		if ( !fn.isEmpty() ) 
  1.1438 +		{
  1.1439 +			// Check for existing file
  1.1440 +			if (QFile (fn).exists())
  1.1441 +			{
  1.1442 +				QMessageBox mb( "VYM",
  1.1443 +					tr("The file ") + fn + tr ("\nexists already. Do you want to"),
  1.1444 +					QMessageBox::Warning,
  1.1445 +					QMessageBox::Yes | QMessageBox::Default,
  1.1446 +					QMessageBox::Cancel | QMessageBox::Escape,
  1.1447 +					QMessageBox::QMessageBox::NoButton);
  1.1448 +				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  1.1449 +				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1.1450 +				switch( mb.exec() ) 
  1.1451 +				{
  1.1452 +					case QMessageBox::Yes:
  1.1453 +						// save 
  1.1454 +						break;
  1.1455 +					case QMessageBox::Cancel:
  1.1456 +						// do nothing
  1.1457 +						return;
  1.1458 +						break;
  1.1459 +				}
  1.1460 +			} else
  1.1461 +			{
  1.1462 +				// New file, add extension to filename, if missing
  1.1463 +				// This is always .vym or .vyp, depending on savemode
  1.1464 +				if (savemode==CompleteMap)
  1.1465 +				{
  1.1466 +					if (!fn.contains (".vym") && !fn.contains (".xml"))
  1.1467 +						fn +=".vym";
  1.1468 +				} else		
  1.1469 +				{
  1.1470 +					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  1.1471 +						fn +=".vyp";
  1.1472 +				}
  1.1473 +			}
  1.1474 +	
  1.1475 +
  1.1476 +
  1.1477 +
  1.1478 +			// Save now
  1.1479 +			currentMapEditor()->setFilePath(fn);
  1.1480 +			fileSave(savemode);
  1.1481 +
  1.1482 +			// Set name of tab
  1.1483 +			tabWidget->setTabLabel (currentMapEditor(),
  1.1484 +				currentMapEditor()->getFileName() );
  1.1485 +			return;
  1.1486 +		} 
  1.1487 +	}
  1.1488 +}
  1.1489 +
  1.1490 +void Main::fileSaveAs()
  1.1491 +{
  1.1492 +	fileSaveAs (CompleteMap);
  1.1493 +}
  1.1494 +
  1.1495 +void Main::fileImportDir()
  1.1496 +{
  1.1497 +	if (currentMapEditor())
  1.1498 +		currentMapEditor()->importDir();	
  1.1499 +}
  1.1500 +
  1.1501 +void Main::fileExportXML()
  1.1502 +{
  1.1503 +	if (currentMapEditor())
  1.1504 +	{
  1.1505 +		QString dir=browseDirectory(tr("Export XML to directory"));
  1.1506 +		if (dir !="" && reallyWriteDirectory(dir) )
  1.1507 +			currentMapEditor()->exportXML(dir);
  1.1508 +	}	
  1.1509 +}
  1.1510 +
  1.1511 +void Main::fileExportHTML()
  1.1512 +{
  1.1513 +	if (currentMapEditor())
  1.1514 +	{
  1.1515 +		ExportHTMLDialog dia(this);
  1.1516 +		
  1.1517 +		if (dia.exec()==QDialog::Accepted)
  1.1518 +		{
  1.1519 +			QString dir=dia.getDir();
  1.1520 +			if (reallyWriteDirectory(dir) )
  1.1521 +			{
  1.1522 +				currentMapEditor()->exportXML (dia.getDir() );
  1.1523 +				dia.doExport(currentMapEditor()->getMapName() );
  1.1524 +			}	
  1.1525 +		}
  1.1526 +	}	
  1.1527 +}
  1.1528 +
  1.1529 +void Main::fileExportXHTML()
  1.1530 +{
  1.1531 +	QString dir;
  1.1532 +	if (currentMapEditor())
  1.1533 +	{
  1.1534 +		ExportXHTMLDialog dia(this);
  1.1535 +		dia.setFilePath (currentMapEditor()->getFilePath() );
  1.1536 +		dia.setMapName (currentMapEditor()->getMapName() );
  1.1537 +		dia.readSettings();
  1.1538 +		
  1.1539 +		if (dia.exec()==QDialog::Accepted)
  1.1540 +		{
  1.1541 +			QString dir=dia.getDir();
  1.1542 +			// Check, if warnings should be used before overwriting
  1.1543 +			// the output directory
  1.1544 +			bool ok;
  1.1545 +			if (dia.warnings()) 
  1.1546 +				ok=reallyWriteDirectory(dir);
  1.1547 +			else
  1.1548 +				ok=true;
  1.1549 +
  1.1550 +			if (ok)
  1.1551 +			{
  1.1552 +				currentMapEditor()->exportXML (dia.getDir() );
  1.1553 +				dia.doExport(currentMapEditor()->getMapName() );
  1.1554 +				if (dia.hasChanged())
  1.1555 +					currentMapEditor()->setChanged();
  1.1556 +			}	
  1.1557 +		}
  1.1558 +	}	
  1.1559 +}
  1.1560 +
  1.1561 +void Main::fileExportImage(int item)
  1.1562 +{
  1.1563 +	if (currentMapEditor())
  1.1564 +	{
  1.1565 +		QString fn = QFileDialog::getSaveFileName( QString::null, "Image  (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *xbm *.xpm)",
  1.1566 +							   this );
  1.1567 +		if ( !fn.isEmpty() ) 
  1.1568 +		{
  1.1569 +			currentMapEditor()->exportImage(fn,item);
  1.1570 +		} else {
  1.1571 +			statusBar()->message( tr("Couldn't save") + fn, statusbarTime );
  1.1572 +		}
  1.1573 +	}
  1.1574 +}
  1.1575 +
  1.1576 +void Main::fileExportASCII()
  1.1577 +{
  1.1578 +	if (currentMapEditor())
  1.1579 +		currentMapEditor()->exportASCII();	
  1.1580 +}
  1.1581 +
  1.1582 +void Main::fileCloseMap()
  1.1583 +{
  1.1584 +	if (currentMapEditor())
  1.1585 +	{
  1.1586 +		if (currentMapEditor()->hasChanged())
  1.1587 +		{
  1.1588 +			QMessageBox mb( "VYM",
  1.1589 +				tr("The map ") + currentMapEditor()->getFileName() +
  1.1590 +				tr(" has been modified but not saved yet. Do you want to"),
  1.1591 +				QMessageBox::Warning,
  1.1592 +				QMessageBox::Yes | QMessageBox::Default,
  1.1593 +				QMessageBox::No,
  1.1594 +				QMessageBox::Cancel | QMessageBox::Escape );
  1.1595 +			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  1.1596 +			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  1.1597 +			switch( mb.exec() ) 
  1.1598 +			{
  1.1599 +				case QMessageBox::Yes:
  1.1600 +					// save and close
  1.1601 +					fileSave(CompleteMap);
  1.1602 +					break;
  1.1603 +				case QMessageBox::No:
  1.1604 +				// close  without saving
  1.1605 +					break;
  1.1606 +				case QMessageBox::Cancel:
  1.1607 +					// do nothing
  1.1608 +				return;
  1.1609 +			}
  1.1610 +		} 
  1.1611 +		currentMapEditor()->closeMap();
  1.1612 +		tabWidget->removePage(currentMapEditor());
  1.1613 +		if (tabWidget->count()==0)
  1.1614 +			actionFilePrint->setEnabled (false);
  1.1615 +	}	
  1.1616 +}
  1.1617 +
  1.1618 +void Main::filePrint()
  1.1619 +{
  1.1620 +	if (currentMapEditor())
  1.1621 +		currentMapEditor()->print();
  1.1622 +}
  1.1623 +
  1.1624 +void Main::fileExitVYM()
  1.1625 +{
  1.1626 +	// Check if one or more editors have changed
  1.1627 +	MapEditor *me;
  1.1628 +	int i;
  1.1629 +	for (i=0;i<=tabWidget->count() -1;i++)
  1.1630 +	{
  1.1631 +		
  1.1632 +		me=(MapEditor*)tabWidget->page(i);
  1.1633 +
  1.1634 +		// If something changed, ask what to do
  1.1635 +		if (me->isUnsaved())
  1.1636 +		{
  1.1637 +			tabWidget->setCurrentPage(i);
  1.1638 +			QMessageBox mb( "VYM",
  1.1639 +				tr("This map is not saved yet. Do you want to"),
  1.1640 +				QMessageBox::Warning,
  1.1641 +				QMessageBox::Yes | QMessageBox::Default,
  1.1642 +				QMessageBox::No,
  1.1643 +				QMessageBox::Cancel | QMessageBox::Escape );
  1.1644 +			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  1.1645 +			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  1.1646 +			mb.show();
  1.1647 +			// Call undocumented function: setActiveWindow is only
  1.1648 +			// possible, if widget is visible. This depends on
  1.1649 +			// windowmanager...
  1.1650 +#if defined(Q_OS_LINUX)
  1.1651 +			qt_wait_for_window_manager( this);
  1.1652 +#endif			
  1.1653 +			mb.setActiveWindow();
  1.1654 +			switch( mb.exec() ) {
  1.1655 +				case QMessageBox::Yes:
  1.1656 +					// save (the changed editors) and exit
  1.1657 +					fileSave(CompleteMap);
  1.1658 +					break;
  1.1659 +				case QMessageBox::No:
  1.1660 +					// exit without saving
  1.1661 +					break;
  1.1662 +				case QMessageBox::Cancel:
  1.1663 +					// don't save and don't exit
  1.1664 +				return;
  1.1665 +			}
  1.1666 +		}
  1.1667 +	} // loop over all MEs	
  1.1668 +    qApp->quit();
  1.1669 +}
  1.1670 +
  1.1671 +void Main::editUndo()
  1.1672 +{
  1.1673 +	if (currentMapEditor())
  1.1674 +		currentMapEditor()->undo();
  1.1675 +}
  1.1676 +
  1.1677 +void Main::editRedo()	    // TODO
  1.1678 +{
  1.1679 +}
  1.1680 +
  1.1681 +void Main::editCopy()
  1.1682 +{
  1.1683 +	if (currentMapEditor())
  1.1684 +		currentMapEditor()->copy();
  1.1685 +}
  1.1686 +
  1.1687 +void Main::editPaste()
  1.1688 +{
  1.1689 +	if (currentMapEditor())
  1.1690 +		currentMapEditor()->paste();
  1.1691 +}
  1.1692 +
  1.1693 +void Main::editCut()
  1.1694 +{
  1.1695 +	if (currentMapEditor())
  1.1696 +		currentMapEditor()->cut();
  1.1697 +}
  1.1698 +
  1.1699 +void Main::editOpenFindWindow()
  1.1700 +{
  1.1701 +	findWindow->popup();
  1.1702 +	findWindow->raise();
  1.1703 +
  1.1704 +	// Call undocumented function: setActiveWindow is only
  1.1705 +	// possible, if widget is visible. This depends on
  1.1706 +	// windowmanager...
  1.1707 +#if defined(Q_OS_LINUX)
  1.1708 +	qt_wait_for_window_manager( this);
  1.1709 +#endif	
  1.1710 +	findWindow->setActiveWindow();
  1.1711 +}
  1.1712 +
  1.1713 +void Main::editFind(QString s)
  1.1714 +{
  1.1715 +	bool cs=false;
  1.1716 +	BranchObj *bo=currentMapEditor()->findText(s, cs);
  1.1717 +	if (bo)
  1.1718 +	{	
  1.1719 +		statusBar()->message( "Found: " + bo->getHeading(), statusbarTime );
  1.1720 +	} else
  1.1721 +	{
  1.1722 +		QMessageBox::information( findWindow, tr( "VYM -Information:" ),
  1.1723 +							   tr("No matches found for ")+
  1.1724 +							   "'<b>"+s+"</b>'");
  1.1725 +	}	
  1.1726 +}
  1.1727 +
  1.1728 +void Main::editFindChanged()
  1.1729 +{	// Notify editor, to abort the current find process
  1.1730 +	currentMapEditor()->findReset();
  1.1731 +}
  1.1732 +
  1.1733 +void Main::editOpenURL()
  1.1734 +{
  1.1735 +	if (currentMapEditor())
  1.1736 +	    currentMapEditor()->openURL();
  1.1737 +}
  1.1738 +
  1.1739 +void Main::editURL()
  1.1740 +{
  1.1741 +	if (currentMapEditor())
  1.1742 +	    currentMapEditor()->editURL();
  1.1743 +}
  1.1744 +
  1.1745 +void Main::editHeading2URL()
  1.1746 +{
  1.1747 +	if (currentMapEditor())
  1.1748 +	    currentMapEditor()->editHeading2URL();
  1.1749 +}
  1.1750 +
  1.1751 +void Main::editBugzilla2URL()
  1.1752 +{
  1.1753 +	if (currentMapEditor())
  1.1754 +	    currentMapEditor()->editBugzilla2URL();
  1.1755 +}
  1.1756 +
  1.1757 +void Main::editOpenVymLink()
  1.1758 +{
  1.1759 +	// Get current path to map
  1.1760 +	QString currentVymLink;
  1.1761 +	if (currentMapEditor())
  1.1762 +	{
  1.1763 +		currentVymLink=currentMapEditor()->getVymLink();	
  1.1764 +		// compare path with already loaded maps
  1.1765 +		int index=-1;
  1.1766 +		int i;
  1.1767 +		MapEditor *me;
  1.1768 +		for (i=0;i<=tabWidget->count() -1;i++)
  1.1769 +		{
  1.1770 +			me=(MapEditor*)tabWidget->page(i);
  1.1771 +			if (currentVymLink==me->getFilePath() )
  1.1772 +			{
  1.1773 +				index=i;
  1.1774 +				break;
  1.1775 +			}
  1.1776 +		}	
  1.1777 +		if (index<0)
  1.1778 +		// Load map
  1.1779 +		{
  1.1780 +			if (!QFile(currentVymLink).exists() )
  1.1781 +				QMessageBox::critical( 0, tr( "Critical Error" ),
  1.1782 +				   tr("Couldn't open map " +currentVymLink)+".");
  1.1783 +			else
  1.1784 +			{
  1.1785 +				fileLoad (currentVymLink, NewMap);
  1.1786 +				tabWidget->setCurrentPage (tabWidget->count()-1);	
  1.1787 +			}
  1.1788 +		} else
  1.1789 +			// Go to tab containing the map
  1.1790 +			tabWidget->setCurrentPage (index);	
  1.1791 +	}
  1.1792 +}
  1.1793 +
  1.1794 +void Main::editVymLink()
  1.1795 +{
  1.1796 +	if (currentMapEditor())
  1.1797 +		currentMapEditor()->editVymLink();	
  1.1798 +}
  1.1799 +
  1.1800 +void Main::editDeleteVymLink()
  1.1801 +{
  1.1802 +	if (currentMapEditor())
  1.1803 +		currentMapEditor()->deleteVymLink();	
  1.1804 +}
  1.1805 +
  1.1806 +void Main::editMapInfo()
  1.1807 +{
  1.1808 +	if (currentMapEditor())
  1.1809 +		currentMapEditor()->editMapInfo();	
  1.1810 +}
  1.1811 +
  1.1812 +void Main::editMoveUp()
  1.1813 +{
  1.1814 +	if (currentMapEditor())
  1.1815 +	    currentMapEditor()->moveBranchUp();
  1.1816 +}
  1.1817 +
  1.1818 +void Main::editMoveDown()
  1.1819 +{
  1.1820 +	if (currentMapEditor())
  1.1821 +		currentMapEditor()->moveBranchDown();
  1.1822 +}
  1.1823 +
  1.1824 +void Main::editToggleScroll()
  1.1825 +{
  1.1826 +	if (currentMapEditor())
  1.1827 +	{
  1.1828 +		currentMapEditor()->toggleScroll();	
  1.1829 +	}	
  1.1830 +}
  1.1831 +
  1.1832 +void Main::editUnScrollAll()
  1.1833 +{
  1.1834 +	if (currentMapEditor())
  1.1835 +	{
  1.1836 +		currentMapEditor()->unScrollAll();	
  1.1837 +	}	
  1.1838 +}
  1.1839 +
  1.1840 +void Main::editHeading()
  1.1841 +{
  1.1842 +	if (currentMapEditor())
  1.1843 +		currentMapEditor()->editHeading();
  1.1844 +}
  1.1845 +
  1.1846 +void Main::editNewBranch()
  1.1847 +{
  1.1848 +	if (currentMapEditor())
  1.1849 +		currentMapEditor()->addNewBranch(0);
  1.1850 +}
  1.1851 +
  1.1852 +void Main::editNewBranchAbove()
  1.1853 +{
  1.1854 +	if (currentMapEditor())
  1.1855 +		currentMapEditor()->addNewBranch(-1);
  1.1856 +}
  1.1857 +
  1.1858 +void Main::editNewBranchBelow()
  1.1859 +{
  1.1860 +	if (currentMapEditor())
  1.1861 +		currentMapEditor()->addNewBranch(1);
  1.1862 +}
  1.1863 +
  1.1864 +void Main::editImportAdd()
  1.1865 +{
  1.1866 +	fileLoad (ImportAdd);
  1.1867 +}
  1.1868 +
  1.1869 +void Main::editImportReplace()
  1.1870 +{
  1.1871 +	fileLoad (ImportReplace);
  1.1872 +}
  1.1873 +
  1.1874 +void Main::editSaveBranch()
  1.1875 +{
  1.1876 +	fileSaveAs (PartOfMap);
  1.1877 +}
  1.1878 +
  1.1879 +void Main::editDeleteSelection()
  1.1880 +{
  1.1881 +	if (currentMapEditor())
  1.1882 +		currentMapEditor()->deleteSelection();
  1.1883 +}
  1.1884 +
  1.1885 +void Main::editUpperBranch()
  1.1886 +{
  1.1887 +	if (currentMapEditor())
  1.1888 +		currentMapEditor()->selectUpperBranch();
  1.1889 +}
  1.1890 +
  1.1891 +void Main::editLowerBranch()
  1.1892 +{
  1.1893 +	if (currentMapEditor())
  1.1894 +		currentMapEditor()->selectLowerBranch();
  1.1895 +}
  1.1896 +
  1.1897 +void Main::editLeftBranch()
  1.1898 +{
  1.1899 +	if (currentMapEditor())
  1.1900 +		currentMapEditor()->selectLeftBranch();
  1.1901 +}
  1.1902 +
  1.1903 +void Main::editRightBranch()
  1.1904 +{
  1.1905 +	if (currentMapEditor())
  1.1906 +		currentMapEditor()->selectRightBranch();
  1.1907 +}
  1.1908 +
  1.1909 +void Main::editFirstBranch()
  1.1910 +{
  1.1911 +	if (currentMapEditor())
  1.1912 +		currentMapEditor()->selectFirstBranch();
  1.1913 +}
  1.1914 +
  1.1915 +void Main::editLastBranch()
  1.1916 +{
  1.1917 +	if (currentMapEditor())
  1.1918 +		currentMapEditor()->selectLastBranch();
  1.1919 +}
  1.1920 +
  1.1921 +void Main::editLoadImage()
  1.1922 +{
  1.1923 +	if (currentMapEditor())
  1.1924 +		currentMapEditor()->loadFloatImage();
  1.1925 +}
  1.1926 +
  1.1927 +void Main::editSaveImage(int item)
  1.1928 +{
  1.1929 +	if (currentMapEditor())
  1.1930 +		currentMapEditor()->saveFloatImage(item);
  1.1931 +}
  1.1932 +
  1.1933 +void Main::editToggleFloatExport()
  1.1934 +{
  1.1935 +	if (currentMapEditor())
  1.1936 +		currentMapEditor()->toggleFloatExport();
  1.1937 +}
  1.1938 +
  1.1939 +void Main::formatSelectColor()
  1.1940 +{
  1.1941 +	if (currentMapEditor())
  1.1942 +	{
  1.1943 +		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
  1.1944 +		if ( !col.isValid() ) return;
  1.1945 +		currentMapEditor()->setColor( col );
  1.1946 +		colorChanged( col );
  1.1947 +	}	
  1.1948 +}
  1.1949 +
  1.1950 +void Main::formatPickColor()
  1.1951 +{
  1.1952 +	if (currentMapEditor())
  1.1953 +		colorChanged( currentMapEditor()->pickColor() );
  1.1954 +}
  1.1955 +
  1.1956 +void Main::colorChanged(QColor c)
  1.1957 +{
  1.1958 +    QPixmap pix( 16, 16 );
  1.1959 +    pix.fill( c );
  1.1960 +    actionFormatColor->setIconSet( pix );
  1.1961 +}
  1.1962 +
  1.1963 +void Main::formatColorItem()
  1.1964 +{
  1.1965 +	if (currentMapEditor())
  1.1966 +		currentMapEditor()->colorItem();
  1.1967 +}
  1.1968 +
  1.1969 +void Main::formatColorBranch()
  1.1970 +{
  1.1971 +	if (currentMapEditor())
  1.1972 +		currentMapEditor()->colorBranch();
  1.1973 +}
  1.1974 +
  1.1975 +void Main::formatLinkStyleLine()
  1.1976 +{
  1.1977 +	if (currentMapEditor())
  1.1978 +		currentMapEditor()->setLinkStyle(StyleLine);
  1.1979 +}
  1.1980 +
  1.1981 +void Main::formatLinkStyleParabel()
  1.1982 +{
  1.1983 +	if (currentMapEditor())
  1.1984 +		currentMapEditor()->setLinkStyle(StyleParabel);
  1.1985 +}
  1.1986 +
  1.1987 +void Main::formatLinkStylePolyLine()
  1.1988 +{
  1.1989 +	if (currentMapEditor())
  1.1990 +		currentMapEditor()->setLinkStyle(StylePolyLine);
  1.1991 +}
  1.1992 +
  1.1993 +void Main::formatLinkStylePolyParabel()
  1.1994 +{
  1.1995 +	if (currentMapEditor())
  1.1996 +		currentMapEditor()->setLinkStyle(StylePolyParabel);
  1.1997 +}
  1.1998 +
  1.1999 +void Main::formatSelectBackColor()
  1.2000 +{
  1.2001 +	if (currentMapEditor())
  1.2002 +		currentMapEditor()->selectBackgroundColor();
  1.2003 +}
  1.2004 +
  1.2005 +void Main::formatSelectLinkColor()
  1.2006 +{
  1.2007 +	if (currentMapEditor())
  1.2008 +		currentMapEditor()->selectLinkColor();
  1.2009 +}
  1.2010 +
  1.2011 +void Main::formatToggleLinkColorHint()
  1.2012 +{
  1.2013 +	currentMapEditor()->toggleLinkColorHint();
  1.2014 +}
  1.2015 +
  1.2016 +void Main::formatFrameNone()
  1.2017 +{
  1.2018 +	if (currentMapEditor())
  1.2019 +		currentMapEditor()->setFrame(NoFrame);
  1.2020 +}
  1.2021 +
  1.2022 +void Main::formatFrameRectangle()
  1.2023 +{
  1.2024 +	if (currentMapEditor())
  1.2025 +		currentMapEditor()->setFrame(Rectangle);
  1.2026 +}
  1.2027 +
  1.2028 +void Main::viewZoomReset()
  1.2029 +{
  1.2030 +	if (currentMapEditor())
  1.2031 +	{
  1.2032 +		QWMatrix m;
  1.2033 +		m.reset();
  1.2034 +		currentMapEditor()->setWorldMatrix( m );
  1.2035 +		currentMapEditor()->setViewCenter();
  1.2036 +		currentMapEditor()->adjustCanvasSize();
  1.2037 +	}	
  1.2038 +}
  1.2039 +
  1.2040 +void Main::viewZoomIn()
  1.2041 +{
  1.2042 +	if (currentMapEditor())
  1.2043 +	{
  1.2044 +		QWMatrix m = currentMapEditor()->worldMatrix();
  1.2045 +		m.scale( 1.25, 1.25 );
  1.2046 +		currentMapEditor()->setWorldMatrix( m );
  1.2047 +		currentMapEditor()->setViewCenter();
  1.2048 +		currentMapEditor()->adjustCanvasSize();
  1.2049 +	}	
  1.2050 +}
  1.2051 +
  1.2052 +void Main::viewZoomOut()
  1.2053 +{
  1.2054 +	if (currentMapEditor())
  1.2055 +	{
  1.2056 +		QWMatrix m = currentMapEditor()->worldMatrix();
  1.2057 +		m.scale( 0.8, 0.8 );
  1.2058 +		currentMapEditor()->setWorldMatrix( m );
  1.2059 +		currentMapEditor()->setViewCenter();
  1.2060 +		currentMapEditor()->adjustCanvasSize();
  1.2061 +	}	
  1.2062 +}
  1.2063 +bool Main::settingsPDF()
  1.2064 +{
  1.2065 +	// Default browser is set in constructor
  1.2066 +	bool ok;
  1.2067 +	QString text = QInputDialog::getText(
  1.2068 +		"VYM", tr("Enter path for pdf reader:"), QLineEdit::Normal,
  1.2069 +		settings.readEntry("/vym/mainwindow/readerPDF"), &ok, this );
  1.2070 +	if (ok)
  1.2071 +		settings.writeEntry ("/vym/mainwindow/readerPDF",text);
  1.2072 +	return ok;
  1.2073 +}
  1.2074 +
  1.2075 +
  1.2076 +bool Main::settingsURL()
  1.2077 +{
  1.2078 +	// Default browser is set in constructor
  1.2079 +	bool ok;
  1.2080 +	QString text = QInputDialog::getText(
  1.2081 +		"VYM", tr("Enter path for application to open an URL:"), QLineEdit::Normal,
  1.2082 +		settings.readEntry("/vym/mainwindow/readerURL")
  1.2083 +		, &ok, this );
  1.2084 +	if (ok)
  1.2085 +		settings.writeEntry ("/vym/mainwindow/readerURL",text);
  1.2086 +	return ok;
  1.2087 +}
  1.2088 +
  1.2089 +void Main::windowToggleNoteEditor()
  1.2090 +{
  1.2091 +	if (textEditor->showWithMain() )
  1.2092 +		windowHideNoteEditor();
  1.2093 +	else	
  1.2094 +		windowShowNoteEditor();
  1.2095 +}
  1.2096 +
  1.2097 +void Main::windowShowNoteEditor()
  1.2098 +{
  1.2099 +	textEditor->setShowWithMain(true);
  1.2100 +	textEditor->show();
  1.2101 +	actionViewToggleNoteEditor->setOn (true);
  1.2102 +}
  1.2103 +
  1.2104 +void Main::windowHideNoteEditor()
  1.2105 +{
  1.2106 +	textEditor->setShowWithMain(false);
  1.2107 +	textEditor->hide();
  1.2108 +	actionViewToggleNoteEditor->setOn (false);
  1.2109 +}
  1.2110 +
  1.2111 +void Main::windowNextEditor()
  1.2112 +{
  1.2113 +	if (tabWidget->currentPageIndex() < tabWidget->count())
  1.2114 +		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
  1.2115 +}
  1.2116 +
  1.2117 +void Main::windowPreviousEditor()
  1.2118 +{
  1.2119 +	if (tabWidget->currentPageIndex() >0)
  1.2120 +		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
  1.2121 +}
  1.2122 +
  1.2123 +void Main::standardFlagChanged()
  1.2124 +{
  1.2125 +	currentMapEditor()->toggleStandardFlag(sender()->name());
  1.2126 +}
  1.2127 +
  1.2128 +void Main::testFunction()
  1.2129 +{
  1.2130 +	//textEditor->stackUnder(this);
  1.2131 +	currentMapEditor()->testFunction();
  1.2132 +}
  1.2133 +
  1.2134 +void Main::testShowClipboard()
  1.2135 +{
  1.2136 +	clipboardME->show();
  1.2137 +}
  1.2138 +
  1.2139 +void Main::helpDoc()
  1.2140 +{
  1.2141 +	QString docpath;
  1.2142 +	// default path in SUSE LINUX
  1.2143 +	docpath="/usr/share/doc/packages/vym/doc/vym.pdf";
  1.2144 +
  1.2145 +	if (!QFile (docpath).exists() )
  1.2146 +	{
  1.2147 +		// relative path for easy testing in tarball
  1.2148 +		docpath="doc/vym.pdf";
  1.2149 +		if (!QFile (docpath).exists() )
  1.2150 +		{
  1.2151 +			// relative path for testing while still writing vym.tex
  1.2152 +			docpath="doc/tex/vym.pdf";
  1.2153 +			if (!QFile (docpath).exists() )
  1.2154 +			{
  1.2155 +				QMessageBox::critical(0, 
  1.2156 +				tr("Critcal error"),
  1.2157 +				tr("Couldn't find the documentation\n"
  1.2158 +				"vym.pdf in various places."));
  1.2159 +				return;
  1.2160 +			}	
  1.2161 +		}
  1.2162 +	}
  1.2163 +	
  1.2164 +	Process *pdfProc = new Process();
  1.2165 +	pdfProc->clearArguments();
  1.2166 +	pdfProc->addArgument( settings.readEntry("/vym/mainwindow/readerPDF"));
  1.2167 +	pdfProc->addArgument( docpath);
  1.2168 +
  1.2169 +	if ( !pdfProc->start() ) 
  1.2170 +	{
  1.2171 +		// error handling
  1.2172 +		QMessageBox::critical(0, 
  1.2173 +		tr("Critcal error"),
  1.2174 +		tr("Couldn't find a viewer to read vym.pdf.\n"
  1.2175 +		"Please use Settings->")+tr("Set application to open pdf files"));
  1.2176 +		return;
  1.2177 +	}
  1.2178 +}
  1.2179 +
  1.2180 +
  1.2181 +void Main::helpAbout()
  1.2182 +{
  1.2183 +    static QMessageBox* about = new QMessageBox( "VYM",
  1.2184 +			"<h3>VYM - View Your Mind </h3>"
  1.2185 +			"<p> A tool to put the things you have got in your mind into a map.</p>"
  1.2186 +			"<ul>"
  1.2187 +				"<li> (c) by Uwe Drechsel (vym@InSilmaril.de)</li>"
  1.2188 +				"<li> vym is released under the GPL (Gnu General Public License)"
  1.2189 +				", with one exception (see the file \"LICENSE\"which "
  1.2190 +				"comes with vym). This exception is needed to build vym with QT libraries for proprietary operating systems.</li>"
  1.2191 +				"<li> Project homepage <a href=\"http:/www.InSilmaril.de/vym\">"
  1.2192 +    					"http:/www.InSilmaril.de/vym</a></li>"
  1.2193 +			"<li> Credits " 
  1.2194 +				"<ul>"
  1.2195 +					"<li>Thomas Schraitle for the stylesheet  used for XHTML-export </li>"
  1.2196 +					"<li>Clemens Kraus for stylesheets and script used for HTML-export "
  1.2197 +					"<a href=\"http://www.clemens-kraus.de\">(www.clemens-kraus.de)</a></li>"
  1.2198 +					"<li>Alexander Johannesen for providing stylesheets from his xsiteable project " 
  1.2199 +					"<a href=\"http://www.shelter.nu/xsiteable/xsiteable.html\">(www.shelter.nu/xsiteable/xsiteable.html)</a>. </li>"
  1.2200 +					"<li>Ken Wimer and Olaf Hering for Mac support</li>"
  1.2201 +				"</ul>"
  1.2202 +			"</li>"
  1.2203 +			"<li> Version "  __VYM_VERSION__  "</li>"
  1.2204 +				"<li> Build date "  __BUILD_DATE__"</li>"
  1.2205 +			"</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
  1.2206 +    about->setButtonText( 1, "Dismiss" );
  1.2207 +    about->setMinimumSize(QSize(300,300));
  1.2208 +	about->setIconPixmap (QPixmap(vym_logo_xpm));
  1.2209 +    about->show();
  1.2210 +}
  1.2211 +
  1.2212 +void Main::helpAboutQT()
  1.2213 +{
  1.2214 +	QMessageBox::aboutQt( this, "Qt Application Example" );
  1.2215 +}
  1.2216 +