2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
6 Henri Lampela - henri.lampela@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include "friendlistpanel.h"
25 #include "friendlistitem.h"
26 #include "friendlistitemdelegate.h"
27 #include "panelcommon.h"
28 #include "sidepanel.h"
30 FriendListPanel::FriendListPanel(QWidget *parent)
33 qDebug() << __PRETTY_FUNCTION__;
34 setType(SidePanel::FriendPanel);
36 QHBoxLayout *filterLayout = new QHBoxLayout;
37 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
38 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
39 m_friendListHeaderWidget = new QWidget();
40 m_friendListHeaderWidget->setLayout(filterLayout);
41 m_friendListHeaderWidget->setAutoFillBackground(true);
42 QPalette labelPalette = m_friendListHeaderWidget->palette();
43 labelPalette.setColor(QPalette::Background, Qt::black);
44 m_friendListHeaderWidget->setPalette(labelPalette);
45 m_friendListHeaderWidget->hide();
46 m_friendListLabel = new QLabel(this);
47 m_clearFilterButton = new QPushButton(tr("Show all"));
48 filterLayout->addWidget(m_friendListLabel);
49 filterLayout->addWidget(m_clearFilterButton);
50 m_panelVBox->addWidget(m_friendListHeaderWidget);
52 QHBoxLayout *friendListLayout = new QHBoxLayout;
53 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
54 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
56 m_friendListView = new ListView(this);
57 m_friendListView->setAutoFillBackground(false);
58 m_friendListView->viewport()->setAutoFillBackground(false);
59 m_friendListItemDelegate = new FriendListItemDelegate();
60 m_friendListView->setItemDelegate(m_friendListItemDelegate);
62 friendListLayout->addWidget(m_friendListView);
63 m_panelVBox->addLayout(friendListLayout);
65 connect(m_friendListView, SIGNAL(listItemClicked(QPointF)),
66 this, SIGNAL(findFriend(QPointF)));
68 connect(m_clearFilterButton, SIGNAL(clicked()),
69 this, SLOT(clearFriendListFilter()));
70 connect(this, SIGNAL(panelOpened()),
71 this, SLOT(clearFriendListFilter()));
74 void FriendListPanel::friendImageReady(User *user)
76 qDebug() << __PRETTY_FUNCTION__;
78 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
81 item->setAvatarImage(user->profileImage());
84 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
86 qDebug() << __PRETTY_FUNCTION__;
88 QStringList newUserIDs;
90 foreach (User *user, friendList) {
91 FriendListItem *item = 0;
92 if (!m_friendListView->contains(user->userId())) {
93 item = new FriendListItem();
94 item->setUserData(user);
95 m_friendListView->addListItem(user->userId(), item);
98 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
102 item->setUserData(user);
103 m_friendListView->addListItemToView(item);
107 newUserIDs.append(user->userId());
110 m_friendListView->clearUnused(newUserIDs);
113 void FriendListPanel::clearFriendListFilter()
115 qDebug() << __PRETTY_FUNCTION__;
117 m_friendListHeaderWidget->hide();
118 m_friendListView->clearFilter();
121 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
123 qDebug() << __PRETTY_FUNCTION__;
125 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
128 m_friendListHeaderWidget->show();
129 m_friendListView->filter(userIDs);