mapeditor.cpp
changeset 390 0e1aeb21cb78
parent 388 3a58c9ef4a18
child 393 053b8645e3e9
     1.1 --- a/mapeditor.cpp	Thu Sep 21 13:48:05 2006 +0000
     1.2 +++ b/mapeditor.cpp	Mon Oct 16 12:42:54 2006 +0000
     1.3 @@ -1,23 +1,5 @@
     1.4  #include "mapeditor.h"
     1.5  
     1.6 -#include <QActionGroup>
     1.7 -#include <QColor>
     1.8 -#include <QColorDialog>
     1.9 -#include <QContextMenuEvent>
    1.10 -#include <QDir>
    1.11 -#include <QDragEnterEvent>
    1.12 -#include <QDropEvent>
    1.13 -#include <QFile>
    1.14 -#include <QInputDialog>
    1.15 -#include <QMessageBox>
    1.16 -#include <QMouseEvent>
    1.17 -#include <QPainter>
    1.18 -#include <QPixmap>
    1.19 -#include <QPrinter>
    1.20 -#include <QResizeEvent>
    1.21 -#include <QTextStream>
    1.22 -
    1.23 -#include <Q3PtrList>
    1.24  #include <q3dragobject.h>
    1.25  #include <q3urloperator.h>
    1.26  #include <q3networkprotocol.h>
    1.27 @@ -49,76 +31,8 @@
    1.28  extern QString tmpVymDir;
    1.29  extern QString clipboardDir;
    1.30  extern bool clipboardEmpty;
    1.31 -extern FlagRowObj *systemFlagsDefault;
    1.32  extern FlagRowObj *standardFlagsDefault;
    1.33  
    1.34 -extern Q3PtrList <QAction> actionListBranches;
    1.35 -
    1.36 -extern QAction *actionFileSave;
    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 *actionEditURL;
    1.48 -extern QAction *actionEditHeading2URL;
    1.49 -extern QAction *actionEditBugzilla2URL;
    1.50 -extern QAction *actionEditFATE2URL;
    1.51 -extern QAction *actionEditOpenVymLink;
    1.52 -extern QAction *actionEditVymLink;
    1.53 -extern QAction *actionEditDeleteVymLink;
    1.54 -extern QAction *actionEditToggleHideExport;
    1.55 -extern QAction *actionEditHeading;
    1.56 -extern QAction *actionEditDelete;
    1.57 -extern QAction *actionEditAddBranch;
    1.58 -extern QAction *actionEditAddBranchAbove;
    1.59 -extern QAction *actionEditAddBranchBelow;
    1.60 -extern QAction *actionEditRemoveBranchHere;
    1.61 -extern QAction *actionEditRemoveChilds;
    1.62 -extern QAction *actionEditImportAdd;
    1.63 -extern QAction *actionEditImportReplace;
    1.64 -extern QAction *actionEditSaveBranch;
    1.65 -extern QAction *actionEditSelectFirst;
    1.66 -extern QAction *actionEditSelectLast;
    1.67 -extern QAction *actionEditLoadImage;
    1.68 -
    1.69 -extern QAction* actionFormatPickColor;
    1.70 -extern QAction* actionFormatColorBranch;
    1.71 -extern QAction* actionFormatColorSubtree;
    1.72 -extern QAction *actionFormatLinkColorHint;
    1.73 -extern QAction *actionFormatBackColor;
    1.74 -extern QAction *actionFormatLinkColor;
    1.75 -
    1.76 -extern QActionGroup* actionGroupModModes;
    1.77 -extern QAction* actionModModeColor;
    1.78 -extern QAction* actionModModeLink;
    1.79 -extern QAction* actionModModeCopy;
    1.80 -
    1.81 -extern QActionGroup *actionGroupFormatFrameTypes;
    1.82 -extern QAction *actionFormatFrameNone;
    1.83 -extern QAction *actionFormatFrameRectangle;
    1.84 -
    1.85 -extern QActionGroup *actionGroupFormatLinkStyles;
    1.86 -extern QAction *actionFormatIncludeImagesVer;
    1.87 -extern QAction *actionFormatIncludeImagesHor;
    1.88 -extern QAction *actionFormatHideLinkUnselected;
    1.89 -extern QAction *actionFormatLinkStyleLine;
    1.90 -extern QAction *actionFormatLinkStyleParabel;
    1.91 -extern QAction *actionFormatLinkStylePolyLine;
    1.92 -extern QAction *actionFormatLinkStylePolyParabel;
    1.93 -
    1.94 -extern QAction *actionViewToggleNoteEditor;
    1.95 -
    1.96 -extern QAction *actionSettingsAutoedit;
    1.97 -extern QAction *actionSettingsAutoselectHeading;
    1.98 -extern QAction *actionSettingsAutoselectText;
    1.99 -extern QAction *actionSettingsUseFlagGroups;
   1.100 -
   1.101  extern QMenu* branchContextMenu;
   1.102  extern QMenu* branchAddContextMenu;
   1.103  extern QMenu* branchRemoveContextMenu;
   1.104 @@ -145,7 +59,7 @@
   1.105  ///////////////////////////////////////////////////////////////////////
   1.106  ///////////////////////////////////////////////////////////////////////
   1.107  MapEditor::MapEditor(
   1.108 -	QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
   1.109 +	QWidget* parent, const char* name, Qt::WFlags f) :
   1.110    Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
   1.111  {
   1.112  	//cout << "Constructor ME "<<this<<endl;
   1.113 @@ -224,8 +138,6 @@
   1.114  
   1.115  	hidemode=HideNone;
   1.116  
   1.117 -	isInteractive=interactive;	// FIXME still needed?
   1.118 -
   1.119  	// Create temporary files
   1.120  	makeTmpDirs();
   1.121  
   1.122 @@ -249,18 +161,14 @@
   1.123    }
   1.124  
   1.125  	//cout <<"Destructor MapEditor\n";
   1.126 -
   1.127 -	// Save Settings
   1.128 -	//settings.writeEntry( "/mapeditor/editmode/autoselect",  );
   1.129 -
   1.130  }
   1.131  
   1.132 -QColor MapEditor::color()
   1.133 +QColor MapEditor::getColor()
   1.134  {
   1.135      return actColor;
   1.136  }
   1.137  
   1.138 -QColor MapEditor::backgroundColor()
   1.139 +QColor MapEditor::getBackgroundColor()
   1.140  {
   1.141      return mapCanvas->backgroundColor();
   1.142  }
   1.143 @@ -493,6 +401,7 @@
   1.144  		NULL);
   1.145  }
   1.146  
   1.147 +/* FIXME not used
   1.148  void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) 
   1.149  {
   1.150  	QString redoSelection="";
   1.151 @@ -506,6 +415,7 @@
   1.152  		comment, 
   1.153  		saveSel);
   1.154  }
   1.155 +*/
   1.156  
   1.157  void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
   1.158  {
   1.159 @@ -833,8 +743,6 @@
   1.160  	mapChanged=true;
   1.161  	mapDefault=false;
   1.162  	mapUnsaved=true;
   1.163 -	actionEditUndo->setEnabled (true);
   1.164 -	actionFileSave->setEnabled (true);
   1.165  	findReset();
   1.166  }
   1.167  
   1.168 @@ -1000,7 +908,7 @@
   1.169  	{
   1.170  		mapChanged=false;
   1.171  		mapUnsaved=false;
   1.172 -		actionFileSave->setEnabled(false);
   1.173 +		updateActions();
   1.174  	}
   1.175  
   1.176  	return returnCode;
   1.177 @@ -1369,6 +1277,14 @@
   1.178  
   1.179  }
   1.180  
   1.181 +bool MapEditor::isRedoAvailable()
   1.182 +{
   1.183 +	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
   1.184 +		return true;
   1.185 +	else	
   1.186 +		return false;
   1.187 +}
   1.188 +
   1.189  void MapEditor::undo()
   1.190  {
   1.191  	blockSaveState=true;
   1.192 @@ -1434,6 +1350,14 @@
   1.193  	updateActions();
   1.194  }
   1.195  
   1.196 +bool MapEditor::isUndoAvailable()
   1.197 +{
   1.198 +	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
   1.199 +		return true;
   1.200 +	else	
   1.201 +		return false;
   1.202 +}
   1.203 +
   1.204  void MapEditor::gotoStep (int i)
   1.205  {
   1.206  	// Restore variables
   1.207 @@ -1744,15 +1668,15 @@
   1.208  			adjustCanvasSize();
   1.209  
   1.210  
   1.211 -			if (actionSettingsAutoedit->isOn() ||
   1.212 -				actionSettingsAutoselectHeading->isOn() )
   1.213 +			if (mainWindow->autoEdit() ||
   1.214 +				mainWindow->autoSelectHeading() )
   1.215  			{
   1.216  				selection->unselect();
   1.217  				selection=newbo;
   1.218  				selection->select();
   1.219 -				if (actionSettingsAutoedit->isOn() )
   1.220 +				if (mainWindow->autoEdit() )
   1.221  					mainWindow->editHeading();
   1.222 -				if (!actionSettingsAutoselectHeading->isOn()
   1.223 +				if (!mainWindow->autoSelectHeading()
   1.224  					)//&& !wasScrolled)  //FIXME wasScrolled was moved to addNewBranchInt
   1.225  				{
   1.226  					selection->unselect();
   1.227 @@ -1787,15 +1711,15 @@
   1.228  
   1.229  		mapCenter->reposition();
   1.230  		adjustCanvasSize();
   1.231 -		if (actionSettingsAutoedit->isOn() ||
   1.232 -			actionSettingsAutoselectHeading->isOn() )
   1.233 +		if (mainWindow->autoEdit() ||
   1.234 +			mainWindow->autoSelectHeading() )
   1.235  		{
   1.236  			selection->unselect();
   1.237  			selection=newbo;
   1.238  			selection->select();
   1.239 -			if (actionSettingsAutoedit->isOn() )
   1.240 +			if (mainWindow->autoEdit() )
   1.241  				mainWindow->editHeading();
   1.242 -			if (!actionSettingsAutoselectHeading->isOn()
   1.243 +			if (!mainWindow->autoSelectHeading()
   1.244  				&& !wasScrolled)
   1.245  			{
   1.246  				selection->unselect();
   1.247 @@ -2345,7 +2269,7 @@
   1.248  			saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f), 
   1.249  				QString("%1 (\"%2\")").arg(r).arg(f),
   1.250  				QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
   1.251 -			bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
   1.252 +			bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
   1.253  			adjustCanvasSize();
   1.254  		}
   1.255  	}	
   1.256 @@ -2571,7 +2495,6 @@
   1.257  			s="Set";
   1.258  		}	
   1.259  		saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection)));	//TODO undoCommand
   1.260 -		actionEditToggleHideExport->setOn (oo->hideInExport());	
   1.261  		updateActions();
   1.262  		mapCenter->reposition();
   1.263  		adjustCanvasSize();
   1.264 @@ -2683,190 +2606,8 @@
   1.265  
   1.266  void MapEditor::updateActions()
   1.267  {
   1.268 -	QAction *a;
   1.269 -	if (getLinkColorHint()==HeadingColor) 
   1.270 -		actionFormatLinkColorHint->setOn(true);
   1.271 -	else	
   1.272 -		actionFormatLinkColorHint->setOn(false);
   1.273 -
   1.274 -	switch (linkstyle)
   1.275 -	{
   1.276 -		case StyleLine: 
   1.277 -			actionFormatLinkStyleLine->setOn(true);
   1.278 -			break;
   1.279 -		case StyleParabel:
   1.280 -			actionFormatLinkStyleParabel->setOn(true);
   1.281 -			break;
   1.282 -		case StylePolyLine:	
   1.283 -			actionFormatLinkStylePolyLine->setOn(true);
   1.284 -			break;
   1.285 -		case StylePolyParabel:	
   1.286 -			actionFormatLinkStylePolyParabel->setOn(true);
   1.287 -			break;
   1.288 -		default:
   1.289 -			break;
   1.290 -	}	
   1.291 -
   1.292 -	QPixmap pix( 16, 16 );
   1.293 -    pix.fill( mapCanvas->backgroundColor() );
   1.294 -    actionFormatBackColor->setIconSet( pix );
   1.295 -    pix.fill( defLinkColor );
   1.296 -    actionFormatLinkColor->setIconSet( pix );
   1.297 -
   1.298 -	actionFileSave->setEnabled( mapUnsaved );
   1.299 -	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
   1.300 -		actionEditUndo->setEnabled( true);
   1.301 -	else	
   1.302 -		actionEditUndo->setEnabled( false);
   1.303 -
   1.304 -	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
   1.305 -		actionEditRedo->setEnabled( true);
   1.306 -	else	
   1.307 -		actionEditRedo->setEnabled( false);
   1.308 -
   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 -//FIXME do this in mainwindow				standardFlagsDefault->setEnabled (false);
   1.435 -
   1.436 -		actionEditCopy->setEnabled (false);	
   1.437 -		actionEditCut->setEnabled (false);	
   1.438 -		actionEditPaste->setEnabled (false);	
   1.439 -		for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.440 -			a->setEnabled(false);
   1.441 -
   1.442 -		actionEditToggleScroll->setEnabled (false);
   1.443 -		actionEditOpenURL->setEnabled (false);
   1.444 -		actionEditOpenVymLink->setEnabled (false);
   1.445 -		actionEditDeleteVymLink->setEnabled (false);	
   1.446 -		actionEditHeading2URL->setEnabled (false);	
   1.447 -		actionEditDelete->setEnabled (false);
   1.448 -		actionEditMoveUp->setEnabled (false);
   1.449 -		actionEditMoveDown->setEnabled (false);
   1.450 -		actionEditToggleHideExport->setEnabled (false);	
   1.451 -	}	
   1.452 +	mainWindow->updateActions();
   1.453 +	// FIXME maybe don't update if blockReposition is set
   1.454  }
   1.455  
   1.456  void MapEditor::updateNoteFlag()
   1.457 @@ -3417,13 +3158,13 @@
   1.458  	// Special case: CTRL is pressed
   1.459  	if (e->state() & Qt::ControlModifier)
   1.460  	{
   1.461 -		if (actionModModeColor->isOn())
   1.462 +		if (mainWindow->getModMode()==ModModeColor)
   1.463  		{
   1.464  				pickingColor=true;
   1.465  				setCursor (pickColorCursor);
   1.466  				return;
   1.467  		} 
   1.468 -		if (actionModModeLink->isOn())
   1.469 +		if (mainWindow->getModMode()==ModModeXLink)
   1.470  		{	
   1.471  			BranchObj *bo_begin=NULL;
   1.472  			if (lmo)
   1.473 @@ -3462,7 +3203,7 @@
   1.474  
   1.475  			// If modMode==copy, then we want to "move" the _new_ object around
   1.476  			// then we need the offset from p to the _old_ selection, because of tmp
   1.477 -			if (actionModModeCopy->isOn() &&
   1.478 +			if (mainWindow->getModMode()==ModModeCopy &&
   1.479  				e->state() & Qt::ControlModifier)
   1.480  			{
   1.481  				if (typeid(*selection)==typeid(BranchObj) )