From 829a19209e97792432bcbc1c343e6a3ca47d0154 Mon Sep 17 00:00:00 2001 From: akashihi Date: Tue, 30 Mar 2010 13:54:03 +0000 Subject: [PATCH] Add:gui/qml:Added command processing git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3104 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/gui_qml.cpp | 59 +++++++++++++++++++++++------ navit/navit/gui/qml/skins/navit/Makefile.am | 2 +- navit/navit/gui/qml/skins/navit/command.qml | 29 ++++++++++++++ 3 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 navit/navit/gui/qml/skins/navit/command.qml diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 6f81ed4..0930862 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -28,6 +28,7 @@ #include "track.h" #include "search.h" #include "bookmarks.h" +#include "command.h" //WORKAOUND for the c/c++ compatibility issues. //range is defined inside of struct attr so it is invisible in c++ @@ -545,6 +546,8 @@ class NGQProxyGui : public NGQProxy { Q_PROPERTY(QString iconPath READ iconPath CONSTANT); Q_PROPERTY(QString returnSource READ returnSource WRITE setReturnSource); + Q_PROPERTY(QString commandFunction READ commandFunction CONSTANT); + Q_PROPERTY(QString localeName READ localeName CONSTANT); Q_PROPERTY(QString langName READ langName CONSTANT); Q_PROPERTY(QString ctryName READ ctryName CONSTANT); @@ -564,11 +567,15 @@ public: this->object->currentPoint = new NGQPoint(this->object,p,type,NULL); this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); } + void processCommand(QString function) { + this->function=function; + this->setPage("command.qml",true); + } signals: void widthSignal(int); void heightSignal(int); public slots: - void setPage(QString page) { + void setPage(QString page,bool hidden=false) { dbg(0,"Page is: %s\n",page.toStdString().c_str()); this->source+="/"+page; @@ -601,15 +608,18 @@ public slots: #else this->object->guiWidget->setSource(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); #endif - this->object->guiWidget->show(); - this->object->switcherWidget->addWidget(this->object->guiWidget); - this->object->switcherWidget->setCurrentWidget(this->object->guiWidget); + if (!hidden) { + //we render commands page hidden, so the screen doesn't flicks. + this->object->guiWidget->show(); + this->object->switcherWidget->addWidget(this->object->guiWidget); + this->object->switcherWidget->setCurrentWidget(this->object->guiWidget); + } } void backToMap() { if (this->object->graphicsWidget) { this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason); + this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget); this->object->graphicsWidget->show(); - this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget); } } void backToPrevPage() { @@ -648,6 +658,9 @@ public slots: this->object->h=h; this->heightSignal(h); } + QString commandFunction() { + return this->function; + } //Locale properties QString localeName() { @@ -682,6 +695,7 @@ protected: int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); } private: QString source; + QString function; }; //Main window class for resizeEvent handling @@ -830,12 +844,6 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) return 0; } -static void gui_qml_disable_suspend(struct gui_priv *this_) -{ -/* if (this->win->disable_suspend) - this->win->disable_suspend(this->win);*/ -} - static int gui_qml_get_attr(struct gui_priv *this_, enum attr_type type, struct attr *attr) { @@ -885,12 +893,35 @@ struct gui_methods gui_qml_methods = { NULL, NULL, NULL, - gui_qml_disable_suspend, + NULL, gui_qml_get_attr, NULL, gui_qml_set_attr, }; +static void +gui_qml_command(struct gui_priv *this_, char *function, struct attr **in, struct attr ***out, int *valid) { + struct attr **curr=in; + struct attr *attr; + if (!strcasecmp(function,"command")) { + if( (attr=attr_search(in,NULL,attr_command))) { + //The value setting code in command.c is buggy + //so i disable this fucntionality for a while + //function=attr->u.str; + } + } + while (curr && *curr) { + dbg(0,"attr type is: %s\n",attr_to_name((*curr)->type)); + curr++; + } + this_->guiProxy->processCommand(function); +} + +static struct command_table commands[] = { + {"menu",command_cast(gui_qml_command)}, + {"fullscreen",command_cast(gui_qml_command)}, + {"command",command_cast(gui_qml_command)}, +}; static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui) { @@ -946,6 +977,10 @@ static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth this_->icon_src=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/xpm/",NULL); } + if ((attr=attr_search(attrs, NULL, attr_callback_list))) { + command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this_); + } + this_->cbl=callback_list_new(); return this_; diff --git a/navit/navit/gui/qml/skins/navit/Makefile.am b/navit/navit/gui/qml/skins/navit/Makefile.am index bc683c2..25c7c16 100644 --- a/navit/navit/gui/qml/skins/navit/Makefile.am +++ b/navit/navit/gui/qml/skins/navit/Makefile.am @@ -4,7 +4,7 @@ SKIN = navit qmldir=$(skinsdir)/$(SKIN) -qml_DATA = ButtonIcon.qml ToggleSwitch.qml ListSelector.qml Slider.qml Cellar.qml main.qml point.qml PageAbout.qml PageBookmarksAdd.qml PageBookmarks.qml PageNavigation.qml PageRoute.qml PageSearch.qml PageSearchSelector.qml PageSettingsDisplay.qml PageSettingsLocale.qml PageSettings.qml PageSettingsRules.qml PageSettingsTools.qml PageSettingsVehicle.qml +qml_DATA = ButtonIcon.qml ToggleSwitch.qml ListSelector.qml Slider.qml Cellar.qml main.qml point.qml command.qml PageAbout.qml PageBookmarksAdd.qml PageBookmarks.qml PageNavigation.qml PageRoute.qml PageSearch.qml PageSearchSelector.qml PageSettingsDisplay.qml PageSettingsLocale.qml PageSettings.qml PageSettingsRules.qml PageSettingsTools.qml PageSettingsVehicle.qml qml_DATA += background.svg knob.svg do_button_subst = sed -e 's,matchProperties,properties,g' \ diff --git a/navit/navit/gui/qml/skins/navit/command.qml b/navit/navit/gui/qml/skins/navit/command.qml new file mode 100644 index 0000000..f03a7fd --- /dev/null +++ b/navit/navit/gui/qml/skins/navit/command.qml @@ -0,0 +1,29 @@ + +import Qt 4.6 + +Rectangle { + id: page + + function pageOpen(command) { + if ( command=="menu") { + gui.returnSource=""; + gui.setPage("main.qml"); + } + if (command=="fullscreen") { + if (gui.getAttr("fullscreen") == "1") { + gui.setAttr("fullscreen",0) + } else { + gui.setAttr("fullscreen",1) + } + gui.backToMap(); + } + if (command=="quit") { + navit.quit(); + } + + } + + Component.onCompleted: pageOpen(gui.commandFunction); + + Text { id: myText; anchors.centerIn: parent; text: "Hi, i'm Navit!"; color: "Black"; font.pointSize: gui.height/32 } +} -- 2.7.4