Added listcommon.h file.
[situare] / src / ui / friendlistitem.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #ifndef FRIENDLISTITEM_H
23 #define FRIENDLISTITEM_H
24
25 #include <QWidget>
26 #include <QTreeWidgetItem>
27 #include <QListWidgetItem>
28
29 #include "../user/user.h"
30 #include "listitem.h"
31
32 /**
33 * @brief FriendListItem shows friend data in expandable item.
34 *
35 * @class FriendListItem friendlistitem.h "ui/friendlistitem.h"
36 */
37 class FriendListItem : public ListItem
38 {
39
40 public:
41     /**
42     * @brief Construct FriendListItem.
43     *
44     * Initializes layouts and member variables. Sets stylesheet
45     * for this class.
46     * @param parent parent widget
47     */
48     FriendListItem();
49
50 /******************************************************************************
51 * MEMBER FUNCTIONS AND SLOTS
52 ******************************************************************************/
53 public:
54     /**
55     * @brief Set user data for this item.
56     *
57     * @param user User pointer
58     */
59     void setUserData(User *user);
60
61     bool toggleSelection();
62     void setSelected(bool expanded);
63
64     void setId(const QString &id);
65     QString id() const;
66     QPointF coordinates();
67
68 private:
69     /**
70     * @brief Set distance icon.
71     *
72     * Icon is selected by distance.
73     *
74     * @param value distance value
75     * @param unit distance unit
76     */
77     void setDistanceIcon(double value, const QString &unit);
78
79     /**
80     * @brief Set shortened or full-length text to labels.
81     *
82     * @param expanded true if full-length text is set, false otherwise
83     */
84     void setText(bool expanded);
85
86     /**
87     * @brief Set shortened texts from User data.
88     *
89     * Text length is defined by MAXIMUM_CHARS.
90     */
91     void shortenTexts();
92
93     void calculateTextRects();
94
95 /******************************************************************************
96 * DATA MEMBERS
97 ******************************************************************************/
98 private:
99     bool m_selected;                ///< Item selected state
100     QPoint m_mousePosition;         ///< Current mouse press position
101     QRect m_locationRect;
102     QRect m_statusTextRect;
103     QRect m_updatedRect;
104     int m_expandedHeight;
105     QString m_shortenedLocation;    ///< Shortened location text
106     QString m_shortenedName;        ///< Shortened name text
107     QString m_shortenedStatusText;  ///< Shortened status text
108     QString m_shortenedUpdated;     ///< Shortened updated text
109     QString m_distanceText;         ///< Distance text
110     User *m_user;                   ///< User data
111 };
112
113 #endif // FRIENDLISTITEM_H