--- guidemanager.cpp~	2004-06-03 10:54:22.000000000 +0200
+++ guidemanager.cpp	2004-06-05 12:31:44.837359624 +0200
@@ -18,21 +18,12 @@
 
 /***************************************************************************
  * guides manager for scribus
- * .inspired by tabmanager.cpp and guidemanager.cpp by franz shmid
- * .porting structure and functionality of the tabmanager to the guides
- * .the dialog layout hasn't been modified
- * .first steps in unifying the variable naming schema...
- * .a couple of bugs have been corrected (delete was enabled even when
- *  there were no more guides/tabs)
- * .a couple of enhancements: guides can be "moved"; to delete all the guides,
- *  just keep on clicking on delete; guides can be entered
- *  without using the mouse (click on add, write the measure, press
- *  tab, press space, enter the next guide)
- * .open questions: should i use GetUnit or directly access the array?
- *  why do the VerXXX variables refer to the horizontal guides? Should
- *  i change this? Should the precision depend on the unit used? Why are
- *  all the methods and properties public? Only LocHor and LocVer should
- *  be public! 
+ * - bug 356:
+ *   a: ok
+ *   d: ok
+ *   e: ok
+ *   f: press tab to make it update! (no focus in/out signal for qspinbox)
+ * - added the esc key
  ***************************************************************************/
 
 #include "guidemanager.h"
@@ -185,6 +176,7 @@
 	
 	Cancel = new QPushButton(this, "Cancel");
 	Cancel->setText( tr("Cancel"));
+    Cancel->setAccel(QKeySequence("Esc"));
 	Layout5->addWidget(Cancel);
 	
 	QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
@@ -207,6 +199,8 @@
 	connect(VerDel, SIGNAL(clicked()), this, SLOT(DelVerVal()));
 	connect(VerSpin, SIGNAL(valueChanged(int)), this, SLOT(ChangeVerVal()));
 	connect(Lock, SIGNAL(clicked()), this, SLOT(HandleLock()));
+
+	// connect(VerSpin, SIGNAL(focusIn()), this, SLOT(FocusInEvent()));
 	
 	UpdateHorList();
 	UpdateVerList();
@@ -238,7 +232,10 @@
 	QValueList<double>::Iterator it;
 	it = LocHor.at(selHor);
 	it = LocHor.remove(it);
-	selHor = LocHor.isEmpty() ? -1 : static_cast<int>(LocHor.count() - 1);
+    if (LocHor.isEmpty())
+        selHor = -1;
+    else if (selHor > static_cast<int>(LocHor.count()-1))
+        selHor--;
 	if (selHor == -1)
 		HorDel->setEnabled(false);
 	UpdateHorList();
@@ -249,7 +246,10 @@
 	QValueList<double>::Iterator it;
 	it = LocVer.at(selVer);
 	it = LocVer.remove(it);
-	selVer = LocVer.isEmpty() ? -1 : static_cast<int>(LocVer.count() - 1);
+    if (LocVer.isEmpty())
+        selVer = -1;
+    else if (selVer > static_cast<int>(LocVer.count()-1))
+        selVer--;
 	if (selVer == -1)
 		VerDel->setEnabled(false);
 	UpdateVerList();
@@ -257,6 +257,11 @@
 	
 void GuideManager::AddHorVal()
 {
+    if (HorSpin->hasFocus())
+        HorSpin->clearFocus();
+    if (VerSpin->hasFocus())
+        VerSpin->clearFocus();
+
 	LocHor.prepend(0);
 	selHor = 0;
 	
@@ -266,12 +271,19 @@
 	
 	HorDel->setEnabled(true);
 	UpdateHorList();
+    HorList->setCurrentItem(0);
+    HorList->setSelected(0,true);
 	HorSpin->setFocus();
 	HorSpin->selectAll();
 }
 	
 void GuideManager::AddVerVal()
 {
+    if (HorSpin->hasFocus())
+        HorSpin->clearFocus();
+    if (VerSpin->hasFocus())
+        VerSpin->clearFocus();
+
 	LocVer.prepend(0);
 	selVer = 0;
 	
@@ -281,6 +293,8 @@
 	
 	VerDel->setEnabled(true);
 	UpdateVerList();
+    VerList->setCurrentItem(0);
+    VerList->setSelected(0,true);
 	VerSpin->setFocus();
 	VerSpin->selectAll();
 }
@@ -402,6 +416,7 @@
 
 	if (selHor != -1)
 		HorList->setCurrentItem(selHor);
+
 	HorSpin->setEnabled(selHor != -1 ? true : false);
 	HorSpin->setValue(selHor != -1 ? (LocHor[selHor] * UmReFaktor * 10000.0) / 10000.0 : 0);
 
@@ -414,10 +429,10 @@
 	disconnect(VerList, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selVerIte(QListBoxItem*)));
 	disconnect(VerSpin, SIGNAL(valueChanged(int)), this, SLOT(ChangeVerVal()));
 	
-	QString tmp;
-	
 	VerList->clear();
 	
+	QString tmp;
+	
 	for (uint i = 0; i < LocVer.count(); ++ i)
 		VerList->insertItem(tmp.setNum(qRound(LocVer[i] * UmReFaktor * 10000.0) / 10000.0, 'f', 4) +
 					 GetUnit());
