Added new scalable panels, deleted obsolite bitmaps and made some minor cosmetic...
[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(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);
49
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);
61
62     connect(m_clearFilterButton, SIGNAL(clicked()),
63             this, SLOT(clearFriendListFilter()));
64     connect(this, SIGNAL(panelOpened()),
65             this, SLOT(clearFriendListFilter()));
66 }
67
68 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71
72     QStringList newUserIDs;
73
74     foreach (User *user, friendList) {
75         FriendListItem *item = 0;
76         if (!m_friendListView->contains(user->userId())) {
77             item = new FriendListItem(m_friendListView);
78             item->setData(user);
79             m_friendListView->addWidget(user->userId(), item);
80
81             connect(item, SIGNAL(findFriend(QPointF)),
82                 this, SIGNAL(findFriend(QPointF)));
83         }
84         else {
85             item = m_friendListView->takeWidgetFromView(user->userId());
86             if (item) {
87                 item->setData(user);
88                 m_friendListView->addWidgetToView(item);
89             }
90         }
91
92         newUserIDs.append(user->userId());
93     }
94
95     m_friendListView->clearUnused(newUserIDs);
96 }
97
98 void FriendListPanel::clearFriendListFilter()
99 {
100     qDebug() << __PRETTY_FUNCTION__;
101
102     m_friendListHeaderWidget->hide();
103     m_friendListView->clearFilter();
104 }
105
106 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
107 {
108     qDebug() << __PRETTY_FUNCTION__;
109
110     m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
111
112     openPanel();
113     m_friendListHeaderWidget->show();
114     m_friendListView->filter(userIDs);
115 }