d86190a8ea6f3154afe8b46c4fc9ec01ef07074b
[situare] / src / ui / locationsearchpanel.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         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #ifndef LOCATIONSEARCHPANEL_H
24 #define LOCATIONSEARCHPANEL_H
25
26 #include <QtGui>
27
28 #include "panelbase.h"
29
30 class ExtendedListItemDelegate;
31 class GeoCoordinate;
32 class ImageButton;
33 class Location;
34 class LocationListView;
35 class SearchHistoryListView;
36
37 /**
38  * @brief Location search panel
39  *
40  * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
41  * @author Sami Rämö - sami.ramo (at) ixonos.com
42  */
43 class LocationSearchPanel : public PanelBase
44 {
45     Q_OBJECT
46
47 public:
48     /**
49      * @brief Default constructor
50      *
51      * @param parent
52      */
53     LocationSearchPanel(QWidget *parent = 0);
54
55     /**
56      * @brief Destructor
57      *
58      * Writes search history to settings.
59      */
60     ~LocationSearchPanel();
61
62 /*******************************************************************************
63  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
64  ******************************************************************************/
65 protected:
66     /**
67     * @brief Re-implemented from QWidget::hideEvent()
68     *
69     * Calls clearListsSelections()
70     *
71     * @param event
72     */
73     void hideEvent(QHideEvent *event);
74
75 /*******************************************************************************
76  * MEMBER FUNCTIONS AND SLOTS
77  ******************************************************************************/
78 private:
79     /**
80     * @brief Reads search history from settings.
81     */
82     void readSettings();
83
84     /**
85     * @brief Set text for header
86     *
87     * @param count Search result count
88     */
89     void setHeaderText(int count);
90
91 private slots:
92     /**
93     * @brief Prepends search history list view with search.
94     *
95     * If search history limit is reached, oldest search is removed from list view.
96     *
97     * @param searchString search string to add
98     * @param dateTime date and time of search (if empty, current date and time is added)
99     */
100     void prependSearchHistory(QString searchString, QDateTime dateTime = QDateTime());
101
102     /**
103     * @brief Clears lists' selections.
104     *
105     * Does call setRouteButtonDisabled().
106     */
107     void clearListsSelections();
108
109     /**
110     * @brief Shows search history list.
111     */
112     void showSearchHistoryList();
113
114     /**
115     * @brief Populates location list view.
116     *
117     * @param locations list of Location objects
118     */
119     void populateLocationListView(const QList<Location> &locations);
120
121     /**
122     * @brief Routes to selected location.
123     *
124     * Emits routeToLocation if location is selected from list.
125     */
126     void routeToSelectedLocation();
127
128     /**
129     * @brief Sets route button disabled.
130     *
131     * Disabled if there isn't any list item selected.
132     */
133     void setRouteButtonDisabled();
134
135 /*******************************************************************************
136  * SIGNALS
137  ******************************************************************************/
138 signals:
139     /**
140     * @brief Signal for location item clicked.
141     *
142     * @param swBound south-west bound GeoCoordinate
143     * @param neBound north-east bound GeoCoordinate
144     */
145     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
146
147     /**
148     * @brief Signal for requesting searching location.
149     */
150     void requestSearchLocation();
151
152     /**
153     * @brief Signal for routing to location.
154     *
155     * @param coordinates location's geo coordinates
156     */
157     void routeToLocation(const GeoCoordinate &coordinates);
158
159     /**
160     * @brief Signal for route waypoint item clicked.
161     *
162     * @param coordinate waypoint item's coordinate
163     */
164     void routeWaypointItemClicked(const GeoCoordinate &coordinate);
165
166     /**
167     * @brief Signal is emitted when search history item is clicked.
168     *
169     * @param searchString search string used
170     */
171     void searchHistoryItemClicked(const QString &searchString);
172
173 /*******************************************************************************
174  * DATA MEMBERS
175  ******************************************************************************/
176 private:
177     QLabel *m_resultsLabel;                         ///< Location list label
178
179     ImageButton *m_clearLocationListButton;         ///< Clear location list button
180     ImageButton *m_routeButton;                     ///< Route to location button
181     SearchHistoryListView *m_searchHistoryListView; ///< Search history list view
182     LocationListView *m_locationListView;           ///< Search results list view
183 };
184
185 #endif // LOCATIONSEARCHPANEL_H