Modified FriendListItem constructor and paintEvent.
[situare] / src / ui / friendlistitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@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 <QVBoxLayout>
23 #include <QPushButton>
24 #include <QPainter>
25 #include <QDebug>
26 #include <QPaintEvent>
27 #include <QLabel>
28 #include <QPixmap>
29
30 #include "friendlistitem.h"
31
32 const int BACKGROUND_TOP_WIDTH = 368;
33 const int BACKGROUND_TOP_HEIGHT = 20;
34 const int BACKGROUND_MIDDLE_X = 0;
35 const int BACKGROUND_MIDDLE_Y = BACKGROUND_TOP_HEIGHT;
36 const int BACKGROUND_MIDDLE_WIDTH = 368;
37 const int BACKGROUND_MIDDLE_HEIGHT = 106;
38 const int BACKGROUND_BOTTOM_X = 0;
39 const int BACKGROUND_BOTTOM_Y = BACKGROUND_MIDDLE_Y + BACKGROUND_MIDDLE_HEIGHT;
40 const int BACKGROUND_BOTTOM_WIDTH = 368;
41 const int BACKGROUND_BOTTOM_HEIGHT = 15;
42 const int IMAGE_X = 9;
43 const int IMAGE_Y = 0;
44 const int IMAGE_WIDTH = 60;
45 const int IMAGE_HEIGHT = 60;
46 const int CLOCK_X = 75;
47 const int CLOCK_Y = 53;
48 const int ENVELOPE_X = 75;
49 const int ENVELOPE_Y = 77;
50 const int COMPASS_X = 75;
51 const int COMPASS_Y = 101;
52 const int ICON_WIDTH = 24;
53 const int ICON_HEIGHT = 24;
54
55 const QString BACKGROUND_TOP_PATH = QString(":/resources/list_item_top.png");
56 const QString BACKGROUND_MIDDLE_PATH = QString(":/resources/list_item_middle.png");
57 const QString BACKGROUND_BOTTOM_PATH = QString(":/resources/list_item_bottom.png");
58 const QString CLOCK_PATH = QString(":/resources/clock.png");
59 const QString ENVELOPE_PATH = QString(":/resources/envelope.png");
60 const QString COMPASS_PATH = QString(":/resources/compass.png");
61
62 FriendListItem::FriendListItem()
63 {
64     QVBoxLayout *layout = new QVBoxLayout(this);
65
66     QWidget *childWidget = new QWidget(this);
67     QPalette palette = childWidget->palette();
68     palette.setColor(QPalette::Foreground, QColor::fromRgb(152,152,152));
69     childWidget->setPalette(palette);
70     QFont font = QFont("Nokia Sans", 13, QFont::Normal);
71     childWidget->setFont(font);
72
73     QGridLayout *infoLayout = new QGridLayout(this);
74     infoLayout->setSpacing(0);
75     infoLayout->setMargin(0);
76     childWidget->setLayout(infoLayout);
77
78     QLabel *clockLabel = new QLabel(this);
79     clockLabel->setPixmap(QPixmap(CLOCK_PATH));
80     QLabel *envelopeLabel = new QLabel(this);
81     envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
82     QLabel *compassLabel = new QLabel(this);
83     compassLabel->setPixmap(QPixmap(COMPASS_PATH));
84
85     updatedLabel = new QLabel("22 min ago", this);
86     statusTextLabel = new QLabel("Just testing Situare...", this);
87     locationLabel = new QLabel("Some address 10, 1234 City", this);
88
89     infoLayout->setColumnStretch(1, 1);
90     infoLayout->setColumnMinimumWidth(0, 28);
91
92     infoLayout->addWidget(clockLabel, 0, 0);
93     infoLayout->addWidget(updatedLabel, 0, 1);
94     infoLayout->addWidget(envelopeLabel, 1, 0);
95     infoLayout->addWidget(statusTextLabel, 1, 1);
96     infoLayout->addWidget(compassLabel, 2, 0);
97     infoLayout->addWidget(locationLabel, 2, 1);
98
99     childWidget->setGeometry(75, 53, 250, 70);
100
101     this->setMinimumSize(368, 141);
102 }
103
104 void FriendListItem::paintEvent(QPaintEvent *)
105 {
106     QPainter painter(this);
107
108     QRect itemRect = QRect(0, 0, 368, 141);
109
110     //Draw background
111     QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_TOP_WIDTH,
112                           BACKGROUND_TOP_HEIGHT);
113     painter.drawPixmap(topRect, QPixmap(BACKGROUND_TOP_PATH));
114
115     QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_MIDDLE_WIDTH,
116                              BACKGROUND_MIDDLE_HEIGHT);
117     painter.drawPixmap(middleRect, QPixmap(BACKGROUND_MIDDLE_PATH));
118
119     QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_BOTTOM_WIDTH,
120                              BACKGROUND_BOTTOM_HEIGHT);
121     painter.drawPixmap(bottomRect, QPixmap(BACKGROUND_BOTTOM_PATH));
122
123     //Draw image
124     QString image = QString(":/resources/dummy_Avatar.png");
125     QRect imageRect = QRect(itemRect.left() + IMAGE_X, itemRect.top() + IMAGE_Y,
126                                 IMAGE_WIDTH, IMAGE_HEIGHT);
127     painter.drawPixmap(imageRect, QPixmap(image));
128
129     //Draw name
130     QRect nameRect = QRect(itemRect.left() + IMAGE_WIDTH + 11, itemRect.top() + 15, itemRect.width(),
131                            itemRect.height());
132     QString name = QString("This is friend item");
133     QPen whitePen(QColor(Qt::white), 1, Qt::SolidLine);
134     painter.setPen(whitePen);
135     painter.setFont(QFont( "Nokia Sans", 18, QFont::Normal));
136     painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, name, &nameRect);
137 }