2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
6 Sami Rämö - sami.ramo@ixonos.com
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.
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.
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,
23 #include "extendedlistitemdelegate.h"
24 #include "locationlistitem.h"
25 #include "locationlistview.h"
26 #include "imagebutton.h"
27 #include "panelcommon.h"
28 #include "routing/location.h"
30 #include "locationsearchpanel.h"
32 LocationSearchPanel::LocationSearchPanel(QWidget *parent)
35 qDebug() << __PRETTY_FUNCTION__;
37 // --- HEADER WIDGET ---
38 QWidget *resultsHeaderWidget = new QWidget();
39 resultsHeaderWidget->setAutoFillBackground(true);
40 QPalette labelPalette = resultsHeaderWidget->palette();
41 labelPalette.setColor(QPalette::Background, Qt::black);
42 resultsHeaderWidget->setPalette(labelPalette);
44 QHBoxLayout *headerLayout = new QHBoxLayout();
45 resultsHeaderWidget->setLayout(headerLayout);
46 headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
47 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
49 m_resultsLabel = new QLabel(this);
50 headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter);
53 // --- SEARCH RESULTS LIST VIEW ---
54 m_locationListView = new LocationListView(this);
55 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
57 connect(m_locationListView,
58 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
60 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
62 connect(m_locationListView, SIGNAL(listItemSelectionChanged()),
63 this, SLOT(setRouteButtonDisabled()));
65 connect(m_locationListView, SIGNAL(listItemSelectionChanged()),
66 this, SLOT(onListItemSelectionChanged()));
68 QVBoxLayout *resultsListViewLayout = new QVBoxLayout;
69 resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
70 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
71 resultsListViewLayout->addWidget(m_locationListView);
73 // --- MAIN LAYOUT ---
74 QVBoxLayout *panelLayout = new QVBoxLayout;
75 panelLayout->setSpacing(0);
76 setLayout(panelLayout);
78 const int MARGIN_LEFT = 0;
79 panelLayout->setContentsMargins(MARGIN_LEFT, PANEL_MARGIN_TOP,
80 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
82 panelLayout->addWidget(resultsHeaderWidget);
83 panelLayout->addLayout(resultsListViewLayout);
85 // --- CONTEXT BUTTONS ---
86 m_routeButton = new ImageButton(":res/images/compass.png", "", "", this);
87 m_routeButton->setDisabled(true);
88 connect(m_routeButton, SIGNAL(clicked()),
89 this, SLOT(routeToSelectedLocation()));
91 ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
92 ":/res/images/search_s.png", "", this);
93 connect(searchLocationButton, SIGNAL(clicked()),
94 this, SIGNAL(requestSearchLocation()));
96 m_itemButtonsLayout->addWidget(m_routeButton);
97 m_genericButtonsLayout->addWidget(searchLocationButton);
100 void LocationSearchPanel::clearListsSelections()
102 qDebug() << __PRETTY_FUNCTION__;
104 m_locationListView->clearItemSelection();
106 setRouteButtonDisabled();
109 void LocationSearchPanel::hideEvent(QHideEvent *event)
111 qDebug() << __PRETTY_FUNCTION__;
113 QWidget::hideEvent(event);
115 clearListsSelections();
118 void LocationSearchPanel::populateLocationListView(const QList<Location> &locations)
120 qDebug() << __PRETTY_FUNCTION__;
122 setHeaderText(locations.count());
124 m_locationListView->clearList();
126 for (int i = 0; i < locations.size(); ++i) {
127 LocationListItem *item = new LocationListItem();
128 item->setLocationData(locations.at(i));
129 m_locationListView->addListItem(QString::number(i), item);
132 const int FIRST_LOCATION_ITEM_INDEX = 0;
133 const int ONE_LOCATION_ITEM = 1;
135 if (locations.size() == ONE_LOCATION_ITEM) {
136 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
139 m_locationListView->setSelectedItem(item);
142 m_locationListView->scrollToTop();
145 void LocationSearchPanel::routeToSelectedLocation()
147 qDebug() << __PRETTY_FUNCTION__;
149 LocationListItem *item = dynamic_cast<LocationListItem *>
150 (m_locationListView->selectedItem());
153 emit routeToLocation(item->coordinates());
156 void LocationSearchPanel::setHeaderText(int count)
158 qDebug() << __PRETTY_FUNCTION__;
160 m_resultsLabel->setText(tr("Search results: %1").arg(count));
163 void LocationSearchPanel::setRouteButtonDisabled()
165 qDebug() << __PRETTY_FUNCTION__;
167 m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());