-Delegate.
connect(m_ui, SIGNAL(findFriend(GeoCoordinate)),
m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
+ connect(m_ui, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
+ m_mapEngine, SLOT(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+
// signals from distence indicator button
connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
this, SLOT(changeAutoCenteringSetting(bool)));
connect(m_ui, SIGNAL(searchForLocation(QString)),
this, SLOT(locationSearch(QString)));
-
- connect(m_ui, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
- m_mapEngine, SLOT(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
}
void SituareEngine::signalsFromMapEngine()
location.setCoordinates(locationMap["lat"].toDouble(),
locationMap["lng"].toDouble());
- QVariant boundsVariant = geometryMap["bounds"];
+ QVariant boundsVariant = geometryMap["viewport"];
QMap<QString, QVariant> boundsMap = boundsVariant.toMap();
QVariant swVariant = boundsMap["southwest"];
QMap<QString, QVariant> swMap = swVariant.toMap();
ui/extendedlistitem.cpp \
ui/extendedlistitemstore.cpp \
ui/extendedlistitemdelegate.cpp \
- ui/locationlistview.cpp
+ ui/locationlistview.cpp \
+ ui/friendlistview.cpp
HEADERS += application.h \
common.h \
engine/engine.h \
ui/extendedlistitem.h \
ui/extendedlistitemstore.h \
ui/extendedlistitemdelegate.h \
- ui/locationlistview.h
+ ui/locationlistview.h \
+ ui/friendlistview.h
QT += network \
webkit
#include "extendedlistitem.h"
-const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT;
+const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT; ///< Sub item text row height
ExtendedListItem::ExtendedListItem()
: m_selected(false),
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__;
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)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_subItemTextWidth = width;
}
bool ExtendedListItem::toggleSelection()
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
setSelected(!m_selected);
return m_selected;
void ExtendedListItem::setSelected(bool selected)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
m_selected = selected;
setData(ITEM_EXPANDED_INDEX, m_selected);
setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
}
}
+
+ExtendedListItem::~ExtendedListItem()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ clearSubItems();
+ delete m_subItemStoreList;
+}
class ExtendedListItemStore;
+/**
+* @brief Base class for extended list items.
+*/
class ExtendedListItem : public ListItem
{
public:
+ /**
+ * @brief Constructor.
+ *
+ * Sets item size and creates sub item store list.
+ */
ExtendedListItem();
+ /**
+ * @brief Destructor.
+ *
+ * Deletes sub item stores and sub item store list.
+ */
+ virtual ~ExtendedListItem();
+
/*******************************************************************************
- * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
- ******************************************************************************/
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+ /**
+ * @brief Adds sub item.
+ *
+ * Sub item area is defined by sub item text width.
+ * @param text sub item text
+ * @param icon sub item icon, optional
+ */
+ void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
+
+ /**
+ * @brief Clears sub items.
+ *
+
+ */
+ void clearSubItems();
/**
* @brief Sets item selected.
*/
void setSelected(bool selected);
+ /**
+ * @brief Sets sub items' text width.
+ *
+ * @param width sub item width
+ */
void setSubitemTextWidth(int width);
/**
*/
bool toggleSelection();
- void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
-
private:
+ /**
+ * @brief Calculates text rects.
+ *
+ * Rect width is defined by sub item text width.
+ * @param text text which rect is calculated
+ * @return text rect
+ */
QRect calculateExpandedTextRect(const QString &text);
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
private:
- bool m_selected;
- int m_expandedHeight;
- int m_normalHeight;
- int m_subItemTextWidth;
+ bool m_selected; ///< Selected flag
+ int m_expandedHeight; ///< Item expanded height
+ int m_normalHeight; ///< Item normal height
+ int m_subItemTextWidth; ///< Sub items' text wdith
- QList<ExtendedListItemStore *> *m_subItemStoreList;
+ QList<ExtendedListItemStore *> *m_subItemStoreList; ///< ExtendedListItemStore list
};
#endif // EXTENDEDLISTITEM_H
#include "extendedlistitemdelegate.h"
-ExtendedListItemDelegate::ExtendedListItemDelegate()
+ExtendedListItemDelegate::ExtendedListItemDelegate(QWidget *parent)
+ : ListItemDelegate(parent)
{
+ qDebug() << __PRETTY_FUNCTION__;
}
void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
ListItemDelegate::paint(painter, option, index);
painter->setPen(COLOR_GRAY);
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) {
text = itemStore->shortenedText();
}
- QRect iconRect = QRect(itemRect.left() + MARGIN*2,
- previousSubItemTextRectBottom,
+ QRect iconRect = QRect(itemRect.left() + MARGIN*3,
+ previousSubItemTextRectBottom + ICON_MARGIN,
ICON_WIDTH, ICON_HEIGHT);
+
+ if (itemHasImage)
+ iconRect.translate(IMAGE_WIDTH, 0);
+
subItemTextRect.translate(iconRect.right() + MARGIN, iconRect.top());
if (!itemStore->icon().isNull())
}
}
}
-
-QSize ExtendedListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const
-{
- return ListItemDelegate::sizeHint(option, index);
-}
#include "listitemdelegate.h"
+/**
+* @brief Defines ExtendedListItem style.
+*/
class ExtendedListItemDelegate : public ListItemDelegate
{
public:
- ExtendedListItemDelegate();
+ /**
+ * @brief Constructor
+ *
+ * @param parent QWidget
+ */
+ ExtendedListItemDelegate(QWidget *parent = 0);
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
******************************************************************************/
/**
- * @brief Draws FriendListItem data.
+ * @brief Draws ExtendedListItem content.
*
- * Draws distance, status, updated and location texts with icons.
+ * Draws ExtendedListItem sub items icon and text.
* @param painter QPainter
* @param option QStyleOptionViewItem
* @param index QModelIndex
*/
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
-
- /**
- * @brief Returns item's size hint.
- *
- * @param option QStyleOptionViewItem
- * @param index QModelIndex
- * @return QSize
- */
- QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
-
};
#endif // EXTENDEDLISTITEMDELEGATE_H
#include "extendedlistitemstore.h"
-ExtendedListItemStore::ExtendedListItemStore()
-{
-}
-
ExtendedListItemStore::ExtendedListItemStore(const QString &text)
: m_icon(QPixmap()),
m_textRect(QRect()),
#include <QString>
#include <QMetaType>
+/**
+* @brief Store ExtendedListItem data.
+*/
class ExtendedListItemStore
{
public:
- ExtendedListItemStore();
-
+ /**
+ * @brief Constructor.
+ *
+ * Sets text.
+ * @param text item text
+ */
ExtendedListItemStore(const QString &text);
+/*******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+ /**
+ * @brief Sets shortended text.
+ *
+ * @param shortenedText shortened text
+ */
void setShortenedText(const QString &shortenedText);
+ /**
+ * @brief Sets icon.
+ *
+ * @param icon item icon
+ */
void setIcon(const QPixmap &icon);
+ /**
+ * @brief Sets text rect.
+ *
+ * @param textRect text rect
+ */
void setTextRect(const QRect &textRect);
+ /**
+ * @brief Returns icon.
+ *
+ * @return QPixmap
+ */
QPixmap icon() const;
+
+ /**
+ * @brief Returns text rect.
+ *
+ * @return QRect
+ */
QRect textRect() const;
+
+ /**
+ * @brief Returns text
+ *
+ * @return QString
+ */
QString text() const;
+
+ /**
+ * @brief Returns shortened text.
+ *
+ * @return QString
+ */
QString shortenedText() const;
+/******************************************************************************
+* DATA MEMBERS
+******************************************************************************/
private:
- QPixmap m_icon;
- QRect m_textRect;
- QString m_text;
- QString m_shortenedText;
+ QPixmap m_icon; ///< Icon pixmap
+ QRect m_textRect; ///< Text rect
+ QString m_text; ///< Text string
+ QString m_shortenedText; ///< Shortened text string
};
#endif // EXTENDEDLISTITEMSTORE_H
USA.
*/
-#include <QVBoxLayout>
-#include <QPushButton>
#include <QPainter>
#include <QDebug>
-#include <QPaintEvent>
-#include <QLabel>
#include <QPixmap>
-#include <QFormLayout>
-#include <QSpacerItem>
-#include <QStylePainter>
-#include <math.h>
-#include "friendlistitem.h"
#include "../user/user.h"
-#include "imagebutton.h"
#include "../common.h"
#include "listcommon.h"
+#include "friendlistitem.h"
+
const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
-const int RECTS_MINIMUM_FACTOR_SUM = 3; ///< Rects minimum factor sum
-
FriendListItem::FriendListItem()
- : m_selected(false)
- , m_user(0)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-}
-
-void FriendListItem::calculateTextRects()
+ : m_user(0)
{
qDebug() << __PRETTY_FUNCTION__;
- //Dummy value to get painter font metrics.
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics smallFontMetrics = painter.fontMetrics();
-
- QRect distanceRect = smallFontMetrics.boundingRect(m_distanceText);
- QRect statusTextRect = smallFontMetrics.boundingRect(m_user->note());
- QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
- QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
-
- int statusTextRectFactor = statusTextRect.width() / SUBITEM_TEXT_MAX_WIDTH;
- statusTextRectFactor++;
- m_statusTextRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
- int updatedRectFactor = updatedRect.width() / SUBITEM_TEXT_MAX_WIDTH;
- updatedRectFactor++;
- m_updatedRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
- int locationRectFactor = locationRect.width() / SUBITEM_TEXT_MAX_WIDTH;
- locationRectFactor++;
- m_locationRect = QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT * locationRectFactor);
-
- m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
- locationRectFactor - RECTS_MINIMUM_FACTOR_SUM)
- * ICON_HEIGHT);
-
- setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+ setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
}
GeoCoordinate FriendListItem::coordinates()
if(user) {
m_user = user;
- if (!m_user->profileImage().isNull())
- setImage(m_user->profileImage());
-
QString unit;
double value;
m_user->distance(value, unit);
- m_distanceText = QString::number(value) + " " + unit;
- setData(DISTANCE_TEXT_DISPLAY_INDEX, m_distanceText);
+ QString distanceText = QString::number(value) + " " + unit;
+ setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
setDistanceIcon(value, unit);
- shortenTexts();
- calculateTextRects();
- setText(false);
+ //Dummy value to get painter font metrics.
+ QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+ QPainter painter(&p);
+ painter.setFont(NOKIA_FONT_SMALL);
+ QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
+ QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
+
+ setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+ setName(shortenText(m_user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
+ ListItem::TEXT_SIZE_NORMAL));
+
+ if (!m_user->profileImage().isNull())
+ setImage(m_user->profileImage());
+
+ clearSubItems();
+
+ addSubItem(m_user->note(), QPixmap(":/res/images/envelope.png"));
+ addSubItem(m_user->address(), QPixmap(":/res/images/compass.png"));
+ addSubItem(m_user->timestamp(), QPixmap(":/res/images/clock.png"));
}
}
qDebug() << __PRETTY_FUNCTION__;
if(!image.isNull())
- setImage(m_user->profileImage());
+ setImage(image);
}
void FriendListItem::setDistanceIcon(double value, const QString &unit)
setData(DISTANCE_IMAGE_INDEX, distanceImage);
}
-void FriendListItem::shortenTexts()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- int distanceLabelWidth = 50;//otherLabelsMetrics.width(m_distanceText) + MARGIN;
- setName(shortenText(m_user->name(), NAME_TEXT_MAX_WIDTH - distanceLabelWidth,
- ListItem::TEXT_SIZE_NORMAL));
-
- m_shortenedStatusText = shortenText(m_user->note(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
- m_shortenedUpdated = shortenText(m_user->timestamp(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
- m_shortenedLocation = shortenText(m_user->address(), SUBITEM_TEXT_MAX_WIDTH, ListItem::TEXT_SIZE_SMALL);
-}
-
-void FriendListItem::setText(bool expanded)
+FriendListItem::~FriendListItem()
{
qDebug() << __PRETTY_FUNCTION__;
-
- if (expanded) {
- setData(STATUS_TEXT_DISPLAY_INDEX, m_user->note());
- setData(LOCATION_DISPLAY_INDEX, m_user->address());
- setData(UPDATED_DISPLAY_INDEX, m_user->timestamp());
-
- setData(STATUS_TEXT_SIZE_HINT_INDEX, m_statusTextRect);
- setData(LOCATION_SIZE_HINT_INDEX, m_locationRect);
- setData(UPDATED_SIZE_HINT_INDEX, m_updatedRect);
- } else {
- setData(STATUS_TEXT_DISPLAY_INDEX, m_shortenedStatusText);
- setData(LOCATION_DISPLAY_INDEX, m_shortenedLocation);
- setData(UPDATED_DISPLAY_INDEX, m_shortenedUpdated);
-
- setData(STATUS_TEXT_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
- setData(LOCATION_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
- setData(UPDATED_SIZE_HINT_INDEX, QRect(0, 0, SUBITEM_TEXT_MAX_WIDTH, ICON_HEIGHT));
- }
-}
-
-bool FriendListItem::toggleSelection()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- setSelected(!m_selected);
- return m_selected;
-}
-
-void FriendListItem::setSelected(bool selected)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_selected = selected;
-
- if (m_selected) {
- setText(true);
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
- } else {
- setText(false);
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
- }
}
#include <QListWidgetItem>
#include "../user/user.h"
-#include "listitem.h"
+#include "extendedlistitem.h"
/**
-* @brief Stores friend's data.
-*
-* Calculates shortened texts from user data and rects from user data.
-* Rects are used to calculate text field's sizes. Class inherits ListItem.
+* @brief List item stores information about friends.
*/
-class FriendListItem : public ListItem
+class FriendListItem : public ExtendedListItem
{
public:
/**
* @brief Constructor.
*
- * Sets default size hint for item.
+ * Sets sub items' text width.
*/
FriendListItem();
+ /**
+ * @brief Destructor.
+ */
+ ~FriendListItem();
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
******************************************************************************/
*/
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
******************************************************************************/
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.
*/
void setDistanceIcon(double value, const QString &unit);
- /**
- * @brief Sets shortened or full-length text to item.
- *
- * Sets also size hint for status, updated and location texts defined by calculated
- * text rects or default size.
- *
- * @param expanded true if full-length text is set, false otherwise
- */
- void setText(bool expanded);
-
- /**
- * @brief Calculates shortened texts from User data.
- *
- * Text length is defined by NAME_LABEL_MAX_WIDTH and LABEL_MAX_WIDTH.
- */
- void shortenTexts();
-
/******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- bool m_selected; ///< Item selected state
- QRect m_locationRect; ///< Location text rect
- QRect m_statusTextRect; ///< Status text rect
- QRect m_updatedRect; ///< Updated text rect
- int m_expandedHeight; ///< Item's expanded height
- QString m_distanceText; ///< Distance text
- QString m_shortenedLocation; ///< Shortened location text
- QString m_shortenedStatusText; ///< Shortened status text
- QString m_shortenedUpdated; ///< Shortened updated text
-
User *m_user; ///< User data
};
#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,
{
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)));
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);
}
#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
/**
* @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
*/
#include "coordinates/geocoordinate.h"
-#include "listview.h"
+#include "friendlistview.h"
#include "friendlistitem.h"
#include "friendlistitemdelegate.h"
#include "panelcommon.h"
: SidePanel(parent)
{
qDebug() << __PRETTY_FUNCTION__;
+
setType(SidePanel::FriendPanel);
QHBoxLayout *filterLayout = new QHBoxLayout;
filterLayout->addWidget(m_clearFilterButton);
m_panelVBox->addWidget(m_friendListHeaderWidget);
- QHBoxLayout *friendListLayout = new QHBoxLayout;
+ QVBoxLayout *friendListLayout = new QVBoxLayout;
friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
- m_friendListView = new ListView(this);
- m_friendListView->setAutoFillBackground(false);
- m_friendListView->viewport()->setAutoFillBackground(false);
- m_friendListItemDelegate = new FriendListItemDelegate();
- m_friendListView->setItemDelegate(m_friendListItemDelegate);
+ m_friendListView = new FriendListView(this);
+ m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
//REMOVE
- m_friendListView->hide();
+ //m_friendListView->hide();
m_locationListView = new LocationListView(this);
- m_locationListView->setAutoFillBackground(false);
- m_locationListView->viewport()->setAutoFillBackground(false);
- m_locationListView->setItemDelegate(new ExtendedListItemDelegate());
+ m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
+ //REMOVE
+ //m_locationListView->hide();
- //friendListLayout->addWidget(m_friendListView);
+ friendListLayout->addWidget(m_friendListView);
friendListLayout->addWidget(m_locationListView);
m_panelVBox->addLayout(friendListLayout);
- connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
- this, SIGNAL(findFriend(GeoCoordinate)));
+ connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
+ this, SIGNAL(friendItemClicked(GeoCoordinate)));
connect(m_clearFilterButton, SIGNAL(clicked()),
this, SLOT(clearFriendListFilter()));
void FriendListPanel::locationDataReady(QList<Location> &result)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
m_locationListView->clearList();
m_locationListView->addListItem(QString::number(i), item);
}
+ openPanel();
+
+ if (result.size() == 1) {
+ ListItem *item = m_locationListView->listItem(QString("0"));
+ if (item)
+ m_locationListView->listItemClicked(item);
+ }
}
void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
class FriendListItemDelegate;
class GeoCoordinate;
-class ListView;
+class FriendListView;
class User;
class Location;
class LocationListView;
******************************************************************************/
signals:
/**
- * @brief Signal for friend finding.
+ * @brief Signal for friend item clicked.
*
* @param coordinates Target coordinate
*/
- void findFriend(const GeoCoordinate &coordinates);
+ void friendItemClicked(const GeoCoordinate &coordinates);
+ /**
+ * @brief Signal for location item clicked.
+ *
+ * @param swBound south-west bound GeoCoordinate
+ * @param neBound north-east bound GeoCoordinate
+ */
void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
/*******************************************************************************
QWidget *m_friendListHeaderWidget; ///< Friend list header widget
QLabel *m_friendListLabel; ///< Friend list label
QPushButton *m_clearFilterButton; ///< Button to clear list filtering
- ListView *m_friendListView; ///< Friend list view
- LocationListView *m_locationListView;
- FriendListItemDelegate *m_friendListItemDelegate; ///< Friend list item delegate
+ FriendListView *m_friendListView; ///< Friend list view
+ LocationListView *m_locationListView; ///< Location list view
};
#endif // FRIENDLISTPANEL_H
-/*
- 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());
}
-/*
- 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
/**
* @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
const int ICON_WIDTH = 24; ///< Icon width
const int IMAGE_HEIGHT = 64; ///< Friend image height
const int IMAGE_WIDTH = 64; ///< Friend image width
-const int ITEM_MIN_HEIGHT = 75; ///< Minimum height for item
+const int ITEM_MIN_HEIGHT = 70; ///< Minimum height for item
const int MARGIN = 5; ///< Text and image margin
/**
const int ITEM_SIZE_HINT_INDEX = Qt::SizeHintRole;
const int DISTANCE_SIZE_HINT_INDEX = Qt::SizeHintRole + 1;
-const int STATUS_TEXT_SIZE_HINT_INDEX = Qt::SizeHintRole + 2;
-const int LOCATION_SIZE_HINT_INDEX = Qt::SizeHintRole + 3;
-const int UPDATED_SIZE_HINT_INDEX = Qt::SizeHintRole + 4;
-const int SUBITEM_STORE_INDEX = Qt::UserRole + 5;
-const int ITEM_EXPANDED_INDEX = Qt::UserRole + 6;
-const int STATUS_TEXT_DISPLAY_INDEX = Qt::UserRole;
-const int LOCATION_DISPLAY_INDEX = Qt::UserRole + 1;
-const int UPDATED_DISPLAY_INDEX = Qt::UserRole + 2;
+const int SUBITEM_STORE_INDEX = Qt::UserRole;
+const int ITEM_EXPANDED_INDEX = Qt::UserRole + 1;
+const int ITEM_HAS_IMAGE_INDEX = Qt::UserRole + 2;
const int DISTANCE_TEXT_DISPLAY_INDEX = Qt::UserRole + 3;
const int DISTANCE_IMAGE_INDEX = Qt::UserRole + 4;
void ListItem::setImage(const QPixmap &image)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setData(ITEM_HAS_IMAGE_INDEX, true);
setData(AVATAR_IMAGE_INDEX, image);
+
}
void ListItem::setName(const QString &name)
shortenedText.append("...");
}
- qWarning() << shortenedText;
- qWarning() << textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
- qWarning() << textWidth;
-
return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
}
/**
* @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
{
*/
ListItem();
+ /**
+ * @brief Defines text size.
+ */
enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
/**
- * @brief Returns item's coordinates.
- *
- * @return item's coordinates
- */
- virtual GeoCoordinate coordinates() = 0;
-
- /**
* @brief Returns item's ID.
*
* @return item's ID
*/
virtual bool toggleSelection() = 0;
-
-
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
}
//Draw only text
else {
- painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2, NAME_TOP_MARGIN), name);
+ painter->drawText(itemRect.topLeft() + QPoint(MARGIN*3, NAME_TOP_MARGIN), name);
}
}
{
qDebug() << __PRETTY_FUNCTION__;
+ setAutoFillBackground(false);
+ viewport()->setAutoFillBackground(false);
+
connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(listItemClicked(QListWidgetItem*)));
}
m_listItems.clear();
clear();
+
+ m_previousItem = 0;
}
void ListView::clearUnused(const QStringList &userIDs)
void ListView::listItemClicked(QListWidgetItem *item)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
- ListItem *currentItem = static_cast<ListItem*>(item);
+ ListItem *currentItem = dynamic_cast<ListItem*>(item);
if (currentItem) {
- qWarning() << __PRETTY_FUNCTION__ << "currentItem != 0";
if (m_previousItem == currentItem) {
- qWarning() << __PRETTY_FUNCTION__ << "previousItem == currentItem";
- bool selected = currentItem->toggleSelection();
-
- if (selected)
- ;//emit listItemClicked(currentItem->coordinates());
+ currentItem->toggleSelection();
} else {
- qWarning() << __PRETTY_FUNCTION__ << "previousItem != currentItem";
if (m_previousItem)
m_previousItem->setSelected(false);
currentItem->setSelected(true);
- //emit listItemClicked(currentItem->coordinates());
}
m_previousItem = currentItem;
{
qDebug() << __PRETTY_FUNCTION__;
- return static_cast<ListItem*>(m_listItems.value(userID));
+ return dynamic_cast<ListItem*>(m_listItems.value(userID));
+}
+
+
+ListView::~ListView()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ clearList();
}
*/
ListView(QWidget *parent = 0);
+ ~ListView();
+
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
*/
virtual void listItemClicked(QListWidgetItem *item);
-/******************************************************************************
-* SIGNALS
-******************************************************************************/
-signals:
- /**
- * @brief Signal is emitted when list item is clicked.
- *
- * @param coordinates item's coordinates
- */
- void listItemClicked(const GeoCoordinate &coordinates);
-
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
#include "locationlistitem.h"
-const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
+const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN*2 + IMAGE_WIDTH;
LocationListItem::LocationListItem()
{
void LocationListItem::setLocationData(const Location &location)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_location = location;
QStringList addressComponents = m_location.addressComponents();
addressTail.append(", ");
}
+ clearSubItems();
addSubItem(addressTail, QPixmap(":/res/images/compass.png"));
}
void LocationListItem::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_location.bounds(swBound, neBound);
}
+
+LocationListItem::~LocationListItem()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
#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
*/
QString id() const;
- void bounds(GeoCoordinate &swBound, GeoCoordinate &neBound);
-
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
* DATA MEMBERS
******************************************************************************/
private:
- Location m_location;
- bool m_selected;
+ Location m_location; ///< Location data
};
#endif // LOCATIONLISTITEM_H
LocationListView::LocationListView(QWidget *parent)
: ListView(parent)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
}
void LocationListView::listItemClicked(QListWidgetItem *item)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
ListView::listItemClicked(item);
- LocationListItem *locationItem = static_cast<LocationListItem*>(item);
+ LocationListItem *locationItem = dynamic_cast<LocationListItem*>(item);
if (locationItem) {
- qWarning() << __PRETTY_FUNCTION__ << "locationItem != null";
GeoCoordinate swBound;
GeoCoordinate neBound;
locationItem->bounds(swBound, neBound);
#include "listview.h"
+/**
+* @brief Shows LocationListItems in list view.
+*/
class LocationListView : public ListView
{
Q_OBJECT
public:
+ /**
+ * @brief Constructor.
+ *
+ * @param parent QWidget
+ */
LocationListView(QWidget *parent = 0);
-private slots:
+public slots:
+ /**
+ * @brief Slot for list item clicked.
+ *
+ * @param item QListWidgetItem
+ */
void listItemClicked(QListWidgetItem *item);
signals:
+ /**
+ * @brief Signal is emitted when location item is clicked.
+ *
+ * @param swBound south-west bound in GeoCoorinate
+ * @param neBound north-east bound in GeoCoordinate
+ */
void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
};
connect(m_mapView, SIGNAL(viewResized(QSize)),
m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
- connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+ connect(m_friendsListPanel, SIGNAL(friendItemClicked(GeoCoordinate)),
this, SIGNAL(findFriend(GeoCoordinate)));
connect(this, SIGNAL(friendImageReady(User*)),
../../../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
#include <QtGui>
#include "../../../src/ui/friendlistitem.h"
+#include "../../../src/ui/extendedlistitemstore.h"
#include "../../../src/user/user.h"
#include "../../../src/ui/listcommon.h"
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"));
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)
../../../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
#include <QtGui>
#include "../../../src/ui/friendlistitem.h"
-#include "../../../src/ui/listview.h"
+#include "../../../src/ui/friendlistview.h"
class TestListView: public QObject
{
void takeListItemFromView();
private:
- ListView *listView;
+ FriendListView *friendListView;
User *user1;
User *user2;
User *user3;
void TestListView::cleanupTestCase()
{
- delete listView;
+ delete friendListView;
delete user1;
delete user2;
delete user3;
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"),
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();
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++;
}
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)