summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-24 15:11:21 +0000
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-24 15:11:21 +0000
commit79c7d009f35d65ff35c34ea36ae3d0919ea636c5 (patch)
tree2cb6e772264fe80dfa9765a29c0d69d08811fcca
parent42a82a616c9ca48b50861223e547a0c1321a9178 (diff)
downloadnavit-79c7d009f35d65ff35c34ea36ae3d0919ea636c5.tar.gz
Add:gui/qml:Added bookmark viewer
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3083 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/gui/qml/gui_qml.cpp98
-rw-r--r--navit/gui/qml/ngqpoint.h231
-rw-r--r--navit/gui/qml/proxy.h3
-rw-r--r--navit/gui/qml/skins/navit/Makefile.am2
-rw-r--r--navit/gui/qml/skins/navit/PageBookmarks.qml92
-rw-r--r--navit/gui/qml/skins/navit/PageRoute.qml2
6 files changed, 319 insertions, 109 deletions
diff --git a/navit/gui/qml/gui_qml.cpp b/navit/gui/qml/gui_qml.cpp
index 1cd7a5fba..3af550e2e 100644
--- a/navit/gui/qml/gui_qml.cpp
+++ b/navit/gui/qml/gui_qml.cpp
@@ -402,10 +402,75 @@ private:
class NGQProxyBookmarks : public NGQProxy {
Q_OBJECT;
+
+ Q_PROPERTY(QString currentPath READ currentPath WRITE setCurrentPath);
public:
NGQProxyBookmarks(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
public slots:
+ QString currentPath() {
+ return this->current_path;
+ }
+ void setCurrentPath(QString currentPath) {
+ this->current_path=currentPath;
+ }
+ QString getAttrList(const QString &attr_name) {
+ NGQStandardItemModel* ret=new NGQStandardItemModel(this);
+ struct attr attr;
+ struct item* item;
+ struct map_rect *mr=NULL;
+
+ navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
+ mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL);
+ if (!mr) {
+ return QString();
+ }
+
+ if (!this->current_path.isEmpty()) {
+ QStandardItem* curItem=new QStandardItem();
+ QStringList returnPath=this->current_path.split("/",QString::SkipEmptyParts);
+
+ curItem->setData("..",NGQStandardItemModel::ItemName);
+ curItem->setData("yes",NGQStandardItemModel::ItemIcon);
+
+ if (returnPath.size()>1) {
+ returnPath.removeLast();
+ curItem->setData(returnPath.join("/"),NGQStandardItemModel::ItemPath);
+ } else {
+ //Fast way
+ curItem->setData(QString(),NGQStandardItemModel::ItemPath);
+ }
+
+ ret->appendRow(curItem);
+ }
+ while ((item=map_rect_get_item(mr))) {
+ QStandardItem* curItem=new QStandardItem();
+ QString label;
+ QStringList labelList;
+
+ if (item->type != type_bookmark) continue;
+ if (!item_attr_get(item, attr_label, &attr)) continue;
+ //We need to treeize output
+ label=QString::fromLocal8Bit(attr.u.str);
+ curItem->setData(label,NGQStandardItemModel::ItemId);
+ if (!label.startsWith(this->current_path)) continue;
+ label=label.right(label.length()-this->current_path.length());
+ labelList=label.split("/",QString::SkipEmptyParts);
+ curItem->setData(labelList[0],NGQStandardItemModel::ItemName);
+ curItem->setData(QString(this->current_path).append(labelList[0]).append("/"),NGQStandardItemModel::ItemPath);
+ if (labelList.size()>1) {
+ curItem->setData("yes",NGQStandardItemModel::ItemIcon);
+ } else {
+ curItem->setData("no",NGQStandardItemModel::ItemIcon);
+ }
+
+ ret->appendRow(curItem);
+ }
+
+ this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast<QObject*>(ret));
+
+ return QString();
+ }
QString AddBookmark(QString description) {
struct attr attr;
navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
@@ -415,6 +480,37 @@ public slots:
return "Success";
}
}
+ void setPoint(QString bookmark) {
+ struct attr attr;
+ struct item* item;
+ struct coord c;
+ struct map_rect *mr=NULL;
+
+ navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL);
+ mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL);
+ if (!mr) {
+ return;
+ }
+
+ while ((item=map_rect_get_item(mr))) {
+ QString label;
+
+ if (item->type != type_bookmark) continue;
+ if (!item_attr_get(item, attr_label, &attr)) continue;
+
+ label=QString::fromLocal8Bit(attr.u.str);
+ dbg(0,"Bookmark is %s\n",bookmark.toStdString().c_str());
+ if (label.compare(bookmark)) continue;
+ item_coord_get(item, &c, 1);
+ if (this->object->currentPoint!=NULL) {
+ delete this->object->currentPoint;
+ }
+ this->object->currentPoint=new NGQPoint(this->object,&c,bookmark,Bookmark,NULL);
+ this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint);
+ }
+
+ return;
+ }
protected:
int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return 0; }
@@ -423,7 +519,7 @@ protected:
void dropIterFunc(struct attr_iter* iter) { return; };
private:
-
+ QString current_path;
};
class NGQProxyNavit : public NGQProxy {
diff --git a/navit/gui/qml/ngqpoint.h b/navit/gui/qml/ngqpoint.h
index 1dba4764b..c55cd721d 100644
--- a/navit/gui/qml/ngqpoint.h
+++ b/navit/gui/qml/ngqpoint.h
@@ -1,18 +1,14 @@
#ifndef NAVIT_GUI_QML_POINT_H
#define NAVIT_GUI_QML_POINT_H
-enum NGQPointTypes {MapPoint};
+enum NGQPointTypes {MapPoint,Bookmark};
class NGQPoint : public QObject {
Q_OBJECT;
- /*Q_PROPERTY(QString type READ type CONSTANT);*/
-
Q_PROPERTY(QString coordString READ coordString CONSTANT);
Q_PROPERTY(QString pointName READ pointName CONSTANT);
Q_PROPERTY(QString py READ py CONSTANT);
- /*Q_PROPERTY(QString cx READ cx CONSTANT);
- Q_PROPERTY(QString cy READ cy CONSTANT);*/
public:
NGQPoint(struct gui_priv* this_,struct point* p,NGQPointTypes type=MapPoint,QObject *parent=NULL) : QObject(parent) {
this->object=this_;
@@ -24,108 +20,32 @@ public:
this->p.x=p->x;
this->p.y=p->y;
this->type=type;
+
+ this->name=this->_coordName();
+ this->coord=this->_coordString();
+ }
+ NGQPoint(struct gui_priv* this_,struct coord* c,QString name,NGQPointTypes type=Bookmark,QObject *parent=NULL) : QObject(parent) {
+ this->object=this_;
+ this->co.x=c->x;
+ this->co.y=c->y;
+ transform_to_geo(transform_get_projection(navit_get_trans(this->object->nav)), &co, &g);
+ this->c.pro = transform_get_projection(navit_get_trans(this->object->nav));
+ this->c.x = c->x;
+ this->c.y = c->y;
+ this->type=type;
+
+ this->name=name;
+ this->coord=this->_coordString();
}
struct pcoord* pc() { return &c; }
public slots:
- QString coordString() {
- char latc='N',lngc='E';
- int lat_deg,lat_min,lat_sec;
- int lng_deg,lng_min,lng_sec;
- struct coord_geo g=this->g;
-
- if (g.lat < 0) {
- g.lat=-g.lat;
- latc='S';
- }
- if (g.lng < 0) {
- g.lng=-g.lng;
- lngc='W';
- }
- lat_deg=g.lat;
- lat_min=fmod(g.lat*60,60);
- lat_sec=fmod(g.lat*3600,60);
- lng_deg=g.lng;
- lng_min=fmod(g.lng*60,60);
- lng_sec=fmod(g.lng*3600,60);
- return QString(QString::fromLocal8Bit("%1°%2'%3\" %4%5%6°%7'%8\" %9")).arg(lat_deg).arg(lat_min).arg(lat_sec).arg(latc).arg(' ').arg(lng_deg).arg(lng_min).arg(lng_sec).arg(lngc);
- }
- QString pointName() {
- int dist=10;
- struct mapset *ms;
- struct mapset_handle *h;
- struct map_rect *mr;
- struct map *m;
- struct item *item;
- struct street_data *data;
- struct map_selection sel;
- struct transformation *trans;
- enum projection pro;
- struct attr attr;
- char *label;
- QString ret;
-
- trans=navit_get_trans(this->object->nav);
- pro=transform_get_projection(trans);
- transform_from_geo(pro, &g, &co);
- ms=navit_get_mapset(this->object->nav);
- sel.next=NULL;
- sel.u.c_rect.lu.x=c.x-dist;
- sel.u.c_rect.lu.y=c.y+dist;
- sel.u.c_rect.rl.x=c.x+dist;
- sel.u.c_rect.rl.y=c.y-dist;
- sel.order=18;
- sel.range=item_range_all;
- h=mapset_open(ms);
- while ((m=mapset_next(h,1))) {
- mr=map_rect_new(m, &sel);
- if (! mr)
- continue;
- while ((item=map_rect_get_item(mr))) {
- data=street_get_data(item);
- if (transform_within_dist_item(&co, item->type, data->c, data->count, dist)) {
- if (item_attr_get(item, attr_label, &attr)) {
- label=map_convert_string(m, attr.u.str);
- if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
- ret=QString::fromLocal8Bit(item_to_name(item->type));
- ret=ret.remove(QString("poi_"));
- ret+=QString(" ")+QString::fromLocal8Bit(label);
- map_convert_free(label);
- street_data_free(data);
- map_rect_destroy(mr);
- mapset_close(h);
- return ret;
- }
- if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
- ret=QString::fromLocal8Bit(item_to_name(item->type));
- ret=ret.remove(QString("poly_"));
- ret+=QString(" ")+QString::fromLocal8Bit(label);
- map_convert_free(label);
- street_data_free(data);
- map_rect_destroy(mr);
- mapset_close(h);
- return ret;
- }
- if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
- ret="Street ";
- ret+=QString::fromLocal8Bit(label);
- map_convert_free(label);
- street_data_free(data);
- map_rect_destroy(mr);
- mapset_close(h);
- return ret;
- }
- map_convert_free(label);
- } else
- ret=item_to_name(item->type);
- }
- street_data_free(data);
- }
- map_rect_destroy(mr);
- }
- mapset_close(h);
- return ret;
- }
+ QString pointName() {
+ return this->name;
+ }
+ QString coordString() {
+ return this->coord;
+ }
QString px() {
char buffer[1024];
coord_format(this->g.lat,this->g.lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
@@ -133,14 +53,115 @@ public slots:
}
QString py() { return QString().setNum(p.y); }
protected:
+ QString _coordString() {
+ char latc='N',lngc='E';
+ int lat_deg,lat_min,lat_sec;
+ int lng_deg,lng_min,lng_sec;
+ struct coord_geo g=this->g;
+
+ if (g.lat < 0) {
+ g.lat=-g.lat;
+ latc='S';
+ }
+ if (g.lng < 0) {
+ g.lng=-g.lng;
+ lngc='W';
+ }
+ lat_deg=g.lat;
+ lat_min=fmod(g.lat*60,60);
+ lat_sec=fmod(g.lat*3600,60);
+ lng_deg=g.lng;
+ lng_min=fmod(g.lng*60,60);
+ lng_sec=fmod(g.lng*3600,60);
+ return QString(QString::fromLocal8Bit("%1°%2'%3\" %4%5%6°%7'%8\" %9")).arg(lat_deg).arg(lat_min).arg(lat_sec).arg(latc).arg(' ').arg(lng_deg).arg(lng_min).arg(lng_sec).arg(lngc);
+ }
+ QString _coordName() {
+ int dist=10;
+ struct mapset *ms;
+ struct mapset_handle *h;
+ struct map_rect *mr;
+ struct map *m;
+ struct item *item;
+ struct street_data *data;
+ struct map_selection sel;
+ struct transformation *trans;
+ enum projection pro;
+ struct attr attr;
+ char *label;
+ QString ret;
+
+ trans=navit_get_trans(this->object->nav);
+ pro=transform_get_projection(trans);
+ transform_from_geo(pro, &g, &co);
+ ms=navit_get_mapset(this->object->nav);
+ sel.next=NULL;
+ sel.u.c_rect.lu.x=c.x-dist;
+ sel.u.c_rect.lu.y=c.y+dist;
+ sel.u.c_rect.rl.x=c.x+dist;
+ sel.u.c_rect.rl.y=c.y-dist;
+ sel.order=18;
+ sel.range=item_range_all;
+ h=mapset_open(ms);
+ while ((m=mapset_next(h,1))) {
+ mr=map_rect_new(m, &sel);
+ if (! mr)
+ continue;
+ while ((item=map_rect_get_item(mr))) {
+ data=street_get_data(item);
+ if (transform_within_dist_item(&co, item->type, data->c, data->count, dist)) {
+ if (item_attr_get(item, attr_label, &attr)) {
+ label=map_convert_string(m, attr.u.str);
+ if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
+ ret=QString::fromLocal8Bit(item_to_name(item->type));
+ ret=ret.remove(QString("poi_"));
+ ret+=QString(" ")+QString::fromLocal8Bit(label);
+ map_convert_free(label);
+ street_data_free(data);
+ map_rect_destroy(mr);
+ mapset_close(h);
+ return ret;
+ }
+ if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
+ ret=QString::fromLocal8Bit(item_to_name(item->type));
+ ret=ret.remove(QString("poly_"));
+ ret+=QString(" ")+QString::fromLocal8Bit(label);
+ map_convert_free(label);
+ street_data_free(data);
+ map_rect_destroy(mr);
+ mapset_close(h);
+ return ret;
+ }
+ if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
+ ret="Street ";
+ ret+=QString::fromLocal8Bit(label);
+ map_convert_free(label);
+ street_data_free(data);
+ map_rect_destroy(mr);
+ mapset_close(h);
+ return ret;
+ }
+ map_convert_free(label);
+ } else
+ ret=item_to_name(item->type);
+ }
+ street_data_free(data);
+ }
+ map_rect_destroy(mr);
+ }
+ mapset_close(h);
+ return ret;
+ }
private:
struct gui_priv* object;
NGQPointTypes type;
- struct coord_geo g;
- struct coord co;
+ struct coord_geo g;
+ struct coord co;
struct pcoord c;
struct point p;
+
+ QString name;
+ QString coord;
};
#include "ngqpoint.moc"
diff --git a/navit/gui/qml/proxy.h b/navit/gui/qml/proxy.h
index b5235ff2f..3ffa4c3ba 100644
--- a/navit/gui/qml/proxy.h
+++ b/navit/gui/qml/proxy.h
@@ -8,10 +8,11 @@ public:
roleNames.insert(NGQStandardItemModel::ItemId, "itemId");
roleNames.insert(NGQStandardItemModel::ItemName, "itemName");
roleNames.insert(NGQStandardItemModel::ItemIcon, "itemIcon");
+ roleNames.insert(NGQStandardItemModel::ItemPath, "itemPath");
this->setRoleNames(roleNames);
}
- enum listRoles {ItemId=Qt::UserRole+1,ItemName=Qt::UserRole+2,ItemIcon=Qt::UserRole+3};
+ enum listRoles {ItemId=Qt::UserRole+1,ItemName=Qt::UserRole+2,ItemIcon=Qt::UserRole+3,ItemPath=Qt::UserRole+4};
private:
QHash<int, QByteArray> roleNames;
};
diff --git a/navit/gui/qml/skins/navit/Makefile.am b/navit/gui/qml/skins/navit/Makefile.am
index 58fe8071e..5063260ac 100644
--- a/navit/gui/qml/skins/navit/Makefile.am
+++ b/navit/gui/qml/skins/navit/Makefile.am
@@ -4,5 +4,5 @@ SKIN = navit
qmldir=$(skinsdir)/$(SKIN)
-qml_DATA = ButtonIcon.qml Cellar.qml ListSelector.qml PageAbout.qml PageRoute.qml PageNavigation.qml PageSettings.qml PageSettingsDisplay.qml PageSettingsLocale.qml PageSettingsRules.qml PageSettingsTools.qml PageSettingsVehicle.qml Slider.qml ToggleSwitch.qml main.qml point.qml
+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 += background.svg knob.svg
diff --git a/navit/gui/qml/skins/navit/PageBookmarks.qml b/navit/gui/qml/skins/navit/PageBookmarks.qml
new file mode 100644
index 000000000..0b73138c4
--- /dev/null
+++ b/navit/gui/qml/skins/navit/PageBookmarks.qml
@@ -0,0 +1,92 @@
+import Qt 4.6
+
+Rectangle {
+ id: page
+
+ width: gui.width; height: gui.height
+ color: "Black"
+ opacity: 0
+
+ function bookmarkClick(itemId,itemIcon,itemName,itemPath) {
+ if ( itemIcon=="yes" ) {
+ bookmarks.currentPath=itemPath;
+ bookmarks.getAttrList("");
+ } else {
+ bookmarks.setPoint(itemId);
+ gui.setPage("point.qml");
+ }
+ }
+
+ function pageOpen() {
+ page.opacity = 1;
+ }
+
+ Component.onCompleted: pageOpen();
+
+ opacity: Behavior {
+ NumberAnimation { id: opacityAnimation; duration: 300; alwaysRunToEnd: true }
+ }
+
+ Rectangle {
+ color: "Black"
+
+ id:layoutList
+ anchors.top: parent.top; anchors.left: parent.left; anchors.topMargin: gui.height/16; anchors.leftMargin: gui.width/32
+ width: page.width; height: page.height/2-cellar.height
+
+ Component {
+ id: delegate
+ Item {
+ id: wrapper
+ width: list.width; height: 20
+ Column {
+ x: 5; y: 5
+ Text { text: itemName; color: "White" }
+ }
+ MouseRegion {
+ id:delegateMouse
+ anchors.fill: parent
+ onClicked: bookmarkClick(itemId,itemIcon,itemName,itemPath);
+ }
+ }
+ }
+
+ Component {
+ id: highlight
+ Rectangle {
+ color: "lightsteelblue"
+ radius: 5
+ }
+ }
+
+ Text {
+ id: labelTxt; text: "Bookmarks"; color: "White"; font.pointSize: 14;
+ anchors.horizontalCenter: list.horizontalCenter
+ anchors.verticalCenter: layoutList.top
+ }
+
+ ListView {
+ id: list;
+ width: layoutList.width*0.8; height: layoutList.height
+ anchors.top: labelTxt.bottom;
+ anchors.left: layoutList.left
+ model: listModel
+ delegate: delegate
+ highlight: highlight
+ focus: true
+ clip: true
+ highlightFollowsCurrentItem: true
+ keyNavigationWraps: true
+ overShoot: false
+ currentIndex: bookmarks.getAttrList("");
+ }
+ Rectangle {
+ id: listScroller
+ opacity: 0.5; anchors.left: list.right; anchors.leftMargin: 4; width: 6
+ y: (list.visibleArea.yPosition * list.height)+(list.visibleArea.heightRatio * list.height/4)
+ height: list.visibleArea.heightRatio * list.height
+ }
+ }
+
+ Cellar {id: cellar; anchors.bottom: page.bottom; anchors.horizontalCenter: page.horizontalCenter; width: page.width }
+}
diff --git a/navit/gui/qml/skins/navit/PageRoute.qml b/navit/gui/qml/skins/navit/PageRoute.qml
index edf404a90..a2c594947 100644
--- a/navit/gui/qml/skins/navit/PageRoute.qml
+++ b/navit/gui/qml/skins/navit/PageRoute.qml
@@ -23,7 +23,7 @@ Rectangle {
anchors.bottom: parent.verticalCenter; anchors.bottomMargin: gui.height/16;
spacing: gui.width/12
ButtonIcon {
- id: btnBookmarks; text: "Bookmarks"; icon: "gui_bookmark.svg"; onClicked: console.log("Implement me!");
+ id: btnBookmarks; text: "Bookmarks"; icon: "gui_bookmark.svg"; onClicked: {bookmarks.currentPath=""; gui.setPage("PageBookmarks.qml") }
}
ButtonIcon {
id: btnDestinations; text: "Destinations"; icon: "gui_bookmark.svg"; onClicked: console.log("Implement me!");