From 3f8e3ed62f6afa14772e53ec309734d2476f02d6 Mon Sep 17 00:00:00 2001 From: akashihi Date: Wed, 17 Mar 2010 10:38:36 +0000 Subject: [PATCH] Fix:gui/qml:Back/home buttons now work as expected git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3025 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/gui_qml.cpp | 40 +++++++++++++++++----- navit/navit/gui/qml/skins/navit/Cellar.qml | 10 +++--- navit/navit/gui/qml/skins/navit/PageSettings.qml | 10 +++--- .../gui/qml/skins/navit/PageSettingsTools.qml | 2 +- .../gui/qml/skins/navit/PageSettingsVehicle.qml | 2 +- navit/navit/gui/qml/skins/navit/main.qml | 9 +++-- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 66f8be9..0e41377 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -46,6 +46,7 @@ struct gui_priv { char* icon_src; int radius; int pitch; + int lazy; //When TRUE - menu state will not be changed during map/menu switches, FALSE - menu will be always reseted to main.qml //Interface stuff struct callback_list *cbl; @@ -79,21 +80,33 @@ class NGQProxyGui : public NGQProxy { public: NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) { - this->source=QString("NoReturnTicket"); + this->source=QString(""); } public slots: void setPage(QString page) { + dbg(0,"Page is: %s\n",page.toStdString().c_str()); + this->source+="/"+page; this->object->guiWidget->setUrl(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); this->object->guiWidget->execute(); this->object->guiWidget->show(); - dbg(0,"Page is: %s\n",page.toStdString().c_str()); } void backToMap() { if (this->object->graphicsWidget) { this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget); } } + void backToPrevPage() { + QStringList returnList=this->source.split(QString("/"), QString::SkipEmptyParts); + QString returnPage; + if (returnList.size()>1) { + returnList.takeLast();//Remove current element + returnPage=returnList.takeLast(); //Set previous element as return page and remove it from the list + } + this->source=returnList.join(QString("/")); + this->source.prepend(QString("/")); + this->setPage(returnPage); + } //Properties QString iconPath() { @@ -291,6 +304,16 @@ static void gui_qml_button(void *data, int pressed, int button, struct point *p) } if ( button == 1 && this_->menu_on_map_click ) { + if (!this_->lazy) { + this_->guiProxy->setReturnSource(QString("")); + this_->guiProxy->setPage("main.qml"); + } + this_->switcherWidget->setCurrentWidget(this_->guiWidget); + } + /* There is a special 'popup' feature in navit, that makes all 'click-on-point' related stuff + but it looks VERY unflexible, so i'm not able to use it. I believe we need + to re-design the popup feature or remove it at all */ + if ( button == 3 && this_->menu_on_map_click ) { this_->switcherWidget->setCurrentWidget(this_->guiWidget); } } @@ -303,7 +326,6 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) { struct window *win; struct transformation *trans=navit_get_trans(this_->nav); - struct QmlView *view; this_->gra=gra; @@ -327,16 +349,15 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) this_->mainWindow->setCentralWidget(this_->switcherWidget); //Create gui widget - view = new QmlView(NULL); - this_->guiWidget = view; + this_->guiWidget = new QmlView(NULL); //Create proxy object and bind them to gui widget this_->guiProxy = new NGQProxyGui(this_,this_->mainWindow); - view->rootContext()->setContextProperty("gui",this_->guiProxy); + this_->guiWidget->rootContext()->setContextProperty("gui",this_->guiProxy); this_->navitProxy = new NGQProxyNavit(this_,this_->mainWindow); - view->rootContext()->setContextProperty("navit",this_->navitProxy); + this_->guiWidget->rootContext()->setContextProperty("navit",this_->navitProxy); this_->vehicleProxy = new NGQProxyVehicle(this_,this_->mainWindow); - view->rootContext()->setContextProperty("vehicle",this_->vehicleProxy); + this_->guiWidget->rootContext()->setContextProperty("vehicle",this_->vehicleProxy); //Check, if we have compatible graphics this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget"); @@ -451,6 +472,9 @@ static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth this_->pitch = 20; //Default value if( (attr=attr_search(attrs,NULL,attr_pitch))) this_->pitch=attr->u.num; + this_->lazy = 1; //YES by default + if( (attr=attr_search(attrs,NULL,attr_lazy))) + this_->lazy=attr->u.num; if( (attr=attr_search(attrs,NULL,attr_width))) this_->w=attr->u.num; if( (attr=attr_search(attrs,NULL,attr_height))) diff --git a/navit/navit/gui/qml/skins/navit/Cellar.qml b/navit/navit/gui/qml/skins/navit/Cellar.qml index 8936bbc..129a608 100644 --- a/navit/navit/gui/qml/skins/navit/Cellar.qml +++ b/navit/navit/gui/qml/skins/navit/Cellar.qml @@ -2,11 +2,11 @@ import Qt 4.6 Rectangle { - function hideButtons() { - if ( gui.returnSource=="main.qml" ) { + function hideButtons() { + if ( gui.returnSource.split('/').length < 4 ) { btnBack.opacity=0; } - if ( gui.returnSource == "NoReturnTicket" ) { + if ( gui.returnSource == "/main.qml" ) { btnHome.opacity=0; btnBack.opacity=0; } @@ -21,13 +21,13 @@ Rectangle { } ButtonIcon { - id: btnHome; icon: "gui_home.svg"; text: "Home"; onClicked: gui.setPage("main.qml"); + id: btnHome; icon: "gui_home.svg"; text: "Home"; onClicked: { gui.returnSource=""; gui.setPage("main.qml"); } anchors.horizontalCenter: parent.horizontalCenter; anchors.leftMargin: 3 anchors.bottom: parent.bottom; anchors.bottomMargin: 3 } ButtonIcon { - id: btnBack; icon: "gui_arrow_left.svg"; text: "Back"; onClicked: gui.setPage(gui.returnSource); + id: btnBack; icon: "gui_arrow_left.svg"; text: "Back"; onClicked: gui.backToPrevPage(); anchors.right: parent.right; anchors.leftMargin: 3 anchors.bottom: parent.bottom; anchors.bottomMargin: 3 } diff --git a/navit/navit/gui/qml/skins/navit/PageSettings.qml b/navit/navit/gui/qml/skins/navit/PageSettings.qml index 718ea02..50ff35b 100644 --- a/navit/navit/gui/qml/skins/navit/PageSettings.qml +++ b/navit/navit/gui/qml/skins/navit/PageSettings.qml @@ -24,13 +24,13 @@ Rectangle { anchors.bottom: parent.verticalCenter; anchors.bottomMargin: 48; spacing: 64 ButtonIcon { - id: btnDisplay; text: "Display"; icon: "gui_display.svg"; onClicked: { gui.returnSource="PageSettings.qml"; gui.setPage("PageSettingsDisplay.qml") } + id: btnDisplay; text: "Display"; icon: "gui_display.svg"; onClicked: gui.setPage("PageSettingsDisplay.qml") } ButtonIcon { - id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!"); + id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!"); } ButtonIcon { - id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: { gui.returnSource="PageSettings.qml"; gui.setPage("PageSettingsVehicle.qml") } + id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: gui.setPage("PageSettingsVehicle.qml") } } Grid { @@ -39,10 +39,10 @@ Rectangle { anchors.top: parent.verticalCenter; anchors.topMargin: 48; spacing: 64 ButtonIcon { - id: btnRules; text: "Rules"; icon: "gui_rules.svg"; onClicked: { gui.returnSource="PageSettings.qml";gui.setPage("PageSettingsRules.qml") } + id: btnRules; text: "Rules"; icon: "gui_rules.svg"; onClicked: gui.setPage("PageSettingsRules.qml") } ButtonIcon { - id: btnTools; text: "Tools"; icon: "gui_tools.svg"; onClicked: { gui.returnSource="PageSettings.qml";gui.setPage("PageSettingsTools.qml") } + id: btnTools; text: "Tools"; icon: "gui_tools.svg"; onClicked: gui.setPage("PageSettingsTools.qml") } } diff --git a/navit/navit/gui/qml/skins/navit/PageSettingsTools.qml b/navit/navit/gui/qml/skins/navit/PageSettingsTools.qml index d21d026..a7e8f0f 100644 --- a/navit/navit/gui/qml/skins/navit/PageSettingsTools.qml +++ b/navit/navit/gui/qml/skins/navit/PageSettingsTools.qml @@ -25,7 +25,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter; spacing: 64 ButtonIcon { - id: btnDisplay; text: "Locale"; icon: "gui_actions.svg"; onClicked: { gui.returnSource="PageSettingsTools.qml";gui.setPage("PageSettingsLocale.qml") } + id: btnDisplay; text: "Locale"; icon: "gui_actions.svg"; onClicked: gui.setPage("PageSettingsLocale.qml") } } diff --git a/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml b/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml index 31a2c6f..f5e9527 100644 --- a/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml +++ b/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml @@ -25,7 +25,7 @@ Rectangle { } ButtonIcon { - id: btnVehicle; text: "Vehicle options"; icon: "gui_vehicle.svg"; onClicked: { gui.returnSource="PageSettingsVehicle.qml"; gui.setPage("PageSettingsVehicleOptions.qml") } + id: btnVehicle; text: "Vehicle options"; icon: "gui_vehicle.svg"; onClicked: gui.setPage("PageSettingsVehicleOptions.qml") anchors.top: vehicleList.bottom; anchors.topMargin: 48 anchors.right: page.horizontalCenter; } diff --git a/navit/navit/gui/qml/skins/navit/main.qml b/navit/navit/gui/qml/skins/navit/main.qml index 16ea874..ff9a0c1 100644 --- a/navit/navit/gui/qml/skins/navit/main.qml +++ b/navit/navit/gui/qml/skins/navit/main.qml @@ -8,7 +8,6 @@ Rectangle { opacity: 0 function pageOpen() { - gui.returnSource="NoReturnTicket"; page.opacity = 1; } @@ -25,13 +24,13 @@ Rectangle { anchors.bottom: parent.verticalCenter; anchors.bottomMargin: 48; spacing: 64 ButtonIcon { - id: btnRoute; text: "Route"; icon: "cursor.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageRoute.qml") } + id: btnRoute; text: "Route"; icon: "cursor.svg"; onClicked: gui.setPage("PageRoute.qml") } ButtonIcon { - id: btnNavigation; text: "Navigation"; icon: "nav_destination_wh.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageNavigation.qml") } + id: btnNavigation; text: "Navigation"; icon: "nav_destination_wh.svg"; onClicked: gui.setPage("PageNavigation.qml") } ButtonIcon { - id: btnSettings; text: "Settings"; icon: "gui_settings.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageSettings.qml") } + id: btnSettings; text: "Settings"; icon: "gui_settings.svg"; onClicked: gui.setPage("PageSettings.qml") } } @@ -41,7 +40,7 @@ Rectangle { anchors.top: parent.verticalCenter; anchors.topMargin: 48; spacing: 64 ButtonIcon { - id: btnAbout; text: "About"; icon: "gui_about.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageAbout.qml") } + id: btnAbout; text: "About"; icon: "gui_about.svg"; onClicked: gui.setPage("PageAbout.qml") } ButtonIcon { id: btnQuit; text: "Quit"; icon: "gui_quit.svg"; onClicked: navit.quit(); -- 2.7.4