Polishing
[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 <QDebug>
25
26 const int RGB_R = 152;
27 const int RGB_G = 152;
28 const int RGB_B = 152;
29 const int GRADIENT_START_R = 49;
30 const int GRADIENT_START_G = 52;
31 const int GRADIENT_START_B = 57;
32 const int GRADIENT_STOP_R = 82;
33 const int GRADIENT_STOP_G = 73;
34 const int GRADIENT_STOP_B = 74;
35 const int ROUNDNESS = 9;
36 const int SIZE_X = 280;
37 const int SIZE_Y = 280;
38 const int BIG_FONT = 18;
39 const int SMALL_FONT = 13;
40 const int RECT_WIDTH_OFFSET = 2;
41 const int RECT_HEIGHT_OFFSET = 2;
42
43 InfoTab::InfoTab(QWidget *parent)
44     : QWidget(parent, Qt::FramelessWindowHint)
45 {
46     widget = new QWidget(this);
47     verticalLayout = new QVBoxLayout(widget);
48     horizontalLayout = new QHBoxLayout(widget);
49     m_layout = new QGridLayout(widget);
50     situUser = new SituareUser(widget);
51     situUser->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
52     situUser->setMargin(1);
53
54     //Tex color settings
55     QPalette textPalette;
56     QColor textColor(RGB_R,RGB_G,RGB_B);
57     textPalette.setColor(QPalette::WindowText,textColor);
58     m_userNameLabel = new QLabel(widget);
59     m_userNameLabel->setFont(QFont( "Nokia Sans", BIG_FONT, QFont::Normal));
60
61     m_messageLabel = new QLabel(widget);
62     m_messageLabel->setFont(QFont( "Nokia Sans", SMALL_FONT, QFont::Normal));
63     m_messageLabel->setPalette(textPalette);
64
65     m_addressLabel = new QLabel(widget);
66     m_addressLabel->setFont(QFont( "Nokia Sans", SMALL_FONT, QFont::Normal));
67     m_addressLabel->setPalette(textPalette);
68
69     m_timeLabel = new QLabel(widget);
70     m_timeLabel->setFont(QFont( "Nokia Sans", 13, QFont::Normal));
71     m_timeLabel->setPalette(textPalette);
72
73     m_clockLabel = new QLabel(widget);
74     m_clockLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
75     m_envelopeLabel = new QLabel(widget);
76     m_envelopeLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
77     m_compassLabel = new QLabel(widget);
78     m_compassLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
79     ButtonItem *updateFriendsButton = new ButtonItem(widget);
80     ButtonItem *updateStatusMessageButton = new ButtonItem(widget);
81
82     updateFriendsButton->setIcon(QIcon(QPixmap(":/res/images/refresh.png")));
83     updateStatusMessageButton->setIcon(QIcon(QPixmap(":/res/images/send_position.png")));
84
85     m_clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
86     m_envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
87     m_compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
88     m_layout->addWidget(situUser,0,0,1,2,Qt::AlignHCenter);
89     m_layout->addWidget(m_userNameLabel,1,1,1,2);
90     m_layout->addWidget(m_clockLabel,3,0,1,1);
91     m_layout->addWidget(m_envelopeLabel,2,0,1,1);
92     m_layout->addWidget(m_compassLabel,4,0,1,1);
93     m_layout->addWidget(m_timeLabel,3,1,1,1);
94     m_layout->addWidget(m_messageLabel,2,1,1,1);
95     m_layout->addWidget(m_addressLabel,4,1,1,1);
96
97     verticalLayout->addLayout(m_layout);
98     horizontalLayout->setSpacing(0);
99     horizontalLayout->addWidget(updateFriendsButton);
100     horizontalLayout->addWidget(updateStatusMessageButton);
101
102     verticalLayout->addLayout(horizontalLayout);
103
104     connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
105     connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
106 }
107
108 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
109 {
110
111     QRect widgetRect = this->rect();
112
113     //Gradient
114     QLinearGradient linearGrad(QPointF(widgetRect.height(), widgetRect.width()/2),
115                                QPointF(widgetRect.width()/2,0));
116     linearGrad.setColorAt(0, QColor::fromRgb(GRADIENT_START_R,GRADIENT_START_G,GRADIENT_START_B));
117     linearGrad.setColorAt(1, QColor::fromRgb(GRADIENT_STOP_R,GRADIENT_STOP_G,GRADIENT_STOP_B));
118
119     //Look and feel settings
120     QPalette qpalette;
121     QBrush brush(linearGrad);
122     qpalette.setBrush(QPalette::Window,brush);
123     setPalette(qpalette);
124
125     QPainter painter(this);
126
127     painter.save();
128
129     painter.setRenderHint(QPainter::Antialiasing);
130     QPainterPath roundedRect;
131     roundedRect.addRoundedRect(1,1,widgetRect.width()-RECT_WIDTH_OFFSET,
132                                widgetRect.height()-RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
133
134     painter.setClipPath(roundedRect);
135     QRegion maskRegion = painter.clipRegion();
136
137     setMask(maskRegion);
138
139     painter.fillPath(roundedRect,QBrush(brush));
140     painter.restore();
141 }
142
143 QSize InfoTab::sizeHint() const
144 {
145    QSize size(SIZE_X,SIZE_Y);
146    return size;
147 }
148
149 void InfoTab::setAvatar(const QPixmap &avat)
150 {
151     m_avatar = avat;
152     situUser->setPixmap(m_avatar);
153 }
154
155 void InfoTab::setUserName(const QString &usernam)
156 {
157     if(m_userName == usernam)
158       return;
159     m_userName = usernam;
160     m_userNameLabel->setText(m_userName);
161 }
162
163 void InfoTab::setMessageText(const QString &text)
164 {
165     if(m_messageText == text)
166       return;
167     m_messageText = text;
168     m_messageLabel->setText(m_messageText);
169 }
170
171 void InfoTab::setAddress(const QString &addr)
172 {
173     if(m_address == addr)
174       return;
175     m_address = addr;
176     m_addressLabel->setText(m_address);
177 }
178
179 void InfoTab::setTime(const QString &tim)
180 {
181     if(m_time == tim)
182       return;
183     m_time = tim;
184     m_timeLabel->setText(m_time);
185 }
186
187 void InfoTab::messageUpdate()
188 {
189     emit launchMessageUpdate();
190     qDebug() << __PRETTY_FUNCTION__;
191 }
192
193 void InfoTab::updateFriendsStatus()
194 {
195     emit launchUpdateFriendsStatus();
196     qDebug() << __PRETTY_FUNCTION__;
197 }