Added new class AvatarImage.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 10 May 2010 08:26:18 +0000 (11:26 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 10 May 2010 08:26:18 +0000 (11:26 +0300)
12 files changed:
images.qrc
src/src.pro
src/ui/avatarimage.cpp [new file with mode: 0644]
src/ui/avatarimage.h [new file with mode: 0644]
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistpanel.cpp
src/ui/infotab.cpp
src/ui/infotab.h
src/ui/listviewscreen.cpp
src/ui/situareuser.cpp [deleted file]
src/ui/situareuser.h [deleted file]

index e38df87..38c5faf 100644 (file)
@@ -22,5 +22,8 @@
         <file>res/images/list_item_bottom.png</file>
         <file>res/images/list_item_middle.png</file>
         <file>res/images/list_item_top.png</file>
+        <file>res/images/show_position.png</file>
+        <file>res/images/show_position_s.png</file>
+        <file>res/images/face.gif</file>
     </qresource>
 </RCC>
index f53c88c..f9ad717 100644 (file)
@@ -33,7 +33,7 @@ SOURCES += main.cpp \
     ui/friendlistitem.cpp \
     user/user.cpp \
     ui/buttonitem.cpp \
-    ui/situareuser.cpp \
+    ui/avatarimage.cpp \
     engine/engine.cpp \
     ui/settingsdialog.cpp \
     map/maptilerequest.cpp \
@@ -68,7 +68,7 @@ HEADERS += ui/mainwindow.h \
     ui/friendlistitem.h \
     user/user.h \
     ui/buttonitem.h \
-    ui/situareuser.h \
+    ui/avatarimage.h \
     engine/engine.h \
     ui/settingsdialog.h \
     map/maptilerequest.h \
diff --git a/src/ui/avatarimage.cpp b/src/ui/avatarimage.cpp
new file mode 100644 (file)
index 0000000..78100bd
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jukka Saastamoinen - jukka.saastamoinen@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 "avatarimage.h"
+#include <QPainter>
+#include <QDebug>
+
+const int BORDER_X_OFFSET = 7;
+const int BORDER_Y_OFFSET = 7;
+const int RECT_WIDTH_OFFSET = 1;
+const int RECT_HEIGHT_OFFSET = 1;
+const int ROUNDNESS = 9;
+const int IMAGE_SIZE_X = 60;
+const int IMAGE_SIZE_Y = 60;
+
+
+QPixmap AvatarImage::make(const QPixmap &image)
+{
+    QPixmap avatarImage;    // = QPixmap(IMAGE_SIZE_X, IMAGE_SIZE_Y);
+    QPainter painter(&avatarImage);
+//    QLabel label;
+//    label.setPixmap(image);
+
+    QRect widgetRect = QRect(0, 0, image.width(), image.height());
+
+    painter.setRenderHint(QPainter::Antialiasing);
+    QPainterPath roundedRect;
+    roundedRect.addRoundedRect(5, 5, widgetRect.width()+RECT_WIDTH_OFFSET,
+                               widgetRect.height()+RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
+    painter.setClipPath(roundedRect);
+    //QRegion maskRegion = painter.clipRegion();
+
+    //label.setMask(maskRegion);
+
+    painter.drawPixmap(QPointF(5, 5), image);
+    //label.clearMask();
+
+    painter.drawPixmap(QPoint(0, 0), QPixmap(":/res/images/profile_pic_border.png"));
+
+
+    return avatarImage;
+}
diff --git a/src/ui/avatarimage.h b/src/ui/avatarimage.h
new file mode 100644 (file)
index 0000000..23a105d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jukka Saastamoinen - jukka.saastamoinen@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 SITUAREUSER_H
+#define SITUAREUSER_H
+
+#include <QLabel>
+#include <QPixmap>
+
+/**
+* @brief User class for personal information tab
+*
+* @class SituareUser situareuser.h "ui/situareuser.h"
+*/
+class AvatarImage
+{
+public:
+    static QPixmap make(const QPixmap &image);
+};
+
+#endif // SITUAREUSER_H
index d6838eb..f99aad8 100644 (file)
 
 #include "friendlistitem.h"
 #include "../user/user.h"
+#include "avatarimage.h"
 
 const QString BACKGROUND_PATH = ":/res/images/list_item.png";   ///< Background image path
-//const QString BACKGROUND_TOP_PATH = ":/res/images/list_item_top.png";   ///< Background image path
-//const QString BACKGROUND_MIDDLE_PATH = ":/res/images/list_item_middle.png";   ///< Background image path
-//const QString BACKGROUND_BOTTOM_PATH = ":/res/images/list_item_bottom.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 MARGIN = 5;   ///< Icon margin
 const int IMAGE_HEIGHT = 60; ///< Friend image height
 const int IMAGE_WIDTH = 60;  ///< Friend image width
 
@@ -55,17 +53,10 @@ const int LABEL_MAX_WIDTH = 247;   ///< Label maximum width
 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
 
-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 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
 
-/**
-* @var STYLESHEET
-* @brief Stylesheet for FriendListItem
-*/
-const QString STYLESHEET = "QWidget#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 }";
+const QColor COLOR_GRAY = QColor(152, 152, 152);
 
 FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
@@ -75,6 +66,8 @@ FriendListItem::FriendListItem(QWidget *parent)
     qDebug() << __PRETTY_FUNCTION__;
 
     QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->setContentsMargins(MARGIN, 0, MARGIN*2, MARGIN*2);
+    layout->setSpacing(0);
     this->setLayout(layout);
 
     QHBoxLayout *topLayout = new QHBoxLayout();
@@ -91,13 +84,13 @@ FriendListItem::FriendListItem(QWidget *parent)
 
     QLabel *clockLabel = new QLabel();
     clockLabel->setPixmap(QPixmap(CLOCK_PATH));
-    clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+    clockLabel->setContentsMargins(0, 0, MARGIN, 0);
     QLabel *envelopeLabel = new QLabel();
     envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
-    envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+    envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
     QLabel *compassLabel = new QLabel();
     compassLabel->setPixmap(QPixmap(COMPASS_PATH));
-    compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
+    compassLabel->setContentsMargins(0, 0, MARGIN, 0);
 
     m_imageLabel = new QLabel();
     m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
@@ -105,6 +98,16 @@ FriendListItem::FriendListItem(QWidget *parent)
     m_nameLabel = new QLabel();
     m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
 
+    m_distanceLabel = new QLabel();
+    m_distanceLabel->setFixedHeight(IMAGE_HEIGHT);
+    //m_distanceLabel->setAlignment(Qt::AlignHCenter | Qt::AlignRight);
+//    m_distanceLabel->setMinimumWidth(IMAGE_WIDTH + 15);
+//    m_distanceLabel->setMaximumWidth(IMAGE_WIDTH + 15);
+
+    QLabel *button = new QLabel();
+    button->setPixmap(QPixmap("res/images/show_position.png"));
+    button->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
+
     m_updatedLabel = new QLabel();
     m_updatedLabel->setWordWrap(true);
     m_statusTextLabel = new QLabel();
@@ -117,10 +120,11 @@ FriendListItem::FriendListItem(QWidget *parent)
     infoLayout->addRow(clockLabel, m_updatedLabel);
 
     topLayout->addWidget(m_imageLabel);
-    topLayout->addWidget(m_nameLabel);
+    topLayout->addWidget(m_nameLabel, 1);
+    topLayout->addWidget(m_distanceLabel);
 
-    bottomLayout->addSpacing(IMAGE_WIDTH);
-    bottomLayout->addLayout(infoLayout, 1);
+    bottomLayout->addWidget(button, 0, Qt::AlignTop);
+    bottomLayout->addLayout(infoLayout);
 
     layout->addLayout(topLayout, 0);
     layout->addLayout(bottomLayout, 1);
@@ -131,7 +135,7 @@ FriendListItem::FriendListItem(QWidget *parent)
     setFont(NOKIA_FONT_SMALL);
     m_nameLabel->setFont(NOKIA_FONT_NORMAL);
     QPalette itemPalette = palette();
-    itemPalette.setColor(QPalette::Foreground, QColor(152, 152, 152));
+    itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
     setPalette(itemPalette);
     QPalette namePalette = m_nameLabel->palette();
     namePalette.setColor(QPalette::Foreground, Qt::white);
@@ -149,8 +153,11 @@ void FriendListItem::setData(User *user)
     if (user) {
         m_user = user;
         shortenTexts();
-
-        m_imageLabel->setPixmap(m_user->profileImage());
+        m_imageLabel->setPixmap(AvatarImage::make(m_user->profileImage()));
+        QString unit;
+        double value;
+        user->distance(value, unit);
+        m_distanceLabel->setText(QString::number(value) + " " + unit);
         setText(false);
     }
 }
@@ -202,16 +209,20 @@ void FriendListItem::setText(bool expanded)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (expanded) {
+        setUpdatesEnabled(false);
         m_nameLabel->setText(m_shortenedName);
         m_updatedLabel->setText(m_user->timestamp());
         m_statusTextLabel->setText(m_user->note());
         m_locationLabel->setText(m_user->address());
+        setUpdatesEnabled(true);
     }
     else {
+        setUpdatesEnabled(false);
         m_nameLabel->setText(m_shortenedName);
         m_updatedLabel->setText(m_shortenedUpdated);
         m_statusTextLabel->setText(m_shortenedStatusText);
         m_locationLabel->setText(m_shortenedLocation);
+        setUpdatesEnabled(true);
     }
 }
 
@@ -245,12 +256,10 @@ void FriendListItem::paintEvent(QPaintEvent *event)
 
     QPainter painter(this);
 
-    int height = event->rect().height();
-
     QRect topRect = QRect(0, 0, event->rect().width(), 20);
-    QRect middleRect = QRect(0, topRect.bottom() + 1, event->rect().width(),
-                             height + event->rect().top() - 20 - 15);
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, event->rect().width(),
+    QRect middleRect = QRect(0, topRect.bottom(), event->rect().width(),
+                             height() - 20 - 15);
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), event->rect().width(),
                              15);
 
     painter.drawPixmap(topRect, m_backgroundTopImage);
index acfa7cf..a07161f 100644 (file)
@@ -27,7 +27,6 @@
 #include <QListWidgetItem>
 
 #include "../user/user.h"
-#include "situareuser.h"
 
 class QLabel;
 
@@ -103,10 +102,17 @@ private:
     void setText(bool expanded);
 
 /******************************************************************************
+* SIGNALS
+******************************************************************************/
+signals:
+    void findButtonClicked(const QPointF &coordinates);
+
+/******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
     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
index d61c9a5..33edabe 100644 (file)
@@ -66,10 +66,14 @@ FriendListPanel::FriendListPanel(QWidget *parent)
 
     //Debug
     QList<User *> friendList;
-    for (int i = 0; i < 10; ++i)
-        friendList.append(new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
-                                   QString("Hello world! Hello world! Hello world! Hello world! "),
-                                   QUrl(), QString("2 days ago"), false, QString("id")));
+    for (int i = 0; i < 10; ++i) {
+        User *user = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name Name Name Naem"),
+                              QString("Hello world! Hello world! Hello world! Hello world! "),
+                              QUrl(), QString("2 days ago"), false, QString("id"), QString("km"),
+                              10000);
+        user->setProfileImage(QPixmap("res/images/face.gif"));
+        friendList.append(user);
+    }
     friendInfoReceived(friendList);
 
     this->setObjectName("UserPanel");
index 9f39004..43377c2 100644 (file)
@@ -39,7 +39,6 @@ InfoTab::InfoTab(QWidget *parent)
     verticalLayout = new QVBoxLayout(widget);
     horizontalLayout = new QHBoxLayout(widget);
     m_layout = new QGridLayout(widget);
-    situUser = new SituareUser(widget);
 
     //Tex color settings
     QPalette textPalette;
@@ -75,7 +74,7 @@ InfoTab::InfoTab(QWidget *parent)
     m_clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
     m_envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
     m_compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
-    m_layout->addWidget(situUser,0,0,1,2,Qt::AlignHCenter);
+//    m_layout->addWidget(situUser,0,0,1,2,Qt::AlignHCenter);
     m_layout->addWidget(m_userNameLabel,1,1,1,2);
     m_layout->addWidget(m_clockLabel,3,0,1,1);
     m_layout->addWidget(m_envelopeLabel,2,0,1,1);
@@ -119,7 +118,6 @@ QSize InfoTab::sizeHint() const
 void InfoTab::setAvatar(const QPixmap &avat)
 {
     m_avatar = avat;
-    situUser->setPixmap(m_avatar);
 }
 
 void InfoTab::setUserName(const QString &usernam)
index dec7dbd..f6db477 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <QtGui>
 #include <QWidget>
-#include "situareuser.h"
+#include "avatarimage.h"
 
 /**
 * @brief InfoTab class.
@@ -119,7 +119,6 @@ private:
     QString m_userName;       ///< User's name
     QPixmap m_avatar;         ///< User's avatar
     QWidget *widget;          ///< Parent of all widgets.
-    SituareUser *situUser;    ///< Situare user's framed picture
     QVBoxLayout *verticalLayout; ///< Vertical layout for personal infotab
     QHBoxLayout *horizontalLayout; ///< Horizontal layout for personal infotab
     QGridLayout *m_layout; ///< Grid layout for personal infotab
index a0b6240..ac6a631 100644 (file)
@@ -36,7 +36,6 @@
 #include "friendlistview.h"
 #include "friendlistitem.h"
 #include "user/user.h"
-#include "situareuser.h"
 #include "mainwindow.h"
 
 const int INFOTAB_Y_LOC_STATE1 = 71;
diff --git a/src/ui/situareuser.cpp b/src/ui/situareuser.cpp
deleted file mode 100644 (file)
index 03dc65d..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jukka Saastamoinen - jukka.saastamoinen@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 "situareuser.h"
-#include <QPainter>
-#include <QDebug>
-
-const int BORDER_X_OFFSET = 7;
-const int BORDER_Y_OFFSET = 7;
-const int RECT_WIDTH_OFFSET = 1;
-const int RECT_HEIGHT_OFFSET = 1;
-const int ROUNDNESS = 9;
-const int PIC_SIZE_X = 50;
-const int PIC_SIZE_Y = 50;
-
-SituareUser::SituareUser(QWidget *parent)
-    : QLabel(parent)
-{
-    this->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
-    this->setMargin(1);
-}
-
-void SituareUser::paintEvent(QPaintEvent *aPaintEvent)
-{
-    Q_UNUSED(aPaintEvent);
-
-    QRect widgetRect = QRect(0,0,this->pixmap()->width(),this->pixmap()->height());
-
-    QPainter painter(this);
-    painter.save();
-
-    painter.setRenderHint(QPainter::Antialiasing);
-    QPainterPath roundedRect;
-    roundedRect.addRoundedRect(0,0,widgetRect.width()+RECT_WIDTH_OFFSET,
-                               widgetRect.height()+RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
-    painter.setClipPath(roundedRect);
-    QRegion maskRegion = painter.clipRegion();
-
-    setMask(maskRegion);
-
-    painter.drawPixmap(QPointF(0, 0), (*(this->pixmap())));
-    clearMask();
-
-    painter.drawPixmap(QPointF(-BORDER_X_OFFSET,-BORDER_Y_OFFSET),
-                       (QPixmap(":/res/images/profile_pic_border.png")));
-
-    painter.restore();
-}
-
-QSize SituareUser::sizeHint() const
-{
-    return QSize(PIC_SIZE_X, PIC_SIZE_Y);
-}
diff --git a/src/ui/situareuser.h b/src/ui/situareuser.h
deleted file mode 100644 (file)
index c56a9ee..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Jukka Saastamoinen - jukka.saastamoinen@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 SITUAREUSER_H
-#define SITUAREUSER_H
-
-#include <QLabel>
-#include <QPixmap>
-
-/**
-* @brief User class for personal information tab
-*
-* @class SituareUser situareuser.h "ui/situareuser.h"
-*/
-class SituareUser : public QLabel
-{
-    Q_OBJECT
-public:
-    /**
-    * @brief Constructor
-    *
-    * @param parent Parent
-    */
-    SituareUser(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 This function suggests layouter correct size.
-    *
-    * @return QSize Size of the label
-    */
-    QSize sizeHint() const;
-};
-
-#endif // SITUAREUSER_H