2026-03-06 15:55:00 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
property string result: ""
|
|
|
|
|
property string errorText: ""
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: 24
|
|
|
|
|
spacing: 16
|
|
|
|
|
|
|
|
|
|
// ── Title ──────────────────────────────────────────────
|
|
|
|
|
Text {
|
|
|
|
|
text: "Logos Calculator"
|
|
|
|
|
font.pixelSize: 20
|
|
|
|
|
font.weight: Font.DemiBold
|
2026-03-18 14:23:44 +01:00
|
|
|
color: "#ffffff"
|
2026-03-06 15:55:00 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
// ── Two-operand operations ─────────────────────────────
|
|
|
|
|
RowLayout {
|
|
|
|
|
spacing: 12
|
2026-03-06 15:55:00 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
TextField {
|
|
|
|
|
id: inputA
|
|
|
|
|
placeholderText: "a"
|
|
|
|
|
Layout.preferredWidth: 80
|
|
|
|
|
validator: IntValidator {}
|
|
|
|
|
}
|
2026-03-06 15:55:00 +00:00
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
TextField {
|
|
|
|
|
id: inputB
|
|
|
|
|
placeholderText: "b"
|
|
|
|
|
Layout.preferredWidth: 80
|
|
|
|
|
validator: IntValidator {}
|
|
|
|
|
}
|
2026-03-06 15:55:00 +00:00
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
Button {
|
|
|
|
|
text: "Add"
|
|
|
|
|
onClicked: callTwoOp("add", inputA.text, inputB.text)
|
|
|
|
|
}
|
2026-03-06 15:55:00 +00:00
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
Button {
|
|
|
|
|
text: "Multiply"
|
|
|
|
|
onClicked: callTwoOp("multiply", inputA.text, inputB.text)
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
// ── Single-operand operations ──────────────────────────
|
|
|
|
|
RowLayout {
|
|
|
|
|
spacing: 12
|
2026-03-06 15:55:00 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
TextField {
|
|
|
|
|
id: inputN
|
|
|
|
|
placeholderText: "n"
|
|
|
|
|
Layout.preferredWidth: 80
|
|
|
|
|
validator: IntValidator { bottom: 0 }
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
Button {
|
|
|
|
|
text: "Factorial"
|
|
|
|
|
onClicked: callOneOp("factorial", inputN.text)
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
2026-03-18 14:23:44 +01:00
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
text: "Fibonacci"
|
|
|
|
|
onClicked: callOneOp("fibonacci", inputN.text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
text: "libcalc version"
|
|
|
|
|
onClicked: callModule("libVersion", [])
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Result display ─────────────────────────────────────
|
|
|
|
|
Rectangle {
|
|
|
|
|
Layout.fillWidth: true
|
2026-03-18 14:23:44 +01:00
|
|
|
height: 56
|
|
|
|
|
color: root.errorText.length > 0 ? "#3d1a1a" : "#1a2d1a"
|
2026-03-06 15:55:00 +00:00
|
|
|
radius: 8
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
Text {
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
text: root.errorText.length > 0 ? root.errorText
|
|
|
|
|
: (root.result.length > 0 ? root.result : "Enter values and press a button")
|
|
|
|
|
color: root.errorText.length > 0 ? "#f85149" : "#56d364"
|
|
|
|
|
font.pixelSize: 15
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item { Layout.fillHeight: true }
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
// ── Logos bridge helpers ───────────────────────────────────
|
2026-03-06 15:55:00 +00:00
|
|
|
|
|
|
|
|
function callModule(method, args) {
|
|
|
|
|
root.errorText = ""
|
|
|
|
|
root.result = ""
|
|
|
|
|
|
|
|
|
|
if (typeof logos === "undefined" || !logos.callModule) {
|
2026-03-18 14:23:44 +01:00
|
|
|
root.errorText = "Logos bridge not available"
|
2026-03-06 15:55:00 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 14:23:44 +01:00
|
|
|
root.result = String(logos.callModule("calc_module", method, args))
|
2026-03-06 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function callTwoOp(method, a, b) {
|
2026-03-18 14:23:44 +01:00
|
|
|
if (a === "" || b === "") { root.errorText = "Enter values for a and b"; return }
|
2026-03-06 15:55:00 +00:00
|
|
|
callModule(method, [parseInt(a), parseInt(b)])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function callOneOp(method, n) {
|
2026-03-18 14:23:44 +01:00
|
|
|
if (n === "") { root.errorText = "Enter a value for n"; return }
|
2026-03-06 15:55:00 +00:00
|
|
|
callModule(method, [parseInt(n)])
|
|
|
|
|
}
|
|
|
|
|
}
|