summaryrefslogtreecommitdiff
path: root/navit/gui/qml/gui_qml.cpp
diff options
context:
space:
mode:
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-30 11:04:03 +0000
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-30 11:04:03 +0000
commita617640fa63ce94c3334d79028918198c4c00595 (patch)
tree448f5501c2dbe9390099c7062ff8eadf36716c22 /navit/gui/qml/gui_qml.cpp
parent3e47066188ac949ef1cbdc0c5b4693128155f56b (diff)
downloadnavit-a617640fa63ce94c3334d79028918198c4c00595.tar.gz
Add:gui/qml:Added Qt 4.7 support
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3101 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/gui/qml/gui_qml.cpp')
-rw-r--r--navit/gui/qml/gui_qml.cpp320
1 files changed, 172 insertions, 148 deletions
diff --git a/navit/gui/qml/gui_qml.cpp b/navit/gui/qml/gui_qml.cpp
index b3039f4f7..6f81ed4cf 100644
--- a/navit/gui/qml/gui_qml.cpp
+++ b/navit/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();