860bd7ee949318d84645fa07f267d50f5aabc740
[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
33 /**
34 * @brief FriendListItem shows friend data in expandable item.
35 *
36 * @class FriendListItem friendlistitem.h "ui/friendlistitem.h"
37 */
38 class FriendListItem : public QWidget
39 {
40     Q_OBJECT
41
42 public:
43     /**
44     * @brief Construct FriendListItem.
45     *
46     * Initializes layouts and member variables. Sets stylesheet
47     * for this class.
48     * @param parent parent widget
49     */
50     FriendListItem(QWidget *parent = 0);
51
52 /*******************************************************************************
53  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
54  ******************************************************************************/
55 protected:
56     /**
57     * @brief Set current mouse position to mouse event position.
58     *
59     * @param event QMouseEvent mouse press event
60     */
61     void mousePressEvent(QMouseEvent *event);
62
63     /**
64     * @brief Call toggleHeight if mouse position is unchanged.
65     *
66     * Check if current mouse position is same as mouse release position.
67     * @param event QMouseEvent mouse release event
68     */
69     void mouseReleaseEvent(QMouseEvent *event);
70
71     /**
72     * @brief Draws stylesheet used in this class.
73     *
74     * @param QPaintEvent unused
75     */
76     void paintEvent(QPaintEvent *);
77
78 /******************************************************************************
79 * MEMBER FUNCTIONS AND SLOTS
80 ******************************************************************************/
81 public:
82     /**
83     * @brief Set data for this item.
84     *
85     * @param user User object
86     */
87     void setData(const User &user);
88
89 private:
90     /**
91     * @brief Set shortened texts from User data.
92     *
93     * Text length is defined by MAXIMUM_CHARS.
94     */
95     void shortenTexts();
96
97     /**
98     * @brief Toggle item height.
99     */
100     void toggleHeight();
101
102 /******************************************************************************
103 * DATA MEMBERS
104 ******************************************************************************/
105 private:
106     static const int ICON_MARGIN = 5;   ///< Icon margin
107     static const int IMAGE_HEIGHT = 60; ///< Friend image height
108     static const int IMAGE_WIDTH = 60;  ///< Friend image width
109
110     static const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
111     static const int ITEM_MAX_WIDTH = 368;  ///< Maximum width for item
112     static const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
113     static const int ITEM_MIN_WIDTH = 368;  ///< Minimum width for item
114
115     static const int MAXIMUM_CHARS = 32;    ///< Maximum character count for labels
116
117     bool m_expanded;                ///< Item expanded state
118     QLabel *m_imageLabel;           ///< Image label
119     QWidget *m_infoWidget;          ///< Info widget: updated, status text, location
120     QLabel *m_locationLabel;        ///< Location label
121     QPoint m_mousePosition;         ///< Current mouse press position
122     QLabel *m_nameLabel;            ///< Name label
123     QString m_shortenedLocation;    ///< Shortened location text
124     QString m_shortenedName;        ///< Shortened name text
125     QString m_shortenedStatusText;  ///< Shortened status text
126     QString m_shortenedUpdated;     ///< Shortened updated text
127     QLabel *m_statusTextLabel;      ///< Status text label
128     QLabel *m_updatedLabel;         ///< Updated label
129
130     User m_user;                    ///< User data
131 };
132
133 const QString BACKGROUND_PATH = ":/res/images/list_item.png";   ///< Background image path
134 const QString CLOCK_PATH = ":/res/images/clock.png";        ///< Clock image path
135 const QString ENVELOPE_PATH = ":/res/images/envelope.png";  ///< Envelope image path
136 const QString COMPASS_PATH = ":/res/images/compass.png";    ///< Compass image path
137
138 #endif // FRIENDLISTITEM_H