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"
24 #include "friendlistview.h"
25 #include "friendlistitem.h"
26 #include "panelcommon.h"
27 #include "sidepanel.h"
29 #include "friendlistpanel.h"
31 FriendListPanel::FriendListPanel(QWidget *parent)
34 qDebug() << __PRETTY_FUNCTION__;
35 setType(SidePanel::FriendPanel);
37 QHBoxLayout *filterLayout = new QHBoxLayout;
38 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
39 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
40 m_friendListHeaderWidget = new QWidget();
41 m_friendListHeaderWidget->setLayout(filterLayout);
42 m_friendListHeaderWidget->setAutoFillBackground(true);
43 QPalette labelPalette = m_friendListHeaderWidget->palette();
44 labelPalette.setColor(QPalette::Background, Qt::black);
45 m_friendListHeaderWidget->setPalette(labelPalette);
46 m_friendListHeaderWidget->hide();
47 m_friendListLabel = new QLabel(this);
48 m_clearFilterButton = new QPushButton(tr("Show all"));
49 filterLayout->addWidget(m_friendListLabel);
50 filterLayout->addWidget(m_clearFilterButton);
51 m_panelVBox->addWidget(m_friendListHeaderWidget);
53 QHBoxLayout *friendListLayout = new QHBoxLayout;
54 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
55 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
56 m_friendListView = new FriendListView(this);
57 QScrollArea *friendListScroll = new QScrollArea(this);
58 friendListScroll->setWidgetResizable(false);
59 friendListScroll->setWidget(m_friendListView);
60 friendListScroll->viewport()->setAutoFillBackground(false);
61 friendListScroll->widget()->setAutoFillBackground(false);
62 friendListLayout->addWidget(friendListScroll);
63 m_panelVBox->addLayout(friendListLayout);
65 connect(m_clearFilterButton, SIGNAL(clicked()),
66 this, SLOT(clearFriendListFilter()));
67 connect(this, SIGNAL(panelOpened()),
68 this, SLOT(clearFriendListFilter()));
71 void FriendListPanel::friendImageReady(User *user)
73 qDebug() << __PRETTY_FUNCTION__;
75 FriendListItem *item = m_friendListView->widget(user->userId());
76 item->setAvatarImage(user->profileImage());
79 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
81 qDebug() << __PRETTY_FUNCTION__;
83 QStringList newUserIDs;
85 foreach (User *user, friendList) {
86 FriendListItem *item = 0;
87 if (!m_friendListView->contains(user->userId())) {
88 item = new FriendListItem(m_friendListView);
90 m_friendListView->addWidget(user->userId(), item);
92 connect(item, SIGNAL(findFriend(GeoCoordinate)),
93 this, SIGNAL(findFriend(GeoCoordinate)));
96 item = m_friendListView->takeWidgetFromView(user->userId());
99 m_friendListView->addWidgetToView(item);
103 newUserIDs.append(user->userId());
106 m_friendListView->clearUnused(newUserIDs);
109 void FriendListPanel::clearFriendListFilter()
111 qDebug() << __PRETTY_FUNCTION__;
113 m_friendListHeaderWidget->hide();
114 m_friendListView->clearFilter();
117 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
119 qDebug() << __PRETTY_FUNCTION__;
121 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
124 m_friendListHeaderWidget->show();
125 m_friendListView->filter(userIDs);