summaryrefslogtreecommitdiff
path: root/modules/controlcenter/components/SliderInput.qml
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-01-28 19:21:44 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-01-28 19:21:44 +1100
commit9d7f0c48cebec02aaf2ca780b89a763ce91f8624 (patch)
tree2345921b670f730268203020e754465503707ed3 /modules/controlcenter/components/SliderInput.qml
parentcontrolcenter: remove qt5compat dep (diff)
downloadcaelestia-shell-9d7f0c48cebec02aaf2ca780b89a763ce91f8624.tar.gz
caelestia-shell-9d7f0c48cebec02aaf2ca780b89a763ce91f8624.tar.bz2
caelestia-shell-9d7f0c48cebec02aaf2ca780b89a763ce91f8624.zip
internal: format
Diffstat (limited to 'modules/controlcenter/components/SliderInput.qml')
-rw-r--r--modules/controlcenter/components/SliderInput.qml29
1 files changed, 14 insertions, 15 deletions
diff --git a/modules/controlcenter/components/SliderInput.qml b/modules/controlcenter/components/SliderInput.qml
index 7348368..11b3f70 100644
--- a/modules/controlcenter/components/SliderInput.qml
+++ b/modules/controlcenter/components/SliderInput.qml
@@ -21,7 +21,7 @@ ColumnLayout {
property int decimals: 1 // Number of decimal places to show (default: 1)
property var formatValueFunction: null // Optional custom format function
property var parseValueFunction: null // Optional custom parse function
-
+
function formatValue(val: real): string {
if (formatValueFunction) {
return formatValueFunction(val);
@@ -34,7 +34,7 @@ ColumnLayout {
// For DoubleValidator or no validator, use the decimals property
return val.toFixed(root.decimals);
}
-
+
function parseValue(text: string): real {
if (parseValueFunction) {
return parseValueFunction(text);
@@ -48,13 +48,13 @@ ColumnLayout {
}
return parseFloat(text);
}
-
+
signal valueModified(real newValue)
property bool _initialized: false
spacing: Appearance.spacing.small
-
+
Component.onCompleted: {
// Set initialized flag after a brief delay to allow component to fully load
Qt.callLater(() => {
@@ -80,13 +80,13 @@ ColumnLayout {
id: inputField
Layout.preferredWidth: 70
validator: root.validator
-
+
Component.onCompleted: {
// Initialize text without triggering valueModified signal
text = root.formatValue(root.value);
}
-
- onTextEdited: (text) => {
+
+ onTextEdited: text => {
if (hasFocus) {
const val = root.parseValue(text);
if (!isNaN(val)) {
@@ -100,14 +100,14 @@ ColumnLayout {
isValid = false;
}
}
-
+
if (isValid) {
root.valueModified(val);
}
}
}
}
-
+
onEditingFinished: {
const val = root.parseValue(text);
let isValid = true;
@@ -119,7 +119,7 @@ ColumnLayout {
isValid = false;
}
}
-
+
if (isNaN(val) || !isValid) {
text = root.formatValue(root.value);
}
@@ -143,7 +143,7 @@ ColumnLayout {
from: root.from
to: root.to
stepSize: root.stepSize
-
+
// Use Binding to allow slider to move freely during dragging
Binding {
target: slider
@@ -151,7 +151,7 @@ ColumnLayout {
value: root.value
when: !slider.pressed
}
-
+
onValueChanged: {
// Update input field text in real-time as slider moves during dragging
// Always update when slider value changes (during dragging or external updates)
@@ -160,7 +160,7 @@ ColumnLayout {
inputField.text = root.formatValue(newValue);
}
}
-
+
onMoved: {
const newValue = root.stepSize > 0 ? Math.round(value / root.stepSize) * root.stepSize : value;
root.valueModified(newValue);
@@ -169,7 +169,7 @@ ColumnLayout {
}
}
}
-
+
// Update input field when value changes externally (slider is already bound)
onValueChanged: {
// Only update if component is initialized to avoid issues during creation
@@ -178,4 +178,3 @@ ColumnLayout {
}
}
}
-