2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include "friendlistpanel.h"
24 #include "friendlistitem.h"
25 #include "friendlistitemdelegate.h"
26 #include "panelcommon.h"
27 #include "sidepanel.h"
29 FriendListPanel::FriendListPanel(QWidget *parent)
32 qDebug() << __PRETTY_FUNCTION__;
33 setType(SidePanel::FriendPanel);
35 QHBoxLayout *filterLayout = new QHBoxLayout;
36 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
37 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
38 m_friendListHeaderWidget = new QWidget();
39 m_friendListHeaderWidget->setLayout(filterLayout);
40 m_friendListHeaderWidget->setAutoFillBackground(true);
41 QPalette labelPalette = m_friendListHeaderWidget->palette();
42 labelPalette.setColor(QPalette::Background, Qt::black);
43 m_friendListHeaderWidget->setPalette(labelPalette);
44 m_friendListHeaderWidget->hide();
45 m_friendListLabel = new QLabel(this);
46 m_clearFilterButton = new QPushButton(tr("Show all"));
47 filterLayout->addWidget(m_friendListLabel);
48 filterLayout->addWidget(m_clearFilterButton);
49 m_panelVBox->addWidget(m_friendListHeaderWidget);
51 QHBoxLayout *friendListLayout = new QHBoxLayout;
52 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
53 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
55 m_friendListView = new ListView(this);
56 m_friendListView->setAutoFillBackground(false);
57 m_friendListView->viewport()->setAutoFillBackground(false);
58 m_friendListItemDelegate = new FriendListItemDelegate();
59 m_friendListView->setItemDelegate(m_friendListItemDelegate);
61 friendListLayout->addWidget(m_friendListView);
62 m_panelVBox->addLayout(friendListLayout);
64 connect(m_friendListView, SIGNAL(listItemClicked(QPointF)),
65 this, SIGNAL(findFriend(QPointF)));
67 connect(m_clearFilterButton, SIGNAL(clicked()),
68 this, SLOT(clearFriendListFilter()));
69 connect(this, SIGNAL(panelOpened()),
70 this, SLOT(clearFriendListFilter()));
73 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
75 qDebug() << __PRETTY_FUNCTION__;
77 QStringList newUserIDs;
79 foreach (User *user, friendList) {
80 FriendListItem *item = 0;
81 if (!m_friendListView->contains(user->userId())) {
82 item = new FriendListItem();
83 item->setUserData(user);
84 m_friendListView->addListItem(user->userId(), item);
87 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
91 item->setUserData(user);
92 m_friendListView->addListItemToView(item);
96 newUserIDs.append(user->userId());
99 m_friendListView->clearUnused(newUserIDs);
102 void FriendListPanel::clearFriendListFilter()
104 qDebug() << __PRETTY_FUNCTION__;
106 m_friendListHeaderWidget->hide();
107 m_friendListView->clearFilter();
110 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
112 qDebug() << __PRETTY_FUNCTION__;
114 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
117 m_friendListHeaderWidget->show();
118 m_friendListView->filter(userIDs);