diff --git a/qml/Led.qml b/qml/Led.qml new file mode 100644 index 0000000..6fe8fbb --- /dev/null +++ b/qml/Led.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 +import QtGraphicalEffects 1.0 + +/** + * Led: a circle color + */ + +RadialGradient { + property color led_color: "red" + gradient: Gradient { + GradientStop { + position: 0.0 + color: led_color + } + GradientStop { + position: 0.5 + color: "transparent" + } + } +} diff --git a/qml/Scene.qml b/qml/Scene.qml index 45bc965..cc91aa4 100644 --- a/qml/Scene.qml +++ b/qml/Scene.qml @@ -18,7 +18,8 @@ Item { property int note: 2 property int octave: 4 property double freq: 440 - property double deviation: 0.1 + property double deviation: 0.12 + property bool found: true } TunerScreen { diff --git a/qml/TunerScreen.qml b/qml/TunerScreen.qml index 5cd6370..72113f4 100644 --- a/qml/TunerScreen.qml +++ b/qml/TunerScreen.qml @@ -18,6 +18,35 @@ Item { // landscape / portrait property bool is_portrait: height > width + // maximum absolute deviation to display green led + property double deviation_ok: 0.1 + property color led_green: "green" + property color led_red: "red" + + property bool dev_is_ok: Math.abs(tuner.deviation) <= deviation_ok + + Led { + anchors.top: meter.top + anchors.left: meter.left + anchors.topMargin: meter.width / 24 + anchors.leftMargin: anchors.topMargin + width: meter.width / 12 + height: width + led_color: dev_is_ok ? led_green : led_red + visible: tuner.found && (dev_is_ok || tuner.deviation < 0) + } + + Led { + anchors.top: meter.top + anchors.right: meter.right + anchors.topMargin: meter.width / 24 + anchors.rightMargin: anchors.topMargin + width: meter.width / 12 + height: width + led_color: dev_is_ok ? led_green : led_red + visible: tuner.found && (dev_is_ok || tuner.deviation > 0) + } + CircleMeter { id: meter theme: parent.theme diff --git a/qml/desktop.qrc b/qml/desktop.qrc index 47729ec..6a386f6 100644 --- a/qml/desktop.qrc +++ b/qml/desktop.qrc @@ -7,5 +7,6 @@ CircleMeter.qml ScaleToise.qml Toise.qml +Led.qml diff --git a/qml/sailfish.qrc b/qml/sailfish.qrc index 522404c..d05a64a 100644 --- a/qml/sailfish.qrc +++ b/qml/sailfish.qrc @@ -6,5 +6,6 @@ CircleMeter.qml ScaleToise.qml Toise.qml +Led.qml