Personal infotab mods in listviewscreen
[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(":/resources/refresh.png")));
66     updateStatusMessageButton->setIcon(QIcon(QPixmap(":/resources/send_position.png")));
67
68     m_clockLabel->setPixmap(QPixmap(":/resources/clock.png"));
69     m_envelopeLabel->setPixmap(QPixmap(":/resources/envelope.png"));
70     m_compassLabel->setPixmap(QPixmap(":/resources/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     connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
89     connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
90 }
91
92 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
93 {
94
95     QRect widgetRect = this->rect();
96
97     //Gradient
98     QLinearGradient linearGrad(QPointF(widgetRect.height(), widgetRect.width()/2),
99                                QPointF(widgetRect.width()/2,0));
100     linearGrad.setColorAt(0, QColor::fromRgb(49,52,57));
101     linearGrad.setColorAt(1, QColor::fromRgb(82,73,74));
102
103     //Look and feel settings
104     QPalette qpalette;
105     QBrush brush(linearGrad);
106     qpalette.setBrush(QPalette::Window,brush);
107     setPalette(qpalette);
108     int roundness(9);
109
110     QPainter painter(this);
111
112     painter.save();
113
114     painter.setRenderHint(QPainter::Antialiasing);
115     QPainterPath roundedRect;
116     roundedRect.addRoundedRect(1,1,widgetRect.width()-2, widgetRect.height()-2,roundness,roundness);
117
118     painter.setClipPath(roundedRect);
119     QRegion maskRegion = painter.clipRegion();
120
121     setMask(maskRegion);
122
123     painter.fillPath(roundedRect,QBrush(brush));
124     painter.restore();
125 }
126
127 QSize InfoTab::sizeHint() const
128 {
129    QSize size(280,280);
130    return size;
131 }
132
133 void InfoTab::setAvatar(const QPixmap &avat)
134 {
135     m_avatar = avat;
136     situUser->setPixmap(m_avatar);
137 }
138
139 void InfoTab::setUserName(const QString &usernam)
140 {
141     if(m_userName == usernam)
142       return;
143     m_userName = usernam;
144     m_userNameLabel->setText(m_userName);
145 }
146
147 void InfoTab::setMessageText(const QString &text)
148 {
149     if(m_messageText == text)
150       return;
151     m_messageText = text;
152     m_messageLabel->setText(m_messageText);
153 }
154
155 void InfoTab::setAddress(const QString &addr)
156 {
157     if(m_address == addr)
158       return;
159     m_address = addr;
160     m_addressLabel->setText(m_address);
161 }
162
163 void InfoTab::setTime(const QString &tim)
164 {
165     if(m_time == tim)
166       return;
167     m_time = tim;
168     m_timeLabel->setText(m_time);
169 }
170
171 void InfoTab::messageUpdate()
172 {
173     emit launchMessageUpdate();
174     qDebug() << __PRETTY_FUNCTION__;
175 }
176
177 void InfoTab::updateFriendsStatus()
178 {
179     emit launchUpdateFriendsStatus();
180     qDebug() << __PRETTY_FUNCTION__;
181 }