d33634ffff949f3dbac9f69909a517d8852776f7
[situare] / src / ui / userpanel.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 "userpanel.h"
23 #include "panelcommon.h"
24 #include "panelsliderbar.h"
25 #include "userinfo.h"
26
27 UserInfoPanel::UserInfoPanel(QWidget *parent)
28     : QWidget(parent)
29 {
30     qDebug() << __PRETTY_FUNCTION__;
31     m_userPanelVBox = new QVBoxLayout(this);
32     m_userPanelVBox->setMargin(0);
33     m_userPanelVBox->setContentsMargins(SLIDINGBAR_WIDTH+1, 0, SIDEBAR_WIDTH, 0);
34     m_userPanelVBox->setSpacing(0);
35     setLayout(m_userPanelVBox);
36
37     m_userInfo = new UserInfo(this);
38     m_userPanelVBox->addWidget(m_userInfo, 0, Qt::AlignCenter);
39
40     setAutoFillBackground(true);
41     QPalette pal = palette();
42     pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
43     setPalette(pal);
44
45     PanelSliderBar *m_userPanelSlidingBar = new PanelSliderBar(this, LEFT);
46     m_userPanelSlidingBar->move(USERPANEL_WIDTH - SLIDINGBAR_WIDTH, PANEL_TOP_Y);
47
48     m_userPanelStateMachine = new QStateMachine(this);
49     m_userPanelStateClosed = new QState(m_userPanelStateMachine);
50     m_userPanelStateClosed->assignProperty(this, "pos", QPoint(
51             USERPANEL_CLOSED_X, PANEL_TOP_Y));
52     m_userPanelStateMachine->setInitialState(m_userPanelStateClosed);
53
54     m_userPanelStateOpened = new QState(m_userPanelStateMachine);
55     m_userPanelStateOpened->assignProperty(this, "pos", QPoint(
56             USERPANEL_OPENED_X, PANEL_TOP_Y));
57
58     m_userPanelTransitionOpen = m_userPanelStateClosed->addTransition(
59             m_userPanelSlidingBar, SIGNAL(clicked()), m_userPanelStateOpened);
60     m_userPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos", this));
61
62     m_userPanelTransitionClose = m_userPanelStateOpened->addTransition(
63             m_userPanelSlidingBar, SIGNAL(clicked()), m_userPanelStateClosed);
64     m_userPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos", this));
65
66     connect(m_userInfo,SIGNAL(requestReverseGeo()),
67             this, SIGNAL(requestReverseGeo()));
68
69     connect(this, SIGNAL(reverseGeoReady(QString)),
70             m_userInfo, SIGNAL(reverseGeoReady(QString)));
71
72     connect(m_userInfo, SIGNAL(statusUpdate(QString,bool)),
73             this, SIGNAL(statusUpdate(QString,bool)));
74
75     connect(m_userInfo, SIGNAL(refreshUserData()),
76             this, SIGNAL(refreshUserData()));
77
78     m_userPanelStateMachine->start();
79     setObjectName("UserPanel");
80 }
81
82 void UserInfoPanel::userDataReceived(User *user)
83 {
84     qDebug() << __PRETTY_FUNCTION__ << " " << user->name();
85
86     m_userInfo->setUserName(user->name());
87     m_userInfo->setAvatar(user->profileImage());
88     m_userInfo->setMessageText(user->note());
89     m_userInfo->setAddress(user->address());
90     m_userInfo->setTime(user->timestamp());
91 }
92
93 void UserInfoPanel::reDrawUserPanel(int width, int height)
94 {
95     qDebug() << __PRETTY_FUNCTION__;
96     Q_UNUSED(width);
97     resize(USERPANEL_WIDTH,height + MARGIN_CORRECTION);
98 }