return m_user->coordinates();
}
-void FriendListItem::setId(const QString &id)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- ListItem::setId(id);
-}
-
QString FriendListItem::id() const
{
qDebug() << __PRETTY_FUNCTION__;
- return ListItem::id();
+ return m_user->userId();
}
void FriendListItem::setUserData(User *user)
if(user) {
m_user = user;
- setId(m_user->userId());
-
if (!m_user->profileImage().isNull())
setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
#include "listitem.h"
/**
-* @brief FriendListItem shows friend data in expandable item.
+* @brief Stores friend's data.
*
-* @class FriendListItem friendlistitem.h "ui/friendlistitem.h"
+* Calculates shortened texts from user data and rects from user data.
+* Rects are used to calculate text field's sizes. Class inherits ListItem.
*/
class FriendListItem : public ListItem
{
public:
/**
- * @brief Construct FriendListItem.
+ * @brief Constructor.
*
- * Initializes layouts and member variables. Sets stylesheet
- * for this class.
- * @param parent parent widget
+ * Sets default size hint for item.
*/
FriendListItem();
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+ /**
+ * @brief Returns item's coordinates.
+ *
+ * @return item's coordinates
+ */
+ QPointF coordinates();
+
+ /**
+ * @brief Returns item's ID.
+ *
+ * @return item's ID
+ */
+ QString id() const;
+
+ /**
+ * @brief Sets item selected.
+ *
+ * @param selected true if selected, false otherwise
+ */
+ void setSelected(bool expanded);
+
+ /**
+ * @brief Toggles selection.
+ *
+ * @return true if selection was toggled, false otherwise
+ */
+ bool toggleSelection();
+
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
*/
void setUserData(User *user);
- bool toggleSelection();
- void setSelected(bool expanded);
-
- void setId(const QString &id);
- QString id() const;
- QPointF coordinates();
-
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 Set shortened or full-length text to labels.
+ * @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 Set shortened texts from User data.
+ * @brief Calculates shortened texts from User data.
*
- * Text length is defined by MAXIMUM_CHARS.
+ * Text length is defined by NAME_LABEL_MAX_WIDTH and LABEL_MAX_WIDTH.
*/
void shortenTexts();
- void calculateTextRects();
-
/******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
bool m_selected; ///< Item selected state
- QPoint m_mousePosition; ///< Current mouse press position
- QRect m_locationRect;
- QRect m_statusTextRect;
- QRect m_updatedRect;
- int m_expandedHeight;
+ 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_shortenedName; ///< Shortened name text
QString m_shortenedStatusText; ///< Shortened status text
QString m_shortenedUpdated; ///< Shortened updated text
- QString m_distanceText; ///< Distance text
+
User *m_user; ///< User data
};
#include "listitemdelegate.h"
+/**
+* @brief Displays FriendListItem.
+*
+* Class is used to display FriendListItem data.
+*/
class FriendListItemDelegate : public ListItemDelegate
{
public:
+ /**
+ * @brief Constructor.
+ *
+ * Loads clock, compass and envelope images' pixmap.
+ */
FriendListItemDelegate();
+/*******************************************************************************
+ * 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;
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
QPixmap m_clockImage; ///< Top background image
QPixmap m_compassImage; ///< Middle background image
m_friendListView->addListItem(user->userId(), item);
}
else {
- item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(user->userId()));
+ item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
+ user->userId()));
+
if (item) {
item->setUserData(user);
m_friendListView->addListItemToView(item);
#include "listitem.h"
ListItem::ListItem()
- : m_expanded(false),
- m_id(QString(""))
{
qDebug() << __PRETTY_FUNCTION__;
}
m_name = name;
}
-
-void ListItem::setId(const QString &id)
-{
- m_id = id;
-}
-
-QString ListItem::id() const
-{
- return m_id;
-}
class User;
+/**
+* @brief Base class for list items.
+*
+* Stores item's name and image. Defines methods that sub
+* classes have to implement.
+*/
class ListItem : public QListWidgetItem
{
public:
+ /**
+ * @brief Constructor.
+ */
ListItem();
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+ /**
+ * @brief Returns item's ID.
+ *
+ * @return item's ID
+ */
+ virtual QString id() const = 0;
+
+ /**
+ * @brief Returns item's image.
+ *
+ * @return image's pixmap
+ */
QPixmap image() const;
+
+ /**
+ * @brief Returns item's name.
+ *
+ * @return item's name
+ */
QString name() const;
+
+ /**
+ * @brief Sets item's image.
+ *
+ * @param image QPixmap
+ */
void setImage(const QPixmap &image);
- void setName(const QString &neame);
- virtual bool toggleSelection() = 0;
+
+ /**
+ * @brief Sets item's name.
+ *
+ * @param name item's name
+ */
+ void setName(const QString &name);
+
+ /**
+ * @brief Sets item selected.
+ *
+ * @param selected true if selected, false otherwise
+ */
virtual void setSelected(bool selected) = 0;
- virtual QString id() const;
- virtual void setId(const QString &id);
+
+ /**
+ * @brief Toggles selection.
+ *
+ * @return true if selection was toggled, false otherwise
+ */
+ virtual bool toggleSelection() = 0;
+
+ /**
+ * @brief Returns item's coordinates.
+ *
+ * @return item's coordinates
+ */
virtual QPointF coordinates() = 0;
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
- bool m_expanded;
- int m_height;
- QPixmap m_image;
- QString m_name;
- QString m_id;
+ QPixmap m_image; ///< Item's image
+ QString m_name; ///< Item's name
};
#endif // LISTITEM_H
{
qDebug() << __PRETTY_FUNCTION__;
+ Q_UNUSED(option);
+
return index.data(Qt::SizeHintRole).toSize();
}
#include <QStyledItemDelegate>
+/**
+* @brief Displays ListItem.
+*
+* Class is used to display ListItem data.
+*/
class ListItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
+ /**
+ * @brief Constructor.
+ *
+ * Loads background image pixmaps.
+ * @param parent QWidget
+ */
ListItemDelegate(QWidget *parent = 0);
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+ /**
+ * @brief Draws ListItem data.
+ *
+ * Draws item's background, image and name.
+ * @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_backgroundTopImage; ///< Top background image
QPixmap m_backgroundMiddleImage; ///< Middle background image
{
qDebug() << __PRETTY_FUNCTION__;
+ if (previousItem)
+ previousItem->setSelected(false);
+
foreach (ListItem *item, m_listItems)
setItemHidden(item, false);
}
if (currentItem) {
if (previousItem == currentItem) {
- bool expanded = currentItem->toggleSelection();
+ bool selected = currentItem->toggleSelection();
- if (expanded)
+ if (selected)
emit listItemClicked(currentItem->coordinates());
} else {
}
previousItem = currentItem;
-
}
}
class ListItem;
+/**
+* @brief View for ListItems.
+*
+* ListView is used to show ListItems in list view. Items can be added, removed or
+* filtered.
+*/
class ListView : public QListWidget
{
Q_OBJECT
public:
ListView(QWidget *parent = 0);
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
public:
/**
- * @brief Add widget to view and widget list.
+ * @brief Add item to view and item list.
*
* @param key user ID
- * @param widget widget to add to list
+ * @param item item to add to view and list
*/
void addListItem(const QString &key, ListItem *item);
/**
- * @brief Adds widget to view.
+ * @brief Adds item to view.
*
* @param item FriendListItem
*/
void addListItemToView(ListItem *item);
/**
- * @brief Clear unused widgets from view.
+ * @brief Clear unused items from view.
*
- * Clears items which are not in user ID's list from the view and widget list.
+ * Clears items which are not in user ID's list from the view and items list.
*
* @param userIDs list of new user ID's.
*/
/**
* @brief Clears filtering from list.
*
- * Calls show to all widgets.
+ * Shows all items.
*/
void clearFilter();
+ /**
+ * @brief Clears list.
+ *
+ * Items are removed from view and item list.
+ */
void clearList();
/**
- * @brief Checks if view contains widget with userID.
+ * @brief Checks if view contains item with userID.
*
* @param userID user's ID
- * @return true if view contains widget, false otherwise
+ * @return true if view contains item, false otherwise
*/
bool contains(const QString &userID);
/**
* @brief Sets filter to list.
*
- * Hide all widgets that are not in the userIDs list.
+ * Hide all items that are not in the userIDs list.
*
- * @param userIDs user ID's to widgets that are shown
+ * @param userIDs user ID's to items that are shown
*/
void filter(const QList<QString> &userIDs);
/**
- * @brief Takes widget from view.
+ * @brief Takes item from view.
*
- * Widget is not deleted.
+ * Item is not deleted.
*
* @param userID user's ID
- * @return FriendListItem
+ * @return ListItem
*/
ListItem *takeListItemFromView(const QString &userID);
/**
- * @brief Returns FriendListItem with userID.
+ * @brief Returns ListItem with userID.
*
* @param userID user's ID
- * @return FriendListItem
+ * @return ListItem
*/
ListItem *listItem(const QString &userID);
-signals:
- void listItemClicked(const QString &id);
- void listItemClicked(const QPointF &coordinates);
-
-public slots:
-
private slots:
-
+ /**
+ * @brief Slot for list item clicked.
+ *
+ * Toggles items selection state and emits listItemClicked signal.
+ */
void listItemClicked(QListWidgetItem *item);
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
+signals:
+ /**
+ * @brief Signal is emitted when list item is clicked.
+ *
+ * @param coordinates item's coordinates
+ */
+ void listItemClicked(const QPointF &coordinates);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
- ListItem *previousItem;
- QHash<QString, ListItem *> m_listItems; ///< List of items in this view. Key = user ID
+ ListItem *previousItem; ///< Previously selected item
+ QHash<QString, ListItem *> m_listItems; ///< List of items in this view. Key = user ID
};
#endif // LISTVIEW_H