Merge branch 'master' into locationlistview
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 28 Jul 2010 14:20:14 +0000 (17:20 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 28 Jul 2010 14:20:14 +0000 (17:20 +0300)
Conflicts:
src/ui/mainwindow.h

27 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/friendlistpanel.cpp
src/ui/friendlistpanel.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 [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.cpp
src/ui/mainwindow.h

index 9b78942..9dac412 100644 (file)
@@ -644,6 +644,9 @@ void SituareEngine::signalsFromMainWindow()
 
     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()
@@ -685,6 +688,8 @@ void SituareEngine::signalsFromRoutingService()
     connect(m_routingService, SIGNAL(routeParsed(Route&)),
             m_mapEngine, SLOT(setRoute(Route&)));
 
+    connect(m_routingService, SIGNAL(locationDataParsed(QList<Location>&)),
+            m_ui, SIGNAL(locationDataParsed(QList<Location>&)));
 }
 
 void SituareEngine::signalsFromSituareService()
index b710b3b..4c5ef03 100644 (file)
@@ -306,6 +306,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 0edebee..a56f158 100644 (file)
@@ -623,3 +623,11 @@ void MapEngine::zoomOut()
         zoomed();
     }
 }
+
+void MapEngine::locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    centerAndZoomTo(QRect(SceneCoordinate(swBound).toPointF().toPoint(),
+                          SceneCoordinate(neBound).toPointF().toPoint()));
+}
index 0fe23aa..087e273 100644 (file)
@@ -378,6 +378,8 @@ private slots:
      */
     void zoomOut();
 
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
index 785be90..9a969ff 100644 (file)
@@ -66,7 +66,12 @@ SOURCES += main.cpp \
     ui/listitem.cpp \
     ui/listitemdelegate.cpp \
     ui/friendlistitemdelegate.cpp \
-    ui/searchdialog.cpp
+    ui/searchdialog.cpp \
+    ui/locationlistitem.cpp \
+    ui/extendedlistitem.cpp \
+    ui/extendedlistitemstore.cpp \
+    ui/extendedlistitemdelegate.cpp \
+    ui/locationlistview.cpp
 HEADERS += application.h \
     common.h \
     engine/engine.h \
@@ -133,7 +138,12 @@ HEADERS += application.h \
     ui/listitemdelegate.h \
     ui/friendlistitemdelegate.h \
     ui/listcommon.h \
-    ui/searchdialog.h
+    ui/searchdialog.h \
+    ui/locationlistitem.h \
+    ui/extendedlistitem.h \
+    ui/extendedlistitemstore.h \
+    ui/extendedlistitemdelegate.h \
+    ui/locationlistview.h
 QT += network \
     webkit
 
diff --git a/src/ui/extendedlistitem.cpp b/src/ui/extendedlistitem.cpp
new file mode 100644 (file)
index 0000000..4644b42
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+   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;
+
+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);
+}
+
+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);
+    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;
+}
+
+void ExtendedListItem::setSubitemTextWidth(int width)
+{
+    m_subItemTextWidth = width;
+}
+
+bool ExtendedListItem::toggleSelection()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    setSelected(!m_selected);
+    return m_selected;
+}
+
+void ExtendedListItem::setSelected(bool selected)
+{
+    qWarning() << __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));
+    }
+}
diff --git a/src/ui/extendedlistitem.h b/src/ui/extendedlistitem.h
new file mode 100644 (file)
index 0000000..65a1ea8
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef EXTENDEDLISTITEM_H
+#define EXTENDEDLISTITEM_H
+
+#include "../coordinates/geocoordinate.h"
+
+#include "listitem.h"
+
+class ExtendedListItemStore;
+
+class ExtendedListItem : public ListItem
+{
+public:
+    ExtendedListItem();
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+
+    /**
+    * @brief Sets item selected.
+    *
+    * @param selected true if selected, false otherwise
+    */
+    void setSelected(bool selected);
+
+    void setSubitemTextWidth(int width);
+
+    /**
+    * @brief Toggles selection.
+    *
+    * @return true if selection was toggled, false otherwise
+    */
+    bool toggleSelection();
+
+    void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
+
+private:
+    QRect calculateExpandedTextRect(const QString &text);
+
+private:
+    bool m_selected;
+    int m_expandedHeight;
+    int m_normalHeight;
+    int m_subItemTextWidth;
+
+    QList<ExtendedListItemStore *> *m_subItemStoreList;
+};
+
+#endif // EXTENDEDLISTITEM_H
diff --git a/src/ui/extendedlistitemdelegate.cpp b/src/ui/extendedlistitemdelegate.cpp
new file mode 100644 (file)
index 0000000..8fa2ec5
--- /dev/null
@@ -0,0 +1,64 @@
+#include <QPainter>
+#include <QDebug>
+#include <QRect>
+
+#include "../common.h"
+#include "listcommon.h"
+#include "extendedlistitemstore.h"
+
+#include "extendedlistitemdelegate.h"
+
+ExtendedListItemDelegate::ExtendedListItemDelegate()
+{
+}
+
+void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+                                     const QModelIndex &index) const
+{
+    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();
+
+    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*2,
+                                       previousSubItemTextRectBottom,
+                                       ICON_WIDTH, ICON_HEIGHT);
+            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();
+        }
+    }
+}
+
+QSize ExtendedListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
+                                        const QModelIndex &index) const
+{
+    return ListItemDelegate::sizeHint(option, index);
+}
diff --git a/src/ui/extendedlistitemdelegate.h b/src/ui/extendedlistitemdelegate.h
new file mode 100644 (file)
index 0000000..340b95f
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef EXTENDEDLISTITEMDELEGATE_H
+#define EXTENDEDLISTITEMDELEGATE_H
+
+#include "listitemdelegate.h"
+
+class ExtendedListItemDelegate : public ListItemDelegate
+{
+public:
+    ExtendedListItemDelegate();
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+    /**
+    * @brief Draws FriendListItem data.
+    *
+    * Draws distance, status, updated and location texts with icons.
+    * @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
diff --git a/src/ui/extendedlistitemstore.cpp b/src/ui/extendedlistitemstore.cpp
new file mode 100644 (file)
index 0000000..7190e1c
--- /dev/null
@@ -0,0 +1,65 @@
+#include <QDebug>
+
+#include "extendedlistitemstore.h"
+
+ExtendedListItemStore::ExtendedListItemStore()
+{
+}
+
+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..d80bea8
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef EXTENDEDLISTITEMSTORE_H
+#define EXTENDEDLISTITEMSTORE_H
+
+#include <QPixmap>
+#include <QRect>
+#include <QString>
+#include <QMetaType>
+
+class ExtendedListItemStore
+{
+public:
+    ExtendedListItemStore();
+
+    ExtendedListItemStore(const QString &text);
+
+    void setShortenedText(const QString &shortenedText);
+
+    void setIcon(const QPixmap &icon);
+
+    void setTextRect(const QRect &textRect);
+
+    QPixmap icon() const;
+    QRect textRect() const;
+    QString text() const;
+    QString shortenedText() const;
+
+private:
+    QPixmap m_icon;
+    QRect m_textRect;
+    QString m_text;
+    QString m_shortenedText;
+};
+
+#endif // EXTENDEDLISTITEMSTORE_H
index 86faa13..e59ead4 100644 (file)
@@ -49,7 +49,7 @@ FriendListItem::FriendListItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+    setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
 }
 
 void FriendListItem::calculateTextRects()
@@ -67,15 +67,15 @@ void FriendListItem::calculateTextRects()
     QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
     QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
 
-    int statusTextRectFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
+    int statusTextRectFactor = statusTextRect.width() / SUBITEM_TEXT_MAX_WIDTH;
     statusTextRectFactor++;
-    m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
-    int updatedRectFactor = updatedRect.width() / LABEL_MAX_WIDTH;
+    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, LABEL_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
-    int locationRectFactor = locationRect.width() / LABEL_MAX_WIDTH;
+    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, LABEL_MAX_WIDTH, ICON_HEIGHT * 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)
@@ -106,7 +106,7 @@ void FriendListItem::setUserData(User *user)
         m_user = user;
 
         if (!m_user->profileImage().isNull())
-            setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
+            setImage(m_user->profileImage());
 
         QString unit;
         double value;
@@ -126,7 +126,7 @@ void FriendListItem::setAvatarImage(const QPixmap &image)
     qDebug() << __PRETTY_FUNCTION__;
 
     if(!image.isNull())
-        setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
+        setImage(m_user->profileImage());
 }
 
 void FriendListItem::setDistanceIcon(double value, const QString &unit)
@@ -151,50 +151,13 @@ void FriendListItem::shortenTexts()
 {
     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);
+    int distanceLabelWidth = 50;//otherLabelsMetrics.width(m_distanceText) + MARGIN;
+    setName(shortenText(m_user->name(), NAME_TEXT_MAX_WIDTH - distanceLabelWidth,
+                        ListItem::TEXT_SIZE_NORMAL));
 
-    setData(NAME_DISPLAY_INDEX, m_shortenedName);
+    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)
@@ -214,9 +177,9 @@ void FriendListItem::setText(bool expanded)
         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));
+        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));
     }
 }
 
index c91e658..e0f0b7f 100644 (file)
@@ -142,7 +142,6 @@ private:
     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
 
index 70aca8d..fcb7d79 100644 (file)
 #include "friendlistitemdelegate.h"
 #include "panelcommon.h"
 #include "sidepanel.h"
+#include "../routing/location.h"
+#include "locationlistitem.h"
+#include "locationlistview.h"
+#include "extendedlistitemdelegate.h"
 
 #include "friendlistpanel.h"
 
@@ -60,8 +64,16 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     m_friendListView->viewport()->setAutoFillBackground(false);
     m_friendListItemDelegate = new FriendListItemDelegate();
     m_friendListView->setItemDelegate(m_friendListItemDelegate);
+    //REMOVE
+    m_friendListView->hide();
 
-    friendListLayout->addWidget(m_friendListView);
+    m_locationListView = new LocationListView(this);
+    m_locationListView->setAutoFillBackground(false);
+    m_locationListView->viewport()->setAutoFillBackground(false);
+    m_locationListView->setItemDelegate(new ExtendedListItemDelegate());
+
+    //friendListLayout->addWidget(m_friendListView);
+    friendListLayout->addWidget(m_locationListView);
     m_panelVBox->addLayout(friendListLayout);
 
     connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
@@ -71,6 +83,9 @@ FriendListPanel::FriendListPanel(QWidget *parent)
             this, SLOT(clearFriendListFilter()));
     connect(this, SIGNAL(panelOpened()),
             this, SLOT(clearFriendListFilter()));
+
+    connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
+            this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
 }
 
 void FriendListPanel::friendImageReady(User *user)
@@ -120,6 +135,21 @@ void FriendListPanel::clearFriendListFilter()
     m_friendListView->clearFilter();
 }
 
+void FriendListPanel::locationDataReady(QList<Location> &result)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_locationListView->clearList();
+
+    for (int i = 0; i < result.size(); ++i) {
+        LocationListItem *item = new LocationListItem();
+        item->setLocationData(result.at(i));
+        m_locationListView->addListItem(QString::number(i), item);
+    }
+
+
+}
+
 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 6e83cb9..d605ca8 100644 (file)
@@ -34,6 +34,8 @@ class FriendListItemDelegate;
 class GeoCoordinate;
 class ListView;
 class User;
+class Location;
+class LocationListView;
 
 /**
 * @brief Class for sliding friends list panel
@@ -78,6 +80,13 @@ private slots:
     void clearFriendListFilter();
 
     /**
+    * @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 show friends in list.
     *
     * Shows only friends that are on userIDs list.
@@ -96,6 +105,8 @@ signals:
     */
     void findFriend(const GeoCoordinate &coordinates);
 
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
@@ -104,6 +115,7 @@ private:
     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
 };
 
index 17338cc..450ffee 100644 (file)
@@ -30,22 +30,23 @@ 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 = 75; ///< 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;
@@ -56,6 +57,9 @@ 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;
index 6bd4790..869d408 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
+void ListItem::setImage(const QPixmap &image)
 {
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_image;
+    setData(AVATAR_IMAGE_INDEX, image);
 }
 
-QString ListItem::name() const
+void ListItem::setName(const QString &name)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_name;
+    setData(NAME_DISPLAY_INDEX, name);
 }
 
-void ListItem::setImage(const QPixmap &image)
+void ListItem::setSize(const QSize &size)
 {
-    m_image = image;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setData(ITEM_SIZE_HINT_INDEX, size);
 }
 
-void ListItem::setName(const QString &name)
+QString ListItem::shortenText(const QString &text, int textWidth, TextSize textSize)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_name = name;
+    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("...");
+    }
+
+    qWarning() << shortenedText;
+    qWarning() << textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
+    qWarning() << textWidth;
+
+    return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
 }
index 45d8387..89ed4fa 100644 (file)
@@ -42,29 +42,24 @@ public:
     */
     ListItem();
 
+    enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
+
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
     /**
-    * @brief Returns item's ID.
-    *
-    * @return item's ID
-    */
-    virtual QString id() const = 0;
-
-    /**
-    * @brief Returns item's image.
+    * @brief Returns item's coordinates.
     *
-    * @return image's pixmap
+    * @return item's coordinates
     */
-    QPixmap image() const;
+    virtual GeoCoordinate coordinates() = 0;
 
     /**
-    * @brief Returns item's name.
+    * @brief Returns item's ID.
     *
-    * @return item's name
+    * @return item's ID
     */
-    QString name() const;
+    virtual QString id() const = 0;
 
     /**
     * @brief Sets item's image.
@@ -88,18 +83,30 @@ 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 Returns item's coordinates.
+    * @brief Shortens text defined by text width.
     *
-    * @return item's coordinates
+    * @param text text to be shortened
+    * @param textWidth the width the text can use
+    * @param textSize which text size to use
+    * @return shortened text
     */
-    virtual GeoCoordinate coordinates() = 0;
+    QString shortenText(const QString &text, int textWidth, TextSize textSize);
+
+    /**
+    * @brief Toggles selection.
+    *
+    * @return true if selection was toggled, false otherwise
+    */
+    virtual bool toggleSelection() = 0;
+
+
 
 /*******************************************************************************
  * DATA MEMBERS
index 8deb47e..324c254 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*2, NAME_TOP_MARGIN), name);
+    }
 }
 
 QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
index af41cde..995d039 100644 (file)
@@ -116,30 +116,34 @@ ListItem *ListView::takeListItemFromView(const QString &userID)
 
 void ListView::listItemClicked(QListWidgetItem *item)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
     ListItem *currentItem = static_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());
+                ;//emit listItemClicked(currentItem->coordinates());
 
         } else {
+            qWarning() << __PRETTY_FUNCTION__ << "previousItem != currentItem";
             if (m_previousItem)
                 m_previousItem->setSelected(false);
 
             currentItem->setSelected(true);
-            emit listItemClicked(currentItem->coordinates());
+            //emit listItemClicked(currentItem->coordinates());
         }
 
         m_previousItem = currentItem;
     }
 }
 
+
+
 ListItem *ListView::listItem(const QString &userID)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 16d63a8..0b64787 100644 (file)
@@ -122,13 +122,13 @@ public:
     */
     ListItem *listItem(const QString &userID);
 
-private slots:
+protected slots:
     /**
     * @brief Slot for list item clicked.
     *
     * Toggles items selection state and emits listItemClicked signal.
     */
-    void listItemClicked(QListWidgetItem *item);
+    virtual void listItemClicked(QListWidgetItem *item);
 
 /******************************************************************************
 * SIGNALS
diff --git a/src/ui/locationlistitem.cpp b/src/ui/locationlistitem.cpp
new file mode 100644 (file)
index 0000000..fb8306b
--- /dev/null
@@ -0,0 +1,57 @@
+#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)
+{
+    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(", ");
+    }
+
+    addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
+
+}
+
+void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+    m_location.bounds(swBound, neBound);
+}
diff --git a/src/ui/locationlistitem.h b/src/ui/locationlistitem.h
new file mode 100644 (file)
index 0000000..dc89fc1
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef LOCATIONLISTITEM_H
+#define LOCATIONLISTITEM_H
+
+#include "extendedlistitem.h"
+#include "../routing/location.h"
+
+class LocationListItem : public ExtendedListItem
+{
+public:
+    LocationListItem();
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+public:
+    /**
+    * @brief Returns item's coordinates.
+    *
+    * @return item's coordinates
+    */
+    GeoCoordinate coordinates();
+
+    /**
+    * @brief Returns item's ID.
+    *
+    * @return item's ID
+    */
+    QString id() const;
+
+    void bounds(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Set user data for this item.
+    *
+    * @param user User pointer
+    */
+    void setLocationData(const Location &location);
+
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
+private:
+    Location m_location;
+    bool m_selected;
+};
+
+#endif // LOCATIONLISTITEM_H
diff --git a/src/ui/locationlistview.cpp b/src/ui/locationlistview.cpp
new file mode 100644 (file)
index 0000000..5233f56
--- /dev/null
@@ -0,0 +1,26 @@
+#include "locationlistitem.h"
+
+#include "locationlistview.h"
+
+LocationListView::LocationListView(QWidget *parent)
+    : ListView(parent)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+}
+
+void LocationListView::listItemClicked(QListWidgetItem *item)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    ListView::listItemClicked(item);
+
+    LocationListItem *locationItem = static_cast<LocationListItem*>(item);
+
+    if (locationItem) {
+        qWarning() << __PRETTY_FUNCTION__ << "locationItem != null";
+        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..f779b0f
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef LOCATIONLISTVIEW_H
+#define LOCATIONLISTVIEW_H
+
+#include "listview.h"
+
+class LocationListView : public ListView
+{
+    Q_OBJECT
+
+public:
+    LocationListView(QWidget *parent = 0);
+
+private slots:
+    void listItemClicked(QListWidgetItem *item);
+
+signals:
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+};
+
+#endif // LOCATIONLISTVIEW_H
index 7f5997f..5a74bde 100644 (file)
@@ -176,6 +176,12 @@ void MainWindow::buildFriendListPanel()
 
     connect(this, SIGNAL(friendImageReady(User*)),
             m_friendsListPanel, SLOT(friendImageReady(User*)));
+
+    connect(this, SIGNAL(locationDataParsed(QList<Location>&)),
+            m_friendsListPanel, SLOT(locationDataReady(QList<Location>&)));
+
+    connect(m_friendsListPanel, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
+            this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
 }
 
 void MainWindow::buildIndicatorButton()
index 6c0177f..e238b99 100644 (file)
@@ -52,6 +52,7 @@ class SituareService;
 class User;
 class UserInfoPanel;
 class ZoomButtonPanel;
+class Location;
 
 
 /**
@@ -489,12 +490,21 @@ signals:
     void friendsLocationsReady(QList<User *> &friendsList);
 
     /**
+    * @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.
      *
      * @param userIDs list of friends user IDs in the group
      */
     void locationItemClicked(const QList<QString> &userIDs);
 
+    void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
     /**
      * @brief Signals when Login/Logout action is pressed
      *