Files
TNCcat/qml/Main.qml
T
JulianandClaude Opus 5 acef398f49 Workcat: cute desktop cat, no window closing
Reworks the example into a pure desktop-pet: the cat wanders, sits, grooms,
stretches, dashes and naps, reacts to petting and dragging, and follows the
cursor with its eyes. The window-scanning and Accessibility code is gone.

The cat is drawn from rounded primitives plus Shape paths in a fixed 100x90
design space, so it scales cleanly to any size.

Linux/X11 is the primary target: the tray is optional, Wayland gets a warning,
and WORKCAT_X11_BYPASS / WORKCAT_OPAQUE cover uncooperative window managers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 22:20:35 +02:00

88 lines
2.5 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import Workcat
Window {
id: root
required property CatController cat
required property AppSettings settings
readonly property var moodNames: ["walking", "running", "sitting", "grooming", "stretching", "sleeping", "loving", "alert"]
readonly property real floorY: Screen.desktopAvailableHeight - height
function openSettings() {
settingsLoader.active = true
if (settingsLoader.status === Loader.Ready)
(settingsLoader.item as SettingsWindow).show()
}
width: settings.catSize
height: Math.round(settings.catSize * 0.9)
x: cat.x
y: floorY
color: Platform.opaqueBackground ? settings.coat : "transparent"
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool
| Qt.NoDropShadowWindowHint | Qt.WindowDoesNotAcceptFocus
| (Platform.bypassWindowManager ? Qt.X11BypassWindowManagerHint : 0)
visible: true
title: qsTr("Workcat")
Component.onCompleted: {
cat.screenWidth = Screen.desktopAvailableWidth
cat.catWidth = width
}
onWidthChanged: cat.catWidth = width
Screen.onDesktopAvailableWidthChanged: cat.screenWidth = Screen.desktopAvailableWidth
Cat {
id: sprite
anchors.fill: parent
coat: root.settings.coat
facingRight: root.cat.facingRight
mood: root.moodNames[root.cat.mood]
lifted: root.cat.dragging
petted: root.cat.hovered && !root.cat.dragging
look: root.cat.look
Accessible.role: Accessible.Button
Accessible.name: qsTr("Workcat")
}
HoverHandler {
onHoveredChanged: root.cat.hovered = hovered
}
DragHandler {
target: null
onActiveChanged: root.cat.dragging = active
onCentroidChanged: {
if (active)
root.cat.x = Math.max(0, Math.min(root.cat.screenWidth - root.width,
root.x + centroid.position.x - centroid.pressPosition.x))
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: root.cat.pet()
onDoubleTapped: root.openSettings()
}
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: root.openSettings()
}
Loader {
id: settingsLoader
active: false
sourceComponent: SettingsWindow {
cat: root.cat
settings: root.settings
onClosing: settingsLoader.active = false
}
onLoaded: (item as SettingsWindow).show()
}
}