overlay: fps limiter: use enums for states

This commit is contained in:
end-4
2025-11-07 20:49:48 +01:00
parent daa4dd7b0f
commit a91fe7db30
@@ -9,10 +9,13 @@ import qs.modules.common.widgets
Rectangle { Rectangle {
id: root id: root
color: Appearance.m3colors.m3surfaceContainer
property real padding: 16 enum State { Normal, Success, Error }
property string iconState: "normal"
anchors.fill: parent anchors.fill: parent
property real padding: 16
property var currentState: FpsLimiterContent.State.Normal
color: Appearance.m3colors.m3surfaceContainer
implicitWidth: content.implicitWidth + (padding * 2) implicitWidth: content.implicitWidth + (padding * 2)
implicitHeight: content.implicitHeight + (padding * 2) implicitHeight: content.implicitHeight + (padding * 2)
@@ -20,14 +23,14 @@ Rectangle {
id: iconResetTimer id: iconResetTimer
interval: 1000 interval: 1000
onTriggered: { onTriggered: {
root.iconState = "normal"; root.currentState = FpsLimiterContent.State.Normal;
} }
} }
function applyLimit() { function applyLimit() {
var fpsValue = parseInt(fpsField.text); var fpsValue = parseInt(fpsField.text);
if (isNaN(fpsValue) || fpsValue < 0) { if (isNaN(fpsValue) || fpsValue < 0) {
root.iconState = "error"; root.currentState = FpsLimiterContent.State.Error;
iconResetTimer.restart(); iconResetTimer.restart();
fpsField.text = ""; fpsField.text = "";
return; return;
@@ -48,7 +51,7 @@ Rectangle {
fpsSetter.command = ["bash", "-c", cmd]; fpsSetter.command = ["bash", "-c", cmd];
fpsSetter.startDetached(); fpsSetter.startDetached();
root.iconState = "success"; root.currentState = FpsLimiterContent.State.Success;
iconResetTimer.restart(); iconResetTimer.restart();
// Clear the field after applying // Clear the field after applying
@@ -68,7 +71,7 @@ Rectangle {
id: fpsField id: fpsField
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredWidth: 200 Layout.preferredWidth: 200
placeholderText: root.iconState === "error" ? Translation.tr("Insert a valid number") : Translation.tr("Set FPS limit (e.g. 80)") placeholderText: root.currentState === FpsLimiterContent.State.Error ? Translation.tr("Enter a valid number") : Translation.tr("Set FPS limit")
inputMethodHints: Qt.ImhDigitsOnly inputMethodHints: Qt.ImhDigitsOnly
focus: true focus: true
@@ -79,8 +82,13 @@ Rectangle {
IconToolbarButton { IconToolbarButton {
id: applyButton id: applyButton
text: root.iconState === "error" ? "close" : (root.iconState === "success" ? "check" : "save") text: switch (root.currentState) {
enabled: root.iconState === "normal" && fpsField.text.length > 0 case FpsLimiterContent.State.Error: return "close";
case FpsLimiterContent.State.Success: return "check";
case FpsLimiterContent.State.Normal:
default: return "save";
}
enabled: root.currentState === FpsLimiterContent.State.Normal && fpsField.text.length > 0
onClicked: { onClicked: {
root.applyLimit(); root.applyLimit();
} }