# HG changeset patch
# User insilmaril
# Date 1168435572 0
# Node ID b7447adddc9ae3e5c2b8384eccd8444904eddc19
# Parent  3988818e808781cb494086a080a2ef3301a94eb5
Fixed relinking of floats undo/redo

diff -r 3988818e8087 -r b7447adddc9a demos/todo.vym
Binary file demos/todo.vym has changed
diff -r 3988818e8087 -r b7447adddc9a historywindow.cpp
--- a/historywindow.cpp	Fri Jan 05 11:17:33 2007 +0000
+++ b/historywindow.cpp	Wed Jan 10 13:26:12 2007 +0000
@@ -37,6 +37,8 @@
 	resize (settings.value ( "/historywindow/geometry/size", QSize(450,600)).toSize());
 	move   (settings.value ( "/historywindow/geometry/pos", QPoint (250,50)).toPoint());
 
+	for (int i=0; i<3; ++i)
+		ui.historyTable->setColumnWidth (i,settings.value( QString("/historywindow/geometry/columnWidth/%1").arg(i),150).toInt());
 /*
 	if (settings.value ( "/historywindow/showWithMain",false).toBool())
 		setShowWithMain(true);
@@ -50,6 +52,8 @@
 	settings.setValue( "/historywindow/geometry/size", size() );
 	settings.setValue( "/historywindow/geometry/pos", pos() );
 	//settings.setValue( "/historywindow/showWithMain",showWithMain());
+	for (int i=0; i<3; ++i)
+		settings.setValue( QString("/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
 }
 
 void HistoryWindow::clearRow(int row)
diff -r 3988818e8087 -r b7447adddc9a mainwindow.cpp
--- a/mainwindow.cpp	Fri Jan 05 11:17:33 2007 +0000
+++ b/mainwindow.cpp	Wed Jan 10 13:26:12 2007 +0000
@@ -2767,8 +2767,10 @@
 
 void Main::editMoveUp()
 {
+	cout << "Main editMoveUp begin\n";
 	if (currentMapEditor())
 	    currentMapEditor()->moveBranchUp();
+	cout << "Main editMoveUp end\n";
 }
 
 void Main::editMoveDown()
@@ -3476,50 +3478,52 @@
 		docname="vym_es.pdf";
 	else	
 		docname="vym.pdf";
+
+	QStringList searchList;
 	QDir docdir;
 	#if defined(Q_OS_MACX)
-		docdir.setPath("./vym.app/Contents");
+		searchList << "./vym.app/Contents";
 	#else
 		// default path in SUSE LINUX
-		docdir.setPath("/usr/share/doc/packages/vym/doc");
+		searchList <<"/usr/share/doc/packages/vym/doc";
 	#endif
 
-	if (!docdir.exists() )
+	searchList << "doc";	// relative path for easy testing in tarball
+	searchList << "doc/tex";	// Easy testing working on vym.tex
+	searchList << "/usr/share/doc/vym";	// Debian
+	searchList << "/usr/share/doc/packages";// Knoppix
+
+	bool found=false;
+	QFile docfile;
+	for (int i=0; i<searchList.count(); ++i)
 	{
-		// relative path for easy testing in tarball
-		docdir.setPath("doc");
-		if (!docdir.exists() )
+		docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
+		if (docfile.exists() )
 		{
-			// relative path for testing while still writing vym.tex
-			docdir.setPath("doc/tex/vym.pdf");
-			if (!docdir.exists() )
-			{
-				// Try yet another one for Knoppix
-				docdir.setPath("/usr/share/doc/packages/vym");
-				if (!docdir.exists() )
-				{
-					QMessageBox::critical(0, 
-					tr("Critcal error"),
-					tr("Couldn't find the documentation\n"
-					"vym.pdf in various directories."));
-					return;
-				}	
-			}	
-		}
+			found=true;
+			break;
+		}	
+
 	}
-	
-	QString docpath=docdir.path()+"/"+docname;
+	if (!found)
+	{
+		QMessageBox::critical(0, 
+			tr("Critcal error"),
+			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
+		return;
+	}	
+
 	QStringList args;
 	Process *pdfProc = new Process();
-	args <<docpath;
-
-	pdfProc->start( settings.value("/mainwindow/readerPDF").toString());
+	args <<docfile.fileName();
+
+	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
 	if ( !pdfProc->waitForStarted() ) 
 	{
 		// error handling
 		QMessageBox::warning(0, 
 			tr("Warning"),
-			tr("Couldn't find a viewer to open %1.\n").arg(docpath)+
+			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
 			tr("Please use Settings->")+tr("Set application to open PDF files"));
 		settingsPDF();	
 		return;
diff -r 3988818e8087 -r b7447adddc9a mapeditor.cpp
--- a/mapeditor.cpp	Fri Jan 05 11:17:33 2007 +0000
+++ b/mapeditor.cpp	Wed Jan 10 13:26:12 2007 +0000
@@ -165,7 +165,7 @@
 	return blockReposition;
 }
 
-QString MapEditor::getName (LinkableMapObj *lmo)
+QString MapEditor::getName (const LinkableMapObj *lmo)
 {
 	QString s;
 	if (!lmo) return QString("Error: NULL has no name!");
@@ -638,6 +638,29 @@
 				}	
 			}	
 		}
+	} else if (com=="linkTo")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj) &&
+					 typeid(*selection) != typeid(FloatImageObj)))
+		{				  
+			api.setError (Aborted,"Type of selection is not a floatimage");
+		} else if (api.checkParamCount(1))
+		{
+			// 0	selectstring of parent
+			s=api.parString(ok,0);
+			LinkableMapObj *dst=mapCenter->findObjBySelect (s);
+			if (dst)
+			{	
+				if (typeid(*dst) == typeid(BranchObj) ||
+				    typeid(*dst) == typeid(MapCenterObj)) 
+					linkTo (dst->getSelectString());
+			} else	
+				api.setError (Aborted,"Destination is not a branch");
+		}
 	} else if (com=="moveBranchUp")
 	{
 		if (!selection)
@@ -1208,10 +1231,12 @@
 
 QPixmap MapEditor::getPixmap()
 {
-/* FIXME getPixmap not ported yet to QT4
 	QRectF mapRect=mapCenter->getTotalBBox();
-	QPixmap pix ();
+	QPixmap pix((int)mapRect.width(),(int)mapRect.height());
+	cout << "w.h="<<(int)mapRect.width()<<","<<(int)mapRect.height()<<endl;
 	QPainter pp (&pix);
+	
+	pp.setRenderHints(renderHints());
 
 	// Don't print the visualisation of selection
 	LinkableMapObj *oldselection=NULL;
@@ -1221,10 +1246,11 @@
 		selection->unselect();
 	}
 
-	pp.setWindow (mapRect);
-
-	//mapScene->drawArea(mapRect, &pp);	// draw scene to painter
-	mapScene->render(&pp);	// draw scene to painter
+	mapScene->render (	&pp, 
+		QRectF(0,0,mapRect.width(),mapRect.height()),
+		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
+
+//	mapScene->render(&pp);	// draw scene to painter
 
 
 
@@ -1236,7 +1262,6 @@
 	}	
 	
 	return pix;
-*/
 }
 
 void MapEditor::setHideTmpMode (HideTmpMode mode)
@@ -1513,6 +1538,7 @@
 
 	mainWindow->updateHistory (undoSet);
 	updateActions();
+	ensureSelectionVisible();
 }
 
 bool MapEditor::isUndoAvailable()
@@ -1689,6 +1715,7 @@
 			QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
 		((OrnamentedObj*)selection)->move2RelPos (x,y);
 		mapCenter->reposition();
+		selection->updateLink();
 	}
 }
 
@@ -1706,6 +1733,7 @@
 		selection->select();
 		saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
 		mapCenter->reposition();
+		scene()->update();
 		ensureSelectionVisible();
 	}
 }
@@ -1724,10 +1752,42 @@
 		selection->select();
 		saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
 		mapCenter->reposition();
+		scene()->update();
 		ensureSelectionVisible();
 	}	
 }
 
+void MapEditor::linkTo(const QString &dstString)
+{
+	BranchObj *dst=(BranchObj*)(mapCenter->findObjBySelect(dstString));
+	if (dst && (typeid(*dst)==typeid (BranchObj) || 
+	            typeid(*dst)==typeid (MapCenterObj)))
+	{			
+		LinkableMapObj *dstPar=dst->getParObj();
+		QString parString=dstPar->getSelectString();
+		if (typeid(*selection)==typeid(FloatImageObj)) 
+		{
+			FloatImageObj *fio=(FloatImageObj*)selection;
+			QString fioPreSelectString=fio->getSelectString();
+			QString fioPreParentSelectString=fio->getParObj()->getSelectString();
+			((BranchObj*)(dst))->addFloatImage (fio);
+			fio->unselect();
+			((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
+			fio=((BranchObj*)(dst))->getLastFloatImage();
+			fio->setRelPos();
+			fio->reposition();
+			selection=(LinkableMapObj*)fio;
+			selection->select();
+			saveState(
+				fio->getSelectString(),
+				QString("linkTo (\"%1\")").arg(fioPreParentSelectString), 
+				fioPreSelectString, 
+				QString ("linkTo (\"%1\")").arg(dstString),
+				QString ("Link floatimage to %1").arg(getName(dst)));
+		}	
+	}
+}
+
 QString MapEditor::getHeading(bool &ok, QPoint &p)
 {
 	if (selection  &&  
@@ -3310,7 +3370,7 @@
 		cout << "canceled!\n";
 	return;
 
-/* Hide hidden stuff temporary, maybe add this as regular function somewhere
+/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
 	if (hidemode==HideNone)
 	{
 		setHideTmpMode (HideExport);
@@ -3593,21 +3653,32 @@
 				( lmo != fo->getParObj())  
 				)
 			{
-				if (typeid(*fo) == typeid(FloatImageObj)) 
+				if (typeid(*fo) == typeid(FloatImageObj) && 
+				( (typeid(*lmo)==typeid(BranchObj) ||
+				  typeid(*lmo)==typeid(MapCenterObj)) ))  
 				{
-					//FIXME undocom for relinking of floats
-
-					//saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
-					FloatImageObj *fio=(FloatImageObj*)(fo);
-					((BranchObj*)(lmo))->addFloatImage (fio);
-					fio->unselect();
-					((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
-					fio=((BranchObj*)(lmo))->getLastFloatImage();
-					fio->setRelPos();
-					fio->reposition();
-					selection=(LinkableMapObj*)(fio);
-					selection->select();
-					movingObj=(MapObj*)(fio);
+
+					// Also save the move which was done so far
+					FloatImageObj *fio=(FloatImageObj*)selection;
+					QString pold=qpointfToString(movingObj_orgRelPos);
+					QString pnow=qpointfToString(fio->getRelPos());
+					saveState(
+						selection,
+						"moveRel "+pold,
+						selection,
+						"moveRel "+pnow,
+						QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
+					fio->getParObj()->requestReposition();
+					mapCenter->reposition();
+
+					cout << "current relPos="<<movingObj_orgRelPos<<endl;
+					linkTo (lmo->getSelectString());
+					cout << "setting movingObj\n";
+					movingObj=(MapObj*)selection;
+					movingObj_orgRelPos=selection->getRelPos();	
+					cout <<"ok 0\n";
+
+					mapCenter->reposition();
 				}	
 			}
 		} else	
@@ -3929,7 +4000,7 @@
                        bo->setHeading(uris.at(i).toString());
 				}
 			}
-		mapCenter->reposition();
+			mapCenter->reposition();
 		}
 	}	
 	event->acceptProposedAction();
diff -r 3988818e8087 -r b7447adddc9a mapeditor.h
--- a/mapeditor.h	Fri Jan 05 11:17:33 2007 +0000
+++ b/mapeditor.h	Wed Jan 10 13:26:12 2007 +0000
@@ -24,7 +24,7 @@
 	bool isRepositionBlocked(); // block while load or undo
 	
 private:
-	QString getName(LinkableMapObj*);	// Get e.g. heading or filename
+	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
 	void makeTmpDirs();		// create temporary directories
     QString saveToDir(const QString&,const QString &,bool, const QPointF &,LinkableMapObj*);
     void saveStateChangingPart (LinkableMapObj *, LinkableMapObj *, const QString &, const QString &);
@@ -93,6 +93,9 @@
     void moveRel (const int &x, const int &y);
     void moveBranchUp();
     void moveBranchDown();
+private:	
+	void linkTo(const QString &);
+public:	
 	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
 	void setHeading(const QString &);
 private:
diff -r 3988818e8087 -r b7447adddc9a tex/vym.changelog
--- a/tex/vym.changelog	Fri Jan 05 11:17:33 2007 +0000
+++ b/tex/vym.changelog	Wed Jan 10 13:26:12 2007 +0000
@@ -1,3 +1,10 @@
+-------------------------------------------------------------------
+Wed Jan 10 19:48:32 CET 2007 - uwe
+
+- Version: 1.8.64
+- Bugfix: move branch up/down calls scene()->update() now => much faster
+- Bugfix: Relinking of floatimages undo/redo
+
 -------------------------------------------------------------------
 Tue Jan  2 19:30:50 CET 2007 - uwedr
 
diff -r 3988818e8087 -r b7447adddc9a tex/vym.tex
--- a/tex/vym.tex	Fri Jan 05 11:17:33 2007 +0000
+++ b/tex/vym.tex	Wed Jan 10 13:26:12 2007 +0000
@@ -147,8 +147,8 @@
 
 \section{Concept of \vym}
 %TODO may add a general introduction here...
-\subsection{Windows: mapeditor and noteeditor}
-\vym uses two windows: an editor for the map itself and another one for
+\subsection{Windows: Mapeditor, Noteeditor, and more}
+\vym uses mainly two windows: an editor for the map itself and another one for
 notes, which are part of the map. Let's call them {\em mapeditor} and
 {\em noteeditor}: 
 \begin{center}
@@ -160,6 +160,10 @@
 information e.g. the content of a email easily in a {\em branch}: Just
 type or copy\&paste it into the {\em noteeditor}. Working with notes is
 explained in \ref{noteeditor}
+ 
+Another window which can be toggled on or off is the {\em history
+window}. It can be used to see the latest actions performed on a map and
+also to undo and redo actions. Details are in \ref{historywindow}.
 
 \subsection{Menus and Context menus}
 On top of each window you find the menubar. The options you find there
@@ -577,9 +581,9 @@
 \end{center}
 
 \subsection{Import and export notes}
-The note is always saved automatically within the \vym file itself.
+The note is always saved automatically within the \vym map itself.
 Nevertheless sometimes it is nice to import a note from an external file
-or write it. Use "File\ra~Import" and "File\ra~Export" to do so. 
+or write it. Use "Map\ra~Import" and "Map\ra~Export" to do so. 
 
 \subsection{Edit and print note}
 Editing works like in any simple texteditor, including undo and redo
@@ -630,17 +634,6 @@
 an email. Normally \vym will generate a new paragraph for each new line.
 This usually is not what you want, so you can choose from the menu
 
-\subsection{Advanced actions}
-\subsubsection*{Edit \ra Convert subsubsections:}
-This turns subsubsections in selected text (or all text, if nothing is
-selected) into linebreaks. This is especially useful for snippets of
-source code.
-
-\subsubsection*{Edit \ra Join Lines:}
-Tries to format text, so that empty lines are used to delimit
-paragraphs. This is done for selected text (or all text, if nothing is
-selected). Especially useful for text like emails, meeting minutes etc.
-
 \section{Hello world}
 This section is about how \vym can interact with other applications.
 Many applications meanwhile can read and write their data using XML, the
@@ -658,7 +651,7 @@
 use \vym to maintain the bookmark mess? To create a new map containing
 your current KDE bookmarks just choose
 \begin{itemize}
-	\item File \ra Import\ra KDE Bookmarks
+	\item Map \ra Import\ra KDE Bookmarks
 \end{itemize}
 
 \subsubsection*{Mind Manager}
@@ -669,7 +662,7 @@
 \href{http://mindjet.de}{http://mindjet.de}} into \vym maps. Notes and
 pictures are not converted at the moment. You can import files with
 \begin{itemize}
-	\item File \ra Import\ra Mind Manager
+	\item Map \ra Import\ra Mind Manager
 \end{itemize}
 
 
@@ -701,7 +694,7 @@
 currently limited, but it possible to export presentations which can be
 opened in Open Office Impress. By selecting
 \begin{itemize}
-	\item File \ra Export\ra Open Office
+	\item Map  \ra Export\ra Open Office
 \end{itemize}
 you get a file dialogue where you can choose the output file and the
 file type:
@@ -740,7 +733,7 @@
 as experimental, there are no options (yet). 
 By selecting
 \begin{itemize}
-	\item File \ra Export\ra \LaTeX 
+	\item Map  \ra Export\ra \LaTeX 
 \end{itemize}
 you will be asked in a file dialog for the name of the output file. This
 file should be included in a \LaTeX document using command  
@@ -753,7 +746,7 @@
 running konquerors via DCOP of the changed file. \vym does not create a
 backup!
 \begin{itemize}
-	\item File \ra Export \ra KDE Bookmarks
+	\item Map \ra Export \ra KDE Bookmarks
 \end{itemize}
 
 
@@ -808,6 +801,9 @@
 
 \section{Advanced Editing}
 
+\subsection{Changing the history: Undo and Redo}
+%FIXME
+
 \subsection{How to deal with Bookmarks} \label{bookmarks}
 \subsubsection*{Open new tabs instead of new windows}
 If you use konqueror as browser, \vym will remember the konqueror which
@@ -939,6 +935,7 @@
 choose between {\em Import Add} and {\em Import Replace}: The imported
 data will be added after the selection resp. replace the selection.
 
+\label{historywindow}
 
 \section{\vym on Mac OS X}
 \subsection{Overview}
@@ -973,7 +970,22 @@
 
 \begin{appendix}
 
-\section{Starting \vym}
+\section{\vym initialization process and configuration}
+\subsection{Configuration file}
+On startup \vym will look for a configuration for user specific settings
+like window positions, toolbars etc. If this file does not already
+exist, it will be created. The file is located in the users home
+directory. The exact position depends on the platform:
+\begin{center}
+\begin{tabular}{cl}
+	{\bf Platform}	& {\bf Configuration file} \\ \hline
+	Linux		& {\tt $\sim$/.config/InSilmaril/vym.conf  } \\
+	Mac OS X	& {\tt /Users/NAME/Library/Preferences/com.insilmaril.vym.plist  } \\
+\end{tabular}
+\end{center}
+The file can be edited manually, or on Mac~OS~X with Property List
+Editor (installed with xtools).
+
 \subsection{Path to ressources}
 \vym will try to find its ressources (images, stylesheets, filters,
 etc.) in the following places:
diff -r 3988818e8087 -r b7447adddc9a version.h
--- a/version.h	Fri Jan 05 11:17:33 2007 +0000
+++ b/version.h	Wed Jan 10 13:26:12 2007 +0000
@@ -4,8 +4,8 @@
 #include <QString>
 
 #define __VYM_NAME "VYM"
-#define __VYM_VERSION "1.8.64"
-#define __VYM_BUILD_DATE "January 2, 2007"
+#define __VYM_VERSION "1.8.65"
+#define __VYM_BUILD_DATE "January 9, 2007"
 
 
 bool checkVersion(const QString &);