diff options
Diffstat (limited to 'app')
47 files changed, 1763 insertions, 563 deletions
diff --git a/app/BtnEnlarge.qml b/app/BtnEnlarge.qml index 664c3aa..229b5f1 100755..100644 --- a/app/BtnEnlarge.qml +++ b/app/BtnEnlarge.qml @@ -3,15 +3,14 @@ import QtQuick.Controls 1.5 Item {
Button {
- id: btn_enlarge
width: 100
height: 100
- function doSomething() {
- // ...
+ function zoomUp() {
+ map.zoomLevel += 1
}
- onClicked: { doSomething() }
+ onClicked: { zoomUp() }
Image {
id: image
@@ -19,7 +18,7 @@ Item { height: 92
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
- source: "images/Enlarge_button.bmp"
+ source: "images/240px-Antu_kdenlive-zoom-large.svg.png"
}
}
}
diff --git a/app/BtnGuidance.qml b/app/BtnGuidance.qml new file mode 100644 index 0000000..18efd9f --- /dev/null +++ b/app/BtnGuidance.qml @@ -0,0 +1,128 @@ +import QtQuick 2.0
+import QtQuick.Controls 1.5
+import QtLocation 5.9
+import QtPositioning 5.6
+
+Item {
+ id: btn_guidance
+
+ // 0: idle
+ // 1: routing
+ // 2: on guide
+ property int sts_guide: 0
+
+ onSts_guideChanged: {
+ console.log("onSts_guideChanged")
+ switch(btn_guidance.sts_guide){
+ case 0:
+ positionTimer.stop();
+ break
+ case 1:
+ break
+ case 2:
+ positionTimer.start();
+ break
+ default:
+ break
+ }
+ }
+
+ function startGuidance() {
+ btn_present_position.state = "Flowing"
+ btn_guidance.sts_guide = 2
+ btn_guidance.state = "onGuide"
+ }
+
+ function discardWaypoints() {
+ map.initDestination()
+
+ if(btn_guidance.sts_guide != 0){
+ map.qmlSignalStopDemo()
+ }
+
+ if(map.center !== map.currentpostion){
+ btn_present_position.state = "Optional"
+ }
+
+ btn_guidance.sts_guide = 0
+ btn_guidance.state = "Idle"
+ }
+
+ Timer {
+ id: positionTimer
+ interval: fileOperation.getInterval() // set millisecond
+ running: false
+ repeat: true
+ onTriggered: map.updatePositon()
+ }
+
+ Button {
+ id: discard
+ width: 100
+ height: 100
+
+ visible: false
+
+ onClicked: discardWaypoints()
+
+ Image {
+ id: discard_image
+ width: 92
+ height: 92
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.horizontalCenter
+ source: "images/200px-Black_close_x.svg.png"
+ }
+ }
+
+ Button {
+ id: guidance
+ width: 100
+ height: 100
+
+ visible: false
+
+ onClicked: { startGuidance() }
+
+ Image {
+ id: guidance_image
+ width: 92
+ height: 92
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.horizontalCenter
+ source: "images/124px-Pictograms-nps-land-driving_tour-2.svg.png"
+ }
+
+ }
+ states: [
+ State {
+ name: "Idle"
+ PropertyChanges { target: discard; visible: false }
+ PropertyChanges { target: guidance; visible: false }
+ PropertyChanges { target: guidance; x: 0 }
+ PropertyChanges { target: progress_next_cross; state: "invisible" }
+ PropertyChanges { target: img_destination_direction; state: "invisible" }
+ },
+ State {
+ name: "Routing"
+ PropertyChanges { target: discard; visible: true }
+ PropertyChanges { target: guidance; visible: true }
+ PropertyChanges { target: guidance; x: -150 }
+ PropertyChanges { target: progress_next_cross; state: "invisible" }
+ PropertyChanges { target: img_destination_direction; state: "invisible" }
+ },
+ State {
+ name: "onGuide"
+ PropertyChanges { target: discard; visible: true }
+ PropertyChanges { target: guidance; visible: false }
+ PropertyChanges { target: guidance; x: 0 }
+ PropertyChanges { target: progress_next_cross; state: "visible" }
+ PropertyChanges { target: img_destination_direction; state: "0" }
+ }
+ ]
+
+ transitions: Transition {
+ NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad }
+ NumberAnimation { properties: "visible"; easing.type: Easing.InOutQuad }
+ }
+}
diff --git a/app/BtnMapDirection.qml b/app/BtnMapDirection.qml index ea52d6e..8f6074d 100755..100644 --- a/app/BtnMapDirection.qml +++ b/app/BtnMapDirection.qml @@ -2,18 +2,23 @@ import QtQuick 2.0 import QtQuick.Controls 1.5
Item {
- Button {
+ Button {
id: btn_map_direction
width: 100
height: 100
function settleState() {
- if(btn_map_direction.state == "HeadingUp"){
- btn_map_direction.state = "NorthUp";
+ if(root.st_heading_up){
+ btn_map_direction.state = "NorthUp"
+ car_position_mapitem.state = "NorthUp"
+ root.st_heading_up = false
} else {
- btn_map_direction.state = "HeadingUp";
+ btn_map_direction.state = "HeadingUp"
+ car_position_mapitem.state = "HeadingUp"
+ root.st_heading_up = true
}
- }
+ map.rotateMapSmooth()
+ }
onClicked: { settleState() }
@@ -23,18 +28,18 @@ Item { height: 92
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
- source: "images/Direction_Hup.jpeg"
+ source: "images/202px-Compass-icon_bb_N.svg.png"
}
states: [
State {
name: "HeadingUp"
- PropertyChanges { target: image; source: "images/Direction_Hup.jpeg" }
+ PropertyChanges { target: image; source: "images/240px-Compass_icon_NE.svg.png" }
},
State {
name: "NorthUp"
- PropertyChanges { target: image; source: "images/Direction_Nup.jpeg" }
- }
+ PropertyChanges { target: image; source: "images/202px-Compass-icon_bb_N.svg.png" }
+ }
]
- }
+ }
}
diff --git a/app/BtnPresentPosition.qml b/app/BtnPresentPosition.qml index 54e3077..02cdc74 100755 --- a/app/BtnPresentPosition.qml +++ b/app/BtnPresentPosition.qml @@ -2,24 +2,39 @@ import QtQuick 2.0 import QtQuick.Controls 1.5
Item {
- Button {
- id: btn_present_position
+ id: btn_present_position
+
+ Button {
+ id: btn_present_position_
width: 100
height: 100
+ visible: false
- function doSomething() {
- // ...
- }
+ function present_position_clicked() {
+ map.center = map.currentpostion
+// map.zoomLevel = root.default_zoom_level
+ btn_present_position.state = "Flowing"
+ }
+ onClicked: { present_position_clicked() }
- onClicked: { doSomething() }
+ Image {
+ id: image_present_position
+ width: 48
+ height: 92
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.horizontalCenter: parent.horizontalCenter
+ source: "images/207px-Car_icon_top.svg.png"
+ }
+ }
+ states: [
+ State{
+ name: "Flowing"
+ PropertyChanges { target: btn_present_position_; visible: false }
+ },
+ State{
+ name: "Optional"
+ PropertyChanges { target: btn_present_position_; visible: true }
+ }
+ ]
- Image {
- id: image
- width: 92
- height: 92
- anchors.verticalCenter: parent.verticalCenter
- anchors.horizontalCenter: parent.horizontalCenter
- source: "images/thum500_t002_0_ip_0175.jpg"
- }
- }
}
diff --git a/app/BtnShrink.qml b/app/BtnShrink.qml index 1c67e5b..1387557 100755..100644 --- a/app/BtnShrink.qml +++ b/app/BtnShrink.qml @@ -7,11 +7,11 @@ Item { width: 100
height: 100
- function doSomething() {
- // ...
+ function zoomDown() {
+ map.zoomLevel -= 1
}
- onClicked: { doSomething() }
+ onClicked: { zoomDown() }
Image {
id: image
@@ -19,7 +19,7 @@ Item { height: 92
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
- source: "images/Shrink_button.bmp"
+ source: "images/240px-Antu_file-zoom-out.svg.png"
}
}
}
diff --git a/app/ImgDestinationDirection.qml b/app/ImgDestinationDirection.qml index e6c36d5..b5528dd 100755..100644 --- a/app/ImgDestinationDirection.qml +++ b/app/ImgDestinationDirection.qml @@ -2,82 +2,94 @@ import QtQuick 2.0 Item {
id: img_destination_direction
+ width: 100
+ height: 100
+ visible: false
- width: childrenRect.width
- height: childrenRect.height
+ Rectangle {
+ width: parent.width
+ height: parent.height
+ color: "#a0a0a0"
- function settleState() {
- if(img_destination_direction.state == "1"){
- img_destination_direction.state = "2";
- } else if(img_destination_direction.state == "2"){
- img_destination_direction.state = "3";
- } else if(img_destination_direction.state == "3"){
- img_destination_direction.state = "4";
- } else if(img_destination_direction.state == "4"){
- img_destination_direction.state = "5";
- } else if(img_destination_direction.state == "5"){
- img_destination_direction.state = "6";
- } else if(img_destination_direction.state == "6"){
- img_destination_direction.state = "7";
- } else if(img_destination_direction.state == "7"){
- img_destination_direction.state = "8";
- } else if(img_destination_direction.state == "8"){
- img_destination_direction.state = "9";
- } else {
- img_destination_direction.state = "1";
- }
- }
-
- Image {
- id: direction
- x: 0
- y: 0
- width: 100
- height: 100
- source: "images/1_uturn.png"
-
- MouseArea {
- anchors.fill: parent
- onClicked: { settleState() }
- }
- }
+ Image {
+ id: direction
+ anchors.fill: parent
+ anchors.margins: 1
+ source: "images/SW_Patern_3.bmp"
+ }
+ }
states: [
- State {
- name: "1"
- PropertyChanges { target: direction; source: "images/1_uturn.png" }
+ State {
+ name: "0" // NoDirection
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/SW_Patern_3.bmp" }
+ },
+ State {
+ name: "1" // DirectionForward
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/5_straight.png" }
},
State {
- name: "2"
- PropertyChanges { target: direction; source: "images/2_sharp_right.png" }
+ name: "2" // DirectionBearRight
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/11_2_bear_right_112px-Signal_C117a.svg.png" }
},
State {
- name: "3"
- PropertyChanges { target: direction; source: "images/3_right.png" }
+ name: "3" // DirectionLightRight
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/4_slight_right.png" }
},
State {
- name: "4"
- PropertyChanges { target: direction; source: "images/4_slight_right.png" }
+ name: "4" // DirectionRight
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/3_right.png" }
},
State {
- name: "5"
- PropertyChanges { target: direction; source: "images/5_straight.png" }
+ name: "5" // DirectionHardRight
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/2_sharp_right.png" }
},
State {
- name: "6"
- PropertyChanges { target: direction; source: "images/6_slight_left.png" }
+ name: "6" // DirectionUTurnRight
+ PropertyChanges { target: img_destination_direction; visible: true }
+ //PropertyChanges { target: direction; source: "images/1_uturn.png" }
+ PropertyChanges { target: direction; source: "images/9_7_uturn_left.png" } // no u-turn right in CES2019
},
State {
- name: "7"
- PropertyChanges { target: direction; source: "images/7_left.png" }
+ name: "7" // DirectionUTurnLeft
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/9_7_uturn_left.png" }
},
State {
- name: "8"
- PropertyChanges { target: direction; source: "images/8_sharp_left.png" }
+ name: "8" // DirectionHardLeft
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/8_sharp_left.png" }
},
State {
- name: "9"
- PropertyChanges { target: direction; source: "images/Dest_Flag.jpg" }
- }
+ name: "9" // DirectionLeft
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/7_left.png" }
+ },
+ State {
+ name: "10" // DirectionLightLeft
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/6_slight_left.png" }
+ },
+ State {
+ name: "11" // DirectionBearLeft
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/10_11_bear_left_112px-Signal_C117a.svg.png" }
+ },
+ State {
+ name: "12" // arrived at your destination
+ PropertyChanges { target: img_destination_direction; visible: true }
+ PropertyChanges { target: direction; source: "images/Dest_Flag.jpg" }
+ },
+ State {
+ name: "invisible"
+ PropertyChanges { target: img_destination_direction; visible: false }
+ }
+
]
}
diff --git a/app/ProgressNextCross.qml b/app/ProgressNextCross.qml index 49765ce..d9e04a5 100755..100644 --- a/app/ProgressNextCross.qml +++ b/app/ProgressNextCross.qml @@ -1,86 +1,45 @@ import QtQuick 2.0
import QtQuick.Controls 1.5
+import QtQuick.Controls.Styles 1.4
Item {
id: progress_next_cross
- function move() {
- if(progress_next_cross.state == "0.1"){
- progress_next_cross.state = "0.2"
- } else if(progress_next_cross.state == "0.2"){
- progress_next_cross.state = "0.3"
- } else if(progress_next_cross.state == "0.3"){
- progress_next_cross.state = "0.4"
- } else if(progress_next_cross.state == "0.4"){
- progress_next_cross.state = "0.5"
- } else if(progress_next_cross.state == "0.5"){
- progress_next_cross.state = "0.6"
- } else if(progress_next_cross.state == "0.6"){
- progress_next_cross.state = "0.7"
- } else if(progress_next_cross.state == "0.7"){
- progress_next_cross.state = "0.8"
- } else if(progress_next_cross.state == "0.8"){
- progress_next_cross.state = "0.9"
- } else if(progress_next_cross.state == "0.9"){
- progress_next_cross.state = "1.0"
- } else {
- progress_next_cross.state = "0.1"
- }
+ visible: false
+
+ // val [Input]
+ // distance to next cross. (unit = meter)
+ // when over the ProgressBar.maximumValue/m, progress bar indicates max (same as ProgressBar.maximumValue/m)
+ function setProgress(val) {
+ if ( (0 < val) && (val < bar.maximumValue ) ) {
+ bar.value = val
+ }else if ( bar.maximumValue < val ){
+ bar.value = bar.maximumValue
+ }else{
+ bar.value = 0
+ }
}
ProgressBar {
id: bar
width: 25
height: 100
- orientation: 0
- value: 0.7
+ orientation: Qt.Vertical
+ value: 0
+ minimumValue: 0
+ maximumValue: 300
- MouseArea {
- anchors.fill: parent
- onClicked: { move() }
- }
+ style: ProgressBarStyle {
+ progress: Rectangle {
+ color: "green"
+ }
+ }
}
+ states: [
+ State {
+ name: "visible"; PropertyChanges { target: progress_next_cross; visible: true }},
+ State {
+ name: "invisible"; PropertyChanges { target: progress_next_cross; visible: false }}
+ ]
- states: [
- State {
- name: "0.1"
- PropertyChanges { target: bar; value: 0.1 }
- },
- State {
- name: "0.2"
- PropertyChanges { target: bar; value: 0.2 }
- },
- State {
- name: "0.3"
- PropertyChanges { target: bar; value: 0.3 }
- },
- State {
- name: "0.4"
- PropertyChanges { target: bar; value: 0.4 }
- },
- State {
- name: "0.5"
- PropertyChanges { target: bar; value: 0.5 }
- },
- State {
- name: "0.6"
- PropertyChanges { target: bar; value: 0.6 }
- },
- State {
- name: "0.7"
- PropertyChanges { target: bar; value: 0.7 }
- },
- State {
- name: "0.8"
- PropertyChanges { target: bar; value: 0.8 }
- },
- State {
- name: "0.9"
- PropertyChanges { target: bar; value: 0.9 }
- },
- State {
- name: "1.0"
- PropertyChanges { target: bar; value: 1.0 }
- }
- ]
}
diff --git a/app/app.pro b/app/app.pro index 1701af2..c693ee9 100755..100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,14 +1,29 @@ TARGET = navigation -QT = quick aglextras qml +QT = quick qml + +QT += aglextras +PKGCONFIG += qlibhomescreen qlibwindowmanager + +QT += positioning +QT += dbus +QT += core CONFIG += c++11 link_pkgconfig -#PKGCONFIG += -#HEADERS += +HEADERS += \ + markermodel.h \ + dbus_server.h \ + guidance_module.h \ + file_operation.h -SOURCES += main.cpp +SOURCES += main.cpp \ + dbus_server.cpp RESOURCES += \ - testqt.qrc \ + navigation.qrc \ images/images.qrc +DBUS_ADAPTORS += dbusinterface/org.agl.naviapi.xml +DBUS_INTERFACES += dbusinterface/org.agl.naviapi.xml + include(app.pri) + diff --git a/app/dbus_server.cpp b/app/dbus_server.cpp new file mode 100644 index 0000000..d83528e --- /dev/null +++ b/app/dbus_server.cpp @@ -0,0 +1,134 @@ +#include"dbus_server.h" +#include <QDebug> + +DBus_Server::DBus_Server(const QString &pathName, + const QString &objName, + const QString &serverName, + QObject *parent) : + m_serverName(serverName), + m_pathName(pathName + serverName), + m_objName(objName + serverName) +{ + initDBus(); + initAPIs(parent); +} +DBus_Server::~DBus_Server(){} + +void DBus_Server::initDBus(){ + + new NaviapiAdaptor(this); + + if (!QDBusConnection::sessionBus().registerService(m_pathName)) + qDebug() << m_pathName << "registerService() failed"; + + if (!QDBusConnection::sessionBus().registerObject(m_objName, this)) + qDebug() << m_objName << "registerObject() failed"; + + QDBusConnection sessionBus = QDBusConnection::connectToBus(QDBusConnection::SessionBus, m_serverName); + if (!sessionBus.isConnected()) { + qDebug() << m_serverName << "connectToBus() failed"; + } + + //for receive dbus signal + org::agl::naviapi *mInterface; + mInterface = new org::agl::naviapi(QString(),QString(),QDBusConnection::sessionBus(),this); + if (!connect(mInterface,SIGNAL(getRouteInfo()),this,SLOT(getRouteInfoSlot()))){ + qDebug() << m_serverName << "sessionBus.connect():getRouteInfoSlot failed"; + } + +} + +void DBus_Server::initAPIs(QObject *parent){ + + if(!QObject::connect(this,SIGNAL(doAddPOI(QVariant,QVariant,QVariant)), + parent,SLOT(addPoiIconSLOT(QVariant,QVariant,QVariant)))) { + qDebug() << m_serverName << "cppSIGNAL:doAddPOI to qmlSLOT:addPoiIcon connect is failed"; + } + + if(!QObject::connect(this,SIGNAL(doRemovePOIs(QVariant)), + parent,SLOT(removePoiIconsSLOT(QVariant)))) { + qDebug() << m_serverName << "cppSIGNAL:doRemovePOIs to qmlSLOT:removePoiIcons connect is failed"; + } + + if(!QObject::connect(this,SIGNAL(doGetRouteInfo()), + parent,SLOT(doGetRouteInfoSlot()))) { + qDebug() << m_serverName << "cppSIGNAL:doGetRouteInfo to qmlSLOT:doGetRouteInfoSlot connect is failed"; + } + + if(!QObject::connect(parent,SIGNAL(qmlSignalRouteInfo(double,double,double,double)), + this,SLOT(sendSignalRouteInfo(double,double,double,double)))) { + qDebug() << m_serverName << "qmlSIGNAL:qmlSignalRouteInfo to cppSLOT:sendSignalRouteInfo connect is failed"; + } + + if(!QObject::connect(parent,SIGNAL(qmlSignalPosInfo(double,double,double,double)), + this,SLOT(sendSignalPosInfo(double,double,double,double)))) { + qDebug() << m_serverName << "qmlSIGNAL:qmlSignalPosInfo to cppSLOT:sendSignalPosInfo connect is failed"; + } + + if(!QObject::connect(parent,SIGNAL(qmlSignalStopDemo()), + this,SLOT(sendSignalStopDemo()))) { + qDebug() << m_serverName << "qmlSIGNAL:qmlSignalStopDemo to cppSLOT:sendSignalStopDemo connect is failed"; + } + + if(!QObject::connect(parent,SIGNAL(qmlSignalArrvied()), + this,SLOT(sendSignalArrvied()))) { + qDebug() << m_serverName << "qmlSIGNAL:qmlSignalArrvied to cppSLOT:sendSignalArrvied connect is failed"; + } +} + +void DBus_Server::getRouteInfoSlot(){ + qDebug() << "call getRouteInfoSlot "; + emit doGetRouteInfo(); + return; +} + +// Signal +void DBus_Server::sendSignalRouteInfo(double srt_lat, double srt_lon, double end_lat, double end_lon){ + qDebug() << "call sendSignalRouteInfo "; + QDBusMessage message = QDBusMessage::createSignal(m_objName, + org::agl::naviapi::staticInterfaceName(), + "signalRouteInfo"); + message << srt_lat << srt_lon << end_lat << end_lon; + QDBusConnection::sessionBus().send(message); + return; +} + +void DBus_Server::sendSignalPosInfo(double lat, double lon, double drc, double dst){ +// qDebug() << "call sendSignalPosInfo "; + QDBusMessage message = QDBusMessage::createSignal(m_objName, + org::agl::naviapi::staticInterfaceName(), + "signalPosInfo"); + message << lat << lon << drc << dst; + QDBusConnection::sessionBus().send(message); + return; +} + +void DBus_Server::sendSignalStopDemo(){ + qDebug() << "call sendSignalStopDemo "; + QDBusMessage message = QDBusMessage::createSignal(m_objName, + org::agl::naviapi::staticInterfaceName(), + "signalStopDemo"); + QDBusConnection::sessionBus().send(message); + return; +} + +void DBus_Server::sendSignalArrvied(){ + qDebug() << "call sendSignalArrvied "; + QDBusMessage message = QDBusMessage::createSignal(m_objName, + org::agl::naviapi::staticInterfaceName(), + "signalArrvied"); + QDBusConnection::sessionBus().send(message); + return; +} + +// Method +void DBus_Server::addPOI(uint category_id, double poi_Lat, double poi_Lon){ + qDebug() << "call addPOI category_id: " << category_id << " poi_Lat: " << poi_Lat << " poi_Lon: " << poi_Lon; + emit doAddPOI(poi_Lat,poi_Lon,category_id); + return; +} +void DBus_Server::removePOIs(uint category_id){ + qDebug() << "call removePOIs category_id: " << category_id; + emit doRemovePOIs(category_id); + return; +} diff --git a/app/dbus_server.h b/app/dbus_server.h new file mode 100644 index 0000000..8cd2f52 --- /dev/null +++ b/app/dbus_server.h @@ -0,0 +1,40 @@ +#ifndef DBUS_SERVER_H +#define DBUS_SERVER_H +#include "naviapi_interface.h" +#include "naviapi_adaptor.h" +#include <QtQml/QQmlApplicationEngine> + +class DBus_Server : public QObject{ + + Q_OBJECT + + QString m_serverName; + QString m_pathName; + QString m_objName; + +public: + DBus_Server(const QString &pathName, + const QString &objName, + const QString &serverName, + QObject *parent = nullptr); + ~DBus_Server(); + +private: + void initDBus(); + void initAPIs(QObject*); + +signals: + void doAddPOI(QVariant,QVariant,QVariant); + void doRemovePOIs(QVariant); + void doGetRouteInfo(); + +public slots: + void addPOI(uint category_id, double poi_Lat, double poi_Lon); + void removePOIs(uint category_id); + void getRouteInfoSlot(); + void sendSignalRouteInfo(double srt_lat,double srt_lon,double end_lat,double end_lon); + void sendSignalPosInfo(double lat,double lon,double drc,double dst); + void sendSignalStopDemo(); + void sendSignalArrvied(); +}; +#endif // DBUS_SERVER_H diff --git a/app/dbusinterface/org.agl.naviapi.xml b/app/dbusinterface/org.agl.naviapi.xml new file mode 100644 index 0000000..f5b095c --- /dev/null +++ b/app/dbusinterface/org.agl.naviapi.xml @@ -0,0 +1,36 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.agl.naviapi"> + <method name="addPOI"> + <arg direction="in" name="category_id" type="u"/> + <arg direction="in" name="poi_Lat" type="d"/> + <arg direction="in" name="poi_Lon" type="d"/> + </method> + <method name="removePOIs"> + <arg direction="in" name="category_id" type="u"/> + </method> + <!-- void signalRouteInfo() --> + <signal name="signalRouteInfo"> + <arg name="start_latitude" type="d" direction="out"/> + <arg name="start_longitude" type="d" direction="out"/> + <arg name="end_latitude" type="d" direction="out"/> + <arg name="end_longitude" type="d" direction="out"/> + </signal> + <!-- void signalPosInfo() --> + <signal name="signalPosInfo"> + <arg name="latitude" type="d" direction="out"/> + <arg name="longitude" type="d" direction="out"/> + <arg name="direction" type="d" direction="out"/> + <arg name="distance" type="d" direction="out"/> + </signal> + <!-- void signalStopDemo() --> + <signal name="signalStopDemo"> + </signal> + <!-- void signalArrvied() --> + <signal name="signalArrvied"> + </signal> + <!-- void getRouteInfo() --> + <signal name="getRouteInfo"> + </signal> + </interface> +</node> diff --git a/app/file_operation.h b/app/file_operation.h new file mode 100644 index 0000000..618d26b --- /dev/null +++ b/app/file_operation.h @@ -0,0 +1,144 @@ +#ifndef FILE_OPERATION_H +#define FILE_OPERATION_H +#include <QObject> +#include <QString> +#include <QFile> +#include <QFile> +#include <QJsonObject> +#include <QJsonDocument> + +/****************************************************** + * Write access token of mapbox in /etc/mapAccessToken + ******************************************************/ +#define MAP_ACCESS_TOKEN_FILEPATH "/etc/mapAccessToken" + +class File_Operation: public QObject{ + + Q_OBJECT +public: + Q_INVOKABLE QString getMapAccessToken() { + #if 0 + char buf[512]; + QString mapAccessToken = ""; + + FILE* filep = fopen(qPrintable(MAP_ACCESS_TOKEN_FILEPATH), "r"); + if (!filep) { + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return mapAccessToken; + } + if (!fgets(buf, 512, filep)) { + fprintf(stderr,"Failed to read mapAccessToken from mapAccessToken file \"%s\"", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + fclose(filep); + return mapAccessToken; + } + if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = '\0'; + } + mapAccessToken = QString(buf); + + fclose(filep); + + return mapAccessToken; + #else + QString mapAccessToken = ""; + QFile file(MAP_ACCESS_TOKEN_FILEPATH); + if (!file.open(QIODevice::ReadOnly)){ + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return mapAccessToken; + } + QByteArray data = file.readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject jsonObj(jsonDoc.object()); + if(jsonObj.contains("mapAccessToken")){ + mapAccessToken = jsonObj["mapAccessToken"].toString(); + }else{ + fprintf(stderr,"Failed to find mapAccessToken data \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + } + + file.close(); + return mapAccessToken; + #endif + } + + Q_INVOKABLE double getSpeed() { + double speed = 60; // km/h + QFile file(MAP_ACCESS_TOKEN_FILEPATH); + if (!file.open(QIODevice::ReadOnly)){ + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return speed; + } + QByteArray data = file.readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject jsonObj(jsonDoc.object()); + if(jsonObj.contains("speed")){ + speed = jsonObj["speed"].toDouble(); + }else{ + fprintf(stderr,"Failed to find speed data \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + } + + file.close(); + return speed; + } + + Q_INVOKABLE int getInterval() { + int interval = 15; // ms + QFile file(MAP_ACCESS_TOKEN_FILEPATH); + if (!file.open(QIODevice::ReadOnly)){ + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return interval; + } + QByteArray data = file.readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject jsonObj(jsonDoc.object()); + if(jsonObj.contains("interval")){ + interval = (int)jsonObj["interval"].toDouble(); + }else{ + fprintf(stderr,"Failed to find interval data \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + } + + file.close(); + return interval; + } + + Q_INVOKABLE double getLatitude() { + double latitude = 36.136261; + QFile file(MAP_ACCESS_TOKEN_FILEPATH); + if (!file.open(QIODevice::ReadOnly)){ + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return latitude; + } + QByteArray data = file.readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject jsonObj(jsonDoc.object()); + if(jsonObj.contains("latitude")){ + latitude = jsonObj["latitude"].toDouble(); + }else{ + fprintf(stderr,"Failed to find latitude data \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + } + + file.close(); + return latitude; + } + + Q_INVOKABLE double getLongitude() { + double longitute = -115.151254; + QFile file(MAP_ACCESS_TOKEN_FILEPATH); + if (!file.open(QIODevice::ReadOnly)){ + fprintf(stderr,"Failed to open mapAccessToken file \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + return longitute; + } + QByteArray data = file.readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject jsonObj(jsonDoc.object()); + if(jsonObj.contains("longitute")){ + longitute = jsonObj["longitute"].toDouble(); + }else{ + fprintf(stderr,"Failed to find longitute data \"%s\": %m", qPrintable(MAP_ACCESS_TOKEN_FILEPATH)); + } + + file.close(); + return longitute; + } +}; + +#endif // FILE_OPERATION_H diff --git a/app/guidance_module.h b/app/guidance_module.h new file mode 100644 index 0000000..3a70a90 --- /dev/null +++ b/app/guidance_module.h @@ -0,0 +1,32 @@ +#include <sys/stat.h> +#include <QObject> +#include <QString> +#include <QDebug> + +#define SYS_LANGUAGE_INIT 0 +#define SYS_LANGUAGE_JP 1 +#define SYS_LANGUAGE_EN 2 +#define TTSMAX (2048) + +class Guidance_Module : public QObject +{ + Q_OBJECT +public: + int g_voicelanguage = SYS_LANGUAGE_INIT; + QString g_voice_module = ""; + Q_INVOKABLE void guidance(const QString &text){ + char tts_voice[TTSMAX]; + int len = 0; + memset(tts_voice,0,TTSMAX); + + strncat(tts_voice, "sh flite '", (TTSMAX - len - 1)); + + len = strlen(tts_voice); + strncat(tts_voice, text.toUtf8().data(), (TTSMAX - len - 1)); + + len = strlen(tts_voice); + strncat(tts_voice, "'&", (TTSMAX - len - 1)); + + system(tts_voice); + } +}; diff --git a/app/images/10_11_bear_left_112px-Signal_C117a.svg.png b/app/images/10_11_bear_left_112px-Signal_C117a.svg.png Binary files differnew file mode 100644 index 0000000..f658a9c --- /dev/null +++ b/app/images/10_11_bear_left_112px-Signal_C117a.svg.png diff --git a/app/images/11_2_bear_right_112px-Signal_C117a.svg.png b/app/images/11_2_bear_right_112px-Signal_C117a.svg.png Binary files differnew file mode 100644 index 0000000..a4c9326 --- /dev/null +++ b/app/images/11_2_bear_right_112px-Signal_C117a.svg.png diff --git a/app/images/124px-Pictograms-nps-land-driving_tour-2.svg.png b/app/images/124px-Pictograms-nps-land-driving_tour-2.svg.png Binary files differnew file mode 100644 index 0000000..edcf729 --- /dev/null +++ b/app/images/124px-Pictograms-nps-land-driving_tour-2.svg.png diff --git a/app/images/181px-u-turn.svg.png b/app/images/181px-u-turn.svg.png Binary files differnew file mode 100644 index 0000000..221ebfd --- /dev/null +++ b/app/images/181px-u-turn.svg.png diff --git a/app/images/200px-Black_close_x.svg.png b/app/images/200px-Black_close_x.svg.png Binary files differnew file mode 100644 index 0000000..7e82526 --- /dev/null +++ b/app/images/200px-Black_close_x.svg.png diff --git a/app/images/202px-Compass-icon_bb_N.svg.png b/app/images/202px-Compass-icon_bb_N.svg.png Binary files differnew file mode 100644 index 0000000..0d4ccbf --- /dev/null +++ b/app/images/202px-Compass-icon_bb_N.svg.png diff --git a/app/images/207px-Car_icon_top.svg.png b/app/images/207px-Car_icon_top.svg.png Binary files differnew file mode 100644 index 0000000..ab380ef --- /dev/null +++ b/app/images/207px-Car_icon_top.svg.png diff --git a/app/images/240px-Antu_file-zoom-out.svg.png b/app/images/240px-Antu_file-zoom-out.svg.png Binary files differnew file mode 100644 index 0000000..3041d3e --- /dev/null +++ b/app/images/240px-Antu_file-zoom-out.svg.png diff --git a/app/images/240px-Antu_kdenlive-zoom-large.svg.png b/app/images/240px-Antu_kdenlive-zoom-large.svg.png Binary files differnew file mode 100644 index 0000000..8daffe0 --- /dev/null +++ b/app/images/240px-Antu_kdenlive-zoom-large.svg.png diff --git a/app/images/240px-Compass_icon_NE.svg.png b/app/images/240px-Compass_icon_NE.svg.png Binary files differnew file mode 100644 index 0000000..72e210e --- /dev/null +++ b/app/images/240px-Compass_icon_NE.svg.png diff --git a/app/images/240px-HEB_project_flow_icon_04_checkered_flag.svg.png b/app/images/240px-HEB_project_flow_icon_04_checkered_flag.svg.png Binary files differnew file mode 100644 index 0000000..48dc65f --- /dev/null +++ b/app/images/240px-HEB_project_flow_icon_04_checkered_flag.svg.png diff --git a/app/images/240px-Red_Arrow_Up.svg.png b/app/images/240px-Red_Arrow_Up.svg.png Binary files differnew file mode 100644 index 0000000..0ab10f1 --- /dev/null +++ b/app/images/240px-Red_Arrow_Up.svg.png diff --git a/app/images/91px-MUTCD_M6-1L.svg.png b/app/images/91px-MUTCD_M6-1L.svg.png Binary files differnew file mode 100644 index 0000000..3375739 --- /dev/null +++ b/app/images/91px-MUTCD_M6-1L.svg.png diff --git a/app/images/91px-MUTCD_M6-1R.svg.png b/app/images/91px-MUTCD_M6-1R.svg.png Binary files differnew file mode 100644 index 0000000..0ed977f --- /dev/null +++ b/app/images/91px-MUTCD_M6-1R.svg.png diff --git a/app/images/91px-MUTCD_M6-2L.svg.png b/app/images/91px-MUTCD_M6-2L.svg.png Binary files differnew file mode 100644 index 0000000..a0e6a5f --- /dev/null +++ b/app/images/91px-MUTCD_M6-2L.svg.png diff --git a/app/images/91px-MUTCD_M6-2R.svg.png b/app/images/91px-MUTCD_M6-2R.svg.png Binary files differnew file mode 100644 index 0000000..ba0ed24 --- /dev/null +++ b/app/images/91px-MUTCD_M6-2R.svg.png diff --git a/app/images/91px-MUTCD_M6-2aL.svg.png b/app/images/91px-MUTCD_M6-2aL.svg.png Binary files differnew file mode 100644 index 0000000..a1451d5 --- /dev/null +++ b/app/images/91px-MUTCD_M6-2aL.svg.png diff --git a/app/images/91px-MUTCD_M6-2aR.svg.png b/app/images/91px-MUTCD_M6-2aR.svg.png Binary files differnew file mode 100644 index 0000000..722aa2c --- /dev/null +++ b/app/images/91px-MUTCD_M6-2aR.svg.png diff --git a/app/images/91px-MUTCD_M6-3.svg.png b/app/images/91px-MUTCD_M6-3.svg.png Binary files differnew file mode 100644 index 0000000..985e6f2 --- /dev/null +++ b/app/images/91px-MUTCD_M6-3.svg.png diff --git a/app/images/9_7_uturn_left.png b/app/images/9_7_uturn_left.png Binary files differnew file mode 100644 index 0000000..c7af3c1 --- /dev/null +++ b/app/images/9_7_uturn_left.png diff --git a/app/images/BuildingIcon.png b/app/images/BuildingIcon.png Binary files differnew file mode 100644 index 0000000..94f0694 --- /dev/null +++ b/app/images/BuildingIcon.png diff --git a/app/images/ChurchIcon.png b/app/images/ChurchIcon.png Binary files differnew file mode 100644 index 0000000..f1e4d88 --- /dev/null +++ b/app/images/ChurchIcon.png diff --git a/app/images/Flag-export_lightblue.png b/app/images/Flag-export_lightblue.png Binary files differnew file mode 100644 index 0000000..451a28d --- /dev/null +++ b/app/images/Flag-export_lightblue.png diff --git a/app/images/Map_marker_icon_–_Nicolas_Mollet_–_Flag_–_Tourism_–_Classic.png b/app/images/Map_marker_icon_–_Nicolas_Mollet_–_Flag_–_Tourism_–_Classic.png Binary files differnew file mode 100644 index 0000000..b9e2c45 --- /dev/null +++ b/app/images/Map_marker_icon_–_Nicolas_Mollet_–_Flag_–_Tourism_–_Classic.png diff --git a/app/images/Map_symbol_location_02.png b/app/images/Map_symbol_location_02.png Binary files differnew file mode 100644 index 0000000..1b585f0 --- /dev/null +++ b/app/images/Map_symbol_location_02.png diff --git a/app/images/RestaurantMapIcon.png b/app/images/RestaurantMapIcon.png Binary files differnew file mode 100644 index 0000000..8081e97 --- /dev/null +++ b/app/images/RestaurantMapIcon.png diff --git a/app/images/SupermarketMapIcon.png b/app/images/SupermarketMapIcon.png Binary files differnew file mode 100644 index 0000000..772c2e0 --- /dev/null +++ b/app/images/SupermarketMapIcon.png diff --git a/app/images/images.qrc b/app/images/images.qrc index 8fb37c3..1db63f3 100755..100644 --- a/app/images/images.qrc +++ b/app/images/images.qrc @@ -1,23 +1,41 @@ -<RCC> - <qresource prefix="/images"> - <file>SW_Patern_1.bmp</file> - <file>SW_Patern_2.bmp</file> - <file>SW_Patern_3.bmp</file> - <file>Enlarge_button.bmp</file> - <file>Direction_Hup.jpeg</file> - <file>Direction_Nup.jpeg</file> - <file>thum500_t002_0_ip_0175.jpg</file> - <file>Shrink_button.bmp</file> - <file>1_uturn.png</file> - <file>2_sharp_right.png</file> - <file>3_right.png</file> - <file>4_slight_right.png</file> - <file>5_straight.png</file> - <file>6_slight_left.png</file> - <file>7_left.png</file> - <file>8_sharp_left.png</file> - <file>Dest_Flag.jpg</file> - <file>car_icon.svg</file> - <file>nmea.txt</file> - </qresource> -</RCC> +<RCC>
+ <qresource prefix="/images">
+ <file>91px-MUTCD_M6-1L.svg.png</file>
+ <file>91px-MUTCD_M6-1R.svg.png</file>
+ <file>91px-MUTCD_M6-2aL.svg.png</file>
+ <file>91px-MUTCD_M6-2aR.svg.png</file>
+ <file>91px-MUTCD_M6-2L.svg.png</file>
+ <file>91px-MUTCD_M6-2R.svg.png</file>
+ <file>91px-MUTCD_M6-3.svg.png</file>
+ <file>124px-Pictograms-nps-land-driving_tour-2.svg.png</file>
+ <file>200px-Black_close_x.svg.png</file>
+ <file>202px-Compass-icon_bb_N.svg.png</file>
+ <file>240px-Antu_file-zoom-out.svg.png</file>
+ <file>240px-Antu_kdenlive-zoom-large.svg.png</file>
+ <file>240px-Compass_icon_NE.svg.png</file>
+ <file>240px-Red_Arrow_Up.svg.png</file>
+ <file>240px-HEB_project_flow_icon_04_checkered_flag.svg.png</file>
+ <file>207px-Car_icon_top.svg.png</file>
+ <file>181px-u-turn.svg.png</file>
+ <file>Dest_Flag.jpg</file>
+ <file>1_uturn.png</file>
+ <file>2_sharp_right.png</file>
+ <file>3_right.png</file>
+ <file>4_slight_right.png</file>
+ <file>5_straight.png</file>
+ <file>6_slight_left.png</file>
+ <file>7_left.png</file>
+ <file>8_sharp_left.png</file>
+ <file>9_7_uturn_left.png</file>
+ <file>10_11_bear_left_112px-Signal_C117a.svg.png</file>
+ <file>11_2_bear_right_112px-Signal_C117a.svg.png</file>
+ <file>SW_Patern_3.bmp</file>
+ <file>Map_symbol_location_02.png</file>
+ <file>Map_marker_icon_–_Nicolas_Mollet_–_Flag_–_Tourism_–_Classic.png</file>
+ <file>RestaurantMapIcon.png</file>
+ <file>SupermarketMapIcon.png</file>
+ <file>BuildingIcon.png</file>
+ <file>ChurchIcon.png</file>
+ <file>Flag-export_lightblue.png</file>
+ </qresource>
+</RCC>
diff --git a/app/main.cpp b/app/main.cpp index 5101969..7eb92a0 100755..100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,37 +1,171 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <QtAGLExtras/AGLApplication> -#include <QtCore/QDebug> -#include <QtCore/QCommandLineParser> -#include <QtCore/QUrlQuery> -#include <QtCore/QSettings> -#include <QtGui/QGuiApplication> -#include <QtQml/QQmlApplicationEngine> -#include <QtQml/QQmlContext> -#include <QtQuickControls2/QQuickStyle> -#include <QQuickWindow> - -int main(int argc, char *argv[]) -{ - AGLApplication app(argc, argv); - app.setApplicationName("navigation"); - app.setupApplicationRole("navigation"); - - app.load(QUrl(QStringLiteral("qrc:/testqt.qml"))); - return app.exec(); -} - +/*
+ * Copyright (C) 2016 The Qt Company Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define USE_QTAGLEXTRAS 0
+#define USE_QLIBWINDOWMANAGER 1
+
+#if USE_QTAGLEXTRAS
+#include <QtAGLExtras/AGLApplication>
+#elif USE_QLIBWINDOWMANAGER
+#include <qlibwindowmanager.h>
+#include <qlibhomescreen.h>
+#include <string>
+#include <ilm/ivi-application-client-protocol.h>
+#include <wayland-client.h>
+#endif
+#include <QtCore/QDebug>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QUrlQuery>
+#include <QtCore/QSettings>
+#include <QtGui/QGuiApplication>
+#include <QtQml/QQmlApplicationEngine>
+#include <QtQml/QQmlContext>
+#include <QtQuickControls2/QQuickStyle>
+#include <QQuickWindow>
+#include <QtDBus/QDBusConnection>
+#include "markermodel.h"
+#include "dbus_server.h"
+#include "guidance_module.h"
+#include "file_operation.h"
+
+int main(int argc, char *argv[])
+{
+
+ // for dbusIF
+ QString pathBase = "org.agl.";
+ QString objBase = "/org/agl/";
+ QString serverName = "naviapi";
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ qWarning("Cannot connect to the D-Bus session bus.\n"
+ "Please check your system settings and try again.\n");
+ return 1;
+ }
+
+#if USE_QTAGLEXTRAS
+ AGLApplication app(argc, argv);
+ app.setApplicationName("navigation");
+ app.setupApplicationRole("navigation");
+ app.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
+
+#elif USE_QLIBWINDOWMANAGER
+ QGuiApplication app(argc, argv);
+ QString myname = QString("navigation");
+ int port = 1700;
+ QString token = "hello";
+ QCoreApplication::setOrganizationDomain("LinuxFoundation");
+ QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
+ QCoreApplication::setApplicationName(myname);
+ QCoreApplication::setApplicationVersion("0.1.0");
+ QCommandLineParser parser;
+ parser.addPositionalArgument("port", app.translate("main", "port for binding"));
+ parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.process(app);
+ QStringList positionalArguments = parser.positionalArguments();
+ if (positionalArguments.length() == 2) {
+ port = positionalArguments.takeFirst().toInt();
+ token = positionalArguments.takeFirst();
+ }
+ fprintf(stderr, "[navigation]app_name: %s, port: %d, token: %s.\n",
+ myname.toStdString().c_str(),
+ port,
+ token.toStdString().c_str());
+ // QLibWM
+ QLibWindowmanager* qwmHandler = new QLibWindowmanager();
+ int res;
+ if((res = qwmHandler->init(port,token)) != 0){
+ fprintf(stderr, "[navigation]init qlibwm err(%d)\n", res);
+ return -1;
+ }
+ if((res = qwmHandler->requestSurface(myname)) != 0) {
+ fprintf(stderr, "[navigation]request surface err(%d)\n", res);
+ return -1;
+ }
+ qwmHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwmHandler, myname](json_object *object) {
+ qwmHandler->endDraw(myname);
+ });
+ qwmHandler->set_event_handler(QLibWindowmanager::Event_Visible, [qwmHandler, myname](json_object *object) {
+ ;
+ });
+ qwmHandler->set_event_handler(QLibWindowmanager::Event_Invisible, [qwmHandler, myname](json_object *object) {
+ ;
+ });
+ // QLibHS
+ QLibHomeScreen* qhsHandler = new QLibHomeScreen();
+ qhsHandler->init(port, token.toStdString().c_str());
+ qhsHandler->set_event_handler(QLibHomeScreen::Event_TapShortcut, [qwmHandler, myname](json_object *object){
+ json_object *appnameJ = nullptr;
+ if(json_object_object_get_ex(object, "application_name", &appnameJ))
+ {
+ const char *appname = json_object_get_string(appnameJ);
+ if(QString::compare(myname, appname, Qt::CaseInsensitive) == 0)
+ {
+ qDebug("Surface %s got tapShortcut\n", appname);
+ json_object *para, *area;
+ json_object_object_get_ex(object, "parameter", ¶);
+ json_object_object_get_ex(para, "area", &area);
+ const char *displayArea = json_object_get_string(area);
+ qDebug("Surface %s got tapShortcut area\n", displayArea);
+ qwmHandler->activateWindow(myname, QString(QLatin1String(displayArea)));
+ }
+ }
+ });
+ // Load qml
+ QQmlApplicationEngine engine;
+
+ MarkerModel model;
+ engine.rootContext()->setContextProperty("markerModel", &model);
+
+ Guidance_Module guidance;
+ engine.rootContext()->setContextProperty("guidanceModule", &guidance);
+
+ File_Operation file;
+ engine.rootContext()->setContextProperty("fileOperation", &file);
+
+ engine.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
+ QObject *root = engine.rootObjects().first();
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
+ QObject::connect(window, SIGNAL(frameSwapped()), qwmHandler, SLOT(slotActivateSurface()));
+ QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
+ DBus_Server dbus(pathBase,objBase,serverName,map);
+
+#else // for only libwindowmanager
+ QGuiApplication app(argc, argv);
+ app.setApplicationName("navigation");
+
+ // Load qml
+ QQmlApplicationEngine engine;
+
+ MarkerModel model;
+ engine.rootContext()->setContextProperty("markerModel", &model);
+
+ Guidance_Module guidance;
+ engine.rootContext()->setContextProperty("guidanceModule", &guidance);
+
+ File_Operation file;
+ engine.rootContext()->setContextProperty("fileOperation", &file);
+
+ engine.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
+ QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
+ DBus_Server dbus(pathBase,objBase,serverName,map);
+
+#endif
+
+ return app.exec();
+}
+
diff --git a/app/markermodel.h b/app/markermodel.h new file mode 100644 index 0000000..742dd39 --- /dev/null +++ b/app/markermodel.h @@ -0,0 +1,50 @@ +#ifndef MARKERMODEL_H +#define MARKERMODEL_H + +#include <QAbstractListModel> +#include <QGeoCoordinate> + +class MarkerModel : public QAbstractListModel +{ + Q_OBJECT + +public: + using QAbstractListModel::QAbstractListModel; + enum MarkerRoles{positionRole = Qt::UserRole + 1}; + + Q_INVOKABLE void addMarker(const QGeoCoordinate &coordinate){ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_coordinates.append(coordinate); + endInsertRows(); + } + + Q_INVOKABLE void removeMarker(){ + beginResetModel(); + m_coordinates.clear(); + endResetModel(); + } + + int rowCount(const QModelIndex &parent = QModelIndex()) const override{ + Q_UNUSED(parent) + return m_coordinates.count(); + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override{ + if (index.row() < 0 || index.row() >= m_coordinates.count()) + return QVariant(); + if(role== MarkerModel::positionRole) + return QVariant::fromValue(m_coordinates[index.row()]); + return QVariant(); + } + + QHash<int, QByteArray> roleNames() const{ + QHash<int, QByteArray> roles; + roles[positionRole] = "position"; + return roles; + } + +private: + QList<QGeoCoordinate> m_coordinates; +}; + +#endif // MARKERMODEL_H diff --git a/app/navigation.qml b/app/navigation.qml new file mode 100755 index 0000000..ffc0ded --- /dev/null +++ b/app/navigation.qml @@ -0,0 +1,804 @@ +/* + * Copyright (C) 2016 The Qt Company Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import QtQuick 2.6 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.0 +import QtWebSockets 1.0 +import QtLocation 5.9 +import QtPositioning 5.6 + +ApplicationWindow { + id: root + visible: true + width: 1080 + height: 1488 +// height: 680 //debug + title: qsTr("navigation") + + property real car_position_lat: fileOperation.getLatitude() // WestGate as default + property real car_position_lon: fileOperation.getLongitude() + property real car_direction: 0 //North + property real car_driving_speed: fileOperation.getSpeed() // set Km/h + property real prev_car_direction: 0 + property bool st_heading_up: false + property real default_zoom_level : 18 + property real default_car_direction : 0 + property real car_accumulated_distance : 0 + property real positionTimer_interval : fileOperation.getInterval() // set millisecond + property real car_moving_distance : (car_driving_speed / 3.6) / (1000/positionTimer_interval) // Metric unit + + Map{ + id: map + property int pathcounter : 0 + property int segmentcounter : 0 + property int waypoint_count: -1 + property int lastX : -1 + property int lastY : -1 + property int pressX : -1 + property int pressY : -1 + property int jitterThreshold : 30 + property variant currentpostion : QtPositioning.coordinate(car_position_lat, car_position_lon) + property var poiArray: new Array + property int last_segmentcounter : -1 + + signal qmlSignalRouteInfo(double srt_lat,double srt_lon,double end_lat,double end_lon); + signal qmlSignalPosInfo(double lat,double lon,double drc,double dst); + signal qmlSignalStopDemo(); + signal qmlSignalArrvied(); + + width: parent.width + height: parent.height + plugin: Plugin { + name: "mapboxgl" + PluginParameter { name: "mapboxgl.access_token"; + value: fileOperation.getMapAccessToken() } + } + center: QtPositioning.coordinate(car_position_lat, car_position_lon) + zoomLevel: default_zoom_level + bearing: 0 + objectName: "map" + + GeocodeModel { + id: geocodeModel + plugin: map.plugin + onStatusChanged: { + if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)) + map.geocodeFinished() + } + onLocationsChanged: + { + if (count == 1) { + map.center.latitude = get(0).coordinate.latitude + map.center.longitude = get(0).coordinate.longitude + } + } + //coordinate: poiTheQtComapny.coordinate + //anchorPoint: Qt.point(-poiTheQtComapny.sourceItem.width * 0.5,poiTheQtComapny.sourceItem.height * 1.5) + } + MapItemView { + model: geocodeModel + delegate: pointDelegate + } + Component { + id: pointDelegate + + MapCircle { + id: point + radius: 1000 + color: "#46a2da" + border.color: "#190a33" + border.width: 2 + smooth: true + opacity: 0.25 + center: locationData.coordinate + } + } + + function geocode(fromAddress) + { + // send the geocode request + geocodeModel.query = fromAddress + geocodeModel.update() + } + + MapQuickItem { + id: poi + sourceItem: Rectangle { width: 14; height: 14; color: "#e41e25"; border.width: 2; border.color: "white"; smooth: true; radius: 7 } + coordinate { + latitude: 36.136261 + longitude: -115.151254 + } + opacity: 1.0 + anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2) + } + MapQuickItem { + sourceItem: Text{ + text: "Westgate" + color:"#242424" + font.bold: true + styleColor: "#ECECEC" + style: Text.Outline + } + coordinate: poi.coordinate + anchorPoint: Qt.point(-poi.sourceItem.width * 0.5, poi.sourceItem.height * 1.5) + } + MapQuickItem { + id: car_position_mapitem + sourceItem: Image { + id: car_position_mapitem_image + width: 32 + height: 32 + source: "images/240px-Red_Arrow_Up.svg.png" + + transform: Rotation { + id: car_position_mapitem_image_rotate + origin.x: car_position_mapitem_image.width/2 + origin.y: car_position_mapitem_image.height/2 + angle: car_direction + } + } + anchorPoint: Qt.point(car_position_mapitem_image.width/2, car_position_mapitem_image.height/2) + coordinate: map.currentpostion + + + states: [ + State { + name: "HeadingUp" + PropertyChanges { target: car_position_mapitem_image_rotate; angle: 0 } + }, + State { + name: "NorthUp" + PropertyChanges { target: car_position_mapitem_image_rotate; angle: root.car_direction } + } + ] + transitions: Transition { + RotationAnimation { properties: "angle"; easing.type: Easing.InOutQuad } + } + } + + MapQuickItem { + id: icon_start_point + anchorPoint.x: icon_start_point_image.width/2 + anchorPoint.y: icon_start_point_image.height + sourceItem: Image { + id: icon_start_point_image + width: 32 + height: 32 + source: "images/240px-HEB_project_flow_icon_04_checkered_flag.svg.png" + } + } + + MapQuickItem { + id: icon_end_point + anchorPoint.x: icon_end_point_image.width/2 + anchorPoint.y: icon_end_point_image.height + sourceItem: Image { + id: icon_end_point_image + width: 32 + height: 32 + source: "images/Map_marker_icon_–_Nicolas_Mollet_–_Flag_–_Tourism_–_Classic.png" + } + } + + MapQuickItem { + id: icon_segment_point + anchorPoint.x: icon_segment_point_image.width/2 - 5 + anchorPoint.y: icon_segment_point_image.height/2 + 25 + sourceItem: Image { + id: icon_segment_point_image + width: 64 + height: 64 + source: "images/Map_symbol_location_02.png" + } + } + + RouteModel { + id: routeModel + plugin: Plugin { + name: "mapbox" + PluginParameter { name: "mapbox.access_token"; + value: fileOperation.getMapAccessToken() } + } + query: RouteQuery { + id: routeQuery + } + onStatusChanged: { + if (status == RouteModel.Ready) { + switch (count) { + case 0: + // technically not an error + // map.routeError() + break + case 1: + map.pathcounter = 0 + map.segmentcounter = 0 +// console.log("1 route found") +// console.log("path: ", get(0).path.length, "segment: ", get(0).segments.length) +// for(var i = 0; i < get(0).path.length; i++){ +// console.log("", get(0).path[i]) +// } + console.log("1st instruction: ", get(0).segments[map.segmentcounter].maneuver.instructionText) + for( var i = 0; i < routeModel.get(0).segments.length; i++){ +// console.log("segments[",i,"].maneuver.direction:" ,routeModel.get(0).segments[i].maneuver.direction) +// console.log("segments[",i,"].maneuver.instructionText:" ,routeModel.get(0).segments[i].maneuver.instructionText) +// console.log("segments[",i,"].maneuver.path[0]:" ,routeModel.get(0).segments[i].path[0].latitude,",",routeModel.get(0).segments[i].path[0].longitude) +// markerModel.addMarker(routeModel.get(0).segments[i].path[0]) // for debug + } + break + } + } else if (status == RouteModel.Error) { + // map.routeError() + } + } + } + + Component { + id: routeDelegate + + MapRoute { + id: route + route: routeData + line.color: "#4658da" + line.width: 10 + smooth: true + opacity: 0.8 + } + } + + MapItemView { + model: routeModel + delegate: routeDelegate + } + + MapItemView{ + model: markerModel + delegate: mapcomponent + } + + Component { + id: mapcomponent + MapQuickItem { + id: icon_destination_point + anchorPoint.x: icon_destination_point_image.width/4 + anchorPoint.y: icon_destination_point_image.height + coordinate: position + + sourceItem: Image { + id: icon_destination_point_image + width: 32 + height: 32 + source: "images/200px-Black_close_x.svg.png" + } + } + } + + function addDestination(coord){ + if( waypoint_count < 0 ){ + initDestination() + } + + if(waypoint_count == 0) { + // set icon_start_point + icon_start_point.coordinate = currentpostion + map.addMapItem(icon_start_point) + } + + if(waypoint_count < 9){ + routeQuery.addWaypoint(coord) + waypoint_count += 1 + + btn_guidance.sts_guide = 1 + btn_guidance.state = "Routing" + + var waypointlist = routeQuery.waypoints + for(var i=1; i<waypoint_count; i++) { + markerModel.addMarker(waypointlist[i]) + +// map.addPoiIconSLOT(waypointlist[i].latitude,waypointlist[i].longitude,i % 5) // for Debug + } + + routeModel.update() + map.qmlSignalRouteInfo(car_position_lat, car_position_lon,coord.latitude,coord.longitude) + + // update icon_end_point + icon_end_point.coordinate = coord + map.addMapItem(icon_end_point) + } + } + + function initDestination(){ + routeModel.reset(); + console.log("initWaypoint") + + // reset currentpostion + map.currentpostion = QtPositioning.coordinate(car_position_lat, car_position_lon) + car_accumulated_distance = 0 + map.qmlSignalPosInfo(car_position_lat, car_position_lon,car_direction,car_accumulated_distance) + + routeQuery.clearWaypoints(); + routeQuery.addWaypoint(map.currentpostion) + routeQuery.travelModes = RouteQuery.CarTravel + routeQuery.routeOptimizations = RouteQuery.FastestRoute + for (var i=0; i<9; i++) { + routeQuery.setFeatureWeight(i, 0) + } + waypoint_count = 0 + pathcounter = 0 + segmentcounter = 0 + routeModel.update(); + markerModel.removeMarker(); + map.removeMapItem(markerModel); + + // remove MapItem + map.removeMapItem(icon_start_point) + map.removeMapItem(icon_end_point) + map.removeMapItem(icon_segment_point) + + // for Debug +// while(poiArray.length>0) +// map.removeMapItem(poiArray.pop()) + + // update car_position_mapitem angle + root.car_direction = root.default_car_direction + + } + + function calculateMarkerRoute() + { + var startCoordinate = QtPositioning.coordinate(car_position_lat, car_position_lon) + + console.log("calculateMarkerRoute") + routeQuery.clearWaypoints(); + routeQuery.addWaypoint(startCoordinate) + routeQuery.addWaypoint(mouseArea.lastCoordinate) + routeQuery.travelModes = RouteQuery.CarTravel + routeQuery.routeOptimizations = RouteQuery.FastestRoute + for (var i=0; i<9; i++) { + routeQuery.setFeatureWeight(i, 0) + } + routeModel.update(); + } + + // Calculate direction from latitude and longitude between two points + function calculateDirection(lat1, lon1, lat2, lon2) { + var curlat = lat1 * Math.PI / 180; + var curlon = lon1 * Math.PI / 180; + var taglat = lat2 * Math.PI / 180; + var taglon = lon2 * Math.PI / 180; + + var Y = Math.sin(taglon - curlon); + var X = Math.cos(curlat) * Math.tan(taglat) - Math.sin(curlat) * Math.cos(Y); + var direction = 180 * Math.atan2(Y,X) / Math.PI; + if (direction < 0) { + direction = direction + 360; + } + return direction; + } + + // Calculate distance from latitude and longitude between two points + function calculateDistance(lat1, lon1, lat2, lon2) + { + var radLat1 = lat1 * Math.PI / 180; + var radLon1 = lon1 * Math.PI / 180; + var radLat2 = lat2 * Math.PI / 180; + var radLon2 = lon2 * Math.PI / 180; + + var r = 6378137.0; + + var averageLat = (radLat1 - radLat2) / 2; + var averageLon = (radLon1 - radLon2) / 2; + var result = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(averageLat), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(averageLon), 2))); + return Math.round(result); + } + + // Setting the next car position from the direction and demonstration mileage + function setNextCoordinate(curlat,curlon,direction,distance) + { + var radian = direction * Math.PI / 180 + var lat_per_meter = 111319.49079327358; + var lat_distance = distance * Math.cos(radian); + var addlat = lat_distance / lat_per_meter + var lon_distance = distance * Math.sin(radian) + var lon_per_meter = (Math.cos( (curlat+addlat) / 180 * Math.PI) * 2 * Math.PI * 6378137) / 360; + var addlon = lon_distance / lon_per_meter + map.currentpostion = QtPositioning.coordinate(curlat+addlat, curlon+addlon); + } + + function addPoiIconSLOT(lat,lon,type) { + console.log("called addPoiIcon") + var poiItem; + switch(type){ + case 0: + poiItem = Qt.createQmlObject(" + import QtQuick 2.0; + import QtLocation 5.9; + MapQuickItem { + id: poi_icon; + anchorPoint.x: icon_flag_liteblue_image.width/2; + anchorPoint.y: icon_flag_liteblue_image.height; + sourceItem: Image { + id: icon_flag_liteblue_image; + width: 32; + height: 37; + source: \"images/Flag-export_lightblue.png\"; + } + } + ",map,"dynamic"); + break; + case 1: + poiItem = Qt.createQmlObject(" + import QtQuick 2.0; + import QtLocation 5.9; + MapQuickItem { + id: poi_icon; + anchorPoint.x: icon_building_image.width/2; + anchorPoint.y: icon_building_image.height; + sourceItem: Image { + id: icon_building_image; + width: 32; + height: 37; + source: \"images/BuildingIcon.png\"; + } + } + ",map,"dynamic"); + break; + case 2: + poiItem = Qt.createQmlObject(" + import QtQuick 2.0; + import QtLocation 5.9; + MapQuickItem { + id: poi_icon; + anchorPoint.x: icon_church_image.width/2; + anchorPoint.y: icon_church_image.height; + sourceItem: Image { + id: icon_church_image; + width: 32; + height: 37; + source: \"images/ChurchIcon.png\"; + } + } + ",map,"dynamic"); + break; + case 3: + poiItem = Qt.createQmlObject(" + import QtQuick 2.0; + import QtLocation 5.9; + MapQuickItem { + id: poi_icon; + anchorPoint.x: icon_restaurant_image.width/2; + anchorPoint.y: icon_restaurant_image.height; + sourceItem: Image { + id: icon_restaurant_image; + width: 32; + height: 37; + source: \"images/RestaurantMapIcon.png\"; + } + } + ",map,"dynamic"); + break; + case 4: + poiItem = Qt.createQmlObject(" + import QtQuick 2.0; + import QtLocation 5.9; + MapQuickItem { + id: poi_icon; + anchorPoint.x: icon_supermarket_image.width/2; + anchorPoint.y: icon_supermarket_image.height; + sourceItem: Image { + id: icon_supermarket_image; + width: 32; + height: 37; + source: \"images/SupermarketMapIcon.png\"; + } + } + ",map,"dynamic"); + break; + default: + poiItem = null; + break; + } + + if(poiItem === null) { + console.log("error creating object" + poiItem.errorString()); + return false; + } + + poiItem.coordinate = QtPositioning.coordinate(lat, lon); + map.addMapItem(poiItem); + poiArray.push(poiItem); +// console.log("success creating object"); + return true; + } + + MouseArea { + id: mouseArea + property variant lastCoordinate + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onPressed : { + map.lastX = mouse.x + map.lastY = mouse.y + map.pressX = mouse.x + map.pressY = mouse.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) + } + + onPositionChanged: { + if (mouse.button === Qt.LeftButton) { + map.lastX = mouse.x + map.lastY = mouse.y + } + } + + onPressAndHold:{ + if(btn_guidance.state !== "onGuide") + { + if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold + && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { + map.addDestination(lastCoordinate) + } + } + + } + } + gesture.onFlickStarted: { + btn_present_position.state = "Optional" + } + gesture.onPanStarted: { + btn_present_position.state = "Optional" + } + function updatePositon() + { +// console.log("updatePositon") + if(pathcounter <= routeModel.get(0).path.length - 1){ +// console.log("path: ", pathcounter, "/", routeModel.get(0).path.length - 1, " segment: ", segmentcounter, "/", routeModel.get(0).segments.length - 1) +// console.log("from_to:",map.currentpostion.latitude,",",map.currentpostion.longitude,",",routeModel.get(0).path[pathcounter].latitude,",",routeModel.get(0).path[pathcounter].longitude) + // calculate distance + var next_distance = calculateDistance(map.currentpostion.latitude, + map.currentpostion.longitude, + routeModel.get(0).path[pathcounter].latitude, + routeModel.get(0).path[pathcounter].longitude); +// console.log("next_distance:",next_distance); + + // calculate direction + var next_direction = calculateDirection(map.currentpostion.latitude, + map.currentpostion.longitude, + routeModel.get(0).path[pathcounter].latitude, + routeModel.get(0).path[pathcounter].longitude); +// console.log("next_direction:",next_direction); + + // calculate next cross distance + var next_cross_distance = calculateDistance(map.currentpostion.latitude, + map.currentpostion.longitude, + routeModel.get(0).segments[segmentcounter].path[0].latitude, + routeModel.get(0).segments[segmentcounter].path[0].longitude); +// console.log("next_cross_distance:",next_cross_distance); + // set next coordidnate + if(next_distance < (root.car_moving_distance * 1.5)) + { + map.currentpostion = routeModel.get(0).path[pathcounter] + if(pathcounter != 0){ + car_accumulated_distance += next_distance + } + map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) + if(pathcounter < routeModel.get(0).path.length - 1){ + pathcounter++ + } + else + { + // Arrive at your destination + btn_guidance.sts_guide = 0 + map.qmlSignalArrvied() + } + }else{ + setNextCoordinate(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,root.car_moving_distance) + if(pathcounter != 0){ + car_accumulated_distance += root.car_moving_distance + } + map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) + } +// console.log("NextCoordinate:",map.currentpostion.latitude,",",map.currentpostion.longitude) + + // car_position_mapitem angle + root.prev_car_direction = root.car_direction + root.car_direction = next_direction + + if(btn_present_position.state === "Flowing") + { + // update map.center + map.center = map.currentpostion + + rotateMapSmooth() + } + + // report a new instruction if current position matches with the head position of the segment + if(segmentcounter <= routeModel.get(0).segments.length - 1){ + if(next_cross_distance < 2){ +// console.log("new segment instruction: ", routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + progress_next_cross.setProgress(0) + if(segmentcounter < routeModel.get(0).segments.length - 1){ + segmentcounter++ + } + if(segmentcounter === routeModel.get(0).segments.length - 1){ + img_destination_direction.state = "12" + map.removeMapItem(icon_segment_point) + }else{ + img_destination_direction.state = routeModel.get(0).segments[segmentcounter].maneuver.direction + icon_segment_point.coordinate = routeModel.get(0).segments[segmentcounter].path[0] + map.addMapItem(icon_segment_point) + // console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + // guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + } + }else{ + if(next_cross_distance <= 330 && last_segmentcounter != segmentcounter) { + last_segmentcounter = segmentcounter + console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + } + // update progress_next_cross + progress_next_cross.setProgress(next_cross_distance) + } + } + } + } + function removePoiIconsSLOT(category_id){ + console.log("called removePoiIcons") + while(poiArray.length>0) + map.removeMapItem(poiArray.pop()) + } + + function doGetRouteInfoSlot(){ + if(btn_guidance.sts_guide == 0){ // idle + console.log("called doGetRouteInfoSlot sts_guide == idle") + map.qmlSignalPosInfo(car_position_lat, car_position_lon,car_direction,car_accumulated_distance); + }else if(btn_guidance.sts_guide == 1){ // Routing + console.log("called doGetRouteInfoSlot sts_guide == Routing") + map.qmlSignalPosInfo(car_position_lat, car_position_lon,car_direction,car_accumulated_distance); + map.qmlSignalRouteInfo(car_position_lat, car_position_lon,routeQuery.waypoints[1].latitude,routeQuery.waypoints[1].longitude); + }else if(btn_guidance.sts_guide == 2){ // onGuide + console.log("called doGetRouteInfoSlot sts_guide == onGuide") + map.qmlSignalRouteInfo(car_position_lat, car_position_lon,routeQuery.waypoints[1].latitude,routeQuery.waypoints[1].longitude); + } + } + + function rotateMapSmooth(){ + var prev = root.prev_car_direction + var now = root.car_direction + var diff + + if(root.st_heading_up){ + + diff = now - prev + + if ( 180 < diff ){ + diff = diff - 360.0 + } else if ( diff < -180 ){ + diff = diff + 360.0 + } + + //console.log("prev:", prev, ", now:", now, ", diff:", diff) + + if( 0 < diff ){ + rot_anim.direction = RotationAnimation.Clockwise + } else { + rot_anim.direction = RotationAnimation.Counterclockwise + } + + map.state = "none" + map.state = "smooth_rotate" + }else{ + diff = 0 - prev + + if ( 180 < diff ){ + diff = diff - 360.0 + } else if ( diff < -180 ){ + diff = diff + 360.0 + } + + //console.log("prev:", prev, ", now:", now, ", diff:", diff) + if( 0 < diff ){ + rot_anim.direction = RotationAnimation.Clockwise + } else { + rot_anim.direction = RotationAnimation.Counterclockwise + } + + map.state = "smooth_rotate_north" + } + } + + states: [ + State { + name: "none" + }, + State { + name: "smooth_rotate" + PropertyChanges { target: map; bearing: root.car_direction } + }, + State { + name: "smooth_rotate_north" + PropertyChanges { target: map; bearing: 0 } + } + ] + + transitions: Transition { + NumberAnimation { properties: "center"; easing.type: Easing.InOutQuad } + RotationAnimation { + id: rot_anim + property: "bearing" + easing.type: Easing.InOutQuad + duration: 200 + } + } + } + + BtnPresentPosition { + id: btn_present_position + anchors.right: parent.right + anchors.rightMargin: 125 + anchors.bottom: parent.bottom + anchors.bottomMargin: 125 + } + + BtnMapDirection { + id: btn_map_direction + anchors.top: parent.top + anchors.topMargin: 25 + anchors.left: parent.left + anchors.leftMargin: 25 + } + + BtnGuidance { + id: btn_guidance + anchors.top: parent.top + anchors.topMargin: 25 + anchors.right: parent.right + anchors.rightMargin: 125 + } + + BtnShrink { + id: btn_shrink + anchors.left: parent.left + anchors.leftMargin: 25 + anchors.bottom: parent.bottom + anchors.bottomMargin: 250 + } + + BtnEnlarge { + id: btn_enlarge + anchors.left: parent.left + anchors.leftMargin: 25 + anchors.bottom: parent.bottom + anchors.bottomMargin: 125 + } + + ImgDestinationDirection { + id: img_destination_direction + anchors.top: parent.top + anchors.topMargin: 25 + anchors.left: parent.left + anchors.leftMargin: 150 + } + + ProgressNextCross { + id: progress_next_cross + anchors.top: parent.top + anchors.topMargin: 25 + anchors.left: img_destination_direction.right + anchors.leftMargin: 20 + } +} diff --git a/app/navigation.qrc b/app/navigation.qrc new file mode 100644 index 0000000..b0c2023 --- /dev/null +++ b/app/navigation.qrc @@ -0,0 +1,12 @@ +<RCC>
+ <qresource prefix="/">
+ <file>navigation.qml</file>
+ <file>BtnMapDirection.qml</file>
+ <file>BtnShrink.qml</file>
+ <file>BtnEnlarge.qml</file>
+ <file>ImgDestinationDirection.qml</file>
+ <file>ProgressNextCross.qml</file>
+ <file>BtnGuidance.qml</file>
+ <file>BtnPresentPosition.qml</file>
+ </qresource>
+</RCC>
diff --git a/app/testqt.qml b/app/testqt.qml deleted file mode 100755 index 52c5a47..0000000 --- a/app/testqt.qml +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import QtQuick 2.6 -import QtQuick.Layouts 1.1 -import QtQuick.Controls 2.0 -import QtWebSockets 1.0 -import QtLocation 5.9 -import QtPositioning 5.6 - -ApplicationWindow { - id: root - visible: true - width: 1080 - height: 1488 - title: qsTr("TestQt") - - Map{ - id: map - property variant pathcounter : 0 - property variant segmentcounter : 0 - property int lastX : -1 - property int lastY : -1 - property int pressX : -1 - property int pressY : -1 - property int jitterThreshold : 30 - anchors.fill: parent - plugin: Plugin { - name: "mapbox" - PluginParameter { name: "mapbox.access_token"; - value: "pk.eyJ1IjoiYWlzaW53ZWkiLCJhIjoiY2pqNWg2cG81MGJoazNxcWhldGZzaDEwYyJ9.imkG45PQUKpgJdhO2OeADQ" } - } - center: QtPositioning.coordinate(36.131998,-115.1516808) - zoomLevel: 14 - property variant modepositionfollowing : false - property variant currentpostion : QtPositioning.coordinate(36.131998,-115.1516808) - - MapQuickItem { - id: poiTheQtComapny - sourceItem: Rectangle { width: 14; height: 14; color: "#e41e25"; border.width: 2; border.color: "white"; smooth: true; radius: 7 } - coordinate { - latitude: 36.131998 - longitude: -115.1516808 - } - opacity: 1.0 - anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2) - } - MapQuickItem { - sourceItem: Text{ - text: "LAS VEGAS CONVENTION CENTER" - color:"#242424" - font.bold: true - styleColor: "#ECECEC" - style: Text.Outline - } - coordinate: poiTheQtComapny.coordinate - anchorPoint: Qt.point(-poiTheQtComapny.sourceItem.width * 0.5,poiTheQtComapny.sourceItem.height * 1.5) - } - MapQuickItem { - id: marker - anchorPoint.x: imageMarker.width/2 - anchorPoint.y: imageMarker.height/2 - sourceItem: Image { - id: imageMarker - width: 150 - height: 150 - source: "images/car_icon.svg" - } - coordinate: map.currentpostion - } - - RouteModel { - id: routeModel - plugin : map.plugin - query: RouteQuery { - id: routeQuery - } - onStatusChanged: { - if (status == RouteModel.Ready) { - switch (count) { - case 0: - // technically not an error - // map.routeError() - break - case 1: - map.pathcounter = 0 - map.segmentcounter = 0 - // report position on route and 1st instruction - console.log("1 route found") - console.log("path: ", get(0).path.length, "segment: ", get(0).segments.length) - for(var i = 0; i < get(0).path.length; i++){ - console.log("", get(0).path[i]) - } - console.log("1st instruction: ", get(0).segments[map.segmentcounter].maneuver.instructionText) - break - } - } else if (status == RouteModel.Error) { - // map.routeError() - } - } - } - - Component { - id: routeDelegate - - MapRoute { - id: route - route: routeData - line.color: "#4658da" - line.width: 10 - smooth: true - opacity: 0.8 - } - } - - MapItemView { - model: routeModel - delegate: routeDelegate - autoFitViewport: true - } - - function calculateMarkerRoute() - { - var startCoordinate = QtPositioning.coordinate(36.131998,-115.1516808) // The Qt Company in Oslo - - console.log("calculateMarkerRoute") - routeQuery.clearWaypoints(); - routeQuery.addWaypoint(startCoordinate) - routeQuery.addWaypoint(mouseArea.lastCoordinate) - routeQuery.travelModes = RouteQuery.CarTravel - routeQuery.routeOptimizations = RouteQuery.FastestRoute - for (var i=0; i<9; i++) { - routeQuery.setFeatureWeight(i, 0) - } - routeModel.update(); - } - MouseArea { - id: mouseArea - property variant lastCoordinate - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton - - onPressed : { - map.lastX = mouse.x - map.lastY = mouse.y - map.pressX = mouse.x - map.pressY = mouse.y - lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) - } - - onPositionChanged: { - if (mouse.button == Qt.LeftButton) { - map.lastX = mouse.x - map.lastY = mouse.y - } - } - - onPressAndHold:{ - if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold - && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { - map.modepositionfollowing = false - // arrow.positionTimer.stop(); - map.calculateMarkerRoute(); - } - } - } - gesture.onFlickStarted: { - map.modepositionfollowing = false - } - gesture.onPanStarted: { - map.modepositionfollowing = false - } - - function updatePositon() - { - console.log("updatePositon") - if(routeModel.status == RouteModel.Ready){ - if(pathcounter < routeModel.get(0).path.length){ - console.log("path: ", pathcounter, "/", routeModel.get(0).path.length, "", routeModel.get(0).path[pathcounter]) - map.currentpostion = routeModel.get(0).path[pathcounter] - marker.coordinate = map.currentpostion - if(map.modepositionfollowing == true){ - map.center = map.currentpostion - } - // report a new instruction if current position matches with the head position of the segment - if(segmentcounter < routeModel.get(0).segments.length){ - if(routeModel.get(0).path[pathcounter] == routeModel.get(0).segments[segmentcounter].path[0]){ - console.log("new segment: ", segmentcounter, "/", routeModel.get(0).segments.length) - console.log("instruction: ", routeModel.get(0).segments[segmentcounter].maneuver.instructionText) - segmentcounter++ - } - } - pathcounter++ - }else{ - pathcounter = 0 - segmentcounter = 0 - map.currentpostion = QtPositioning.coordinate(36.131998,-115.1516808) - marker.coordinate = map.currentpostion - if(map.modepositionfollowing == true){ - map.center = map.currentpostion - } - } - }else{ - pathcounter = 0 - segmentcounter = 0 - } - } - } - - // use external nmea data to simulate current position -// PositionSource { -// id: src -// updateInterval: 500 -// active: true -// nmeaSource: "images/nmea.txt" -// -// onPositionChanged: { -// var coord = src.position.coordinate; -// console.log("Coordinate: ", src.position.coordinate); -// map.currentpostion = src.position.coordinate; -// } -// } - - Item { - id: present_position - x: 942 - y: 1328 - - Button { - id: btn_present_position - width: 100 - height: 100 - - function present_position_clicked() { - map.modepositionfollowing = true - map.center = map.currentpostion - } - onClicked: { present_position_clicked() } - - Image { - id: image_present_position - width: 92 - height: 92 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - source: "images/thum500_t002_0_ip_0175.jpg" - } - } - } - Item { - id: arrow - x: 940 - y: 20 - - Timer { - id: positionTimer - interval: 250; running: false; repeat: true - onTriggered: map.updatePositon() - } - - Button { - id: btn_arrow - width: 100 - height: 100 - - function arrow_clicked() { - if(positionTimer.running == false){ - map.modepositionfollowing = true - positionTimer.start(); - }else{ - map.modepositionfollowing = false - positionTimer.stop(); - } - } - - onClicked: { arrow_clicked() } - - Image { - id: image_arrow - width: 92 - height: 92 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - source: "images/SW_Patern_1.bmp" - } - } - } - - BtnMapDirection { - id: btn_map_direction - x: 15 - y: 20 - } - BtnShrink { - id: btn_shrink - x: 23 - y:1200 - } - BtnEnlarge { - id: btn_enlarge - x: 23 - y: 1330 - } - ImgDestinationDirection { - id: img_destination_direction - x: 120 - y: 20 - } - ProgressNextCross { - id: progress_next_cross - x: 225 - y: 20 - } -} diff --git a/app/testqt.qrc b/app/testqt.qrc deleted file mode 100755 index 7b1bfe1..0000000 --- a/app/testqt.qrc +++ /dev/null @@ -1,10 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>testqt.qml</file> - <file>BtnMapDirection.qml</file> - <file>BtnShrink.qml</file> - <file>BtnEnlarge.qml</file> - <file>ImgDestinationDirection.qml</file> - <file>ProgressNextCross.qml</file> - </qresource> -</RCC> |