lqml/examples/Qt6/9999/qml/main.qml
pls.153 dc29ac9084 add Qt6 version of some examples (see below); revisions
'9999', 'advanced-qml-auto-reload', 'planets', 'sokoban'
2024-10-22 13:27:56 +02:00

69 lines
1.3 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Window
Rectangle {
id: main
width: 200
height: 300 + input.height
color: "lavender"
TextField {
id: input
objectName: "input"
width: parent.width
horizontalAlignment: Qt.AlignHCenter
text: "0000"
inputMask: "9999"
inputMethodHints: Qt.ImhDigitsOnly
focus: true
onTextChanged: Lisp.call("app:draw-number", Number(text))
}
Canvas {
id: canvas
objectName: "canvas"
y: input.height
width: parent.width
height: {
var h = Qt.inputMethod.keyboardRectangle.y
var f = (Qt.platform.os === "android") ? Screen.devicePixelRatio : 1
h = (h === 0) ? main.height : h / f
return (h - input.height)
}
property var ctx
// functions to be called from Lisp
function begin(color, width) {
ctx.beginPath()
ctx.strokeStyle = color
ctx.lineWidth = width
ctx.lineCap = "round"
}
function end() {
ctx.stroke()
}
function drawLine(x1, y1, x2, y2) {
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
}
onPaint: {
ctx = getContext("2d")
ctx.reset()
ctx.translate(canvas.width / 2, canvas.height / 2)
var s = height / 340
ctx.scale(s, s)
Lisp.call("app:paint")
ctx.stroke()
}
}
}