Added sliding bars to the panels
[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     this->setLayout(m_friendsPanelVBox);
33     m_friendsPanelExpandButton = new QPushButton("Friends", this);
34     m_friendsPanelVBox->addWidget(m_friendsPanelExpandButton);
35
36     m_friendListView = new FriendListView(this);
37     QScrollArea *friendListScroll = new QScrollArea(this);
38     friendListScroll->setWidget(m_friendListView);
39     friendListScroll->setWidgetResizable(true);
40     friendListScroll->viewport()->setAutoFillBackground(false);
41
42     this->setAutoFillBackground(true);
43     QPalette pal = palette();
44     pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
45     setPalette(pal);
46
47     m_friendsPanelVBox->addWidget(friendListScroll);
48
49     m_friendsPanelStateMachine = new QStateMachine(this);
50     m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
51     m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
52             FRIENDPANEL_CLOSED_X, PANEL_TOP_Y));
53     m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
54
55     m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
56     m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
57             FRIENDPANEL_OPENED_X, PANEL_TOP_Y));
58
59     m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
60             this, SIGNAL(clicked()), m_friendsPanelStateOpened);
61     m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos", this));
62
63     m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
64             this, SIGNAL(clicked()), m_friendsPanelStateClosed);
65     m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos", this));
66
67     m_friendsPanelStateMachine->start();
68     this->setObjectName("FriendsPanel");
69
70     m_friendsPanelSlidingBar = new QWidget(this);
71     m_friendsPanelSlidingBar->setObjectName("FriendsPanelSlidingBar");
72     m_friendsPanelSlidingBar->setStyleSheet(QString(
73             "#FriendsPanelSlidingBar{background-image: url(:/res/images/sliding_bar_right.png)}"));
74     m_friendsPanelSlidingBar->resize(SLIDINGBAR_WIDTH, SLIDINGBAR_HEIGHT);
75     m_friendsPanelSlidingBar->move(0, PANEL_TOP_Y);
76 }
77
78 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
79 {
80     qDebug() << __PRETTY_FUNCTION__;
81
82     m_friendListView->clear();
83
84     foreach (User *user, friendList) {
85         FriendListItem *item = new FriendListItem(m_friendListView);
86         item->setData(user);
87         m_friendListView->addWidget(item);
88     }
89 }
90
91 void FriendListPanel::reDrawFriendsPanel(int width, int height)
92 {
93     qDebug() << __PRETTY_FUNCTION__;
94     this->resize(FRIENDPANEL_WIDTH,height + MARGIN_CORRECTION);
95     m_friendsPanelSlidingBar->resize(SLIDINGBAR_WIDTH, SLIDINGBAR_HEIGHT);
96     m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
97             width-PANEL_PEEK_AMOUNT, PANEL_TOP_Y));
98     m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
99             width - FRIENDPANEL_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
100     this->move(width-PANEL_PEEK_AMOUNT, PANEL_TOP_Y);
101 }
102
103 void FriendListPanel::mouseReleaseEvent(QMouseEvent *)
104 {
105     qDebug() << __PRETTY_FUNCTION__;
106     emit clicked();
107 }
108
109 void FriendListPanel::paintEvent(QPaintEvent *)
110 {
111     qDebug() << __PRETTY_FUNCTION__;
112
113     QStyleOption option;
114     option.init(this);
115
116     QStylePainter painter(this);
117     style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
118 }