ui/friendlistitemdelegate.cpp \
ui/searchdialog.cpp \
ui/locationlistitem.cpp \
- ui/extendedlistitem.cpp
+ ui/extendedlistitem.cpp \
+ ui/extendedlistitemstore.cpp \
+ ui/extendedlistitemdelegate.cpp
HEADERS += application.h \
common.h \
engine/engine.h \
ui/listcommon.h \
ui/searchdialog.h \
ui/locationlistitem.h \
- ui/extendedlistitem.h
+ ui/extendedlistitem.h \
+ ui/extendedlistitemstore.h \
+ ui/extendedlistitemdelegate.h
QT += network \
webkit
#include <QDebug>
#include <QFontMetrics>
+#include <QPainter>
#include "../common.h"
#include "listcommon.h"
+#include "extendedlistitemstore.h"
-const int ROW_HEIGHT = ICON_HEIGHT;
+#include "extendedlistitem.h"
-ExtendedListItem::ExtendedListItem()
- : m_textWidth(0)
-{
- qDebug() << __PRETTY_FUNCTION__;
-}
-
-void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- QRect itemRect = caclulateTextRect(text);
- QString shortenedText = shortenText(text);
-
- m_subItems
-}
-
-QRect ExtendedListItem::calculateTextRect(const QString &text)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics smallFontMetrics = painter.fontMetrics();
-
- QRect textRect = smallFontMetrics.boundingRect(text);
-
- int textRectFactor = textRect.width() / m_width;
- statusTextRectFactor++;
- QRect expandedTextRect = QRect(0, 0, m_width, ROW_HEIGHT * textRectFactor);
-
- m_normalHeight += ROW_HEIGHT;
- m_expandedHeight += expandedTextRect.height();
-}
-
-void ExtendedListItem::calculateTextRects()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- //Dummy value to get painter font metrics.
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics smallFontMetrics = painter.fontMetrics();
-
- QRect distanceRect = smallFontMetrics.boundingRect(m_distanceText);
- QRect statusTextRect = smallFontMetrics.boundingRect(m_user->note());
- QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
- QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
-
- int statusTextRectFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
- statusTextRectFactor++;
- m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
- int updatedRectFactor = updatedRect.width() / LABEL_MAX_WIDTH;
- updatedRectFactor++;
- m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
- int locationRectFactor = locationRect.width() / LABEL_MAX_WIDTH;
- locationRectFactor++;
- m_locationRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * locationRectFactor);
-
- m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
- locationRectFactor - RECTS_MINIMUM_FACTOR_SUM)
- * ICON_HEIGHT);
-
- setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
-}
-
-GeoCoordinate ExtendedListItem::coordinates()
-{
- qDebug() << __PRETTY_FUNCTION__;
+const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT;
- return m_user->coordinates();
-}
-
-QString ExtendedListItem::id() const
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- return m_user->userId();
-}
-
-void ExtendedListItem::setTextWidth(int width)
-{
- m_textWidth = width;
-}
-
-void ExtendedListItem::setUserData(User *user)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if(user) {
- m_user = user;
-
- if (!m_user->profileImage().isNull())
- setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
-
- QString unit;
- double value;
- m_user->distance(value, unit);
- m_distanceText = QString::number(value) + " " + unit;
- setData(DISTANCE_TEXT_DISPLAY_INDEX, m_distanceText);
- setDistanceIcon(value, unit);
-
- shortenTexts();
- calculateTextRects();
- setText(false);
- }
-}
+ExtendedListItem::ExtendedListItem()
+ : m_selected(false),
+ m_expandedHeight(ITEM_MIN_HEIGHT),
+ m_normalHeight(ITEM_MIN_HEIGHT),
+ m_subItemTextWidth(0)
-void ExtendedListItem::setAvatarImage(const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
- if(!image.isNull())
- setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
+ setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+ m_subItemStoreList = new QList<ExtendedListItemStore *>();
+ setData(SUBITEM_STORE_INDEX, qVariantFromValue((void *) m_subItemStoreList));
}
-void ExtendedListItem::setDistanceIcon(double value, const QString &unit)
+void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
{
qDebug() << __PRETTY_FUNCTION__;
- QPixmap distanceImage;
-
- if ((unit == "m") || (value < WALK_DISTANCE))
- distanceImage.load(":/res/images/walk_icon_gray.png");
- else if (value < CAR_DISTANCE)
- distanceImage.load(":/res/images/car_icon_gray.png");
- else if (value < AEROPLANE_DISTANCE)
- distanceImage.load(":/res/images/aeroplane_icon_gray.png");
- else
- distanceImage.load(":/res/images/rocket_icon_gray.png");
+ ExtendedListItemStore *itemStore = new ExtendedListItemStore(text);
+ itemStore->setIcon(icon);
+ itemStore->setShortenedText(shortenText(text, m_subItemTextWidth, ListItem::TEXT_SIZE_SMALL));
+ itemStore->setTextRect(calculateExpandedTextRect(text));
- setData(DISTANCE_IMAGE_INDEX, distanceImage);
+ m_subItemStoreList->append(itemStore);
}
-void ExtendedListItem::shortenTexts()
+QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
{
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("...");
- }
+ 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();
- 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);
+ setSize(QSize(ITEM_WIDTH, m_normalHeight));
- setData(NAME_DISPLAY_INDEX, m_shortenedName);
+ return expandedTextRect;
}
-void ExtendedListItem::setText(bool expanded)
+void ExtendedListItem::setSubitemTextWidth(int width)
{
- qDebug() << __PRETTY_FUNCTION__;
-
- if (expanded) {
- setData(STATUS_TEXT_DISPLAY_INDEX, m_user->note());
- setData(LOCATION_DISPLAY_INDEX, m_user->address());
- setData(UPDATED_DISPLAY_INDEX, m_user->timestamp());
-
- setData(STATUS_TEXT_SIZE_HINT_INDEX, m_statusTextRect);
- setData(LOCATION_SIZE_HINT_INDEX, m_locationRect);
- setData(UPDATED_SIZE_HINT_INDEX, m_updatedRect);
- } else {
- setData(STATUS_TEXT_DISPLAY_INDEX, m_shortenedStatusText);
- setData(LOCATION_DISPLAY_INDEX, m_shortenedLocation);
- setData(UPDATED_DISPLAY_INDEX, m_shortenedUpdated);
-
- setData(STATUS_TEXT_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
- setData(LOCATION_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
- setData(UPDATED_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
- }
+ m_subItemTextWidth = width;
}
bool ExtendedListItem::toggleSelection()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
setSelected(!m_selected);
return m_selected;
void ExtendedListItem::setSelected(bool selected)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
m_selected = selected;
+ setData(ITEM_EXPANDED_INDEX, m_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));
+ setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
}
}
#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:
- int m_textWidth;
+ 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 "sidepanel.h"
#include "../routing/location.h"
#include "locationlistitem.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();
m_locationListView = new ListView(this);
m_locationListView->setAutoFillBackground(false);
m_locationListView->viewport()->setAutoFillBackground(false);
- m_locationListView->setItemDelegate(m_friendListItemDelegate);
+ m_locationListView->setItemDelegate(new ExtendedListItemDelegate());
- friendListLayout->addWidget(m_friendListView);
+ //friendListLayout->addWidget(m_friendListView);
+ friendListLayout->addWidget(m_locationListView);
m_panelVBox->addLayout(friendListLayout);
- m_panelVBox->addWidget(m_locationListView);
connect(m_friendListView, SIGNAL(listItemClicked(GeoCoordinate)),
this, SIGNAL(findFriend(GeoCoordinate)));
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->setPen(Qt::white);
painter->setFont(NOKIA_FONT_NORMAL);
- //Image is set
+ //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, NAME_TOP_MARGIN), name);
+ painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2, NAME_TOP_MARGIN), name);
}
}
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());
} else {
+ qWarning() << __PRETTY_FUNCTION__ << "previousItem != currentItem";
if (m_previousItem)
m_previousItem->setSelected(false);
#include "locationlistitem.h"
+const int LOCATION_SUBITEM_TEXT_MAX_WIDTH = SUBITEM_TEXT_MAX_WIDTH + MARGIN + IMAGE_WIDTH;
+
LocationListItem::LocationListItem()
- : m_selected(false)
{
qDebug() << __PRETTY_FUNCTION__;
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-}
-
-void LocationListItem::calculateTextRects()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- //Dummy value to get painter font metrics.
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics smallFontMetrics = painter.fontMetrics();
-
- QRect statusTextRect = smallFontMetrics.boundingRect(m_user->note());
- QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
- QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
-
- int statusTextRectFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
- statusTextRectFactor++;
- m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
- int updatedRectFactor = updatedRect.width() / LABEL_MAX_WIDTH;
- updatedRectFactor++;
- m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
- int locationRectFactor = locationRect.width() / LABEL_MAX_WIDTH;
- locationRectFactor++;
- m_locationRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * locationRectFactor);
-
- m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
- locationRectFactor - RECTS_MINIMUM_FACTOR_SUM)
- * ICON_HEIGHT);
-
- setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
+ setSubitemTextWidth(LOCATION_SUBITEM_TEXT_MAX_WIDTH);
+ addSubItem(QString("Hei pitka teksti hep hep hep hep hep hep hep hep hep hep hep hep"),
+ QPixmap(":/res/images/clock.png"));
+ addSubItem(QString("Hep"));
+ addSubItem(QString("Jep"), QPixmap(":/res/images/compass.png"));
}
GeoCoordinate LocationListItem::coordinates()
return QString();
}
-void LocationListItem::setSelected(bool selected)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_selected = selected;
-
- if (m_selected) {
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, 300));
- } else {
- setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
- }
-}
-
void LocationListItem::setLocationData(const Location &location)
{
m_location = location;
- setData(NAME_DISPLAY_INDEX, m_location.formattedAddress());
-}
-
-bool LocationListItem::toggleSelection()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- setSelected(!m_selected);
- return m_selected;
+ setName(shortenText("blaah bavlsdfasdfhldsaf dsafldsaf ldsa lfadsl fl sadf",
+ ITEM_WIDTH - 3*MARGIN, ListItem::TEXT_SIZE_NORMAL));
}
#ifndef LOCATIONLISTITEM_H
#define LOCATIONLISTITEM_H
-#include "listitem.h"
+#include "extendedlistitem.h"
#include "../routing/location.h"
-class LocationListItem : public ListItem
+class LocationListItem : public ExtendedListItem
{
public:
LocationListItem();
*/
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
******************************************************************************/