1 #include "coordinates/geocoordinate.h"
2 #include "locationlistitem.h"
3 #include "locationlistview.h"
4 #include "extendedlistitemdelegate.h"
5 #include "routing/location.h"
6 #include "routing/route.h"
7 #include "routewaypointlistview.h"
8 #include "routewaypointlistitem.h"
9 #include "panelcommon.h"
11 #include "routingpanel.h"
13 RoutingPanel::RoutingPanel(QWidget *parent)
16 qDebug() << __PRETTY_FUNCTION__;
18 QVBoxLayout *routingLayout = new QVBoxLayout;
19 routingLayout->setMargin(0);
20 routingLayout->setSpacing(0);
21 setLayout(routingLayout);
23 QHBoxLayout *headerLayout = new QHBoxLayout();
24 headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
25 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
27 QVBoxLayout *listViewLayout = new QVBoxLayout;
28 listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
30 m_routeButton = new QPushButton("Route to location");
32 m_locationListHeaderWidget = new QWidget();
33 m_locationListHeaderWidget->setLayout(headerLayout);
34 m_locationListHeaderWidget->setAutoFillBackground(true);
35 QPalette labelPalette = m_locationListHeaderWidget->palette();
36 labelPalette.setColor(QPalette::Background, Qt::black);
37 m_locationListHeaderWidget->setPalette(labelPalette);
38 m_locationListHeaderWidget->hide();
40 m_locationListLabel = new QLabel(this);
42 m_locationListView = new LocationListView(this);
43 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
44 m_locationListView->hide();
46 m_routeWaypointListView = new RouteWaypointListView(this);
47 m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
48 m_routeWaypointListView->hide();
50 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
52 listViewLayout->addWidget(m_locationListView);
53 listViewLayout->addWidget(m_routeWaypointListView);
55 routingLayout->addWidget(m_routeButton);
56 routingLayout->addWidget(m_locationListHeaderWidget);
57 routingLayout->addLayout(listViewLayout);
59 connect(m_locationListView,
60 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
62 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
64 connect(m_routeButton, SIGNAL(clicked()),
65 this, SLOT(routeToSelectedLocation()));
67 connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
68 this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
71 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
73 qDebug() << __PRETTY_FUNCTION__;
75 m_locationListHeaderWidget->show();
76 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
78 m_routeWaypointListView->hide();
79 m_locationListView->show();
80 m_locationListView->clearList();
82 for (int i = 0; i < locations.size(); ++i) {
83 LocationListItem *item = new LocationListItem();
84 item->setLocationData(locations.at(i));
85 m_locationListView->addListItem(QString::number(i), item);
90 const int FIRST_LOCATION_ITEM_INDEX = 0;
91 const int ONE_LOCATION_ITEM = 1;
93 if (locations.size() == ONE_LOCATION_ITEM) {
94 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
97 m_locationListView->setSelectedItem(item);
101 void RoutingPanel::routeToSelectedLocation()
103 qDebug() << __PRETTY_FUNCTION__;
105 LocationListItem *item = dynamic_cast<LocationListItem *>
106 (m_locationListView->selectedItem());
109 emit routeToLocation(item->coordinates());
112 void RoutingPanel::setRoute(Route &route)
114 qDebug() << __PRETTY_FUNCTION__;
116 m_locationListView->hide();
117 m_routeWaypointListView->show();
118 m_routeWaypointListView->clear();
120 QList<RouteSegment> segments = route.segments();
121 QList<GeoCoordinate> geometryPoints = route.geometryPoints();
123 for (int i = 0; i < segments.size(); ++i) {
124 RouteWaypointListItem *item = new RouteWaypointListItem();
125 RouteSegment routeSegment = segments.at(i);
126 item->setRouteWaypointData(routeSegment,
127 geometryPoints.at(routeSegment.positionIndex()));
129 m_routeWaypointListView->addListItem(QString::number(i), item);