--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+ Katri Kaikkonen - katri.kaikkonen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QPainter>
+#include <QDebug>
+#include <QPaintEvent>
+#include <QLabel>
+#include <QPixmap>
+#include <QFormLayout>
+#include <QSpacerItem>
+#include <QStylePainter>
+#include <math.h>
+
+#include "imagebutton.h"
+#include "avatarimage.h"
+#include "../user/user.h"
+#include "userinfo.h"
+
+UserInfo::UserInfo(QWidget *parent)
+ : QWidget(parent)
+ , m_expanded(false)
+{
+ QVBoxLayout *verticalLayout = new QVBoxLayout(this);
+ verticalLayout->setContentsMargins(MARGIN, 0, MARGIN*2, MARGIN*2);
+ verticalLayout->setSpacing(0);
+ setLayout(verticalLayout);
+
+ QGridLayout *gridLayout = new QGridLayout(this);
+ gridLayout->setMargin(0);
+ gridLayout->setSpacing(0);
+
+ QHBoxLayout *topLayout = new QHBoxLayout(this);
+ topLayout->setMargin(0);
+ topLayout->setSpacing(0);
+
+ QFormLayout *infoLayout = new QFormLayout(this);
+ infoLayout->setMargin(0);
+ infoLayout->setSpacing(0);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout(this);
+ buttonLayout->setMargin(0);
+ buttonLayout->setSpacing(0);
+
+ QLabel *clockLabel = new QLabel();
+ clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
+ clockLabel->setContentsMargins(0, 0, MARGIN, 0);
+ clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
+ QLabel *envelopeLabel = new QLabel();
+ envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
+ envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
+ envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
+ QLabel *compassLabel = new QLabel();
+ compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
+ compassLabel->setContentsMargins(0, 0, MARGIN, 0);
+ compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
+
+ m_imageLabel = new QLabel();
+ m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
+ m_imageLabel->setAlignment(Qt::AlignHCenter);
+
+ m_nameLabel = new QLabel();
+ m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
+
+
+
+ m_updatedLabel = new QLabel();
+ m_updatedLabel->setWordWrap(true);
+ m_statusTextLabel = new QLabel();
+ m_statusTextLabel->setWordWrap(true);
+ m_locationLabel = new QLabel();
+ m_locationLabel->setWordWrap(true);
+
+ ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
+ ":/res/images/refresh_s.png");
+ ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
+ ":/res/images/send_position_s.png");
+
+ buttonLayout->addWidget(updateFriendsButton);
+ buttonLayout->addWidget(updateStatusMessageButton);
+
+
+ infoLayout->addRow(compassLabel, m_locationLabel);
+ infoLayout->addRow(envelopeLabel, m_statusTextLabel);
+ infoLayout->addRow(clockLabel, m_updatedLabel);
+
+ topLayout->addWidget(m_nameLabel);
+
+ gridLayout->addWidget(m_imageLabel);
+
+ verticalLayout->addLayout(gridLayout, 0);
+ verticalLayout->addLayout(topLayout, 1);
+ verticalLayout->addLayout(infoLayout);
+ verticalLayout->addLayout(buttonLayout, 2 );
+
+ connect(updateStatusMessageButton,SIGNAL(clicked()),
+ this,SLOT(messageUpdate()));
+ connect(updateFriendsButton,SIGNAL(clicked()),
+ this,SLOT(updateFriendsStatus()));
+
+ setFont(NOKIA_FONT_SMALL);
+ m_nameLabel->setFont(NOKIA_FONT_NORMAL);
+ QPalette itemPalette = palette();
+ itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
+ setPalette(itemPalette);
+ QPalette namePalette = m_nameLabel->palette();
+ namePalette.setColor(QPalette::Foreground, Qt::white);
+ m_nameLabel->setPalette(namePalette);
+
+ m_nameLabel->setText("");
+
+ this->setMaximumHeight(300);
+
+ m_backgroundTopImage.load(":/res/images/list_item_top.png");
+ m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
+ m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
+}
+
+
+
+void UserInfo::setUserName(const QString &name)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << name;
+
+ m_nameLabel->setText(name);
+
+// shortenTexts();
+}
+
+void UserInfo::setAvatar(const QPixmap &image)
+{
+// m_avatar = image;
+// // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+// //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+// m_imageLabel->setPixmap(m_avatar);
+}
+
+
+void UserInfo::setMessageText(const QString &text)
+{
+ if(m_messageText == text)
+ return;
+ m_messageText = text;
+ m_statusTextLabel->setText(m_messageText);
+// shortenTexts();
+}
+
+void UserInfo::setAddress(const QString &addr)
+{
+ if(m_address == addr)
+ return;
+ m_address = addr;
+ m_locationLabel->setText(m_address);
+// shortenTexts();
+}
+
+void UserInfo::setTime(const QString &tim)
+{
+ if(m_time == tim)
+ return;
+ m_time = tim;
+ m_updatedLabel->setText(m_time);
+// shortenTexts();
+}
+
+//void UserInfo::shortenTexts()
+//{
+// qDebug() << __PRETTY_FUNCTION__;
+//
+// QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
+// QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
+//
+// QString name = m_userName;
+// QString updated = m_time;
+// QString statusText = m_messageText;
+// QString location = m_address;
+//
+// int nameIndex = name.indexOf('\n');
+// int updatedIndex = updated.indexOf('\n');
+// int statusTextIndex = statusText.indexOf('\n');
+// int locationIndex = location.indexOf('\n');
+//
+// if (nameIndex > 0) {
+// name.truncate(nameIndex);
+// name.append("...");
+// }
+// if (updatedIndex > 0) {
+// updated.truncate(updatedIndex);
+// updated.append("...");
+// }
+// if (statusTextIndex > 0) {
+// statusText.truncate(statusTextIndex);
+// statusText.append("...");
+// }
+// if (locationIndex > 0) {
+// location.truncate(locationIndex);
+// location.append("...");
+// }
+//
+// m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
+// m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
+// m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
+// LABEL_MAX_WIDTH);
+// m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
+//}
+//
+//void UserInfo::setText(bool expanded)
+//{
+// qDebug() << __PRETTY_FUNCTION__;
+//
+// if (expanded) {
+// m_nameLabel->setText(m_userName);
+// m_updatedLabel->setText(m_time);
+// m_statusTextLabel->setText(m_messageText);
+// m_locationLabel->setText(m_address);
+// }
+// else {
+// m_nameLabel->setText(m_shortenedName);
+// m_updatedLabel->setText(m_shortenedUpdated);
+// m_statusTextLabel->setText(m_shortenedStatusText);
+// m_locationLabel->setText(m_shortenedLocation);
+// }
+//}
+
+//void UserInfo::mouseReleaseEvent(QMouseEvent *event)
+//{
+// qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+//
+// if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
+// (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
+// if (m_expanded) {
+// setText(false);
+// m_expanded = false;
+// }
+// else {
+// setText(true);
+// m_expanded = true;
+// }
+// }
+//}
+void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
+{
+// Q_UNUSED(aPaintEvent);
+//
+// QStyleOption option;
+// option.init(this);
+// QStylePainter painter(this);
+//
+// // Temporary border
+// painter.setPen(Qt::red);
+// painter.drawRect(this->rect().x(), this->rect().y(), this->rect().width() - 1, this->rect().height() - 1);
+//
+// style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
+//
+ qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
+
+ QPainter painter(this);
+ QRect topRect = QRect(0, 0, ITEM_MIN_WIDTH, BACKGROUND_TOP_HEIGHT);
+ QRect middleRect = QRect(0, topRect.bottom(), ITEM_MIN_WIDTH,
+ height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
+ QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_MIN_WIDTH,
+ BACKGROUND_BOTTOM_HEIGHT);
+
+ painter.drawPixmap(topRect, m_backgroundTopImage);
+ painter.drawPixmap(middleRect, m_backgroundMiddleImage);
+ painter.drawPixmap(bottomRect, m_backgroundBottomImage);
+}
+
+
+void UserInfo::mousePressEvent(QMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+
+ m_mousePosition = event->pos();
+}
+
+void UserInfo::messageUpdate()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_locationDialog = new UpdateLocationDialog(this);
+ m_locationDialog->show();
+}
+
+void UserInfo::updateFriendsStatus()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ //emit launchUpdateFriendsStatus();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef USERINFO_H
+#define USERINFO_H
+
+#include <QWidget>
+#include <QTreeWidgetItem>
+#include <QListWidgetItem>
+#include "updatelocation/updatelocationdialog.h"
+
+#include "../user/user.h"
+
+class QLabel;
+
+class UserInfo : public QWidget
+{
+ Q_OBJECT
+public:
+ /**
+ * @brief Constructor
+ *
+ * @param parent Parent
+ */
+ UserInfo(QWidget *parent=0);
+
+/*******************************************************************************
+* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+*******************************************************************************/
+protected:
+ /**
+ * @brief This function is called when the widget is drawn
+ *
+ * @param aPaintEvent Pointer to paint event
+ */
+ void paintEvent(QPaintEvent *aPaintEvent);
+ /**
+ * @brief Set current mouse position to mouse event position.
+ *
+ * @param event QMouseEvent mouse press event
+ */
+ void mousePressEvent(QMouseEvent *event);
+// /**
+// * @brief Call toggleHeight if mouse position is unchanged.
+// *
+// * Check if current mouse position is same as mouse release position.
+// * @param event QMouseEvent mouse release event
+// */
+// void mouseReleaseEvent(QMouseEvent *event);
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public slots:
+
+
+ /**
+ * @brief Sets the users current address
+ *
+ * @param addr Reference to users current address
+ */
+ void setAddress(const QString &addr);
+ /**
+ * @brief Sets the user picture
+ *
+ * @param avat Reference to user picture
+ */
+ void setAvatar(const QPixmap &image);
+ /**
+ * @brief Sets the message text
+ *
+ * @param text Reference to user message
+ */
+ void setMessageText(const QString &text);
+ /**
+ * @brief Sets the time of updated message
+ *
+ * @param tim Reference to time when message was sent.
+ */
+ void setTime(const QString &tim);
+ /**
+ * @brief Sets the user name
+ *
+ * @param usernam Reference to user name
+ */
+ void setUserName(const QString &name);
+private slots:
+ /**
+ * @brief Slot function to forward messageUpdate launch signal
+ *
+ */
+ void messageUpdate();
+// /**
+// * @brief Set shortened or full-length text to labels.
+// *
+// * @param expanded true if full-length text is set, false otherwise
+// */
+// void setText(bool expanded);
+// /**
+// * @brief Set shortened texts from User data.
+// *
+// * Text length is defined by MAXIMUM_CHARS.
+// */
+// void shortenTexts();
+ /**
+ * @brief Slot function to forward friends status update signal
+ *
+ */
+ void updateFriendsStatus();
+
+signals:
+ /**
+ * @brief Signal to launch manual message update dialog
+ *
+ */
+ void launchMessageUpdate();
+ /**
+ * @brief Signal to refresh friends statuses
+ * @todo: Connect to friends lists when ready
+ */
+ void launchUpdateFriendsStatus();
+
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+ QPixmap m_backgroundTopImage; ///< Top background image
+ QPixmap m_backgroundMiddleImage; ///< Middle background image
+ QPixmap m_backgroundBottomImage; ///< Bottom background image
+ bool m_expanded; ///< Item expanded state
+ QLabel *m_distanceLabel; ///< Distance to friend label
+ QLabel *m_imageLabel; ///< Image label
+ QLabel *m_locationLabel; ///< Location label
+ QPoint m_mousePosition; ///< Current mouse press position
+ QLabel *m_nameLabel; ///< Name label
+ QString m_address;
+ QString m_time;
+ QString m_messageText;
+ QString m_avatar;
+ QString m_shortenedLocation; ///< Shortened location text
+ QString m_shortenedName; ///< Shortened name text
+ QString m_shortenedStatusText; ///< Shortened status text
+ QString m_shortenedUpdated; ///< Shortened updated text
+ QString m_userName;
+ QLabel *m_statusTextLabel; ///< Status text label
+ QLabel *m_updatedLabel; ///< Updated label
+ UpdateLocationDialog *m_locationDialog; ///< Message dialog
+
+};
+
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
+const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
+const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal); ///< Small font
+const int ICON_HEIGHT = 24; ///< Icon height
+const int ICON_WIDTH = 24; ///< Icon width
+const int IMAGE_HEIGHT = 60; ///< Friend image height
+const int IMAGE_WIDTH = 60; ///< Friend image width
+const int ITEM_MAX_HEIGHT = 1240; ///< Maximum height for item
+const int ITEM_MAX_WIDTH = 250; ///< Maximum width for item
+const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
+const int ITEM_MIN_WIDTH = 250; ///< Minimum width for item
+const int MARGIN = 5; ///< Icon margin
+const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
+const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
+/**
+* @var NAME_LABEL_MAX_WIDTH
+*
+* @brief Name label's maximum width
+*/
+const int NAME_LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH;
+/**
+* @var LABEL_MAX_WIDTH
+*
+* @brief All label's maximum width
+*/
+const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
+
+#endif // USERINFO_H