Merge branch 'master' of https://vcs.maemo.org/git/situare into list_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 #include "panelcommon.h"
26
27 FriendListPanel::FriendListPanel(QWidget *parent)
28     : QWidget(parent)
29 {
30     qDebug() << __PRETTY_FUNCTION__;
31     m_friendsPanelVBox = new QVBoxLayout(this);
32     m_friendsPanelVBox->setMargin(0);
33     m_friendsPanelVBox->setSpacing(0);
34     this->setLayout(m_friendsPanelVBox);
35     m_friendsPanelExpandButton = new QPushButton("Friends", this);
36     m_friendsPanelVBox->addWidget(m_friendsPanelExpandButton);
37
38     m_friendListView = new FriendListView(this);
39     QScrollArea *friendListScroll = new QScrollArea(this);
40     friendListScroll->setWidget(m_friendListView);
41     friendListScroll->viewport()->setAutoFillBackground(false);
42     friendListScroll->widget()->setAutoFillBackground(false);
43
44     m_friendsPanelVBox->addWidget(friendListScroll);
45
46     m_friendsPanelStateMachine = new QStateMachine(this);
47     m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
48     m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
49             FRIENDPANEL_CLOSED_X, PANEL_TOP_Y));
50     m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
51
52     m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
53     m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
54             FRIENDPANEL_OPENED_X, PANEL_TOP_Y));
55
56     m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
57             m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateOpened);
58     m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos"));
59
60     m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
61             m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateClosed);
62     m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos"));
63
64     m_friendsPanelStateMachine->start();
65
66     //Debug
67     QList<User *> friendList;
68     for (int i = 0; i < 10; ++i) {
69         User *user = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name Name Name Naem"),
70                               QString("Hello world! Hello world! Hello world! Hello world! "),
71                               QUrl(), QString("2 days ago"), false, QString("id"), QString("km"),
72                               600);
73         user->setProfileImage(QPixmap(":/res/images/face.gif"));
74         friendList.append(user);
75     }
76     friendInfoReceived(friendList);
77
78     this->setObjectName("UserPanel");
79     //this->setStyleSheet(QString("#UserPanel{background-image: url(:/res/images/personal_info_bckgrnd.png)}"));
80
81     this->setAutoFillBackground(true);
82     QPalette pal = palette();
83     pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
84     setPalette(pal);
85 }
86
87 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
88 {
89     qDebug() << __PRETTY_FUNCTION__;
90
91     //m_friendListView->clear();
92
93     foreach (User *user, friendList) {
94         FriendListItem *item = new FriendListItem(m_friendListView);
95         item->setData(user);
96         m_friendListView->addWidget(item);
97         FriendListItem *item2 = new FriendListItem(m_friendListView);
98         item2->setData(user);
99         m_friendListView->addWidget(item2);
100         FriendListItem *item3 = new FriendListItem(m_friendListView);
101         item3->setData(user);
102         m_friendListView->addWidget(item3);
103         FriendListItem *item4 = new FriendListItem(m_friendListView);
104         item4->setData(user);
105         m_friendListView->addWidget(item4);
106     }
107 }
108
109 void FriendListPanel::reDrawFriendsPanel(int width, int height)
110 {
111     qDebug() << __PRETTY_FUNCTION__;
112     this->resize(FRIENDPANEL_WIDTH,height + MARGIN_CORRECTION);
113     m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
114             width-PANEL_PEEK_AMOUNT, PANEL_TOP_Y));
115     m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
116             width - FRIENDPANEL_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
117     this->move(width-PANEL_PEEK_AMOUNT, PANEL_TOP_Y);
118 }
119
120 void FriendListPanel::paintEvent(QPaintEvent *)
121 {
122     QStyleOption option;
123     option.init(this);
124
125     QStylePainter painter(this);
126     style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
127 }