From 61c1a395ddf45d18eb172bab6766cced4f73c5fd Mon Sep 17 00:00:00 2001 From: akashihi Date: Tue, 23 Mar 2010 12:35:57 +0000 Subject: [PATCH] Add:gui/qml:Added country selector git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3076 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/gui_qml.cpp | 147 ++++++++++++++++++++- navit/navit/gui/qml/skins/navit/PageRoute.qml | 2 +- navit/navit/gui/qml/skins/navit/PageSearch.qml | 47 +++++++ .../gui/qml/skins/navit/PageSearchSelector.qml | 36 +++++ 4 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 navit/navit/gui/qml/skins/navit/PageSearch.qml create mode 100644 navit/navit/gui/qml/skins/navit/PageSearchSelector.qml diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 721f20e..508a581 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -24,6 +24,9 @@ #include "transform.h" #include "mapset.h" #include "route.h" +#include "country.h" +#include "track.h" +#include "search.h" //WORKAOUND for the c/c++ compatibility issues. //range is defined inside of struct attr so it is invisible in c++ @@ -50,7 +53,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 + int lazy; //When TRUE - menu state will not be changed during map/menu switches, FALSE - menu will be always reset to main.qml //Interface stuff struct callback_list *cbl; @@ -67,6 +70,7 @@ struct gui_priv { class NGQProxyGui* guiProxy; class NGQProxyNavit* navitProxy; class NGQProxyVehicle* vehicleProxy; + class NGQProxySearch* searchProxy; class NGQPoint* currentPoint; }; @@ -74,6 +78,145 @@ struct gui_priv { #include "ngqpoint.h" //Proxy classes +class NGQProxySearch : public NGQProxy { + Q_OBJECT; + + Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal); + Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal); + + Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext); + +public: + NGQProxySearch(struct gui_priv* this_,QObject* parent) : NGQProxy(this_,parent) { + struct attr search_attr, country_name, country_iso2, *country_attr; + struct item *item; + struct country_search *cs; + struct tracking *tracking; + struct search_list_result *res; + + this->sl=search_list_new(navit_get_mapset(this->object->nav)); + this->search_context="country"; + + country_attr=country_default(); + tracking=navit_get_tracking(this->object->nav); + if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL)) + country_attr=&search_attr; + if (country_attr) { + cs=country_search_new(country_attr, 0); + item=country_search_get_item(cs); + if (item && item_attr_get(item, attr_country_name, &country_name)) { + search_attr.type=attr_country_all; + dbg(0,"country %s\n", country_name.u.str); + this->country_name=QString::fromLocal8Bit(country_name.u.str); + search_attr.u.str=country_name.u.str; + search_list_search(this->sl, &search_attr, 0); + while((res=search_list_get_result(this->sl))); + if (item_attr_get(item, attr_country_iso2, &country_iso2)) { + this->country_iso2=QString::fromLocal8Bit(country_iso2.u.str); + } + } + country_search_destroy(cs); + } else { + dbg(0,"warning: no default country found\n"); + if (!this->country_iso2.isEmpty()) { + dbg(0,"attempting to use country '%s'\n",this->country_iso2.toStdString().c_str()); + search_attr.type=attr_country_iso2; + search_attr.u.str=(char*)this->country_iso2.toStdString().c_str(); + search_list_search(this->sl, &search_attr, 0); + while((res=search_list_get_result(this->sl))); + } + } + } + +signals: + void countryNameSignal(QString); + void countryISO2Signal(QString); + +public slots: + QString getAttrList(const QString &attr_name) { + NGQStandardItemModel* ret=new NGQStandardItemModel(this); + struct attr attr; + struct search_list_result *res; + int counter=0; + QString currentValue, retId; + + if (this->search_context=="country") { + currentValue=this->country_name; + attr.type=attr_country_name; + attr.u.str=""; + } + if (this->search_context=="town") { + currentValue=this->town_name; + attr.type=attr_town_or_district_name; + attr.u.str=""; + } + + search_list_search(this->sl,&attr,1); + + while ((res=search_list_get_result(this->sl))) { + QStandardItem* curItem=new QStandardItem(); + //Result processing depends on search type + if (this->search_context=="country") { + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + curItem->setData(QString::fromLocal8Bit(res->country->name),NGQStandardItemModel::ItemName); + curItem->setData(QString("country_%1%2").arg(res->country->iso2).arg(".svgz"),NGQStandardItemModel::ItemIcon); + if (this->country_name==QString::fromLocal8Bit(res->country->name)) { + retId.setNum(counter); + } + } + counter++; + ret->appendRow(curItem); + } + + this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); + + return retId; + } + QString countryName() { + return this->country_name; + } + void setCountryName(QString countryName) { + this->country_name=countryName; + struct attr attr; + struct search_list_result *res; + + //We need to update ISO2 + attr.type=attr_country_name; + attr.u.str=countryName.toLocal8Bit().data(); + search_list_search(this->sl,&attr,0); + while ((res=search_list_get_result(this->sl))) { + this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2)); + } + + countryNameSignal(countryName); + } + QString countryISO2() { + return this->country_iso2; + } + void setCountryISO2(QString countryISO2) { + this->country_iso2=countryISO2; + countryISO2Signal(countryISO2); + } + QString searchContext() { + return this->search_context; + } + void setSearchContext(QString searchContext) { + this->search_context=searchContext; + } + +protected: + virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) { + return 0; + } + virtual int setAttrFunc(struct attr *attr) { + return 0; + } +private: + struct search_list *sl; + QString search_context; + QString country_iso2,country_name,town_name; +}; + class NGQProxyGui : public NGQProxy { Q_OBJECT; @@ -421,6 +564,8 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) this_->guiWidget->rootContext()->setContextProperty("navit",this_->navitProxy); this_->vehicleProxy = new NGQProxyVehicle(this_,this_->mainWindow); this_->guiWidget->rootContext()->setContextProperty("vehicle",this_->vehicleProxy); + this_->searchProxy = new NGQProxySearch(this_,this_->mainWindow); + this_->guiWidget->rootContext()->setContextProperty("search",this_->searchProxy); //Check, if we have compatible graphics this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget"); diff --git a/navit/navit/gui/qml/skins/navit/PageRoute.qml b/navit/navit/gui/qml/skins/navit/PageRoute.qml index 7f3ea65..edf404a 100644 --- a/navit/navit/gui/qml/skins/navit/PageRoute.qml +++ b/navit/navit/gui/qml/skins/navit/PageRoute.qml @@ -39,7 +39,7 @@ Rectangle { anchors.top: parent.verticalCenter; anchors.topMargin: gui.height/16; spacing: gui.width/12 ButtonIcon { - id: btnAbout; text: "Search"; icon: "gui_town.svg"; onClicked: console.log("Implement me!"); + id: btnAbout; text: "Search"; icon: "gui_town.svg"; onClicked: gui.setPage("PageSearch.qml"); } ButtonIcon { id: btnQuit; text: "POIs"; icon: "attraction.svg"; onClicked: console.log("Implement me!"); diff --git a/navit/navit/gui/qml/skins/navit/PageSearch.qml b/navit/navit/gui/qml/skins/navit/PageSearch.qml new file mode 100644 index 0000000..80e0283 --- /dev/null +++ b/navit/navit/gui/qml/skins/navit/PageSearch.qml @@ -0,0 +1,47 @@ +import Qt 4.6 + +Rectangle { + id: page + + width: gui.width; height: gui.height + color: "Black" + opacity: 0 + + function pageOpen() { + page.opacity = 1; + } + + Component.onCompleted: pageOpen(); + + opacity: Behavior { + NumberAnimation { id: opacityAnimation; duration: 300; alwaysRunToEnd: true } + } + + Grid { + columns: 2;rows: 1 + anchors.horizontalCenter: parent.horizontalCenter; + anchors.bottom: parent.verticalCenter; anchors.bottomMargin: gui.height/16; + spacing: gui.width/12 + ButtonIcon { + id: btnCountry; text: search.countryName; icon: "country_"+search.countryISO2+".svgz"; onClicked: { search.searchContext="country"; gui.setPage("PageSearchSelector.qml"); } + } + ButtonIcon { + id: btnCity; text: "City"; icon: "gui_bookmark.svg"; onClicked: { search.searchContext="town"; gui.setPage("PageSearchSelector.qml"); } + } + } + + Grid { + columns: 2;rows: 1 + anchors.horizontalCenter: parent.horizontalCenter; + anchors.top: parent.verticalCenter; anchors.topMargin: gui.height/16; + spacing: gui.width/12 + ButtonIcon { + id: btnStreet; text: "Street"; icon: "gui_town.svg"; onClicked: console.log("Implement me!"); + } + ButtonIcon { + id: btnAddress; text: "Address"; icon: "attraction.svg"; onClicked: console.log("Implement me!"); + } + } + + Cellar {anchors.bottom: page.bottom; anchors.horizontalCenter: page.horizontalCenter; width: page.width } +} diff --git a/navit/navit/gui/qml/skins/navit/PageSearchSelector.qml b/navit/navit/gui/qml/skins/navit/PageSearchSelector.qml new file mode 100644 index 0000000..dd7319f --- /dev/null +++ b/navit/navit/gui/qml/skins/navit/PageSearchSelector.qml @@ -0,0 +1,36 @@ + +import Qt 4.6 + +Rectangle { + id: page + + width: gui.width; height: gui.height + color: "Black" + opacity: 0 + + function setSearchResult() { + if (search.searchContext=="country") { + search.countryName=layoutList.value; + gui.backToPrevPage(); + } + } + + function pageOpen() { + page.opacity = 1; + } + + Component.onCompleted: pageOpen(); + + opacity: Behavior { + NumberAnimation { id: opacityAnimation; duration: 300; alwaysRunToEnd: true } + } + + ListSelector { + id:layoutList; text: search.searchContext; itemId: search.getAttrList(search.searchContext); onChanged: setSearchResult() + anchors.top: parent.top; + anchors.left: parent.left; anchors.leftMargin: 3 + anchors.topMargin: gui.height/16; anchors.leftMargin: gui.width/32 + } + + Cellar {anchors.bottom: page.bottom; anchors.horizontalCenter: page.horizontalCenter; width: page.width } +} -- 2.7.4