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, PANEL_MARGIN_TOP,
26 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
28 QVBoxLayout *listViewLayout = new QVBoxLayout;
29 listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
30 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
32 ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
33 ":/res/images/search_s.png",
36 m_contextButtonLayout->addWidget(searchLocationButton, 0, 0);
38 m_routeButton = new QPushButton(tr("Route to location"));
39 m_routeButton->setDisabled(true);
40 m_routeButton->hide();
42 m_locationListHeaderWidget = new QWidget();
43 m_locationListHeaderWidget->setLayout(headerLayout);
44 m_locationListHeaderWidget->setAutoFillBackground(true);
45 QPalette labelPalette = m_locationListHeaderWidget->palette();
46 labelPalette.setColor(QPalette::Background, Qt::black);
47 m_locationListHeaderWidget->setPalette(labelPalette);
48 m_locationListHeaderWidget->hide();
50 m_locationListLabel = new QLabel(this);
52 m_locationListView = new LocationListView(this);
53 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
54 m_locationListView->hide();
56 m_routeWaypointListView = new RouteWaypointListView(this);
57 m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
58 m_routeWaypointListView->hide();
60 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
62 listViewLayout->addWidget(m_locationListView);
63 listViewLayout->addWidget(m_routeWaypointListView);
65 routingLayout->addWidget(m_routeButton);
66 routingLayout->addWidget(m_locationListHeaderWidget);
67 routingLayout->addLayout(listViewLayout);
69 connect(m_locationListView,
70 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
72 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
74 connect(m_locationListView, SIGNAL(listItemSelectionChanged()),
75 this, SLOT(setRouteButtonDisabled()));
77 connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
78 this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
80 connect(m_routeButton, SIGNAL(clicked()),
81 this, SLOT(routeToSelectedLocation()));
83 connect(searchLocationButton, SIGNAL(clicked()),
84 this, SIGNAL(requestSearchLocation()));
87 void RoutingPanel::clearListsSelections()
89 qDebug() << __PRETTY_FUNCTION__;
91 m_locationListView->clearItemSelection();
92 m_routeWaypointListView->clearItemSelection();
94 setRouteButtonDisabled();
97 void RoutingPanel::hideEvent(QHideEvent *event)
99 qDebug() << __PRETTY_FUNCTION__;
101 QWidget::hideEvent(event);
103 clearListsSelections();
106 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
108 qDebug() << __PRETTY_FUNCTION__;
110 m_routeButton->show();
112 m_locationListHeaderWidget->show();
113 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
115 m_routeWaypointListView->hide();
116 m_locationListView->show();
117 m_locationListView->clearList();
119 for (int i = 0; i < locations.size(); ++i) {
120 LocationListItem *item = new LocationListItem();
121 item->setLocationData(locations.at(i));
122 m_locationListView->addListItem(QString::number(i), item);
125 const int FIRST_LOCATION_ITEM_INDEX = 0;
126 const int ONE_LOCATION_ITEM = 1;
128 if (locations.size() == ONE_LOCATION_ITEM) {
129 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
132 m_locationListView->setSelectedItem(item);
135 m_locationListView->scrollToTop();
138 void RoutingPanel::routeToSelectedLocation()
140 qDebug() << __PRETTY_FUNCTION__;
142 LocationListItem *item = dynamic_cast<LocationListItem *>
143 (m_locationListView->selectedItem());
146 emit routeToLocation(item->coordinates());
149 void RoutingPanel::setRoute(Route &route)
151 qDebug() << __PRETTY_FUNCTION__;
153 m_routeButton->hide();
155 m_locationListHeaderWidget->hide();
156 m_locationListView->hide();
157 m_routeWaypointListView->show();
158 m_routeWaypointListView->clearList();
160 QList<RouteSegment> segments = route.segments();
161 QList<GeoCoordinate> geometryPoints = route.geometryPoints();
163 for (int i = 0; i < segments.size(); ++i) {
164 RouteWaypointListItem *item = new RouteWaypointListItem();
165 RouteSegment routeSegment = segments.at(i);
166 item->setRouteWaypointData(routeSegment,
167 geometryPoints.at(routeSegment.positionIndex()));
169 m_routeWaypointListView->addListItem(QString::number(i), item);
172 m_routeWaypointListView->scrollToTop();
174 emit showPanelRequested(this);
177 void RoutingPanel::setRouteButtonDisabled()
179 qDebug() << __PRETTY_FUNCTION__;
181 m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());