Added missing comments to list classes.
[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 "listview.h"
24 #include "friendlistitem.h"
25 #include "friendlistitemdelegate.h"
26 #include "panelcommon.h"
27 #include "sidepanel.h"
28
29 FriendListPanel::FriendListPanel(QWidget *parent)
30     : SidePanel(parent)
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33     setType(SidePanel::FriendPanel);
34
35     QHBoxLayout *filterLayout = new QHBoxLayout;
36     filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
37                                      FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
38     m_friendListHeaderWidget = new QWidget();
39     m_friendListHeaderWidget->setLayout(filterLayout);
40     m_friendListHeaderWidget->setAutoFillBackground(true);
41     QPalette labelPalette = m_friendListHeaderWidget->palette();
42     labelPalette.setColor(QPalette::Background, Qt::black);
43     m_friendListHeaderWidget->setPalette(labelPalette);
44     m_friendListHeaderWidget->hide();
45     m_friendListLabel = new QLabel(this);
46     m_clearFilterButton = new QPushButton(tr("Show all"));
47     filterLayout->addWidget(m_friendListLabel);
48     filterLayout->addWidget(m_clearFilterButton);
49     m_panelVBox->addWidget(m_friendListHeaderWidget);
50
51     QHBoxLayout *friendListLayout =  new QHBoxLayout;
52     friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
53                                          FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
54
55     m_friendListView = new ListView(this);
56     m_friendListView->setAutoFillBackground(false);
57     m_friendListView->viewport()->setAutoFillBackground(false);
58     m_friendListItemDelegate = new FriendListItemDelegate();
59     m_friendListView->setItemDelegate(m_friendListItemDelegate);
60
61     friendListLayout->addWidget(m_friendListView);
62     m_panelVBox->addLayout(friendListLayout);
63
64     connect(m_friendListView, SIGNAL(listItemClicked(QPointF)),
65             this, SIGNAL(findFriend(QPointF)));
66
67     connect(m_clearFilterButton, SIGNAL(clicked()),
68             this, SLOT(clearFriendListFilter()));
69     connect(this, SIGNAL(panelOpened()),
70             this, SLOT(clearFriendListFilter()));
71 }
72
73 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
74 {
75     qDebug() << __PRETTY_FUNCTION__;
76
77     QStringList newUserIDs;
78
79     foreach (User *user, friendList) {
80         FriendListItem *item = 0;
81         if (!m_friendListView->contains(user->userId())) {
82             item = new FriendListItem();
83             item->setUserData(user);
84             m_friendListView->addListItem(user->userId(), item);
85         }
86         else {
87             item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
88                     user->userId()));
89
90             if (item) {
91                 item->setUserData(user);
92                 m_friendListView->addListItemToView(item);
93             }
94         }
95
96         newUserIDs.append(user->userId());
97     }
98
99     m_friendListView->clearUnused(newUserIDs);
100 }
101
102 void FriendListPanel::clearFriendListFilter()
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105
106     m_friendListHeaderWidget->hide();
107     m_friendListView->clearFilter();
108 }
109
110 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
111 {
112     qDebug() << __PRETTY_FUNCTION__;
113
114     m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
115
116     openPanel();
117     m_friendListHeaderWidget->show();
118     m_friendListView->filter(userIDs);
119 }