f65c0bf2cd87c6c50ce5fe623ea65df2783ea519
[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     //Q_OBJECT
40
41 public:
42     /**
43     * @brief Construct FriendListItem.
44     *
45     * Initializes layouts and member variables. Sets stylesheet
46     * for this class.
47     * @param parent parent widget
48     */
49     FriendListItem();
50
51
52 /******************************************************************************
53 * MEMBER FUNCTIONS AND SLOTS
54 ******************************************************************************/
55 public:
56     /**
57     * @brief Set user data for this item.
58     *
59     * @param user User pointer
60     */
61     void setUserData(User *user);
62
63     void toggleHeight();
64     void setExpanded(bool expanded);
65
66     void setId(const QString &id);
67     QString id() const;
68     QPointF coordinates();
69
70 private:
71     /**
72     * @brief Set distance icon.
73     *
74     * Icon is selected by distance.
75     *
76     * @param value distance value
77     * @param unit distance unit
78     */
79     void setDistanceIcon(double value, const QString &unit);
80
81     /**
82     * @brief Set shortened or full-length text to labels.
83     *
84     * @param expanded true if full-length text is set, false otherwise
85     */
86     void setText(bool expanded);
87
88     /**
89     * @brief Set shortened texts from User data.
90     *
91     * Text length is defined by MAXIMUM_CHARS.
92     */
93     void shortenTexts();
94
95     QString elideText(int width, const QString &text);
96
97     void calculateTextRects();
98 //private slots:
99 //    /**
100 //    * @brief Slot for find button click
101 //    */
102 //    void findButtonClicked();
103
104 /******************************************************************************
105 * SIGNALS
106 ******************************************************************************/
107 //signals:
108 //    /**
109 //    * @brief Signal for finding friend.
110 //    *
111 //    * @param coordinates friend's geo coordinates
112 //    */
113 //    void findFriend(const QPointF &coordinates);
114
115 /******************************************************************************
116 * DATA MEMBERS
117 ******************************************************************************/
118 private:
119     bool m_expanded;                ///< Item expanded state
120     QPoint m_mousePosition;         ///< Current mouse press position
121     QRect m_locationRect;
122     QRect m_statusTextRect;
123     QRect m_updatedRect;
124     int m_expandedHeight;
125     QString m_shortenedLocation;    ///< Shortened location text
126     QString m_shortenedName;        ///< Shortened name text
127     QString m_shortenedStatusText;  ///< Shortened status text
128     QString m_shortenedUpdated;     ///< Shortened updated text
129     QString m_distanceText;         ///< Distance text
130     User *m_user;                   ///< User data
131 };
132
133 #endif // FRIENDLISTITEM_H