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