Added missing default values to PanelBar, PanelBase and TabbedPanel constructors
[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         Henri Lampela - henri.lampela@ixonos.com
7         Pekka Nissinen - pekka.nissinen@ixonos.com
8
9     Situare is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License
11     version 2 as published by the Free Software Foundation.
12
13     Situare is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with Situare; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21     USA.
22  */
23
24 #include "coordinates/geocoordinate.h"
25 #include "listview.h"
26 #include "friendlistitem.h"
27 #include "friendlistitemdelegate.h"
28 #include "panelcommon.h"
29
30 #include "friendlistpanel.h"
31
32 FriendListPanel::FriendListPanel(QWidget *parent)
33     : QWidget(parent)
34 {
35     qDebug() << __PRETTY_FUNCTION__;
36
37     QVBoxLayout *friendListPanelLayout = new QVBoxLayout();
38     friendListPanelLayout->setMargin(0);
39     friendListPanelLayout->setSpacing(0);
40     friendListPanelLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
41     setLayout(friendListPanelLayout);
42
43     QHBoxLayout *filterLayout = new QHBoxLayout();
44     filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
45                                      FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
46
47     m_friendListHeaderWidget = new QWidget();
48     m_friendListHeaderWidget->setLayout(filterLayout);
49     m_friendListHeaderWidget->setAutoFillBackground(true);
50
51     QPalette labelPalette = m_friendListHeaderWidget->palette();
52     labelPalette.setColor(QPalette::Background, Qt::black);
53
54     m_friendListHeaderWidget->setPalette(labelPalette);
55     m_friendListHeaderWidget->hide();
56     m_friendListLabel = new QLabel(this);
57     m_clearFilterButton = new QPushButton(tr("Show all"));
58
59     filterLayout->addWidget(m_friendListLabel);
60     filterLayout->addWidget(m_clearFilterButton);
61
62     m_friendListView = new ListView(this);
63
64     m_friendListView->setAutoFillBackground(false);
65     m_friendListView->viewport()->setAutoFillBackground(false);
66     m_friendListItemDelegate = new FriendListItemDelegate();
67     m_friendListView->setItemDelegate(m_friendListItemDelegate);
68
69     friendListPanelLayout->addWidget(m_friendListHeaderWidget);
70     friendListPanelLayout->addWidget(m_friendListView);
71
72     connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
73             this, SIGNAL(findFriend(GeoCoordinate)));
74
75     connect(m_clearFilterButton, SIGNAL(clicked()),
76             this, SLOT(clearFriendListFilter()));
77
78 //    connect(this, SIGNAL(panelOpened()),
79 //            this, SLOT(clearFriendListFilter()));
80 }
81
82 void FriendListPanel::friendImageReady(User *user)
83 {
84     qDebug() << __PRETTY_FUNCTION__;
85
86     FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
87
88     if (item)
89         item->setAvatarImage(user->profileImage());
90 }
91
92 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
93 {
94     qDebug() << __PRETTY_FUNCTION__;
95
96     QStringList newUserIDs;
97
98     foreach (User *user, friendList) {
99         FriendListItem *item = 0;
100         if (!m_friendListView->contains(user->userId())) {
101             item = new FriendListItem();
102             item->setUserData(user);
103             m_friendListView->addListItem(user->userId(), item);
104         } else {
105             item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
106                     user->userId()));
107
108             if (item) {
109                 item->setUserData(user);
110                 m_friendListView->addListItemToView(item);
111             }
112         }
113
114         newUserIDs.append(user->userId());
115     }
116
117     m_friendListView->clearUnused(newUserIDs);
118 }
119
120 void FriendListPanel::clearFriendListFilter()
121 {
122     qDebug() << __PRETTY_FUNCTION__;
123
124     m_friendListHeaderWidget->hide();
125     m_friendListView->clearFilter();
126 }
127
128 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
129 {
130     qDebug() << __PRETTY_FUNCTION__;
131
132     m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
133
134 //    openPanel();
135     m_friendListHeaderWidget->show();
136     m_friendListView->filter(userIDs);
137 }