From c99973a42b32c0878c94debec42036a6bccf19ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 30 Dec 2015 01:46:47 +0100 Subject: [PATCH] Added mouse control over sun and moon positions --- .../modeler/qml/AtmosphereSection.qml | 2 +- src/interface/modeler/qml/BasePanel.qml | 10 +++++++ .../modeler/qml/PanelAtmosphereDaytime.qml | 10 ++++--- src/interface/modeler/qml/WidgetDayTime.qml | 19 +++++++------ .../modeler/qml/WidgetSphericalCoords.qml | 28 ++++++++++++++++++- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/interface/modeler/qml/AtmosphereSection.qml b/src/interface/modeler/qml/AtmosphereSection.qml index cfb3dbf..3401c35 100644 --- a/src/interface/modeler/qml/AtmosphereSection.qml +++ b/src/interface/modeler/qml/AtmosphereSection.qml @@ -11,7 +11,7 @@ BaseSection { id: tool_daytime checked: true picture: "images/icon_atmosphere_daytime.png" - hovertext: qsTr("Change the time of day") + hovertext: qsTr("Control the sun and moon") } ToolbarButton { diff --git a/src/interface/modeler/qml/BasePanel.qml b/src/interface/modeler/qml/BasePanel.qml index ad26f8f..ac4b4ea 100644 --- a/src/interface/modeler/qml/BasePanel.qml +++ b/src/interface/modeler/qml/BasePanel.qml @@ -4,8 +4,18 @@ BaseRectangle { id: panel width: 200 height: parent.height + property string title: "" anchors.top: parent.top color: "#40909090" + + Text { + text: title + visible: title != "" + font.bold: true + font.pixelSize: 12 + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + } } diff --git a/src/interface/modeler/qml/PanelAtmosphereDaytime.qml b/src/interface/modeler/qml/PanelAtmosphereDaytime.qml index e7eded7..be0134f 100644 --- a/src/interface/modeler/qml/PanelAtmosphereDaytime.qml +++ b/src/interface/modeler/qml/PanelAtmosphereDaytime.qml @@ -1,7 +1,8 @@ import QtQuick 2.0 BasePanel { - width: 200 + width: 320 + title: tool_daytime.hovertext Column { anchors.centerIn: parent @@ -9,7 +10,7 @@ BasePanel { spacing: 30 Text { - text: "Sun location in the sky" + text: qsTr("Sun location in the sky") anchors.horizontalCenter: parent.horizontalCenter } @@ -19,10 +20,11 @@ BasePanel { anchors.horizontalCenter: parent.horizontalCenter icon: "images/icon_atmosphere_day.png" width: parent.width + onThetaChanged: atmosphere_daytime.value = (atmosphere_sun_direction.theta / (Math.PI * 2.0)) - 0.75 } Text { - text: "Time of day" + text: qsTr("Time of day") anchors.horizontalCenter: parent.horizontalCenter } @@ -34,7 +36,7 @@ BasePanel { } Text { - text: "Moon location in the sky" + text: qsTr("Moon location in the sky") anchors.horizontalCenter: parent.horizontalCenter } diff --git a/src/interface/modeler/qml/WidgetDayTime.qml b/src/interface/modeler/qml/WidgetDayTime.qml index a343af2..90f6a99 100644 --- a/src/interface/modeler/qml/WidgetDayTime.qml +++ b/src/interface/modeler/qml/WidgetDayTime.qml @@ -4,10 +4,11 @@ Grid { id: clock property real value + property real modvalue: value - Math.floor(value) - property int hour: value * 86400 / 3600 - property int minute: (value * 86400 - 3600 * hour) / 60 - property int second: value * 86400 - 3600 * hour - 60 * minute + property int hour: Math.floor(86400.0 * modvalue / 3600.0) + property int minute: Math.floor((86400.0 * modvalue - 3600.0 * hour) / 60.0) + property int second: Math.floor(86400.0 * modvalue - 3600.0 * hour - 60.0 * minute) rows: 3 columns: 5 rowSpacing: 4 @@ -16,21 +17,21 @@ Grid { width: 20 height: 10 source: "images/arrow_up.png" - onClicked: value += 1.0 / 24.0 + onClicked: value = modvalue + 1.0 / 24.0 } Item {width: 1; height: 1} ClickableImage { width: 20 height: 10 source: "images/arrow_up.png" - onClicked: value += 1.0 / 1440.0 + onClicked: value = modvalue + 1.0 / 1440.0 } Item {width: 1; height: 1} ClickableImage { width: 20 height: 10 source: "images/arrow_up.png" - onClicked: value += 1.0 / 86400.0 + onClicked: value = modvalue + 1.0 / 86400.0 } Text { @@ -58,20 +59,20 @@ Grid { width: 20 height: 10 source: "images/arrow_down.png" - onClicked: value -= 1.0 / 24.0 + onClicked: value = modvalue - 1.0 / 24.0 } Item {width: 1; height: 1} ClickableImage { width: 20 height: 10 source: "images/arrow_down.png" - onClicked: value -= 1.0 / 1440.0 + onClicked: value = modvalue - 1.0 / 1440.0 } Item {width: 1; height: 1} ClickableImage { width: 20 height: 10 source: "images/arrow_down.png" - onClicked: value -= 1.0 / 86400.0 + onClicked: value = modvalue - 1.0 / 86400.0 } } diff --git a/src/interface/modeler/qml/WidgetSphericalCoords.qml b/src/interface/modeler/qml/WidgetSphericalCoords.qml index 355c7ea..e623ebb 100644 --- a/src/interface/modeler/qml/WidgetSphericalCoords.qml +++ b/src/interface/modeler/qml/WidgetSphericalCoords.qml @@ -22,7 +22,20 @@ Row { height: parent.width / 10 anchors.centerIn: parent anchors.horizontalCenterOffset: width * 4 * Math.cos(phi) * Math.cos(theta) - anchors.verticalCenterOffset: -width * 4 * Math.sin(phi) * Math.cos(theta) + anchors.verticalCenterOffset: width * 4 * Math.sin(phi) * Math.cos(theta) + } + MouseArea { + anchors.fill: parent + hoverEnabled: true + property real oldval: 0 + + onPositionChanged: { + var newval = Math.atan2(mouseY - height / 2, mouseX - width / 2); + if (pressedButtons & Qt.LeftButton) { + phi += newval - oldval; + } + oldval = newval; + } } } @@ -41,5 +54,18 @@ Row { anchors.horizontalCenterOffset: width * 4.5 * Math.cos(theta) anchors.verticalCenterOffset: -width * 4.5 * Math.sin(theta) } + MouseArea { + anchors.fill: parent + hoverEnabled: true + property real oldval: 0 + + onPositionChanged: { + var newval = Math.atan2(height / 2 - mouseY, mouseX - width / 2); + if (pressedButtons & Qt.LeftButton) { + theta += newval - oldval; + } + oldval = newval; + } + } } }