Fix non-sensical logic, timers and animations.

This commit is contained in:
reakjra
2025-11-07 16:28:45 +01:00
parent 7f49daf422
commit e50ea627e8
@@ -10,9 +10,8 @@ import qs.modules.common.widgets
Rectangle { Rectangle {
id: root id: root
color: Appearance.m3colors.m3surfaceContainer color: Appearance.m3colors.m3surfaceContainer
property real padding: 20 property real padding: 16
property bool showCheckIcon: false property string iconState: "normal"
property bool showError: false
implicitWidth: contentColumn.implicitWidth + padding * 2 implicitWidth: contentColumn.implicitWidth + padding * 2
implicitHeight: contentColumn.implicitHeight + padding * 2 implicitHeight: contentColumn.implicitHeight + padding * 2
@@ -20,23 +19,15 @@ Rectangle {
id: iconResetTimer id: iconResetTimer
interval: 1000 interval: 1000
onTriggered: { onTriggered: {
root.showCheckIcon = false; root.iconState = "normal";
}
}
Timer {
id: errorResetTimer
interval: 1000
onTriggered: {
root.showError = false;
} }
} }
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.showError = true; root.iconState = "error";
errorResetTimer.restart(); iconResetTimer.restart();
fpsField.text = ""; fpsField.text = "";
return; return;
} }
@@ -56,20 +47,13 @@ Rectangle {
fpsSetter.command = ["bash", "-c", cmd]; fpsSetter.command = ["bash", "-c", cmd];
fpsSetter.startDetached(); fpsSetter.startDetached();
root.showCheckIcon = true; root.iconState = "success";
iconResetTimer.restart(); iconResetTimer.restart();
// Clear the field after applying // Clear the field after applying
fpsField.text = ""; fpsField.text = "";
} }
Keys.onPressed: event => {
if (event.key === Qt.Key_Escape) {
fpsField.text = "";
event.onAccepted();
}
}
ColumnLayout { ColumnLayout {
id: contentColumn id: contentColumn
anchors.centerIn: parent anchors.centerIn: parent
@@ -82,21 +66,21 @@ Rectangle {
ToolbarTextField { ToolbarTextField {
id: fpsField id: fpsField
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredWidth: 200 Layout.preferredWidth: 180
placeholderText: root.showError ? Translation.tr("Insert a valid number!") : Translation.tr("Set FPS limit (e.g. 80)") placeholderText: root.iconState === "error" ? Translation.tr("Insert a valid number") : Translation.tr("Set FPS limit (e.g. 80)")
inputMethodHints: Qt.ImhDigitsOnly inputMethodHints: Qt.ImhDigitsOnly
focus: true focus: true
Keys.onReturnPressed: { onAccepted: {
root.applyLimit(); root.applyLimit();
event.onAccepted(); event.accepted = true;
} }
} }
RippleButton { RippleButton {
id: applyButton id: applyButton
implicitWidth: 36 implicitWidth: 25
implicitHeight: 36 implicitHeight: 25
buttonRadius: Appearance.rounding.full buttonRadius: Appearance.rounding.full
onClicked: { onClicked: {
root.applyLimit(); root.applyLimit();
@@ -105,21 +89,16 @@ Rectangle {
anchors.centerIn: parent anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pixelSize: Appearance.font.pixelSize.title font.pixelSize: Appearance.font.pixelSize.title
text: root.showError ? "close" : (root.showCheckIcon ? "check" : "save") text: root.iconState === "error" ? "close" : (root.iconState === "success" ? "check" : "save")
rotation: (root.showCheckIcon || root.showError) ? 360 : 0 rotation: root.iconState !== "normal" ? 360 : 0
color: root.showError ? "#ef5350" : (root.showCheckIcon ? Appearance.m3colors.m3primary : Appearance.m3colors.m3onSurface) color: root.iconState === "error" ? "#ef5350" : (root.iconState === "success" ? Appearance.m3colors.m3primary : Appearance.m3colors.m3onSurface)
Behavior on rotation { Behavior on rotation {
NumberAnimation { animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this)
duration: 200
easing.type: Easing.OutCubic
}
} }
Behavior on color { Behavior on color {
ColorAnimation { animation: Appearance.animation.elementMoveFast.colorAnimation.createObject(this)
duration: 200
}
} }
} }
} }