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()
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()
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
zoomed();
}
}
+
+void MapEngine::locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ centerAndZoomTo(QRect(SceneCoordinate(swBound).toPointF().toPoint(),
+ SceneCoordinate(neBound).toPointF().toPoint()));
+}
*/
void zoomOut();
+ void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
/*******************************************************************************
* SIGNALS
******************************************************************************/
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 \
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
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <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));
+ }
+}
--- /dev/null
+#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
--- /dev/null
+#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);
+}
--- /dev/null
+#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
--- /dev/null
+#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;
+}
--- /dev/null
+#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
{
qDebug() << __PRETTY_FUNCTION__;
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+ setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
}
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)
m_user = user;
if (!m_user->profileImage().isNull())
- setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
+ setImage(m_user->profileImage());
QString unit;
double value;
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)
{
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)
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));
}
}
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
#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"
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)),
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)
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__;
class GeoCoordinate;
class ListView;
class User;
+class Location;
+class LocationListView;
/**
* @brief Class for sliding friends list panel
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.
*/
void findFriend(const GeoCoordinate &coordinates);
+ void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
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
};
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;
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;
*/
#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);
}
*/
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.
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
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
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__;
*/
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
--- /dev/null
+#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);
+}
--- /dev/null
+#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
--- /dev/null
+#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);
+ }
+}
--- /dev/null
+#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
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()
class User;
class UserInfoPanel;
class ZoomButtonPanel;
+class Location;
/**
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
*