Files
TNCcat/qml/AppToggle.qml
T
JulianandClaude Opus 5 1581a760be Drop Qt Quick Controls and Qt Widgets
The binary now links Core, Gui, Quick and QuickShapes, nothing else.

Qt Widgets was there for one reason, QSystemTrayIcon, so the tray icon is gone
and QApplication is back to QGuiApplication. The cat itself is the whole
interface: right-click or long-press opens the settings window, which carries
the tricks and a quit button. Ctrl+C in the terminal works as well.

The settings window is rebuilt from Qt Quick primitives. AppButton, AppSlider,
AppToggle and SettingsGroup replace the Controls types, keyboard handling and
accessible roles included, and a Flickable with plain positioners replaces
QtQuick.Layouts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 08:58:51 +02:00

73 lines
1.8 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
// An on/off switch built from primitives.
Item {
id: toggle
property bool checked: false
property alias text: label.text
signal toggled(bool checked)
function flip() {
toggle.toggled(!toggle.checked)
}
implicitWidth: track.width + 10 + label.implicitWidth
implicitHeight: Math.max(22, label.implicitHeight)
activeFocusOnTab: true
Accessible.role: Accessible.CheckBox
Accessible.name: label.text
Accessible.checked: toggle.checked
Accessible.onToggleAction: toggle.flip()
Rectangle {
id: track
anchors.verticalCenter: parent.verticalCenter
width: 40
height: 22
radius: 11
color: toggle.checked ? "#4d7ea8" : "#cfc9c0"
border.width: toggle.activeFocus ? 2 : 0
border.color: "#2f5f85"
antialiasing: true
Behavior on color { ColorAnimation { duration: 150 } }
Rectangle {
y: 3
x: toggle.checked ? track.width - width - 3 : 3
width: 16
height: 16
radius: 8
color: "white"
antialiasing: true
Behavior on x { NumberAnimation { duration: 150; easing.type: Easing.OutQuad } }
}
}
Text {
id: label
anchors.left: track.right
anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter
width: Math.max(0, toggle.width - track.width - 10)
elide: Text.ElideRight
color: "#2f2a36"
font.pixelSize: 13
}
TapHandler {
onTapped: toggle.flip()
}
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Space || event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
toggle.flip()
event.accepted = true
}
}
}