mainwindow.cpp
changeset 390 0e1aeb21cb78
parent 389 bb94eec7c8f3
child 393 053b8645e3e9
     1.1 --- a/mainwindow.cpp	Thu Sep 21 13:48:05 2006 +0000
     1.2 +++ b/mainwindow.cpp	Mon Oct 16 12:42:54 2006 +0000
     1.3 @@ -1,24 +1,10 @@
     1.4  #include "mainwindow.h"
     1.5  
     1.6  #include <QtGui>
     1.7 -#include <QPainter>
     1.8 -#include <QPrinter>
     1.9 -#include <QFile>
    1.10 +
    1.11  #include <q3filedialog.h>
    1.12 -#include <QColor>
    1.13 -#include <QColorDialog>
    1.14 -#include <QBitmap>
    1.15 -#include <QInputDialog>
    1.16 -//Added by qt3to4:
    1.17  #include <Q3StrList>
    1.18 -#include <QPixmap>
    1.19 -#include <QCloseEvent>
    1.20 -#include <QShowEvent>
    1.21 -#include <QHideEvent>
    1.22 -#include <Q3PopupMenu>
    1.23 -#include <QActionGroup>
    1.24  #include <Q3PtrList>
    1.25 -//#include <qdatetime.h>			// for random seed
    1.26  
    1.27  #include <iostream>
    1.28  #include <cstdlib>
    1.29 @@ -49,94 +35,17 @@
    1.30  extern FlagRowObj* standardFlagsDefault;
    1.31  extern FlagRowObj* systemFlagsDefault;
    1.32  
    1.33 -extern Q3PtrList <QAction> actionListBranches;
    1.34 -
    1.35 -extern QAction* actionFileSave;
    1.36 -extern QAction* actionFilePrint;
    1.37 -extern QAction* actionEditUndo;
    1.38 -extern QAction* actionEditRedo;
    1.39 -extern QAction *actionEditCopy;
    1.40 -extern QAction *actionEditCut;
    1.41 -extern QAction *actionEditPaste;
    1.42 -extern QAction *actionEditMoveUp;
    1.43 -extern QAction *actionEditMoveDown;
    1.44 -extern QAction *actionEditToggleScroll;
    1.45 -extern QAction* actionEditOpenURL;
    1.46 -extern QAction* actionEditOpenURLTab;
    1.47 -extern QAction* actionEditOpenMultipleURLTabs;
    1.48 -extern QAction* actionEditURL;
    1.49 -extern QAction* actionEditHeading2URL;
    1.50 -extern QAction* actionEditBugzilla2URL;
    1.51 -extern QAction* actionEditFATE2URL;
    1.52 -extern QAction *actionEditOpenVymLink;
    1.53 -extern QAction *actionEditOpenMultipleVymLinks;
    1.54 -extern QAction *actionEditVymLink;
    1.55 -extern QAction *actionEditDeleteVymLink;
    1.56 -extern QAction *actionEditToggleHideExport;
    1.57 -extern QAction *actionEditMapInfo;
    1.58 -extern QAction *actionEditHeading;
    1.59 -extern QAction *actionEditDelete;
    1.60 -extern QAction *actionEditAddBranch;
    1.61 -extern QAction *actionEditAddBranchHere;
    1.62 -extern QAction *actionEditAddBranchAbove;
    1.63 -extern QAction *actionEditAddBranchBelow;
    1.64 -extern QAction *actionEditRemoveBranchKeepChilds;
    1.65 -extern QAction *actionEditRemoveChilds;
    1.66 -extern QAction *actionEditImportAdd;
    1.67 -extern QAction *actionEditImportReplace;
    1.68 -extern QAction *actionEditSaveBranch;
    1.69 -extern QAction *actionEditSelectFirst;
    1.70 -extern QAction *actionEditSelectLast;
    1.71 -extern QAction *actionEditLoadImage;
    1.72 -
    1.73 -extern QAction* actionFormatColor;
    1.74 -extern QAction* actionFormatPickColor;
    1.75 -extern QAction* actionFormatColorBranch;
    1.76 -extern QAction* actionFormatColorSubtree;
    1.77 -extern QAction* actionFormatLinkColorHint;
    1.78 -extern QAction* actionFormatBackColor;
    1.79 -extern QAction* actionFormatLinkColor;
    1.80 -extern QAction *actionFormatIncludeImagesVer;
    1.81 -extern QAction *actionFormatIncludeImagesHor;
    1.82 -
    1.83 -extern QActionGroup* actionGroupModModes;
    1.84 -extern QAction* actionModModeColor;
    1.85 -extern QAction* actionModModeLink;
    1.86 -extern QAction* actionModModeCopy;
    1.87 -
    1.88 -extern QActionGroup *actionGroupFormatFrameTypes;
    1.89 -extern QAction *actionFormatFrameNone;
    1.90 -extern QAction *actionFormatFrameRectangle;
    1.91 -
    1.92 -extern QActionGroup *actionGroupFormatLinkStyles;
    1.93 -extern QAction *actionFormatLinkStyleLine;
    1.94 -extern QAction *actionFormatLinkStyleParabel;
    1.95 -extern QAction *actionFormatLinkStylePolyLine;
    1.96 -extern QAction *actionFormatLinkStylePolyParabel;
    1.97 -extern QAction *actionFormatHideLinkUnselected;
    1.98 -
    1.99 -extern QAction *actionViewToggleNoteEditor;
   1.100 -extern QAction *actionViewToggleHistoryWindow;
   1.101 -
   1.102 -extern QAction* actionSettingsAutoedit;
   1.103 -extern QAction* actionSettingsAutoselectHeading;
   1.104 -extern QAction* actionSettingsAutoselectHeading;
   1.105 -extern QAction* actionSettingsAutoselectText;
   1.106 -extern QAction* actionSettingsUseDelKey;
   1.107 -extern QAction* actionSettingsUseFlagGroups;
   1.108 -extern QAction* actionSettingsUseHideExport;
   1.109 -
   1.110 -extern QMenu* branchContextMenu;
   1.111 -extern QMenu* branchAddContextMenu;
   1.112 -extern QMenu* branchRemoveContextMenu;
   1.113 -extern QMenu* branchLinksContextMenu;
   1.114 -extern QMenu* branchXLinksContextMenuEdit;
   1.115 -extern QMenu* branchXLinksContextMenuFollow;
   1.116 -extern QMenu* floatimageContextMenu;
   1.117 -extern QMenu* canvasContextMenu;
   1.118 -extern QMenu* fileLastMapsMenu;
   1.119 -extern QMenu* fileImportMenu;
   1.120 -extern QMenu* fileExportMenu;
   1.121 +QMenu* branchContextMenu;
   1.122 +QMenu* branchAddContextMenu;
   1.123 +QMenu* branchRemoveContextMenu;
   1.124 +QMenu* branchLinksContextMenu;
   1.125 +QMenu* branchXLinksContextMenuEdit;
   1.126 +QMenu* branchXLinksContextMenuFollow;
   1.127 +QMenu* floatimageContextMenu;
   1.128 +QMenu* canvasContextMenu;
   1.129 +QMenu* fileLastMapsMenu;
   1.130 +QMenu* fileImportMenu;
   1.131 +QMenu* fileExportMenu;
   1.132  
   1.133  
   1.134  extern Settings settings;
   1.135 @@ -252,6 +161,7 @@
   1.136  
   1.137  	// Connect TextEditor, so that we can update flags if text changes
   1.138  	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
   1.139 +	connect (textEditor, SIGNAL (textClosed() ), this, SLOT (updateActions()));
   1.140  
   1.141  	updateGeometry();
   1.142  }
   1.143 @@ -267,9 +177,9 @@
   1.144  	settings.setValue( "/version/version", __VYM_VERSION );
   1.145  	settings.setValue( "/version/builddate", __BUILD_DATE );
   1.146  
   1.147 -	settings.setValue( "/mapeditor/editmode/autoSelectHeading",actionSettingsAutoselectHeading->isOn() );
   1.148 -	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoselectText->isOn() );
   1.149 -	settings.setValue( "/mapeditor/editmode/autoEdit",actionSettingsAutoedit->isOn() );
   1.150 +	settings.setValue( "/mapeditor/editmode/autoSelectHeading",actionSettingsAutoSelectHeading->isOn() );
   1.151 +	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
   1.152 +	settings.setValue( "/mapeditor/editmode/autoEdit",actionSettingsAutoEdit->isOn() );
   1.153  	settings.setValue( "/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   1.154  	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
   1.155  	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
   1.156 @@ -957,19 +867,19 @@
   1.157      connect( a, SIGNAL( triggered() ), this, SLOT( formatFrameRectangle() ) );
   1.158  	actionFormatFrameRectangle=a;
   1.159  
   1.160 -    a = new QAction( tr( "Include images vertically" ),  actionFormatIncludeImagesVer);
   1.161 +    a = new QAction( tr( "Include images vertically" ),  this);
   1.162  	a->setStatusTip ( tr ("Include top and bottom position of images into branch"));
   1.163  	a->setToggleAction(true);
   1.164      connect( a, SIGNAL( triggered() ), this, SLOT( formatIncludeImagesVer() ) );
   1.165  	actionFormatIncludeImagesVer=a;
   1.166  
   1.167 -    a = new QAction( tr( "Include images horizontally" ),  actionFormatIncludeImagesHor );
   1.168 +    a = new QAction( tr( "Include images horizontally" ),  this);
   1.169  	a->setStatusTip ( tr ("Include left and right position of images into branch"));
   1.170  	a->setToggleAction(true);
   1.171      connect( a, SIGNAL( triggered() ), this, SLOT( formatIncludeImagesHor() ) );
   1.172  	actionFormatIncludeImagesHor=a;
   1.173  
   1.174 -    a = new QAction( tr( "Hide link if object is not selected" ), actionFormatHideLinkUnselected);
   1.175 +    a = new QAction( tr( "Hide link if object is not selected" ), this);
   1.176  	a->setStatusTip (tr( "Hide link" ));
   1.177  	a->setToggleAction(true);
   1.178      connect( a, SIGNAL( triggered() ), this, SLOT( formatHideLinkUnselected() ) );
   1.179 @@ -1093,7 +1003,7 @@
   1.180      a->setStatusTip( tr( "Use modifier to draw xLinks" ));
   1.181  	a->setToggleAction(true);
   1.182  	a->addTo (tb);
   1.183 -	actionModModeLink=a;
   1.184 +	actionModModeXLink=a;
   1.185  }
   1.186  
   1.187  // Flag Actions
   1.188 @@ -1438,21 +1348,21 @@
   1.189  	a->setToggleAction(true);
   1.190  	a->setOn ( settings.value ("/mapeditor/editmode/autoEdit",true).toBool());
   1.191  	settingsMenu->addAction (a);
   1.192 -	actionSettingsAutoedit=a;
   1.193 +	actionSettingsAutoEdit=a;
   1.194  
   1.195      a= new QAction( tr( "Select branch after adding it" ), this );
   1.196      a->setStatusTip( tr( "Select branch after adding it" ));
   1.197  	a->setToggleAction(true);
   1.198  	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectHeading",false).toBool() );
   1.199  	settingsMenu->addAction (a);
   1.200 -	actionSettingsAutoselectHeading=a;
   1.201 +	actionSettingsAutoSelectHeading=a;
   1.202  	
   1.203      a= new QAction(tr( "Select existing heading" ), this);
   1.204      a->setStatusTip( tr( "Select heading before editing" ));
   1.205  	a->setToggleAction(true);
   1.206  	a->setOn ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
   1.207  	settingsMenu->addAction (a);
   1.208 -	actionSettingsAutoselectText=a;
   1.209 +	actionSettingsAutoSelectText=a;
   1.210  	
   1.211      a= new QAction( tr( "Delete key" ), this);
   1.212      a->setStatusTip( tr( "Delete key for deleting branches" ));
   1.213 @@ -1739,7 +1649,7 @@
   1.214  void Main::fileNew()
   1.215  {
   1.216  	QString fn="unnamed";
   1.217 -	MapEditor* medit = new MapEditor ( NULL,true);
   1.218 +	MapEditor* medit = new MapEditor ( NULL);
   1.219  	tabWidget->addTab (medit,fn);
   1.220  	tabWidget->showPage(medit);
   1.221  	medit->viewport()->setFocus();
   1.222 @@ -1807,7 +1717,7 @@
   1.223  		// create a new mapeditor in a new tab
   1.224  		if ( lmode==NewMap && (!me || !me->isDefault() ) )
   1.225  		{
   1.226 -			me= new MapEditor ( NULL,true);
   1.227 +			me= new MapEditor ( NULL);
   1.228  			tabWidget->addTab (me,fn);
   1.229  			tabIndex=tabWidget->indexOf (me);
   1.230  			tabWidget->setCurrentPage (tabIndex);
   1.231 @@ -2978,7 +2888,7 @@
   1.232  {
   1.233  	if (currentMapEditor())
   1.234  	{
   1.235 -		QColor col = QColorDialog::getColor( currentMapEditor()->color(), this );
   1.236 +		QColor col = QColorDialog::getColor( currentMapEditor()->getColor(), this );
   1.237  		if ( !col.isValid() ) return;
   1.238  		currentMapEditor()->setColor( col );
   1.239  		colorChanged( col );
   1.240 @@ -3117,14 +3027,6 @@
   1.241  	}	
   1.242  }
   1.243  
   1.244 -void Main::modModeColor()
   1.245 -{
   1.246 -}
   1.247 -
   1.248 -void Main::modModeLink()
   1.249 -{
   1.250 -}
   1.251 -
   1.252  bool Main::settingsPDF()
   1.253  {
   1.254  	// Default browser is set in constructor
   1.255 @@ -3182,6 +3084,222 @@
   1.256  		currentMapEditor()->updateNoteFlag();
   1.257  }
   1.258  
   1.259 +void Main::updateActions()
   1.260 +{
   1.261 +	MapEditor *me=currentMapEditor();
   1.262 +	if (!me) return;
   1.263 +
   1.264 +	// updateActions is also called when NoteEditor is closed
   1.265 +	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
   1.266 +
   1.267 +	QAction *a;
   1.268 +	if (me->getLinkColorHint()==HeadingColor) 
   1.269 +		actionFormatLinkColorHint->setOn(true);
   1.270 +	else	
   1.271 +		actionFormatLinkColorHint->setOn(false);
   1.272 +
   1.273 +	switch (me->getLinkStyle())
   1.274 +	{
   1.275 +		case StyleLine: 
   1.276 +			actionFormatLinkStyleLine->setOn(true);
   1.277 +			break;
   1.278 +		case StyleParabel:
   1.279 +			actionFormatLinkStyleParabel->setOn(true);
   1.280 +			break;
   1.281 +		case StylePolyLine:	
   1.282 +			actionFormatLinkStylePolyLine->setOn(true);
   1.283 +			break;
   1.284 +		case StylePolyParabel:	
   1.285 +			actionFormatLinkStylePolyParabel->setOn(true);
   1.286 +			break;
   1.287 +		default:
   1.288 +			break;
   1.289 +	}	
   1.290 +
   1.291 +	QPixmap pix( 16, 16 );
   1.292 +    pix.fill( me->getBackgroundColor() );
   1.293 +    actionFormatBackColor->setIconSet( pix );
   1.294 +    pix.fill( me->getDefLinkColor() );
   1.295 +    actionFormatLinkColor->setIconSet( pix );
   1.296 +
   1.297 +	actionFileSave->setEnabled( me->isUnsaved() );
   1.298 +	if (me->isUndoAvailable())
   1.299 +		actionEditUndo->setEnabled( true);
   1.300 +	else	
   1.301 +		actionEditUndo->setEnabled( false);
   1.302 +
   1.303 +	if (me->isRedoAvailable())
   1.304 +		actionEditRedo->setEnabled( true);
   1.305 +	else	
   1.306 +		actionEditRedo->setEnabled( false);
   1.307 +
   1.308 +	LinkableMapObj *selection=me->getSelection();
   1.309 +	if (selection)
   1.310 +	{
   1.311 +		if ( (typeid(*selection) == typeid(BranchObj)) || 
   1.312 +			(typeid(*selection) == typeid(MapCenterObj))  )
   1.313 +		{
   1.314 +			BranchObj *bo=(BranchObj*)selection;
   1.315 +			// Take care of links
   1.316 +			if (bo->countXLinks()==0)
   1.317 +			{
   1.318 +				branchXLinksContextMenuEdit->clear();
   1.319 +				branchXLinksContextMenuFollow->clear();
   1.320 +			} else
   1.321 +			{
   1.322 +				BranchObj *bot;
   1.323 +				QString s;
   1.324 +				branchXLinksContextMenuEdit->clear();
   1.325 +				branchXLinksContextMenuFollow->clear();
   1.326 +				for (int i=0; i<=bo->countXLinks();i++)
   1.327 +				{
   1.328 +					bot=bo->XLinkTargetAt(i);
   1.329 +					if (bot)
   1.330 +					{
   1.331 +						s=bot->getHeading();
   1.332 +						if (s.length()>25)
   1.333 +							s=s.left(25)+"...";
   1.334 +						branchXLinksContextMenuFollow->addAction (s);
   1.335 +						branchXLinksContextMenuEdit->addAction (s);
   1.336 +					}	
   1.337 +				}
   1.338 +			}
   1.339 +
   1.340 +			standardFlagsDefault->setEnabled (true);
   1.341 +
   1.342 +			actionEditToggleScroll->setEnabled (true);
   1.343 +			if ( bo->isScrolled() )
   1.344 +				actionEditToggleScroll->setOn(true);
   1.345 +			else	
   1.346 +				actionEditToggleScroll->setOn(false);
   1.347 +
   1.348 +			if ( bo->getURL().isEmpty() )
   1.349 +			{
   1.350 +				actionEditOpenURL->setEnabled (false);
   1.351 +				actionEditOpenURLTab->setEnabled (false);
   1.352 +			}	
   1.353 +			else	
   1.354 +			{
   1.355 +				actionEditOpenURL->setEnabled (true);
   1.356 +				actionEditOpenURLTab->setEnabled (true);
   1.357 +			}
   1.358 +			if ( bo->getVymLink().isEmpty() )
   1.359 +			{
   1.360 +				actionEditOpenVymLink->setEnabled (false);
   1.361 +				actionEditDeleteVymLink->setEnabled (false);
   1.362 +			} else	
   1.363 +			{
   1.364 +				actionEditOpenVymLink->setEnabled (true);
   1.365 +				actionEditDeleteVymLink->setEnabled (true);
   1.366 +			}	
   1.367 +
   1.368 +			if (bo->canMoveBranchUp()) 
   1.369 +				actionEditMoveUp->setEnabled (true);
   1.370 +			else	
   1.371 +				actionEditMoveUp->setEnabled (false);
   1.372 +			if (bo->canMoveBranchDown()) 
   1.373 +				actionEditMoveDown->setEnabled (true);
   1.374 +			else	
   1.375 +				actionEditMoveDown->setEnabled (false);
   1.376 +
   1.377 +
   1.378 +			actionEditToggleHideExport->setEnabled (true);	
   1.379 +			actionEditToggleHideExport->setOn (bo->hideInExport() );	
   1.380 +
   1.381 +			actionEditCopy->setEnabled (true);	
   1.382 +			actionEditCut->setEnabled (true);	
   1.383 +			if (!clipboardEmpty)
   1.384 +				actionEditPaste->setEnabled (true);	
   1.385 +			else	
   1.386 +				actionEditPaste->setEnabled (false);	
   1.387 +			for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.388 +				a->setEnabled(true);
   1.389 +			actionEditDelete->setEnabled (true);
   1.390 +			switch (selection->getFrameType())
   1.391 +			{
   1.392 +				case NoFrame: 
   1.393 +					actionFormatFrameNone->setOn(true);
   1.394 +					break;
   1.395 +				case Rectangle:
   1.396 +					actionFormatFrameRectangle->setOn(true);
   1.397 +					break;
   1.398 +				default:
   1.399 +					break;
   1.400 +			}	
   1.401 +			actionFormatIncludeImagesVer->setOn
   1.402 +				( ((BranchObj*)selection)->getIncludeImagesVer());
   1.403 +			actionFormatIncludeImagesHor->setOn
   1.404 +				( ((BranchObj*)selection)->getIncludeImagesHor());
   1.405 +			actionFormatHideLinkUnselected->setOn
   1.406 +				(selection->getHideLinkUnselected());
   1.407 +		}
   1.408 +		if ( (typeid(*selection) == typeid(FloatImageObj)) )
   1.409 +		{
   1.410 +			FloatObj *fo=(FloatImageObj*)selection;
   1.411 +//FIXME do this in mainwindow					standardFlagsDefault->setEnabled (false);
   1.412 +
   1.413 +			actionEditOpenURL->setEnabled (false);
   1.414 +			actionEditOpenVymLink->setEnabled (false);
   1.415 +			actionEditDeleteVymLink->setEnabled (false);	
   1.416 +			actionEditToggleHideExport->setEnabled (true);	
   1.417 +			actionEditToggleHideExport->setOn (fo->hideInExport() );	
   1.418 +
   1.419 +
   1.420 +			actionEditCopy->setEnabled (true);
   1.421 +			actionEditCut->setEnabled (true);	
   1.422 +			actionEditPaste->setEnabled (false);
   1.423 +			for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.424 +				a->setEnabled(false);
   1.425 +			actionEditDelete->setEnabled (true);
   1.426 +			actionFormatHideLinkUnselected->setOn
   1.427 +				( selection->getHideLinkUnselected());
   1.428 +			actionEditMoveUp->setEnabled (false);
   1.429 +			actionEditMoveDown->setEnabled (false);
   1.430 +		}
   1.431 +
   1.432 +	} else
   1.433 +	{
   1.434 +		actionEditCopy->setEnabled (false);	
   1.435 +		actionEditCut->setEnabled (false);	
   1.436 +		actionEditPaste->setEnabled (false);	
   1.437 +		for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.438 +			a->setEnabled(false);
   1.439 +
   1.440 +		actionEditToggleScroll->setEnabled (false);
   1.441 +		actionEditOpenURL->setEnabled (false);
   1.442 +		actionEditOpenVymLink->setEnabled (false);
   1.443 +		actionEditDeleteVymLink->setEnabled (false);	
   1.444 +		actionEditHeading2URL->setEnabled (false);	
   1.445 +		actionEditDelete->setEnabled (false);
   1.446 +		actionEditMoveUp->setEnabled (false);
   1.447 +		actionEditMoveDown->setEnabled (false);
   1.448 +		actionEditToggleHideExport->setEnabled (false);	
   1.449 +	}	
   1.450 +}
   1.451 +
   1.452 +ModMode Main::getModMode()
   1.453 +{
   1.454 +	if (actionModModeColor->isOn()) return ModModeColor;
   1.455 +	if (actionModModeCopy->isOn()) return ModModeCopy;
   1.456 +	if (actionModModeXLink->isOn()) return ModModeXLink;
   1.457 +	return ModModeNone;
   1.458 +}
   1.459 +
   1.460 +bool Main::autoEdit()
   1.461 +{
   1.462 +	return actionSettingsAutoEdit->isOn();
   1.463 +}
   1.464 +
   1.465 +bool Main::autoSelectHeading()
   1.466 +{
   1.467 +	return actionSettingsAutoSelectHeading->isOn();
   1.468 +}
   1.469 +
   1.470 +bool Main::useFlagGroups()
   1.471 +{
   1.472 +	return actionSettingsUseFlagGroups->isOn();
   1.473 +}
   1.474 +
   1.475  void Main::windowShowNoteEditor()
   1.476  {
   1.477  	textEditor->setShowWithMain(true);