Fix:gui/qml:Back/home buttons now work as expected
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 17 Mar 2010 10:38:36 +0000 (10:38 +0000)
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 17 Mar 2010 10:38:36 +0000 (10:38 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3025 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/qml/gui_qml.cpp
navit/navit/gui/qml/skins/navit/Cellar.qml
navit/navit/gui/qml/skins/navit/PageSettings.qml
navit/navit/gui/qml/skins/navit/PageSettingsTools.qml
navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml
navit/navit/gui/qml/skins/navit/main.qml

index 66f8be9..0e41377 100644 (file)
@@ -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)))
index 8936bbc..129a608 100644 (file)
@@ -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
     }
index 718ea02..50ff35b 100644 (file)
@@ -24,13 +24,13 @@ Rectangle {
         anchors.bottom: parent.verticalCenter; anchors.bottomMargin: 48;\r
         spacing: 64\r
         ButtonIcon {\r
-            id: btnDisplay; text: "Display"; icon: "gui_display.svg"; onClicked: { gui.returnSource="PageSettings.qml"; gui.setPage("PageSettingsDisplay.qml") }\r
+            id: btnDisplay; text: "Display"; icon: "gui_display.svg"; onClicked: gui.setPage("PageSettingsDisplay.qml")
         }\r
         ButtonIcon {\r
-            id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!");\r
+            id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!");
         }\r
         ButtonIcon {\r
-            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")
         }\r
     }\r
     Grid {\r
@@ -39,10 +39,10 @@ Rectangle {
         anchors.top: parent.verticalCenter; anchors.topMargin: 48;\r
         spacing: 64\r
         ButtonIcon {\r
-            id: btnRules; text: "Rules"; icon: "gui_rules.svg"; onClicked: { gui.returnSource="PageSettings.qml";gui.setPage("PageSettingsRules.qml") }\r
+            id: btnRules; text: "Rules"; icon: "gui_rules.svg"; onClicked: gui.setPage("PageSettingsRules.qml")
         }\r
         ButtonIcon {\r
-            id: btnTools; text: "Tools"; icon: "gui_tools.svg"; onClicked: { gui.returnSource="PageSettings.qml";gui.setPage("PageSettingsTools.qml") }\r
+            id: btnTools; text: "Tools"; icon: "gui_tools.svg"; onClicked: gui.setPage("PageSettingsTools.qml")
         }\r
     }\r
 \r
index d21d026..a7e8f0f 100644 (file)
@@ -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")
         }
     }
 
index 31a2c6f..f5e9527 100644 (file)
@@ -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;
         }
index 16ea874..ff9a0c1 100644 (file)
@@ -8,7 +8,6 @@ Rectangle {
     opacity: 0\r
 \r
     function pageOpen() {\r
-       gui.returnSource="NoReturnTicket";\r
         page.opacity = 1;\r
     }\r
     \r
@@ -25,13 +24,13 @@ Rectangle {
         anchors.bottom: parent.verticalCenter; anchors.bottomMargin: 48;\r
         spacing: 64\r
         ButtonIcon {\r
-            id: btnRoute; text: "Route"; icon: "cursor.svg";  onClicked: { gui.returnSource="main.qml";gui.setPage("PageRoute.qml") }\r
+            id: btnRoute; text: "Route"; icon: "cursor.svg";  onClicked: gui.setPage("PageRoute.qml")\r
         }\r
         ButtonIcon {\r
-            id: btnNavigation; text: "Navigation"; icon: "nav_destination_wh.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageNavigation.qml") }\r
+            id: btnNavigation; text: "Navigation"; icon: "nav_destination_wh.svg"; onClicked: gui.setPage("PageNavigation.qml")\r
         }\r
         ButtonIcon {\r
-            id: btnSettings; text: "Settings"; icon: "gui_settings.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageSettings.qml") }\r
+            id: btnSettings; text: "Settings"; icon: "gui_settings.svg"; onClicked: gui.setPage("PageSettings.qml")\r
         }\r
     }\r
 \r
@@ -41,7 +40,7 @@ Rectangle {
         anchors.top: parent.verticalCenter; anchors.topMargin: 48;\r
         spacing: 64\r
         ButtonIcon {\r
-            id: btnAbout; text: "About"; icon: "gui_about.svg"; onClicked: { gui.returnSource="main.qml";gui.setPage("PageAbout.qml") }\r
+            id: btnAbout; text: "About"; icon: "gui_about.svg"; onClicked: gui.setPage("PageAbout.qml") \r
         }\r
         ButtonIcon {\r
             id: btnQuit; text: "Quit"; icon: "gui_quit.svg"; onClicked: navit.quit();\r