Changed when keyboard grabbing is enabled / disabled
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 12 Aug 2010 13:43:59 +0000 (16:43 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 12 Aug 2010 13:43:59 +0000 (16:43 +0300)
 - Grabbing is enabled in showEvent() if the MainWindow is topmost

 - Grabbing is disabled when other window becomes the topmost one

src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h

index f693d9b..b8a77d7 100644 (file)
@@ -32,7 +32,8 @@
 #include "friendlistpanel.h"
 
 FriendListPanel::FriendListPanel(QWidget *parent)
-    : QWidget(parent)
+    : QWidget(parent),
+      m_mainWindowIsTopmost(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -108,7 +109,7 @@ FriendListPanel::FriendListPanel(QWidget *parent)
             this, SLOT(clearFiltering()));
 
     connect(qApp, SIGNAL(topmostWindowChanged(bool)),
-            this, SLOT(setKeyboardGrabbing(bool)));
+            this, SLOT(topmostWindowChanged(bool)));
 }
 
 void FriendListPanel::clearFiltering()
@@ -177,6 +178,13 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
     m_friendListView->clearUnused(newUserIDs);
 }
 
+void FriendListPanel::hideEvent(QHideEvent *event)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    QWidget::hideEvent(event);
+}
+
 void FriendListPanel::setFilteringLayoutVisible(bool visible)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -185,14 +193,11 @@ void FriendListPanel::setFilteringLayoutVisible(bool visible)
     m_filterClearButton->setVisible(visible);
 }
 
-void FriendListPanel::setKeyboardGrabbing(bool grab)
+void FriendListPanel::updateKeyboardGrabbing()
 {
-    qWarning() << __PRETTY_FUNCTION__ << grab;
+    qWarning() << __PRETTY_FUNCTION__;
+
 
-    if (grab)
-        m_filterField->grabKeyboard();
-    else
-        m_filterField->releaseKeyboard();
 }
 
 void FriendListPanel::showEvent(QShowEvent *event)
@@ -201,10 +206,14 @@ void FriendListPanel::showEvent(QShowEvent *event)
 
     QWidget::showEvent(event);
 
-    if (QWidget::keyboardGrabber() != qobject_cast<QWidget *>(m_filterField)) {
-//        qWarning() << __PRETTY_FUNCTION__ << "grabbing the keyboard for filter text field";
-//        m_filterField->grabKeyboard();
+    if (m_mainWindowIsTopmost
+        && (QWidget::keyboardGrabber() != qobject_cast<QWidget *>(m_filterField))) {
+
+        qWarning() << __PRETTY_FUNCTION__ << "grabbed";
+        m_filterField->grabKeyboard();
         setFilteringLayoutVisible(false);
+    } else {
+        qWarning() << __PRETTY_FUNCTION__ << "DID NOT GRAB!";
     }
 }
 
@@ -218,3 +227,18 @@ void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
     m_friendListHeaderWidget->show();
     m_friendListView->filter(userIDs);
 }
+
+void FriendListPanel::topmostWindowChanged(bool grab)
+{
+    qWarning() << __PRETTY_FUNCTION__ << grab;
+
+    m_mainWindowIsTopmost = grab;
+
+    if (grab && isVisible() && (QWidget::keyboardGrabber() != m_filterField)) {
+        m_filterField->grabKeyboard();
+        qWarning() << __PRETTY_FUNCTION__ << "grabbed";
+    } else if (!grab && (QWidget::keyboardGrabber() == m_filterField)) {
+        m_filterField->releaseKeyboard();
+        qWarning() << __PRETTY_FUNCTION__ << "released";
+    }
+}
index c1130c3..65c75c1 100644 (file)
@@ -61,6 +61,8 @@ public:
  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
  ******************************************************************************/
 protected:
+    void hideEvent(QHideEvent *event);
+
     /**
     * @brief Used for grabbing the keyboard after the text field is fully initiated.
     *
@@ -94,6 +96,8 @@ private:
     */
     void setFilteringLayoutVisible(bool visible);
 
+    void updateKeyboardGrabbing();
+
 private slots:
     /**
      * @brief Slot to clear friend list filter.
@@ -115,7 +119,7 @@ private slots:
     */
     void filterTextChanged(const QString &text);
 
-    void setKeyboardGrabbing(bool grab);
+    void topmostWindowChanged(bool grab);
 
     /**
      * @brief Slot to show friends in list.
@@ -140,6 +144,8 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
+    bool m_mainWindowIsTopmost;
+
     QLabel *m_friendListLabel;          ///< Friend list label
     QLineEdit *m_filterField;           ///< Text field for the filter text
     QPushButton *m_clearFilterButton;   ///< Button to clear list filtering