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 QVBoxLayout *resultsListViewLayout = new QVBoxLayout;
66 resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
67 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
68 resultsListViewLayout->addWidget(m_locationListView);
70 // --- MAIN LAYOUT ---
71 QVBoxLayout *panelLayout = new QVBoxLayout;
72 panelLayout->setSpacing(0);
73 setLayout(panelLayout);
75 const int MARGIN_LEFT = 0;
76 panelLayout->setContentsMargins(MARGIN_LEFT, PANEL_MARGIN_TOP,
77 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
79 panelLayout->addWidget(resultsHeaderWidget);
80 panelLayout->addLayout(resultsListViewLayout);
82 // --- CONTEXT BUTTONS ---
83 m_routeButton = new ImageButton(":res/images/compass.png", "", "", this);
84 m_routeButton->setDisabled(true);
85 connect(m_routeButton, SIGNAL(clicked()),
86 this, SLOT(routeToSelectedLocation()));
88 ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
89 ":/res/images/search_s.png", "", this);
90 connect(searchLocationButton, SIGNAL(clicked()),
91 this, SIGNAL(requestSearchLocation()));
93 m_contextButtonLayout->addWidget(m_routeButton);
94 m_contextButtonLayout->addWidget(searchLocationButton);
97 void LocationSearchPanel::clearListsSelections()
99 qDebug() << __PRETTY_FUNCTION__;
101 m_locationListView->clearItemSelection();
103 setRouteButtonDisabled();
106 void LocationSearchPanel::hideEvent(QHideEvent *event)
108 qDebug() << __PRETTY_FUNCTION__;
110 QWidget::hideEvent(event);
112 clearListsSelections();
115 void LocationSearchPanel::populateLocationListView(const QList<Location> &locations)
117 qDebug() << __PRETTY_FUNCTION__;
119 setHeaderText(locations.count());
121 m_locationListView->clearList();
123 for (int i = 0; i < locations.size(); ++i) {
124 LocationListItem *item = new LocationListItem();
125 item->setLocationData(locations.at(i));
126 m_locationListView->addListItem(QString::number(i), item);
129 const int FIRST_LOCATION_ITEM_INDEX = 0;
130 const int ONE_LOCATION_ITEM = 1;
132 if (locations.size() == ONE_LOCATION_ITEM) {
133 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
136 m_locationListView->setSelectedItem(item);
139 m_locationListView->scrollToTop();
142 void LocationSearchPanel::routeToSelectedLocation()
144 qDebug() << __PRETTY_FUNCTION__;
146 LocationListItem *item = dynamic_cast<LocationListItem *>
147 (m_locationListView->selectedItem());
150 emit routeToLocation(item->coordinates());
153 void LocationSearchPanel::setHeaderText(int count)
155 qDebug() << __PRETTY_FUNCTION__;
157 m_resultsLabel->setText(tr("Search results: %1").arg(count));
160 void LocationSearchPanel::setRouteButtonDisabled()
162 qDebug() << __PRETTY_FUNCTION__;
164 m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());