From: Jussi Laitinen Date: Thu, 20 May 2010 07:14:11 +0000 (+0300) Subject: Merge branch 'master' into friendlist X-Git-Tag: v0.5~43 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=29f85e5649df6c5a1805e4905061b86f1046fd95;hp=27bf5947e07aed8807684f8bdb49ebbee6c4af34;p=situare Merge branch 'master' into friendlist --- diff --git a/src/ui/friendlistpanel.cpp b/src/ui/friendlistpanel.cpp index 8fe37e6..8a631db 100644 --- a/src/ui/friendlistpanel.cpp +++ b/src/ui/friendlistpanel.cpp @@ -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 &friendList) @@ -88,9 +94,10 @@ void FriendListPanel::friendInfoReceived(QList &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 &userIDs) +{ + m_clearFilterButton->show(); + m_friendListView->filter(userIDs); +} diff --git a/src/ui/friendlistpanel.h b/src/ui/friendlistpanel.h index 2845c5c..29e01ba 100644 --- a/src/ui/friendlistpanel.h +++ b/src/ui/friendlistpanel.h @@ -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 &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 diff --git a/src/ui/friendlistview.cpp b/src/ui/friendlistview.cpp index 18e870b..36c7cc3 100644 --- a/src/ui/friendlistview.cpp +++ b/src/ui/friendlistview.cpp @@ -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 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(); } diff --git a/src/ui/friendlistview.h b/src/ui/friendlistview.h index 5ba2d79..6dd26b8 100644 --- a/src/ui/friendlistview.h +++ b/src/ui/friendlistview.h @@ -23,7 +23,7 @@ #define FRIENDLISTVIEW_H #include -#include +#include 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 userIDs); + /****************************************************************************** * DATA MEMBERS ******************************************************************************/ private: QVBoxLayout *m_friendListLayout; ///< Layout for this view - QList widgets; ///< List of widgets in this view + QHash widgets; ///< List of widgets in this view. Key = user ID }; #endif // FRIENDLISTVIEW_H