2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
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.
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.
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,
22 #include <QVBoxLayout>
23 #include <QPushButton>
26 #include <QPaintEvent>
29 #include <QStateMachine>
30 #include <QAbstractTransition>
31 #include <QPropertyAnimation>
32 #include <QSignalTransition>
34 #include "friendlistitem.h"
35 #include "user/user.h"
37 const int BACKGROUND_TOP_WIDTH = 368;
38 const int BACKGROUND_TOP_HEIGHT = 20;
39 const int BACKGROUND_MIDDLE_X = 0;
40 const int BACKGROUND_MIDDLE_Y = BACKGROUND_TOP_HEIGHT;
41 const int BACKGROUND_MIDDLE_WIDTH = 368;
42 const int BACKGROUND_MIDDLE_HEIGHT = 106;
43 const int BACKGROUND_BOTTOM_X = 0;
44 const int BACKGROUND_BOTTOM_Y = BACKGROUND_MIDDLE_Y + BACKGROUND_MIDDLE_HEIGHT;
45 const int BACKGROUND_BOTTOM_WIDTH = 368;
46 const int BACKGROUND_BOTTOM_HEIGHT = 15;
47 const int IMAGE_X = 9;
48 const int IMAGE_Y = 0;
49 const int IMAGE_WIDTH = 60;
50 const int IMAGE_HEIGHT = 60;
51 const int CLOCK_X = 75;
52 const int CLOCK_Y = 53;
53 const int ENVELOPE_X = 75;
54 const int ENVELOPE_Y = 77;
55 const int COMPASS_X = 75;
56 const int COMPASS_Y = 101;
57 const int ICON_WIDTH = 24;
58 const int ICON_HEIGHT = 24;
60 const QString BACKGROUND_TOP_PATH = QString(":/res/images/list_item_top.png");
61 const QString BACKGROUND_MIDDLE_PATH = QString(":/res/images/list_item_middle.png");
62 const QString BACKGROUND_BOTTOM_PATH = QString(":/res/images/list_item_bottom.png");
63 const QString CLOCK_PATH = QString(":/res/images/clock.png");
64 const QString ENVELOPE_PATH = QString(":/res/images/envelope.png");
65 const QString COMPASS_PATH = QString(":/res/images/compass.png");
67 FriendListItem::FriendListItem(QWidget *parent)
70 QWidget *childWidget = new QWidget(this);
71 QPalette palette = childWidget->palette();
72 palette.setColor(QPalette::Foreground, QColor::fromRgb(152, 152, 152));
73 childWidget->setPalette(palette);
74 QFont font = QFont("Nokia Sans", 13, QFont::Normal);
75 childWidget->setFont(font);
77 QGridLayout *infoLayout = new QGridLayout(this);
78 infoLayout->setSpacing(0);
79 infoLayout->setMargin(0);
80 childWidget->setLayout(infoLayout);
82 QLabel *clockLabel = new QLabel(this);
83 clockLabel->setPixmap(QPixmap(CLOCK_PATH));
84 QLabel *envelopeLabel = new QLabel(this);
85 envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
86 QLabel *compassLabel = new QLabel(this);
87 compassLabel->setPixmap(QPixmap(COMPASS_PATH));
89 m_updatedLabel = new QLabel("", this);
90 m_updatedLabel->setWordWrap(true);
91 m_statusTextLabel = new QLabel("", this);
92 m_statusTextLabel->setWordWrap(true);
93 m_locationLabel = new QLabel("", this);
94 m_locationLabel->setWordWrap(true);
96 infoLayout->setColumnStretch(1, 1);
97 infoLayout->setColumnMinimumWidth(0, 28);
98 infoLayout->setRowMinimumHeight(0, 28);
100 infoLayout->addWidget(clockLabel, 0, 0, 1, 1, Qt::AlignTop);
101 infoLayout->addWidget(m_updatedLabel, 0, 1);
102 infoLayout->addWidget(envelopeLabel, 1, 0, 1, 1, Qt::AlignTop);
103 infoLayout->addWidget(m_statusTextLabel, 1, 1);
104 infoLayout->addWidget(compassLabel, 2, 0, 1, 1, Qt::AlignTop);
105 infoLayout->addWidget(m_locationLabel, 2, 1);
107 childWidget->setGeometry(75, 53, 368-75-5, 141-53-5);
109 this->setMinimumSize(368, 141);
111 // QStateMachine machine;
112 // QState *state1 = new QState(&machine);
113 // QState *state2 = new QState(&machine);
114 // machine.setInitialState(state1);
116 // QPushButton *btn = new QPushButton(this);
118 // //state1->assignProperty(childWidget, "geometry", QRect(0, 0, 150, 50));
119 // state1->assignProperty(childWidget, "pos", QPointF(0, 0));
120 // //state2->assignProperty(childWidget, "geometry", QRect(0, 0, 150, 100));
121 // state2->assignProperty(childWidget, "pos", QPointF(100, 100));
124 // QAbstractTransition *t1 = state1->addTransition(btn, SIGNAL(clicked()), state2);
125 // //t1->addAnimation(new QPropertyAnimation(childWidget, "geometry"));
126 // t1->addAnimation(new QPropertyAnimation(childWidget, "pos"));
128 // QAbstractTransition *t2 = state2->addTransition(btn, SIGNAL(clicked()), state1);
129 // //t2->addAnimation(new QPropertyAnimation(childWidget, "geometry"));
130 // t2->addAnimation(new QPropertyAnimation(childWidget, "pos"));
135 void FriendListItem::setData(const User &user)
137 m_name = user.name();
138 m_updatedLabel->setText(user.timestamp());
139 m_statusTextLabel->setText(user.note());
140 m_locationLabel->setText(user.address());
141 m_image = user.profileImageUrl().toString();
144 void FriendListItem::mousePressEvent(QMouseEvent *event)
149 void FriendListItem::paintEvent(QPaintEvent *event)
151 QPainter painter(this);
152 //QRect itemRect = event->rect();
153 QRect itemRect = QRect(0, 0, 368, 141);
154 qDebug() << event->rect();
156 QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_TOP_WIDTH,
157 BACKGROUND_TOP_HEIGHT);
158 painter.drawPixmap(topRect, QPixmap(BACKGROUND_TOP_PATH));
160 QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_MIDDLE_WIDTH,
161 BACKGROUND_MIDDLE_HEIGHT);
162 painter.drawPixmap(middleRect, QPixmap(BACKGROUND_MIDDLE_PATH));
164 if (itemRect.height() >= (141 - 15)) {
165 QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_BOTTOM_WIDTH,
166 BACKGROUND_BOTTOM_HEIGHT);
167 painter.drawPixmap(bottomRect, QPixmap(BACKGROUND_BOTTOM_PATH));
171 QString image = QString(":/res/images/dummy_Avatar.png");
172 QRect imageRect = QRect(itemRect.left() + IMAGE_X, itemRect.top() + IMAGE_Y,
173 IMAGE_WIDTH, IMAGE_HEIGHT);
174 painter.drawPixmap(imageRect, QPixmap(image));
177 QRect nameRect = QRect(itemRect.left() + IMAGE_WIDTH + 11, itemRect.top() + 15, itemRect.width(),
179 QPen whitePen(QColor(Qt::white), 1, Qt::SolidLine);
180 painter.setPen(whitePen);
181 painter.setFont(QFont( "Nokia Sans", 18, QFont::Normal));
182 painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_name, &nameRect);