Added new class AvatarImage.
[situare] / src / ui / infotab.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jukka Saastamoinen - jukka.saastamoinen@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 "infotab.h"
23 #include "buttonitem.h"
24 #include "mainwindow.h"
25 #include <QDebug>
26
27 const int RGB_R = 152;
28 const int RGB_G = 152;
29 const int RGB_B = 152;
30 const int SIZE_X = 320;
31 const int SIZE_Y = 280;
32 const int BIG_FONT = 18;
33 const int SMALL_FONT = 13;
34
35 InfoTab::InfoTab(QWidget *parent)
36     : QWidget(parent, Qt::FramelessWindowHint)
37 {
38     widget = new QWidget(this);
39     verticalLayout = new QVBoxLayout(widget);
40     horizontalLayout = new QHBoxLayout(widget);
41     m_layout = new QGridLayout(widget);
42
43     //Tex color settings
44     QPalette textPalette;
45     QColor textColor(RGB_R,RGB_G,RGB_B);
46     textPalette.setColor(QPalette::WindowText,textColor);
47     m_userNameLabel = new QLabel(widget);
48     m_userNameLabel->setFont(QFont( "Nokia Sans", BIG_FONT, QFont::Normal));
49
50     m_messageLabel = new QLabel(widget);
51     m_messageLabel->setFont(QFont( "Nokia Sans", SMALL_FONT, QFont::Normal));
52     m_messageLabel->setPalette(textPalette);
53
54     m_addressLabel = new QLabel(widget);
55     m_addressLabel->setFont(QFont( "Nokia Sans", SMALL_FONT, QFont::Normal));
56     m_addressLabel->setPalette(textPalette);
57
58     m_timeLabel = new QLabel(widget);
59     m_timeLabel->setFont(QFont( "Nokia Sans", 13, QFont::Normal));
60     m_timeLabel->setPalette(textPalette);
61
62     m_clockLabel = new QLabel(widget);
63     m_clockLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
64     m_envelopeLabel = new QLabel(widget);
65     m_envelopeLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
66     m_compassLabel = new QLabel(widget);
67     m_compassLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
68     ButtonItem *updateFriendsButton = new ButtonItem(widget);
69     ButtonItem *updateStatusMessageButton = new ButtonItem(widget);
70
71     updateFriendsButton->setIcon(QIcon(QPixmap(":/res/images/refresh.png")));
72     updateStatusMessageButton->setIcon(QIcon(QPixmap(":/res/images/send_position.png")));
73
74     m_clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
75     m_envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
76     m_compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
77 //    m_layout->addWidget(situUser,0,0,1,2,Qt::AlignHCenter);
78     m_layout->addWidget(m_userNameLabel,1,1,1,2);
79     m_layout->addWidget(m_clockLabel,3,0,1,1);
80     m_layout->addWidget(m_envelopeLabel,2,0,1,1);
81     m_layout->addWidget(m_compassLabel,4,0,1,1);
82     m_layout->addWidget(m_timeLabel,3,1,1,1);
83     m_layout->addWidget(m_messageLabel,2,1,1,1);
84     m_layout->addWidget(m_addressLabel,4,1,1,1);
85
86     verticalLayout->addLayout(m_layout);
87     horizontalLayout->setSpacing(0);
88     horizontalLayout->addWidget(updateFriendsButton);
89     horizontalLayout->addWidget(updateStatusMessageButton);
90
91     verticalLayout->addLayout(horizontalLayout);
92
93     connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
94     connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
95
96     widget->setObjectName("infoTab");
97     widget->setStyleSheet(QString("#infoTab { border-image: url(:/res/images/list_item.png) 20%; " \
98                                   "border-width: 20px 14px 16px 14px; }"));
99 }
100
101 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
102 {
103     Q_UNUSED(aPaintEvent);
104
105     QStyleOption option;
106     option.init(this);
107
108     QPainter painter(this);
109     style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
110 }
111
112 QSize InfoTab::sizeHint() const
113 {
114    QSize size(SIZE_X,SIZE_Y);
115    return size;
116 }
117
118 void InfoTab::setAvatar(const QPixmap &avat)
119 {
120     m_avatar = avat;
121 }
122
123 void InfoTab::setUserName(const QString &usernam)
124 {
125     if(m_userName == usernam)
126       return;
127     m_userName = usernam;
128     m_userNameLabel->setText(m_userName);
129 }
130
131 void InfoTab::setMessageText(const QString &text)
132 {
133     if(m_messageText == text)
134       return;
135     m_messageText = text;
136     m_messageLabel->setText(m_messageText);
137 }
138
139 void InfoTab::setAddress(const QString &addr)
140 {
141     if(m_address == addr)
142       return;
143     m_address = addr;
144     m_addressLabel->setText(m_address);
145 }
146
147 void InfoTab::setTime(const QString &tim)
148 {
149     if(m_time == tim)
150       return;
151     m_time = tim;
152     m_timeLabel->setText(m_time);
153 }
154
155 void InfoTab::messageUpdate()
156 {
157     emit launchMessageUpdate();
158     qDebug() << __PRETTY_FUNCTION__;
159 }
160
161 void InfoTab::updateFriendsStatus()
162 {
163     emit launchUpdateFriendsStatus();
164     qDebug() << __PRETTY_FUNCTION__;
165 }