Custom int inputs.

This commit is contained in:
armored-dragon 2024-11-19 07:55:30 -06:00
parent 97e6271391
commit 7c462ab71c
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 222 additions and 144 deletions

View file

@ -0,0 +1,151 @@
import QtQuick 2.7
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
// TODO: Non int numbers
// TODO: Numpad Enter key support
Item {
id: root;
property string settingText: "";
property var settingValue: 0;
// property bool isInt: true;
property int decimalPlaces: 0;
property real minValue: 0;
property real maxValue: 9;
property string suffixText: "";
// property real stepSize: 1;
signal valueChanged(int value);
height: 50;
width: parent.width;
RowLayout {
width: parent.width - 10;
height: parent.height;
anchors.horizontalCenter: parent.horizontalCenter;
Layout.alignment: Qt.AlignTop;
Text {
id: settingTextElem
height: parent.height;
text: settingText;
color: "white";
font.pointSize: 14;
width: parent.width - 200;
}
SpinBox {
id: spinbox;
value: settingValue;
// decimals: 2;
from: minValue;
to: maxValue;
// stepSize: stepSize;
Layout.alignment: Qt.AlignRight;
implicitWidth: 200;
implicitHeight: parent.height;
contentItem: TextField {
id: spinboxText;
color: "white";
text: parent.value;
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter
width: parent.width;
clip: true;
font.pointSize: 14
validator: RegExpValidator { regExp: /[0-9]*/ }
background: Rectangle {
color: "transparent";
border.width: 1;
border.color: "white";
radius: 10;
}
onTextChanged: {
valueChanged(spinbox.value);
}
Keys.onPressed: {
if (event.key === Qt.Key_Return) {
event.accepted = true;
valueChanged(spinboxText.text);
}
}
}
up.indicator: Button {
height: parent.height - 15;
width: parent.height;
x: parent.width - width;
anchors.verticalCenter: parent.verticalCenter;
background: Rectangle {
color: "transparent";
border.color: "white";
border.width: 1;
radius: 10;
}
Text {
text: "+";
color: "white";
font.pointSize: 20;
verticalAlignment: Qt.AlignVCenter
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;
}
onClicked: {
spinbox.value += 1;
valueChanged(spinbox.value);
}
}
down.indicator: Button {
height: parent.height - 15;
width: parent.height;
anchors.verticalCenter: parent.verticalCenter;
background: Rectangle {
color: "transparent";
border.color: "white";
border.width: 1;
radius: 10;
}
Text {
text: "-";
color: "white";
font.pointSize: 20;
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;
}
onClicked: {
spinbox.value -= 1;
valueChanged(spinbox.value);
}
}
background: Rectangle {
color: "transparent";
}
}
Text {
visible: suffixText != "";
text: suffixText;
color: "white";
height: parent.height;
verticalAlignment: Qt.AlignVCenter
}
}
}

View file

@ -157,159 +157,86 @@ Rectangle {
}
// FIXME: Height is hardcoded
// FPS sub options
Item {
Layout.fillWidth: true
visible: refresh_rate_cb.currentIndex == 3
height: 75 * 3
Layout.fillWidth: true;
visible: refresh_rate_cb.currentIndex == 3;
height: children[0].height;
width: parent.width;
Rectangle {
color: "#333333"
height: parent.children[1].height
width: parent.width
}
GridLayout {
columns: 2
width: parent.width - 10
anchors.horizontalCenter: parent.horizontalCenter
height: 75 * 3
color: "#222222";
width: parent.width;
height: children[0].height;
radius: 10;
Column {
Text {
text: "Focus Active"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
ColumnLayout {
width: parent.width - 10;
Component.onCompleted: {
text = Performance.getCustomRefreshRate(0)
SettingNumber {
settingText: "Focus Active";
minValue: 1;
decimalPlaces: 2;
maxValue: 9999;
suffixText: "fps";
settingValue: Performance.getCustomRefreshRate(0)
onValueChanged: {
Performance.setCustomRefreshRate(0, value);
}
onTextChanged: {
Performance.setCustomRefreshRate(0, text)
}
SettingNumber {
settingText: "Focus Inactive";
minValue: 1;
decimalPlaces: 2;
maxValue: 9999;
suffixText: "fps";
settingValue: Performance.getCustomRefreshRate(1)
onValueChanged: {
Performance.setCustomRefreshRate(1, value);
}
}
SettingNumber {
settingText: "Minimized";
minValue: 1;
decimalPlaces: 2;
maxValue: 9999;
suffixText: "fps";
settingValue: Performance.getCustomRefreshRate(3)
onValueChanged: {
Performance.setCustomRefreshRate(3, value);
}
}
SettingNumber {
settingText: "Startup";
minValue: 1;
decimalPlaces: 2;
maxValue: 9999;
suffixText: "fps";
settingValue: Performance.getCustomRefreshRate(4)
onValueChanged: {
Performance.setCustomRefreshRate(4, value);
}
}
SettingNumber {
settingText: "Shutdown";
minValue: 1;
decimalPlaces: 2;
maxValue: 9999;
suffixText: "fps";
settingValue: Performance.getCustomRefreshRate(5)
onValueChanged: {
Performance.setCustomRefreshRate(5, value);
}
}
}
Column {
Text {
text: "Focus Inactive"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
Component.onCompleted: {
text = Performance.getCustomRefreshRate(1)
}
onTextChanged: {
Performance.setCustomRefreshRate(1, text)
}
}
}
Column {
Text {
text: "Unfocus"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
Component.onCompleted: {
text = Performance.getCustomRefreshRate(2)
}
onTextChanged: {
Performance.setCustomRefreshRate(2, text)
}
}
}
Column {
Text {
text: "Minimized"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
Component.onCompleted: {
text = Performance.getCustomRefreshRate(3)
}
onTextChanged: {
Performance.setCustomRefreshRate(3, text)
}
}
}
Column {
Text {
text: "Startup"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
Component.onCompleted: {
text = Performance.getCustomRefreshRate(4)
}
onTextChanged: {
Performance.setCustomRefreshRate(4, text)
}
}
}
Column {
Text {
text: "Shutdown"
Layout.fillWidth: true
color: "white"
}
TextField {
width: 100
Layout.maximumWidth: 50
inputMethodHints: Qt.ImhFormattedNumbersOnly
validator: RegExpValidator { regExp: /[0-9]*/ }
Component.onCompleted: {
text = Performance.getCustomRefreshRate(5)
}
onTextChanged: {
Performance.setCustomRefreshRate(5, text)
}
}
}
}
}