From ba0ae5323f3e1fad87473d14ee4da2c6b085d9eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Tue, 10 Aug 2010 09:31:05 +0300 Subject: [PATCH] Implemented text field for filtering the friend list - 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 | 26 ++++++++++++++++++++++++++ src/ui/friendlistpanel.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/src/ui/friendlistpanel.cpp b/src/ui/friendlistpanel.cpp index 70aca8d..d243b82 100644 --- a/src/ui/friendlistpanel.cpp +++ b/src/ui/friendlistpanel.cpp @@ -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) diff --git a/src/ui/friendlistpanel.h b/src/ui/friendlistpanel.h index 6e83cb9..fb2d9d7 100644 --- a/src/ui/friendlistpanel.h +++ b/src/ui/friendlistpanel.h @@ -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 -- 1.7.9.5