cf5996151704828cd68b46115f1042817e167676
[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(QListWidget *parent = 0, int type = Type);
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 public:
52     /**
53     * @brief Sets item's image.
54     *
55     * @param image QPixmap
56     */
57     void setImage(const QPixmap &image);
58
59     /**
60     * @brief Sets item's title.
61     *
62     * @param name item's title
63     */
64     void setTitle(const QString &name);
65
66     /**
67     * @brief Sets item selected.
68     *
69     * @param selected true if selected, false otherwise
70     */
71     virtual void setSelected(bool selected) = 0;
72
73     /**
74     * @brief Sets item size.
75     *
76     * @param size item size
77     */
78     void setSize(const QSize &size);
79
80     /**
81     * @brief Shortens text defined by text width.
82     *
83     * @param text text to be shortened
84     * @param textWidth the width the text can use
85     * @param textSize which text size to use
86     * @return shortened text
87     */
88     QString shortenText(const QString &text, int textWidth, TextSize textSize);
89
90     /**
91     * @brief Returns item's title.
92     *
93     * @return item's title
94     */
95     QString title() const;
96
97     /**
98     * @brief Toggles selection.
99     *
100     * @return true if selection was toggled, false otherwise
101     */
102     virtual bool toggleSelection() = 0;
103
104 /*******************************************************************************
105  * DATA MEMBERS
106  ******************************************************************************/
107 private:
108     QPixmap m_image;    ///< Item's image
109     QString m_name;     ///< Item's name
110 };
111
112 #endif // LISTITEM_H