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