Created a sliding user information panel
[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
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.
10
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.
15
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,
19     USA.
20  */
21
22 #include "friendlistpanel.h"
23 #include "friendlistview.h"
24 #include "friendlistitem.h"
25
26 FriendListPanel::FriendListPanel(QWidget *parent)
27     : QWidget(parent)
28 {
29     qDebug() << __PRETTY_FUNCTION__;
30     m_friendsPanelVBox = new QVBoxLayout(this);
31     this->setLayout(m_friendsPanelVBox);
32     m_friendsPanelExpandButton = new QPushButton("Friends", this);
33     m_friendsPanelVBox->addWidget(m_friendsPanelExpandButton);
34
35     m_friendListView = new FriendListView(this);
36     QScrollArea *friendListScroll = new QScrollArea(this);
37     friendListScroll->setWidget(m_friendListView);
38     friendListScroll->setWidgetResizable(true);
39     friendListScroll->viewport()->setAutoFillBackground(false);
40
41     m_friendsPanelVBox->addWidget(friendListScroll);
42
43     this->resize(420,600);
44
45     m_friendsPanelStateMachine = new QStateMachine(this);
46     m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
47     m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(800,0));
48     m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
49
50     m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
51     m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(400,0));
52
53     m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
54             m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateOpened);
55     m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos"));
56
57     m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
58             m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateClosed);
59     m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos"));
60
61     m_friendsPanelStateMachine->start();
62 }
63
64 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
65 {
66     qDebug() << __PRETTY_FUNCTION__;
67
68     m_friendListView->clear();
69
70     foreach (User *user, friendList) {
71         FriendListItem *item = new FriendListItem(m_friendListView);
72         item->setData(user);
73         m_friendListView->addWidget(item);
74     }
75 }
76
77 void FriendListPanel::reDrawFriendsPanel(int width, int height)
78 {
79     qDebug() << __PRETTY_FUNCTION__;
80 }