--- /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.
+ */
+
+ #include <QVBoxLayout>
+ #include <QPushButton>
+ #include <QPainter>
+ #include <QDebug>
+ #include <QPaintEvent>
+ #include <QLabel>
+ #include <QPixmap>
+ #include <QFormLayout>
+ #include <QSpacerItem>
+
+ #include "friendlistitem.h"
+ #include "../user/user.h"
+
+ const QString BACKGROUND_PATH = ":/res/images/list_item.png"; ///< Background image path
+ const QString CLOCK_PATH = ":/res/images/clock.png"; ///< Clock image path
+ const QString COMPASS_PATH = ":/res/images/compass.png"; ///< Compass image path
+ const QString ENVELOPE_PATH = ":/res/images/envelope.png"; ///< Envelope image path
+
+ const int ICON_MARGIN = 5; ///< Icon margin
+ const int IMAGE_HEIGHT = 60; ///< Friend image height
+ const int IMAGE_WIDTH = 60; ///< Friend image width
+
+ const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
+ const int ITEM_MAX_WIDTH = 368; ///< Maximum width for item
+ const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
+ const int ITEM_MIN_WIDTH = 368; ///< Minimum width for item
+ const int LABEL_MAX_WIDTH = 350; ///< Label maximum width
+
+ FriendListItem::FriendListItem(QWidget *parent)
+ : QWidget(parent)
+ , m_expanded(false)
+ , m_user(0)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ this->setLayout(layout);
+
+ QHBoxLayout *topLayout = new QHBoxLayout();
+ topLayout->setMargin(0);
+ topLayout->setSpacing(0);
+
+ QHBoxLayout *bottomLayout = new QHBoxLayout();
+ bottomLayout->setMargin(0);
+ bottomLayout->setSpacing(0);
+
+ QFormLayout *infoLayout = new QFormLayout();
+ infoLayout->setMargin(0);
+ infoLayout->setSpacing(0);
+
+ QLabel *clockLabel = new QLabel();
+ clockLabel->setPixmap(QPixmap(CLOCK_PATH));
+ clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+ QLabel *envelopeLabel = new QLabel();
+ envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
+ envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+ QLabel *compassLabel = new QLabel();
+ compassLabel->setPixmap(QPixmap(COMPASS_PATH));
+ compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+
+ m_imageLabel = new QLabel();
+ m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
+ 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);
+
+ infoLayout->addRow(clockLabel, m_updatedLabel);
+ infoLayout->addRow(envelopeLabel, m_statusTextLabel);
+ infoLayout->addRow(compassLabel, m_locationLabel);
+
+ topLayout->addWidget(m_imageLabel);
+ topLayout->addWidget(m_nameLabel);
+
+ bottomLayout->addSpacing(IMAGE_WIDTH);
+ bottomLayout->addLayout(infoLayout, 1);
+
+ layout->addLayout(topLayout, 0);
+ layout->addLayout(bottomLayout, 1);
+
+ setObjectName("listItem");
+ m_nameLabel->setObjectName("nameLabel");
+
+ setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
+ "border-width: 20px 14px 16px 14px; } " \
+ "QLabel { font-size: 13pt; color: #989898; }" \
+ "#nameLabel { font-size: 18pt; color: #ffffff }");
+
+ setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
+ setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
+ }
+
+ void FriendListItem::setData(User *user)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (user) {
+ m_user = user;
+ shortenTexts();
+
+ m_imageLabel->setPixmap(m_user->profileImage());
+ setText(false);
+ }
+ }
+
+ void FriendListItem::shortenTexts()
+ {
- qDebug() << __PRETTY_FUNCTION__ << m_user->address().length();
++ qDebug() << __PRETTY_FUNCTION__;
+
+ m_shortenedName = m_nameLabel->fontMetrics()
+ .elidedText(m_user->name(), Qt::ElideRight, LABEL_MAX_WIDTH);
+ m_shortenedUpdated = m_updatedLabel->fontMetrics()
+ .elidedText(m_user->timestamp(), Qt::ElideRight, LABEL_MAX_WIDTH);
+ m_shortenedStatusText = m_statusTextLabel->fontMetrics()
+ .elidedText(m_user->note(), Qt::ElideRight, LABEL_MAX_WIDTH);
+ m_shortenedLocation = m_locationLabel->fontMetrics()
+ .elidedText(m_user->address(), Qt::ElideRight, LABEL_MAX_WIDTH);
+ }
+
+ void FriendListItem::setText(bool expanded)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (expanded) {
+ m_nameLabel->setText(m_user->name());
+ m_updatedLabel->setText(m_user->timestamp());
+ m_statusTextLabel->setText(m_user->note());
+ m_locationLabel->setText(m_user->address());
+ }
+ else {
+ m_nameLabel->setText(m_shortenedName);
+ m_updatedLabel->setText(m_shortenedUpdated);
+ m_statusTextLabel->setText(m_shortenedStatusText);
+ m_locationLabel->setText(m_shortenedLocation);
+ }
+ }
+
+ void FriendListItem::mousePressEvent(QMouseEvent *event)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_mousePosition = event->pos();
+ }
+
+ void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (event->pos() == m_mousePosition) {
+ if (m_expanded) {
+ setText(false);
+ m_expanded = false;
+ }
+ else {
+ setText(true);
+ m_expanded = true;
+ }
+ }
+ }
+
+ void FriendListItem::paintEvent(QPaintEvent *)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QStyleOption option;
+ option.init(this);
+
+ QPainter painter(this);
+ style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
+ }
ListViewScreen::~ListViewScreen()
{
- if (m_personalInfo)
- delete m_personalInfo;
- if (m_leftSideBar)
- delete m_leftSideBar;
- if (m_slidingLeftSideBar)
- delete m_slidingLeftSideBar;
- if (m_trans1)
- delete m_trans1;
- if (m_trans2)
- delete m_trans2;
- if (m_anim1)
- delete m_anim1;
- if (m_anim2)
- delete m_anim2;
- if (m_anim3)
- delete m_anim3;
- if (m_anim4)
- delete m_anim4;
- if (m_anim5)
- delete m_anim5;
- if (m_anim6)
- delete m_anim6;
- if (m_anim7)
- delete m_anim7;
- if (m_anim8)
- delete m_anim8;
- if (m_vbox)
- delete m_vbox;
+ delete m_personalInfo;
+ delete m_leftSideBar;
+ delete m_slidingLeftSideBar;
+ delete m_personalInfoBackGround;
+ delete m_arrowLeft;
+ delete m_arrowRight;
+ delete m_trans1;
+ delete m_trans2;
+ delete m_anim1;
+ delete m_anim2;
+ delete m_anim3;
+ delete m_anim4;
+ delete m_anim5;
+ delete m_anim6;
+ delete m_anim7;
+ delete m_anim8;
+ delete m_anim9;
+ delete m_anim10;
+ delete m_anim11;
+ delete m_anim12;
+ delete m_anim13;
+ delete m_anim14;
+ delete m_vbox;
}
- void ListViewScreen::updateMessage()
-void ListViewScreen::userDataChanged(User *user, QList<User *> &friends)
++void ListViewScreen::userDataReceived(User *user)
{
- qDebug() << __PRETTY_FUNCTION__;
- // m_locationDialog->exec();
+ qDebug() << __PRETTY_FUNCTION__;
+
- emit toggleProgressIndicator(false);
-
+ m_personalInfo->setUserName(user->name());
+ m_personalInfo->setAvatar(user->profileImage());
+ m_personalInfo->setMessageText(user->note());
+ m_personalInfo->setAddress(user->address());
+ m_personalInfo->setTime(user->timestamp());
+
++ emit toggleProgressIndicator(false);
++}
++
++void ListViewScreen::friendInfoReceived(QList<User *> &friendList)
++{
++ qDebug() << __PRETTY_FUNCTION__;
++
+ m_friendListView->clear();
+
- foreach (User *user, friends) {
++ foreach (User *user, friendList) {
+ FriendListItem *item = new FriendListItem(m_friendListView);
+ item->setData(user);
+ m_friendListView->addWidget(item);
+ }
++
++ emit toggleProgressIndicator(false);
}
connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
SIGNAL(statusUpdate(QString,bool)));
- connect(this, SIGNAL(userDataChanged(User*,QList<User*>&)), m_listViewScreen,
- SLOT(userDataChanged(User*,QList<User*>&)));
-
+ connect(this, SIGNAL(userLocationReady(User*)),
+ m_mapViewScreen, SLOT(userLocationReady(User*)));
+ connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+ m_mapViewScreen, SLOT(friendsLocationsReady(QList<User*>&)));
++
++ connect(this, SIGNAL(userLocationReady(User*)), m_listViewScreen,
++ SLOT(userDataReceived(User*)));
++ connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)), m_listViewScreen,
++ SLOT(friendInfoReceived(QList<User*>&)));
+ connect(m_listViewScreen, SIGNAL(updateFriendsData()),
+ this, SIGNAL(refreshUserData()));
-
+ connect(m_listViewScreen, SIGNAL(toggleProgressIndicator(bool)), this,
+ SLOT(toggleProgressIndicator(bool)));
+
+ this->toggleProgressIndicator(true);
}
MainWindow::~MainWindow()