2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
6 Henri Lampela - henri.lampela@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include "coordinates/geocoordinate.h"
24 #include "friendlistview.h"
25 #include "friendlistitem.h"
26 #include "friendlistitemdelegate.h"
27 #include "panelcommon.h"
28 #include "sidepanel.h"
29 #include "../routing/location.h"
30 #include "locationlistitem.h"
31 #include "locationlistview.h"
32 #include "extendedlistitemdelegate.h"
34 #include "friendlistpanel.h"
36 FriendListPanel::FriendListPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 setType(SidePanel::FriendPanel);
43 QHBoxLayout *filterLayout = new QHBoxLayout;
44 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
45 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
46 m_friendListHeaderWidget = new QWidget();
47 m_friendListHeaderWidget->setLayout(filterLayout);
48 m_friendListHeaderWidget->setAutoFillBackground(true);
49 QPalette labelPalette = m_friendListHeaderWidget->palette();
50 labelPalette.setColor(QPalette::Background, Qt::black);
51 m_friendListHeaderWidget->setPalette(labelPalette);
52 //m_friendListHeaderWidget->hide();
53 m_friendListLabel = new QLabel(this);
54 m_clearFilterButton = new QPushButton(tr("Show all"));
55 filterLayout->addWidget(m_friendListLabel);
56 filterLayout->addWidget(m_clearFilterButton);
57 m_panelVBox->addWidget(m_friendListHeaderWidget);
59 QVBoxLayout *friendListLayout = new QVBoxLayout;
60 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
61 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
63 m_friendListView = new FriendListView(this);
64 m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
66 //m_friendListView->hide();
68 m_locationListView = new LocationListView(this);
69 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
71 m_locationListView->hide();
73 friendListLayout->addWidget(m_friendListView);
74 //friendListLayout->addWidget(m_locationListView);
75 m_panelVBox->addLayout(friendListLayout);
77 connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
78 this, SIGNAL(friendItemClicked(GeoCoordinate)));
80 connect(m_clearFilterButton, SIGNAL(clicked()),
81 this, SLOT(clearFriendListFilter()));
83 connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
84 this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
86 connect(this, SIGNAL(panelClosed()),
87 this, SLOT(thisPanelClosed()));
89 connect(this, SIGNAL(panelOpened()),
90 this, SLOT(thisPanelOpened()));
94 void FriendListPanel::friendImageReady(User *user)
96 qDebug() << __PRETTY_FUNCTION__;
98 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
101 item->setAvatarImage(user->profileImage());
104 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
106 qDebug() << __PRETTY_FUNCTION__;
108 QStringList newUserIDs;
110 foreach (User *user, friendList) {
111 FriendListItem *item = 0;
112 if (!m_friendListView->contains(user->userId())) {
113 item = new FriendListItem();
114 item->setUserData(user);
115 m_friendListView->addListItem(user->userId(), item);
118 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
122 item->setUserData(user);
123 m_friendListView->addListItemToView(item);
127 newUserIDs.append(user->userId());
130 m_friendListView->clearUnused(newUserIDs);
133 void FriendListPanel::clearFriendListFilter()
135 qDebug() << __PRETTY_FUNCTION__;
137 m_friendListHeaderWidget->hide();
138 m_friendListView->clearFilter();
141 void FriendListPanel::keyPressEvent(QKeyEvent *event)
143 qDebug() << __PRETTY_FUNCTION__;
145 if (event->key() == Qt::Key_Backspace)
146 m_friendListNameRegExp.chop(1);
148 m_friendListNameRegExp.append(event->text());
150 if (!m_friendListNameRegExp.isEmpty())
151 m_friendListView->filter(m_friendListNameRegExp);
154 void FriendListPanel::locationDataReady(QList<Location> &result)
156 qDebug() << __PRETTY_FUNCTION__;
158 m_locationListView->clearList();
160 for (int i = 0; i < result.size(); ++i) {
161 LocationListItem *item = new LocationListItem();
162 item->setLocationData(result.at(i));
163 m_locationListView->addListItem(QString::number(i), item);
168 if (result.size() == 1) {
169 ListItem *item = m_locationListView->listItem(QString("0"));
172 m_locationListView->listItemClicked(item);
176 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
178 qDebug() << __PRETTY_FUNCTION__;
180 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
183 m_friendListHeaderWidget->show();
184 m_friendListView->filter(userIDs);
187 void FriendListPanel::thisPanelClosed()
189 qDebug() << __PRETTY_FUNCTION__;
194 void FriendListPanel::thisPanelOpened()
196 qDebug() << __PRETTY_FUNCTION__;
199 clearFriendListFilter();