Merge branch 'master' into friendlist
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 20 May 2010 07:14:11 +0000 (10:14 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 20 May 2010 07:14:11 +0000 (10:14 +0300)
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/friendlistview.cpp
src/ui/friendlistview.h

index 8fe37e6..8a631db 100644 (file)
@@ -35,6 +35,10 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     m_friendsPanelVBox->setSpacing(0);
     setLayout(m_friendsPanelVBox);
 
+    m_clearFilterButton = new QPushButton("Clear filtering");
+    m_clearFilterButton->hide();
+    m_friendsPanelVBox->addWidget(m_clearFilterButton, 0, Qt::AlignCenter);
+
     m_panelBase = new QWidget(this);
     m_panelBase->setLayout(m_friendsPanelVBox);
     m_panelBase->move(TOP_CORNER_X + SLIDINGBAR_WIDTH,PANEL_TOP_Y);
@@ -77,6 +81,8 @@ FriendListPanel::FriendListPanel(QWidget *parent)
 
     m_friendsPanelStateMachine->start();
     setObjectName("FriendsPanel");
+
+    connect(m_clearFilterButton, SIGNAL(clicked()), this, SLOT(clearFriendListFilter()));
 }
 
 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
@@ -88,9 +94,10 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
     foreach (User *user, friendList) {
         FriendListItem *item = new FriendListItem(m_friendListView);
         item->setData(user);
+        m_friendListView->addWidget(user->userId(), item);
+
         connect(item, SIGNAL(findFriend(QPointF)),
             this, SIGNAL(findFriend(QPointF)));
-        m_friendListView->addWidget(item);
     }
 }
 
@@ -105,3 +112,15 @@ void FriendListPanel::reDrawFriendsPanel(int width, int height)
             width - FRIENDPANEL_WIDTH - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
     move(width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y);
 }
+
+void FriendListPanel::clearFriendListFilter()
+{
+    m_clearFilterButton->hide();
+    m_friendListView->clearFilter();
+}
+
+void FriendListPanel::filterFriendList(const QList<QString> &userIDs)
+{
+    m_clearFilterButton->show();
+    m_friendListView->filter(userIDs);
+}
index 2845c5c..29e01ba 100644 (file)
@@ -65,6 +65,20 @@ public slots:
     */
     void reDrawFriendsPanel(int width, int height);
 
+private slots:
+    /**
+    * @brief Slot to clear friend list filter.
+    */
+    void clearFriendListFilter();
+
+    /**
+    * @brief Slot to show friends in list.
+    *
+    * Shows only friends that are on userIDs list.
+    * @param userIDs list of user ID's
+    */
+    void showFriendsInList(const QList<QString> &userIDs);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -82,6 +96,7 @@ signals:
 private:
     FriendListView *m_friendListView; ///< Friend list view
     PanelSliderBar *m_friendsPanelSlidingBar; ///< Widget for sidebar tab item
+    QPushButton *m_clearFilterButton;   ///< Button to clear list filtering
     QState *m_friendsPanelStateClosed; ///< State of the closed panel
     QStateMachine *m_friendsPanelStateMachine; ///< State machine for sliding the panel
     QState *m_friendsPanelStateOpened; ///< State of the opened panel
index 18e870b..36c7cc3 100644 (file)
@@ -39,13 +39,13 @@ FriendListView::FriendListView(QWidget *parent)
     this->setLayout(m_friendListLayout);
 }
 
-void FriendListView::addWidget(QWidget *widget)
+void FriendListView::addWidget(const QString &key, QWidget *widget)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (!widgets.contains(widget)) {
+    if (!widgets.contains(key)) {
         m_friendListLayout->addWidget(widget);
-        widgets.append(widget);
+        widgets.insert(key, widget);
     }
 }
 
@@ -55,8 +55,27 @@ void FriendListView::clear()
 
     foreach (QWidget *widget, widgets) {
         m_friendListLayout->removeWidget(widget);
-        widgets.removeOne(widget);
         disconnect(widget, 0, 0, 0);
         delete widget;
     }
+
+    widgets.clear();
+}
+
+void FriendListView::filter(const QList<QString> userIDs)
+{
+    foreach (QWidget *widget, widgets)
+        widget->hide();
+
+    foreach (QString userID, userIDs) {
+        QWidget *widget = widgets.value(userID);
+        if (widget)
+            widget->show();
+    }
+}
+
+void FriendListView::clearFilter()
+{
+    foreach (QWidget *widget, widgets)
+        widget->show();
 }
index 5ba2d79..6dd26b8 100644 (file)
@@ -23,7 +23,7 @@
 #define FRIENDLISTVIEW_H
 
 #include <QWidget>
-#include <QList>
+#include <QHash>
 
 class QVBoxLayout;
 class QLabel;
@@ -31,7 +31,6 @@ class QLabel;
 /**
 * @brief FriendListView shows items in list.
 *
-* @class FriendListView friendlistview.h "ui/friendlistview.h"
 */
 class FriendListView : public QWidget
 {
@@ -52,9 +51,10 @@ public:
     /**
     * @brief Add widget to view and widget list.
     *
+    * @param key user ID
     * @param widget widget to add to list
     */
-    void addWidget(QWidget *widget);
+    void addWidget(const QString &key, QWidget *widget);
 
     /**
     * @brief Clear view.
@@ -63,12 +63,28 @@ public:
     */
     void clear();
 
+    /**
+    * @brief Clears filtering from list.
+    *
+    * Calls show to all widgets.
+    */
+    void clearFilter();
+
+    /**
+    * @brief Sets filter to list.
+    *
+    * Hide all widgets that are not in the userIDs list.
+    *
+    * @param userIDs user ID's to widgets that are shown
+    */
+    void filter(const QList<QString> userIDs);
+
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
     QVBoxLayout *m_friendListLayout;    ///< Layout for this view
-    QList<QWidget *> widgets;           ///< List of widgets in this view
+    QHash<QString, QWidget *> widgets;           ///< List of widgets in this view. Key = user ID
 };
 
 #endif // FRIENDLISTVIEW_H