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"
25 #include "friendlistitem.h"
26 #include "friendlistitemdelegate.h"
27 #include "panelcommon.h"
28 #include "sidepanel.h"
30 #include "friendlistpanel.h"
32 FriendListPanel::FriendListPanel(QWidget *parent)
35 qDebug() << __PRETTY_FUNCTION__;
36 setType(SidePanel::FriendPanel);
38 QHBoxLayout *filterLayout = new QHBoxLayout;
39 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
40 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
41 m_friendListHeaderWidget = new QWidget();
42 m_friendListHeaderWidget->setLayout(filterLayout);
43 m_friendListHeaderWidget->setAutoFillBackground(true);
44 QPalette labelPalette = m_friendListHeaderWidget->palette();
45 labelPalette.setColor(QPalette::Background, Qt::black);
46 m_friendListHeaderWidget->setPalette(labelPalette);
47 m_friendListHeaderWidget->hide();
48 m_friendListLabel = new QLabel(this);
49 m_clearFilterButton = new QPushButton(tr("Show all"));
50 filterLayout->addWidget(m_friendListLabel);
51 filterLayout->addWidget(m_clearFilterButton);
52 m_panelVBox->addWidget(m_friendListHeaderWidget);
54 QHBoxLayout *friendListLayout = new QHBoxLayout;
55 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
56 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
58 m_friendListView = new ListView(this);
59 m_friendListView->setAutoFillBackground(false);
60 m_friendListView->viewport()->setAutoFillBackground(false);
61 m_friendListItemDelegate = new FriendListItemDelegate();
62 m_friendListView->setItemDelegate(m_friendListItemDelegate);
64 friendListLayout->addWidget(m_friendListView);
65 m_panelVBox->addLayout(friendListLayout);
67 connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
68 this, SIGNAL(findFriend(GeoCoordinate)));
70 connect(m_clearFilterButton, SIGNAL(clicked()),
71 this, SLOT(clearFriendListFilter()));
72 connect(this, SIGNAL(panelOpened()),
73 this, SLOT(clearFriendListFilter()));
75 /// @todo remove old filterLayout when new panel are merged
77 //////////////////////////////////////////////////////////////////////////
78 // NOTE! Do not mix the new filtering layout below with the old one above
79 //////////////////////////////////////////////////////////////////////////
82 QHBoxLayout *filteringLayout = new QHBoxLayout();
83 m_panelVBox->addLayout(filteringLayout);
85 // line edit for filtering
86 m_filterField = new QLineEdit;
87 filteringLayout->addWidget(m_filterField);
89 connect(m_filterField, SIGNAL(returnPressed()),
90 this, SLOT(clearFiltering()));
92 connect(m_filterField, SIGNAL(textChanged(QString)),
93 this, SLOT(filterTextChanged(QString)));
95 // button for clearing the filtering
96 m_filterClearButton = new QPushButton();
97 filteringLayout->addWidget(m_filterClearButton);
98 m_filterClearButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
100 connect(m_filterClearButton, SIGNAL(clicked()),
101 this, SLOT(clearFiltering()));
104 void FriendListPanel::clearFiltering()
106 qDebug() << __PRETTY_FUNCTION__;
108 // clearing the filtering text field does cause also hiding the filtering layout
109 m_filterField->clear();
112 void FriendListPanel::clearFriendListFilter()
114 qDebug() << __PRETTY_FUNCTION__;
116 m_friendListHeaderWidget->hide();
117 m_friendListView->clearFilter();
120 void FriendListPanel::filterTextChanged(const QString &text)
122 qDebug() << __PRETTY_FUNCTION__;
124 if (m_filterField->isHidden() && !text.isEmpty())
125 setFilteringLayoutVisible(true);
126 else if (m_filterField->isVisible() && text.isEmpty())
127 setFilteringLayoutVisible(false);
130 void FriendListPanel::friendImageReady(User *user)
132 qDebug() << __PRETTY_FUNCTION__;
134 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
137 item->setAvatarImage(user->profileImage());
140 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
142 qDebug() << __PRETTY_FUNCTION__;
144 QStringList newUserIDs;
146 foreach (User *user, friendList) {
147 FriendListItem *item = 0;
148 if (!m_friendListView->contains(user->userId())) {
149 item = new FriendListItem();
150 item->setUserData(user);
151 m_friendListView->addListItem(user->userId(), item);
154 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
158 item->setUserData(user);
159 m_friendListView->addListItemToView(item);
163 newUserIDs.append(user->userId());
166 m_friendListView->clearUnused(newUserIDs);
169 void FriendListPanel::setFilteringLayoutVisible(bool visible)
171 qDebug() << __PRETTY_FUNCTION__;
173 m_filterField->setVisible(visible);
174 m_filterClearButton->setVisible(visible);
177 void FriendListPanel::showEvent(QShowEvent *event)
179 qWarning() << __PRETTY_FUNCTION__;
181 QWidget::showEvent(event);
183 if (QWidget::keyboardGrabber() != qobject_cast<QWidget *>(m_filterField)) {
184 qWarning() << __PRETTY_FUNCTION__ << "grabbing the keyboard for filter text field";
185 m_filterField->grabKeyboard();
186 setFilteringLayoutVisible(false);
190 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
192 qDebug() << __PRETTY_FUNCTION__;
194 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
197 m_friendListHeaderWidget->show();
198 m_friendListView->filter(userIDs);