Merge branch 'new_panels' into locationlistview
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 11 Aug 2010 08:04:02 +0000 (11:04 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 11 Aug 2010 08:04:02 +0000 (11:04 +0300)
Conflicts:
src/src.pro
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/listcommon.h
src/ui/mainwindow.cpp

35 files changed:
src/engine/engine.cpp
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapengine.h
src/src.pro
src/ui/extendedlistitem.cpp [new file with mode: 0644]
src/ui/extendedlistitem.h [new file with mode: 0644]
src/ui/extendedlistitemdelegate.cpp [new file with mode: 0644]
src/ui/extendedlistitemdelegate.h [new file with mode: 0644]
src/ui/extendedlistitemstore.cpp [new file with mode: 0644]
src/ui/extendedlistitemstore.h [new file with mode: 0644]
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/listitemdelegate.h
src/ui/listview.cpp
src/ui/listview.h
src/ui/locationlistitem.cpp [new file with mode: 0644]
src/ui/locationlistitem.h [new file with mode: 0644]
src/ui/locationlistview.cpp [new file with mode: 0644]
src/ui/locationlistview.h [new file with mode: 0644]
src/ui/mainwindow.h
tests/ui/friendlistitem/friendlistitem.pro
tests/ui/friendlistitem/testfriendlistitem.cpp
tests/ui/listview/listview.pro
tests/ui/listview/testlistview.cpp

index 4c1183f..1590cb9 100644 (file)
@@ -362,13 +362,6 @@ void SituareEngine::initializeGpsAndAutocentering()
     }
 }
 
-void SituareEngine::locationDataReady(QList<Location> &result)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    Q_UNUSED(result) /// @todo remove Q_UNUSED
-}
-
 void SituareEngine::locationSearch(QString location)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -577,7 +570,7 @@ void SituareEngine::signalsFromGeocodingService()
     qDebug() << __PRETTY_FUNCTION__;
 
     connect(m_geocodingService, SIGNAL(locationDataParsed(QList<Location>&)),
-            this, SLOT(locationDataReady(QList<Location>&)));
+            m_ui, SIGNAL(locationDataParsed(QList<Location>&)));
 }
 
 void SituareEngine::signalsFromGPS()
@@ -658,6 +651,9 @@ 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)));
index 8a1dd24..31b4857 100644 (file)
@@ -89,13 +89,6 @@ public slots:
     void fetchUsernameFromSettings();
 
     /**
-    * @brief Slot to intercept signal when location search results are ready
-    *
-    * @param result list if location search results
-    */
-    void locationDataReady(QList<Location> &result);
-
-    /**
     * @brief Slot to intercept signal when location search is issued
     *
     * @param location QString location
@@ -317,6 +310,13 @@ signals:
     void friendImageReady(User *user);
 
     /**
+    * @brief Emited when location request is parsed and is ready for further processing
+    *
+    * @param result List of Location items
+    */
+    void locationDataParsed(QList<Location> &result);
+
+    /**
     * @brief Signals when new user data is ready
     *
     * @param user Instance of User
index d3935a9..1d89aa3 100644 (file)
@@ -129,14 +129,21 @@ QRect MapEngine::calculateTileGrid(SceneCoordinate coordinate)
     return QRect(topLeft, m_tilesGridSize);
 }
 
-void MapEngine::centerAndZoomTo(QRect rect)
+void MapEngine::centerAndZoomTo(QRect rect, bool useMargins)
 {
-    const int MARGIN_HORIZONTAL = 50;
-    const int MARGIN_VERTICAL = 5;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    int marginHorizontal = 50;
+    int marginVertical = 5;
+
+    if (!useMargins) {
+        marginHorizontal = 0;
+        marginVertical = 0;
+    }
 
     // calculate the usable size of the view
-    int viewUsableHeight = m_viewSize.height() - 2 * MARGIN_VERTICAL;
-    int viewUsableWidth = m_viewSize.width() - 2 * MARGIN_HORIZONTAL;
+    int viewUsableHeight = m_viewSize.height() - 2 * marginHorizontal;
+    int viewUsableWidth = m_viewSize.width() - 2 * marginVertical;
 
     // calculate how many levels must be zoomed out from the closest zoom level to get the rect
     // fit inside the usable view area
@@ -293,6 +300,17 @@ bool MapEngine::isCenterTileChanged(SceneCoordinate coordinate)
     return (centerTile != temp);
 }
 
+void MapEngine::locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QRect area;
+    area.setTopRight(SceneCoordinate(neBound).toPointF().toPoint());
+    area.setBottomLeft(SceneCoordinate(swBound).toPointF().toPoint());
+
+    centerAndZoomTo(area, false);
+}
+
 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
index b421974..b498ac2 100644 (file)
@@ -185,8 +185,9 @@ private:
     * as big as possible.
     *
     * @param rect Target rect
+    * @param useMargins true if margins should be added to rect, false otherwise
     */
-    void centerAndZoomTo(QRect rect);
+    void centerAndZoomTo(QRect rect, bool useMargins = true);
 
     /**
      * @brief Request disabling of auto centering if centered too far from the real location.
@@ -268,6 +269,15 @@ private slots:
     void gpsPositionUpdate(GeoCoordinate position, qreal accuracy);
 
     /**
+    * @brief Called when location item is clicked.
+    *
+    * Calls centerAndZoomTo() with bounds.
+    * @param swBound south-west bound of location item
+    * @param neBound north-east bound of location item
+    */
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
+    /**
      * @brief Slot for received map tile images
      *
      * Does receive map tile images from MapFetcher. Calls MapScene::addTile() for creating and adding
index 7f98fd5..2978f35 100644 (file)
@@ -45,11 +45,21 @@ SOURCES += main.cpp \
     ui/updatelocation/texteditautoresizer.cpp \
     ui/updatelocation/updatelocationdialog.cpp \
     ui/avatarimage.cpp \
+    ui/extendedlistitem.cpp \
+    ui/extendedlistitemdelegate.cpp \
+    ui/extendedlistitemstore.cpp \
     ui/friendlistitem.cpp \
+    ui/friendlistitemdelegate.cpp \
     ui/friendlistpanel.cpp \
+    ui/friendlistview.cpp \
     ui/fullscreenbutton.cpp \
     ui/imagebutton.cpp \
     ui/indicatorbutton.cpp \
+    ui/listitem.cpp \
+    ui/listitemdelegate.cpp \
+    ui/listview.cpp \
+    ui/locationlistitem.cpp \
+    ui/locationlistview.cpp \
     ui/logindialog.cpp \
     ui/mainwindow.cpp \
     ui/mapscale.cpp \
@@ -58,10 +68,6 @@ SOURCES += main.cpp \
     ui/userinfopanel.cpp \
     ui/zoombutton.cpp \
     ui/zoombuttonpanel.cpp \
-    ui/listview.cpp \
-    ui/listitem.cpp \
-    ui/listitemdelegate.cpp \
-    ui/friendlistitemdelegate.cpp \
     ui/searchdialog.cpp \
     ui/paneltab.cpp \
     ui/tabbedpanel.cpp \
@@ -134,6 +140,13 @@ HEADERS += application.h \
     ui/friendlistitemdelegate.h \
     ui/listcommon.h \
     ui/searchdialog.h \
+    ui/locationlistitem.h \
+    ui/extendedlistitem.h \
+    ui/extendedlistitemstore.h \
+    ui/extendedlistitemdelegate.h \
+    ui/locationlistview.h \
+    ui/friendlistview.h \
+    error.h \
     ui/paneltab.h \
     ui/tabbedpanel.h \
     ui/panelbar.h \
diff --git a/src/ui/extendedlistitem.cpp b/src/ui/extendedlistitem.cpp
new file mode 100644 (file)
index 0000000..f5d18be
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+   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 <QDebug>
+#include <QFontMetrics>
+#include <QPainter>
+
+#include "../common.h"
+#include "listcommon.h"
+#include "extendedlistitemstore.h"
+
+#include "extendedlistitem.h"
+
+const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT;    ///< Sub item text row height
+
+ExtendedListItem::ExtendedListItem()
+    : m_selected(false),
+      m_expandedHeight(ITEM_MIN_HEIGHT),
+      m_normalHeight(ITEM_MIN_HEIGHT),
+      m_subItemTextWidth(0)
+
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+
+    m_subItemStoreList = new QList<ExtendedListItemStore *>();
+    setData(SUBITEM_STORE_INDEX, qVariantFromValue((void *) m_subItemStoreList));
+}
+
+void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    ExtendedListItemStore *itemStore = new ExtendedListItemStore(text);
+    itemStore->setIcon(icon);
+    itemStore->setShortenedText(shortenText(text, m_subItemTextWidth, ListItem::TEXT_SIZE_SMALL));
+    itemStore->setTextRect(calculateExpandedTextRect(text));
+
+    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__;
+
+    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+    QPainter painter(&p);
+    painter.setFont(NOKIA_FONT_SMALL);
+    QFontMetrics textMetrics = painter.fontMetrics();
+
+    QRect textRect = textMetrics.boundingRect(text);
+    int textRectFactor = textRect.width() / m_subItemTextWidth;
+    textRectFactor++;
+    QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
+                                   * textRectFactor);
+
+    m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT;
+    m_expandedHeight += expandedTextRect.height();
+    setSize(QSize(ITEM_WIDTH, m_normalHeight));
+
+    return expandedTextRect;
+}
+
+void ExtendedListItem::setSubitemTextWidth(int width)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_subItemTextWidth = width;
+}
+
+bool ExtendedListItem::toggleSelection()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setSelected(!m_selected);
+    return m_selected;
+}
+
+void ExtendedListItem::setSelected(bool selected)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_selected = selected;
+    setData(ITEM_EXPANDED_INDEX, m_selected);
+
+    if (m_selected)
+        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
+    else
+        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
+}
+
+ExtendedListItem::~ExtendedListItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    clearSubItems();
+    delete m_subItemStoreList;
+}
diff --git a/src/ui/extendedlistitem.h b/src/ui/extendedlistitem.h
new file mode 100644 (file)
index 0000000..440d300
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef EXTENDEDLISTITEM_H
+#define EXTENDEDLISTITEM_H
+
+#include "listitem.h"
+
+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();
+
+/*******************************************************************************
+* 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.
+    *
+    * Clears sub items' list and deletes items. Sets item default and
+    * extended height to default values.
+    */
+    void clearSubItems();
+
+    /**
+    * @brief Sets item selected.
+    *
+    * @param selected true if selected, false otherwise
+    */
+    void setSelected(bool selected);
+
+    /**
+    * @brief Sets sub items' text width.
+    *
+    * @param width sub item width
+    */
+    void setSubitemTextWidth(int width);
+
+    /**
+    * @brief Toggles selection.
+    *
+    * @return true if selection was toggled, false otherwise
+    */
+    bool toggleSelection();
+
+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;        ///< 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; ///< ExtendedListItemStore list
+};
+
+#endif // EXTENDEDLISTITEM_H
diff --git a/src/ui/extendedlistitemdelegate.cpp b/src/ui/extendedlistitemdelegate.cpp
new file mode 100644 (file)
index 0000000..6826945
--- /dev/null
@@ -0,0 +1,67 @@
+#include <QPainter>
+#include <QDebug>
+#include <QRect>
+
+#include "../common.h"
+#include "listcommon.h"
+#include "extendedlistitemstore.h"
+
+#include "extendedlistitemdelegate.h"
+
+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);
+    painter->setFont(NOKIA_FONT_SMALL);
+
+    QRect itemRect = option.rect;
+    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) {
+
+        int previousSubItemTextRectBottom = itemRect.top() + IMAGE_HEIGHT - 2*MARGIN;
+
+        for (int i = 0; i < subItems->size(); ++i) {
+
+            ExtendedListItemStore *itemStore = subItems->at(i);
+            QRect subItemTextRect = itemStore->textRect();
+            QString text;
+
+            if (expanded) {
+                text = itemStore->text();
+            }
+            else {
+                subItemTextRect.setHeight(ICON_HEIGHT);
+                text = itemStore->shortenedText();
+            }
+
+            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())
+                painter->drawPixmap(iconRect, itemStore->icon());
+
+            painter->drawText(subItemTextRect, Qt::TextWrapAnywhere, text);
+            previousSubItemTextRectBottom = subItemTextRect.bottom();
+        }
+    }
+}
diff --git a/src/ui/extendedlistitemdelegate.h b/src/ui/extendedlistitemdelegate.h
new file mode 100644 (file)
index 0000000..c5da470
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef EXTENDEDLISTITEMDELEGATE_H
+#define EXTENDEDLISTITEMDELEGATE_H
+
+#include "listitemdelegate.h"
+
+/**
+* @brief Defines ExtendedListItem style.
+*/
+class ExtendedListItemDelegate : public ListItemDelegate
+{
+
+public:
+    /**
+    * @brief Constructor.
+    *
+    * @param parent QWidget
+    */
+    ExtendedListItemDelegate(QWidget *parent = 0);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+    /**
+    * @brief Draws ExtendedListItem content.
+    *
+    * 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;
+};
+
+#endif // EXTENDEDLISTITEMDELEGATE_H
diff --git a/src/ui/extendedlistitemstore.cpp b/src/ui/extendedlistitemstore.cpp
new file mode 100644 (file)
index 0000000..1bff51e
--- /dev/null
@@ -0,0 +1,61 @@
+#include <QDebug>
+
+#include "extendedlistitemstore.h"
+
+ExtendedListItemStore::ExtendedListItemStore(const QString &text)
+    : m_icon(QPixmap()),
+      m_textRect(QRect()),
+      m_text(text),
+      m_shortenedText(QString())
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+void ExtendedListItemStore::setIcon(const QPixmap &icon)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_icon = icon;
+}
+
+void ExtendedListItemStore::setShortenedText(const QString &shortenedText)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_shortenedText = shortenedText;
+}
+
+void ExtendedListItemStore::setTextRect(const QRect &textRect)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_textRect = textRect;
+}
+
+QPixmap ExtendedListItemStore::icon() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_icon;
+}
+
+QString ExtendedListItemStore::shortenedText() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_shortenedText;
+}
+
+QString ExtendedListItemStore::text() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_text;
+}
+
+QRect ExtendedListItemStore::textRect() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_textRect;
+}
diff --git a/src/ui/extendedlistitemstore.h b/src/ui/extendedlistitemstore.h
new file mode 100644 (file)
index 0000000..7e00228
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef EXTENDEDLISTITEMSTORE_H
+#define EXTENDEDLISTITEMSTORE_H
+
+#include <QPixmap>
+#include <QRect>
+#include <QString>
+
+/**
+* @brief Stores ExtendedListItem data.
+*/
+class ExtendedListItemStore
+{
+public:
+    /**
+    * @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;             ///< Icon pixmap
+    QRect m_textRect;           ///< Text rect
+    QString m_text;             ///< Text string
+    QString m_shortenedText;    ///< Shortened text string
+};
+
+#endif // EXTENDEDLISTITEMSTORE_H
index 86faa13..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)
+    : m_user(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-}
-
-void FriendListItem::calculateTextRects()
-{
-    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() / LABEL_MAX_WIDTH;
-    statusTextRectFactor++;
-    m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
-    int updatedRectFactor = updatedRect.width() / LABEL_MAX_WIDTH;
-    updatedRectFactor++;
-    m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
-    int locationRectFactor = locationRect.width() / LABEL_MAX_WIDTH;
-    locationRectFactor++;
-    m_locationRect = QRect(0, 0, LABEL_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())
-            setData(AVATAR_IMAGE_INDEX, 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())
-        setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
+        setImage(image);
 }
 
 void FriendListItem::setDistanceIcon(double value, const QString &unit)
@@ -147,98 +117,7 @@ void FriendListItem::setDistanceIcon(double value, const QString &unit)
     setData(DISTANCE_IMAGE_INDEX, distanceImage);
 }
 
-void FriendListItem::shortenTexts()
+FriendListItem::~FriendListItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    //Dummy value to get painter font metrics.
-    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
-    QPainter painter(&p);
-    painter.setFont(NOKIA_FONT_NORMAL);
-    QFontMetrics nameLabelMetrics = painter.fontMetrics();
-    painter.setFont(NOKIA_FONT_SMALL);
-    QFontMetrics otherLabelsMetrics = painter.fontMetrics();
-
-    QString name = m_user->name();
-    QString updated = m_user->timestamp();
-    QString statusText = m_user->note();
-    QString location = m_user->address();
-
-    int nameIndex = name.indexOf('\n');
-    int updatedIndex = updated.indexOf('\n');
-    int statusTextIndex = statusText.indexOf('\n');
-    int locationIndex = location.indexOf('\n');
-
-    if (nameIndex > 0) {
-        name.truncate(nameIndex);
-        name.append("...");
-    }
-    if (updatedIndex > 0) {
-        updated.truncate(updatedIndex);
-        updated.append("...");
-    }
-    if (statusTextIndex > 0) {
-        statusText.truncate(statusTextIndex);
-        statusText.append("...");
-    }
-    if (locationIndex > 0) {
-        location.truncate(locationIndex);
-        location.append("...");
-    }
-
-    int distanceLabelWidth = otherLabelsMetrics.width(m_distanceText) + MARGIN;
-    m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, NAME_LABEL_MAX_WIDTH
-                                                  - distanceLabelWidth);
-    m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
-                                                          LABEL_MAX_WIDTH);
-    m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
-    m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
-
-    setData(NAME_DISPLAY_INDEX, m_shortenedName);
-}
-
-void FriendListItem::setText(bool expanded)
-{
-    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, LABEL_MAX_WIDTH, ICON_HEIGHT));
-        setData(LOCATION_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
-        setData(UPDATED_SIZE_HINT_INDEX, QRect(0, 0, LABEL_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 c91e658..a83a970 100644 (file)
 #ifndef FRIENDLISTITEM_H
 #define FRIENDLISTITEM_H
 
-#include <QWidget>
-#include <QTreeWidgetItem>
-#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();
 
-/*******************************************************************************
- * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
- ******************************************************************************/
     /**
-    * @brief Returns item's coordinates.
-    *
-    * @return item's coordinates
+    * @brief Destructor.
     */
-    GeoCoordinate coordinates();
+    ~FriendListItem();
 
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+public:
     /**
     * @brief Returns item's ID.
     *
@@ -63,25 +55,18 @@ 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
 ******************************************************************************/
 public:
     /**
+    * @brief Returns item's coordinates.
+    *
+    * @return item's coordinates
+    */
+    GeoCoordinate coordinates();
+
+    /**
     * @brief Set user data for this item.
     *
     * @param user User pointer
@@ -97,14 +82,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,38 +91,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_shortenedName;        ///< Shortened name 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 4b705be..b1ba413 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #include "coordinates/geocoordinate.h"
-#include "listview.h"
+#include "friendlistview.h"
 #include "friendlistitem.h"
 #include "friendlistitemdelegate.h"
 #include "panelcommon.h"
@@ -59,21 +59,18 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     filterLayout->addWidget(m_friendListLabel);
     filterLayout->addWidget(m_clearFilterButton);
 
-    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));
 
     friendListPanelLayout->addWidget(m_friendListHeaderWidget);
     friendListPanelLayout->addWidget(m_friendListView);
 
-    connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
+    connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
             this, SIGNAL(findFriend(GeoCoordinate)));
 
     connect(m_clearFilterButton, SIGNAL(clicked()),
             this, SLOT(clearFriendListFilter()));
+
     connect(this, SIGNAL(panelOpened()),
             this, SLOT(clearFriendListFilter()));
 }
index 87eb2b7..26bf2db 100644 (file)
@@ -31,7 +31,7 @@ class QWidget;
 
 class FriendListItemDelegate;
 class GeoCoordinate;
-class ListView;
+class FriendListView;
 class User;
 
 /**
@@ -108,8 +108,7 @@ private:
 
     QPushButton *m_clearFilterButton;   ///< Button to clear list filtering
 
-    ListView *m_friendListView;                         ///< Friend list view
-    FriendListItemDelegate *m_friendListItemDelegate;   ///< Friend list item delegate
+    FriendListView *m_friendListView;   ///< Friend 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 dd6dbc0..a7f3fff 100644 (file)
@@ -30,35 +30,34 @@ 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 = 141;///< Minimum height for item
+const int ITEM_MIN_HEIGHT = 70; ///< Minimum height for item
 const int MARGIN = 5;           ///< Text and image margin
 
 /**
-* @var NAME_LABEL_MAX_WIDTH
+* @var NAME_TEXT_MAX_WIDTH
 *
 * @brief Name label's maximum width
 */
-const int NAME_LABEL_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH;
+const int NAME_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH;
 
 /**
-* @var LABEL_MAX_WIDTH
+* @var SUBITEM_TEXT_MAX_WIDTH
 *
 * @brief All label's maximum width
 */
-const int LABEL_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH - MARGIN * 2;
+const int SUBITEM_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH
+                                   - MARGIN * 2;
 
 const int NAME_DISPLAY_INDEX = Qt::DisplayRole;
 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 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 6bd4790..6ca1b99 100644 (file)
 */
 
 #include <QDebug>
+#include <QPainter>
 
 #include "listitem.h"
+#include "listcommon.h"
+#include "../common.h"
 
 ListItem::ListItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
+    setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
 }
 
-QPixmap ListItem::image() const
+QString ListItem::name() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_image;
+    return data(NAME_DISPLAY_INDEX).toString();
 }
 
-QString ListItem::name() const
+void ListItem::setImage(const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_name;
+    setData(ITEM_HAS_IMAGE_INDEX, true);
+    setData(AVATAR_IMAGE_INDEX, image);
+
 }
 
-void ListItem::setImage(const QPixmap &image)
+void ListItem::setName(const QString &name)
 {
-    m_image = image;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setData(NAME_DISPLAY_INDEX, name);
 }
 
-void ListItem::setName(const QString &name)
+void ListItem::setSize(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_name = name;
+    setData(ITEM_SIZE_HINT_INDEX, size);
+}
+
+QString ListItem::shortenText(const QString &text, int textWidth, TextSize textSize)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+    QPainter painter(&p);
+
+    if (textSize == ListItem::TEXT_SIZE_NORMAL)
+        painter.setFont(NOKIA_FONT_NORMAL);
+    else
+        painter.setFont(NOKIA_FONT_SMALL);
+
+    QFontMetrics textMetrics = painter.fontMetrics();
+
+    QString shortenedText = text;
+
+    int index = shortenedText.indexOf('\n');
+
+    if (index > 0) {
+        shortenedText.truncate(index);
+        shortenedText.append("...");
+    }
+
+    return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
 }
index 45d8387..254fafd 100644 (file)
 
 #include <QListWidgetItem>
 
-class User;
-
-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
 {
+
 public:
     /**
     * @brief Constructor.
     */
     ListItem();
 
+    /**
+    * @brief Defines text size.
+    */
+    enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
+
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -53,13 +54,6 @@ public:
     virtual QString id() const = 0;
 
     /**
-    * @brief Returns item's image.
-    *
-    * @return image's pixmap
-    */
-    QPixmap image() const;
-
-    /**
     * @brief Returns item's name.
     *
     * @return item's name
@@ -88,18 +82,28 @@ public:
     virtual void setSelected(bool selected) = 0;
 
     /**
-    * @brief Toggles selection.
+    * @brief Sets item size.
     *
-    * @return true if selection was toggled, false otherwise
+    * @param size item size
     */
-    virtual bool toggleSelection() = 0;
+    void setSize(const QSize &size);
+
+    /**
+    * @brief Shortens text defined by text width.
+    *
+    * @param text text to be shortened
+    * @param textWidth the width the text can use
+    * @param textSize which text size to use
+    * @return shortened text
+    */
+    QString shortenText(const QString &text, int textWidth, TextSize textSize);
 
     /**
-    * @brief Returns item's coordinates.
+    * @brief Toggles selection.
     *
-    * @return item's coordinates
+    * @return true if selection was toggled, false otherwise
     */
-    virtual GeoCoordinate coordinates() = 0;
+    virtual bool toggleSelection() = 0;
 
 /*******************************************************************************
  * DATA MEMBERS
index 8deb47e..b350db4 100644 (file)
@@ -65,12 +65,19 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
     painter->drawPixmap(middleRect, m_backgroundMiddleImage);
     painter->drawPixmap(bottomRect, m_backgroundBottomImage);
 
-    painter->drawPixmap(itemRect.left() + MARGIN*2, itemRect.top(), image);
-
     painter->setPen(Qt::white);
     painter->setFont(NOKIA_FONT_NORMAL);
-    painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN, NAME_TOP_MARGIN),
-                      name);
+
+    //Image is set, draw image and text
+    if (!image.isNull()) {
+        painter->drawPixmap(itemRect.left() + MARGIN*2, itemRect.top(), image);
+        painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN,
+                                                      NAME_TOP_MARGIN), name);
+    }
+    //Draw only text
+    else {
+        painter->drawText(itemRect.topLeft() + QPoint(MARGIN*3, NAME_TOP_MARGIN), name);
+    }
 }
 
 QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
index e35a2d5..e9a2c64 100644 (file)
@@ -68,9 +68,9 @@ public:
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    QPixmap m_backgroundTopImage;   ///< Top background image
-    QPixmap m_backgroundMiddleImage;   ///< Middle background image
     QPixmap m_backgroundBottomImage;   ///< Bottom background image
+    QPixmap m_backgroundMiddleImage;   ///< Middle background image
+    QPixmap m_backgroundTopImage;       ///< Top background image
 };
 
 #endif // LISTITEMDELEGATE_H
index af41cde..051f17c 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,14 +61,16 @@ void ListView::clearList()
 
     m_listItems.clear();
     clear();
+
+    m_previousItem = 0;
 }
 
-void ListView::clearUnused(const QStringList &userIDs)
+void ListView::clearUnused(const QStringList &itemIDs)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     foreach (QString key, m_listItems.keys()) {
-        if (!userIDs.contains(key)) {
+        if (!itemIDs.contains(key)) {
             ListItem *item = m_listItems.take(key);
             if (item) {
                 takeItem(row(item));
@@ -86,30 +91,42 @@ void ListView::clearFilter()
         setItemHidden(item, false);
 }
 
-bool ListView::contains(const QString &userID)
+bool ListView::contains(const QString &itemID)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_listItems.contains(itemID);
+}
+
+void ListView::filter(const QList<QString> &itemIDs)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_listItems.contains(userID);
+    foreach (ListItem *item, m_listItems) {
+        if (itemIDs.contains(item->id()))
+            setItemHidden(item, false);
+        else
+            setItemHidden(item, true);
+    }
 }
 
-void ListView::filter(const QList<QString> &userIDs)
+void ListView::filter(const QString &pattern)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     foreach (ListItem *item, m_listItems) {
-        if (userIDs.contains(item->id()))
+        if (item->name().contains(pattern, Qt::CaseInsensitive))
             setItemHidden(item, false);
         else
             setItemHidden(item, true);
     }
 }
 
-ListItem *ListView::takeListItemFromView(const QString &userID)
+ListItem *ListView::takeListItemFromView(const QString &itemID)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ListItem *item = listItem(userID);
+    ListItem *item = listItem(itemID);
     takeItem(row(item));
     return item;
 }
@@ -118,31 +135,35 @@ void ListView::listItemClicked(QListWidgetItem *item)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ListItem *currentItem = static_cast<ListItem*>(item);
+    ListItem *currentItem = dynamic_cast<ListItem*>(item);
 
     if (currentItem) {
-
         if (m_previousItem == currentItem) {
-            bool selected = currentItem->toggleSelection();
-
-            if (selected)
-                emit listItemClicked(currentItem->coordinates());
+            currentItem->toggleSelection();
 
         } else {
             if (m_previousItem)
                 m_previousItem->setSelected(false);
 
             currentItem->setSelected(true);
-            emit listItemClicked(currentItem->coordinates());
         }
-
         m_previousItem = currentItem;
     }
 }
 
-ListItem *ListView::listItem(const QString &userID)
+
+
+ListItem *ListView::listItem(const QString &itemID)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return dynamic_cast<ListItem*>(m_listItems.value(itemID));
+}
+
+
+ListView::~ListView()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return static_cast<ListItem*>(m_listItems.value(userID));
+    clearList();
 }
index 16d63a8..8e98a4b 100644 (file)
@@ -45,6 +45,13 @@ public:
     */
     ListView(QWidget *parent = 0);
 
+    /**
+    * @brief Destructor.
+    *
+    * Calls ListView::clearList().
+    */
+    ~ListView();
+
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -67,11 +74,11 @@ public:
     /**
     * @brief Clear unused items from view.
     *
-    * Clears items which are not in user ID's list from the view and items list.
+    * Clears items which are not in item ID's list from the view and items list.
     *
-    * @param userIDs list of new user ID's.
+    * @param itemIDs list of item ID's to keep in list view
     */
-    void clearUnused(const QStringList &userIDs);
+    void clearUnused(const QStringList &itemIDs);
 
     /**
     * @brief Clears filtering from list.
@@ -96,57 +103,56 @@ public:
     bool contains(const QString &userID);
 
     /**
-    * @brief Sets filter to list.
+    * @brief Filters list by item IDs.
+    *
+    * Hide all items that are not in the itemIDs list.
+    *
+    * @param itemIDs item ID's for items that are shown
+    */
+    void filter(const QList<QString> &itemIDs);
+
+    /**
+    * @brief Filters list by text pattern.
     *
-    * Hide all items that are not in the userIDs list.
+    * Filtering uses item names.
     *
-    * @param userIDs user ID's to items that are shown
+    * @param pattern text pattern to filter
     */
-    void filter(const QList<QString> &userIDs);
+    void filter(const QString &pattern);
 
     /**
     * @brief Takes item from view.
     *
     * Item is not deleted.
     *
-    * @param userID user's ID
+    * @param itemID item's ID
     * @return ListItem
     */
-    ListItem *takeListItemFromView(const QString &userID);
+    ListItem *takeListItemFromView(const QString &itemID);
 
     /**
-    * @brief Returns ListItem with userID.
+    * @brief Returns ListItem with itemID.
     *
-    * @param userID user's ID
+    * @param itemID item's ID
     * @return ListItem
     */
-    ListItem *listItem(const QString &userID);
+    ListItem *listItem(const QString &itemID);
 
-private slots:
+protected slots:
     /**
     * @brief Slot for list item clicked.
     *
     * Toggles items selection state and emits listItemClicked signal.
     */
-    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);
+    virtual void listItemClicked(QListWidgetItem *item);
 
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    ListItem *m_previousItem;               ///< Previously selected item
     QHash<QString, ListItem *> m_listItems; ///< List of items in this view. Key = user ID
+
+    ListItem *m_previousItem;               ///< Previously selected item
 };
 
 #endif // LISTVIEW_H
diff --git a/src/ui/locationlistitem.cpp b/src/ui/locationlistitem.cpp
new file mode 100644 (file)
index 0000000..20accca
--- /dev/null
@@ -0,0 +1,67 @@
+#include <QDebug>
+
+#include "../common.h"
+#include "listcommon.h"
+
+#include "locationlistitem.h"
+
+const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
+
+LocationListItem::LocationListItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setSubitemTextWidth(LOCATION_SUBITEM_TEXT_MAX_WIDTH);
+}
+
+GeoCoordinate LocationListItem::coordinates()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_location.coordinates();
+}
+
+QString LocationListItem::id() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return QString();
+}
+
+void LocationListItem::setLocationData(const Location &location)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_location = location;
+
+    QStringList addressComponents = m_location.addressComponents();
+
+    if (addressComponents.count() > 0)
+        setName(shortenText(addressComponents.at(0), ITEM_WIDTH - 3*MARGIN,
+                            ListItem::TEXT_SIZE_NORMAL));
+
+    QString addressTail;
+
+    for (int i = 1; i < addressComponents.count(); ++i) {
+        addressTail.append(addressComponents.at(i));
+
+        if (i < (addressComponents.count() - 1))
+            addressTail.append(", ");
+    }
+
+    clearSubItems();
+    addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
+
+}
+
+void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_location.viewport(swBound, neBound);
+}
+
+LocationListItem::~LocationListItem()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
diff --git a/src/ui/locationlistitem.h b/src/ui/locationlistitem.h
new file mode 100644 (file)
index 0000000..90aedb9
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef LOCATIONLISTITEM_H
+#define LOCATIONLISTITEM_H
+
+#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
+    */
+    GeoCoordinate coordinates();
+
+    /**
+    * @brief Returns item's ID.
+    *
+    * @return item's ID
+    */
+    QString id() const;
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Set location data for this item.
+    *
+    * @param location Location data
+    */
+    void setLocationData(const Location &location);
+
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+    Location m_location;    ///< Location data
+};
+
+#endif // LOCATIONLISTITEM_H
diff --git a/src/ui/locationlistview.cpp b/src/ui/locationlistview.cpp
new file mode 100644 (file)
index 0000000..eacfcc9
--- /dev/null
@@ -0,0 +1,25 @@
+#include "locationlistitem.h"
+
+#include "locationlistview.h"
+
+LocationListView::LocationListView(QWidget *parent)
+    : ListView(parent)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+void LocationListView::listItemClicked(QListWidgetItem *item)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    ListView::listItemClicked(item);
+
+    LocationListItem *locationItem = dynamic_cast<LocationListItem*>(item);
+
+    if (locationItem) {
+        GeoCoordinate swBound;
+        GeoCoordinate neBound;
+        locationItem->bounds(swBound, neBound);
+        emit locationItemClicked(swBound, neBound);
+    }
+}
diff --git a/src/ui/locationlistview.h b/src/ui/locationlistview.h
new file mode 100644 (file)
index 0000000..19af2a0
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef LOCATIONLISTVIEW_H
+#define LOCATIONLISTVIEW_H
+
+#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);
+
+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);
+};
+
+#endif // LOCATIONLISTVIEW_H
index ee4e7ea..a120f88 100644 (file)
@@ -52,6 +52,7 @@ class SituareService;
 class User;
 class UserInfoPanel;
 class ZoomButtonPanel;
+class Location;
 
 /**
 * @brief Main Window Class
@@ -485,13 +486,28 @@ signals:
     void friendsLocationsReady(QList<User *> &friendsList);
 
     /**
-     * @brief Signal is emitted when location item is clicked.
+    * @brief Emited when location request is parsed and is ready for further processing
+    *
+    * @param result List of Location items
+    */
+    void locationDataParsed(QList<Location> &result);
+
+    /**
+     * @brief Signal is emitted when location item is clicked on map.
      *
      * @param userIDs list of friends user IDs in the group
      */
     void locationItemClicked(const QList<QString> &userIDs);
 
     /**
+     * @brief Signal is emitted when location item is clicked in list.
+     *
+     * @param swBound south-west bound in GeoCoorinate
+     * @param neBound north-east bound in GeoCoordinate
+     */
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
+    /**
      * @brief Signals when Login/Logout action is pressed
      *
      */
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)