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