ui/listview.h \
ui/listitem.h \
ui/listitemdelegate.h \
- ui/friendlistitemdelegate.h
+ ui/friendlistitemdelegate.h \
+ ui/listcommon.h
QT += network \
webkit
#include "../user/user.h"
#include "imagebutton.h"
#include "../common.h"
-
-const int ITEM_WIDTH = 368;
-const int ICON_HEIGHT = 24; ///< Icon height
-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 MARGIN = 5; ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-
-/**
-* @var NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = ITEM_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH - MARGIN;
+#include "listcommon.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
FriendListItem::FriendListItem()
- : m_expanded(false)
+ : m_selected(false)
, m_user(0)
{
qDebug() << __PRETTY_FUNCTION__;
- setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+ setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
}
void FriendListItem::calculateTextRects()
{
- QPixmap p = QPixmap(10, 10);
+ 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 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);
- qDebug() << m_shortenedStatusText;
-
- int statusTextFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
- statusTextFactor++;
- m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * statusTextFactor);
- int updatedFactor = updatedRect.width() / LABEL_MAX_WIDTH;
- updatedFactor++;
- m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * updatedFactor);
- int locationFactor = locationRect.width() / LABEL_MAX_WIDTH;
- locationFactor++;
- m_locationRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * locationFactor);
-
- qDebug() << statusTextRect;
- qDebug() << updatedRect;
- qDebug() << locationRect;
-
- qDebug() << m_statusTextRect;
- qDebug() << m_updatedRect;
- qDebug() << m_locationRect;
-
- qWarning() << statusTextRect.width() << statusTextRect.height();
- qWarning() << m_statusTextRect.width() << m_statusTextRect.height();
+ m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
+ locationRectFactor - 3) * ICON_HEIGHT);
- m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextFactor + updatedFactor + locationFactor - 3) *
- ICON_HEIGHT);
-
- setData(Qt::SizeHintRole + 1, distanceRect);
+ setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
}
QPointF FriendListItem::coordinates()
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
return m_user->coordinates();
}
QString FriendListItem::id() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return ListItem::id();
}
setId(m_user->userId());
if (!m_user->profileImage().isNull())
- setData(Qt::DecorationRole, m_user->profileImage());
+ setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
QString unit;
double value;
m_user->distance(value, unit);
m_distanceText = QString::number(value) + " " + unit;
- setData(Qt::UserRole + 3, m_distanceText);
+ setData(DISTANCE_TEXT_DISPLAY_INDEX, m_distanceText);
setDistanceIcon(value, unit);
shortenTexts();
void FriendListItem::setDistanceIcon(double value, const QString &unit)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
QPixmap distanceImage;
if ((unit == "m") || (value < WALK_DISTANCE))
else
distanceImage.load(":/res/images/rocket_icon_gray.png");
- qDebug() << __PRETTY_FUNCTION__ << distanceImage.isNull();
-
- setData(Qt::UserRole + 4, distanceImage);
+ setData(DISTANCE_IMAGE_INDEX, distanceImage);
}
void FriendListItem::shortenTexts()
{
qDebug() << __PRETTY_FUNCTION__;
- QPixmap p = QPixmap(10, 10);
-
+ //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();
location.append("...");
}
- int distanceLabelWidth = otherLabelsMetrics.width(m_distanceText) + 5;
+ 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,
m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
- setData(Qt::SizeHintRole + 4, QRect(0, 0, distanceLabelWidth, 24));
-
- qWarning() << m_shortenedStatusText;
-}
-
-QString FriendListItem::elideText(int width, const QString &text)
-{
- QFontMetrics otherLabelsMetrics = QFontMetrics(NOKIA_FONT_SMALL);
- int widthSum = 0;
- QString t = text;
-
- for (int i = 0; i < text.size(); ++i) {
- QChar c = text.at(i);
-
- widthSum += otherLabelsMetrics.width(c);
-
- if (widthSum > width) {
- t.truncate(i - 3);
- t.append("...");
- break;
- }
- }
-
- return t;
+ setData(NAME_DISPLAY_INDEX, m_shortenedName);
}
void FriendListItem::setText(bool expanded)
{
qDebug() << __PRETTY_FUNCTION__;
- setData(Qt::DisplayRole, m_shortenedName);
-
if (expanded) {
- setData(Qt::UserRole, m_user->note());
- setData(Qt::UserRole + 1, m_user->timestamp());
- setData(Qt::UserRole + 2, m_user->address());
+ 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);
- setData(Qt::SizeHintRole + 2, m_statusTextRect);
- setData(Qt::SizeHintRole + 3, m_updatedRect);
- setData(Qt::SizeHintRole + 4, m_locationRect);
}
else {
- setData(Qt::UserRole, m_shortenedStatusText);
- setData(Qt::UserRole + 1, m_shortenedUpdated);
- setData(Qt::UserRole + 2, m_shortenedLocation);
+ setData(STATUS_TEXT_DISPLAY_INDEX, m_shortenedStatusText);
+ setData(LOCATION_DISPLAY_INDEX, m_shortenedLocation);
+ setData(UPDATED_DISPLAY_INDEX, m_shortenedUpdated);
- setData(Qt::SizeHintRole + 2, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
- setData(Qt::SizeHintRole + 3, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
- setData(Qt::SizeHintRole + 4, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
+ 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));
}
}
-void FriendListItem::toggleHeight()
+bool FriendListItem::toggleSelection()
{
- if (m_expanded) {
- m_expanded = false;
- setText(false);
- setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
- }
- else {
- m_expanded = true;
- setText(true);
- setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, m_expandedHeight));
- }
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setSelected(!m_selected);
+ return m_selected;
}
-void FriendListItem::setExpanded(bool expanded)
+void FriendListItem::setSelected(bool selected)
{
- m_expanded = expanded;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_selected = selected;
- if (m_expanded) {
+ if (m_selected) {
setText(true);
- setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, m_expandedHeight));
+ setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
}
else {
setText(false);
- setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+ setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
}
}
*/
class FriendListItem : public ListItem
{
- //Q_OBJECT
public:
/**
*/
FriendListItem();
-
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
*/
void setUserData(User *user);
- void toggleHeight();
- void setExpanded(bool expanded);
+ bool toggleSelection();
+ void setSelected(bool expanded);
void setId(const QString &id);
QString id() const;
*/
void shortenTexts();
- QString elideText(int width, const QString &text);
-
void calculateTextRects();
-//private slots:
-// /**
-// * @brief Slot for find button click
-// */
-// void findButtonClicked();
-
-/******************************************************************************
-* SIGNALS
-******************************************************************************/
-//signals:
-// /**
-// * @brief Signal for finding friend.
-// *
-// * @param coordinates friend's geo coordinates
-// */
-// void findFriend(const QPointF &coordinates);
/******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- bool m_expanded; ///< Item expanded state
+ bool m_selected; ///< Item selected state
QPoint m_mousePosition; ///< Current mouse press position
QRect m_locationRect;
QRect m_statusTextRect;
+/*
+ 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 <QPainter>
#include "friendlistitemdelegate.h"
#include "../common.h"
-
-const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_WIDTH = 368;
-const int ICON_HEIGHT = 24; ///< Icon height
-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 MARGIN = 5; ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-
-/**
-* @var NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
+#include "listcommon.h"
FriendListItemDelegate::FriendListItemDelegate()
{
painter->setPen(COLOR_GRAY);
painter->setFont(NOKIA_FONT_SMALL);
- QString statusText = index.data(Qt::UserRole).toString();
- QString address = index.data(Qt::UserRole + 1).toString();
- QString timestamp = index.data(Qt::UserRole + 2).toString();
- QString distance = index.data(Qt::UserRole + 3).toString();
- QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 4)));
+ 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)));
QRect itemRect = option.rect;
- QPoint distanceIconPoint = QPoint(BACKGROUND_WIDTH - ICON_WIDTH - 15, itemRect.top() + 5);
- QRect distanceRect = index.data(Qt::SizeHintRole + 1).toRect();
- distanceRect.translate(BACKGROUND_WIDTH - distanceRect.width() - 5, itemRect.top() + ICON_HEIGHT + 10);
+ QPoint distanceIconPoint = QPoint(ITEM_WIDTH - ICON_WIDTH - 3*MARGIN, itemRect.top() + MARGIN);
+ QRect distanceRect = index.data(DISTANCE_SIZE_HINT_INDEX).toRect();
+ distanceRect.translate(ITEM_WIDTH - distanceRect.width() - 2*MARGIN,
+ itemRect.top() + ICON_HEIGHT + 2*MARGIN);
painter->drawPixmap(distanceIconPoint, distanceIcon);
painter->drawText(distanceRect, Qt::TextSingleLine, distance);
- QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 15, itemRect.top() + IMAGE_HEIGHT - 10,
- ICON_WIDTH, ICON_HEIGHT);
- QRect statusTextRect = index.data(Qt::SizeHintRole + 2).toRect();
- statusTextRect.translate(envelopeRect.right() + 5, envelopeRect.top());
+ 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() + 2, ICON_WIDTH,
- ICON_HEIGHT);
- QRect locationRect = index.data(Qt::SizeHintRole + 3).toRect();
- locationRect.translate(compassRect.right() + 5, compassRect.top());
+ 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, address);
-
+ painter->drawText(locationRect, Qt::TextWrapAnywhere, location);
- QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + 2, ICON_WIDTH, ICON_HEIGHT);
- QRect timestampRect = index.data(Qt::SizeHintRole + 4).toRect();
- timestampRect.translate(clockRect.right() + 5, clockRect.top());
+ 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(timestampRect, Qt::TextWrapAnywhere, timestamp);
+ painter->drawText(updatedRect, Qt::TextWrapAnywhere, updated);
}
QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
+/*
+ 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 FRIENDLISTITEMDELEGATE_H
#define FRIENDLISTITEMDELEGATE_H
--- /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.
+*/
+
+#ifndef LISTCOMMON_H
+#define LISTCOMMON_H
+
+#include <Qt>
+
+const int ITEM_WIDTH = 368; ///< Item minimum width
+const int ICON_HEIGHT = 24; ///< Icon height
+const int ICON_MARGIN = 2; ///< Icon margin
+const int ICON_WIDTH = 24; ///< Icon width
+const int IMAGE_HEIGHT = 64; ///< Friend image height
+const int IMAGE_WIDTH = 64; ///< Friend image width
+const int ITEM_MIN_HEIGHT = 141;///< Minimum height for item
+const int MARGIN = 5; ///< Text and image margin
+
+/**
+* @var NAME_LABEL_MAX_WIDTH
+*
+* @brief Name label's maximum width
+*/
+const int NAME_LABEL_MAX_WIDTH = ITEM_WIDTH - 3*MARGIN - IMAGE_WIDTH;
+
+/**
+* @var LABEL_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 NAME_DISPLAY_INDEX = Qt::DisplayRole;
+const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
+
+const int ITEM_SIZE_HINT_INDEX = Qt::SizeHintRole;
+const int DISTANCE_SIZE_HINT_INDEX = Qt::SizeHintRole + 1;
+const int STATUS_TEXT_SIZE_HINT_INDEX = Qt::SizeHintRole + 2;
+const int LOCATION_SIZE_HINT_INDEX = Qt::SizeHintRole + 3;
+const int UPDATED_SIZE_HINT_INDEX = Qt::SizeHintRole + 4;
+
+const int STATUS_TEXT_DISPLAY_INDEX = Qt::UserRole;
+const int LOCATION_DISPLAY_INDEX = Qt::UserRole + 1;
+const int UPDATED_DISPLAY_INDEX = Qt::UserRole + 2;
+const int DISTANCE_TEXT_DISPLAY_INDEX = Qt::UserRole + 3;
+const int DISTANCE_IMAGE_INDEX = Qt::UserRole + 4;
+
+#endif // LISTCOMMON_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 <QDebug>
#include "listitem.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.
+*/
+
#ifndef LISTITEM_H
#define LISTITEM_H
QString name() const;
void setImage(const QPixmap &image);
void setName(const QString &neame);
- virtual void toggleHeight() = 0;
- virtual void setExpanded(bool expanded) = 0;
+ virtual bool toggleSelection() = 0;
+ virtual void setSelected(bool selected) = 0;
virtual QString id() const;
virtual void setId(const QString &id);
virtual QPointF coordinates() = 0;
+/*
+ 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 <QPainter>
#include <QDebug>
#include "listitemdelegate.h"
#include "listitem.h"
#include "../common.h"
+#include "listcommon.h"
#include "avatarimage.h"
const int BACKGROUND_BOTTOM_HEIGHT = 15;
const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_WIDTH = 368;
-const int IMAGE_HEIGHT = 64; ///< Friend image height
-const int IMAGE_WIDTH = 64; ///< Friend image width
-const int MARGIN = 5; ///< Icon margin
+const int NAME_TOP_MARGIN = 40;
ListItemDelegate::ListItemDelegate(QWidget *parent) :
QStyledItemDelegate(parent)
{
qDebug() << __PRETTY_FUNCTION__;
- QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
- QString name = index.data(Qt::DisplayRole).toString();
- QSize size = index.data(Qt::SizeHintRole).toSize();
+ QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(AVATAR_IMAGE_INDEX)));
+ QString name = index.data(NAME_DISPLAY_INDEX).toString();
+ QSize size = index.data(ITEM_SIZE_HINT_INDEX).toSize();
QRect itemRect = option.rect;
- QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_WIDTH,
+ QRect topRect = QRect(itemRect.left(), itemRect.top(), ITEM_WIDTH,
BACKGROUND_TOP_HEIGHT);
- QRect middleRect = QRect(itemRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
+ QRect middleRect = QRect(itemRect.left(), topRect.bottom(), ITEM_WIDTH,
size.height() - BACKGROUND_TOP_HEIGHT
- BACKGROUND_BOTTOM_HEIGHT);
- QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
+ QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_WIDTH,
BACKGROUND_BOTTOM_HEIGHT);
painter->drawPixmap(topRect, m_backgroundTopImage);
painter->setPen(Qt::white);
painter->setFont(NOKIA_FONT_NORMAL);
- painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN,
- MARGIN + 35), name);
+ painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN, NAME_TOP_MARGIN),
+ name);
}
QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+/*
+ 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 LISTITEMDELEGATE_H
#define LISTITEMDELEGATE_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 <QDebug>
#include "listitem.h"
if (!m_listItems.contains(key)) {
addItem(item);
m_listItems.insert(key, item);
- qDebug() << __PRETTY_FUNCTION__ << key << " lisattiin";
}
- else
- qDebug() << __PRETTY_FUNCTION__ << key << " ei lisatty";
}
void ListView::addListItemToView(ListItem *item)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
addItem(item);
}
void ListView::clearList()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_listItems.clear();
clear();
-
- qDebug() << __PRETTY_FUNCTION__ << count();
- qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
}
void ListView::clearUnused(const QStringList &userIDs)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
foreach (QString key, m_listItems.keys()) {
if (!userIDs.contains(key)) {
ListItem *item = m_listItems.take(key);
}
}
}
- qDebug() << __PRETTY_FUNCTION__ << count();
- qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
}
void ListView::clearFilter()
{
+ qDebug() << __PRETTY_FUNCTION__;
+
foreach (ListItem *item, m_listItems)
setItemHidden(item, false);
}
bool ListView::contains(const QString &userID)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_listItems.contains(userID);
}
void ListView::filter(const QList<QString> &userIDs)
{
- qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
+ qDebug() << __PRETTY_FUNCTION__;
foreach (ListItem *item, m_listItems) {
if (userIDs.contains(item->id()))
ListItem *ListView::takeListItemFromView(const QString &userID)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
ListItem *item = listItem(userID);
takeItem(row(item));
return item;
void ListView::listItemClicked(QListWidgetItem *item)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
ListItem *currentItem = static_cast<ListItem*>(item);
if (currentItem) {
if (previousItem == currentItem) {
- currentItem->toggleHeight();
- }
- else {
+ bool expanded = currentItem->toggleSelection();
+
+ if (expanded)
+ emit listItemClicked(currentItem->coordinates());
+
+ } else {
if (previousItem)
- previousItem->setExpanded(false);
+ previousItem->setSelected(false);
- currentItem->setExpanded(true);
+ currentItem->setSelected(true);
+ emit listItemClicked(currentItem->coordinates());
}
previousItem = currentItem;
- emit listItemClicked(currentItem->coordinates());
}
}
ListItem *ListView::listItem(const QString &userID)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return static_cast<ListItem*>(m_listItems.value(userID));
}
+/*
+ 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 LISTVIEW_H
#define LISTVIEW_H
CONFIG += qtestlib
-#DEFINES += QT_NO_DEBUG_OUTPUT
+DEFINES += QT_NO_DEBUG_OUTPUT
INCLUDEPATH += . \
../../../src/
HEADERS += ../../../src/ui/listview.h \