From: Pekka Nissinen Date: Fri, 27 Aug 2010 05:33:42 +0000 (+0300) Subject: Merge branch 'move_buttons_to_content_area' into new_panels_with_context_buttons X-Git-Tag: v2.0b-1~37 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=2614cfefd32cf1000a9c58d5cc2ef428cf94c3c8;hp=704b276ec6cb68be3fc8f7d2e0df7385d2824eeb;p=situare Merge branch 'move_buttons_to_content_area' into new_panels_with_context_buttons --- diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 4b7b821..4f0359e 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -671,6 +671,9 @@ void SituareEngine::signalsFromMainWindow() m_mapEngine, SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&))); + connect(m_ui, SIGNAL(clearRoute()), + m_mapEngine, SLOT(clearRoute())); + // signals from distence indicator button connect(m_ui, SIGNAL(autoCenteringTriggered(bool)), this, SLOT(changeAutoCenteringSetting(bool))); diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index 8c2a706..0675e1f 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -177,6 +177,17 @@ void MapEngine::centerToCoordinates(GeoCoordinate coordinate) scrollToPosition(SceneCoordinate(coordinate)); } +void MapEngine::clearRoute() +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_mapRouteItem) { + m_mapScene->removeItem(m_mapRouteItem); + delete m_mapRouteItem; + m_mapRouteItem = 0; + } +} + QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, SceneCoordinate coordinate) { qDebug() << __PRETTY_FUNCTION__; @@ -463,17 +474,9 @@ void MapEngine::setRoute(Route &route) { qDebug() << __PRETTY_FUNCTION__; - m_route = route; - - // delete old route track (if exists) - if (m_mapRouteItem) { - m_mapScene->removeItem(m_mapRouteItem); - delete m_mapRouteItem; - m_mapRouteItem = 0; - } + clearRoute(); - // create new route track - m_mapRouteItem = new MapRouteItem(&m_route); + m_mapRouteItem = new MapRouteItem(&route); m_mapScene->addItem(m_mapRouteItem); centerAndZoomTo(m_mapRouteItem->boundingRect().toRect()); diff --git a/src/map/mapengine.h b/src/map/mapengine.h index 07db7b9..0177ea0 100644 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@ -267,6 +267,11 @@ private: private slots: /** + * @brief Slot for clearing the current route + */ + void clearRoute(); + + /** * @brief This slot is called after friend items position have been updated * * Does run MapScene::spanItems() @@ -471,7 +476,6 @@ private: MapScene *m_mapScene; ///< Scene for map tiles MapScroller *m_scroller; ///< Kinetic scroller OwnLocationItem *m_ownLocation; ///< Item to show own location - Route m_route; ///< Current route data }; #endif // MAPENGINE_H diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 1168d3a..6701a52 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -376,6 +376,9 @@ void MainWindow::buildRoutingPanel() connect(m_routingPanel, SIGNAL(requestSearchLocation()), this, SLOT(startLocationSearch())); + + connect(m_routingPanel, SIGNAL(clearRoute()), + this, SIGNAL(clearRoute())); } void MainWindow::buildUserInfoPanel() diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 5c2776f..044a1c4 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -442,6 +442,11 @@ signals: void centerToSceneCoordinates(const SceneCoordinate &coordinate); /** + * @brief Emitted when route is cleared + */ + void clearRoute(); + + /** * @brief Signal when direction and distance from current map center point to current GPS * location is changed * diff --git a/src/ui/routingpanel.cpp b/src/ui/routingpanel.cpp index 7b7f132..6135f31 100644 --- a/src/ui/routingpanel.cpp +++ b/src/ui/routingpanel.cpp @@ -4,10 +4,10 @@ #include "locationlistview.h" #include "imagebutton.h" #include "panelcommon.h" -#include "routing/location.h" -#include "routing/route.h" #include "routewaypointlistitem.h" #include "routewaypointlistview.h" +#include "routing/location.h" +#include "routing/route.h" #include "routingpanel.h" @@ -16,54 +16,41 @@ RoutingPanel::RoutingPanel(QWidget *parent) { qDebug() << __PRETTY_FUNCTION__; - QVBoxLayout *routingLayout = new QVBoxLayout; - routingLayout->setMargin(0); - routingLayout->setSpacing(0); - setLayout(routingLayout); - - QHBoxLayout *headerLayout = new QHBoxLayout(); - headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, - PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); - - QVBoxLayout *listViewLayout = new QVBoxLayout; - listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, - PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); + // --- ROUTING INSTRUCTIONS WIDGET --- + m_routeWaypointListView = new RouteWaypointListView(this); + m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this)); - ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png", - ":/res/images/search_s.png", - "", this); + connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)), + this, SIGNAL(routeWaypointItemClicked(GeoCoordinate))); - m_contextButtonLayout->addWidget(searchLocationButton); + QVBoxLayout *routingViewLayout = new QVBoxLayout; + routingViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, + PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); - m_routeButton = new ImageButton(":res/images/route_to_location.png", - ":res/images/route_to_location_s.png", "", this); - m_routeButton->setDisabled(true); + // main routing layout + m_routingView = new QWidget(); + m_routingView->setLayout(routingViewLayout); + routingViewLayout->addWidget(m_routeWaypointListView); - m_locationListHeaderWidget = new QWidget(); - m_locationListHeaderWidget->setLayout(headerLayout); - m_locationListHeaderWidget->setAutoFillBackground(true); - QPalette labelPalette = m_locationListHeaderWidget->palette(); + // --- SEARCH RESULTS WIDGET --- + // header + QWidget *resultsHeaderWidget = new QWidget(); + resultsHeaderWidget->setAutoFillBackground(true); + QPalette labelPalette = resultsHeaderWidget->palette(); labelPalette.setColor(QPalette::Background, Qt::black); - m_locationListHeaderWidget->setPalette(labelPalette); - m_locationListHeaderWidget->hide(); + resultsHeaderWidget->setPalette(labelPalette); + + QHBoxLayout *headerLayout = new QHBoxLayout(); + resultsHeaderWidget->setLayout(headerLayout); + headerLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, + PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); - m_locationListLabel = new QLabel(this); + m_resultsLabel = new QLabel(this); + headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter); + // list view m_locationListView = new LocationListView(this); m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this)); - m_locationListView->hide(); - - m_routeWaypointListView = new RouteWaypointListView(this); - m_routeWaypointListView->setItemDelegate(new ExtendedListItemDelegate(this)); - m_routeWaypointListView->hide(); - - headerLayout->addWidget(m_locationListLabel, 0, Qt::AlignCenter); - - listViewLayout->addWidget(m_locationListView); - listViewLayout->addWidget(m_routeWaypointListView); - - routingLayout->addWidget(m_locationListHeaderWidget); - routingLayout->addLayout(listViewLayout); connect(m_locationListView, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)), @@ -73,16 +60,51 @@ RoutingPanel::RoutingPanel(QWidget *parent) connect(m_locationListView, SIGNAL(listItemSelectionChanged()), this, SLOT(setRouteButtonDisabled())); - connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)), - this, SIGNAL(routeWaypointItemClicked(GeoCoordinate))); - - connect(m_routeButton, SIGNAL(clicked()), - this, SLOT(routeToSelectedLocation())); + QVBoxLayout *resultsListViewLayout = new QVBoxLayout; + resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, + PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); + resultsListViewLayout->addWidget(m_locationListView); + + // main results layout + m_resultsView = new QWidget(); + QVBoxLayout *resultsViewLayout = new QVBoxLayout; + const int CONTENTS_MARGIN_LEFT = 0; + resultsViewLayout->setContentsMargins(CONTENTS_MARGIN_LEFT, PANEL_MARGIN_TOP, + PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); + m_resultsView->setLayout(resultsViewLayout); + + resultsViewLayout->addWidget(resultsHeaderWidget); + resultsViewLayout->addLayout(resultsListViewLayout); + + // --- MAIN LAYOUT --- + QVBoxLayout *routingPanelLayout = new QVBoxLayout; + routingPanelLayout->setMargin(0); + routingPanelLayout->setSpacing(0); + setLayout(routingPanelLayout); + + m_views = new QStackedLayout(); + routingPanelLayout->addLayout(m_views); + m_views->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, + PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); + + m_views->addWidget(m_routingView); + m_views->addWidget(m_resultsView); + + // --- CONTEXT BUTTONS --- + m_searchLocationButton = new ImageButton(":/res/images/search.png", + ":/res/images/search_s.png", "", this); + m_searchLocationButton->setCheckable(true); + connect(m_searchLocationButton, SIGNAL(toggled(bool)), + this, SLOT(searchLocationButtonToggled(bool))); - connect(searchLocationButton, SIGNAL(clicked()), - this, SIGNAL(requestSearchLocation())); + m_routeButton = new ImageButton(":res/images/route_to_location.png", + ":res/images/route_to_location_s.png", "", this); + m_routeButton->setCheckable(true); + m_routeButton->setDisabled(true); + connect(m_routeButton, SIGNAL(toggled(bool)), + this, SLOT(routeButtonToggled(bool))); - // CONTEXT BUTTONS + m_contextButtonLayout->addWidget(m_searchLocationButton); m_contextButtonLayout->addWidget(m_routeButton); } @@ -109,11 +131,8 @@ void RoutingPanel::populateLocationListView(const QList &locations) { qDebug() << __PRETTY_FUNCTION__; - m_locationListHeaderWidget->show(); - m_locationListLabel->setText(tr("Search results: %1").arg(locations.count())); + m_resultsLabel->setText(tr("Search results: %1").arg(locations.count())); - m_routeWaypointListView->hide(); - m_locationListView->show(); m_locationListView->clearList(); for (int i = 0; i < locations.size(); ++i) { @@ -135,6 +154,20 @@ void RoutingPanel::populateLocationListView(const QList &locations) m_locationListView->scrollToTop(); } +void RoutingPanel::routeButtonToggled(bool checked) +{ + qDebug() << __PRETTY_FUNCTION__; + + if (checked) { + routeToSelectedLocation(); + m_searchLocationButton->setChecked(false); + } else { + emit clearRoute(); + m_routeWaypointListView->clearList(); + setRouteButtonDisabled(); + } +} + void RoutingPanel::routeToSelectedLocation() { qDebug() << __PRETTY_FUNCTION__; @@ -146,13 +179,22 @@ void RoutingPanel::routeToSelectedLocation() emit routeToLocation(item->coordinates()); } +void RoutingPanel::searchLocationButtonToggled(bool checked) +{ + qDebug() << __PRETTY_FUNCTION__; + + if (checked) { + showResultsView(); + emit requestSearchLocation(); + } else { + showRoutingView(); + } +} + void RoutingPanel::setRoute(Route &route) { qDebug() << __PRETTY_FUNCTION__; - m_locationListHeaderWidget->hide(); - m_locationListView->hide(); - m_routeWaypointListView->show(); m_routeWaypointListView->clearList(); QList segments = route.segments(); @@ -169,6 +211,18 @@ void RoutingPanel::setRoute(Route &route) m_routeWaypointListView->scrollToTop(); + // route might come from FriendListPanel's route to friend button, so we have to + // check the routing button without emitting new routing request + blockSignals(true); + m_routeButton->setEnabled(true); + m_routeButton->setChecked(true); + blockSignals(false); + m_searchLocationButton->setChecked(false); + + // search location button might be already false, so we have to make sure the + // toggle action handler is called every time + searchLocationButtonToggled(false); + emit showPanelRequested(this); } @@ -176,5 +230,22 @@ void RoutingPanel::setRouteButtonDisabled() { qDebug() << __PRETTY_FUNCTION__; - m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty()); + m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty() + && !m_routeButton->isChecked()); +} + +void RoutingPanel::showResultsView() +{ + qDebug() << __PRETTY_FUNCTION__; + + m_views->setCurrentWidget(m_resultsView); + m_routeWaypointListView->clearItemSelection(); +} + +void RoutingPanel::showRoutingView() +{ + qDebug() << __PRETTY_FUNCTION__; + + m_views->setCurrentWidget(m_routingView); + m_locationListView->clearItemSelection(); } diff --git a/src/ui/routingpanel.h b/src/ui/routingpanel.h index bb433f5..45e8d18 100644 --- a/src/ui/routingpanel.h +++ b/src/ui/routingpanel.h @@ -67,6 +67,17 @@ protected: /******************************************************************************* * MEMBER FUNCTIONS AND SLOTS ******************************************************************************/ +private: + /** + * @brief Switch to search results view mode + */ + void showResultsView(); + + /** + * @brief Switch to routing instructions view mode + */ + void showRoutingView(); + private slots: /** * @brief Clears lists' selections. @@ -83,6 +94,11 @@ private slots: void populateLocationListView(const QList &locations); /** + * @brief Handler for route button toggling actions + */ + void routeButtonToggled(bool checked); + + /** * @brief Routes to selected location. * * Emits routeToLocation if location is selected from list. @@ -90,6 +106,11 @@ private slots: void routeToSelectedLocation(); /** + * @brief Handler for search button toggling actions + */ + void searchLocationButtonToggled(bool checked); + + /** * @brief Sets route to the panel. * * Appends route waypoint list with route segments. @@ -109,6 +130,11 @@ private slots: ******************************************************************************/ signals: /** + * @brief Emitted when route is cleared + */ + void clearRoute(); + + /** * @brief Signal for location item clicked. * * @param swBound south-west bound GeoCoordinate @@ -146,15 +172,17 @@ signals: * DATA MEMBERS ******************************************************************************/ private: - QLabel *m_locationListLabel; ///< Location list label + QLabel *m_resultsLabel; ///< Location list label - QPushButton *m_searchLocationButton; ///< Search location button + QStackedLayout *m_views; ///< Views - QWidget *m_locationListHeaderWidget; ///< Location list header widget + QWidget *m_resultsView; ///< Search results view widget + QWidget *m_routingView; ///< Routing instructions view widget ImageButton *m_routeButton; ///< Route to location button - LocationListView *m_locationListView; ///< Location list view - RouteWaypointListView *m_routeWaypointListView; ///< Route waypoint list view + ImageButton *m_searchLocationButton; ///< Search location button + LocationListView *m_locationListView; ///< Search results list view + RouteWaypointListView *m_routeWaypointListView; ///< Route instructions list view }; #endif // ROUTINGPANEL_H