Added ExtendedListItem::boundingRect method.
[situare] / src / ui / extendedlistitem.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
23 #ifndef EXTENDEDLISTITEM_H
24 #define EXTENDEDLISTITEM_H
25
26 #include "listitem.h"
27
28 class ExtendedListItemStore;
29
30 /**
31 * @brief Base class for extended list items.
32 *
33 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
34 */
35 class ExtendedListItem : public ListItem
36 {
37 public:
38     /**
39     * @brief Constructor.
40     *
41     * Sets item size and creates sub item store list.
42     */
43     ExtendedListItem();
44
45     /**
46     * @brief Destructor.
47     *
48     * Deletes sub item stores and sub item store list.
49     */
50     virtual ~ExtendedListItem();
51
52 /*******************************************************************************
53 * MEMBER FUNCTIONS AND SLOTS
54 ******************************************************************************/
55 public:
56     /**
57     * @brief Adds sub item.
58     *
59     * Sub item area is defined by sub item text width.
60     * @param text sub item text
61     * @param icon sub item icon, optional
62     */
63     void addSubItem(const QString &text, const QPixmap &icon = QPixmap());
64
65     /**
66     * @brief Clears sub items.
67     *
68     * Clears sub items' list and deletes items. Sets item default and
69     * extended height to default values.
70     */
71     void clearSubItems();
72
73     /**
74     * @brief Sets item selected.
75     *
76     * @param selected true if selected, false otherwise
77     */
78     void setSelected(bool selected);
79
80     /**
81     * @brief Sets sub items' text width.
82     *
83     * @param width sub item width
84     */
85     void setSubitemTextWidth(int width);
86
87     /**
88     * @brief Toggles selection.
89     *
90     * @return true if selection was toggled, false otherwise
91     */
92     bool toggleSelection();
93
94 private:
95     /**
96     * @brief Returns text's bounding rect.
97     *
98     * Takes into account line breaks in text.
99     *
100     * @param text text which rect is calculated
101     */
102     QRect boundingRect(const QString &text);
103
104     /**
105     * @brief Calculates text rects.
106     *
107     * Rect width is defined by sub item text width.
108     * @param text text which rect is calculated
109     * @return text rect
110     */
111     QRect calculateExpandedTextRect(const QString &text);
112
113 /******************************************************************************
114 * DATA MEMBERS
115 ******************************************************************************/
116 private:
117     bool m_selected;        ///< Selected flag
118     int m_expandedHeight;   ///< Item expanded height
119     int m_normalHeight;     ///< Item normal height
120     int m_subItemTextWidth; ///< Sub items' text wdith
121
122     QList<ExtendedListItemStore *> *m_subItemStoreList; ///< ExtendedListItemStore list
123 };
124
125 #endif // EXTENDEDLISTITEM_H