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
7 Pekka Nissinen - pekka.nissinen@ixonos.com
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QHBoxLayout>
26 #include <QPushButton>
28 #include "coordinates/geocoordinate.h"
30 #include "friendlistitem.h"
31 #include "friendlistitemdelegate.h"
32 #include "panelcommon.h"
34 #include "friendlistpanel.h"
36 FriendListPanel::FriendListPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 const int FRIENDPANEL_FILTER_MARGIN_LEFT = PANEL_MARGIN_LEFT + 4;
42 const int FRIENDPANEL_FILTER_MARGIN_TOP = 0;
43 const int FRIENDPANEL_FILTER_MARGIN_RIGHT = PANEL_MARGIN_RIGHT + MAEMO5_SCROLLBAR_WIDTH + 4;
44 const int FRIENDPANEL_FILTER_MARGIN_BOTTOM = 0;
46 QVBoxLayout *friendListPanelLayout = new QVBoxLayout();
47 friendListPanelLayout->setMargin(0);
48 friendListPanelLayout->setSpacing(0);
49 friendListPanelLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
50 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
51 setLayout(friendListPanelLayout);
53 QHBoxLayout *filterLayout = new QHBoxLayout();
54 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, FRIENDPANEL_FILTER_MARGIN_TOP,
55 FRIENDPANEL_FILTER_MARGIN_RIGHT, FRIENDPANEL_FILTER_MARGIN_BOTTOM);
57 m_friendListHeaderWidget = new QWidget();
58 m_friendListHeaderWidget->setLayout(filterLayout);
59 m_friendListHeaderWidget->setAutoFillBackground(true);
61 QPalette labelPalette = m_friendListHeaderWidget->palette();
62 labelPalette.setColor(QPalette::Background, Qt::black);
64 m_friendListHeaderWidget->setPalette(labelPalette);
65 m_friendListHeaderWidget->hide();
66 m_friendListLabel = new QLabel(this);
67 m_clearFilterButton = new QPushButton(tr("Show all"));
69 filterLayout->addWidget(m_friendListLabel);
70 filterLayout->addWidget(m_clearFilterButton);
72 m_friendListView = new ListView(this);
74 m_friendListView->setAutoFillBackground(false);
75 m_friendListView->viewport()->setAutoFillBackground(false);
76 m_friendListItemDelegate = new FriendListItemDelegate();
77 m_friendListView->setItemDelegate(m_friendListItemDelegate);
79 friendListPanelLayout->addWidget(m_friendListHeaderWidget);
80 friendListPanelLayout->addWidget(m_friendListView);
82 connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
83 this, SIGNAL(findFriend(GeoCoordinate)));
85 connect(m_clearFilterButton, SIGNAL(clicked()),
86 this, SLOT(clearFriendListFilter()));
89 void FriendListPanel::friendImageReady(User *user)
91 qDebug() << __PRETTY_FUNCTION__;
93 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
96 item->setAvatarImage(user->profileImage());
99 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
101 qDebug() << __PRETTY_FUNCTION__;
103 QStringList newUserIDs;
105 foreach (User *user, friendList) {
106 FriendListItem *item = 0;
107 if (!m_friendListView->contains(user->userId())) {
108 item = new FriendListItem();
109 item->setUserData(user);
110 m_friendListView->addListItem(user->userId(), item);
112 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
116 item->setUserData(user);
117 m_friendListView->addListItemToView(item);
121 newUserIDs.append(user->userId());
124 m_friendListView->clearUnused(newUserIDs);
127 void FriendListPanel::clearFriendListFilter()
129 qDebug() << __PRETTY_FUNCTION__;
131 m_friendListHeaderWidget->hide();
132 m_friendListView->clearFilter();
135 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
137 qDebug() << __PRETTY_FUNCTION__;
139 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
141 m_friendListHeaderWidget->show();
142 m_friendListView->filter(userIDs);
144 emit showPanelRequested(this);