Fixed list view selection to work as expected. Selection is cleared
[situare] / src / ui / friendlistpanel.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7         Pekka Nissinen - pekka.nissinen@ixonos.com
8         Jussi Laitinen - jussi.laitinen@ixonos.com
9         Sami Rämö - sami.ramo@ixonos.com
10
11     Situare is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License
13     version 2 as published by the Free Software Foundation.
14
15     Situare is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with Situare; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23     USA.
24 */
25
26 #ifndef FRIENDLISTPANEL_H
27 #define FRIENDLISTPANEL_H
28
29 #include <QWidget>
30
31 class QLabel;
32 class QLineEdit;
33 class QPushButton;
34
35 class FriendListItemDelegate;
36 class GeoCoordinate;
37 class FriendListView;
38 class User;
39
40 /**
41  * @brief Class for sliding friends list panel
42  *
43  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
44  * @author Henri Lampela - henri.lampela (at) ixonos.com
45  * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
46  * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
47  * @author Sami Rämö - sami.ramo (at) ixonos.com
48  */
49 class FriendListPanel : public QWidget
50 {
51     Q_OBJECT
52
53 public:
54     /**
55      * @brief Default constructor
56      *
57      * @param parent
58      */
59     FriendListPanel(QWidget *parent = 0);
60
61 /*******************************************************************************
62  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
63  ******************************************************************************/
64 protected:
65     /**
66     * @brief Re-implemented from QWidget::hideEvent()
67     *
68     * Calls updateKeyboardGrabbing() and clearFriendGroupFiltering().
69     *
70     * @param event
71     */
72     void hideEvent(QHideEvent *event);
73
74     /**
75     * @brief Re-implemented from QWidget::showEvent()
76     *
77     * Calls updateKeyboardGrabbing().
78     *
79     * @param event
80     */
81     void showEvent(QShowEvent *event);
82
83 /*******************************************************************************
84  * MEMBER FUNCTIONS AND SLOTS
85  ******************************************************************************/
86 public slots:
87     /**
88      * @brief Slot to update friend item's image
89      *
90      * @param user Friend
91      */
92     void friendImageReady(User *user);
93
94     /**
95      * @brief Slot to refresh friends list
96      *
97      * @param friendList
98      */
99     void friendInfoReceived(QList<User *> &friendList);
100
101 private:
102     /**
103     * @brief Set visibility for filtering text field and clearing button
104     *
105     * @param visible True if items should be visible, false if not
106     */
107     void setFilteringLayoutVisibility(bool visible);
108
109     /**
110     * @brief Takes care of grabbing and releasing the keyboard when required
111     *
112     * Keyboard is grabbed when MainWindow it the topmost window, panel tab is open and
113     * FriendListPanel is visible. Releasing is done if the MainWindow is not the topmost window
114     * or panel tab is not open or FriendListPanel is invisible.
115     */
116     void updateKeyboardGrabbing();
117
118 private slots:
119     /**
120     * @brief Called when any of the panel tabs is closed
121     *
122     * Does call clearFriendGroupFiltering().
123     *
124     * Calls updateKeyboardGrabbing() for releasing the grabbing when FriendListPanel is closed, not
125     * changed to other panel. In this case the hideEvent() is not triggered.
126     */
127     void anyPanelClosed();
128
129     /**
130     * @brief Called when any of the panel tabs is opened
131     *
132     * Calls updateKeyboardGrabbing() for grabbing the keyboard when FriendListPanel is closed and
133     * is the last selected tab. In this case the showEvent() is not triggered.
134     */
135     void anyPanelOpened();
136
137     /**
138     * @brief Slot for clearing the filtering
139     *
140     * Clears friend group (or single friend) filtering and calls clearTextFiltering().
141     */
142     void clearFiltering();
143
144     /**
145     * @brief Slot for clearing the text based filtering.
146     *
147     * Does clear only the text based filtering. Friend group based filtering is not affected.
148     */
149     void clearTextFiltering();
150
151     /**
152     * @brief Updates the filtering when filtering text value is changed
153     *
154     * Filtering UI elements are invoked when the text becomes not empty and hidden when text
155     * becomes empty.
156     *
157     * Sets the new filtering text.
158     *
159     * @param text New text value
160     */
161     void filterTextChanged(const QString &text);
162
163     /**
164     * @brief Routes to selected friend.
165     *
166     * Emits routeToFriend if friend is selected from list.
167     */
168     void routeToSelectedFriend();
169
170     /**
171     * @brief Sets route button disabled.
172     *
173     * Disabled if there isn't any list item selected.
174     */
175     void setRouteButtonDisabled();
176
177     /**
178      * @brief Slot to show friends in list.
179      *
180      * Shows only friends that are on userIDs list
181      * @param userIDs list of user ID's
182      */
183     void showFriendsInList(const QList<QString> &userIDs);
184
185     /**
186     * @brief Called when topmost window is changed
187     *
188     * Does set m_mainWindowIsTopmost and calls updateKeyboardGrabbing()
189     *
190     * @param mainWindowIsTopmost True if MainWindow is the topmost one
191     */
192     void topmostWindowChanged(bool mainWindowIsTopmost);
193
194 /*******************************************************************************
195  * SIGNALS
196  ******************************************************************************/
197 signals:
198     /**
199      * @brief Signal for friend finding
200      *
201      * @param coordinates Target coordinate
202      */
203     void findFriend(const GeoCoordinate &coordinates);
204
205     /**
206     * @brief Signal for routing to friend.
207     *
208     * @param coordinates friend's geo coordinates
209     */
210     void routeToFriend(const GeoCoordinate &coordinates);
211
212     /**
213      * @brief Signal for requesting a panel to be opened
214      *
215      * @param widget Pointer to the widget that emitted the signal
216      */
217     void showPanelRequested(QWidget *widget);
218
219 /*******************************************************************************
220  * DATA MEMBERS
221  ******************************************************************************/
222 private:
223     bool m_mainWindowIsTopmost;         ///< Is the MainWindow the topmost one
224     bool m_somePanelIsOpen;             ///< Is any panel tab open
225
226     QLabel *m_friendListLabel;          ///< Friend list label
227
228     QLineEdit *m_filterField;           ///< Text field for the filter text
229
230     QPushButton *m_clearFilterButton;   ///< Button to clear list filtering
231     QPushButton *m_filterClearButton;   ///< Button for clearing the filtering
232     QPushButton *m_routeButton;         ///< Button to route to friend
233
234     QWidget *m_friendListHeaderWidget;  ///< Friend list header widget
235
236     FriendListView *m_friendListView;   ///< Friend list view
237 };
238
239 #endif // FRIENDLISTPANEL_H