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);
m_friendsPanelStateMachine->start();
setObjectName("FriendsPanel");
+
+ connect(m_clearFilterButton, SIGNAL(clicked()), this, SLOT(clearFriendListFilter()));
}
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);
}
}
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);
+}
*/
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
******************************************************************************/
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
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);
}
}
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();
}
#define FRIENDLISTVIEW_H
#include <QWidget>
-#include <QList>
+#include <QHash>
class QVBoxLayout;
class QLabel;
/**
* @brief FriendListView shows items in list.
*
-* @class FriendListView friendlistview.h "ui/friendlistview.h"
*/
class FriendListView : public QWidget
{
/**
* @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.
*/
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