Added listcommon.h file.
[situare] / src / ui / listview.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 LISTVIEW_H
23 #define LISTVIEW_H
24
25 #include <QListWidget>
26
27 class ListItem;
28
29 class ListView : public QListWidget
30 {
31     Q_OBJECT
32 public:
33     ListView(QWidget *parent = 0);
34
35 public:
36     /**
37     * @brief Add widget to view and widget list.
38     *
39     * @param key user ID
40     * @param widget widget to add to list
41     */
42     void addListItem(const QString &key, ListItem *item);
43
44     /**
45     * @brief Adds widget to view.
46     *
47     * @param item FriendListItem
48     */
49     void addListItemToView(ListItem *item);
50
51     /**
52     * @brief Clear unused widgets from view.
53     *
54     * Clears items which are not in user ID's list from the view and widget list.
55     *
56     * @param userIDs list of new user ID's.
57     */
58     void clearUnused(const QStringList &userIDs);
59
60     /**
61     * @brief Clears filtering from list.
62     *
63     * Calls show to all widgets.
64     */
65     void clearFilter();
66
67     void clearList();
68
69     /**
70     * @brief Checks if view contains widget with userID.
71     *
72     * @param userID user's ID
73     * @return true if view contains widget, false otherwise
74     */
75     bool contains(const QString &userID);
76
77     /**
78     * @brief Sets filter to list.
79     *
80     * Hide all widgets that are not in the userIDs list.
81     *
82     * @param userIDs user ID's to widgets that are shown
83     */
84     void filter(const QList<QString> &userIDs);
85
86     /**
87     * @brief Takes widget from view.
88     *
89     * Widget is not deleted.
90     *
91     * @param userID user's ID
92     * @return FriendListItem
93     */
94     ListItem *takeListItemFromView(const QString &userID);
95
96     /**
97     * @brief Returns FriendListItem with userID.
98     *
99     * @param userID user's ID
100     * @return FriendListItem
101     */
102     ListItem *listItem(const QString &userID);
103
104 signals:
105     void listItemClicked(const QString &id);
106     void listItemClicked(const QPointF &coordinates);
107
108 public slots:
109
110 private slots:
111
112     void listItemClicked(QListWidgetItem *item);
113
114 private:
115     ListItem *previousItem;
116     QHash<QString, ListItem *> m_listItems;  ///< List of items in this view. Key = user ID
117 };
118
119 #endif // LISTVIEW_H