Rough implementation of the item related buttons
[situare] / src / ui / routingpanel.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Jussi Laitinen - jussi.laitinen@ixonos.com
6         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include "coordinates/geocoordinate.h"
24 #include "extendedlistitemdelegate.h"
25 #include "imagebutton.h"
26 #include "panelcommon.h"
27 #include "routewaypointlistitem.h"
28 #include "routewaypointlistview.h"
29 #include "routing/location.h"
30 #include "routing/route.h"
31
32 #include "routingpanel.h"
33
34 RoutingPanel::RoutingPanel(QWidget *parent)
35     : PanelBase(parent)
36 {
37     qDebug() << __PRETTY_FUNCTION__;
38
39     // --- LAYOUT & ROUTING INSTRUCTIONS VIEW ---
40     m_routeWaypointListView = new RouteWaypointListView(this);
41     m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this));
42
43     connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
44             this, SIGNAL(routeWaypointItemClicked(GeoCoordinate)));
45
46     connect(m_routeWaypointListView, SIGNAL(listItemSelectionChanged()),
47             this, SLOT(onListItemSelectionChanged()));
48
49     QVBoxLayout *panelLayout = new QVBoxLayout;
50     panelLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
51                                     PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
52
53     panelLayout->addWidget(m_routeWaypointListView);
54     setLayout(panelLayout);
55
56     // --- CONTEXT BUTTONS ---
57     ImageButton *routeToCursorButton = new ImageButton(":res/images/sight.png",
58                                                        "", "", this);
59     connect(routeToCursorButton, SIGNAL(clicked()),
60             this, SIGNAL(routeToCursor()));
61
62     m_clearRouteButton = new ImageButton(":/res/images/gps_position.png",
63                                          "", "", this);
64     connect(m_clearRouteButton, SIGNAL(clicked()),
65             this, SLOT(clearRouteButtonClicked()));
66     m_clearRouteButton->setDisabled(true);
67
68     m_genericButtonsLayout->addWidget(routeToCursorButton);
69     m_genericButtonsLayout->addWidget(m_clearRouteButton);
70 }
71
72 void RoutingPanel::clearListsSelections()
73 {
74     qDebug() << __PRETTY_FUNCTION__;
75
76     m_routeWaypointListView->clearItemSelection();
77 }
78
79 void RoutingPanel::clearRouteButtonClicked()
80 {
81     qDebug() << __PRETTY_FUNCTION__;
82
83     m_clearRouteButton->setDisabled(true);
84     m_routeWaypointListView->clearList();
85     emit clearRoute();
86 }
87
88 void RoutingPanel::hideEvent(QHideEvent *event)
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91
92     QWidget::hideEvent(event);
93
94     clearListsSelections();
95 }
96
97 void RoutingPanel::setRoute(Route &route)
98 {
99     qDebug() << __PRETTY_FUNCTION__;
100
101     m_routeWaypointListView->clearList();
102
103     QList<RouteSegment> segments = route.segments();
104     QList<GeoCoordinate> geometryPoints = route.geometryPoints();
105
106     for (int i = 0; i < segments.size(); ++i) {
107         RouteWaypointListItem *item = new RouteWaypointListItem();
108         RouteSegment routeSegment = segments.at(i);
109         item->setRouteWaypointData(routeSegment,
110                                    geometryPoints.at(routeSegment.positionIndex()));
111
112         m_routeWaypointListView->addListItem(QString::number(i), item);
113     }
114
115     m_routeWaypointListView->scrollToTop();
116
117     m_clearRouteButton->setDisabled(false);
118
119     emit openPanelRequested(this);
120 }