Added missing comments to list classes.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Jul 2010 06:57:14 +0000 (09:57 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Jul 2010 06:57:14 +0000 (09:57 +0300)
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistitemdelegate.h
src/ui/friendlistpanel.cpp
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listitemdelegate.cpp
src/ui/listitemdelegate.h
src/ui/listview.cpp
src/ui/listview.h

index 1be6a57..b81899f 100644 (file)
@@ -88,18 +88,11 @@ QPointF FriendListItem::coordinates()
     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)
@@ -109,8 +102,6 @@ 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());
 
index 07962bd..0b4e030 100644 (file)
 #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
 ******************************************************************************/
@@ -58,15 +88,16 @@ public:
     */
     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.
@@ -77,36 +108,37 @@ private:
     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
 };
 
index 1e07a1c..fa8e1dc 100644 (file)
 
 #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
index 90005d2..a99a588 100644 (file)
@@ -84,7 +84,9 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
             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);
index 16e397a..6bd4790 100644 (file)
@@ -24,8 +24,6 @@
 #include "listitem.h"
 
 ListItem::ListItem()
-    : m_expanded(false),
-      m_id(QString(""))
 {
     qDebug() << __PRETTY_FUNCTION__;
 }
@@ -55,13 +53,3 @@ void ListItem::setName(const QString &name)
 
     m_name = name;
 }
-
-void ListItem::setId(const QString &id)
-{
-    m_id = id;
-}
-
-QString ListItem::id() const
-{
-    return m_id;
-}
index f05f67d..4e70d74 100644 (file)
 
 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
index ae93581..98608ec 100644 (file)
@@ -77,6 +77,8 @@ QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    Q_UNUSED(option);
+
     return index.data(Qt::SizeHintRole).toSize();
 
 }
index f7dbceb..e35a2d5 100644 (file)
 
 #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
index ac3bd75..2df8fad 100644 (file)
@@ -79,6 +79,9 @@ void ListView::clearFilter()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    if (previousItem)
+        previousItem->setSelected(false);
+
     foreach (ListItem *item, m_listItems)
         setItemHidden(item, false);
 }
@@ -120,9 +123,9 @@ void ListView::listItemClicked(QListWidgetItem *item)
     if (currentItem) {
 
         if (previousItem == currentItem) {
-            bool expanded = currentItem->toggleSelection();
+            bool selected = currentItem->toggleSelection();
 
-            if (expanded)
+            if (selected)
                 emit listItemClicked(currentItem->coordinates());
 
         } else {
@@ -134,7 +137,6 @@ void ListView::listItemClicked(QListWidgetItem *item)
         }
 
         previousItem = currentItem;
-
     }
 }
 
index 3eab7a2..676e776 100644 (file)
 
 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.
     */
@@ -60,60 +69,77 @@ public:
     /**
     * @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