Added mouse control over sun and moon positions

This commit is contained in:
Michaël Lemaire 2015-12-30 01:46:47 +01:00
parent c1d6a3261c
commit c99973a42b
5 changed files with 54 additions and 15 deletions

View file

@ -11,7 +11,7 @@ BaseSection {
id: tool_daytime id: tool_daytime
checked: true checked: true
picture: "images/icon_atmosphere_daytime.png" picture: "images/icon_atmosphere_daytime.png"
hovertext: qsTr("Change the time of day") hovertext: qsTr("Control the sun and moon")
} }
ToolbarButton { ToolbarButton {

View file

@ -4,8 +4,18 @@ BaseRectangle {
id: panel id: panel
width: 200 width: 200
height: parent.height height: parent.height
property string title: ""
anchors.top: parent.top anchors.top: parent.top
color: "#40909090" color: "#40909090"
Text {
text: title
visible: title != ""
font.bold: true
font.pixelSize: 12
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
}
} }

View file

@ -1,7 +1,8 @@
import QtQuick 2.0 import QtQuick 2.0
BasePanel { BasePanel {
width: 200 width: 320
title: tool_daytime.hovertext
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent
@ -9,7 +10,7 @@ BasePanel {
spacing: 30 spacing: 30
Text { Text {
text: "Sun location in the sky" text: qsTr("Sun location in the sky")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
@ -19,10 +20,11 @@ BasePanel {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
icon: "images/icon_atmosphere_day.png" icon: "images/icon_atmosphere_day.png"
width: parent.width width: parent.width
onThetaChanged: atmosphere_daytime.value = (atmosphere_sun_direction.theta / (Math.PI * 2.0)) - 0.75
} }
Text { Text {
text: "Time of day" text: qsTr("Time of day")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
@ -34,7 +36,7 @@ BasePanel {
} }
Text { Text {
text: "Moon location in the sky" text: qsTr("Moon location in the sky")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }

View file

@ -4,10 +4,11 @@ Grid {
id: clock id: clock
property real value property real value
property real modvalue: value - Math.floor(value)
property int hour: value * 86400 / 3600 property int hour: Math.floor(86400.0 * modvalue / 3600.0)
property int minute: (value * 86400 - 3600 * hour) / 60 property int minute: Math.floor((86400.0 * modvalue - 3600.0 * hour) / 60.0)
property int second: value * 86400 - 3600 * hour - 60 * minute property int second: Math.floor(86400.0 * modvalue - 3600.0 * hour - 60.0 * minute)
rows: 3 rows: 3
columns: 5 columns: 5
rowSpacing: 4 rowSpacing: 4
@ -16,21 +17,21 @@ Grid {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_up.png" source: "images/arrow_up.png"
onClicked: value += 1.0 / 24.0 onClicked: value = modvalue + 1.0 / 24.0
} }
Item {width: 1; height: 1} Item {width: 1; height: 1}
ClickableImage { ClickableImage {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_up.png" source: "images/arrow_up.png"
onClicked: value += 1.0 / 1440.0 onClicked: value = modvalue + 1.0 / 1440.0
} }
Item {width: 1; height: 1} Item {width: 1; height: 1}
ClickableImage { ClickableImage {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_up.png" source: "images/arrow_up.png"
onClicked: value += 1.0 / 86400.0 onClicked: value = modvalue + 1.0 / 86400.0
} }
Text { Text {
@ -58,20 +59,20 @@ Grid {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_down.png" source: "images/arrow_down.png"
onClicked: value -= 1.0 / 24.0 onClicked: value = modvalue - 1.0 / 24.0
} }
Item {width: 1; height: 1} Item {width: 1; height: 1}
ClickableImage { ClickableImage {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_down.png" source: "images/arrow_down.png"
onClicked: value -= 1.0 / 1440.0 onClicked: value = modvalue - 1.0 / 1440.0
} }
Item {width: 1; height: 1} Item {width: 1; height: 1}
ClickableImage { ClickableImage {
width: 20 width: 20
height: 10 height: 10
source: "images/arrow_down.png" source: "images/arrow_down.png"
onClicked: value -= 1.0 / 86400.0 onClicked: value = modvalue - 1.0 / 86400.0
} }
} }

View file

@ -22,7 +22,20 @@ Row {
height: parent.width / 10 height: parent.width / 10
anchors.centerIn: parent anchors.centerIn: parent
anchors.horizontalCenterOffset: width * 4 * Math.cos(phi) * Math.cos(theta) 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.horizontalCenterOffset: width * 4.5 * Math.cos(theta)
anchors.verticalCenterOffset: -width * 4.5 * Math.sin(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;
}
}
} }
} }