7c6e320477bf473afa5a9002fc74ec531c85af42
[situare] / src / ui / listitem.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 LISTITEM_H
23 #define LISTITEM_H
24
25 #include <QListWidgetItem>
26
27 /**
28 * @brief Base class for list items.
29 *
30 * Stores item's name and image and includes method to shorten texts.
31 *
32 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
33 */
34 class ListItem : public QListWidgetItem
35 {
36
37 public:
38     /**
39     * @brief Constructor.
40     */
41     ListItem();
42
43     /**
44     * @brief Defines text size.
45     */
46     enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
47
48 /******************************************************************************
49 * MEMBER FUNCTIONS AND SLOTS
50 ******************************************************************************/
51     /**
52     * @brief Returns item's title.
53     *
54     * @return item's title
55     */
56     QString title() const;
57
58     /**
59     * @brief Sets item's image.
60     *
61     * @param image QPixmap
62     */
63     void setImage(const QPixmap &image);
64
65     /**
66     * @brief Sets item's title.
67     *
68     * @param name item's title
69     */
70     void setTitle(const QString &name);
71
72     /**
73     * @brief Sets item selected.
74     *
75     * @param selected true if selected, false otherwise
76     */
77     virtual void setSelected(bool selected) = 0;
78
79     /**
80     * @brief Sets item size.
81     *
82     * @param size item size
83     */
84     void setSize(const QSize &size);
85
86     /**
87     * @brief Shortens text defined by text width.
88     *
89     * @param text text to be shortened
90     * @param textWidth the width the text can use
91     * @param textSize which text size to use
92     * @return shortened text
93     */
94     QString shortenText(const QString &text, int textWidth, TextSize textSize);
95
96     /**
97     * @brief Toggles selection.
98     *
99     * @return true if selection was toggled, false otherwise
100     */
101     virtual bool toggleSelection() = 0;
102
103 /*******************************************************************************
104  * DATA MEMBERS
105  ******************************************************************************/
106 private:
107     QPixmap m_image;    ///< Item's image
108     QString m_name;     ///< Item's name
109 };
110
111 #endif // LISTITEM_H