mapeditor.cpp
changeset 98 58adc2d2ed08
parent 97 0b048b6bb6f4
child 102 dba9303a1a5c
     1.1 --- a/mapeditor.cpp	Thu Apr 21 19:14:38 2005 +0000
     1.2 +++ b/mapeditor.cpp	Wed May 04 20:35:39 2005 +0000
     1.3 @@ -61,6 +61,8 @@
     1.4  extern FlagRowObj *standardFlagsDefault;
     1.5  extern MapEditor *clipboardME;
     1.6  
     1.7 +extern QPtrList <QAction> actionListBranches;
     1.8 +
     1.9  extern QAction *actionFileSave;
    1.10  extern QAction *actionEditUndo;
    1.11  extern QAction *actionEditCopy;
    1.12 @@ -81,6 +83,8 @@
    1.13  extern QAction *actionEditAddBranch;
    1.14  extern QAction *actionEditAddBranchAbove;
    1.15  extern QAction *actionEditAddBranchBelow;
    1.16 +extern QAction *actionEditRemoveBranchHere;
    1.17 +extern QAction *actionEditRemoveChilds;
    1.18  extern QAction *actionEditImportAdd;
    1.19  extern QAction *actionEditImportReplace;
    1.20  extern QAction *actionEditSaveBranch;
    1.21 @@ -1343,7 +1347,6 @@
    1.22  	}				
    1.23  }
    1.24  
    1.25 -
    1.26  void MapEditor::addNewBranch(int pos)
    1.27  {
    1.28  	// Finish open lineEdits
    1.29 @@ -1410,6 +1413,57 @@
    1.30  	}	
    1.31  }
    1.32  
    1.33 +
    1.34 +void MapEditor::addNewBranchHere()
    1.35 +{
    1.36 +	// Finish open lineEdits
    1.37 +	if (lineedit) finishedLineEditNoSave();
    1.38 +
    1.39 +	if (selection  &&  
    1.40 +		 (typeid(*selection) == typeid(BranchObj) ) )
    1.41 +	{
    1.42 +		setChanged();
    1.43 +		saveState(PartOfMap,selection);
    1.44 +
    1.45 +		BranchObj* bo1 = (BranchObj*) (selection);
    1.46 +		bool wasScrolled=false;
    1.47 +		BranchObj *newbo=NULL;
    1.48 +		BranchObj *parbo=(BranchObj*)(selection->getParObj());
    1.49 +		if (parbo)
    1.50 +		{
    1.51 +			// add below selection
    1.52 +			newbo=parbo->insertBranch(bo1->getNum()+1);
    1.53 +		} 
    1.54 +
    1.55 +		LinkableMapObj *oldselection=selection;
    1.56 +		((BranchObj*)(selection))->moveBranchTo (newbo,-1);
    1.57 +
    1.58 +		mapCenter->reposition();
    1.59 +		adjustCanvasSize();
    1.60 +		if (actionSettingsAutoedit->isOn() ||
    1.61 +			actionSettingsAutoselectHeading->isOn() )
    1.62 +		{
    1.63 +			selection->unselect();
    1.64 +			selection=newbo;
    1.65 +			selection->select();
    1.66 +			if (actionSettingsPasteNewHeading->isOn() )
    1.67 +			{
    1.68 +				BranchObj *bo2= (BranchObj*)(selection);
    1.69 +				bo2->setHeading("");
    1.70 +			}	
    1.71 +			if (actionSettingsAutoedit->isOn() )
    1.72 +				editHeading();
    1.73 +			if (!actionSettingsAutoselectHeading->isOn()
    1.74 +				&& !wasScrolled)
    1.75 +			{
    1.76 +				selection->unselect();
    1.77 +				selection=oldselection;
    1.78 +				selection->select();
    1.79 +			}
    1.80 +		}	
    1.81 +	}	
    1.82 +}
    1.83 +
    1.84  void MapEditor::deleteSelection()
    1.85  {
    1.86  	// Finish open lineEdits
    1.87 @@ -1459,7 +1513,7 @@
    1.88  	// Finally select the found object
    1.89  	if (lmo)
    1.90  	{
    1.91 -		if (selection) selection->unselect();
    1.92 +		if (selection) unselect();
    1.93  		selection=lmo;
    1.94  		selection->select();
    1.95  		adjustCanvasSize();
    1.96 @@ -2127,6 +2181,33 @@
    1.97  	
    1.98  }
    1.99  
   1.100 +void MapEditor::removeBranchHere()
   1.101 +{
   1.102 +	if (selection && (typeid(*selection) == typeid(BranchObj) ))
   1.103 +	{		
   1.104 +		setChanged();
   1.105 +		saveState(PartOfMap,selection->getParObj());
   1.106 +		QString sel=selection->getSelectString();
   1.107 +		BranchObj* bo=(BranchObj*)(selection);
   1.108 +		BranchObj* par=(BranchObj*)(bo->getParObj());
   1.109 +		unselect();
   1.110 +		par->removeBranchHere(bo);
   1.111 +		mapCenter->reposition();
   1.112 +		select (sel);
   1.113 +	}	
   1.114 +}
   1.115 +
   1.116 +void MapEditor::removeChilds()
   1.117 +{
   1.118 +	if (selection && (typeid(*selection) == typeid(BranchObj) ))
   1.119 +	{		
   1.120 +		setChanged();
   1.121 +		saveState(PartOfMap,selection->getParObj());
   1.122 +		((BranchObj*)(selection))->removeChilds();
   1.123 +		mapCenter->reposition();
   1.124 +	}	
   1.125 +}
   1.126 +
   1.127  void MapEditor::editMapInfo()
   1.128  {
   1.129  	ExtraInfoDialog dia;
   1.130 @@ -2170,6 +2251,7 @@
   1.131  
   1.132  void MapEditor::updateActions()
   1.133  {
   1.134 +	QAction *a;
   1.135  	if (getLinkColorHint()==HeadingColor) 
   1.136  		actionFormatLinkColorHint->setOn(true);
   1.137  	else	
   1.138 @@ -2242,9 +2324,6 @@
   1.139  				actionEditOpenURL->setEnabled (false);
   1.140  			else	
   1.141  				actionEditOpenURL->setEnabled (true);
   1.142 -			actionEditURL->setEnabled (true);	
   1.143 -			actionEditHeading2URL->setEnabled (true);	
   1.144 -			actionEditBugzilla2URL->setEnabled (true);	
   1.145  
   1.146  			if ( bo->getVymLink().isEmpty() )
   1.147  			{
   1.148 @@ -2255,28 +2334,14 @@
   1.149  				actionEditOpenVymLink->setEnabled (true);
   1.150  				actionEditDeleteVymLink->setEnabled (true);
   1.151  			}	
   1.152 -			actionEditVymLink->setEnabled (true);	
   1.153  
   1.154  			actionEditCopy->setEnabled (true);	
   1.155  			actionEditCut->setEnabled (true);	
   1.156  			actionEditPaste->setEnabled (true);	
   1.157 -			actionEditMoveUp->setEnabled (true);	
   1.158 -			actionEditMoveDown->setEnabled (true);	
   1.159 -			actionEditToggleScroll->setEnabled (true);	
   1.160 -			actionEditHeading->setEnabled (true);
   1.161 +			for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.162 +				a->setEnabled(true);
   1.163  			actionEditDelete->setEnabled (true);
   1.164 -			actionEditAddBranch->setEnabled (true);
   1.165 -			actionEditAddBranchAbove->setEnabled (true);
   1.166 -			actionEditAddBranchBelow->setEnabled (true);
   1.167 -			actionEditImportAdd->setEnabled (true);
   1.168 -			actionEditImportReplace->setEnabled (true);
   1.169 -			actionEditSaveBranch->setEnabled (true);
   1.170 -			actionEditSelectFirst->setEnabled (true);
   1.171 -			actionEditSelectLast->setEnabled (true);
   1.172  			actionEditToggleFloatExport->setEnabled (false);
   1.173 -			actionFormatPickColor->setEnabled (true);
   1.174 -			actionFormatColorBranch->setEnabled (true);
   1.175 -			actionFormatColorSubtree->setEnabled (true);
   1.176  			switch (selection->getFrameType())
   1.177  			{
   1.178  				case NoFrame: 
   1.179 @@ -2294,34 +2359,17 @@
   1.180  			standardFlagsDefault->setEnabled (false);
   1.181  
   1.182  			actionEditOpenURL->setEnabled (false);
   1.183 -			actionEditURL->setEnabled (false);	
   1.184 -			actionEditHeading2URL->setEnabled (false);	
   1.185 -			actionEditBugzilla2URL->setEnabled (false);	
   1.186  			actionEditOpenVymLink->setEnabled (false);
   1.187 -			actionEditVymLink->setEnabled (false);	
   1.188  			actionEditDeleteVymLink->setEnabled (false);	
   1.189  
   1.190  			actionEditCopy->setEnabled (true);
   1.191  			actionEditCut->setEnabled (true);	
   1.192  			actionEditPaste->setEnabled (false);	//FIXME
   1.193 -			actionEditMoveUp->setEnabled (false);	
   1.194 -			actionEditMoveDown->setEnabled (false);	
   1.195 -			actionEditToggleScroll->setEnabled (false);	
   1.196 -			actionEditHeading->setEnabled (false);
   1.197 +			for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.198 +				a->setEnabled(false);
   1.199  			actionEditDelete->setEnabled (true);
   1.200 -			actionEditAddBranch->setEnabled (false);
   1.201 -			actionEditAddBranchAbove->setEnabled (false);
   1.202 -			actionEditAddBranchBelow->setEnabled (false);
   1.203 -			actionEditImportAdd->setEnabled (false);
   1.204 -			actionEditSaveBranch->setEnabled (false);
   1.205 -			actionEditImportReplace->setEnabled (false);
   1.206 -			actionEditSelectFirst->setEnabled (false);
   1.207 -			actionEditSelectLast->setEnabled (false);
   1.208  			actionEditToggleFloatExport->setOn
   1.209  				( ((FloatImageObj*)(selection))->getFloatExport() );
   1.210 -			actionFormatPickColor->setEnabled (false);
   1.211 -			actionFormatColorBranch->setEnabled (false);
   1.212 -			actionFormatColorSubtree->setEnabled (false);
   1.213  		}
   1.214  
   1.215  	} else
   1.216 @@ -2331,29 +2379,15 @@
   1.217  		actionEditCopy->setEnabled (false);	
   1.218  		actionEditCut->setEnabled (false);	
   1.219  		actionEditPaste->setEnabled (false);	
   1.220 -		actionEditMoveUp->setEnabled (false);	
   1.221 -		actionEditMoveDown->setEnabled (false);	
   1.222 -		actionEditToggleScroll->setEnabled (false);	
   1.223 +		for (a=actionListBranches.first();a;a=actionListBranches.next())
   1.224 +			a->setEnabled(false);
   1.225 +
   1.226  		actionEditOpenURL->setEnabled (false);
   1.227 -		actionEditURL->setEnabled (false);	
   1.228  		actionEditOpenVymLink->setEnabled (false);
   1.229 -		actionEditVymLink->setEnabled (false);	
   1.230  		actionEditDeleteVymLink->setEnabled (false);	
   1.231  		actionEditHeading2URL->setEnabled (false);	
   1.232 -		actionEditBugzilla2URL->setEnabled (false);	
   1.233 -		actionEditHeading->setEnabled (false);
   1.234  		actionEditDelete->setEnabled (false);
   1.235 -		actionEditAddBranch->setEnabled (false);
   1.236 -		actionEditAddBranchAbove->setEnabled (false);
   1.237 -		actionEditAddBranchBelow->setEnabled (false);
   1.238 -		actionEditSaveBranch->setEnabled (false);
   1.239 -		actionEditImportReplace->setEnabled (false);
   1.240 -		actionEditSelectFirst->setEnabled (false);
   1.241 -		actionEditSelectLast->setEnabled (false);
   1.242  		actionEditToggleFloatExport->setEnabled (false);
   1.243 -		actionFormatPickColor->setEnabled (false);
   1.244 -		actionFormatColorBranch->setEnabled (false);
   1.245 -		actionFormatColorSubtree->setEnabled (false);
   1.246  	}	
   1.247  }
   1.248  
   1.249 @@ -2716,20 +2750,20 @@
   1.250  void MapEditor::testFunction()
   1.251  {
   1.252  	cout << "MapEditor::testFunction() called\n";
   1.253 -	//cout <<((BranchObj*)(selection))->getSelectString()<<endl;
   1.254 -	QString tmpdir,prefix;
   1.255 -	cout << saveToDir(tmpdir,prefix,true,QPoint(0,0),CompleteMap)<<endl;
   1.256  }
   1.257  
   1.258  void MapEditor::ensureSelectionVisible()
   1.259  {
   1.260 -	LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
   1.261 -	QPoint p;
   1.262 -	if (selection->getOrientation() == OrientLeftOfCenter)
   1.263 -		p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
   1.264 -	else	
   1.265 -		p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
   1.266 -	ensureVisible (p.x(), p.y() );
   1.267 +	if (selection)
   1.268 +	{
   1.269 +		LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
   1.270 +		QPoint p;
   1.271 +		if (selection->getOrientation() == OrientLeftOfCenter)
   1.272 +			p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
   1.273 +		else	
   1.274 +			p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
   1.275 +		ensureVisible (p.x(), p.y() );
   1.276 +	}
   1.277  
   1.278  }
   1.279