# HG changeset patch
# User insilmaril
# Date 1268235379 0
# Node ID 0fad394bc330313a9bb75d515891458c9efb911c
# Parent  bfacef6f29c1db4dc838d497b2ca5429ce45537e
Minor fixes

diff -r bfacef6f29c1 -r 0fad394bc330 findwidget.cpp
--- a/findwidget.cpp	Tue Mar 09 13:09:05 2010 +0000
+++ b/findwidget.cpp	Wed Mar 10 15:36:19 2010 +0000
@@ -46,13 +46,17 @@
 
 	nextbutton = new QPushButton;
 	nextbutton->setText (tr("Next","Find widget"));
-	nextbutton->setDefault (true);
-	nextbutton->setShortcut (Qt::Key_Return);
 	connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
 
+	// QAction needed to only activate shortcut while FindWidget has focus
+	QAction *a=new QAction (nextbutton->text(),this);
+	a->setShortcut (Qt::Key_Return);
+	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
+	connect ( a, SIGNAL( triggered() ), this, SLOT( nextPressed() ) );
+	addAction (a);
+
 	showAllButton = new QPushButton;
 	showAllButton->setText (tr("Show all","Find widget"));
-	//connect ( showAllButton, SIGNAL( clicked() ), this, SLOT( showAllPressed() ) );
 	connect ( showAllButton, SIGNAL( clicked() ), mainWindow, SLOT( editOpenFindWidget() ) );
 
 	row2Layout->addWidget (cancelbutton);
diff -r bfacef6f29c1 -r 0fad394bc330 mainwindow.cpp
--- a/mainwindow.cpp	Tue Mar 09 13:09:05 2010 +0000
+++ b/mainwindow.cpp	Wed Mar 10 15:36:19 2010 +0000
@@ -1921,11 +1921,12 @@
 	return NULL;	
 }
 
-VymModel* Main::getModel(uint id) const	//FIXME-2 id not used
+VymModel* Main::getModel(uint id) const	
 {
 	// Used in BugAgent
-	if ( tabWidget->currentPage())
-		return vymViews.at(tabWidget->currentIndex())->getModel();
+	for (int i=0; i<vymViews.count();i++)
+		if (vymViews.at(i)->getModel()->getID()==id)
+			return vymViews.at(i)->getModel();
 	return NULL;	
 }
 
@@ -3961,28 +3962,10 @@
 	if (!currentMapEditor()) return;
 	currentMapEditor()->testFunction1();
 */
-/*
-
-	VymModel *m=currentModel();
-	if (!m) return;
-
-	bool ok;
-	QString text = QInputDialog::getText(
-			"VYM", "Enter Filter:", QLineEdit::Normal,	// FIXME-3 no translation yet
-			m->getSortFilter(), &ok, NULL);
-	if ( ok) 
-		// user entered something and pressed OK
-		m->setSortFilter (text);
-*/
 }
 
 void Main::testFunction2()
 {
-	findResultWidget->setModel (currentModel());
-	findResultWidget->addResult ("Test",currentModel()->getSelectedItem());
-	
-	return;
-
 	if (!currentMapEditor()) return;
 	currentMapEditor()->testFunction2();
 }
diff -r bfacef6f29c1 -r 0fad394bc330 mapeditor.cpp
--- a/mapeditor.cpp	Tue Mar 09 13:09:05 2010 +0000
+++ b/mapeditor.cpp	Wed Mar 10 15:36:19 2010 +0000
@@ -1,7 +1,5 @@
 #include "mapeditor.h"
 
-#include <iostream>	
-
 #include <QObject>
 
 #include "branchitem.h"
@@ -31,7 +29,7 @@
 ///////////////////////////////////////////////////////////////////////
 MapEditor::MapEditor( VymModel *vm) 
 {
-	//cout << "Constructor ME "<<this<<endl;
+	//qDebug() << "Constructor ME "<<this;
 	mapScene= new QGraphicsScene(NULL);
 	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
 
@@ -162,7 +160,7 @@
 
 MapEditor::~MapEditor()
 {
-	//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
+	//qDebug() <<"Destructor MapEditor for "<<model->getMapName();
 	model->unregisterEditor(this);
 }
 
@@ -425,8 +423,8 @@
 
 				if (rt.isNull()) rt=r1;
 				rt=addBBox (r1, rt);
-				//FIXME-2 cout <<"ME: r1="<<r1<<"  "<<cur->getHeadingStd()<<endl;
-				//cout <<"    rt="<<rt<<endl;
+				//qDebug() <<"ME: r1="<<r1<<"  "<<cur->getHeadingStd();
+				//qDebug() <<"    rt="<<rt;
 			}
 		}
 		model->nextBranch(cur,prev);
@@ -472,7 +470,7 @@
 		mapCenter->calcBBoxSizeWithChilds();
 		QRectF totalBBox=mapCenter->getTotalBBox();
 		//QRectF mapRect=totalBBox;
-		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
+		qDebug() << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
 	
 		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
 			totalBBox.width(), totalBBox.height());
@@ -488,7 +486,7 @@
 	{
 		setHideTmpMode (HideNone);
 	}	
-	cout <<"  hidemode="<<hidemode<<endl;
+	qDebug() <<"  hidemode="<<hidemode;
 */
 /*
 	// Toggle hidemode
@@ -499,106 +497,8 @@
 */		
 }
 
-TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
+void MapEditor::autoLayout()
 {
-	// Start with mapcenter, no images allowed at rootItem
-	int i=0;
-	BranchItem *bi=model->getRootItem()->getFirstBranch();
-	TreeItem *found=NULL;
-	while (bi)
-	{
-		found=bi->findMapItem (p, exclude);
-		if (found) return found;
-		i++;
-		bi=model->getRootItem()->getBranchNum(i);
-	}
-	return NULL;
-}
-
-AttributeTable* MapEditor::attributeTable()
-{
-	return attrTable;
-}
-
-void MapEditor::testFunction1()
-{
-	cout << "ME::test1  selected TI="<<model->getSelectedItem()<<endl;
-	model->setExportMode (true);
-
-	/*
-	// Code copied from Qt sources
-	QRectF rect=model->getSelectedBranchObj()->getBBox();
-	int xmargin=50;
-	int ymargin=50;
-
-    qreal width = viewport()->width();
-    qreal height = viewport()->height();
-    QRectF viewRect = matrix().mapRect(rect);
-
-    qreal left = horizontalScrollBar()->value();
-    qreal right = left + width;
-    qreal top = verticalScrollBar()->value();
-    qreal bottom = top + height;
-
-    if (viewRect.left() <= left + xmargin) {
-        // need to scroll from the left
-  //      if (!d->leftIndent)
-            horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
-    }
-    if (viewRect.right() >= right - xmargin) {
-        // need to scroll from the right
-//        if (!d->leftIndent)
-            horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
-    }
-    if (viewRect.top() <= top + ymargin) {
-        // need to scroll from the top
-   //     if (!d->topIndent)
-            verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
-    }
-    if (viewRect.bottom() >= bottom - ymargin) {
-        // need to scroll from the bottom
-//        if (!d->topIndent)
-            verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
-    }
-	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
-	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
-}
-
-*/
-/*
-	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
-	 animation->setDuration(5000);
-	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
-	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
-	 animation->setStartValue(sceneRect() );
-	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
-
-	 animation->start();
-*/	 
-/*
-	QDialog *dia= new QDialog (this);
-	dia->setGeometry (50,50,10,10);
-
-     dia->show();
-     dia ->raise();
-
-	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
-	 animation->setDuration(1000);
-	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
-	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
-	 animation->setStartValue(QRect(50, 50, 10, 10));
-	 animation->setEndValue(QRect(250, 250, 100, 100));
-
-	 animation->start();
- */
-
-}
-	
-void MapEditor::testFunction2()
-{
-	model->setExportMode (false);
-	return;
-
 	// Create list with all bounding polygons
 	QList <LinkableMapObj*> mapobjects;
 	QList <ConvexPolygon> polys; 
@@ -659,19 +559,19 @@
 					if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
 					{
 						collisions++;
-						//cout << "Collision: "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<endl;
+						//qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
 						v=polys.at(j).centroid()-polys.at(i).centroid();
 						// Move also away if centroids are identical
 						if (v.isNull()) 
 						{
-							//cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<endl;
+							//qDebug() << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v;
 							v.setX (rand()%200 -100);
 							v.setY (rand()%200 -100);
-							//cout << v;
+							//qDebug() << v;
 						}
 						v.normalize();
 						v.scale (2);
-						//cout <<  "  v="<<v<<endl;
+						//qDebug() <<  "  v="<<v;
 						vectors[j]=v;
 						vectors[i]=v;
 						vectors[i].invert();
@@ -680,10 +580,10 @@
 			}
 			for (int i=0;i<vectors.size();i++)
 			{
-				//cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
+				//qDebug() << " v="<<vectors[i]<<" "<<headings[i];
 				polys[i].translate (vectors[i]);
 			}
-			cout << "Collisions: "<<collisions<<endl;
+			if (debug) qDebug()<< "Collisions: "<<collisions;
 			//collisions=0;
 		}	
 
@@ -693,9 +593,11 @@
 		{
 			Vector v=polys[i].at(0)-orgpos[i];
 			orients.append (mapobjects[i]->getOrientation());
-			mapobjects[i]->moveBy(v.x(),v.y() );
-			mapobjects[i]->setRelPos();
+		//	mapobjects[i]->moveBy(v.x(),v.y() );
+		//	mapobjects[i]->setRelPos();
+			model->startAnimation ((BranchObj*)mapobjects[i], mapobjects[i]->getAbsPos(), mapobjects[i]->getAbsPos() + v);
 		}	
+		/*
 		model->reposition();	
 		orientationChanged=false;
 		for (int i=0;i<polys.size();i++)
@@ -704,14 +606,116 @@
 				orientationChanged=true;
 				break;
 			}
-		cout << "Final: orientChanged="<<orientationChanged<<endl;
+		*/
 		break;
+
+
 		//orientationChanged=false;
 	} // loop if orientation has changed
 
 	model->emitSelectionChanged();
 }
 
+TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
+{
+	// Start with mapcenter, no images allowed at rootItem
+	int i=0;
+	BranchItem *bi=model->getRootItem()->getFirstBranch();
+	TreeItem *found=NULL;
+	while (bi)
+	{
+		found=bi->findMapItem (p, exclude);
+		if (found) return found;
+		i++;
+		bi=model->getRootItem()->getBranchNum(i);
+	}
+	return NULL;
+}
+
+AttributeTable* MapEditor::attributeTable()
+{
+	return attrTable;
+}
+
+void MapEditor::testFunction1()
+{
+	qDebug()<< "ME::test1  selected TI="<<model->getSelectedItem();
+	model->setExportMode (true);
+
+	/*
+	// Code copied from Qt sources
+	QRectF rect=model->getSelectedBranchObj()->getBBox();
+	int xmargin=50;
+	int ymargin=50;
+
+    qreal width = viewport()->width();
+    qreal height = viewport()->height();
+    QRectF viewRect = matrix().mapRect(rect);
+
+    qreal left = horizontalScrollBar()->value();
+    qreal right = left + width;
+    qreal top = verticalScrollBar()->value();
+    qreal bottom = top + height;
+
+    if (viewRect.left() <= left + xmargin) {
+        // need to scroll from the left
+  //      if (!d->leftIndent)
+            horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
+    }
+    if (viewRect.right() >= right - xmargin) {
+        // need to scroll from the right
+//        if (!d->leftIndent)
+            horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
+    }
+    if (viewRect.top() <= top + ymargin) {
+        // need to scroll from the top
+   //     if (!d->topIndent)
+            verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
+    }
+    if (viewRect.bottom() >= bottom - ymargin) {
+        // need to scroll from the bottom
+//        if (!d->topIndent)
+            verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
+    }
+	qDebug() << "test1:  hor="<<horizontalScrollBar()->value();
+	qDebug() << "test1:  ver="<<verticalScrollBar()->value();
+}
+
+*/
+/*
+	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
+	 animation->setDuration(5000);
+	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
+	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
+	 animation->setStartValue(sceneRect() );
+	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
+
+	 animation->start();
+*/	 
+/*
+	QDialog *dia= new QDialog (this);
+	dia->setGeometry (50,50,10,10);
+
+     dia->show();
+     dia ->raise();
+
+	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
+	 animation->setDuration(1000);
+	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
+	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
+	 animation->setStartValue(QRect(50, 50, 10, 10));
+	 animation->setEndValue(QRect(250, 250, 100, 100));
+
+	 animation->start();
+ */
+
+}
+	
+void MapEditor::testFunction2()
+{
+	autoLayout();
+}
+
 BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
 {
 	if (bi)
@@ -1021,11 +1025,11 @@
 
 void MapEditor::mousePressEvent(QMouseEvent* e)
 {
-//cout << "ME::mousePressed\n"; //FIXME-3
+//qDebug() << "ME::mousePressed\n"; //FIXME-3
 	// Ignore right clicks, these will go to context menus
 	if (e->button() == Qt::RightButton )
 	{
-		//cout << "  ME::ignoring right mouse event...\n";
+		//qDebug() << "  ME::ignoring right mouse event...\n";
 		e->ignore();
 		return;
 	}
@@ -1033,7 +1037,7 @@
 	//Ignore clicks while editing heading
 	if (model->isSelectionBlocked() ) 
 	{
-		//cout << "  ME::ignoring other mouse event...\n";
+		//qDebug() << "  ME::ignoring other mouse event...\n";
 		e->ignore();
 		return;
 	}
@@ -1136,9 +1140,9 @@
     if (lmo) 
 	{	
 	/*
-		cout << "ME::mouse pressed\n";
-		cout << "  lmo="<<lmo<<endl;
-		cout << "   ti="<<ti->getHeadingStd()<<endl;
+		qDebug() << "ME::mouse pressed\n";
+		qDebug() << "  lmo="<<lmo;
+		qDebug() << "   ti="<<ti->getHeadingStd();
 	*/
 		// Select the clicked object
 
@@ -1559,9 +1563,8 @@
 {
 	if (debug) 
 	{
-		cout << "ME p="<<mapToScene (e->pos())<<"  scrollBarPos="<<getScrollBarPos();
-		cout << "  min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
-		cout << endl;
+		qDebug()<< "ME p="<<mapToScene (e->pos())<<"  scrollBarPos="<<getScrollBarPos() <<
+		           "  min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
 	}
 
 
@@ -1617,30 +1620,30 @@
 		if (debug)
 		{
 			foreach (QString format,event->mimeData()->formats()) 
-				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
+				qDebug()<< "MapEditor: Dropped format: "<<qPrintable (format);
 			foreach (QString url,event->mimeData()->urls())
-				cout << "  URL:"<<url.toStdString()<<endl;
+				qDebug()<< "  URL:"<<url;
 			//foreach (QString plain,event->mimeData()->text())
-			//	cout << "   PLAIN:"<<plain.toStdString()<<endl;
+			//	qDebug()<< "   PLAIN:"<<plain;
 			QByteArray ba=event->mimeData()->data("STRING");
 			
 			QString s;
 			s=ba;
-			cout << "  STRING:" <<s.toStdString()<<endl;
+			qDebug() << "  STRING:" <<s;
 
 			ba=event->mimeData()->data("TEXT");
 			s=ba;
-			cout << "    TEXT:" <<s.toStdString()<<endl;
+			qDebug() << "    TEXT:" <<s;
 
 			ba=event->mimeData()->data("COMPOUND_TEXT");
 			s=ba;
-			cout << "   CTEXT:" <<s.toStdString()<<endl;
+			qDebug() << "   CTEXT:" <<s;
 
 			ba=event->mimeData()->data("text/x-moz-url");
 			s=ba;
-			cout << "   x-moz-url:" <<s.toStdString()<<endl;
+			qDebug() << "   x-moz-url:" <<s;
 			foreach (char b,ba)
-				if (b!=0) cout << "b="<<b<<endl;
+				if (b!=0) qDebug() << "b="<<b;
 		}
 
 		if (event->mimeData()->hasImage()) 
@@ -1825,15 +1828,15 @@
 	TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
 
 /* testing
-	cout << "ME::updateData\n";
+	qDebug() << "ME::updateData\n";
 
-	cout << "  ti="<<ti<<endl;
-	cout << "  h="<<ti->getHeading().toStdString()<<endl;
+	qDebug() << "  ti="<<ti;
+	qDebug() << "  h="<<ti->getHeading();
 	*/
 	
 	if (ti->isBranchLikeType())
 	{
-	//	cout << "  ->updating...\n";
+	//	qDebug() << "  ->updating...\n";
 		BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
 		bo->updateData();
 	}
diff -r bfacef6f29c1 -r 0fad394bc330 mapeditor.h
--- a/mapeditor.h	Tue Mar 09 13:09:05 2010 +0000
+++ b/mapeditor.h	Wed Mar 10 15:36:19 2010 +0000
@@ -56,6 +56,7 @@
 	void setAntiAlias (bool);	//!< Set or unset antialiasing
 	void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
 	void setHideTmp (bool);		//!< Hide parts temporary
+	void autoLayout();			//!< Auto layout of map by using collision detection
 public:
 	TreeItem *findMapItem (QPointF p,TreeItem *exclude);	//! find item in map at position p. Ignore item exclude 
 
diff -r bfacef6f29c1 -r 0fad394bc330 tex/vym.changelog
--- a/tex/vym.changelog	Tue Mar 09 13:09:05 2010 +0000
+++ b/tex/vym.changelog	Wed Mar 10 15:36:19 2010 +0000
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Wed Mar 10 16:35:23 CET 2010 - vym@insilmaril.de
+
+- Bugfix: MainWindow::getModel() returns correct model now
+- Bugfix: Better focus handling in FindWidget
+
 -------------------------------------------------------------------
 Tue Mar  9 14:04:10 CET 2010 - vym@insilmaril.de
 
diff -r bfacef6f29c1 -r 0fad394bc330 version.h
--- a/version.h	Tue Mar 09 13:09:05 2010 +0000
+++ b/version.h	Wed Mar 10 15:36:19 2010 +0000
@@ -7,7 +7,7 @@
 #define __VYM_VERSION "1.13.0"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2010-03-09"
+#define __VYM_BUILD_DATE "2010-03-10"
 
 
 bool checkVersion(const QString &);
diff -r bfacef6f29c1 -r 0fad394bc330 vymmodel.cpp
--- a/vymmodel.cpp	Tue Mar 09 13:09:05 2010 +0000
+++ b/vymmodel.cpp	Wed Mar 10 15:36:19 2010 +0000
@@ -1562,6 +1562,7 @@
 	}
 	selti->setNote(s);
 	emitNoteHasChanged(selti);
+	emitDataHasChanged(selti);
 }
 
 QString VymModel::getNote()
@@ -1660,8 +1661,7 @@
 		{
 			i=cur->getNote().indexOf (s,i,cs);
 			if (i>=0) i++;
-			qDebug()<<"i="<<i;
-
+			//qDebug()<<"i="<<i;
 		} 
 		nextBranch(cur,prev);
 	}
@@ -4761,7 +4761,8 @@
 		ap.setTicks (animationTicks);
 		ap.setAnimated (true);
 		bo->setAnimation (ap);
-		animObjList.append( bo );
+		if (!animObjList.contains(bo))
+			animObjList.append( bo );
 		animationTimer->setSingleShot (true);
 		animationTimer->start(animationInterval);
 	}