Re-factored the source to use the new coordinate classes
[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
31 class QLabel;
32 class ImageButton;
33
34 /**
35 * @brief FriendListItem shows friend data in expandable item.
36 *
37 * @class FriendListItem friendlistitem.h "ui/friendlistitem.h"
38 */
39 class FriendListItem : public QWidget
40 {
41     Q_OBJECT
42
43 public:
44     /**
45     * @brief Construct FriendListItem.
46     *
47     * Initializes layouts and member variables. Sets stylesheet
48     * for this class.
49     * @param parent parent widget
50     */
51     FriendListItem(QWidget *parent = 0);
52
53 /*******************************************************************************
54  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
55  ******************************************************************************/
56 protected:
57     /**
58     * @brief Set current mouse position to mouse event position.
59     *
60     * @param event QMouseEvent mouse press event
61     */
62     void mousePressEvent(QMouseEvent *event);
63
64     /**
65     * @brief Call toggleHeight if mouse position is unchanged.
66     *
67     * Check if current mouse position is same as mouse release position.
68     * @param event QMouseEvent mouse release event
69     */
70     void mouseReleaseEvent(QMouseEvent *event);
71
72     /**
73     * @brief Draws stylesheet used in this class.
74     *
75     * @param event QPaintEvent
76     */
77     void paintEvent(QPaintEvent *event);
78
79 /******************************************************************************
80 * MEMBER FUNCTIONS AND SLOTS
81 ******************************************************************************/
82 public:
83     /**
84     * @brief Set data for this item.
85     *
86     * @param user User pointer
87     */
88     void setData(User *user);
89
90     /**
91     * @brief Sets avatar image for this item.
92     *
93     * @param image image
94     */
95     void setAvatarImage(const QPixmap &image);
96
97 private:
98     /**
99     * @brief Set distance icon.
100     *
101     * Icon is selected by distance.
102     *
103     * @param value distance value
104     * @param unit distance unit
105     */
106     void setDistanceIcon(double value, const QString &unit);
107
108     /**
109     * @brief Set shortened or full-length text to labels.
110     *
111     * @param expanded true if full-length text is set, false otherwise
112     */
113     void setText(bool expanded);
114
115     /**
116     * @brief Set shortened texts from User data.
117     *
118     * Text length is defined by MAXIMUM_CHARS.
119     */
120     void shortenTexts();
121
122 private slots:
123     /**
124     * @brief Slot for find button click
125     */
126     void findButtonClicked();
127
128 /******************************************************************************
129 * SIGNALS
130 ******************************************************************************/
131 signals:
132     /**
133     * @brief Signal for finding friend.
134     *
135     * @param coordinates friend's coordinates
136     */
137     void findFriend(const GeoCoordinate &coordinates);
138
139 /******************************************************************************
140 * DATA MEMBERS
141 ******************************************************************************/
142 private:
143     QPixmap m_backgroundTopImage;   ///< Top background image
144     QPixmap m_backgroundMiddleImage;   ///< Middle background image
145     QPixmap m_backgroundBottomImage;   ///< Bottom background image
146     bool m_expanded;                ///< Item expanded state
147     QLabel *m_distanceImageLabel;   ///< Distance image for friend label
148     QLabel *m_distanceTextLabel;    ///< Distance text for friend label
149     ImageButton *m_findButton;      ///< Friend find button
150     QLabel *m_locationLabel;        ///< Location label
151     QPoint m_mousePosition;         ///< Current mouse press position
152     QLabel *m_nameLabel;            ///< Name label
153     QString m_shortenedLocation;    ///< Shortened location text
154     QString m_shortenedName;        ///< Shortened name text
155     QString m_shortenedStatusText;  ///< Shortened status text
156     QString m_shortenedUpdated;     ///< Shortened updated text
157     QLabel *m_statusTextLabel;      ///< Status text label
158     QLabel *m_updatedLabel;         ///< Updated label
159     User *m_user;                   ///< User data
160 };
161
162 #endif // FRIENDLISTITEM_H