summaryrefslogtreecommitdiff
path: root/navit/gui/qml/guiProxy.h
blob: 7648eb5b3bbaf6d2f94550c87d81c64cb8f897d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef NAVIT_GUI_QML_GUIPROXY_H
#define NAVIT_GUI_QML_GUIPROXY_H

class NGQProxyGui : public NGQProxy {
    Q_OBJECT;

	Q_PROPERTY(QString iconPath READ iconPath CONSTANT);

	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);

	Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false);
	Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false);

private:
	QStringList returnPath;

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);
	}
	void setNewPoint(struct coord* c,NGQPointTypes type) {
		if (this->object->currentPoint!=NULL) {
			delete this->object->currentPoint;
		}
		this->object->currentPoint = new NGQPoint(this->object,c,type,NULL);
		this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
	}
	void setNewPoint(struct pcoord* pc,NGQPointTypes type) {
		if (this->object->currentPoint!=NULL) {
			delete this->object->currentPoint;
		}
		this->object->currentPoint = new NGQPoint(this->object,pc,type,NULL);
		this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
	}
	void processCommand(QString function) {
		//QDeclarativeExpression commandJS(this->object->guiWidget->rootContext(),QString(),qobject_cast<QObject*>(this->object->guiWidget->rootObject()));
		//commandJS.setSourceLocation("command.js",0);
		//this->function=function;
		//commandJS.eval(qobject_cast<QObject*>(this->object->guiWidget->rootObject()));		
	}
signals:
	void widthSignal(int);
	void heightSignal(int);
public slots:
	void pushPage(QString page) {
		returnPath.push_front(page);
	}
	QString popPage() {		
		if (!returnPath.empty()) {
			if (returnPath.length()>1) {
				returnPath.pop_front();
			}
			return returnPath.first();
		}
		return QString();
	}
	int lengthPage() {
		return returnPath.length();
	}
	void backToMap() {
        if (this->object->graphicsWidget) {
				this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason);
				this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget);
				this->object->graphicsWidget->show();
        }
    }
	void switchToMenu(struct point* p) {
		if (!this->object->lazy) {
			this->returnPath.clear();
			this->object->guiWidget->setSource(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/main.qml"));
		}
		this->setNewPoint(p,MapPoint);
		this->object->guiWidget->setFocus(Qt::ActiveWindowFocusReason);
		this->object->switcherWidget->setCurrentWidget(this->object->guiWidget);

	}
	//Properties
	QString iconPath() {
		return QString(this->object->icon_src);
	}
	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);
	}
	QString commandFunction() {
		return this->function;
	}

	//Locale properties
	QString localeName() {
		return QString()+"LANG="+getenv("LANG");
	}
	QString langName() {
#ifdef HAVE_API_WIN32_BASE
		char str[32];

		GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, str, sizeof(str));
		return QString()+"LOCALE_SABBREVLANGNAME="+str;
#else
		return QString();
#endif
	}
	QString ctryName() {
#ifdef HAVE_API_WIN32_BASE
		char str[32];

		GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, str, sizeof(str));
		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;
	QString function;
};

void __setNewPoint(struct gui_priv* this_,struct coord* c, NGQPointTypes type) {
	this_->guiProxy->setNewPoint(c,type);
}
void __setNewPoint(struct gui_priv* this_,struct pcoord* pc, NGQPointTypes type) {
	this_->guiProxy->setNewPoint(pc,type);
}

#include "guiProxy.moc"

#endif /* NAVIT_GUI_QML_GUIPROXY_H */