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(onListItemSelectionChanged()));
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/routing.png", "", "", this);
84 connect(m_routeButton, SIGNAL(clicked()),
85 this, SLOT(routeToSelectedLocation()));
87 ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
88 ":/res/images/search_s.png", "", this);
89 connect(searchLocationButton, SIGNAL(clicked()),
90 this, SIGNAL(requestSearchLocation()));
92 m_itemButtonsLayout->addWidget(m_routeButton);
93 m_genericButtonsLayout->addWidget(searchLocationButton);
96 void LocationSearchPanel::clearListsSelections()
98 qDebug() << __PRETTY_FUNCTION__;
100 m_locationListView->clearItemSelection();
103 void LocationSearchPanel::hideEvent(QHideEvent *event)
105 qDebug() << __PRETTY_FUNCTION__;
107 QWidget::hideEvent(event);
109 clearListsSelections();
112 void LocationSearchPanel::populateLocationListView(const QList<Location> &locations)
114 qDebug() << __PRETTY_FUNCTION__;
116 setHeaderText(locations.count());
118 m_locationListView->clearList();
120 for (int i = 0; i < locations.size(); ++i) {
121 LocationListItem *item = new LocationListItem();
122 item->setLocationData(locations.at(i));
123 m_locationListView->addListItem(QString::number(i), item);
126 const int FIRST_LOCATION_ITEM_INDEX = 0;
127 const int ONE_LOCATION_ITEM = 1;
129 if (locations.size() == ONE_LOCATION_ITEM) {
130 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
133 m_locationListView->setSelectedItem(item);
136 m_locationListView->scrollToTop();
139 void LocationSearchPanel::routeToSelectedLocation()
141 qDebug() << __PRETTY_FUNCTION__;
143 LocationListItem *item = dynamic_cast<LocationListItem *>
144 (m_locationListView->selectedItem());
147 emit routeToLocation(item->coordinates());
150 void LocationSearchPanel::setHeaderText(int count)
152 qDebug() << __PRETTY_FUNCTION__;
154 m_resultsLabel->setText(tr("Search results: %1").arg(count));