diff options
author | akashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-03-30 11:04:03 +0000 |
---|---|---|
committer | akashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-03-30 11:04:03 +0000 |
commit | 1ff495291059c3d31652697924c8be28459a3311 (patch) | |
tree | 62b48d6a5ec6d9463356b43256e7d2972de1ebac | |
parent | 8e21ead1c1451900f9e5fbef3be4d4f0a2d22861 (diff) | |
download | navit-svn-1ff495291059c3d31652697924c8be28459a3311.tar.gz |
Add:gui/qml:Added Qt 4.7 support
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/navit@3101 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | gui/qml/gui_qml.cpp | 320 | ||||
-rw-r--r-- | gui/qml/skins/navit/ButtonIcon.qml.in (renamed from gui/qml/skins/navit/ButtonIcon.qml) | 0 | ||||
-rw-r--r-- | gui/qml/skins/navit/Makefile.am | 19 | ||||
-rw-r--r-- | gui/qml/skins/navit/PageSettingsDisplay.qml | 4 | ||||
-rw-r--r-- | gui/qml/skins/navit/PageSettingsRules.qml | 6 | ||||
-rw-r--r-- | gui/qml/skins/navit/ToggleSwitch.qml.in (renamed from gui/qml/skins/navit/ToggleSwitch.qml) | 14 |
6 files changed, 202 insertions, 161 deletions
diff --git a/gui/qml/gui_qml.cpp b/gui/qml/gui_qml.cpp index b3039f4f..6f81ed4c 100644 --- a/gui/qml/gui_qml.cpp +++ b/gui/qml/gui_qml.cpp @@ -63,7 +63,13 @@ struct gui_priv { struct graphics *gra; struct QMainWindow *mainWindow; QWidget *graphicsWidget; - QmlView *guiWidget; +#if QT_VERSION < 0x040700 + QmlView *guiWidget; + QmlView *prevGuiWidget; +#else + QDeclarativeView *guiWidget; + QDeclarativeView *prevGuiWidget; +#endif QStackedWidget *switcherWidget; struct callback *button_cb; @@ -267,138 +273,6 @@ private: QString country_iso2,country_name,town_name,street_name; }; -class NGQProxyGui : public NGQProxy { - Q_OBJECT; - - Q_PROPERTY(QString iconPath READ iconPath CONSTANT); - Q_PROPERTY(QString returnSource READ returnSource WRITE setReturnSource); - - Q_PROPERTY(QString localeName READ localeName CONSTANT); - Q_PROPERTY(QString langName READ langName CONSTANT); - Q_PROPERTY(QString ctryName READ ctryName CONSTANT); - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false); - Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false); - -public: - NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) { - this->source=QString(""); - } - - void setNewPoint(struct point* p,NGQPointTypes type) { - if (this->object->currentPoint!=NULL) { - delete this->object->currentPoint; - } - this->object->currentPoint = new NGQPoint(this->object,p,type,NULL); - this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); - } -signals: - void widthSignal(int); - void heightSignal(int); -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(); - } - void backToMap() { - if (this->object->graphicsWidget) { - this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason); - 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() { - return QString(this->object->icon_src); - } - QString returnSource() { - return this->source; - } - void setReturnSource(QString returnSource) { - this->source=returnSource; - } - int width() { - return this->object->w; - } - void setWidth(int w) { - this->object->w=w; - this->widthSignal(w); - } - int height() { - return this->object->h; - } - void setHeight(int h) { - this->object->h=h; - this->heightSignal(h); - } - - //Locale properties - QString localeName() { - return QString()+"LANG="+getenv("LANG"); - } - QString langName() { -#ifdef HAVE_API_WIN32_BASE - wchar_t wstr[32]; - char str[32]; - - GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wstr, sizeof(wstr)); - WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); - return QString()+"LOCALE_SABBREVLANGNAME="+str; -#else - return QString(); -#endif - } - QString ctryName() { -#ifdef HAVE_API_WIN32_BASE - wchar_t wstr[32]; - char str[32]; - - GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wstr, sizeof(wstr)); - WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); - return QString()+"LOCALE_SABBREVCTRYNAME="+str; -#else - return QString(); -#endif - } -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return gui_get_attr(this->object->gui, type, attr, iter); } - int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); } -private: - QString source; -}; - -class NGQProxyVehicle : public NGQProxy { - Q_OBJECT; - -public: - NGQProxyVehicle(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; - -public slots: - -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return vehicle_get_attr(this->object->currVehicle, type, attr, iter); } - int setAttrFunc(struct attr* attr) {return vehicle_set_attr(this->object->currVehicle,attr); } - struct attr_iter* getIterFunc() { return vehicle_attr_iter_new(); }; - void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); }; - -private: - -}; - class NGQProxyBookmarks : public NGQProxy { Q_OBJECT; @@ -560,6 +434,23 @@ protected: private: QString current_path; }; +class NGQProxyVehicle : public NGQProxy { + Q_OBJECT; + +public: + NGQProxyVehicle(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; + +public slots: + +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return vehicle_get_attr(this->object->currVehicle, type, attr, iter); } + int setAttrFunc(struct attr* attr) {return vehicle_set_attr(this->object->currVehicle,attr); } + struct attr_iter* getIterFunc() { return vehicle_attr_iter_new(); }; + void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); }; + +private: + +}; class NGQProxyNavit : public NGQProxy { Q_OBJECT; @@ -648,6 +539,151 @@ private: }; +class NGQProxyGui : public NGQProxy { + Q_OBJECT; + + Q_PROPERTY(QString iconPath READ iconPath CONSTANT); + Q_PROPERTY(QString returnSource READ returnSource WRITE setReturnSource); + + Q_PROPERTY(QString localeName READ localeName CONSTANT); + Q_PROPERTY(QString langName READ langName CONSTANT); + Q_PROPERTY(QString ctryName READ ctryName CONSTANT); + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false); + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false); + +public: + NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) { + this->source=QString(""); + } + + void setNewPoint(struct point* p,NGQPointTypes type) { + if (this->object->currentPoint!=NULL) { + delete this->object->currentPoint; + } + this->object->currentPoint = new NGQPoint(this->object,p,type,NULL); + this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); + } +signals: + void widthSignal(int); + void heightSignal(int); +public slots: + void setPage(QString page) { + dbg(0,"Page is: %s\n",page.toStdString().c_str()); + this->source+="/"+page; + + //Reload widget + if (this->object->guiWidget) { + this->object->switcherWidget->removeWidget(this->object->guiWidget); + if (this->object->prevGuiWidget) { + delete this->object->prevGuiWidget; + } + this->object->prevGuiWidget=this->object->guiWidget; + } +#if QT_VERSION < 0x040700 + this->object->guiWidget = new QmlView(NULL); + this->object->guiWidget->setContentResizable(true); +#else + this->object->guiWidget = new QDeclarativeView(NULL); + this->object->guiWidget->setResizeMode(QDeclarativeView::SizeRootObjectToView); +#endif + + this->object->guiWidget->rootContext()->setContextProperty("gui",this->object->guiProxy); + this->object->guiWidget->rootContext()->setContextProperty("navit",this->object->navitProxy); + this->object->guiWidget->rootContext()->setContextProperty("vehicle",this->object->vehicleProxy); + this->object->guiWidget->rootContext()->setContextProperty("search",this->object->searchProxy); + this->object->guiWidget->rootContext()->setContextProperty("bookmarks",this->object->bookmarksProxy); + this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); + +#if QT_VERSION < 0x040700 + this->object->guiWidget->setUrl(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); + this->object->guiWidget->execute(); +#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); + } + void backToMap() { + if (this->object->graphicsWidget) { + this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason); + this->object->graphicsWidget->show(); + 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() { + return QString(this->object->icon_src); + } + QString returnSource() { + return this->source; + } + void setReturnSource(QString returnSource) { + this->source=returnSource; + } + int width() { + return this->object->w; + } + void setWidth(int w) { + this->object->w=w; + this->widthSignal(w); + } + int height() { + return this->object->h; + } + void setHeight(int h) { + this->object->h=h; + this->heightSignal(h); + } + + //Locale properties + QString localeName() { + return QString()+"LANG="+getenv("LANG"); + } + QString langName() { +#ifdef HAVE_API_WIN32_BASE + wchar_t wstr[32]; + char str[32]; + + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wstr, sizeof(wstr)); + WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); + return QString()+"LOCALE_SABBREVLANGNAME="+str; +#else + return QString(); +#endif + } + QString ctryName() { +#ifdef HAVE_API_WIN32_BASE + wchar_t wstr[32]; + char str[32]; + + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wstr, sizeof(wstr)); + WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); + return QString()+"LOCALE_SABBREVCTRYNAME="+str; +#else + return QString(); +#endif + } +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return gui_get_attr(this->object->gui, type, attr, iter); } + int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); } +private: + QString source; +}; + //Main window class for resizeEvent handling class NGQMainWindow : public QMainWindow { public: @@ -709,7 +745,6 @@ static void gui_qml_button(void *data, int pressed, int button, struct point *p) if ( button == 3 ) { this_->guiProxy->setNewPoint(p,MapPoint); this_->guiWidget->setFocus(Qt::ActiveWindowFocusReason); - this_->guiWidget->reset(); this_->guiProxy->setReturnSource(QString("")); this_->guiProxy->setPage("point.qml"); this_->switcherWidget->setCurrentWidget(this_->guiWidget); @@ -728,7 +763,6 @@ 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_->guiWidget->clearItems(); this_->guiProxy->setReturnSource(QString("")); this_->guiProxy->setPage("main.qml"); } @@ -767,21 +801,12 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) } this_->mainWindow->setCentralWidget(this_->switcherWidget); - //Create gui widget - this_->guiWidget = new QmlView(NULL); - this_->guiWidget->setContentResizable(true); - //Create proxy object and bind them to gui widget this_->guiProxy = new NGQProxyGui(this_,this_->mainWindow); - this_->guiWidget->rootContext()->setContextProperty("gui",this_->guiProxy); this_->navitProxy = new NGQProxyNavit(this_,this_->mainWindow); - 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); this_->bookmarksProxy = new NGQProxyBookmarks(this_,this_->mainWindow); - this_->guiWidget->rootContext()->setContextProperty("bookmarks",this_->bookmarksProxy); //Check, if we have compatible graphics this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget"); @@ -790,16 +815,15 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra) } this_->switcherWidget->addWidget(this_->graphicsWidget); - //Switch to graphics - this_->switcherWidget->setCurrentWidget(this_->graphicsWidget); - //Link graphics events this_->button_cb=callback_new_attr_1(callback_cast(gui_qml_button), attr_button, this_); graphics_add_callback(gra, this_->button_cb); //Instantiate qml components this_->guiProxy->setPage(QString("main.qml")); - this_->switcherWidget->addWidget(this_->guiWidget); + + //Switch to graphics + this_->switcherWidget->setCurrentWidget(this_->graphicsWidget); this_->mainWindow->show(); diff --git a/gui/qml/skins/navit/ButtonIcon.qml b/gui/qml/skins/navit/ButtonIcon.qml.in index 4433be79..4433be79 100644 --- a/gui/qml/skins/navit/ButtonIcon.qml +++ b/gui/qml/skins/navit/ButtonIcon.qml.in diff --git a/gui/qml/skins/navit/Makefile.am b/gui/qml/skins/navit/Makefile.am index 5063260a..bc683c2e 100644 --- a/gui/qml/skins/navit/Makefile.am +++ b/gui/qml/skins/navit/Makefile.am @@ -4,5 +4,22 @@ SKIN = navit qmldir=$(skinsdir)/$(SKIN) -qml_DATA = ButtonIcon.qml PageBookmarksAdd.qml PageSearchSelector.qml PageSettingsTools.qml Cellar.qml PageBookmarks.qml PageSettingsDisplay.qml PageSettingsVehicle.qml ListSelector.qml PageNavigation.qml PageSettingsLocale.qml point.qml main.qml PageRoute.qml PageSettings.qml Slider.qml PageAbout.qml PageSearch.qml PageSettingsRules.qml ToggleSwitch.qml +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 += background.svg knob.svg + +do_button_subst = sed -e 's,matchProperties,properties,g' \ + -e 's,easing\:\ \"ease,easing\.type\:\ \",g' + +ButtonIcon.qml: ButtonIcon.qml.in +if QT_DECLARATIVE_NEWAPI + $(do_button_subst) < ButtonIcon.qml.in > ButtonIcon.qml +else + cp ButtonIcon.qml.in ButtonIcon.qml +endif + +ToggleSwitch.qml: ToggleSwitch.qml.in +if QT_DECLARATIVE_NEWAPI + $(do_button_subst) < ToggleSwitch.qml.in > ToggleSwitch.qml +else + cp ToggleSwitch.qml.in ToggleSwitch.qml +endif
\ No newline at end of file diff --git a/gui/qml/skins/navit/PageSettingsDisplay.qml b/gui/qml/skins/navit/PageSettingsDisplay.qml index 8bf673a5..42dad7df 100644 --- a/gui/qml/skins/navit/PageSettingsDisplay.qml +++ b/gui/qml/skins/navit/PageSettingsDisplay.qml @@ -54,10 +54,10 @@ Rectangle { anchors.topMargin: gui.height/16; anchors.leftMargin: gui.width/32 spacing: gui.width/12 ToggleSwitch { - id: fullscreenSw; on: gui.getAttr("fullscreen"); text: "Fullscreen"; onChanged: gui.setAttr("fullscreen",fullscreenSw.on) + id: fullscreenSw; stOn: gui.getAttr("fullscreen"); text: "Fullscreen"; onChanged: gui.setAttr("fullscreen",fullscreenSw.stOn) } ToggleSwitch { - id: tripledSw; on: page.isTripleD(); text: "2D/3D"; onChanged: setTripleD(tripledSw.on) + id: tripledSw; stOn: page.isTripleD(); text: "2D/3D"; onChanged: setTripleD(tripledSw.stOn) } Slider { id: pitchSlider; minValue: 5; maxValue: 90; value: navit.getAttr("pitch"); text: "Pitch"; onChanged: { navit.setAttr("pitch",pitchSlider.value); gui.setAttr("pitch",pitchSlider.value) } diff --git a/gui/qml/skins/navit/PageSettingsRules.qml b/gui/qml/skins/navit/PageSettingsRules.qml index 09b0cda8..4460a941 100644 --- a/gui/qml/skins/navit/PageSettingsRules.qml +++ b/gui/qml/skins/navit/PageSettingsRules.qml @@ -24,13 +24,13 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter;
spacing: gui.width/12
ToggleSwitch {
- id: trackingSw; on: navit.getAttr("tracking"); text: "Lock on road"; onChanged: navit.setAttr("tracking",trackingSw.on)
+ id: trackingSw; stOn: navit.getAttr("tracking"); text: "Lock on road"; onChanged: navit.setAttr("tracking",trackingSw.stOn)
}
ToggleSwitch {
- id: orientationSw; on: navit.getAttr("orientation"); text: "Northing"; onChanged: navit.setAttr("orientation",orientationSw.on) + id: orientationSw; stOn: navit.getAttr("orientation"); text: "Northing"; onChanged: navit.setAttr("orientation",orientationSw.stOn) }
ToggleSwitch {
- id: followrcursorSw; on: navit.getAttr("follow_cursor"); text: "Map follows Vehicle"; onChanged: navit.setAttr("follow_cursor",followrcursorSw.on)
+ id: followrcursorSw; stOn: navit.getAttr("follow_cursor"); text: "Map follows Vehicle"; onChanged: navit.setAttr("follow_cursor",followrcursorSw.stOn)
}
}
diff --git a/gui/qml/skins/navit/ToggleSwitch.qml b/gui/qml/skins/navit/ToggleSwitch.qml.in index 73b9b073..35f90d16 100644 --- a/gui/qml/skins/navit/ToggleSwitch.qml +++ b/gui/qml/skins/navit/ToggleSwitch.qml.in @@ -4,7 +4,7 @@ import Qt 4.6 id: toggleswitch
width: background.width + label.width + gui.width/24; height: background.height
- property string on: "false"
+ property string stOn: "false"
property string text: "Toggle switch"
signal changed
@@ -15,11 +15,11 @@ import Qt 4.6 }
function startup () {
- if (toggleswitch.on == "1" )
- toggleswitch.on = "true";
+ if (toggleswitch.stOn == "1" )
+ toggleswitch.stOn = "true";
else
- toggleswitch.on = "false";
- if (toggleswitch.on == "true")
+ toggleswitch.stOn = "false";
+ if (toggleswitch.stOn == "true")
toggleswitch.state = "on";
else
toggleswitch.state = "off";
@@ -55,13 +55,13 @@ import Qt 4.6 State {
name: "on"
PropertyChanges { target: knob; x: background.width-knob.width }
- PropertyChanges { target: toggleswitch; on: "true" }
+ PropertyChanges { target: toggleswitch; stOn: "true" }
StateChangeScript { script: toggleswitch.changed(); }
},
State {
name: "off"
PropertyChanges { target: knob; x: 1 }
- PropertyChanges { target: toggleswitch; on: "false" }
+ PropertyChanges { target: toggleswitch; stOn: "false" }
StateChangeScript { script: toggleswitch.changed(); }
}
]
|