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_locationListHeaderWidget = new QWidget();
28 m_locationListHeaderWidget->setLayout(headerLayout);
29 m_locationListHeaderWidget->setAutoFillBackground(true);
30 QPalette labelPalette = m_locationListHeaderWidget->palette();
31 labelPalette.setColor(QPalette::Background, Qt::black);
32 m_locationListHeaderWidget->setPalette(labelPalette);
33 m_locationListHeaderWidget->hide();
35 m_locationListLabel = new QLabel(this);
37 m_locationListView = new LocationListView(this);
38 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
40 headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
42 listViewLayout->addWidget(m_locationListView);
44 routingLayout->addWidget(m_locationListHeaderWidget);
45 routingLayout->addLayout(listViewLayout);
47 connect(m_locationListView,
48 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
50 SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
53 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
55 qDebug() << __PRETTY_FUNCTION__;
57 m_locationListHeaderWidget->show();
58 m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
60 m_locationListView->clearList();
62 for (int i = 0; i < locations.size(); ++i) {
63 LocationListItem *item = new LocationListItem();
64 item->setLocationData(locations.at(i));
65 m_locationListView->addListItem(QString::number(i), item);
70 const int FIRST_LOCATION_ITEM_INDEX = 0;
71 const int ONE_LOCATION_ITEM = 1;
73 if (locations.size() == ONE_LOCATION_ITEM) {
74 ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
77 m_locationListView->listItemClicked(item);