mapeditor.cpp
changeset 486 9c86935835a4
parent 473 8b9cfc26638c
child 491 c58b3973337c
     1.1 --- a/mapeditor.cpp	Wed May 02 15:31:18 2007 +0000
     1.2 +++ b/mapeditor.cpp	Wed May 02 15:31:20 2007 +0000
     1.3 @@ -281,6 +281,93 @@
     1.4  	return s;
     1.5  }
     1.6  
     1.7 +void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
     1.8 +{
     1.9 +	// Main saveState
    1.10 +
    1.11 +	if (blockSaveState) return;
    1.12 +
    1.13 +	/* TODO remove after testing
    1.14 +	*/
    1.15 +	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
    1.16 +	
    1.17 +	int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
    1.18 +	int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
    1.19 +	int curStep=undoSet.readNumEntry ("/history/curStep",0);
    1.20 +	// Find out current undo directory
    1.21 +	if (undosAvail<stepsTotal) undosAvail++;
    1.22 +	curStep++;
    1.23 +	if (curStep>stepsTotal) curStep=1;
    1.24 +	
    1.25 +	QString backupXML="";
    1.26 +	QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
    1.27 +	QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
    1.28 +	QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
    1.29 +
    1.30 +	// Create bakMapDir if not available
    1.31 +	QDir d(bakMapDir);
    1.32 +	if (!d.exists()) 
    1.33 +		makeSubDirs (bakMapDir);
    1.34 +
    1.35 +	// Save depending on how much needs to be saved	
    1.36 +	if (saveSel)
    1.37 +		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
    1.38 +		
    1.39 +	QString undoCommand="";
    1.40 +	if (savemode==UndoCommand)
    1.41 +	{
    1.42 +		undoCommand=undoCom;
    1.43 +	}	
    1.44 +	else if (savemode==PartOfMap )
    1.45 +	{
    1.46 +		undoCommand=undoCom;
    1.47 +		undoCommand.replace ("PATH",bakMapPath);
    1.48 +	}
    1.49 +
    1.50 +	if (!backupXML.isEmpty())
    1.51 +		// Write XML Data to disk
    1.52 +		saveStringToDisk (QString(bakMapPath),backupXML);
    1.53 +
    1.54 +	// We would have to save all actions in a tree, to keep track of 
    1.55 +	// possible redos after a action. Possible, but we are too lazy: forget about redos.
    1.56 +	redosAvail=0;
    1.57 +
    1.58 +	// Write the current state to disk
    1.59 +	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
    1.60 +	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
    1.61 +	undoSet.setEntry ("/history/curStep",QString::number(curStep));
    1.62 +	undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
    1.63 +	undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
    1.64 +	undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
    1.65 +	undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
    1.66 +	undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
    1.67 +	undoSet.setEntry (QString("/history/version"),vymVersion);
    1.68 +	undoSet.writeSettings(histPath);
    1.69 +
    1.70 +	if (debug)
    1.71 +	{
    1.72 +		// TODO remove after testing
    1.73 +		//cout << "          into="<< histPath.toStdString()<<endl;
    1.74 +		cout << "    stepsTotal="<<stepsTotal<<
    1.75 +		", undosAvail="<<undosAvail<<
    1.76 +		", redosAvail="<<redosAvail<<
    1.77 +		", curStep="<<curStep<<endl;
    1.78 +		cout << "    ---------------------------"<<endl;
    1.79 +		cout << "    comment="<<comment.toStdString()<<endl;
    1.80 +		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
    1.81 +		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
    1.82 +		cout << "    redoCom="<<redoCom.toStdString()<<endl;
    1.83 +		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
    1.84 +		if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
    1.85 +		cout << "    ---------------------------"<<endl;
    1.86 +	}
    1.87 +
    1.88 +	mainWindow->updateHistory (undoSet);
    1.89 +	setChanged();
    1.90 +	updateActions();
    1.91 +}
    1.92 +
    1.93 +
    1.94  void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
    1.95  {
    1.96  	// save the selected part of the map, Undo will replace part of map 
    1.97 @@ -355,92 +442,6 @@
    1.98  }
    1.99  
   1.100  		
   1.101 -void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
   1.102 -{
   1.103 -	// Main saveState
   1.104 -
   1.105 -	if (blockSaveState) return;
   1.106 -
   1.107 -	/* TODO remove after testing
   1.108 -	*/
   1.109 -	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
   1.110 -	
   1.111 -	int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
   1.112 -	int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
   1.113 -	int curStep=undoSet.readNumEntry ("/history/curStep",0);
   1.114 -	// Find out current undo directory
   1.115 -	if (undosAvail<stepsTotal) undosAvail++;
   1.116 -	curStep++;
   1.117 -	if (curStep>stepsTotal) curStep=1;
   1.118 -	
   1.119 -	QString backupXML="";
   1.120 -	QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
   1.121 -	QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
   1.122 -	QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
   1.123 -
   1.124 -	// Create bakMapDir if not available
   1.125 -	QDir d(bakMapDir);
   1.126 -	if (!d.exists()) 
   1.127 -		makeSubDirs (bakMapDir);
   1.128 -
   1.129 -	// Save depending on how much needs to be saved	
   1.130 -	if (saveSel)
   1.131 -		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
   1.132 -		
   1.133 -	QString undoCommand="";
   1.134 -	if (savemode==UndoCommand)
   1.135 -	{
   1.136 -		undoCommand=undoCom;
   1.137 -	}	
   1.138 -	else if (savemode==PartOfMap )
   1.139 -	{
   1.140 -		undoCommand=undoCom;
   1.141 -		undoCommand.replace ("PATH",bakMapPath);
   1.142 -	}
   1.143 -
   1.144 -	if (!backupXML.isEmpty())
   1.145 -		// Write XML Data to disk
   1.146 -		saveStringToDisk (QString(bakMapPath),backupXML);
   1.147 -
   1.148 -	// We would have to save all actions in a tree, to keep track of 
   1.149 -	// possible redos after a action. Possible, but we are too lazy: forget about redos.
   1.150 -	redosAvail=0;
   1.151 -
   1.152 -	// Write the current state to disk
   1.153 -	undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
   1.154 -	undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
   1.155 -	undoSet.setEntry ("/history/curStep",QString::number(curStep));
   1.156 -	undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
   1.157 -	undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
   1.158 -	undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
   1.159 -	undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
   1.160 -	undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
   1.161 -	undoSet.setEntry (QString("/history/version"),vymVersion);
   1.162 -	undoSet.writeSettings(histPath);
   1.163 -
   1.164 -	if (debug)
   1.165 -	{
   1.166 -		// TODO remove after testing
   1.167 -		//cout << "          into="<< histPath.toStdString()<<endl;
   1.168 -		cout << "    stepsTotal="<<stepsTotal<<
   1.169 -		", undosAvail="<<undosAvail<<
   1.170 -		", redosAvail="<<redosAvail<<
   1.171 -		", curStep="<<curStep<<endl;
   1.172 -		cout << "    ---------------------------"<<endl;
   1.173 -		cout << "    comment="<<comment.toStdString()<<endl;
   1.174 -		cout << "    undoCom="<<undoCommand.toStdString()<<endl;
   1.175 -		cout << "    undoSel="<<undoSelection.toStdString()<<endl;
   1.176 -		cout << "    redoCom="<<redoCom.toStdString()<<endl;
   1.177 -		cout << "    redoSel="<<redoSelection.toStdString()<<endl;
   1.178 -		if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
   1.179 -		cout << "    ---------------------------"<<endl;
   1.180 -	}
   1.181 -
   1.182 -	mainWindow->updateHistory (undoSet);
   1.183 -	setChanged();
   1.184 -	updateActions();
   1.185 -}
   1.186 -
   1.187  void MapEditor::parseAtom(const QString &atom)
   1.188  {
   1.189  	BranchObj *selb=xelection.getBranch();
   1.190 @@ -830,6 +831,50 @@
   1.191  			s=parser.parString(ok,0);
   1.192  			if (ok) setFrameType (s);
   1.193  		}	
   1.194 +	} else if (com=="setFramePenColor")
   1.195 +	{
   1.196 +		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
   1.197 +		{
   1.198 +			parser.setError (Aborted,"Type of selection does not allow setting of pen color");
   1.199 +		}
   1.200 +		else if (parser.checkParamCount(1))
   1.201 +		{
   1.202 +			QColor c=parser.parColor(ok,0);
   1.203 +			if (ok) setFramePenColor (c);
   1.204 +		}	
   1.205 +	} else if (com=="setFrameBrushColor")
   1.206 +	{
   1.207 +		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
   1.208 +		{
   1.209 +			parser.setError (Aborted,"Type of selection does not allow setting brush color");
   1.210 +		}
   1.211 +		else if (parser.checkParamCount(1))
   1.212 +		{
   1.213 +			QColor c=parser.parColor(ok,0);
   1.214 +			if (ok) setFrameBrushColor (c);
   1.215 +		}	
   1.216 +	} else if (com=="setFramePadding")
   1.217 +	{
   1.218 +		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
   1.219 +		{
   1.220 +			parser.setError (Aborted,"Type of selection does not allow setting frame padding");
   1.221 +		}
   1.222 +		else if (parser.checkParamCount(1))
   1.223 +		{
   1.224 +			x=parser.parInt(ok,0);
   1.225 +			if (ok) setFramePadding(x);
   1.226 +		}	
   1.227 +	} else if (com=="setFrameBorderWidth")
   1.228 +	{
   1.229 +		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
   1.230 +		{
   1.231 +			parser.setError (Aborted,"Type of selection does not allow setting frame border width");
   1.232 +		}
   1.233 +		else if (parser.checkParamCount(1))
   1.234 +		{
   1.235 +			x=parser.parInt(ok,0);
   1.236 +			if (ok) setFrameBorderWidth (x);
   1.237 +		}	
   1.238  	} else if (com=="setMapAuthor")
   1.239  	{
   1.240  		if (parser.checkParamCount(1))
   1.241 @@ -1084,11 +1129,6 @@
   1.242      return mapDefault;
   1.243  }
   1.244  
   1.245 -bool MapEditor::isUnsaved()
   1.246 -{
   1.247 -    return mapUnsaved;
   1.248 -}
   1.249 -
   1.250  bool MapEditor::hasChanged()
   1.251  {
   1.252      return mapChanged;
   1.253 @@ -1116,26 +1156,21 @@
   1.254  	close();
   1.255  }
   1.256  
   1.257 -void MapEditor::setFilePath(QString fname)
   1.258 +void MapEditor::setFilePath(QString fpath, QString destname)
   1.259  {
   1.260 -	setFilePath (fname,fname);
   1.261 -}
   1.262 -
   1.263 -void MapEditor::setFilePath(QString fname, QString destname)
   1.264 -{
   1.265 -	if (fname.isEmpty() || fname=="")
   1.266 +	if (fpath.isEmpty() || fpath=="")
   1.267  	{
   1.268  		filePath="";
   1.269  		fileName="";
   1.270  		destPath="";
   1.271  	} else
   1.272  	{
   1.273 -		filePath=fname;		// becomes absolute path
   1.274 -		fileName=fname;		// gets stripped of path
   1.275 +		filePath=fpath;		// becomes absolute path
   1.276 +		fileName=fpath;		// gets stripped of path
   1.277  		destPath=destname;	// needed for vymlinks
   1.278  
   1.279 -		// If fname is not an absolute path, complete it
   1.280 -		filePath=QDir(fname).absPath();
   1.281 +		// If fpath is not an absolute path, complete it
   1.282 +		filePath=QDir(fpath).absPath();
   1.283  		fileDir=filePath.left (1+filePath.findRev ("/"));
   1.284  
   1.285  		// Set short name, too. Search from behind:
   1.286 @@ -1147,6 +1182,11 @@
   1.287  	}
   1.288  }
   1.289  
   1.290 +void MapEditor::setFilePath(QString fpath)
   1.291 +{
   1.292 +	setFilePath (fpath,fpath);
   1.293 +}
   1.294 +
   1.295  QString MapEditor::getFilePath()
   1.296  {
   1.297  	return filePath;
   1.298 @@ -3442,30 +3482,30 @@
   1.299  	}	
   1.300  }
   1.301  
   1.302 -void MapEditor::setFramePadding (const int &)
   1.303 +void MapEditor::setFramePadding (const int &i)
   1.304  {
   1.305  	BranchObj *bo=xelection.getBranch();
   1.306 -	/*
   1.307  	if (bo)
   1.308  	{
   1.309 -		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
   1.310 -			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
   1.311 -		bo->setFrameBrushColor (c);
   1.312 +		saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
   1.313 +			bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
   1.314 +		bo->setFramePadding (i);
   1.315 +		mapCenter->reposition();
   1.316 +		bo->updateLink();
   1.317  	}	
   1.318 -	*/
   1.319  }
   1.320  
   1.321 -void MapEditor::setFrameBorderWidth(const int &)
   1.322 +void MapEditor::setFrameBorderWidth(const int &i)
   1.323  {
   1.324  	BranchObj *bo=xelection.getBranch();
   1.325 -	/*
   1.326  	if (bo)
   1.327  	{
   1.328 -		saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
   1.329 -			bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
   1.330 -		bo->setFrameBrushColor (c);
   1.331 +		saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
   1.332 +			bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
   1.333 +		bo->setFrameBorderWidth (i);
   1.334 +		mapCenter->reposition();
   1.335 +		bo->updateLink();
   1.336  	}	
   1.337 -	*/
   1.338  }
   1.339  
   1.340  void MapEditor::setIncludeImagesVer(bool b)