9700b7c8d0705efbec537b9bc96993fe62d54746
[situare] / src / ui / messagepanel.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Jussi Laitinen - jussi.laitinen@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 <QDebug>
23 #include <QVBoxLayout>
24
25 #include "extendedlistitemdelegate.h"
26 #include "imagebutton.h"
27 #include "messagelistitem.h"
28 #include "messagelistview.h"
29 #include "panelcommon.h"
30 #include "situareservice/message.h"
31
32 #include "messagepanel.h"
33
34 MessagePanel::MessagePanel(QWidget *parent)
35     : PanelBase(parent)
36 {
37     qDebug() << __PRETTY_FUNCTION__;
38
39     // --- MAIN LAYOUT ---
40     QVBoxLayout *messageLayout = new QVBoxLayout;
41     messageLayout->setMargin(0);
42     messageLayout->setSpacing(0);
43     setLayout(messageLayout);
44
45     QVBoxLayout *listViewLayout = new QVBoxLayout;
46     listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
47                                        PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
48     messageLayout->addLayout(listViewLayout);
49
50     ImageButton *refreshMessagesButton = new ImageButton(":/res/images/refresh.png",
51                                                               ":/res/images/refresh_s.png",
52                                                               "", this);
53     connect(refreshMessagesButton, SIGNAL(clicked()),
54             this, SIGNAL(requestMessages()));
55
56     m_messageListView = new MessageListView(this);
57     m_messageListView->setItemDelegate(new ExtendedListItemDelegate(this));
58     listViewLayout->addWidget(m_messageListView);
59
60     m_genericButtonsLayout->addWidget(refreshMessagesButton);
61 }
62
63 void MessagePanel::anyPanelClosed()
64 {
65     qDebug() << __PRETTY_FUNCTION__;
66
67     m_messageListView->clearItemSelection();
68 }
69
70 void MessagePanel::hideEvent(QHideEvent *event)
71 {
72     qDebug() << __PRETTY_FUNCTION__;
73
74     QWidget::hideEvent(event);
75
76     m_messageListView->clearItemSelection();
77 }
78
79 void MessagePanel::populateMessageListView(QList<Message> &messages)
80 {
81     qDebug() << __PRETTY_FUNCTION__;
82
83     m_messageListView->clearList();
84
85     foreach (Message message, messages) {
86         MessageListItem *item = new MessageListItem();
87         item->setMessageData(message);
88         m_messageListView->addListItem(message.id(), item);
89     }
90 }
91
92 void MessagePanel::setImage(const QString &id, const QPixmap &image)
93 {
94     qDebug() << __PRETTY_FUNCTION__;
95
96     MessageListItem *item = dynamic_cast<MessageListItem*>(
97             m_messageListView->listItem(id));
98
99     if (item)
100         item->setImage(image);
101 }
102