From 933d3ab7b34500c8edb927505d831fe439ca4253 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Mon, 24 May 2010 17:06:22 +0100
Subject: Dismiss the status editing when the edit loses focus.

Resolves: #358
Resolves: #362

diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index 28df59c..6aeec4a 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -74,9 +74,13 @@ QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Q
 
 	menu_ = new QListWidget();
 	menu_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint );
-	menu_->setAlternatingRowColors(true);		
+	menu_->setAlternatingRowColors(true);
+	menu_->setFocusProxy(statusEdit_);
 
 	connect(menu_, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleItemClicked(QListWidgetItem*)));
+
+	connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
+
 	viewMode();
 }
 
@@ -84,6 +88,15 @@ QtStatusWidget::~QtStatusWidget() {
 	delete menu_;
 }
 
+void QtStatusWidget::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* now) {
+	if (stack_->currentIndex() == 0) {
+		return;
+	}
+	if (now != menu_ && now != statusEdit_) {
+		handleEditCancelled();
+	}
+}
+
 void QtStatusWidget::mousePressEvent(QMouseEvent*) {
 	handleClicked();
 }
diff --git a/Swift/QtUI/QtStatusWidget.h b/Swift/QtUI/QtStatusWidget.h
index 84994d8..4e6aa20 100644
--- a/Swift/QtUI/QtStatusWidget.h
+++ b/Swift/QtUI/QtStatusWidget.h
@@ -37,6 +37,7 @@ namespace Swift {
 			void handleClicked();
 			void handleEditComplete();
 			void handleEditCancelled();
+			void handleApplicationFocusChanged(QWidget* old, QWidget* now);
 		protected slots:
 			virtual void mousePressEvent(QMouseEvent* event);
 			void handleItemClicked(QListWidgetItem* item);
-- 
cgit v0.10.2-6-g49f6