// Small square checkbox primitive matching the QBZ dark theme. import { Theme } from "../foundation/semantic-colors.slint"; import { QbzIcon } from "QbzIcon.slint"; export component QbzCheckbox inherits Rectangle { in-out property checked: false; callback toggled(); width: 18px; height: 18px; border-radius: 4px; background: root.checked ? Theme.accent : transparent; border-width: root.checked ? 0px : 1.5px; border-color: Theme.text-muted; QbzIcon { source: @image-url("../assets/icons/check.svg"); visible: root.checked; width: 12px; height: 12px; x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; tint: Theme.accent-text; } TouchArea { mouse-cursor: pointer; clicked => { root.checked = !root.checked; root.toggled(); } } // Keyboard activation: Enter/Space toggle the box, same as a click. The // TouchArea stays the pointer source; this only adds key activation + focus. fs := FocusScope { // See QbzPrimaryButton: declared after `ta`, so Slint hit-tests it // first; focus-on-click:false stops it eating the first press. focus-on-click: false; key-pressed(event) => { if (event.text == Key.Return || event.text == " ") { root.checked = !root.checked; root.toggled(); return accept; } return reject; } } // Non-layout focus ring — transparent-bordered overlay shown only on // keyboard focus, so it never reflows the checkbox. Rectangle { x: 0; y: 0; width: parent.width; height: parent.height; background: transparent; border-width: 2px; border-color: fs.has-focus ? Theme.focus-ring : transparent; border-radius: parent.border-radius; } }