# HG changeset patch
# User insilmaril
# Date 1107127547 0
# Node ID e90f5bef70c80b9e3d6483eff9fdadcc7294e898
# Parent  920e6ed5889b53983439c1677c8c063f66fa1c8e
1.6.1 optimized moving of branches, basic linking functions

diff -r 920e6ed5889b -r e90f5bef70c8 Makefile
--- a/Makefile	Sun Jan 30 12:59:10 2005 +0000
+++ b/Makefile	Sun Jan 30 23:25:47 2005 +0000
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: vym
-# Generated by qmake (1.07a) (Qt 3.3.1) on: Tue Jan  4 10:40:21 2005
+# Generated by qmake (1.07a) (Qt 3.3.1) on: Mon Jan 31 00:05:28 2005
 # Project:  vym.pro
 # Template: app
 # Command: $(QMAKE) -o Makefile vym.pro
@@ -12,14 +12,14 @@
 CXX      = g++
 LEX      = flex
 YACC     = yacc
-CFLAGS   = -pipe -O2 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -fmessage-length=0 -Wall -fPIC  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
-CXXFLAGS = -pipe -O2 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -fmessage-length=0 -Wall -fPIC  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
+CFLAGS   = -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
+CXXFLAGS = -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
 LEXFLAGS = 
 YACCFLAGS= -d
 INCPATH  = -I/usr/lib/qt3/mkspecs/linux-g++ -I. -I/usr/include -I$(QTDIR)/include
 LINK     = g++
 LFLAGS   = 
-LIBS     = $(SUBLIBS) -L/usr/lib64/ -L$(QTDIR)/lib64/ -L/usr/X11R6/lib64/ -lqt-mt -lXext -lX11 -lm
+LIBS     = $(SUBLIBS) -L/usr/lib/ -L$(QTDIR)/lib/ -L/usr/X11R6/lib/ -lqt-mt -lXext -lX11 -lm
 AR       = ar cqs
 RANLIB   = 
 MOC      = $(QTDIR)/bin/moc
@@ -56,6 +56,7 @@
 		headingobj.h \
 		imageobj.h \
 		linkablemapobj.h \
+		linkobj.h \
 		mainwindow.h \
 		mapcenterobj.h \
 		mapeditor.h \
@@ -81,6 +82,7 @@
 		headingobj.cpp \
 		imageobj.cpp \
 		linkablemapobj.cpp \
+		linkobj.cpp \
 		main.cpp \
 		mainwindow.cpp \
 		mapcenterobj.cpp \
@@ -106,6 +108,7 @@
 		headingobj.o \
 		imageobj.o \
 		linkablemapobj.o \
+		linkobj.o \
 		main.o \
 		mainwindow.o \
 		mapcenterobj.o \
@@ -196,7 +199,7 @@
 $(MOC): 
 	( cd $(QTDIR)/src/moc && $(MAKE) )
 
-Makefile: vym.pro  /usr/lib/qt3/mkspecs/linux-g++/qmake.conf /usr/lib/qt3/lib64/libqt-mt.prl
+Makefile: vym.pro  /usr/lib/qt3/mkspecs/linux-g++/qmake.conf /usr/lib/qt3/lib/libqt-mt.prl
 	$(QMAKE) -o Makefile vym.pro
 qmake: 
 	@$(QMAKE) -o Makefile vym.pro
@@ -235,6 +238,7 @@
 		floatimageobj.h \
 		linkablemapobj.h \
 		ornamentedobj.h \
+		linkobj.h \
 		floatobj.h \
 		frameobj.h \
 		noteobj.h \
@@ -253,6 +257,7 @@
 		linkablemapobj.h \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		floatimageobj.h \
 		ornamentedobj.h \
@@ -291,7 +296,8 @@
 		misc.h \
 		flagobj.h \
 		imageobj.h \
-		ornamentedobj.h
+		ornamentedobj.h \
+		linkobj.h
 
 floatobj.o: floatobj.cpp floatobj.h \
 		linkablemapobj.h \
@@ -330,9 +336,25 @@
 		imageobj.h \
 		floatimageobj.h \
 		ornamentedobj.h \
+		linkobj.h \
 		floatobj.h \
 		mapcenterobj.h
 
+linkobj.o: linkobj.cpp linkobj.h \
+		branchobj.h \
+		linkablemapobj.h \
+		frameobj.h \
+		noteobj.h \
+		headingobj.h \
+		flagrowobj.h \
+		mapobj.h \
+		misc.h \
+		flagobj.h \
+		imageobj.h \
+		floatimageobj.h \
+		ornamentedobj.h \
+		floatobj.h
+
 main.o: main.cpp settings.h \
 		options.h \
 		mainwindow.h \
@@ -346,6 +368,7 @@
 		findwindow.h \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		floatimageobj.h \
 		linkablemapobj.h \
@@ -394,6 +417,7 @@
 		findwindow.h \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		floatimageobj.h \
 		linkablemapobj.h \
 		ornamentedobj.h \
@@ -410,6 +434,7 @@
 		floatimageobj.h \
 		mapeditor.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		linkablemapobj.h \
 		ornamentedobj.h \
@@ -456,6 +481,7 @@
 		icons/flag-lifebelt.xpm \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		floatimageobj.h \
 		ornamentedobj.h \
 		floatobj.h \
@@ -490,6 +516,7 @@
 		imageobj.h \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		floatimageobj.h \
 		floatobj.h
@@ -533,6 +560,7 @@
 		mapcenterobj.h \
 		mapeditor.h \
 		branchobj.h \
+		linkobj.h \
 		floatimageobj.h \
 		linkablemapobj.h \
 		ornamentedobj.h \
@@ -610,6 +638,7 @@
 		findwindow.h \
 		mapcenterobj.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		floatimageobj.h \
 		linkablemapobj.h \
@@ -627,6 +656,7 @@
 moc_mapeditor.o: moc_mapeditor.cpp  mapeditor.h mapcenterobj.h \
 		misc.h \
 		branchobj.h \
+		linkobj.h \
 		version.h \
 		floatimageobj.h \
 		linkablemapobj.h \
@@ -654,10 +684,9 @@
 
 moc_texteditor.o: moc_texteditor.cpp  texteditor.h 
 
-moc_exporthtmldialog.o: moc_exporthtmldialog.cpp  exporthtmldialog.h showtextdialog.h
+moc_exporthtmldialog.o: moc_exporthtmldialog.cpp  exporthtmldialog.h 
 
-moc_exportxhtmldialog.o: moc_exportxhtmldialog.cpp  exportxhtmldialog.h process.h \
-		showtextdialog.h
+moc_exportxhtmldialog.o: moc_exportxhtmldialog.cpp  exportxhtmldialog.h 
 
 moc_showtextdialog.o: moc_showtextdialog.cpp  showtextdialog.h 
 
@@ -721,6 +750,18 @@
 	-$(DEL_DIR) "$(INSTALL_ROOT)/usr/share/vym/"
 
 
+install_doc: all 
+	@$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/share/doc/packages/vym/" || $(MKDIR) "$(INSTALL_ROOT)/usr/share/doc/packages/vym/"
+	-$(INSTALL_DIR) "doc/CVS" "$(INSTALL_ROOT)/usr/share/doc/packages/vym"
+	-$(INSTALL_FILE) "doc/vym.pdf" "$(INSTALL_ROOT)/usr/share/doc/packages/vym"
+
+
+uninstall_doc: 
+	-$(DEL_FILE) -r "$(INSTALL_ROOT)/usr/share/doc/packages/vym/CVS"
+	-$(DEL_FILE) -r "$(INSTALL_ROOT)/usr/share/doc/packages/vym/vym.pdf"
+	-$(DEL_DIR) "$(INSTALL_ROOT)/usr/share/doc/packages/vym/"
+
+
 install_demo: all 
 	@$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/share/vym/" || $(MKDIR) "$(INSTALL_ROOT)/usr/share/vym/"
 	-$(INSTALL_DIR) "demos" "$(INSTALL_ROOT)/usr/share/vym/"
@@ -731,7 +772,7 @@
 	-$(DEL_DIR) "$(INSTALL_ROOT)/usr/share/vym/"
 
 
-install: install_target install_support install_demo  
+install: install_target install_support install_doc install_demo  
 
-uninstall: uninstall_target uninstall_support uninstall_demo  
+uninstall: uninstall_target uninstall_support uninstall_doc uninstall_demo  
 
diff -r 920e6ed5889b -r e90f5bef70c8 branchobj.cpp
--- a/branchobj.cpp	Sun Jan 30 12:59:10 2005 +0000
+++ b/branchobj.cpp	Sun Jan 30 23:25:47 2005 +0000
@@ -27,6 +27,7 @@
 BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
 {
 //    cout << "Const BranchObj (c)  called from MapCenterObj (c)\n";
+	parObj=NULL;
     canvas=c;
 }
 
@@ -47,16 +48,18 @@
 
 BranchObj::~BranchObj ()
 {
-    //cout << "Destr BranchObj\n";
+//	cout << "Destr BranchObj of "<<this<<endl;
 	// Check, if this branch was the last child to be deleted
 	// If so, unset the scrolled flags
 
 	BranchObj *po=(BranchObj*)(parObj);
+	BranchObj *bo;
 	if (po)
 	{
-		BranchObj *bo=((BranchObj*)(parObj))->getLastBranch();
+		bo=((BranchObj*)(parObj))->getLastBranch();
 		if (!bo) po->unScroll();
 	}
+	clear();
 }
 
 bool BranchObj::operator< ( const BranchObj & other )
@@ -82,17 +85,19 @@
 
 void BranchObj::init () 
 {
-    branch.setAutoDelete (true);
+    branch.setAutoDelete (false);
     floatimage.setAutoDelete (true);
+    link.setAutoDelete (false);
 
-	absPos=getRandPos();
-	absPos+=parObj->getChildPos();
+	if (parObj)
+	{
+		absPos=getRandPos();
+		absPos+=parObj->getChildPos();
+	}
 
     // TODO This should be done in TextObj later
     QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
-//    font.setPointSize(12);
-   heading->setFont(font );
-//    heading->setText(QObject::tr("new branch"));
+    heading->setFont(font );
 
     lastSelectedBranch=-1;
 
@@ -135,8 +140,17 @@
 
 void BranchObj::clear() 
 {
-	branch.clear();
 	floatimage.clear();
+	while (!link.isEmpty())
+		deleteLink (link.first() );
+
+	BranchObj *bo;
+	while (!branch.isEmpty())
+	{
+		bo=branch.first();
+		branch.removeFirst();
+		delete (bo);
+	}
 }
 
 int BranchObj::getNum()
@@ -541,7 +555,7 @@
     for (b=branch.first(); b;b=branch.next() ) 
 		b->moveBy (x,y);
 }
-
+	
 void BranchObj::moveBy (QPoint p)
 {
 	moveBy (p.x(), p.y());
@@ -550,6 +564,14 @@
 
 void BranchObj::positionBBox()
 {
+	// FIXME testing
+	/*
+	QString h=getHeading();
+	if (!h.isEmpty())
+		cout << "BO::positionBBox("<<h<<")\n";
+	else	
+		cout << "BO::positionBBox (noHeading)\n";
+	*/	
 
     heading->positionBBox();
 	systemFlags->positionBBox();
@@ -561,12 +583,16 @@
 	bbox.setY (absPos.y() );
 	bbox.setWidth(w_old);
 	bbox.setHeight(h_old);
-
-
+	
 	setSelBox();
 
 	// set the frame
 	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
+
+	// Update links to other branches
+	LinkObj *l;
+    for (l=link.first(); l; l=link.next() )
+		l->updateLink();
 }
 
 void BranchObj::calcBBoxSize()
@@ -759,6 +785,28 @@
     return s;
 }
 
+void BranchObj::addLink (LinkObj *lo)
+{
+	link.append (lo);
+	
+}
+
+void BranchObj::removeLink (LinkObj *lo)
+{
+	link.remove (lo);
+}
+
+void BranchObj::deleteLink(LinkObj *lo)
+{
+	lo->deactivate();
+	if (!lo->isUsed()) delete (lo);
+}
+
+int BranchObj::countLink()
+{
+	return link.count();
+}
+
 LinkableMapObj* BranchObj::addFloatImage ()
 {
 	FloatImageObj *newfi=new FloatImageObj (canvas,this);
@@ -850,6 +898,17 @@
 	return newbo;
 }
 
+BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
+{
+	branch.append (bo);
+	bo->setParObj (this);
+	bo->depth=depth+1;
+	bo->setLinkStyle (bo->getDefLinkStyle() );
+	if (scrolled) tmpUnscroll();
+	setLastSelectedBranch (bo);
+	return bo;
+}
+
 BranchObj* BranchObj::insertBranch(int pos)
 {
 	savePosInAngle();
@@ -870,11 +929,36 @@
 	return newbo;
 }
 
+BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
+{
+	savePosInAngle();
+	// Add new bo and resort branches
+	bo->angle=pos-0.5;
+	branch.append (bo);
+	bo->setParObj (this);
+	bo->depth=depth+1;
+	bo->setLinkStyle (bo->getDefLinkStyle() );
+	if (scrolled) tmpUnscroll();
+	setLastSelectedBranch (bo);
+	branch.sort();
+	return bo;
+}
+
 void BranchObj::removeBranch(BranchObj* bo)
 {
     // if bo is not in branch remove returns false, we
     // don't care...
-    branch.remove (bo);
+	
+    if (branch.remove (bo))
+		delete (bo);
+	else
+		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
+	requestReposition();
+}
+
+void BranchObj::removeBranchPtr(BranchObj* bo)
+{
+	branch.remove (bo);
 	requestReposition();
 }
 
@@ -939,6 +1023,32 @@
 		return branch.at(i);
 }
 
+BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
+{
+	// Find current parent and 
+	// remove pointer to myself there
+	BranchObj *par=(BranchObj*)(parObj);
+	if (par)
+		par->removeBranchPtr (this);
+	else
+		return NULL;
+
+	if (pos<0)
+	{	
+		// links adds myself as last branch at dst
+		dst->addBranchPtr (this);
+		return this;
+	} else
+	{
+		// inserts me at pos in parent of dst
+		par=(BranchObj*)(dst->getParObj());
+		if (par)
+			return par->insertBranchPtr (this,pos);
+		else
+			return NULL;
+	}	
+}
+
 void BranchObj::alignRelativeTo (QPoint ref)
 {
 /* FIXME testing
diff -r 920e6ed5889b -r e90f5bef70c8 branchobj.h
--- a/branchobj.h	Sun Jan 30 12:59:10 2005 +0000
+++ b/branchobj.h	Sun Jan 30 23:25:47 2005 +0000
@@ -4,6 +4,7 @@
 #include "floatimageobj.h"
 #include "linkablemapobj.h"
 #include "ornamentedobj.h"
+#include "linkobj.h"
 
 class BranchObjPtrList : public QPtrList<BranchObj>
 {
@@ -61,6 +62,10 @@
     virtual void setVymLink (QString);
     virtual QString getVymLink ();
 	virtual QString saveToDir (const QString&,const QString&, const QPoint&);// Save data recursivly to tempdir
+	virtual void addLink (LinkObj*);
+	virtual void removeLink (LinkObj*);
+	virtual void deleteLink (LinkObj*);
+	virtual int countLink ();
 	virtual LinkableMapObj* addFloatImage();
 	virtual LinkableMapObj* addFloatImage(FloatImageObj*);
 	virtual void removeFloatImage(FloatImageObj*);
@@ -72,9 +77,12 @@
 public:	
     virtual BranchObj* addBranch();
     virtual BranchObj* addBranch(BranchObj*);		// makes deep copy of BranchObj
+    virtual BranchObj* addBranchPtr(BranchObj*);	// just adds pointer
     virtual BranchObj* insertBranch(int);
     virtual BranchObj* insertBranch(BranchObj*,int);
+    virtual BranchObj* insertBranchPtr (BranchObj*,int);
     virtual void removeBranch(BranchObj*);  
+    virtual void removeBranchPtr (BranchObj*);  
     virtual void setLastSelectedBranch(BranchObj*);
     virtual BranchObj* getLastSelectedBranch();
     virtual BranchObj* getFirstBranch();
@@ -82,7 +90,7 @@
 	virtual BranchObj* getBranchNum(const uint &);
     virtual BranchObj* moveBranchUp(BranchObj*);
     virtual BranchObj* moveBranchDown(BranchObj*);
-
+    virtual BranchObj* moveBranchTo (BranchObj*, int);
     virtual void alignRelativeTo(const QPoint );
 	virtual void reposition();
 
@@ -98,6 +106,7 @@
 	static BranchObj* itLast;		// iterator for first(), next()
     BranchObjPtrList branch;		// all child branches
 	QPtrList<FloatImageObj> floatimage;	// child images
+	QPtrList<LinkObj> link;			// links to other branches
 public:	
 	float angle;					// used in mainbranch to reorder mainbranches
 protected:	
diff -r 920e6ed5889b -r e90f5bef70c8 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r 920e6ed5889b -r e90f5bef70c8 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Sun Jan 30 12:59:10 2005 +0000
+++ b/linkablemapobj.cpp	Sun Jan 30 23:25:47 2005 +0000
@@ -157,6 +157,7 @@
 
 void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
 {
+	//if (newstyle=style) return;
 	delLink();
 		
 	style=newstyle;
@@ -246,9 +247,10 @@
 			default: 
 				break;	
 		}	
+		updateLink();
 	} else
 	{
-		cout << "Error: ChildObj or parObj == NULL in LinkableMapObj::setLinkStyle\n";
+		qWarning ("Error: ChildObj or parObj == NULL in LinkableMapObj::setLinkStyle\n");
 	}
 }
 
@@ -587,7 +589,6 @@
 
 void LinkableMapObj::reposition()
 {
-cout << "LMO::reposition  ???"<<endl;
 	if (depth==0)
 	{
 		// only calculate the sizes once. If the deepest LMO changes its height,
@@ -633,7 +634,8 @@
 	if (parObj) 
 		parObj->forceReposition(); 
 	else 
-		reposition(); }
+		reposition(); 
+}
 
 bool LinkableMapObj::repositionRequested()
 {
diff -r 920e6ed5889b -r e90f5bef70c8 mapcenterobj.cpp
--- a/mapcenterobj.cpp	Sun Jan 30 12:59:10 2005 +0000
+++ b/mapcenterobj.cpp	Sun Jan 30 23:25:47 2005 +0000
@@ -32,6 +32,7 @@
 
 void MapCenterObj::init () 
 {
+	BranchObj::init();
     orientation=OrientUndef;
     absPos=QPoint (canvas->width()/2, canvas->height()/2);
 
@@ -39,15 +40,9 @@
 	QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
 	heading->setFont(font);
 
-	branch.setAutoDelete (TRUE);
-	floatimage.setAutoDelete (TRUE);
-
 	move (absPos.x(), absPos.y() );
 	depth=0;
 
-	scrolled=false;
-	tmpUnscrolled=false;
-
 	frame->setFrameType (Rectangle);
 }
 
@@ -233,3 +228,4 @@
 {
 	return QDate::currentDate().toString ("yyyy-MM-dd");
 }
+
diff -r 920e6ed5889b -r e90f5bef70c8 mapcenterobj.h
--- a/mapcenterobj.h	Sun Jan 30 12:59:10 2005 +0000
+++ b/mapcenterobj.h	Sun Jan 30 23:25:47 2005 +0000
@@ -2,6 +2,7 @@
 #define MAPCENTEROBJ_H
 
 #include "branchobj.h"
+#include "linkobj.h"
 #include "version.h"
 
 /////////////////////////////////////////////////////////////////////////////
diff -r 920e6ed5889b -r e90f5bef70c8 mapeditor.cpp
--- a/mapeditor.cpp	Sun Jan 30 12:59:10 2005 +0000
+++ b/mapeditor.cpp	Sun Jan 30 23:25:47 2005 +0000
@@ -300,6 +300,8 @@
 		pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); 
 	#endif
 
+	modifierMode=pickColorMode;
+	modifierMode=linkObjectsMode;	// FIXME testing
 
 	pickingColor=false;
 
@@ -1179,11 +1181,6 @@
 
 LinkableMapObj* MapEditor::pasteNoSave()
 {
-	return pasteAtNoSave (-1);
-}
-
-LinkableMapObj* MapEditor::pasteAtNoSave(int pos)
-{
 	// Finish open lineEdits
 	if (lineedit) finishedLineEditNoSave();
 
@@ -1201,13 +1198,7 @@
 				((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
 			}     
 			if (typeid(*selection) == typeid(BranchObj)) 
-				if (pos<0)
 					returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
-				else
-				{
-					BranchObj *par=(BranchObj*)(selection->getParObj());
-					if (par) returnLMO=par->insertBranch((BranchObj*)(fromLMO),pos );
-				}	
 		}
 		
 		if (typeid(*fromLMO) == typeid(FloatImageObj) &&
@@ -1449,7 +1440,7 @@
 	return selection;
 }
 
-bool MapEditor::select (QString s)
+LinkableMapObj* MapEditor::findObj (QString s)
 {
 	LinkableMapObj *lmo=mapCenter;
 	QString part;
@@ -1473,9 +1464,6 @@
 			else
 				if (typ=="fi:")
 					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
-				
-		
-		
 		if (!lmo) break;
 		
 		if (s.contains(","))
@@ -1483,6 +1471,12 @@
 		else	
 			break;
 	}
+	return lmo;
+}
+
+bool MapEditor::select (const QString &s)
+{
+	LinkableMapObj *lmo=findObj(s);
 
 	// Finally select the found object
 	if (lmo)
@@ -1495,8 +1489,6 @@
 		return true;
 	} else
 		return false;
-	
-	
 }
 
 void MapEditor::unselect()
@@ -2654,6 +2646,10 @@
 void MapEditor::testFunction()
 {
 	cout << "MapEditor::testFunction() called\n";
+	if (modifierMode==pickColorMode)
+		modifierMode=linkObjectsMode;
+	else	
+		modifierMode=pickColorMode;
 }
 
 void MapEditor::ensureSelectionVisible()
@@ -2729,12 +2725,34 @@
     QPoint p = inverseWorldMatrix().map(e->pos());
     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
 	
-	// Special case: CTRL is pressed, don't select anything
+	// Special case: CTRL is pressed
 	if (e->state() & QMouseEvent::ControlButton)
 	{
-		pickingColor=true;
-		setCursor (pickColorCursor);
-		return;
+		if (modifierMode==pickColorMode)
+		{
+			if (e->state() & QMouseEvent::ControlButton)
+			{
+				pickingColor=true;
+				setCursor (pickColorCursor);
+				return;
+			}
+		} 
+		if (modifierMode==linkObjectsMode)
+		{	
+			if (lmo && 
+				(typeid(*lmo) == typeid(BranchObj)) || 
+				(typeid(*lmo) == typeid(MapCenterObj))  )
+			{
+				drawingLink=true;
+				linkingObj_src=selection;
+				tmpLink=new LinkObj (mapCanvas);
+				tmpLink->setBegin ( ((BranchObj*)(lmo)) );
+				tmpLink->setEnd   (p);
+				tmpLink->updateLink();
+				tmpLink->setVisibility (true);
+				return;
+			}	
+		}	
 	}
 
     if (lmo) 
@@ -2803,14 +2821,15 @@
 
 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
 {
+	QPoint p = inverseWorldMatrix().map(e->pos());
+
     // Move the selected MapObj
     if ( selection && movingObj) 
     {	
-		QPoint p = inverseWorldMatrix().map(e->pos());
 		
-		// Now move the selection, but add relative position (movingObj_start) 
-		// where selection 
-		// was chosen with mousepointer. (This avoids flickering resp. jumping 
+		// Now move the selection, but add relative position 
+		// (movingObj_start) where selection was chosen with 
+		// mousepointer. (This avoids flickering resp. jumping 
 		// of selection back to absPos)
 		
 		LinkableMapObj *lmosel;
@@ -2923,8 +2942,15 @@
 		return;
 	} // selection && moving_obj
 		
+	// Draw a link from one branch to another
+	if (drawingLink)
+	{
+		 tmpLink->setEnd (p);
+		 tmpLink->updateLink();
+	}	 
+	
     // Move CanvasView 
-    if (!movingObj && !pickingColor) 
+    if (!movingObj && !pickingColor &&!drawingLink) 
 	{
 		QPoint p=e->globalPos();
 		movingVec.setX(-p.x() + movingObj_start.x() );
@@ -2962,6 +2988,27 @@
 		} 
 		return;
 	}
+
+	// Have we been drawing a link?
+	if (drawingLink)
+	{
+		drawingLink=false;
+		// Check if we are over another branch
+		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
+		if (dst && selection) 
+		{	
+			tmpLink->setEnd ( ((BranchObj*)(dst)) );
+			tmpLink->updateLink();
+			tmpLink->activate();
+			
+		} else
+		{
+			delete(tmpLink);
+			tmpLink=NULL;
+		}
+		return;
+	}
+	
     // Have we been moving something?
     if ( selection && movingObj ) 
     {	
@@ -2992,30 +3039,30 @@
 				// TODO we also could check, if dest and src are on same branch,
 				// then it would be sufficient to saveState of this branch
 
-				// FIXME better introduce BO::move  to speed up and keep IDs
-				copy();			// copy selection to clipboard
-				cutNoSave();	// remove selection here
-
-				selection->unselect();	
-				selection=dst;
 				// Modifiers allow to insert above/below dst
 				if (e->state() & QMouseEvent::ShiftButton)
 				{
-					selection=pasteAtNoSave (((BranchObj*)(dst))->getNum());
-					if (selection) selection->select();
-				}	
-				else if (e->state() & QMouseEvent::ControlButton)
-				{
-					selection=pasteAtNoSave (((BranchObj*)(dst))->getNum()+1);
-					if (selection) selection->select();
-				}	
-				else	
-				{
-					selection=pasteNoSave();
-					selection->select();
-					if (dst->getDepth()==0) 
-						((BranchObj*)(selection))->move (savePos);
-				}	
+						((BranchObj*)(selection))->moveBranchTo 
+						(
+							(BranchObj*)(dst),
+							((BranchObj*)(dst))->getNum()
+						);
+					//if (selection) selection->select();
+				} else 
+					if (e->state() & QMouseEvent::ControlButton)
+					{
+						((BranchObj*)(selection))->moveBranchTo 
+						(
+							(BranchObj*)(dst),
+							((BranchObj*)(dst))->getNum()+1
+						);
+						//if (selection) selection->select();
+					} else	
+					{
+						((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
+						if (dst->getDepth()==0) 
+							((BranchObj*)(selection))->move (savePos);
+					}	
 			} 
 			// Draw the original link, before selection was moved around
 			mapCenter->reposition();
@@ -3025,9 +3072,9 @@
 		canvas()->update();
 		movingObj=NULL;		
 	} else 
-	{	// maybe we moved View: set old cursor
+		// maybe we moved View: set old cursor
 		setCursor (ArrowCursor);
-    }
+    
 }
 
 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
diff -r 920e6ed5889b -r e90f5bef70c8 mapeditor.h
--- a/mapeditor.h	Sun Jan 30 12:59:10 2005 +0000
+++ b/mapeditor.h	Sun Jan 30 23:25:47 2005 +0000
@@ -11,6 +11,8 @@
 #include "mapcenterobj.h"
 #include "misc.h"
 
+enum ModifierMode {pickColorMode,linkObjectsMode};
+
 class MapEditor : public QCanvasView , public xmlObj {
     Q_OBJECT
 
@@ -66,7 +68,6 @@
     void copy();		// copy branch to clipboard
 private:	
     LinkableMapObj* pasteNoSave();		// paste clipboard to branch
-    LinkableMapObj* pasteAtNoSave(int);	// paste clipboard to branch at position i
     void cutNoSave();	// cut to clipboard
 public:	
     void paste();		// paste clipboard to branch and backup
@@ -77,7 +78,8 @@
     void addNewBranch(int);			// pos allows to add above/below selection
     void deleteSelection();
 	LinkableMapObj* getSelection();	// returns selection
-	bool select(QString );			// Select 
+	LinkableMapObj* findObj (QString);
+	bool select(const QString &);	// Select 
 	void unselect();				// before changing current noteedit
 	void reselect();				// after  changing current noteedit
 private:	
@@ -152,13 +154,18 @@
 	LinkColorHint linkcolorhint;// use heading color or own color
 	LinkStyle linkstyle;		// default style for links
 
+	ModifierMode modifierMode;	// pick color or link objects?
+
     QCursor handOpenCursor;		// cursor while moving canvas view
 	QCursor pickColorCursor;	// cursor while picking color 
-	bool pickingColor;			// true while picking Color CTRL-LeftButton
+	bool pickingColor;
+	bool drawingLink;			// true while creating a link
+	LinkObj* tmpLink;
 	
     LinkableMapObj* selection;		// select a LinkableMapObj
     LinkableMapObj* selectionLast;	// last selection 
     MapObj* movingObj;				// moving a MapObj
+	MapObj* linkingObj_src;			// part of a link
     QPoint movingObj_start;			// rel. pos of mouse to absPos 
     QPoint movingCont_start;		// inital pos of moving Content or
     QPoint movingVec;				// how far has Content moved
diff -r 920e6ed5889b -r e90f5bef70c8 version.h
--- a/version.h	Sun Jan 30 12:59:10 2005 +0000
+++ b/version.h	Sun Jan 30 23:25:47 2005 +0000
@@ -1,7 +1,7 @@
 #ifndef VERSION_H 
 #define VERSION_H
 
-#define __VYM_VERSION__ "1.6.0"
-#define __BUILD_DATE__ "January 4, 2005"
+#define __VYM_VERSION__ "1.6.1"
+#define __BUILD_DATE__ "January 30, 2005"
 
 #endif
diff -r 920e6ed5889b -r e90f5bef70c8 vym.pro
--- a/vym.pro	Sun Jan 30 12:59:10 2005 +0000
+++ b/vym.pro	Sun Jan 30 23:25:47 2005 +0000
@@ -35,6 +35,7 @@
 	headingobj.h \
 	imageobj.h \
 	linkablemapobj.h \
+	linkobj.h \
 	mainwindow.h \
 	mapcenterobj.h \
 	mapeditor.h \
@@ -60,6 +61,7 @@
 	headingobj.cpp \
 	imageobj.cpp \
 	linkablemapobj.cpp \
+	linkobj.cpp \
 	main.cpp \
 	mainwindow.cpp \
 	mapcenterobj.cpp \
diff -r 920e6ed5889b -r e90f5bef70c8 xml.cpp
--- a/xml.cpp	Sun Jan 30 12:59:10 2005 +0000
+++ b/xml.cpp	Sun Jan 30 23:25:47 2005 +0000
@@ -47,7 +47,7 @@
                     const QString& eName, const QXmlAttributes& atts ) 
 {
     QColor col;
-//	cout << "startElement <"<<eName<<">  state="<<state <<"  laststate="<<laststate<<endl;
+	//cout << "startElement <"<<eName<<">  state="<<state <<"  laststate="<<laststate<<"   loadMode="<<loadMode<<endl;
     if ( state == StateInit && (eName == "vymmap")  ) 
 	{
         state = StateMap;
@@ -171,6 +171,14 @@
 		isVymPart=true;
 		state=StateBranch;
 		LinkableMapObj* lmo=me->getSelection();
+		if (!lmo)
+		{
+			// If a vym part is _loaded_ (not imported), 
+			// selection==lmo==NULL
+			// Treat it like ImportAdd then...
+			loadMode=ImportAdd;
+			lmo=mc;
+		}	
 		if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
 				|| (typeid(*lmo) == typeid(MapCenterObj) ) )
 		{