Navit SVN

/work/compile/navit/src/navit/gui/qml/guiProxy.h

00001 #ifndef NAVIT_GUI_QML_GUIPROXY_H
00002 #define NAVIT_GUI_QML_GUIPROXY_H
00003 
00004 class NGQProxyGui : public NGQProxy {
00005     Q_OBJECT;
00006 
00007         Q_PROPERTY(QString iconPath READ iconPath CONSTANT);
00008 
00009         Q_PROPERTY(QString commandFunction READ commandFunction CONSTANT);
00010 
00011         Q_PROPERTY(QString localeName READ localeName CONSTANT);
00012         Q_PROPERTY(QString langName READ langName CONSTANT);
00013         Q_PROPERTY(QString ctryName READ ctryName CONSTANT);
00014 
00015         Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false);
00016         Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false);
00017 
00018 private:
00019         QStringList returnPath;
00020 
00021 public:
00022     NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) {
00023                 this->source=QString("");
00024     }
00025 
00026         void setNewPoint(struct point* p,NGQPointTypes type) {
00027                 if (this->object->currentPoint!=NULL) {
00028                         delete this->object->currentPoint;
00029                 }
00030                 this->object->currentPoint = new NGQPoint(this->object,p,type,NULL);
00031                 this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
00032         }
00033         void setNewPoint(struct coord* c,NGQPointTypes type) {
00034                 if (this->object->currentPoint!=NULL) {
00035                         delete this->object->currentPoint;
00036                 }
00037                 this->object->currentPoint = new NGQPoint(this->object,c,type,NULL);
00038                 this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
00039         }
00040         void setNewPoint(struct pcoord* pc,NGQPointTypes type) {
00041                 if (this->object->currentPoint!=NULL) {
00042                         delete this->object->currentPoint;
00043                 }
00044                 this->object->currentPoint = new NGQPoint(this->object,pc,type,NULL);
00045                 this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
00046         }
00047         void processCommand(QString function) {
00048                 //QDeclarativeExpression commandJS(this->object->guiWidget->rootContext(),QString(),qobject_cast<QObject*>(this->object->guiWidget->rootObject()));
00049                 //commandJS.setSourceLocation("command.js",0);
00050                 //this->function=function;
00051                 //commandJS.eval(qobject_cast<QObject*>(this->object->guiWidget->rootObject()));                
00052         }
00053 signals:
00054         void widthSignal(int);
00055         void heightSignal(int);
00056 public slots:
00057         void pushPage(QString page) {
00058                 returnPath.push_front(page);
00059         }
00060         QString popPage() {             
00061                 if (!returnPath.empty()) {
00062                         if (returnPath.length()>1) {
00063                                 returnPath.pop_front();
00064                         }
00065                         return returnPath.first();
00066                 }
00067                 return QString();
00068         }
00069         int lengthPage() {
00070                 return returnPath.length();
00071         }
00072         void backToMap() {
00073         if (this->object->graphicsWidget) {
00074                                 this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason);
00075                                 this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget);
00076                                 this->object->graphicsWidget->show();
00077         }
00078     }
00079         void switchToMenu(struct point* p) {
00080                 if (!this->object->lazy) {
00081                         this->returnPath.clear();
00082                         this->object->guiWidget->setSource(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/main.qml"));
00083                 }
00084                 this->setNewPoint(p,MapPoint);
00085                 this->object->guiWidget->setFocus(Qt::ActiveWindowFocusReason);
00086                 this->object->switcherWidget->setCurrentWidget(this->object->guiWidget);
00087 
00088         }
00089         //Properties
00090         QString iconPath() {
00091                 return QString(this->object->icon_src);
00092         }
00093         int width() {
00094                 return this->object->w;
00095         }
00096         void setWidth(int w) {
00097                 this->object->w=w;
00098                 this->widthSignal(w);
00099         }
00100         int height() {
00101                 return this->object->h;
00102         }
00103         void setHeight(int h) {
00104                 this->object->h=h;
00105                 this->heightSignal(h);
00106         }
00107         QString commandFunction() {
00108                 return this->function;
00109         }
00110 
00111         //Locale properties
00112         QString localeName() {
00113                 return QString()+"LANG="+getenv("LANG");
00114         }
00115         QString langName() {
00116 #ifdef HAVE_API_WIN32_BASE
00117                 char str[32];
00118 
00119                 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, str, sizeof(str));
00120                 return QString()+"LOCALE_SABBREVLANGNAME="+str;
00121 #else
00122                 return QString();
00123 #endif
00124         }
00125         QString ctryName() {
00126 #ifdef HAVE_API_WIN32_BASE
00127                 char str[32];
00128 
00129                 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, str, sizeof(str));
00130                 return QString()+"LOCALE_SABBREVCTRYNAME="+str;
00131 #else
00132                 return QString();
00133 #endif
00134         }
00135 protected:
00136         int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return gui_get_attr(this->object->gui, type, attr, iter); }
00137         int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); }
00138 private:
00139         QString source;
00140         QString function;
00141 };
00142 
00143 void __setNewPoint(struct gui_priv* this_,struct coord* c, NGQPointTypes type) {
00144         this_->guiProxy->setNewPoint(c,type);
00145 }
00146 void __setNewPoint(struct gui_priv* this_,struct pcoord* pc, NGQPointTypes type) {
00147         this_->guiProxy->setNewPoint(pc,type);
00148 }
00149 
00150 #include "guiProxy.moc"
00151 
00152 #endif /* NAVIT_GUI_QML_GUIPROXY_H */