Added search results header to RoutingPanel.
[situare] / src / ui / routingpanel.cpp
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"
7
8 #include "routingpanel.h"
9
10 RoutingPanel::RoutingPanel(QWidget *parent)
11     : QWidget(parent)
12 {
13     qDebug() << __PRETTY_FUNCTION__;
14
15     QVBoxLayout *routingLayout = new QVBoxLayout;
16     routingLayout->setMargin(0);
17     routingLayout->setSpacing(0);
18     setLayout(routingLayout);
19
20     QHBoxLayout *headerLayout = new QHBoxLayout();
21     headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
22                                      FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
23
24     QVBoxLayout *listViewLayout = new QVBoxLayout;
25     listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
26
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();
34
35     m_locationListLabel = new QLabel(this);
36
37     m_locationListView = new LocationListView(this);
38     m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
39
40     headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter);
41
42     listViewLayout->addWidget(m_locationListView);
43
44     routingLayout->addWidget(m_locationListHeaderWidget);
45     routingLayout->addLayout(listViewLayout);
46
47     connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
48             this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
49 }
50
51 void RoutingPanel::populateLocationListView(QList<Location> &locations)
52 {
53     qDebug() << __PRETTY_FUNCTION__;
54
55     m_locationListHeaderWidget->show();
56     m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
57
58     m_locationListView->clearList();
59
60     for (int i = 0; i < locations.size(); ++i) {
61         LocationListItem *item = new LocationListItem();
62         item->setLocationData(locations.at(i));
63         m_locationListView->addListItem(QString::number(i), item);
64     }
65
66     //openPanel();
67
68     if (locations.size() == 1) {
69         ListItem *item = m_locationListView->listItemAt(0);
70
71         if (item)
72             m_locationListView->listItemClicked(item);
73     }
74 }