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"
23 #include "friendlistview.h"
24 #include "friendlistitem.h"
25 #include "panelcommon.h"
26 #include "sidepanel.h"
28 FriendListPanel::FriendListPanel(QWidget *parent)
31 qDebug() << __PRETTY_FUNCTION__;
32 setType(SidePanel::FriendPanel);
34 QHBoxLayout *filterLayout = new QHBoxLayout;
35 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
36 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
37 m_friendListHeaderWidget = new QWidget();
38 m_friendListHeaderWidget->setLayout(filterLayout);
39 m_friendListHeaderWidget->setAutoFillBackground(true);
40 QPalette labelPalette = m_friendListHeaderWidget->palette();
41 labelPalette.setColor(QPalette::Background, Qt::black);
42 m_friendListHeaderWidget->setPalette(labelPalette);
43 m_friendListHeaderWidget->hide();
44 m_friendListLabel = new QLabel(this);
45 m_clearFilterButton = new QPushButton(tr("Show all"));
46 filterLayout->addWidget(m_friendListLabel);
47 filterLayout->addWidget(m_clearFilterButton);
48 m_panelVBox->addWidget(m_friendListHeaderWidget);
50 QHBoxLayout *friendListLayout = new QHBoxLayout;
51 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
52 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
53 m_friendListView = new FriendListView(this);
54 QScrollArea *friendListScroll = new QScrollArea(this);
55 friendListScroll->setWidgetResizable(false);
56 friendListScroll->setWidget(m_friendListView);
57 friendListScroll->viewport()->setAutoFillBackground(false);
58 friendListScroll->widget()->setAutoFillBackground(false);
59 friendListLayout->addWidget(friendListScroll);
60 m_panelVBox->addLayout(friendListLayout);
62 connect(m_clearFilterButton, SIGNAL(clicked()),
63 this, SLOT(clearFriendListFilter()));
64 connect(this, SIGNAL(panelOpened()),
65 this, SLOT(clearFriendListFilter()));
68 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
70 qDebug() << __PRETTY_FUNCTION__;
72 QStringList newUserIDs;
74 foreach (User *user, friendList) {
75 FriendListItem *item = 0;
76 if (!m_friendListView->contains(user->userId())) {
77 item = new FriendListItem(m_friendListView);
79 m_friendListView->addWidget(user->userId(), item);
81 connect(item, SIGNAL(findFriend(QPointF)),
82 this, SIGNAL(findFriend(QPointF)));
85 item = m_friendListView->takeWidgetFromView(user->userId());
88 m_friendListView->addWidgetToView(item);
92 newUserIDs.append(user->userId());
95 m_friendListView->clearUnused(newUserIDs);
98 void FriendListPanel::clearFriendListFilter()
100 qDebug() << __PRETTY_FUNCTION__;
102 m_friendListHeaderWidget->hide();
103 m_friendListView->clearFilter();
106 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
108 qDebug() << __PRETTY_FUNCTION__;
110 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
113 m_friendListHeaderWidget->show();
114 m_friendListView->filter(userIDs);