- /*
+/*
Situare - A location system for Facebook
Copyright (C) 2010 Ixonos Plc. Authors:
Kaj Wallin - kaj.wallin@ixonos.com
+ Henri Lampela - henri.lampela@ixonos.com
+ Pekka Nissinen - pekka.nissinen@ixonos.com
+ Sami Rämö - sami.ramo@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
along with Situare; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
- */
+*/
-#include "friendlistpanel.h"
-#include "friendlistview.h"
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+
+#include "coordinates/geocoordinate.h"
#include "friendlistitem.h"
+#include "friendlistitemdelegate.h"
+#include "friendlistview.h"
+#include "imagebutton.h"
#include "panelcommon.h"
-#include "panelsliderbar.h"
+#include "user/user.h"
+
+#include "friendlistpanel.h"
FriendListPanel::FriendListPanel(QWidget *parent)
- : QWidget(parent)
+ : PanelBase(parent),
+ m_mainWindowIsTopmost(false),
+ m_somePanelIsOpen(false)
{
qDebug() << __PRETTY_FUNCTION__;
- m_friendsPanelVBox = new QVBoxLayout(this);
- m_friendsPanelVBox->setMargin(0);
- m_friendsPanelVBox->setContentsMargins(SLIDINGBAR_WIDTH+1, 0, SIDEBAR_WIDTH, 0);
- m_friendsPanelVBox->setSpacing(0);
- setLayout(m_friendsPanelVBox);
-
- m_panelBase = new QWidget(this);
- m_panelBase->setLayout(m_friendsPanelVBox);
- m_panelBase->move(TOP_CORNER_X + SLIDINGBAR_WIDTH,PANEL_TOP_Y);
- m_panelBase->resize(FRIENDPANEL_WIDTH, FRIENDPANEL_HEIGHT);
-
- QPalette pal = palette();
- pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
- m_panelBase->setPalette(pal);
- m_panelBase->setAutoFillBackground(true);
+ const int FRIENDPANEL_FILTER_MARGIN_LEFT = PANEL_MARGIN_LEFT + 4;
+ const int FRIENDPANEL_FILTER_MARGIN_TOP = 0;
+ const int FRIENDPANEL_FILTER_MARGIN_RIGHT = PANEL_MARGIN_RIGHT + MAEMO5_SCROLLBAR_WIDTH + 4;
+ const int FRIENDPANEL_FILTER_MARGIN_BOTTOM = 0;
+
+ // --- HEADER, HOW MANY FRIENDS ARE SELECTED ---
+ m_headerWidget = new QWidget();
+
+ m_headerWidget->hide();
+ m_headerWidget->setAutoFillBackground(true);
+
+ QPalette headerPalette = m_headerWidget->palette();
+ headerPalette.setColor(QPalette::Background, Qt::black);
+ m_headerWidget->setPalette(headerPalette);
+
+ QHBoxLayout *headerLayout = new QHBoxLayout();
+ m_headerWidget->setLayout(headerLayout);
+ headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT,
+ FRIENDPANEL_FILTER_MARGIN_TOP,
+ FRIENDPANEL_FILTER_MARGIN_RIGHT,
+ FRIENDPANEL_FILTER_MARGIN_BOTTOM);
+
+ m_headerLabel = new QLabel(this);
+ headerLayout->addWidget(m_headerLabel, 0, Qt::AlignCenter);
+
+ // --- FRIEND LIST ---
m_friendListView = new FriendListView(this);
- QScrollArea *friendListScroll = new QScrollArea(this);
- friendListScroll->setWidgetResizable(false);
- friendListScroll->setWidget(m_friendListView);
- friendListScroll->viewport()->setAutoFillBackground(false);
- friendListScroll->widget()->setAutoFillBackground(false);
+ m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
+
+ QVBoxLayout *listViewLayout = new QVBoxLayout;
+ listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+ PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
+ listViewLayout->addWidget(m_friendListView);
+
+ connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
+ this, SIGNAL(findFriend(GeoCoordinate)));
+
+ connect(m_friendListView, SIGNAL(listItemSelectionChanged()),
+ this, SLOT(setRouteButtonDisabled()));
+
+ connect(m_friendListView, SIGNAL(listItemSelectionChanged()),
+ this, SLOT(onListItemSelectionChanged()));
+
+ // --- FOOTER, TEXT BASED FILTERING ---
+ QHBoxLayout *footerLayout = new QHBoxLayout();
+
+ m_filterField = new QLineEdit;
+ footerLayout->addWidget(m_filterField);
+
+ connect(m_filterField, SIGNAL(returnPressed()),
+ this, SLOT(clearTextFiltering()));
+
+ connect(m_filterField, SIGNAL(textChanged(QString)),
+ this, SLOT(filterTextChanged(QString)));
+
+ m_clearTextFilteringButton = new QPushButton();
+ footerLayout->addWidget(m_clearTextFilteringButton);
+ m_clearTextFilteringButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
+
+ connect(m_clearTextFilteringButton, SIGNAL(clicked()),
+ this, SLOT(clearTextFiltering()));
+
+ connect(qApp, SIGNAL(topmostWindowChanged(bool)),
+ this, SLOT(topmostWindowChanged(bool)));
+
+ // --- MAIN LAYOUT ---
+ QVBoxLayout *friendListPanelLayout = new QVBoxLayout();
+ friendListPanelLayout->setMargin(0);
+ friendListPanelLayout->setSpacing(0);
+ setLayout(friendListPanelLayout);
+
+ friendListPanelLayout->addWidget(m_headerWidget);
+ friendListPanelLayout->addLayout(listViewLayout);
+ friendListPanelLayout->addLayout(footerLayout);
- m_friendsPanelVBox->addWidget(friendListScroll);
+ // --- CONTEXT BUTTONS ---
+ m_routeButton = new ImageButton(":res/images/route_to_friend.png",
+ ":res/images/route_to_friend_s.png",
+ ":res/images/route_to_friend_d.png", this);
+ m_routeButton->setDisabled(true);
+ connect(m_routeButton, SIGNAL(clicked()),
+ this, SLOT(routeToSelectedFriend()));
- m_friendsPanelSlidingBar = new PanelSliderBar(this, RIGHT);
- m_friendsPanelSlidingBar->move(TOP_CORNER_X, PANEL_TOP_Y);
+ m_clearGroupFilteringButton = new ImageButton(":res/images/filtered.png",
+ ":res/images/filtered_s.png",
+ ":res/images/filtered_d.png", this);
+ m_clearGroupFilteringButton->setCheckable(true);
+ m_clearGroupFilteringButton->setDisabled(true);
+ connect(m_clearGroupFilteringButton, SIGNAL(clicked()),
+ this, SLOT(clearFiltering()));
- m_friendsPanelStateMachine = new QStateMachine(this);
- m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
- m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
- FRIENDPANEL_CLOSED_X, PANEL_TOP_Y));
- m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
+ m_itemButtonsLayout->addWidget(m_routeButton);
+ m_genericButtonsLayout->addWidget(m_clearGroupFilteringButton);
+}
+
+void FriendListPanel::anyPanelClosed()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
- m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
- FRIENDPANEL_OPENED_X, PANEL_TOP_Y));
+ m_somePanelIsOpen = false;
+ updateKeyboardGrabbing();
- m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
- m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateOpened);
- m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos", this));
+ clearFiltering();
- m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
- m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateClosed);
- m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos", this));
+ m_friendListView->clearItemSelection();
+ setRouteButtonDisabled();
+}
+
+void FriendListPanel::anyPanelOpened()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_somePanelIsOpen = true;
+ updateKeyboardGrabbing();
+}
+
+void FriendListPanel::clearFiltering()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- m_friendsPanelStateMachine->start();
- setObjectName("FriendsPanel");
+ m_headerWidget->hide();
+ m_clearGroupFilteringButton->setChecked(false);
+ m_clearGroupFilteringButton->setDisabled(true);
+ m_friendListView->clearFilter();
+ clearTextFiltering();
+}
+
+void FriendListPanel::clearTextFiltering()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ // clearing the filtering text field does cause also hiding the filtering layout
+ m_filterField->clear();
+}
+
+void FriendListPanel::filterTextChanged(const QString &text)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_filterField->isHidden() && !text.isEmpty())
+ setFilteringLayoutVisibility(true);
+ else if (m_filterField->isVisible() && text.isEmpty())
+ setFilteringLayoutVisibility(false);
+
+ m_friendListView->filter(text);
+}
+
+void FriendListPanel::friendImageReady(User *user)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
+
+ if (item)
+ item->setAvatarImage(user->profileImage());
}
void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
{
qDebug() << __PRETTY_FUNCTION__;
- m_friendListView->clear();
+ QStringList newUserIDs;
foreach (User *user, friendList) {
- FriendListItem *item = new FriendListItem(m_friendListView);
- item->setData(user);
- connect(item, SIGNAL(findFriend(QPointF)),
- this, SIGNAL(findFriend(QPointF)));
- m_friendListView->addWidget(item);
+ FriendListItem *item = 0;
+ if (!m_friendListView->contains(user->userId())) {
+ item = new FriendListItem();
+ item->setUserData(user);
+ m_friendListView->addListItem(user->userId(), item);
+ } else {
+ item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
+ user->userId()));
+
+ if (item) {
+ item->setUserData(user);
+ m_friendListView->addListItemToView(item);
+ }
+ }
+
+ newUserIDs.append(user->userId());
}
+
+ m_friendListView->clearUnused(newUserIDs);
+}
+
+void FriendListPanel::hideEvent(QHideEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QWidget::hideEvent(event);
+ updateKeyboardGrabbing();
+ clearFiltering();
+
+ m_friendListView->clearItemSelection();
+ setRouteButtonDisabled();
+}
+
+void FriendListPanel::routeToSelectedFriend()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ FriendListItem *item = dynamic_cast<FriendListItem *>(m_friendListView->selectedItem());
+
+ if (item)
+ emit routeToFriend(item->coordinates());
+}
+
+void FriendListPanel::setFilteringLayoutVisibility(bool visible)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_filterField->setVisible(visible);
+ m_clearTextFilteringButton->setVisible(visible);
}
-void FriendListPanel::reDrawFriendsPanel(int width, int height)
+void FriendListPanel::updateKeyboardGrabbing()
{
qDebug() << __PRETTY_FUNCTION__;
- resize(FRIENDPANEL_WIDTH + SLIDINGBAR_WIDTH,height + MARGIN_CORRECTION);
- m_panelBase->resize(FRIENDPANEL_WIDTH, height + MARGIN_CORRECTION);
- m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
- width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
- m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
- width - FRIENDPANEL_WIDTH - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
- move(width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y);
+
+ if (!m_mainWindowIsTopmost || !m_somePanelIsOpen || !isVisible()) {
+ if (QWidget::keyboardGrabber() == m_filterField)
+ m_filterField->releaseKeyboard();
+ } else if (m_mainWindowIsTopmost && m_somePanelIsOpen && isVisible()) {
+ if (QWidget::keyboardGrabber() != m_filterField)
+ m_filterField->grabKeyboard();
+ }
+}
+
+void FriendListPanel::setRouteButtonDisabled()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_routeButton->setDisabled(m_friendListView->selectedItems().isEmpty());
+}
+
+void FriendListPanel::showEvent(QShowEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QWidget::showEvent(event);
+ updateKeyboardGrabbing();
+ setFilteringLayoutVisibility(false);
+}
+
+void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_headerLabel->setText(tr("Selected: %1").arg(userIDs.count()));
+
+ m_headerWidget->show();
+ m_clearGroupFilteringButton->setDisabled(false);
+ m_clearGroupFilteringButton->setChecked(true);
+ m_friendListView->filter(userIDs);
+
+ clearTextFiltering();
+
+ emit openPanelRequested(this);
+}
+
+void FriendListPanel::topmostWindowChanged(bool mainWindowIsTopmost)
+{
+ qDebug() << __PRETTY_FUNCTION__ << mainWindowIsTopmost;
+
+ m_mainWindowIsTopmost = mainWindowIsTopmost;
+ updateKeyboardGrabbing();
}