This commit is contained in:
TheUnrealDragon 2026-04-13 17:49:08 +05:30
commit 984c5acacc

130
Main.qml
View file

@ -11,6 +11,7 @@ Window {
title: qsTr("Hello World")
id: root
property color accent_color: "#F05FAF5F"
property color dark_accent_color: "#FF5F7F5F"
property color danger_color: "#F0AF2F1F"
property color water_color: "#F00F7FAF"
Material.accent: root.accent_color
@ -18,6 +19,7 @@ Window {
property int font_normal_text_size: 16
property double distance: 0
property int distance_count: 0
property string mode: "http"
// visibility: Window.FullScreen
Component.onCompleted: {
if(Qt.platform.os !== "android") {
@ -150,8 +152,8 @@ Window {
border.color: root.accent_color
border.width: 1
}
height: parent.height / 1.5
width: parent.width / 1.5
height: parent.height / 1.2
width: parent.width / 1.1
anchors.centerIn: Overlay.overlay
@ -279,7 +281,95 @@ Window {
}
}
Text {
id: settings_mode_text
anchors {
topMargin: 20
top: flip_bits_box.bottom
left: parent.left
}
font.pointSize: root.font_normal_text_size
color: root.accent_color
text: "Mode: "
}
Row {
id: mode_row
anchors {
left: settings_mode_text.right
right: parent.right
verticalCenter: settings_mode_text.verticalCenter
leftMargin: 10
}
RadioButton {
id: udp_radio_button
checked: config.mode === "udp" ? true : false
text: "UDP"
font.pointSize: root.font_normal_text_size
contentItem: Text {
text: udp_radio_button.text
font: udp_radio_button.font
opacity: enabled ? 1.0 : 0.3
color: udp_radio_button.down ? root.dark_accent_color : root.accent_color
verticalAlignment: Text.AlignVCenter
leftPadding: udp_radio_button.indicator.width + udp_radio_button.spacing
}
onCheckedChanged: {
if(checked) {
root.mode = "udp";
}
}
}
RadioButton {
id: http_radio_button
checked: config.mode === "http" ? true : false
text: "HTTP"
font.pointSize: root.font_normal_text_size
contentItem: Text {
text: http_radio_button.text
font: http_radio_button.font
opacity: enabled ? 1.0 : 0.3
color: http_radio_button.down ? root.dark_accent_color : root.accent_color
verticalAlignment: Text.AlignVCenter
leftPadding: http_radio_button.indicator.width + http_radio_button.spacing
}
onCheckedChanged: {
if(checked) {
root.mode = "http";
}
}
}
}
Text {
id: http_url_label
text: "Url: "
anchors {
topMargin: 20
top: settings_mode_text.bottom
left: parent.left
verticalCenter: http_url_input.verticalCenter
}
height: http_url_input.height
verticalAlignment: Text.AlignVCenter
color: root.accent_color
font.pointSize: root.font_normal_text_size
}
TextField {
id: http_url_input
text: config.url
anchors {
right: parent.right
rightMargin: 20
leftMargin: 20
top: mode_row.bottom
topMargin: 20
}
enabled: root.mode === "http" ? true : false
width: Math.max(parent.width / 2, parent.width - http_url_label.width - anchors.leftMargin)
color: root.accent_color
font.pointSize: root.font_normal_text_size
cursorPosition: 0
}
Text {
id: settings_error_label
@ -288,8 +378,8 @@ Window {
visible: settings_error_text === "" ? false : true
anchors {
topMargin: 20
top: flip_bits_box.bottom
bottom: flip_bits_box.top
top: http_url_label.bottom
bottom: reset_averages.top
bottomMargin: 10
left: parent.left
horizontalCenter: parent.horizontalCenter
@ -387,6 +477,8 @@ Window {
let min = parseFloat(min_thres_input.text);
let alert = parseFloat(alert_thres_input.text);
let flipBits = flip_bits_box.checked;
let mode = root.mode;
let url = http_url_input.text;
console.log("Parsed values:", max, min, alert, flip_bits_box.checked);
if(max < min) {
settings_error_label.settings_error_text = "Max cannot be less than min";
@ -400,8 +492,8 @@ Window {
let effective_max_reading = Math.max(0, (parseFloat(max_thres_input.text)) - current_min_reading);
let alert_effective_reading = (effective_max_reading * (100 - alert) / 100) + current_min_reading;
console.log("Alert effective reading is: " + alert_effective_reading + " for value: " + alert);
listener.setConfig(alert_effective_reading, flipBits);
config.saveConfig(max_thres_input.text, min_thres_input.text, alert_thres_input.text, flip_bits_box.checked);
listener.setConfig(alert_effective_reading, flipBits, mode, url);
config.saveConfig(max_thres_input.text, min_thres_input.text, alert_thres_input.text, flip_bits_box.checked, mode, url);
settings_popup.close();
}
onReleased: {
@ -520,11 +612,30 @@ Window {
ConfigInterface {
id: config
onConfigData: (max, min, alert) => {
console.log("Got config data as: ", max, min, alert);
onConfigData: (max, min, alert, mode, url) => {
console.log("Got config data as: ", max, min, alert, mode, url);
}
onModeChanged: {
root.mode = mode;
}
}
Timer {
id: init_timer
running: true
repeat: false
interval: 1000
onTriggered: {
console.log("Timer triggered saving config, hope everything is loaded by now");
let current_min_reading = Math.max(0, (parseFloat(min_thres_input.text)));
let effective_max_reading = Math.max(0, (parseFloat(max_thres_input.text)) - current_min_reading);
let alert = parseFloat(alert_thres_input.text);
let alert_effective_reading = (effective_max_reading * (100 - alert) / 100) + current_min_reading;
console.log("Setting initial configs: ", alert_effective_reading, config.flipBits , config.mode, config.url);
listener.setConfig(alert_effective_reading, config.flipBits , config.mode, config.url);
http_url_input.cursorPosition = 0;
}
}
UDPListener {
id: listener
@ -585,8 +696,7 @@ Window {
let alert = parseFloat(alert_thres_input.text);
let alert_effective_reading = (effective_max_reading * (100 - alert) / 100) + current_min_reading;
console.log("Alert effective reading is: " + alert_effective_reading + " for value: " + alert);
listener.setConfig(alert_effective_reading, flip_bits_box.checked);
listener.setConfig(alert_effective_reading, flip_bits_box.checked, root.mode, http_url_input.text);
}
distance_count += 1;