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 "coordinates/geocoordinate.h"
25 #include "friendlistitem.h"
26 #include "friendlistitemdelegate.h"
27 #include "panelcommon.h"
28 #include "sidepanel.h"
29 #include "../routing/location.h"
30 #include "locationlistitem.h"
32 #include "friendlistpanel.h"
34 FriendListPanel::FriendListPanel(QWidget *parent)
37 qDebug() << __PRETTY_FUNCTION__;
38 setType(SidePanel::FriendPanel);
40 QHBoxLayout *filterLayout = new QHBoxLayout;
41 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
42 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
43 m_friendListHeaderWidget = new QWidget();
44 m_friendListHeaderWidget->setLayout(filterLayout);
45 m_friendListHeaderWidget->setAutoFillBackground(true);
46 QPalette labelPalette = m_friendListHeaderWidget->palette();
47 labelPalette.setColor(QPalette::Background, Qt::black);
48 m_friendListHeaderWidget->setPalette(labelPalette);
49 m_friendListHeaderWidget->hide();
50 m_friendListLabel = new QLabel(this);
51 m_clearFilterButton = new QPushButton(tr("Show all"));
52 filterLayout->addWidget(m_friendListLabel);
53 filterLayout->addWidget(m_clearFilterButton);
54 m_panelVBox->addWidget(m_friendListHeaderWidget);
56 QHBoxLayout *friendListLayout = new QHBoxLayout;
57 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
58 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
60 m_friendListView = new ListView(this);
61 m_friendListView->setAutoFillBackground(false);
62 m_friendListView->viewport()->setAutoFillBackground(false);
63 m_friendListItemDelegate = new FriendListItemDelegate();
64 m_friendListView->setItemDelegate(m_friendListItemDelegate);
66 m_locationListView = new ListView(this);
67 m_locationListView->setAutoFillBackground(false);
68 m_locationListView->viewport()->setAutoFillBackground(false);
69 m_locationListView->setItemDelegate(m_friendListItemDelegate);
71 friendListLayout->addWidget(m_friendListView);
72 m_panelVBox->addLayout(friendListLayout);
73 m_panelVBox->addWidget(m_locationListView);
75 connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
76 this, SIGNAL(findFriend(GeoCoordinate)));
78 connect(m_clearFilterButton, SIGNAL(clicked()),
79 this, SLOT(clearFriendListFilter()));
80 connect(this, SIGNAL(panelOpened()),
81 this, SLOT(clearFriendListFilter()));
84 void FriendListPanel::friendImageReady(User *user)
86 qDebug() << __PRETTY_FUNCTION__;
88 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
91 item->setAvatarImage(user->profileImage());
94 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
96 qDebug() << __PRETTY_FUNCTION__;
98 QStringList newUserIDs;
100 foreach (User *user, friendList) {
101 FriendListItem *item = 0;
102 if (!m_friendListView->contains(user->userId())) {
103 item = new FriendListItem();
104 item->setUserData(user);
105 m_friendListView->addListItem(user->userId(), item);
108 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
112 item->setUserData(user);
113 m_friendListView->addListItemToView(item);
117 newUserIDs.append(user->userId());
120 m_friendListView->clearUnused(newUserIDs);
123 void FriendListPanel::clearFriendListFilter()
125 qDebug() << __PRETTY_FUNCTION__;
127 m_friendListHeaderWidget->hide();
128 m_friendListView->clearFilter();
131 void FriendListPanel::locationDataReady(QList<Location> &result)
133 qWarning() << __PRETTY_FUNCTION__;
135 for (int i = 0; i < result.size(); ++i) {
136 LocationListItem *item = new LocationListItem();
137 item->setLocationData(result.at(i));
138 m_locationListView->addListItem(QString::number(i), item);
144 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
146 qDebug() << __PRETTY_FUNCTION__;
148 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
151 m_friendListHeaderWidget->show();
152 m_friendListView->filter(userIDs);