Merge branch 'master' into friendlist
[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
24 InfoTab::InfoTab(QWidget *parent)
25     : QWidget(parent, Qt::FramelessWindowHint)
26 {
27     m_layout = new QGridLayout(this);
28     m_userPicture = new QLabel;
29     m_userNameLabel = new QLabel;
30     m_messageLabel = new QLabel;
31     m_addressLabel = new QLabel;
32     m_timeLabel = new QLabel;
33     QLabel *m_clockLabel = new QLabel;
34     QLabel *m_envelopeLabel = new QLabel;
35     QLabel *m_compassLabel = new QLabel;
36     QToolButton *updateFriendsButton = new QToolButton;
37     QToolButton *updateStatusMessageButton = new QToolButton;
38
39     updateFriendsButton->setIcon(QIcon(QPixmap(":/res/images/reload_icon.png")));
40     updateStatusMessageButton->setIcon(QIcon(QPixmap(":/res/images/sendPosition_icon.png")));
41
42     m_clockLabel->setPixmap(QPixmap(":/res/images/clock_small.png"));
43     m_envelopeLabel->setPixmap(QPixmap(":/res/images/list_small.png"));
44     m_compassLabel->setPixmap(QPixmap(":/res/images/compas_small.png"));
45     m_layout->addWidget(m_userPicture,0,0,4,1);
46     m_layout->addWidget(m_userNameLabel,0,2,1,2);
47     m_layout->addWidget(m_clockLabel,1,1,1,1);
48     m_layout->addWidget(m_envelopeLabel,2,1,1,1);
49     m_layout->addWidget(m_compassLabel,3,1,1,1);
50     m_layout->addWidget(m_timeLabel,1,2,1,1);
51     m_layout->addWidget(m_messageLabel,2,2,1,1);
52     m_layout->addWidget(m_addressLabel,3,2,1,1);
53     m_layout->addWidget(updateFriendsButton,0,3,2,1);
54     m_layout->addWidget(updateStatusMessageButton,1,3,2,1);
55
56     connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
57     connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
58 }
59
60 InfoTab::~InfoTab()
61 {
62     if (m_userPicture)
63         delete m_userPicture;
64     if (m_userNameLabel)
65         delete m_userNameLabel;
66     if (m_messageLabel)
67         delete m_messageLabel;
68     if (m_addressLabel)
69         delete m_addressLabel;
70     if (m_timeLabel)
71         delete m_timeLabel;
72     if (m_layout)
73         delete m_layout;
74     m_userPicture=NULL;
75     m_userNameLabel=NULL;
76     m_messageLabel=NULL;
77     m_addressLabel=NULL;
78     m_timeLabel=NULL;
79     m_layout=NULL;
80 }
81
82 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
83 {
84     //Look and feel settings
85     QPalette qpalette;
86     QColor myColor(Qt::black);
87     myColor.setAlpha(50);
88     qpalette.setColor(QPalette::Background,myColor);
89     setPalette(qpalette);
90     int roundness(6);
91
92     QRect widgetRect = this->rect();
93     QPainter painter(this);
94     painter.save();
95
96     painter.setRenderHint(QPainter::Antialiasing);
97     QPainterPath roundedRect;
98     roundedRect.addRoundedRect(1,1,widgetRect.width() - 2, widgetRect.height()-2,roundness,roundness);
99
100     painter.setClipPath(roundedRect);
101     QRegion maskRegion = painter.clipRegion();
102
103     setMask(maskRegion);
104
105     painter.fillPath(roundedRect,QBrush(myColor));
106     painter.restore();
107 }
108
109 void InfoTab::setAvatar(const QPixmap &avat)
110 {
111     m_avatar = avat;
112     m_userPicture->setPixmap(m_avatar);
113 }
114
115 void InfoTab::setUserName(const QString &usernam)
116 {
117     if(m_userName == usernam)
118       return;
119     m_userName = usernam;
120     m_userNameLabel->setText(m_userName);
121 }
122
123 void InfoTab::setMessageText(const QString &text)
124 {
125     if(m_messageText == text)
126       return;
127     m_messageText = text;
128     m_messageLabel->setText(m_messageText);
129 }
130
131 void InfoTab::setAddress(const QString &addr)
132 {
133     if(m_address == addr)
134       return;
135     m_address = addr;
136     m_addressLabel->setText(m_address);
137 }
138
139 void InfoTab::setTime(const QString &tim)
140 {
141     if(m_time == tim)
142       return;
143     m_time = tim;
144     m_timeLabel->setText(m_time);
145 }
146
147 void InfoTab::messageUpdate()
148 {
149     emit launchMessageUpdate();
150     qDebug() << __PRETTY_FUNCTION__;
151 }
152
153 void InfoTab::updateFriendsStatus()
154 {
155     emit launchUpdateFriendsStatus();
156     qDebug() << __PRETTY_FUNCTION__;
157 }