Implemented text field for filtering the friend list
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 10 Aug 2010 06:31:05 +0000 (09:31 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 10 Aug 2010 06:31:05 +0000 (09:31 +0300)
 - the field grabs the keyboard, so all keypresses modify the
   field even if it is not focused

 - the field is hidden by default, and is invoked when a key
   is pressed.

 - the field is hidden when it is empty (for example when cleared
   by using the backspace)

 - the field is cleared (and thus hidden) when return/enter is
   pressed

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

index 70aca8d..d243b82 100644 (file)
@@ -71,6 +71,32 @@ FriendListPanel::FriendListPanel(QWidget *parent)
             this, SLOT(clearFriendListFilter()));
     connect(this, SIGNAL(panelOpened()),
             this, SLOT(clearFriendListFilter()));
+
+    m_filterField = new QLineEdit;
+    m_panelVBox->addWidget(m_filterField);
+    m_filterField->grabKeyboard();
+    m_filterField->hide();
+
+    connect(m_filterField, SIGNAL(returnPressed()),
+            this, SLOT(filterReturnPressed()));
+
+    connect(m_filterField, SIGNAL(textChanged(QString)),
+            this, SLOT(filterTextChanged(QString)));
+}
+
+void FriendListPanel::filterReturnPressed()
+{
+    m_filterField->clear();
+}
+
+void FriendListPanel::filterTextChanged(const QString &text)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if(text.isEmpty())
+        m_filterField->hide();
+    else
+        m_filterField->show();
 }
 
 void FriendListPanel::friendImageReady(User *user)
index 6e83cb9..fb2d9d7 100644 (file)
@@ -77,6 +77,10 @@ private slots:
     */
     void clearFriendListFilter();
 
+    void filterReturnPressed();
+
+    void filterTextChanged(const QString &text);
+
     /**
     * @brief Slot to show friends in list.
     *
@@ -105,6 +109,8 @@ private:
     QPushButton *m_clearFilterButton;   ///< Button to clear list filtering
     ListView *m_friendListView;         ///< Friend list view
     FriendListItemDelegate *m_friendListItemDelegate;   ///< Friend list item delegate
+
+    QLineEdit *m_filterField;
 };
 
 #endif // FRIENDLISTPANEL_H