Add snap turn angle settings ui

This commit is contained in:
Kung-vr
2019-03-19 15:05:29 +09:00
parent bdf4227e5c
commit 510e3291f4
4 changed files with 150 additions and 4 deletions
+3
View File
@@ -7,6 +7,7 @@ import "space_drag"
import "space_turn"
import "height_toggle"
import "gravity"
import "snap_turn"
MyStackViewPage {
headerText: "Motion Settings"
@@ -22,6 +23,8 @@ MyStackViewPage {
GravityGroupBox { id: gravityGroupBox }
SnapTurnGroupBox { id: snapTurnGroupBox }
Item {
Layout.fillHeight: true
}
@@ -0,0 +1,112 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import ovras.advsettings 1.0
import "../../common"
GroupBox {
id: snapTurnGroupBox
Layout.fillWidth: true
label: MyText {
leftPadding: 10
text: "Snap Turn Angle"
bottomPadding: -10
}
background: Rectangle {
color: "transparent"
border.color: "#ffffff"
radius: 8
}
ColumnLayout {
anchors.fill: parent
Rectangle {
color: "#ffffff"
height: 1
Layout.fillWidth: true
Layout.bottomMargin: 5
}
RowLayout {
Layout.fillWidth: true
MyTextField {
id: snapTurnAngleText
text: "45°"
keyBoardUID: 154
Layout.preferredWidth: 150
Layout.leftMargin: 10
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val)) {
val = val % 180
MoveCenterTabController.snapTurnAngle = val.toFixed(2) * 100
text = ( Math.round( MoveCenterTabController.snapTurnAngle / 100 ) ) + "°"
} else {
text = ( Math.round( MoveCenterTabController.snapTurnAngle / 100 ) ) + "°"
}
}
}
Item {
Layout.fillWidth: true
}
MyPushButton {
id: snapTurnButton15
Layout.preferredWidth: 90
text:"15°"
onClicked: {
MoveCenterTabController.snapTurnAngle = 1500
}
}
MyPushButton {
id: snapTurnButton30
Layout.preferredWidth: 90
text:"30°"
onClicked: {
MoveCenterTabController.snapTurnAngle = 3000
}
}
MyPushButton {
id: snapTurnButton45
Layout.preferredWidth: 90
text:"45°"
onClicked: {
MoveCenterTabController.snapTurnAngle = 4500
}
}
MyPushButton {
id: snapTurnButton90
Layout.preferredWidth: 90
text:"90°"
onClicked: {
MoveCenterTabController.snapTurnAngle = 9000
}
}
MyPushButton {
id: snapTurnButton180
Layout.preferredWidth: 90
text:"180°"
onClicked: {
MoveCenterTabController.snapTurnAngle = 18000
}
}
}
}
Component.onCompleted: {
snapTurnAngleText.text = ( Math.round( MoveCenterTabController.snapTurnAngle / 100 ) ) + "°"
}
Connections {
target: MoveCenterTabController
onSnapTurnAngleChanged: {
snapTurnAngleText.text = ( Math.round( MoveCenterTabController.snapTurnAngle / 100 ) ) + "°"
}
}
}
+29 -2
View File
@@ -78,6 +78,11 @@ void MoveCenterTabController::initStage1()
{
m_turnComfortFactor = value.toUInt();
}
value = settings->value( "snapTurnAngle", m_snapTurnAngle );
if ( value.isValid() && !value.isNull() )
{
m_snapTurnAngle = value.toInt();
}
value = settings->value( "heightToggleOffset", m_heightToggleOffset );
if ( value.isValid() && !value.isNull() )
{
@@ -256,6 +261,28 @@ void MoveCenterTabController::setTempRotation( int value, bool notify )
}
}
int MoveCenterTabController::snapTurnAngle() const
{
return m_snapTurnAngle;
}
void MoveCenterTabController::setSnapTurnAngle( int value, bool notify )
{
if ( m_snapTurnAngle != value )
{
m_snapTurnAngle = value;
auto settings = OverlayController::appSettings();
settings->beginGroup( "playspaceSettings" );
settings->setValue( "snapTurnAngle", m_snapTurnAngle );
settings->endGroup();
settings->sync();
if ( notify )
{
emit snapTurnAngleChanged( m_snapTurnAngle );
}
}
}
bool MoveCenterTabController::adjustChaperone() const
{
return m_adjustChaperone;
@@ -1363,7 +1390,7 @@ void MoveCenterTabController::snapTurnLeft( bool snapTurnLeftJustPressed )
// TODO add interface to configure snap angle.
// temporarily hard coded to 45 degrees
int newRotationAngleDeg = m_rotation - 4500;
int newRotationAngleDeg = m_rotation - m_snapTurnAngle;
// Keep angle within -18000 ~ 18000 centidegrees
if ( newRotationAngleDeg > 18000 )
{
@@ -1386,7 +1413,7 @@ void MoveCenterTabController::snapTurnRight( bool snapTurnRightJustPressed )
// TODO add interface to configure snap angle.
// temporarily hard coded to 45 degrees
int newRotationAngleDeg = m_rotation + 4500;
int newRotationAngleDeg = m_rotation + m_snapTurnAngle;
// Keep angle within -18000 ~ 18000 centidegrees
if ( newRotationAngleDeg > 18000 )
{
+6 -2
View File
@@ -34,6 +34,8 @@ class MoveCenterTabController : public QObject
int rotation READ rotation WRITE setRotation NOTIFY rotationChanged )
Q_PROPERTY( int tempRotation READ tempRotation WRITE setTempRotation NOTIFY
tempRotationChanged )
Q_PROPERTY( int snapTurnAngle READ snapTurnAngle WRITE setSnapTurnAngle
NOTIFY snapTurnAngleChanged )
Q_PROPERTY( bool adjustChaperone READ adjustChaperone WRITE
setAdjustChaperone NOTIFY adjustChaperoneChanged )
Q_PROPERTY( bool moveShortcutRight READ moveShortcutRight WRITE
@@ -81,6 +83,7 @@ private:
int m_rotation = 0;
int m_oldRotation = 0;
int m_tempRotation = 0;
int m_snapTurnAngle = 4500;
bool m_adjustChaperone = true;
bool m_moveShortcutRightPressed = false;
bool m_moveShortcutLeftPressed = false;
@@ -170,6 +173,7 @@ public:
float offsetZ() const;
int rotation() const;
int tempRotation() const;
int snapTurnAngle() const;
bool adjustChaperone() const;
bool moveShortcutRight() const;
bool moveShortcutLeft() const;
@@ -219,11 +223,10 @@ public slots:
void setOffsetZ( float value, bool notify = true );
void setRotation( int value, bool notify = true );
void setTempRotation( int value, bool notify = true );
void setSnapTurnAngle( int value, bool notify = true );
void setAdjustChaperone( bool value, bool notify = true );
void setMoveShortcutRight( bool value, bool notify = true );
void setMoveShortcutLeft( bool value, bool notify = true );
void setTurnBindRight( bool value, bool notify = true );
@@ -255,6 +258,7 @@ signals:
void offsetZChanged( float value );
void rotationChanged( int value );
void tempRotationChanged( int value );
void snapTurnAngleChanged( int value );
void adjustChaperoneChanged( bool value );
void moveShortcutRightChanged( bool value );
void moveShortcutLeftChanged( bool value );