Added button for clearing the filtering
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 10 Aug 2010 07:41:29 +0000 (10:41 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 10 Aug 2010 07:41:29 +0000 (10:41 +0300)
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h

index d243b82..b603c65 100644 (file)
@@ -72,31 +72,63 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     connect(this, SIGNAL(panelOpened()),
             this, SLOT(clearFriendListFilter()));
 
+    /// @todo remove old filterLayout when new panel are merged
+
+    //////////////////////////////////////////////////////////////////////////
+    // NOTE! Do not mix the new filtering layout below with the old one above
+    //////////////////////////////////////////////////////////////////////////
+
+    // filtering layout
+    QHBoxLayout *filteringLayout = new QHBoxLayout();
+    m_panelVBox->addLayout(filteringLayout);
+
+    // line edit for filtering
     m_filterField = new QLineEdit;
-    m_panelVBox->addWidget(m_filterField);
+    filteringLayout->addWidget(m_filterField);
     m_filterField->grabKeyboard();
-    m_filterField->hide();
 
     connect(m_filterField, SIGNAL(returnPressed()),
-            this, SLOT(filterReturnPressed()));
+            this, SLOT(clearFiltering()));
 
     connect(m_filterField, SIGNAL(textChanged(QString)),
             this, SLOT(filterTextChanged(QString)));
+
+    // button for clearing the filtering
+    m_filterClearButton = new QToolButton();
+    filteringLayout->addWidget(m_filterClearButton);
+    m_filterClearButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
+
+    connect(m_filterClearButton, SIGNAL(clicked()),
+            this, SLOT(clearFiltering()));
+
+    // filtering layout ites are hidden by defaults
+    setFilteringLayoutVisible(false);
 }
 
-void FriendListPanel::filterReturnPressed()
+void FriendListPanel::clearFiltering()
 {
+    qWarning() << __PRETTY_FUNCTION__;
+
+    // clearing the filtering text field does cause also hiding the filtering layout
     m_filterField->clear();
 }
 
+void FriendListPanel::clearFriendListFilter()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_friendListHeaderWidget->hide();
+    m_friendListView->clearFilter();
+}
+
 void FriendListPanel::filterTextChanged(const QString &text)
 {
     qWarning() << __PRETTY_FUNCTION__;
 
-    if(text.isEmpty())
-        m_filterField->hide();
-    else
-        m_filterField->show();
+    if (m_filterField->isHidden() && !text.isEmpty())
+        setFilteringLayoutVisible(true);
+    else if (m_filterField->isVisible() && text.isEmpty())
+        setFilteringLayoutVisible(false);
 }
 
 void FriendListPanel::friendImageReady(User *user)
@@ -138,12 +170,12 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
     m_friendListView->clearUnused(newUserIDs);
 }
 
-void FriendListPanel::clearFriendListFilter()
+void FriendListPanel::setFilteringLayoutVisible(bool visible)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
-    m_friendListHeaderWidget->hide();
-    m_friendListView->clearFilter();
+    m_filterField->setVisible(visible);
+    m_filterClearButton->setVisible(visible);
 }
 
 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
index fb2d9d7..b6c595a 100644 (file)
@@ -71,13 +71,16 @@ public slots:
     */
     void friendInfoReceived(QList<User *> &friendList);
 
+private:
+    void setFilteringLayoutVisible(bool visible);
+
 private slots:
     /**
     * @brief Slot to clear friend list filter.
     */
     void clearFriendListFilter();
 
-    void filterReturnPressed();
+    void clearFiltering();
 
     void filterTextChanged(const QString &text);
 
@@ -111,6 +114,7 @@ private:
     FriendListItemDelegate *m_friendListItemDelegate;   ///< Friend list item delegate
 
     QLineEdit *m_filterField;
+    QToolButton *m_filterClearButton;
 };
 
 #endif // FRIENDLISTPANEL_H