2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
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.
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.
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,
22 #include "friendlistpanel.h"
23 #include "friendlistview.h"
24 #include "friendlistitem.h"
25 #include "panelcommon.h"
26 #include "panelsliderbar.h"
28 FriendListPanel::FriendListPanel(QWidget *parent)
31 qDebug() << __PRETTY_FUNCTION__;
32 m_friendsPanelVBox = new QVBoxLayout(this);
33 m_friendsPanelVBox->setMargin(0);
34 m_friendsPanelVBox->setContentsMargins(SLIDINGBAR_WIDTH+1, 0, SIDEBAR_WIDTH, 0);
35 m_friendsPanelVBox->setSpacing(0);
36 setLayout(m_friendsPanelVBox);
38 m_clearFilterButton = new QPushButton("Clear filtering");
39 m_clearFilterButton->hide();
40 m_friendsPanelVBox->addWidget(m_clearFilterButton, 0, Qt::AlignCenter);
42 m_panelBase = new QWidget(this);
43 m_panelBase->setLayout(m_friendsPanelVBox);
44 m_panelBase->move(TOP_CORNER_X + SLIDINGBAR_WIDTH,PANEL_TOP_Y);
45 m_panelBase->resize(FRIENDPANEL_WIDTH, FRIENDPANEL_HEIGHT);
47 QPalette pal = palette();
48 pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
49 m_panelBase->setPalette(pal);
50 m_panelBase->setAutoFillBackground(true);
52 m_friendListView = new FriendListView(this);
53 QScrollArea *friendListScroll = new QScrollArea(this);
54 friendListScroll->setWidgetResizable(false);
55 friendListScroll->setWidget(m_friendListView);
56 friendListScroll->viewport()->setAutoFillBackground(false);
57 friendListScroll->widget()->setAutoFillBackground(false);
59 m_friendsPanelVBox->addWidget(friendListScroll);
61 m_friendsPanelSlidingBar = new PanelSliderBar(this, RIGHT);
62 m_friendsPanelSlidingBar->move(TOP_CORNER_X, PANEL_TOP_Y);
64 m_friendsPanelStateMachine = new QStateMachine(this);
65 m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
66 m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
67 FRIENDPANEL_CLOSED_X, PANEL_TOP_Y));
68 m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
70 m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
71 m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
72 FRIENDPANEL_OPENED_X, PANEL_TOP_Y));
74 m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
75 m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateOpened);
76 m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos", this));
78 m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
79 m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateClosed);
80 m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos", this));
82 m_friendsPanelStateMachine->start();
83 setObjectName("FriendsPanel");
85 connect(m_clearFilterButton, SIGNAL(clicked()), this, SLOT(clearFriendListFilter()));
88 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
90 qDebug() << __PRETTY_FUNCTION__;
92 m_clearFilterButton->hide();
93 m_friendListView->clear();
95 foreach (User *user, friendList) {
96 FriendListItem *item = new FriendListItem(m_friendListView);
98 m_friendListView->addWidget(user->userId(), item);
99 qDebug() << __PRETTY_FUNCTION__ << user->userId();
100 connect(item, SIGNAL(findFriend(QPointF)),
101 this, SIGNAL(findFriend(QPointF)));
104 QTimer::singleShot(3000, this, SLOT(showFriendsInList()));
105 QTimer::singleShot(6000, this, SLOT(showFriendsInList()));
108 void FriendListPanel::reDrawFriendsPanel(int width, int height)
110 qDebug() << __PRETTY_FUNCTION__;
111 resize(FRIENDPANEL_WIDTH + SLIDINGBAR_WIDTH,height + MARGIN_CORRECTION);
112 m_panelBase->resize(FRIENDPANEL_WIDTH, height + MARGIN_CORRECTION);
113 m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
114 width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
115 m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
116 width - FRIENDPANEL_WIDTH - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
117 move(width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y);
120 void FriendListPanel::clearFriendListFilter()
122 m_clearFilterButton->hide();
123 m_friendListView->clearFilter();
126 void FriendListPanel::showFriendsInList(/*const QList<QString> &userIDs*/)
128 QList<QString> userIDs;
129 static int count = 0;
132 userIDs.append("100000919753435");
134 userIDs.append("783074081");
138 m_clearFilterButton->show();
139 m_friendListView->filter(userIDs);