Changed header text in friend list panel.
[situare] / src / ui / friendlistpanel.cpp
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6
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.
10
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.
15
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,
19     USA.
20  */
21
22 #include "friendlistpanel.h"
23 #include "friendlistview.h"
24 #include "friendlistitem.h"
25 #include "panelcommon.h"
26 #include "sidepanel.h"
27
28 FriendListPanel::FriendListPanel(QWidget *parent)
29     : SidePanel(parent)
30 {
31     qDebug() << __PRETTY_FUNCTION__;
32     setType(SidePanel::FriendPanel);
33
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);
48
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);
59
60     connect(m_clearFilterButton, SIGNAL(clicked()),
61             this, SLOT(clearFriendListFilter()));
62     connect(this, SIGNAL(panelOpened()),
63             this, SLOT(clearFriendListFilter()));
64 }
65
66 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
67 {
68     qDebug() << __PRETTY_FUNCTION__;
69
70     QStringList newUserIDs;
71
72     foreach (User *user, friendList) {
73         FriendListItem *item = 0;
74         if (!m_friendListView->contains(user->userId())) {
75             item = new FriendListItem(m_friendListView);
76             item->setData(user);
77             m_friendListView->addWidget(user->userId(), item);
78
79             connect(item, SIGNAL(findFriend(QPointF)),
80                 this, SIGNAL(findFriend(QPointF)));
81         }
82         else {
83             item = m_friendListView->takeWidgetFromView(user->userId());
84             if (item) {
85                 item->setData(user);
86                 m_friendListView->addWidgetToView(item);
87             }
88         }
89
90         newUserIDs.append(user->userId());
91     }
92
93     m_friendListView->clearUnused(newUserIDs);
94 }
95
96 void FriendListPanel::clearFriendListFilter()
97 {
98     qDebug() << __PRETTY_FUNCTION__;
99
100     m_friendListHeaderWidget->hide();
101     m_friendListView->clearFilter();
102 }
103
104 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
105 {
106     qDebug() << __PRETTY_FUNCTION__;
107
108     m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
109
110     openPanel();
111     m_friendListHeaderWidget->show();
112     m_friendListView->filter(userIDs);
113 }