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