1 #include "coordinates/geocoordinate.h"
2 #include "locationlistitem.h"
3 #include "locationlistview.h"
4 #include "extendedlistitemdelegate.h"
5 #include "imagebutton.h"
6 #include "routing/location.h"
7 #include "routing/route.h"
8 #include "routewaypointlistview.h"
9 #include "routewaypointlistitem.h"
10 #include "panelcommon.h"
12 #include "routingpanel.h"
14 RoutingPanel::RoutingPanel(QWidget *parent)
17 qDebug() << __PRETTY_FUNCTION__;
19 QVBoxLayout *routingLayout = new QVBoxLayout;
20 routingLayout->setMargin(0);
21 routingLayout->setSpacing(0);
22 setLayout(routingLayout);
24 QHBoxLayout *headerLayout = new QHBoxLayout();
25 headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0,
26 PANEL_MARGIN_RIGHT, 0);
28 QVBoxLayout *listViewLayout = new QVBoxLayout;
29 listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
31 ImageButton *searchLocationButton = new ImageButton(0, ":/res/images/search.png",
32 ":/res/images/search_s.png");
34 m_contextButtonList.append(searchLocationButton);
36 m_routeButton = new QPushButton(tr("Route to location"));
37 m_routeButton->hide();
39 m_locationListHeaderWidget = new QWidget();
40 m_locationListHeaderWidget->setLayout(headerLayout);
41 m_locationListHeaderWidget->setAutoFillBackground(true);
42 QPalette labelPalette = m_locationListHeaderWidget->palette();
43 labelPalette.setColor(QPalette::Background, Qt::black);
44 m_locationListHeaderWidget->setPalette(labelPalette);
45 m_locationListHeaderWidget->hide();
47 m_locationListLabel = new QLabel(this);
49 m_locationListView = new LocationListView(this);
50 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
51 m_locationListView->hide();
53 m_routeWaypointListView = new RouteWaypointListView(this);
54 m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
55 m_routeWaypointListView->hide();
57 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
59 listViewLayout->addWidget(m_locationListView);
60 listViewLayout->addWidget(m_routeWaypointListView);
62 routingLayout->addWidget(m_routeButton);
63 routingLayout->addWidget(m_locationListHeaderWidget);
64 routingLayout->addLayout(listViewLayout);
66 connect(m_locationListView,
67 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
69 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
71 connect(m_routeButton, SIGNAL(clicked()),
72 this, SLOT(routeToSelectedLocation()));
74 connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
75 this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
77 connect(searchLocationButton, SIGNAL(clicked()),
78 this, SIGNAL(requestSearchLocation()));
81 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
83 qDebug() << __PRETTY_FUNCTION__;
85 m_routeButton->show();
87 m_locationListHeaderWidget->show();
88 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
90 m_routeWaypointListView->hide();
91 m_locationListView->show();
92 m_locationListView->clearList();
94 for (int i = 0; i < locations.size(); ++i) {
95 LocationListItem *item = new LocationListItem();
96 item->setLocationData(locations.at(i));
97 m_locationListView->addListItem(QString::number(i), item);
100 const int FIRST_LOCATION_ITEM_INDEX = 0;
101 const int ONE_LOCATION_ITEM = 1;
103 if (locations.size() == ONE_LOCATION_ITEM) {
104 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
107 m_locationListView->setSelectedItem(item);
110 m_locationListView->scrollToTop();
113 void RoutingPanel::routeToSelectedLocation()
115 qDebug() << __PRETTY_FUNCTION__;
117 LocationListItem *item = dynamic_cast<LocationListItem *>
118 (m_locationListView->selectedItem());
121 emit routeToLocation(item->coordinates());
124 void RoutingPanel::setRoute(Route &route)
126 qDebug() << __PRETTY_FUNCTION__;
128 m_routeButton->hide();
130 m_locationListHeaderWidget->hide();
131 m_locationListView->hide();
132 m_routeWaypointListView->show();
133 m_routeWaypointListView->clearList();
135 QList<RouteSegment> segments = route.segments();
136 QList<GeoCoordinate> geometryPoints = route.geometryPoints();
138 for (int i = 0; i < segments.size(); ++i) {
139 RouteWaypointListItem *item = new RouteWaypointListItem();
140 RouteSegment routeSegment = segments.at(i);
141 item->setRouteWaypointData(routeSegment,
142 geometryPoints.at(routeSegment.positionIndex()));
144 m_routeWaypointListView->addListItem(QString::number(i), item);
147 m_routeWaypointListView->scrollToTop();
149 emit showPanelRequested(this);