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_searchLocationButton = new QPushButton(tr("Search location"));
32 m_routeButton = new QPushButton(tr("Route to location"));
33 m_routeButton->hide();
35 m_locationListHeaderWidget = new QWidget();
36 m_locationListHeaderWidget->setLayout(headerLayout);
37 m_locationListHeaderWidget->setAutoFillBackground(true);
38 QPalette labelPalette = m_locationListHeaderWidget->palette();
39 labelPalette.setColor(QPalette::Background, Qt::black);
40 m_locationListHeaderWidget->setPalette(labelPalette);
41 m_locationListHeaderWidget->hide();
43 m_locationListLabel = new QLabel(this);
45 m_locationListView = new LocationListView(this);
46 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
47 m_locationListView->hide();
49 m_routeWaypointListView = new RouteWaypointListView(this);
50 m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
51 m_routeWaypointListView->hide();
53 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
55 listViewLayout->addWidget(m_locationListView);
56 listViewLayout->addWidget(m_routeWaypointListView);
58 routingLayout->addWidget(m_searchLocationButton);
59 routingLayout->addWidget(m_routeButton);
60 routingLayout->addWidget(m_locationListHeaderWidget);
61 routingLayout->addLayout(listViewLayout);
63 connect(m_locationListView,
64 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
66 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
68 connect(m_routeButton, SIGNAL(clicked()),
69 this, SLOT(routeToSelectedLocation()));
71 connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
72 this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
74 connect(m_searchLocationButton, SIGNAL(clicked()),
75 this, SIGNAL(requestSearchLocation()));
78 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
80 qDebug() << __PRETTY_FUNCTION__;
82 m_routeButton->show();
84 m_locationListHeaderWidget->show();
85 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
87 m_routeWaypointListView->hide();
88 m_locationListView->show();
89 m_locationListView->clearList();
91 for (int i = 0; i < locations.size(); ++i) {
92 LocationListItem *item = new LocationListItem();
93 item->setLocationData(locations.at(i));
94 m_locationListView->addListItem(QString::number(i), item);
97 const int FIRST_LOCATION_ITEM_INDEX = 0;
98 const int ONE_LOCATION_ITEM = 1;
100 if (locations.size() == ONE_LOCATION_ITEM) {
101 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
104 m_locationListView->setSelectedItem(item);
108 void RoutingPanel::routeToSelectedLocation()
110 qDebug() << __PRETTY_FUNCTION__;
112 LocationListItem *item = dynamic_cast<LocationListItem *>
113 (m_locationListView->selectedItem());
116 emit routeToLocation(item->coordinates());
119 void RoutingPanel::setRoute(Route &route)
121 qDebug() << __PRETTY_FUNCTION__;
123 m_locationListHeaderWidget->hide();
124 m_locationListView->hide();
125 m_routeWaypointListView->show();
126 m_routeWaypointListView->clearList();
128 QList<RouteSegment> segments = route.segments();
129 QList<GeoCoordinate> geometryPoints = route.geometryPoints();
131 for (int i = 0; i < segments.size(); ++i) {
132 RouteWaypointListItem *item = new RouteWaypointListItem();
133 RouteSegment routeSegment = segments.at(i);
134 item->setRouteWaypointData(routeSegment,
135 geometryPoints.at(routeSegment.positionIndex()));
137 m_routeWaypointListView->addListItem(QString::number(i), item);