From a5853e88be12bce08b84f76452e5d2576cf9d10b Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sat, 4 Jul 2009 22:13:56 +0100
Subject: Notify chat tabs even if the parent tabset has focus. issue#150.


diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index e6e0100..6328156 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -106,7 +106,7 @@ void QtChatWindow::convertToMUC() {
 
 void QtChatWindow::qAppFocusChanged(QWidget *old, QWidget *now) {
 	Q_UNUSED(old);
-	if (now == this || now == messageLog_ || now == input_) {
+	if (isWidgetSelected()) {
 		onAllMessagesRead();
 	}
 	
@@ -133,7 +133,7 @@ void QtChatWindow::updateTitleWithUnreadCount() {
 }
 
 void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
-	if (isActiveWindow()) {
+	if (isWidgetSelected()) {
 		onAllMessagesRead();
 	}
 
@@ -156,7 +156,7 @@ void QtChatWindow::addMessage(const String &message, const String &senderName, b
 }
 
 void QtChatWindow::addErrorMessage(const String& errorMessage) {
-	if (isActiveWindow()) {
+	if (isWidgetSelected()) {
 		onAllMessagesRead();
 	}
 
@@ -169,7 +169,7 @@ void QtChatWindow::addErrorMessage(const String& errorMessage) {
 }
 
 void QtChatWindow::addSystemMessage(const String& message) {
-	if (isActiveWindow()) {
+	if (isWidgetSelected()) {
 		onAllMessagesRead();
 	}
 
diff --git a/Swift/QtUI/QtTabbable.cpp b/Swift/QtUI/QtTabbable.cpp
new file mode 100644
index 0000000..8473529
--- /dev/null
+++ b/Swift/QtUI/QtTabbable.cpp
@@ -0,0 +1,12 @@
+#include "QtTabbable.h"
+
+#include <QApplication>
+
+namespace Swift {
+
+bool QtTabbable::isWidgetSelected() {
+	/*isActiveWindow() shouldn't be necessary, but I don't trust it as far as I can throw it*/
+	return isActiveWindow() && isAncestorOf(QApplication::focusWidget());
+}
+
+}
diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h
index 96348b3..ebd495e 100644
--- a/Swift/QtUI/QtTabbable.h
+++ b/Swift/QtUI/QtTabbable.h
@@ -6,6 +6,8 @@
 namespace Swift {
 	class QtTabbable : public QWidget {
 		Q_OBJECT
+		public:
+			bool isWidgetSelected();
 		protected:
 			QtTabbable() : QWidget() {};
 
diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro
index da5f4e8..0af8216 100644
--- a/Swift/QtUI/Swift.pro
+++ b/Swift/QtUI/Swift.pro
@@ -84,6 +84,7 @@ SOURCES += \
 	QtChatTabs.cpp \
 	QtSoundPlayer.cpp \
 	QtSystemTray.cpp \
+	QtTabbable.cpp \
 	ChatSnippet.cpp \
 	MessageSnippet.cpp \
 	SystemMessageSnippet.cpp
-- 
cgit v0.10.2-6-g49f6