v1.3.0: live-bind display mode to config (dialog changes apply without restart); add configurable split-flap cascade seconds

This commit is contained in:
ArnoldCordewiner
2026-09-05 20:29:14 +02:00
parent 9774d8d191
commit bb9bed4184
7 changed files with 67 additions and 9 deletions
+15 -4
View File
@@ -13,6 +13,8 @@ Row {
// wired by the parent loader
property string display: "--"
property color trendColor: "#9e9e9e"
// seconds over which the cascade to a new price is spread
property int flapSeconds: 3
spacing: height * 0.06
@@ -20,6 +22,8 @@ Row {
property bool ready: false
readonly property real cellFont: height * 0.72
readonly property real cellWidth: cellFont * 0.80
// one flap open+close takes 260 ms; keep delays above that
readonly property int flapDuration: 260
Component.onCompleted: {
chars = display.split("");
@@ -32,14 +36,21 @@ Row {
}
var nc = display.split("");
var n = Math.max(chars.length, nc.length);
// spread the changed cells evenly across flapSeconds
var changed = [];
for (var i = 0; i < n; i++) {
var from = i < chars.length ? chars[i] : "";
var to = i < nc.length ? nc[i] : "";
if (from !== to) {
var cell = rep.itemAt(i);
if (cell) {
cell.flipTo(to, i * 45);
}
changed.push([i, to]);
}
}
var span = Math.max(1, flapSeconds) * 1000 - flapDuration;
var step = changed.length > 1 ? Math.max(0, Math.floor(span / (changed.length - 1))) : 0;
for (var j = 0; j < changed.length; j++) {
var cell = rep.itemAt(changed[j][0]);
if (cell) {
cell.flipTo(changed[j][1], j * step);
}
}
chars = nc;
+10
View File
@@ -14,6 +14,7 @@ Kirigami.FormLayout {
// The cfg_ prefix is what Plasma uses to read/write plasmoid.configuration
property alias cfg_displayMode: modeCombo.currentIndex
property alias cfg_refreshMinutes: intervalSpin.value
property alias cfg_flapSeconds: flapSpin.value
Item {
Kirigami.FormData.isSection: true
@@ -25,6 +26,15 @@ Kirigami.FormLayout {
model: [i18n("Plain text"), i18n("Split-flap board"), i18n("Nixie tubes")]
}
QQC2.SpinBox {
id: flapSpin
Kirigami.FormData.label: i18n("Split-flap cascade (seconds):")
from: 1
to: 15
stepSize: 1
editable: true
}
QQC2.SpinBox {
id: intervalSpin
Kirigami.FormData.label: i18n("Refresh interval (minutes):")
+28 -1
View File
@@ -25,11 +25,29 @@ Item {
readonly property int refreshMinutes: Math.max(5, plasmoid.configuration.refreshMinutes)
// Seconds over which the split-flap display cascades to a new price
readonly property int flapSeconds: Math.max(1, plasmoid.configuration.flapSeconds)
// 0 = plain text, 1 = split-flap board, 2 = nixie tubes
property int displayMode: 0
readonly property string modeSource: displayMode === 1 ? "DisplayFlip.qml"
: displayMode === 2 ? "DisplayNixie.qml"
: "DisplayText.qml"
// Enum config values arrive either as an int index or as the choice
// name, depending on the Plasma version — accept both.
function modeFromConfig(v) {
if (typeof v === "number") {
return Math.max(0, Math.min(2, Math.round(v)));
}
if (v === "SplitFlap") {
return 1;
}
if (v === "Nixie") {
return 2;
}
return 0;
}
readonly property string apiUrl: "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=eur"
// -1 = down, 0 = unchanged / no previous reading yet, 1 = up
@@ -72,7 +90,10 @@ Item {
Component.onCompleted: {
try {
displayMode = Math.max(0, Math.min(2, plasmoid.configuration.displayMode));
// live binding: config changes from the dialog apply immediately
displayMode = Qt.binding(function () {
return modeFromConfig(plasmoid.configuration.displayMode);
});
} catch (e) {
// outside a real plasmoid shell (tests): keep the default
}
@@ -119,6 +140,9 @@ Item {
onLoaded: {
item.display = Qt.binding(function () { return root.displayText; });
item.trendColor = Qt.binding(function () { return root.priceColor; });
if (item.flapSeconds !== undefined) {
item.flapSeconds = Qt.binding(function () { return root.flapSeconds; });
}
}
}
}
@@ -154,6 +178,9 @@ Item {
onLoaded: {
item.display = Qt.binding(function () { return root.displayText; });
item.trendColor = Qt.binding(function () { return root.priceColor; });
if (item.flapSeconds !== undefined) {
item.flapSeconds = Qt.binding(function () { return root.flapSeconds; });
}
}
}