1 #include "coordinates/geocoordinate.h"
2 #include "locationlistitem.h"
3 #include "locationlistview.h"
4 #include "extendedlistitemdelegate.h"
5 #include "routing/location.h"
6 #include "panelcommon.h"
8 #include "routingpanel.h"
10 RoutingPanel::RoutingPanel(QWidget *parent)
13 qDebug() << __PRETTY_FUNCTION__;
15 QVBoxLayout *routingLayout = new QVBoxLayout;
16 routingLayout->setMargin(0);
17 routingLayout->setSpacing(0);
18 setLayout(routingLayout);
20 QHBoxLayout *headerLayout = new QHBoxLayout();
21 headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
22 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
24 QVBoxLayout *listViewLayout = new QVBoxLayout;
25 listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
27 m_routeButton = new QPushButton("Route to location");
29 m_locationListHeaderWidget = new QWidget();
30 m_locationListHeaderWidget->setLayout(headerLayout);
31 m_locationListHeaderWidget->setAutoFillBackground(true);
32 QPalette labelPalette = m_locationListHeaderWidget->palette();
33 labelPalette.setColor(QPalette::Background, Qt::black);
34 m_locationListHeaderWidget->setPalette(labelPalette);
35 m_locationListHeaderWidget->hide();
37 m_locationListLabel = new QLabel(this);
39 m_locationListView = new LocationListView(this);
40 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
42 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
44 listViewLayout->addWidget(m_locationListView);
46 routingLayout->addWidget(m_routeButton);
47 routingLayout->addWidget(m_locationListHeaderWidget);
48 routingLayout->addLayout(listViewLayout);
50 connect(m_locationListView,
51 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
53 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
55 connect(m_routeButton, SIGNAL(clicked()),
56 this, SLOT(routeToSelectedLocation()));
59 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
61 qDebug() << __PRETTY_FUNCTION__;
63 m_locationListHeaderWidget->show();
64 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
66 m_locationListView->clearList();
68 for (int i = 0; i < locations.size(); ++i) {
69 LocationListItem *item = new LocationListItem();
70 item->setLocationData(locations.at(i));
71 m_locationListView->addListItem(QString::number(i), item);
76 const int FIRST_LOCATION_ITEM_INDEX = 0;
77 const int ONE_LOCATION_ITEM = 1;
79 if (locations.size() == ONE_LOCATION_ITEM) {
80 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
83 m_locationListView->setSelectedItem(item);
87 void RoutingPanel::routeToSelectedLocation()
89 qDebug() << __PRETTY_FUNCTION__;
91 LocationListItem *item = dynamic_cast<LocationListItem *>
92 (m_locationListView->selectedItem());
95 emit routeToLocation(item->coordinates());