From 6364e628889a9b7ab8aa1cd43808ce1ae4055787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 4 May 2017 20:14:17 -0300 Subject: [PATCH] new wind rose version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- qgcresources.qrc | 2 +- resources/wind-rose-arrow.svg | 62 +++++++++++++ resources/wind-rose-arrows.svg | 75 ---------------- src/PlanView/SurveyItemEditor.qml | 141 +++++++++++++++--------------- 4 files changed, 135 insertions(+), 145 deletions(-) create mode 100644 resources/wind-rose-arrow.svg delete mode 100644 resources/wind-rose-arrows.svg diff --git a/qgcresources.qrc b/qgcresources.qrc index 43c1605e0..a5ec42a9d 100644 --- a/qgcresources.qrc +++ b/qgcresources.qrc @@ -194,7 +194,7 @@ resources/TrashDelete.svg resources/waves.svg resources/wind-rose.svg - resources/wind-rose-arrows.svg + resources/wind-rose-arrow.svg resources/XDelete.svg resources/XDeleteBlack.svg resources/icons/qgroundcontrol.ico diff --git a/resources/wind-rose-arrow.svg b/resources/wind-rose-arrow.svg new file mode 100644 index 000000000..94830efec --- /dev/null +++ b/resources/wind-rose-arrow.svg @@ -0,0 +1,62 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/resources/wind-rose-arrows.svg b/resources/wind-rose-arrows.svg deleted file mode 100644 index e583b3e21..000000000 --- a/resources/wind-rose-arrows.svg +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - diff --git a/src/PlanView/SurveyItemEditor.qml b/src/PlanView/SurveyItemEditor.qml index 943fe66b6..fdca2efb1 100644 --- a/src/PlanView/SurveyItemEditor.qml +++ b/src/PlanView/SurveyItemEditor.qml @@ -422,7 +422,7 @@ Rectangle { onClicked: { var cords = windRoseButton.mapToItem(_root, 0, 0) - windRose.popup(cords.x + windRoseButton.width/2, cords.y + windRoseButton.height/2); + windRosePie.popup(cords.x + windRoseButton.width / 2, cords.y + windRoseButton.height / 2); } } } @@ -547,83 +547,86 @@ Rectangle { } } - - PieMenu { - id: windRose - triggerMode: TriggerMode.TriggerOnPress - height: 2.75*windRoseButton.height - width: 2.75*windRoseButton.width - - onVisibleChanged: { - windRoseSvg.visible = visible + Image { + id: windRoseArrow + source: "/res/wind-rose-arrow.svg" + visible: windRosePie.visible + width: windRosePie.width / 5 + height: width * 1.454 + smooth: true + transform: Rotation { + origin.x: windRoseArrow.width / 2 + origin.y: windRoseArrow.height / 2 + axis { x: 0; y: 0; z: 1 } angle: windRosePie.angle } + x: windRosePie.x + Math.sin(- windRosePie.angle*Math.PI/180 - Math.PI/2)*(windRosePie.width/2 - windRoseArrow.width/2) + windRosePie.width / 2 - windRoseArrow.width / 2 + y: windRosePie.y + Math.cos(- windRosePie.angle*Math.PI/180 - Math.PI/2)*(windRosePie.height/2 - windRoseArrow.width/2) + windRosePie.height / 2 - windRoseArrow.height / 2 + z: windRosePie.z + } - style: PieMenuStyle { - cancelRadius: windRoseButton.height*0.5 - shadowRadius: 0 - startAngle: -22.5 - endAngle: 337.5 + Item { + id: windRosePie + height: 2.6*windRoseButton.height + width: 2.6*windRoseButton.width + visible: false + + property string colorCircle: Qt.rgba(0, 0, 0, 0.45) + property string colorBackground: Qt.rgba(0, 0, 0, 0.75) + property real lineWidth: windRoseButton.width / 3 + property real angle: 0 + + Canvas { + id: windRoseCanvas + anchors.fill: parent + + onPaint: { + var ctx = getContext("2d") + var x = width / 2 + var y = height / 2 + var angleWidth = 0.03 * Math.PI + var start = windRosePie.angle*Math.PI/180 - angleWidth + var end = windRosePie.angle*Math.PI/180 + angleWidth + ctx.reset() + + ctx.beginPath(); + ctx.arc(x, y, (width / 3) - windRosePie.lineWidth / 2, 0, 2*Math.PI, false) + ctx.lineWidth = windRosePie.lineWidth + ctx.strokeStyle = windRosePie.colorBackground + ctx.stroke() + + ctx.beginPath(); + ctx.arc(x, y, (width / 3) - windRosePie.lineWidth / 2, start, end, false) + ctx.lineWidth = windRosePie.lineWidth + ctx.strokeStyle = windRosePie.colorCircle + ctx.stroke() + } } + function popup(x, y) { + if (x !== undefined) + windRosePie.x = x - windRosePie.width / 2; + if (y !== undefined) + windRosePie.y = y - windRosePie.height / 2; - MenuItem { - onTriggered: { - gridAngleText.text = "-90"; - gridAngleText.editingFinished(); - } + windRosePie.visible = true; } - MenuItem { - onTriggered: { - gridAngleText.text = "-45"; - gridAngleText.editingFinished(); - } - } - MenuItem { - onTriggered: { - gridAngleText.text = "0"; - gridAngleText.editingFinished(); - } - } - MenuItem { - onTriggered: { - gridAngleText.text = "45"; - gridAngleText.editingFinished(); - } - } - MenuItem { - onTriggered: { - gridAngleText.text = "90"; - gridAngleText.editingFinished(); - } - } - MenuItem { - onTriggered: { - gridAngleText.text = "135"; - gridAngleText.editingFinished(); - } - } - MenuItem { - onTriggered: { - gridAngleText.text = "180"; - gridAngleText.editingFinished(); + + MouseArea { + id: mouseArea + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onClicked: { + windRosePie.visible = false; } - } - MenuItem { - onTriggered: { - gridAngleText.text = "-135"; + onPositionChanged: { + var point = Qt.point(mouseX - parent.width / 2, mouseY - parent.height / 2) + var angle = Math.round(Math.atan2(point.y, point.x) * 180 / Math.PI) + windRoseCanvas.requestPaint() + windRosePie.angle = angle + gridAngleText.text = angle gridAngleText.editingFinished(); } } } - - Image { - id: windRoseSvg - source: "/res/wind-rose-arrows.svg" - visible: false - width: windRose.width - height: windRose.height - x: windRose.x; - y: windRose.y; - z: windRose.z; - } } -- 2.22.0