Modified FriendListItem and -Delegate to use ExtendedListItem and
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 29 Jul 2010 13:01:21 +0000 (16:01 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 29 Jul 2010 13:01:21 +0000 (16:01 +0300)
-Delegate.

32 files changed:
src/engine/engine.cpp
src/routing/routingservice.cpp
src/src.pro
src/ui/extendedlistitem.cpp
src/ui/extendedlistitem.h
src/ui/extendedlistitemdelegate.cpp
src/ui/extendedlistitemdelegate.h
src/ui/extendedlistitemstore.cpp
src/ui/extendedlistitemstore.h
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistitemdelegate.cpp
src/ui/friendlistitemdelegate.h
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/friendlistview.cpp
src/ui/friendlistview.h
src/ui/listcommon.h
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listitemdelegate.cpp
src/ui/listview.cpp
src/ui/listview.h
src/ui/locationlistitem.cpp
src/ui/locationlistitem.h
src/ui/locationlistview.cpp
src/ui/locationlistview.h
src/ui/mainwindow.cpp
tests/ui/friendlistitem/friendlistitem.pro
tests/ui/friendlistitem/testfriendlistitem.cpp
tests/ui/listview/listview.pro
tests/ui/listview/testlistview.cpp

index 9dac412..39f0650 100644 (file)
@@ -638,15 +638,15 @@ void SituareEngine::signalsFromMainWindow()
     connect(m_ui, SIGNAL(findFriend(GeoCoordinate)),
             m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
 
+    connect(m_ui, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
+            m_mapEngine, SLOT(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+
     // signals from distence indicator button
     connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
             this, SLOT(changeAutoCenteringSetting(bool)));
 
     connect(m_ui, SIGNAL(searchForLocation(QString)),
             this, SLOT(locationSearch(QString)));
-
-    connect(m_ui, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
-            m_mapEngine, SLOT(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
 }
 
 void SituareEngine::signalsFromMapEngine()
index 8a536a3..2008490 100644 (file)
@@ -149,7 +149,7 @@ void RoutingService::parseSearchResults(const QByteArray &jsonReply)
                 location.setCoordinates(locationMap["lat"].toDouble(),
                                         locationMap["lng"].toDouble());
 
-                QVariant boundsVariant = geometryMap["bounds"];
+                QVariant boundsVariant = geometryMap["viewport"];
                 QMap<QString, QVariant> boundsMap = boundsVariant.toMap();
                 QVariant swVariant = boundsMap["southwest"];
                 QMap<QString, QVariant> swMap = swVariant.toMap();
index 9a969ff..838a7df 100644 (file)
@@ -71,7 +71,8 @@ SOURCES += main.cpp \
     ui/extendedlistitem.cpp \
     ui/extendedlistitemstore.cpp \
     ui/extendedlistitemdelegate.cpp \
-    ui/locationlistview.cpp
+    ui/locationlistview.cpp \
+    ui/friendlistview.cpp
 HEADERS += application.h \
     common.h \
     engine/engine.h \
@@ -143,7 +144,8 @@ HEADERS += application.h \
     ui/extendedlistitem.h \
     ui/extendedlistitemstore.h \
     ui/extendedlistitemdelegate.h \
-    ui/locationlistview.h
+    ui/locationlistview.h \
+    ui/friendlistview.h
 QT += network \
     webkit
 
index 4644b42..95b65da 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "extendedlistitem.h"
 
-const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT;
+const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT;    ///< Sub item text row height
 
 ExtendedListItem::ExtendedListItem()
     : m_selected(false),
@@ -57,6 +57,17 @@ void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
     m_subItemStoreList->append(itemStore);
 }
 
+void ExtendedListItem::clearSubItems()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    qDeleteAll(m_subItemStoreList->begin(), m_subItemStoreList->end());
+    m_subItemStoreList->clear();
+
+    m_expandedHeight = ITEM_MIN_HEIGHT;
+    m_normalHeight = ITEM_MIN_HEIGHT;
+}
+
 QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -67,15 +78,13 @@ QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
     QFontMetrics textMetrics = painter.fontMetrics();
 
     QRect textRect = textMetrics.boundingRect(text);
-    qWarning() << textRect.width() << textRect.height();
     int textRectFactor = textRect.width() / m_subItemTextWidth;
     textRectFactor++;
     QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
                                    * textRectFactor);
-    qWarning() << expandedTextRect.width() << expandedTextRect.height();
+
     m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT;
     m_expandedHeight += expandedTextRect.height();
-
     setSize(QSize(ITEM_WIDTH, m_normalHeight));
 
     return expandedTextRect;
@@ -83,12 +92,14 @@ QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
 
 void ExtendedListItem::setSubitemTextWidth(int width)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_subItemTextWidth = width;
 }
 
 bool ExtendedListItem::toggleSelection()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     setSelected(!m_selected);
     return m_selected;
@@ -96,7 +107,7 @@ bool ExtendedListItem::toggleSelection()
 
 void ExtendedListItem::setSelected(bool selected)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_selected = selected;
     setData(ITEM_EXPANDED_INDEX, m_selected);
@@ -107,3 +118,11 @@ void ExtendedListItem::setSelected(bool selected)
         setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
     }
 }
+
+ExtendedListItem::~ExtendedListItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    clearSubItems();
+    delete m_subItemStoreList;
+}
index 65a1ea8..7fd1909 100644 (file)
@@ -7,14 +7,45 @@
 
 class ExtendedListItemStore;
 
+/**
+* @brief Base class for extended list items.
+*/
 class ExtendedListItem : public ListItem
 {
 public:
+    /**
+    * @brief Constructor.
+    *
+    * Sets item size and creates sub item store list.
+    */
     ExtendedListItem();
 
+    /**
+    * @brief Destructor.
+    *
+    * Deletes sub item stores and sub item store list.
+    */
+    virtual ~ExtendedListItem();
+
 /*******************************************************************************
- * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
- ******************************************************************************/
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Adds sub item.
+    *
+    * Sub item area is defined by sub item text width.
+    * @param text sub item text
+    * @param icon sub item icon, optional
+    */
+    void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
+
+    /**
+    * @brief Clears sub items.
+    *
+
+    */
+    void clearSubItems();
 
     /**
     * @brief Sets item selected.
@@ -23,6 +54,11 @@ public:
     */
     void setSelected(bool selected);
 
+    /**
+    * @brief Sets sub items' text width.
+    *
+    * @param width sub item width
+    */
     void setSubitemTextWidth(int width);
 
     /**
@@ -32,18 +68,26 @@ public:
     */
     bool toggleSelection();
 
-    void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
-
 private:
+    /**
+    * @brief Calculates text rects.
+    *
+    * Rect width is defined by sub item text width.
+    * @param text text which rect is calculated
+    * @return text rect
+    */
     QRect calculateExpandedTextRect(const QString &text);
 
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
 private:
-    bool m_selected;
-    int m_expandedHeight;
-    int m_normalHeight;
-    int m_subItemTextWidth;
+    bool m_selected;        ///< Selected flag
+    int m_expandedHeight;   ///< Item expanded height
+    int m_normalHeight;     ///< Item normal height
+    int m_subItemTextWidth; ///< Sub items' text wdith
 
-    QList<ExtendedListItemStore *> *m_subItemStoreList;
+    QList<ExtendedListItemStore *> *m_subItemStoreList; ///< ExtendedListItemStore list
 };
 
 #endif // EXTENDEDLISTITEM_H
index 8fa2ec5..6826945 100644 (file)
@@ -8,13 +8,17 @@
 
 #include "extendedlistitemdelegate.h"
 
-ExtendedListItemDelegate::ExtendedListItemDelegate()
+ExtendedListItemDelegate::ExtendedListItemDelegate(QWidget *parent)
+    : ListItemDelegate(parent)
 {
+    qDebug() << __PRETTY_FUNCTION__;
 }
 
 void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                                      const QModelIndex &index) const
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     ListItemDelegate::paint(painter, option, index);
 
     painter->setPen(COLOR_GRAY);
@@ -24,6 +28,7 @@ void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
     QList<ExtendedListItemStore *> *subItems = (QList<ExtendedListItemStore *> *)
                                                (index.data(SUBITEM_STORE_INDEX).value<void *>());
     bool expanded = index.data(ITEM_EXPANDED_INDEX).toBool();
+    bool itemHasImage = index.data(ITEM_HAS_IMAGE_INDEX).toBool();
 
     if (subItems) {
 
@@ -43,9 +48,13 @@ void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
                 text = itemStore->shortenedText();
             }
 
-            QRect iconRect = QRect(itemRect.left() + MARGIN*2,
-                                       previousSubItemTextRectBottom,
+            QRect iconRect = QRect(itemRect.left() + MARGIN*3,
+                                       previousSubItemTextRectBottom + ICON_MARGIN,
                                        ICON_WIDTH, ICON_HEIGHT);
+
+            if (itemHasImage)
+                iconRect.translate(IMAGE_WIDTH, 0);
+
             subItemTextRect.translate(iconRect.right() + MARGIN, iconRect.top());
 
             if (!itemStore->icon().isNull())
@@ -56,9 +65,3 @@ void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
         }
     }
 }
-
-QSize ExtendedListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
-                                        const QModelIndex &index) const
-{
-    return ListItemDelegate::sizeHint(option, index);
-}
index 340b95f..5de6e14 100644 (file)
@@ -3,34 +3,32 @@
 
 #include "listitemdelegate.h"
 
+/**
+* @brief Defines ExtendedListItem style.
+*/
 class ExtendedListItemDelegate : public ListItemDelegate
 {
 public:
-    ExtendedListItemDelegate();
+    /**
+    * @brief Constructor
+    *
+    * @param parent QWidget
+    */
+    ExtendedListItemDelegate(QWidget *parent = 0);
 
 /*******************************************************************************
  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
  ******************************************************************************/
     /**
-    * @brief Draws FriendListItem data.
+    * @brief Draws ExtendedListItem content.
     *
-    * Draws distance, status, updated and location texts with icons.
+    * Draws ExtendedListItem sub items icon and text.
     * @param painter QPainter
     * @param option QStyleOptionViewItem
     * @param index QModelIndex
     */
     void paint(QPainter *painter, const QStyleOptionViewItem &option,
                const QModelIndex &index) const;
-
-    /**
-    * @brief Returns item's size hint.
-    *
-    * @param option QStyleOptionViewItem
-    * @param index QModelIndex
-    * @return QSize
-    */
-    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
-
 };
 
 #endif // EXTENDEDLISTITEMDELEGATE_H
index 7190e1c..1bff51e 100644 (file)
@@ -2,10 +2,6 @@
 
 #include "extendedlistitemstore.h"
 
-ExtendedListItemStore::ExtendedListItemStore()
-{
-}
-
 ExtendedListItemStore::ExtendedListItemStore(const QString &text)
     : m_icon(QPixmap()),
       m_textRect(QRect()),
index d80bea8..c0b3ee1 100644 (file)
@@ -6,29 +6,81 @@
 #include <QString>
 #include <QMetaType>
 
+/**
+* @brief Store ExtendedListItem data.
+*/
 class ExtendedListItemStore
 {
 public:
-    ExtendedListItemStore();
-
+    /**
+    * @brief Constructor.
+    *
+    * Sets text.
+    * @param text item text
+    */
     ExtendedListItemStore(const QString &text);
 
+/*******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Sets shortended text.
+    *
+    * @param shortenedText shortened text
+    */
     void setShortenedText(const QString &shortenedText);
 
+    /**
+    * @brief Sets icon.
+    *
+    * @param icon item icon
+    */
     void setIcon(const QPixmap &icon);
 
+    /**
+    * @brief Sets text rect.
+    *
+    * @param textRect text rect
+    */
     void setTextRect(const QRect &textRect);
 
+    /**
+    * @brief Returns icon.
+    *
+    * @return QPixmap
+    */
     QPixmap icon() const;
+
+    /**
+    * @brief Returns text rect.
+    *
+    * @return QRect
+    */
     QRect textRect() const;
+
+    /**
+    * @brief Returns text
+    *
+    * @return QString
+    */
     QString text() const;
+
+    /**
+    * @brief Returns shortened text.
+    *
+    * @return QString
+    */
     QString shortenedText() const;
 
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
 private:
-    QPixmap m_icon;
-    QRect m_textRect;
-    QString m_text;
-    QString m_shortenedText;
+    QPixmap m_icon;             ///< Icon pixmap
+    QRect m_textRect;           ///< Text rect
+    QString m_text;             ///< Text string
+    QString m_shortenedText;    ///< Shortened text string
 };
 
 #endif // EXTENDEDLISTITEMSTORE_H
index e59ead4..f3ffc68 100644 (file)
    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 "friendlistitem.h"
 #include "../user/user.h"
-#include "imagebutton.h"
 #include "../common.h"
 #include "listcommon.h"
 
+#include "friendlistitem.h"
+
 const int WALK_DISTANCE = 5;        ///< Walk distance limit for distance icon
 const int CAR_DISTANCE = 500;       ///< Car distance limit for distance icon
 const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
 
-const int RECTS_MINIMUM_FACTOR_SUM = 3; ///< Rects minimum factor sum
-
 FriendListItem::FriendListItem()
-    : m_selected(false)
-    , m_user(0)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-}
-
-void FriendListItem::calculateTextRects()
+    : m_user(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    //Dummy value to get painter font metrics.
-    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
-    QPainter painter(&p);
-    painter.setFont(NOKIA_FONT_SMALL);
-    QFontMetrics smallFontMetrics = painter.fontMetrics();
-
-    QRect distanceRect = smallFontMetrics.boundingRect(m_distanceText);
-    QRect statusTextRect = smallFontMetrics.boundingRect(m_user->note());
-    QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
-    QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
-
-    int statusTextRectFactor = statusTextRect.width() / SUBITEM_TEXT_MAX_WIDTH;
-    statusTextRectFactor++;
-    m_statusTextRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
-    int updatedRectFactor = updatedRect.width() / SUBITEM_TEXT_MAX_WIDTH;
-    updatedRectFactor++;
-    m_updatedRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
-    int locationRectFactor = locationRect.width() / SUBITEM_TEXT_MAX_WIDTH;
-    locationRectFactor++;
-    m_locationRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * locationRectFactor);
-
-    m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
-                                           locationRectFactor - RECTS_MINIMUM_FACTOR_SUM)
-                                          * ICON_HEIGHT);
-
-    setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+    setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
 }
 
 GeoCoordinate FriendListItem::coordinates()
@@ -105,19 +62,32 @@ void FriendListItem::setUserData(User *user)
     if(user) {
         m_user = user;
 
-        if (!m_user->profileImage().isNull())
-            setImage(m_user->profileImage());
-
         QString unit;
         double value;
         m_user->distance(value, unit);
-        m_distanceText = QString::number(value) + " " + unit;
-        setData(DISTANCE_TEXT_DISPLAY_INDEX, m_distanceText);
+        QString distanceText = QString::number(value) + " " + unit;
+        setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
         setDistanceIcon(value, unit);
 
-        shortenTexts();
-        calculateTextRects();
-        setText(false);
+        //Dummy value to get painter font metrics.
+        QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+        QPainter painter(&p);
+        painter.setFont(NOKIA_FONT_SMALL);
+        QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
+        QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
+
+        setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+        setName(shortenText(m_user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
+                            ListItem::TEXT_SIZE_NORMAL));
+
+        if (!m_user->profileImage().isNull())
+            setImage(m_user->profileImage());
+
+        clearSubItems();
+
+        addSubItem(m_user->note(), QPixmap(":/res/images/envelope.png"));
+        addSubItem(m_user->address(), QPixmap(":/res/images/compass.png"));
+        addSubItem(m_user->timestamp(), QPixmap(":/res/images/clock.png"));
     }
 }
 
@@ -126,7 +96,7 @@ void FriendListItem::setAvatarImage(const QPixmap &image)
     qDebug() << __PRETTY_FUNCTION__;
 
     if(!image.isNull())
-        setImage(m_user->profileImage());
+        setImage(image);
 }
 
 void FriendListItem::setDistanceIcon(double value, const QString &unit)
@@ -147,61 +117,7 @@ void FriendListItem::setDistanceIcon(double value, const QString &unit)
     setData(DISTANCE_IMAGE_INDEX, distanceImage);
 }
 
-void FriendListItem::shortenTexts()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    int distanceLabelWidth = 50;//otherLabelsMetrics.width(m_distanceText) + MARGIN;
-    setName(shortenText(m_user->name(), NAME_TEXT_MAX_WIDTH - distanceLabelWidth,
-                        ListItem::TEXT_SIZE_NORMAL));
-
-    m_shortenedStatusText = shortenText(m_user->note(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
-    m_shortenedUpdated = shortenText(m_user->timestamp(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
-    m_shortenedLocation = shortenText(m_user->address(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
-}
-
-void FriendListItem::setText(bool expanded)
+FriendListItem::~FriendListItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    if (expanded) {
-        setData(STATUS_TEXT_DISPLAY_INDEX, m_user->note());
-        setData(LOCATION_DISPLAY_INDEX, m_user->address());
-        setData(UPDATED_DISPLAY_INDEX, m_user->timestamp());
-
-        setData(STATUS_TEXT_SIZE_HINT_INDEX, m_statusTextRect);
-        setData(LOCATION_SIZE_HINT_INDEX, m_locationRect);
-        setData(UPDATED_SIZE_HINT_INDEX, m_updatedRect);
-    } else {
-        setData(STATUS_TEXT_DISPLAY_INDEX, m_shortenedStatusText);
-        setData(LOCATION_DISPLAY_INDEX, m_shortenedLocation);
-        setData(UPDATED_DISPLAY_INDEX, m_shortenedUpdated);
-
-        setData(STATUS_TEXT_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
-        setData(LOCATION_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
-        setData(UPDATED_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
-    }
-}
-
-bool FriendListItem::toggleSelection()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    setSelected(!m_selected);
-    return m_selected;
-}
-
-void FriendListItem::setSelected(bool selected)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_selected = selected;
-
-    if (m_selected) {
-        setText(true);
-        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
-    } else {
-        setText(false);
-        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-    }
 }
index e0f0b7f..3f5b968 100644 (file)
 #include <QListWidgetItem>
 
 #include "../user/user.h"
-#include "listitem.h"
+#include "extendedlistitem.h"
 
 /**
-* @brief Stores friend's data.
-*
-* Calculates shortened texts from user data and rects from user data.
-* Rects are used to calculate text field's sizes. Class inherits ListItem.
+* @brief List item stores information about friends.
 */
-class FriendListItem : public ListItem
+class FriendListItem : public ExtendedListItem
 {
 
 public:
     /**
     * @brief Constructor.
     *
-    * Sets default size hint for item.
+    * Sets sub items' text width.
     */
     FriendListItem();
 
+    /**
+    * @brief Destructor.
+    */
+    ~FriendListItem();
 /*******************************************************************************
  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
  ******************************************************************************/
@@ -63,20 +64,6 @@ public:
     */
     QString id() const;
 
-    /**
-    * @brief Sets item selected.
-    *
-    * @param selected true if selected, false otherwise
-    */
-    void setSelected(bool selected);
-
-    /**
-    * @brief Toggles selection.
-    *
-    * @return true if selection was toggled, false otherwise
-    */
-    bool toggleSelection();
-
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -97,14 +84,6 @@ public:
 
 private:
     /**
-    * @brief Calculates text rects.
-    *
-    * Caclulates distance, status, updated and location texts rects. Sets item's
-    * expanded height from rects.
-    */
-    void calculateTextRects();
-
-    /**
     * @brief Set distance icon.
     *
     * Icon is selected by distance.
@@ -114,37 +93,10 @@ private:
     */
     void setDistanceIcon(double value, const QString &unit);
 
-    /**
-    * @brief Sets shortened or full-length text to item.
-    *
-    * Sets also size hint for status, updated and location texts defined by calculated
-    * text rects or default size.
-    *
-    * @param expanded true if full-length text is set, false otherwise
-    */
-    void setText(bool expanded);
-
-    /**
-    * @brief Calculates shortened texts from User data.
-    *
-    * Text length is defined by NAME_LABEL_MAX_WIDTH and LABEL_MAX_WIDTH.
-    */
-    void shortenTexts();
-
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    bool m_selected;                ///< Item selected state
-    QRect m_locationRect;           ///< Location text rect
-    QRect m_statusTextRect;         ///< Status text rect
-    QRect m_updatedRect;            ///< Updated text rect
-    int m_expandedHeight;           ///< Item's expanded height
-    QString m_distanceText;         ///< Distance text
-    QString m_shortenedLocation;    ///< Shortened location text
-    QString m_shortenedStatusText;  ///< Shortened status text
-    QString m_shortenedUpdated;     ///< Shortened updated text
-
     User *m_user;                   ///< User data
 };
 
index 9f5e9b6..174a830 100644 (file)
 #include "../common.h"
 #include "listcommon.h"
 
-FriendListItemDelegate::FriendListItemDelegate()
+FriendListItemDelegate::FriendListItemDelegate(QWidget *parent)
+    : ExtendedListItemDelegate(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    m_clockImage = QPixmap(":/res/images/clock.png");
-    m_envelopeImage = QPixmap(":/res/images/envelope.png");
-    m_compassImage = QPixmap(":/res/images/compass.png");
 }
 
 void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
@@ -40,14 +37,11 @@ void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ListItemDelegate::paint(painter, option, index);
+    ExtendedListItemDelegate::paint(painter, option, index);
 
     painter->setPen(COLOR_GRAY);
     painter->setFont(NOKIA_FONT_SMALL);
 
-    QString statusText = index.data(STATUS_TEXT_DISPLAY_INDEX).toString();
-    QString location = index.data(LOCATION_DISPLAY_INDEX).toString();
-    QString updated = index.data(UPDATED_DISPLAY_INDEX).toString();
     QString distance = index.data(DISTANCE_TEXT_DISPLAY_INDEX).toString();
     QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(DISTANCE_IMAGE_INDEX)));
 
@@ -60,36 +54,4 @@ void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 
     painter->drawPixmap(distanceIconPoint, distanceIcon);
     painter->drawText(distanceRect, Qt::TextSingleLine, distance);
-
-    QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 3*MARGIN,
-                               itemRect.top() + IMAGE_HEIGHT - 2*MARGIN, ICON_WIDTH, ICON_HEIGHT);
-    QRect statusTextRect = index.data(STATUS_TEXT_SIZE_HINT_INDEX).toRect();
-    statusTextRect.translate(envelopeRect.right() + MARGIN, envelopeRect.top());
-
-    painter->drawPixmap(envelopeRect, m_envelopeImage);
-    painter->drawText(statusTextRect, Qt::TextWrapAnywhere, statusText);
-
-    QRect compassRect = QRect(envelopeRect.left(), statusTextRect.bottom() + ICON_MARGIN,
-                              ICON_WIDTH, ICON_HEIGHT);
-    QRect locationRect = index.data(LOCATION_SIZE_HINT_INDEX).toRect();
-    locationRect.translate(compassRect.right() + MARGIN, compassRect.top());
-
-    painter->drawPixmap(compassRect, m_compassImage);
-    painter->drawText(locationRect, Qt::TextWrapAnywhere, location);
-
-    QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + ICON_MARGIN, ICON_WIDTH,
-                            ICON_HEIGHT);
-    QRect updatedRect = index.data(UPDATED_SIZE_HINT_INDEX).toRect();
-    updatedRect.translate(clockRect.right() + MARGIN, clockRect.top());
-
-    painter->drawPixmap(clockRect, m_clockImage);
-    painter->drawText(updatedRect, Qt::TextWrapAnywhere, updated);
-}
-
-QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
-                                      const QModelIndex &index) const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return ListItemDelegate::sizeHint(option, index);
 }
index fa8e1dc..df7355f 100644 (file)
 #ifndef FRIENDLISTITEMDELEGATE_H
 #define FRIENDLISTITEMDELEGATE_H
 
-#include "listitemdelegate.h"
+#include "extendedlistitemdelegate.h"
 
 /**
 * @brief Displays FriendListItem.
 *
 * Class is used to display FriendListItem data.
 */
-class FriendListItemDelegate : public ListItemDelegate
+class FriendListItemDelegate : public ExtendedListItemDelegate
 {
 public:
     /**
     * @brief Constructor.
     *
-    * Loads clock, compass and envelope images' pixmap.
+    * @param parent QWidget
     */
-    FriendListItemDelegate();
+    FriendListItemDelegate(QWidget *parent = 0);
 
 /*******************************************************************************
  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
@@ -45,30 +45,13 @@ public:
     /**
     * @brief Draws FriendListItem data.
     *
-    * Draws distance, status, updated and location texts with icons.
+    * Draws distance text and icon.
     * @param painter QPainter
     * @param option QStyleOptionViewItem
     * @param index QModelIndex
     */
     void paint(QPainter *painter, const QStyleOptionViewItem &option,
                const QModelIndex &index) const;
-
-    /**
-    * @brief Returns item's size hint.
-    *
-    * @param option QStyleOptionViewItem
-    * @param index QModelIndex
-    * @return QSize
-    */
-    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
-
-/*******************************************************************************
- * DATA MEMBERS
- ******************************************************************************/
-private:
-    QPixmap m_clockImage;   ///< Top background image
-    QPixmap m_compassImage;   ///< Middle background image
-    QPixmap m_envelopeImage;   ///< Bottom background image
 };
 
 #endif // FRIENDLISTITEMDELEGATE_H
index fcb7d79..ac7cf36 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #include "coordinates/geocoordinate.h"
-#include "listview.h"
+#include "friendlistview.h"
 #include "friendlistitem.h"
 #include "friendlistitemdelegate.h"
 #include "panelcommon.h"
@@ -37,6 +37,7 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     : SidePanel(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
+
     setType(SidePanel::FriendPanel);
 
     QHBoxLayout *filterLayout = new QHBoxLayout;
@@ -55,29 +56,26 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     filterLayout->addWidget(m_clearFilterButton);
     m_panelVBox->addWidget(m_friendListHeaderWidget);
 
-    QHBoxLayout *friendListLayout =  new QHBoxLayout;
+    QVBoxLayout *friendListLayout =  new QVBoxLayout;
     friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
                                          FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
 
-    m_friendListView = new ListView(this);
-    m_friendListView->setAutoFillBackground(false);
-    m_friendListView->viewport()->setAutoFillBackground(false);
-    m_friendListItemDelegate = new FriendListItemDelegate();
-    m_friendListView->setItemDelegate(m_friendListItemDelegate);
+    m_friendListView = new FriendListView(this);
+    m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
     //REMOVE
-    m_friendListView->hide();
+    //m_friendListView->hide();
 
     m_locationListView = new LocationListView(this);
-    m_locationListView->setAutoFillBackground(false);
-    m_locationListView->viewport()->setAutoFillBackground(false);
-    m_locationListView->setItemDelegate(new ExtendedListItemDelegate());
+    m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
+    //REMOVE
+    //m_locationListView->hide();
 
-    //friendListLayout->addWidget(m_friendListView);
+    friendListLayout->addWidget(m_friendListView);
     friendListLayout->addWidget(m_locationListView);
     m_panelVBox->addLayout(friendListLayout);
 
-    connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
-            this, SIGNAL(findFriend(GeoCoordinate)));
+    connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
+            this, SIGNAL(friendItemClicked(GeoCoordinate)));
 
     connect(m_clearFilterButton, SIGNAL(clicked()),
             this, SLOT(clearFriendListFilter()));
@@ -137,7 +135,7 @@ void FriendListPanel::clearFriendListFilter()
 
 void FriendListPanel::locationDataReady(QList<Location> &result)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_locationListView->clearList();
 
@@ -147,7 +145,14 @@ void FriendListPanel::locationDataReady(QList<Location> &result)
         m_locationListView->addListItem(QString::number(i), item);
     }
 
+    openPanel();
+
+    if (result.size() == 1) {
+        ListItem *item = m_locationListView->listItem(QString("0"));
 
+        if (item)
+            m_locationListView->listItemClicked(item);
+    }
 }
 
 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
index d605ca8..c934525 100644 (file)
@@ -32,7 +32,7 @@ class QWidget;
 
 class FriendListItemDelegate;
 class GeoCoordinate;
-class ListView;
+class FriendListView;
 class User;
 class Location;
 class LocationListView;
@@ -99,12 +99,18 @@ private slots:
  ******************************************************************************/
 signals:
     /**
-    * @brief Signal for friend finding.
+    * @brief Signal for friend item clicked.
     *
     * @param coordinates Target coordinate
     */
-    void findFriend(const GeoCoordinate &coordinates);
+    void friendItemClicked(const GeoCoordinate &coordinates);
 
+    /**
+    * @brief Signal for location item clicked.
+    *
+    * @param swBound south-west bound GeoCoordinate
+    * @param neBound north-east bound GeoCoordinate
+    */
     void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
 
 /*******************************************************************************
@@ -114,9 +120,8 @@ private:
     QWidget *m_friendListHeaderWidget;  ///< Friend list header widget
     QLabel *m_friendListLabel;          ///< Friend list label
     QPushButton *m_clearFilterButton;   ///< Button to clear list filtering
-    ListView *m_friendListView;         ///< Friend list view
-    LocationListView *m_locationListView;
-    FriendListItemDelegate *m_friendListItemDelegate;   ///< Friend list item delegate
+    FriendListView *m_friendListView;         ///< Friend list view
+    LocationListView *m_locationListView;   ///< Location list view
 };
 
 #endif // FRIENDLISTPANEL_H
index 46266e6..ec4ae30 100644 (file)
-/*
-   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 <QDebug>
-#include <QLabel>
+#include "friendlistitem.h"
 
 #include "friendlistview.h"
-#include "friendlistitem.h"
-#include "../user/user.h"
 
 FriendListView::FriendListView(QWidget *parent)
-    : QWidget(parent)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_friendListLayout = new QVBoxLayout(this);
-    m_friendListLayout->setMargin(0);
-    m_friendListLayout->setSpacing(0);
-    m_friendListLayout->setStretch(0, 0);
-    m_friendListLayout->setSizeConstraint(QLayout::SetFixedSize);
-
-    this->setLayout(m_friendListLayout);
-}
-
-void FriendListView::addWidget(const QString &key, QWidget *widget)
+    : ListView(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    if (!m_widgets.contains(key)) {
-        m_friendListLayout->addWidget(widget);
-        m_widgets.insert(key, widget);
-    }
 }
 
-void FriendListView::addWidgetToView(FriendListItem *item)
+void FriendListView::listItemClicked(QListWidgetItem *item)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_friendListLayout->addWidget(item);
-}
+    ListView::listItemClicked(item);
 
-void FriendListView::clearUnused(const QStringList &userIDs)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    foreach (QString key, m_widgets.keys()) {
-        if (!userIDs.contains(key)) {
-            QWidget *widget = m_widgets.value(key);
-            if (widget) {
-                m_friendListLayout->removeWidget(widget);
-                disconnect(widget, 0, 0, 0);
-                delete widget;
-                m_widgets.remove(key);
-            }
-        }
-    }
-}
-
-void FriendListView::filter(const QList<QString> &userIDs)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    foreach (QWidget *widget, m_widgets)
-        widget->hide();
-
-    foreach (QString userID, userIDs) {
-        QWidget *widget = m_widgets.value(userID);
-        if (widget)
-            widget->show();
-    }
-}
-
-void FriendListView::clearFilter()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    foreach (QWidget *widget, m_widgets)
-        widget->show();
-}
-
-bool FriendListView::contains(const QString &userID)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_widgets.contains(userID);
-}
-
-FriendListItem *FriendListView::widget(const QString &userID)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return static_cast<FriendListItem*>(m_widgets.value(userID));
-}
-
-FriendListItem *FriendListView::takeWidgetFromView(const QString &userID)
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    FriendListItem *friendListItem = dynamic_cast<FriendListItem*>(item);
 
-    FriendListItem *item = widget(userID);
-    m_friendListLayout->removeWidget(item);
-    return item;
+    if (friendListItem)
+        emit friendItemClicked(friendListItem->coordinates());
 }
index 2affb57..5d0304f 100644 (file)
@@ -1,40 +1,12 @@
-/*
-   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 FRIENDLISTVIEW_H
 #define FRIENDLISTVIEW_H
 
-#include <QWidget>
-#include <QHash>
-
-class QVBoxLayout;
-class QLabel;
-class User;
-class FriendListItem;
+#include "listview.h"
 
 /**
-* @brief FriendListView shows items in list.
-*
+* @brief Shows FriendListItems in list view.
 */
-class FriendListView : public QWidget
+class FriendListView : public ListView
 {
     Q_OBJECT
 
@@ -42,86 +14,32 @@ public:
     /**
     * @brief Constructor.
     *
-    * @param parent parent widget
+    * @param parent QWidget
     */
     FriendListView(QWidget *parent = 0);
 
-/******************************************************************************
+/*******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
-public:
-    /**
-    * @brief Add widget to view and widget list.
-    *
-    * @param key user ID
-    * @param widget widget to add to list
-    */
-    void addWidget(const QString &key, QWidget *widget);
-
-    /**
-    * @brief Adds widget to view.
-    *
-    * @param item FriendListItem
-    */
-    void addWidgetToView(FriendListItem *item);
-
-    /**
-    * @brief Clear unused widgets from view.
-    *
-    * Clears items which are not in user ID's list from the view and widget list.
-    *
-    * @param userIDs list of new user ID's.
-    */
-    void clearUnused(const QStringList &userIDs);
-
-    /**
-    * @brief Clears filtering from list.
-    *
-    * Calls show to all widgets.
-    */
-    void clearFilter();
-
+public slots:
     /**
-    * @brief Checks if view contains widget with userID.
+    * @brief Slot for list item clicked.
     *
-    * @param userID user's ID
-    * @return true if view contains widget, false otherwise
+    * @param item QListWidgetItem
     */
-    bool contains(const QString &userID);
-
-    /**
-    * @brief Sets filter to list.
-    *
-    * Hide all widgets that are not in the userIDs list.
-    *
-    * @param userIDs user ID's to widgets that are shown
-    */
-    void filter(const QList<QString> &userIDs);
-
-    /**
-    * @brief Takes widget from view.
-    *
-    * Widget is not deleted.
-    *
-    * @param userID user's ID
-    * @return FriendListItem
-    */
-    FriendListItem *takeWidgetFromView(const QString &userID);
+    void listItemClicked(QListWidgetItem *item);
 
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
+signals:
     /**
-    * @brief Returns FriendListItem with userID.
+    * @brief Signal is emitted when friend item is clicked.
     *
-    * @param userID user's ID
-    * @return FriendListItem
+    * @param coordinates item's coordinates
     */
-    FriendListItem *widget(const QString &userID);
-
-/******************************************************************************
-* DATA MEMBERS
-******************************************************************************/
-private:
-    QVBoxLayout *m_friendListLayout;    ///< Layout for this view
-    QHash<QString, QWidget *> m_widgets;  ///< List of widgets in this view. Key = user ID
+    void friendItemClicked(const GeoCoordinate &coordinates);
 };
 
+
 #endif // FRIENDLISTVIEW_H
index 450ffee..6e5bd22 100644 (file)
@@ -30,7 +30,7 @@ const int ICON_MARGIN = 2;      ///< Icon margin
 const int ICON_WIDTH = 24;      ///< Icon width
 const int IMAGE_HEIGHT = 64;    ///< Friend image height
 const int IMAGE_WIDTH = 64;     ///< Friend image width
-const int ITEM_MIN_HEIGHT = 75; ///< Minimum height for item
+const int ITEM_MIN_HEIGHT = 70; ///< Minimum height for item
 const int MARGIN = 5;           ///< Text and image margin
 
 /**
@@ -53,16 +53,11 @@ const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
 
 const int ITEM_SIZE_HINT_INDEX = Qt::SizeHintRole;
 const int DISTANCE_SIZE_HINT_INDEX = Qt::SizeHintRole + 1;
-const int STATUS_TEXT_SIZE_HINT_INDEX = Qt::SizeHintRole + 2;
-const int LOCATION_SIZE_HINT_INDEX = Qt::SizeHintRole + 3;
-const int UPDATED_SIZE_HINT_INDEX = Qt::SizeHintRole + 4;
 
-const int SUBITEM_STORE_INDEX = Qt::UserRole + 5;
-const int ITEM_EXPANDED_INDEX = Qt::UserRole + 6;
 
-const int STATUS_TEXT_DISPLAY_INDEX = Qt::UserRole;
-const int LOCATION_DISPLAY_INDEX = Qt::UserRole + 1;
-const int UPDATED_DISPLAY_INDEX = Qt::UserRole + 2;
+const int SUBITEM_STORE_INDEX = Qt::UserRole;
+const int ITEM_EXPANDED_INDEX = Qt::UserRole + 1;
+const int ITEM_HAS_IMAGE_INDEX = Qt::UserRole + 2;
 const int DISTANCE_TEXT_DISPLAY_INDEX = Qt::UserRole + 3;
 const int DISTANCE_IMAGE_INDEX = Qt::UserRole + 4;
 
index 869d408..27ba308 100644 (file)
@@ -35,7 +35,11 @@ ListItem::ListItem()
 
 void ListItem::setImage(const QPixmap &image)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setData(ITEM_HAS_IMAGE_INDEX, true);
     setData(AVATAR_IMAGE_INDEX, image);
+
 }
 
 void ListItem::setName(const QString &name)
@@ -75,9 +79,5 @@ QString ListItem::shortenText(const QString &text, int textWidth, TextSize textS
         shortenedText.append("...");
     }
 
-    qWarning() << shortenedText;
-    qWarning() << textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
-    qWarning() << textWidth;
-
     return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
 }
index 89ed4fa..6cdcda9 100644 (file)
@@ -31,8 +31,7 @@ class GeoCoordinate;
 /**
 * @brief Base class for list items.
 *
-* Stores item's name and image. Defines methods that sub
-* classes have to implement.
+* Stores item's name and image and includes method to shorten texts.
 */
 class ListItem : public QListWidgetItem
 {
@@ -42,19 +41,15 @@ public:
     */
     ListItem();
 
+    /**
+    * @brief Defines text size.
+    */
     enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
 
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
     /**
-    * @brief Returns item's coordinates.
-    *
-    * @return item's coordinates
-    */
-    virtual GeoCoordinate coordinates() = 0;
-
-    /**
     * @brief Returns item's ID.
     *
     * @return item's ID
@@ -106,8 +101,6 @@ public:
     */
     virtual bool toggleSelection() = 0;
 
-
-
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
index 324c254..b350db4 100644 (file)
@@ -76,7 +76,7 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
     }
     //Draw only text
     else {
-        painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2, NAME_TOP_MARGIN), name);
+        painter->drawText(itemRect.topLeft() + QPoint(MARGIN*3, NAME_TOP_MARGIN), name);
     }
 }
 
index 995d039..d4459b2 100644 (file)
@@ -31,6 +31,9 @@ ListView::ListView(QWidget *parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    setAutoFillBackground(false);
+    viewport()->setAutoFillBackground(false);
+
     connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
             this, SLOT(listItemClicked(QListWidgetItem*)));
 }
@@ -58,6 +61,8 @@ void ListView::clearList()
 
     m_listItems.clear();
     clear();
+
+    m_previousItem = 0;
 }
 
 void ListView::clearUnused(const QStringList &userIDs)
@@ -116,26 +121,19 @@ ListItem *ListView::takeListItemFromView(const QString &userID)
 
 void ListView::listItemClicked(QListWidgetItem *item)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
-    ListItem *currentItem = static_cast<ListItem*>(item);
+    ListItem *currentItem = dynamic_cast<ListItem*>(item);
 
     if (currentItem) {
-        qWarning() << __PRETTY_FUNCTION__ << "currentItem != 0";
         if (m_previousItem == currentItem) {
-            qWarning() << __PRETTY_FUNCTION__ << "previousItem == currentItem";
-            bool selected = currentItem->toggleSelection();
-
-            if (selected)
-                ;//emit listItemClicked(currentItem->coordinates());
+            currentItem->toggleSelection();
 
         } else {
-            qWarning() << __PRETTY_FUNCTION__ << "previousItem != currentItem";
             if (m_previousItem)
                 m_previousItem->setSelected(false);
 
             currentItem->setSelected(true);
-            //emit listItemClicked(currentItem->coordinates());
         }
 
         m_previousItem = currentItem;
@@ -148,5 +146,13 @@ ListItem *ListView::listItem(const QString &userID)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return static_cast<ListItem*>(m_listItems.value(userID));
+    return dynamic_cast<ListItem*>(m_listItems.value(userID));
+}
+
+
+ListView::~ListView()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    clearList();
 }
index 0b64787..73cc81e 100644 (file)
@@ -45,6 +45,8 @@ public:
     */
     ListView(QWidget *parent = 0);
 
+    ~ListView();
+
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -130,17 +132,6 @@ protected slots:
     */
     virtual void listItemClicked(QListWidgetItem *item);
 
-/******************************************************************************
-* SIGNALS
-******************************************************************************/
-signals:
-    /**
-    * @brief Signal is emitted when list item is clicked.
-    *
-    * @param coordinates item's coordinates
-    */
-    void listItemClicked(const GeoCoordinate &coordinates);
-
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
index fb8306b..e14a8c1 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "locationlistitem.h"
 
-const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
+const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN*2 + IMAGE_WIDTH;
 
 LocationListItem::LocationListItem()
 {
@@ -30,6 +30,8 @@ QString LocationListItem::id() const
 
 void LocationListItem::setLocationData(const Location &location)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_location = location;
 
     QStringList addressComponents = m_location.addressComponents();
@@ -47,11 +49,19 @@ void LocationListItem::setLocationData(const Location &location)
             addressTail.append(", ");
     }
 
+    clearSubItems();
     addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
 
 }
 
 void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_location.bounds(swBound, neBound);
 }
+
+LocationListItem::~LocationListItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
index dc89fc1..b1c7341 100644 (file)
@@ -4,16 +4,37 @@
 #include "extendedlistitem.h"
 #include "../routing/location.h"
 
+/**
+* @brief List item stores information about location results.
+*/
 class LocationListItem : public ExtendedListItem
 {
 public:
+    /**
+    * @brief Constructor.
+    *
+    * Sets sub items' text width.
+    */
     LocationListItem();
 
+    /**
+    * @brief Destructor.
+    */
+    ~LocationListItem();
+
 /*******************************************************************************
  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
  ******************************************************************************/
 public:
     /**
+    * @brief Returns location bounds in parameters.
+    *
+    * @param swBound south-west bound in GeoCoorinate
+    * @param neBound north-east bound in GeoCoordinate
+    */
+    void bounds(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
+    /**
     * @brief Returns item's coordinates.
     *
     * @return item's coordinates
@@ -27,8 +48,6 @@ public:
     */
     QString id() const;
 
-    void bounds(GeoCoordinate &swBound, GeoCoordinate &neBound);
-
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -44,8 +63,7 @@ public:
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    Location m_location;
-    bool m_selected;
+    Location m_location;    ///< Location data
 };
 
 #endif // LOCATIONLISTITEM_H
index 5233f56..eacfcc9 100644 (file)
@@ -5,19 +5,18 @@
 LocationListView::LocationListView(QWidget *parent)
     : ListView(parent)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 }
 
 void LocationListView::listItemClicked(QListWidgetItem *item)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     ListView::listItemClicked(item);
 
-    LocationListItem *locationItem = static_cast<LocationListItem*>(item);
+    LocationListItem *locationItem = dynamic_cast<LocationListItem*>(item);
 
     if (locationItem) {
-        qWarning() << __PRETTY_FUNCTION__ << "locationItem != null";
         GeoCoordinate swBound;
         GeoCoordinate neBound;
         locationItem->bounds(swBound, neBound);
index f779b0f..19af2a0 100644 (file)
@@ -3,17 +3,36 @@
 
 #include "listview.h"
 
+/**
+* @brief Shows LocationListItems in list view.
+*/
 class LocationListView : public ListView
 {
     Q_OBJECT
 
 public:
+    /**
+    * @brief Constructor.
+    *
+    * @param parent QWidget
+    */
     LocationListView(QWidget *parent = 0);
 
-private slots:
+public slots:
+    /**
+    * @brief Slot for list item clicked.
+    *
+    * @param item QListWidgetItem
+    */
     void listItemClicked(QListWidgetItem *item);
 
 signals:
+    /**
+    * @brief Signal is emitted when location item is clicked.
+    *
+    * @param swBound south-west bound in GeoCoorinate
+    * @param neBound north-east bound in GeoCoordinate
+    */
     void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
 };
 
index 5a74bde..c59c300 100644 (file)
@@ -171,7 +171,7 @@ void MainWindow::buildFriendListPanel()
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
 
-    connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+    connect(m_friendsListPanel, SIGNAL(friendItemClicked(GeoCoordinate)),
             this, SIGNAL(findFriend(GeoCoordinate)));
 
     connect(this, SIGNAL(friendImageReady(User*)),
index f7d1428..7422912 100644 (file)
@@ -7,11 +7,15 @@ HEADERS += ../../../src/ui/friendlistitem.h \
     ../../../src/ui/listcommon.h \
     ../../../src/user/user.h \
     ../../../src/coordinates/scenecoordinate.h \
-    ../../../src/coordinates/geocoordinate.h
+    ../../../src/coordinates/geocoordinate.h \
+    ../../../src/ui/extendedlistitemstore.h \
+    ../../../src/ui/extendedlistitem.h
 SOURCES += ../../../src/ui/friendlistitem.cpp \
     ../../../src/ui/listitem.cpp \
     ../../../src/user/user.cpp \
     testfriendlistitem.cpp \
     ../../../src/coordinates/scenecoordinate.cpp \
-    ../../../src/coordinates/geocoordinate.cpp
+    ../../../src/coordinates/geocoordinate.cpp \
+    ../../../src/ui/extendedlistitemstore.cpp \
+    ../../../src/ui/extendedlistitem.cpp
 RESOURCES += ../../../images.qrc
index d85b28f..048c1f6 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtGui>
 
 #include "../../../src/ui/friendlistitem.h"
+#include "../../../src/ui/extendedlistitemstore.h"
 #include "../../../src/user/user.h"
 #include "../../../src/ui/listcommon.h"
 
@@ -55,14 +56,16 @@ void TestFriendListItem::initTestCase()
 
     user1 = new User(QString("Address address address address address"),
                            GeoCoordinate(12.22, 23.33), QString("Name na msfdsa dsfadsaf sdaf"),
-                           QString("Note note note note note note note note"),
+                           QString("Note note note note note note note note note note note note " \
+                                   "note note note note note"),
                            QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
                            true, QString("id1"), QString("km"), 44.12);
     user1->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
 
     user2 = new User(QString("Address address"),
                            GeoCoordinate(12.1, 44.33), QString("Name na msfdsa dsfadsaf sdaf"),
-                           QString("Note note note note note note note note"),
+                           QString("Note note note note note note note note note note note note" \
+                                   "note note note note note"),
                            QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
                            true, QString("id2"), QString("km"), 144.12);
     user2->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
@@ -92,22 +95,28 @@ void TestFriendListItem::setUserData()
 void TestFriendListItem::toggleSelection()
 {
     QCOMPARE(friendListItem->id(), QString("id2"));
-    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141));
-    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
-    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
-    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142));
+
+    QList<ExtendedListItemStore *> *subItems = (QList<ExtendedListItemStore *> *)
+                                               (friendListItem->data(SUBITEM_STORE_INDEX)
+                                                .value<void *>());
+
+    QVERIFY(friendListItem->data(ITEM_HAS_IMAGE_INDEX).toBool());
+
+    QVERIFY(subItems);
+    QCOMPARE(subItems->count(), 3);
+
+    QCOMPARE(subItems->at(0)->textRect(), QRect(0, 0, 250, 72));
+    QCOMPARE(subItems->at(1)->textRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(subItems->at(2)->textRect(), QRect(0, 0, 250, 48));
 
     friendListItem->toggleSelection();
-    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141 + 2*24));
-    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 2*24));
-    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
-    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 2*24));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142 + 3*24));
+    QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), true);
 
     friendListItem->toggleSelection();
-    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141));
-    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
-    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
-    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142));
+    QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), false);
 }
 
 QTEST_MAIN(TestFriendListItem)
index 329f916..bcd62da 100644 (file)
@@ -4,15 +4,21 @@ INCLUDEPATH += . \
     ../../../src/
 HEADERS += ../../../src/ui/listview.h \
     ../../../src/ui/listitem.h \
+    ../../../src/ui/extendedlistitem.h \
+    ../../../src/ui/extendedlistitemstore.h \
     ../../../src/ui/friendlistitem.h \
     ../../../src/user/user.h \
     ../../../src/coordinates/scenecoordinate.h \
-    ../../../src/coordinates/geocoordinate.h
+    ../../../src/coordinates/geocoordinate.h \
+    ../../../src/ui/friendlistview.h
 SOURCES += ../../../src/ui/listview.cpp \
     ../../../src/ui/listitem.cpp \
+    ../../../src/ui/extendedlistitem.cpp \
+    ../../../src/ui/extendedlistitemstore.cpp \
     ../../../src/ui/friendlistitem.cpp \
     ../../../src/user/user.cpp \
     testlistview.cpp \
     ../../../src/coordinates/scenecoordinate.cpp \
-    ../../../src/coordinates/geocoordinate.cpp
+    ../../../src/coordinates/geocoordinate.cpp \
+    ../../../src/ui/friendlistview.cpp
 RESOURCES += ../../../images.qrc
index d3fc0c6..a96dfdc 100644 (file)
@@ -23,7 +23,7 @@
 #include <QtGui>
 
 #include "../../../src/ui/friendlistitem.h"
-#include "../../../src/ui/listview.h"
+#include "../../../src/ui/friendlistview.h"
 
 class TestListView: public QObject
 {
@@ -39,7 +39,7 @@ private slots:
     void takeListItemFromView();
 
 private:
-    ListView *listView;
+    FriendListView *friendListView;
     User *user1;
     User *user2;
     User *user3;
@@ -48,7 +48,7 @@ private:
 
 void TestListView::cleanupTestCase()
 {
-    delete listView;
+    delete friendListView;
     delete user1;
     delete user2;
     delete user3;
@@ -57,8 +57,8 @@ void TestListView::cleanupTestCase()
 
 void TestListView::initTestCase()
 {
-    listView = new ListView();
-    QVERIFY(listView != 0);
+    friendListView = new FriendListView();
+    QVERIFY(friendListView != 0);
 
     user1 = new User(QString("Address address address address address"),
                            GeoCoordinate(12.22, 23.33), QString("Name na msfdsa dsfadsaf sdaf"),
@@ -93,51 +93,51 @@ void TestListView::initTestCase()
 
 void TestListView::addListItem()
 {
-    listView->addListItem("key1", new FriendListItem());
-    QCOMPARE(listView->count(), 1);
+    friendListView->addListItem("key1", new FriendListItem());
+    QCOMPARE(friendListView->count(), 1);
 
-    listView->addListItem("key1", new FriendListItem());
-    QCOMPARE(listView->count(), 1);
+    friendListView->addListItem("key1", new FriendListItem());
+    QCOMPARE(friendListView->count(), 1);
 
-    listView->addListItem("key2", new FriendListItem());
-    QCOMPARE(listView->count(), 2);
+    friendListView->addListItem("key2", new FriendListItem());
+    QCOMPARE(friendListView->count(), 2);
 }
 
 void TestListView::addItemToView()
 {
-    listView->addListItemToView(new FriendListItem());
-    QCOMPARE(listView->count(), 3);
+    friendListView->addListItemToView(new FriendListItem());
+    QCOMPARE(friendListView->count(), 3);
 
-    listView->addListItemToView(new FriendListItem());
-    QCOMPARE(listView->count(), 4);
+    friendListView->addListItemToView(new FriendListItem());
+    QCOMPARE(friendListView->count(), 4);
 
-    listView->clearList();
-    QCOMPARE(listView->count(), 0);
+    friendListView->clearList();
+    QCOMPARE(friendListView->count(), 0);
 }
 
 void TestListView::clearUnused()
 {
-    listView->addListItem("key1", new FriendListItem());
-    listView->addListItem("key2", new FriendListItem());
-    listView->addListItem("key3", new FriendListItem());
-    listView->addListItem("key4", new FriendListItem());
-    QCOMPARE(listView->count(), 4);
+    friendListView->addListItem("key1", new FriendListItem());
+    friendListView->addListItem("key2", new FriendListItem());
+    friendListView->addListItem("key3", new FriendListItem());
+    friendListView->addListItem("key4", new FriendListItem());
+    QCOMPARE(friendListView->count(), 4);
 
     QStringList newUserIDs;
     newUserIDs.append("key2");
     newUserIDs.append("key3");
-    listView->clearUnused(newUserIDs);
-    QCOMPARE(listView->count(), 2);
-    QVERIFY(listView->listItem("key1") == 0);
-    QVERIFY(listView->listItem("key2") != 0);
-    QVERIFY(listView->listItem("key3") != 0);
-    QVERIFY(listView->listItem("key4") == 0);
+    friendListView->clearUnused(newUserIDs);
+    QCOMPARE(friendListView->count(), 2);
+    QVERIFY(friendListView->listItem("key1") == 0);
+    QVERIFY(friendListView->listItem("key2") != 0);
+    QVERIFY(friendListView->listItem("key3") != 0);
+    QVERIFY(friendListView->listItem("key4") == 0);
 }
 
 void TestListView::filterList()
 {
-    listView->clearList();
-    QCOMPARE(listView->count(), 0);
+    friendListView->clearList();
+    QCOMPARE(friendListView->count(), 0);
 
     FriendListItem *item1 = new FriendListItem();
     FriendListItem *item2 = new FriendListItem();
@@ -149,44 +149,44 @@ void TestListView::filterList()
     item3->setUserData(user3);
     item4->setUserData(user4);
 
-    listView->addListItem(item1->id(), item1);
-    listView->addListItem(item2->id(), item2);
-    listView->addListItem(item3->id(), item3);
-    listView->addListItem(item4->id(), item4);
-    QCOMPARE(listView->count(), 4);
+    friendListView->addListItem(item1->id(), item1);
+    friendListView->addListItem(item2->id(), item2);
+    friendListView->addListItem(item3->id(), item3);
+    friendListView->addListItem(item4->id(), item4);
+    QCOMPARE(friendListView->count(), 4);
 
     QList<QString> userIDs;
     userIDs.append(item1->id());
-    listView->filter(userIDs);
-    QCOMPARE(listView->count(), 4);
+    friendListView->filter(userIDs);
+    QCOMPARE(friendListView->count(), 4);
 
     int hiddenCounter = 0;
 
-    for (int i = 0; i < listView->count(); ++i) {
-        if (listView->item(i)->isHidden())
+    for (int i = 0; i < friendListView->count(); ++i) {
+        if (friendListView->item(i)->isHidden())
             hiddenCounter++;
     }
 
     QCOMPARE(hiddenCounter, 3);
 
     userIDs.append(item2->id());
-    listView->filter(userIDs);
-    QCOMPARE(listView->count(), 4);
+    friendListView->filter(userIDs);
+    QCOMPARE(friendListView->count(), 4);
     hiddenCounter = 0;
 
-    for (int i = 0; i < listView->count(); ++i) {
-        if (listView->item(i)->isHidden())
+    for (int i = 0; i < friendListView->count(); ++i) {
+        if (friendListView->item(i)->isHidden())
             hiddenCounter++;
     }
 
     QCOMPARE(hiddenCounter, 2);
 
-    listView->clearFilter();
+    friendListView->clearFilter();
 
     hiddenCounter = 0;
 
-    for (int i = 0; i < listView->count(); ++i) {
-        if (listView->item(i)->isHidden())
+    for (int i = 0; i < friendListView->count(); ++i) {
+        if (friendListView->item(i)->isHidden())
             hiddenCounter++;
     }
 
@@ -195,15 +195,15 @@ void TestListView::filterList()
 
 void TestListView::takeListItemFromView()
 {
-    QCOMPARE(listView->count(), 4);
+    QCOMPARE(friendListView->count(), 4);
 
-    ListItem *item = listView->takeListItemFromView("key3");
+    ListItem *item = friendListView->takeListItemFromView("key3");
     QVERIFY(item != 0);
-    QCOMPARE(listView->count(), 3);
+    QCOMPARE(friendListView->count(), 3);
     QCOMPARE(item->id(), QString("key3"));
 
-    listView->addListItemToView(item);
-    QCOMPARE(listView->count(), 4);
+    friendListView->addListItemToView(item);
+    QCOMPARE(friendListView->count(), 4);
 }
 
 QTEST_MAIN(TestListView)