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(SLIDINGBAR_WIDTH+1, 0, SHOW_ALL_BUTTON_RIGHT_MARGIN, 0);
36 m_friendListHeaderWidget = new QWidget();
37 m_friendListHeaderWidget->setLayout(filterLayout);
38 m_friendListHeaderWidget->setAutoFillBackground(true);
39 QPalette labelPalette = m_friendListHeaderWidget->palette();
40 labelPalette.setColor(QPalette::Background, Qt::black);
41 m_friendListHeaderWidget->setPalette(labelPalette);
42 m_friendListHeaderWidget->hide();
43 m_friendListLabel = new QLabel(this);
44 m_clearFilterButton = new QPushButton(tr("Show all"));
45 filterLayout->addWidget(m_friendListLabel);
46 filterLayout->addWidget(m_clearFilterButton);
47 m_panelVBox->addWidget(m_friendListHeaderWidget);
49 QHBoxLayout *friendListLayout = new QHBoxLayout;
50 friendListLayout->setContentsMargins(SLIDINGBAR_WIDTH+1, 0, SIDEBAR_WIDTH, 0);
51 m_friendListView = new FriendListView(this);
52 QScrollArea *friendListScroll = new QScrollArea(this);
53 friendListScroll->setWidgetResizable(false);
54 friendListScroll->setWidget(m_friendListView);
55 friendListScroll->viewport()->setAutoFillBackground(false);
56 friendListScroll->widget()->setAutoFillBackground(false);
57 friendListLayout->addWidget(friendListScroll);
58 m_panelVBox->addLayout(friendListLayout);
60 connect(m_clearFilterButton, SIGNAL(clicked()),
61 this, SLOT(clearFriendListFilter()));
62 connect(this, SIGNAL(panelOpened()),
63 this, SLOT(clearFriendListFilter()));
66 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
68 qDebug() << __PRETTY_FUNCTION__;
70 QStringList newUserIDs;
72 foreach (User *user, friendList) {
73 FriendListItem *item = 0;
74 if (!m_friendListView->contains(user->userId())) {
75 item = new FriendListItem(m_friendListView);
77 m_friendListView->addWidget(user->userId(), item);
79 connect(item, SIGNAL(findFriend(QPointF)),
80 this, SIGNAL(findFriend(QPointF)));
83 item = m_friendListView->takeWidgetFromView(user->userId());
86 m_friendListView->addWidgetToView(item);
90 newUserIDs.append(user->userId());
93 m_friendListView->clearUnused(newUserIDs);
96 void FriendListPanel::clearFriendListFilter()
98 qDebug() << __PRETTY_FUNCTION__;
100 m_friendListHeaderWidget->hide();
101 m_friendListView->clearFilter();
104 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
106 qDebug() << __PRETTY_FUNCTION__;
108 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
111 m_friendListHeaderWidget->show();
112 m_friendListView->filter(userIDs);