topside-arch 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/contrib/aur/.SRCINFO +20 -0
  4. package/contrib/aur/PKGBUILD +35 -0
  5. package/contrib/aur/topside-arch.install +28 -0
  6. package/contrib/icons/hicolor/scalable/apps/topside.svg +28 -0
  7. package/contrib/systemd/topside.service +10 -0
  8. package/contrib/themes/sakura.json +31 -0
  9. package/dist/adapters/claude/attach.js +92 -0
  10. package/dist/adapters/claude/hook-event.js +173 -0
  11. package/dist/adapters/claude/one-shot.js +30 -0
  12. package/dist/adapters/claude/settings.js +78 -0
  13. package/dist/adapters/claude/usage.js +76 -0
  14. package/dist/adapters/codex/codex.js +73 -0
  15. package/dist/adapters/codex/patch.js +39 -0
  16. package/dist/adapters/codex/usage.js +77 -0
  17. package/dist/adapters/pi/extension.js +271 -0
  18. package/dist/adapters/pi/risk-gate.js +256 -0
  19. package/dist/cli/commands.js +615 -0
  20. package/dist/cli/hook-log.js +32 -0
  21. package/dist/cli/main.js +100 -0
  22. package/dist/daemon/preview.js +70 -0
  23. package/dist/daemon/processes.js +105 -0
  24. package/dist/daemon/server.js +437 -0
  25. package/dist/daemon/session-state.js +179 -0
  26. package/dist/daemon/store.js +176 -0
  27. package/dist/dms/setup.js +137 -0
  28. package/dist/hosts/hosts.js +39 -0
  29. package/dist/jump/jump.js +199 -0
  30. package/dist/pill/config.js +92 -0
  31. package/dist/pill/launch.js +38 -0
  32. package/dist/sekaipop/setup.js +267 -0
  33. package/dist/service/unit.js +77 -0
  34. package/dist/shared/ancestry.js +27 -0
  35. package/dist/shared/client.js +29 -0
  36. package/dist/shared/package.js +25 -0
  37. package/dist/shared/paths.js +69 -0
  38. package/dist/shared/protocol.js +35 -0
  39. package/dist/shared/qml-lib.js +33 -0
  40. package/dist/shared/result.js +6 -0
  41. package/dist/shared/terminal.js +42 -0
  42. package/dist/themes/themes.js +84 -0
  43. package/package.json +49 -4
  44. package/shell/core/AgentIcon.qml +24 -0
  45. package/shell/core/AppLogo.qml +48 -0
  46. package/shell/core/ApprovalRow.qml +197 -0
  47. package/shell/core/BoardDetail.qml +336 -0
  48. package/shell/core/BoardList.qml +419 -0
  49. package/shell/core/BoardNotice.qml +189 -0
  50. package/shell/core/CardButton.qml +55 -0
  51. package/shell/core/CardHeader.qml +46 -0
  52. package/shell/core/ChalkBoard.qml +99 -0
  53. package/shell/core/CompletionCard.qml +106 -0
  54. package/shell/core/FlapText.qml +110 -0
  55. package/shell/core/KeyCap.qml +72 -0
  56. package/shell/core/Mascot.qml +13 -0
  57. package/shell/core/MascotBadge.qml +40 -0
  58. package/shell/core/MascotEffect.qml +40 -0
  59. package/shell/core/Paper.qml +54 -0
  60. package/shell/core/PixelGrid.qml +40 -0
  61. package/shell/core/QuestionRow.qml +161 -0
  62. package/shell/core/SessionRow.qml +257 -0
  63. package/shell/core/Stamp.qml +62 -0
  64. package/shell/core/StatusDots.qml +33 -0
  65. package/shell/core/Surface.qml +32 -0
  66. package/shell/core/Tag.qml +22 -0
  67. package/shell/core/TerminalIcon.qml +34 -0
  68. package/shell/core/Theme.qml +100 -0
  69. package/shell/core/TicketDetail.qml +657 -0
  70. package/shell/core/TicketList.qml +717 -0
  71. package/shell/core/TicketNotice.qml +198 -0
  72. package/shell/core/TopsideClient.qml +201 -0
  73. package/shell/core/UsageLine.qml +106 -0
  74. package/shell/core/agents.js +79 -0
  75. package/shell/core/board.js +132 -0
  76. package/shell/core/hiding.js +68 -0
  77. package/shell/core/pixels.js +542 -0
  78. package/shell/core/qmldir +30 -0
  79. package/shell/core/sounds.js +31 -0
  80. package/shell/core/themes.js +195 -0
  81. package/shell/core/ticket.js +170 -0
  82. package/shell/dms-plugin/TopsideSettings.qml +696 -0
  83. package/shell/dms-plugin/TopsideWidget.qml +554 -0
  84. package/shell/dms-plugin/plugin.json +14 -0
  85. package/shell/pill.qml +279 -0
  86. package/shell/sekaipop-plugin/Bar.qml +150 -0
  87. package/shell/sekaipop-plugin/Card.qml +296 -0
  88. package/shell/sekaipop-plugin/Floating.qml +74 -0
  89. package/shell/sekaipop-plugin/ListWindow.qml +156 -0
  90. package/shell/sekaipop-plugin/Popup.qml +70 -0
  91. package/shell/sekaipop-plugin/Service.qml +418 -0
  92. package/shell/sekaipop-plugin/ShellLook.qml +43 -0
  93. package/shell/sekaipop-plugin/StyledCard.qml +194 -0
  94. package/shell/sekaipop-plugin/place.js +28 -0
  95. package/shell/sekaipop-plugin/plugin.json +109 -0
@@ -0,0 +1,46 @@
1
+ import QtQuick
2
+
3
+ // The top of every card: the session's own row, so a card reads like the
4
+ // list it came from. A plain title when the session isn't known (yet).
5
+ Item {
6
+ id: header
7
+ property var session: null
8
+ property string status: "waiting"
9
+ signal jump()
10
+
11
+ implicitHeight: loader.item ? loader.item.implicitHeight : 0
12
+
13
+ Loader {
14
+ id: loader
15
+ width: parent.width
16
+ sourceComponent: header.session ? row : plain
17
+ }
18
+
19
+ Component {
20
+ id: row
21
+ SessionRow {
22
+ session: Object.assign({}, header.session, { status: header.status })
23
+ onActivated: header.jump()
24
+ }
25
+ }
26
+
27
+ Component {
28
+ id: plain
29
+ Row {
30
+ height: 40
31
+ MascotBadge {
32
+ status: header.status
33
+ width: 54
34
+ anchors.verticalCenter: parent.verticalCenter
35
+ }
36
+ Text {
37
+ font.family: Theme.font
38
+ text: "Claude Code"
39
+ color: Theme.fg
40
+ font.pixelSize: Theme.s(14)
41
+ font.weight: Font.DemiBold
42
+ anchors.verticalCenter: parent.verticalCenter
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,99 @@
1
+ import QtQuick
2
+
3
+ // The menu board over the rail, in the Ticket style: a slate in a wooden
4
+ // frame, chalk dust where it was wiped, a stick of chalk on the ledge. The
5
+ // shift report is written on it in chalk (`chalkFont`, the first
6
+ // handwriting font installed, else the mono font). Everything is opaque:
7
+ // it's a board on a wall.
8
+ Rectangle {
9
+ id: board
10
+ // A hand that writes in chalk: the first of these the system has.
11
+ readonly property string chalkFont: {
12
+ const wanted = ["Caveat", "Patrick Hand", "Kalam", "Gloria Hallelujah", "Indie Flower", "Comic Shanns Mono", "ComicShannsMono Nerd Font"];
13
+ const have = Qt.fontFamilies();
14
+ return wanted.find(f => have.indexOf(f) >= 0) || Theme.monoFont;
15
+ }
16
+ readonly property int frame: 9
17
+ // Lay the writing inside this much from each edge.
18
+ readonly property int inset: frame + 12
19
+
20
+ radius: 5
21
+ // The frame: plain wood, darker toward the bottom.
22
+ gradient: Gradient {
23
+ GradientStop { position: 0.0; color: "#a8743f" }
24
+ GradientStop { position: 0.5; color: "#8a5a2e" }
25
+ GradientStop { position: 1.0; color: "#6b4222" }
26
+ }
27
+ border.color: "#4a2d16"
28
+
29
+ // The wood's grain along the frame.
30
+ Canvas {
31
+ anchors.fill: parent
32
+ opacity: 0.35
33
+ onPaint: {
34
+ const ctx = getContext("2d");
35
+ ctx.reset();
36
+ let seed = 11;
37
+ const next = () => (seed = (seed * 9301 + 49297) % 233280) / 233280;
38
+ ctx.strokeStyle = "#3d2410";
39
+ for (let i = 0; i < 26; i++) {
40
+ const y = next() * height;
41
+ ctx.lineWidth = 0.5 + next();
42
+ ctx.beginPath();
43
+ ctx.moveTo(0, y);
44
+ ctx.bezierCurveTo(width * 0.3, y + (next() - 0.5) * 6, width * 0.7, y + (next() - 0.5) * 6, width, y + (next() - 0.5) * 4);
45
+ ctx.stroke();
46
+ }
47
+ }
48
+ onWidthChanged: requestPaint()
49
+ onHeightChanged: requestPaint()
50
+ }
51
+
52
+ // The slate.
53
+ Rectangle {
54
+ id: slate
55
+ x: board.frame
56
+ y: board.frame
57
+ width: board.width - 2 * board.frame
58
+ height: board.height - 2 * board.frame
59
+ color: "#2a312c"
60
+ border.color: "#1a1f1b"
61
+
62
+ // Chalk dust: wiped clouds, then a few eraser strokes across.
63
+ Canvas {
64
+ anchors.fill: parent
65
+ onPaint: {
66
+ const ctx = getContext("2d");
67
+ ctx.reset();
68
+ let seed = 5;
69
+ const next = () => (seed = (seed * 9301 + 49297) % 233280) / 233280;
70
+ for (let i = 0; i < 9; i++) {
71
+ const x = next() * width, y = next() * height, r = 30 + next() * 90;
72
+ const g = ctx.createRadialGradient(x, y, 0, x, y, r);
73
+ g.addColorStop(0, "rgba(235, 235, 225, " + (0.04 + next() * 0.05) + ")");
74
+ g.addColorStop(1, "rgba(235, 235, 225, 0)");
75
+ ctx.fillStyle = g;
76
+ ctx.fillRect(x - r, y - r, 2 * r, 2 * r);
77
+ }
78
+ for (let i = 0; i < 4; i++) {
79
+ ctx.fillStyle = "rgba(235, 235, 225, " + (0.025 + next() * 0.03) + ")";
80
+ const y = next() * height;
81
+ ctx.fillRect(next() * width * 0.2, y, width * (0.4 + next() * 0.5), 6 + next() * 10);
82
+ }
83
+ }
84
+ onWidthChanged: requestPaint()
85
+ onHeightChanged: requestPaint()
86
+ }
87
+ }
88
+
89
+ // A stick of chalk on the bottom ledge.
90
+ Rectangle {
91
+ x: board.width - 74
92
+ y: board.height - board.frame + 2
93
+ width: 26
94
+ height: 5
95
+ radius: 2
96
+ color: "#f2efe6"
97
+ border.color: "#c9c5b8"
98
+ }
99
+ }
@@ -0,0 +1,106 @@
1
+ import QtQuick
2
+ import QtQuick.Layouts
3
+
4
+ // A finished turn, as Topside's completion card: the session's row, then a
5
+ // box with "You: <prompt>" and "Done" over the agent's last reply, drawn as
6
+ // markdown. A reply taller than about seven lines scrolls inside the box.
7
+ // A click on the header jumps to the session.
8
+ ColumnLayout {
9
+ id: card
10
+ required property var session
11
+ signal jump()
12
+
13
+ // About seven lines of the reply; more scrolls.
14
+ readonly property real replyHeight: 7 * Theme.s(13) * 1.65 + 28
15
+
16
+ spacing: 10
17
+
18
+ CardHeader {
19
+ session: card.session
20
+ status: "done"
21
+ Layout.fillWidth: true
22
+ onJump: card.jump()
23
+ }
24
+
25
+ Surface {
26
+ Layout.fillWidth: true
27
+ implicitHeight: box.implicitHeight
28
+
29
+ Column {
30
+ id: box
31
+ width: parent.width
32
+
33
+ Rectangle {
34
+ width: parent.width
35
+ height: 36
36
+ color: Theme.bgRaised
37
+ radius: Theme.cardRadius
38
+
39
+ // Square off the bottom corners under the rounded top.
40
+ Rectangle {
41
+ anchors.bottom: parent.bottom
42
+ width: parent.width
43
+ height: 9
44
+ color: parent.color
45
+ }
46
+
47
+ RowLayout {
48
+ x: 14
49
+ width: parent.width - 28
50
+ anchors.verticalCenter: parent.verticalCenter
51
+ spacing: 6
52
+ Text {
53
+ font.family: Theme.font
54
+ text: "You:"
55
+ color: Theme.fgDim
56
+ font.pixelSize: Theme.s(13)
57
+ font.weight: Font.Medium
58
+ }
59
+ Text {
60
+ font.family: Theme.font
61
+ text: card.session.lastPrompt || ""
62
+ color: Theme.fg
63
+ font.pixelSize: Theme.s(13)
64
+ font.weight: Font.Medium
65
+ elide: Text.ElideRight
66
+ textFormat: Text.PlainText
67
+ Layout.fillWidth: true
68
+ }
69
+ Text {
70
+ font.family: Theme.font
71
+ text: "Done"
72
+ color: Theme.fgFaint
73
+ font.pixelSize: Theme.s(13)
74
+ font.weight: Font.Medium
75
+ }
76
+ }
77
+ }
78
+
79
+ Flickable {
80
+ id: scroller
81
+ width: parent.width
82
+ height: Math.min(reply.implicitHeight + 28, card.replyHeight)
83
+ contentHeight: reply.implicitHeight + 28
84
+ interactive: contentHeight > height
85
+ boundsBehavior: Flickable.StopAtBounds
86
+ clip: true
87
+
88
+ Text {
89
+ id: reply
90
+ font.family: Theme.font
91
+ x: 14
92
+ y: 14
93
+ width: scroller.width - 28
94
+ text: card.session.lastMessage || "Finished."
95
+ textFormat: Text.MarkdownText
96
+ wrapMode: Text.Wrap
97
+ color: Theme.fg
98
+ linkColor: Theme.working
99
+ font.pixelSize: Theme.s(13)
100
+ lineHeight: 1.2
101
+ onLinkActivated: link => Qt.openUrlExternally(link)
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,110 @@
1
+ import QtQuick
2
+ import "board.js" as Board
3
+
4
+ // A run of split-flap cells, as on a departure board: `length` cells showing
5
+ // `text` in capitals. When the text changes, each cell that changes riffles
6
+ // through a few letters before it settles, the cells a beat apart. When the
7
+ // board comes down (made, or `riffleSerial` bumped), every cell riffles
8
+ // after `startDelay`, once the board's fade-in is done (VIA-PARITY §27).
9
+ Row {
10
+ id: run
11
+ property string text: ""
12
+ property int length: 8
13
+ property real cell: 16
14
+ property color color: "#f3efe2"
15
+ property bool blinking: false
16
+ // Bumped by the board each time it comes down again.
17
+ property int riffleSerial: 0
18
+ property int startDelay: 200
19
+ // The row you picked: its flaps light up.
20
+ property bool lit: false
21
+
22
+ readonly property string shown: Board.fit(text, length)
23
+
24
+ spacing: Math.max(1, Math.round(cell / 9))
25
+
26
+ Repeater {
27
+ model: run.length
28
+ delegate: Rectangle {
29
+ id: flap
30
+ required property int index
31
+ readonly property string target: run.shown.charAt(index)
32
+ property string face: target
33
+ property int turns: 0
34
+
35
+ width: run.cell
36
+ height: Math.round(run.cell * 1.5)
37
+ radius: Math.max(2, run.cell / 7)
38
+ gradient: Gradient {
39
+ GradientStop { position: 0.0; color: run.lit ? "#3a3b42" : "#2b2d34" }
40
+ GradientStop { position: 0.495; color: run.lit ? "#32333a" : "#24262c" }
41
+ GradientStop { position: 0.505; color: run.lit ? "#26272d" : "#1b1c21" }
42
+ GradientStop { position: 1.0; color: run.lit ? "#2c2d33" : "#202127" }
43
+ }
44
+
45
+ // The hinge across the middle.
46
+ Rectangle {
47
+ width: parent.width
48
+ height: 1
49
+ y: Math.round(parent.height / 2)
50
+ color: "#050506"
51
+ }
52
+
53
+ Text {
54
+ anchors.centerIn: parent
55
+ text: flap.face
56
+ color: run.color
57
+ font.family: Theme.monoFont
58
+ font.pixelSize: Math.round(run.cell * 0.95)
59
+ font.weight: Font.Bold
60
+ opacity: run.blinking && blink.dim ? 0.3 : 1
61
+ }
62
+
63
+ function flip() {
64
+ turns = 4 + index % 9;
65
+ riffle.restart();
66
+ }
67
+ onTargetChanged: if (face !== target) flip()
68
+ // A board that just came down clacks into place too, once it shows.
69
+ Component.onCompleted: if (target !== " ") later.restart()
70
+ Connections {
71
+ target: run
72
+ function onRiffleSerialChanged() {
73
+ if (flap.target !== " ") later.restart();
74
+ }
75
+ }
76
+ Timer {
77
+ id: later
78
+ interval: run.startDelay
79
+ onTriggered: flap.flip()
80
+ }
81
+
82
+ Timer {
83
+ id: riffle
84
+ interval: 55
85
+ repeat: true
86
+ onTriggered: {
87
+ if (flap.turns <= 0) {
88
+ flap.face = flap.target;
89
+ stop();
90
+ return;
91
+ }
92
+ flap.turns--;
93
+ flap.face = Board.flapChars.charAt(Math.floor(Math.random() * 36));
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ QtObject {
100
+ id: blink
101
+ property bool dim: false
102
+ }
103
+ Timer {
104
+ interval: 500
105
+ repeat: true
106
+ running: run.blinking
107
+ onTriggered: blink.dim = !blink.dim
108
+ onRunningChanged: if (!running) blink.dim = false
109
+ }
110
+ }
@@ -0,0 +1,72 @@
1
+ import QtQuick
2
+
3
+ // A chunky key under the departure board: a label in capitals and a small
4
+ // line under it (the shortcut, or what the key does). `go` is the amber one,
5
+ // the answer most people give.
6
+ Rectangle {
7
+ id: key
8
+ property string label: ""
9
+ property string sub: ""
10
+ property bool go: false
11
+ // The label's size; the key grows with it.
12
+ property int size: 11
13
+ signal clicked()
14
+
15
+ readonly property bool pressed: tap.pressed
16
+ // A row of keys sizes them all to its widest (BoardDetail.qml).
17
+ readonly property bool isKey: true
18
+
19
+ implicitWidth: Math.max(size * 5.6, column.implicitWidth + size * 1.8)
20
+ implicitHeight: column.implicitHeight + size * 1.3
21
+ radius: Math.round(size * 0.7)
22
+ border.color: "#000000"
23
+ y: pressed ? depth : 0
24
+ readonly property int depth: Math.max(3, Math.round(size / 4))
25
+ gradient: Gradient {
26
+ GradientStop { position: 0; color: key.go ? (hover.hovered ? "#ffd666" : "#f5c84b") : (hover.hovered ? "#474a56" : "#3a3d47") }
27
+ GradientStop { position: 1; color: key.go ? "#d9a92b" : "#24262d" }
28
+ }
29
+
30
+ // The key's side, which the press hides.
31
+ Rectangle {
32
+ z: -1
33
+ anchors.fill: parent
34
+ anchors.topMargin: key.pressed ? 0 : key.depth
35
+ anchors.bottomMargin: key.pressed ? 0 : -key.depth
36
+ radius: parent.radius
37
+ color: "#000000"
38
+ }
39
+
40
+ Column {
41
+ id: column
42
+ anchors.centerIn: parent
43
+ spacing: 1
44
+ Text {
45
+ anchors.horizontalCenter: parent.horizontalCenter
46
+ text: key.label.toUpperCase()
47
+ color: key.go ? "#111111" : "#e9ebf2"
48
+ font.family: Theme.monoFont
49
+ font.pixelSize: key.size
50
+ font.weight: Font.Bold
51
+ font.letterSpacing: key.size / 10
52
+ }
53
+ // Always there, blank when there's nothing to say, so every key in a
54
+ // row is as tall as the others.
55
+ Text {
56
+ anchors.horizontalCenter: parent.horizontalCenter
57
+ text: key.sub === "" ? " " : key.sub
58
+ color: key.go ? "#4d3d10" : "#8e94a6"
59
+ font.family: Theme.monoFont
60
+ font.pixelSize: Math.round(key.size * 0.82)
61
+ }
62
+ }
63
+
64
+ HoverHandler {
65
+ id: hover
66
+ cursorShape: Qt.PointingHandCursor
67
+ }
68
+ TapHandler {
69
+ id: tap
70
+ onTapped: key.clicked()
71
+ }
72
+ }
@@ -0,0 +1,13 @@
1
+ import QtQuick
2
+ import "agents.js" as Agents
3
+
4
+ // The agent's logo in pixels, in the color of the session's status.
5
+ PixelGrid {
6
+ property string agent: "claude"
7
+ property string status: "idle"
8
+ property real size: 12
9
+
10
+ pixels: Agents.style(agent).mascot
11
+ cell: size / 12
12
+ color: Theme.statusColor(status)
13
+ }
@@ -0,0 +1,40 @@
1
+ import QtQuick
2
+ import QtQuick.Effects
3
+
4
+ // The mascot, still, with its state's effect on the right and a soft glow in
5
+ // the status color. `cell` is the effect's pixel; the logo uses half of it,
6
+ // so both are six cells tall.
7
+ Item {
8
+ id: badge
9
+ property string agent: "claude"
10
+ property string status: "idle"
11
+ property real cell: 2
12
+ readonly property color color: Theme.statusColor(status)
13
+
14
+ implicitWidth: row.implicitWidth
15
+ implicitHeight: row.implicitHeight
16
+
17
+ Row {
18
+ id: row
19
+ spacing: badge.cell * 1.5
20
+ layer.enabled: true
21
+ layer.effect: MultiEffect {
22
+ shadowEnabled: true
23
+ shadowColor: Qt.rgba(badge.color.r, badge.color.g, badge.color.b, 0.55)
24
+ shadowBlur: 0.5
25
+ shadowHorizontalOffset: 0
26
+ shadowVerticalOffset: 0
27
+ }
28
+
29
+ Mascot {
30
+ agent: badge.agent
31
+ status: badge.status
32
+ size: 6 * badge.cell
33
+ }
34
+ MascotEffect {
35
+ status: badge.status
36
+ color: badge.color
37
+ cell: badge.cell
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ import QtQuick
2
+ import "agents.js" as Agents
3
+
4
+ // The small effect to a mascot's right, in a box as tall as the mascot so the
5
+ // layout never shifts. What it draws, where and how faded comes from the
6
+ // shared pixel file's `motion` (Agents.effectFrame):
7
+ // waiting "?" blinking
8
+ // done a heart floating up
9
+ // working a sparkle popping in a corner, then another
10
+ // idle a "z" blinking, floating from bottom left to top right
11
+ // reminder "!" blinking, drifting right, for a request nobody answered
12
+ Item {
13
+ id: effect
14
+ property string status: "idle"
15
+ property color color: "white"
16
+ property real cell: 2
17
+
18
+ width: Agents.motion.box * cell
19
+ height: Agents.motion.box * cell
20
+ clip: true
21
+
22
+ property real time: Date.now() / 1000
23
+ Timer {
24
+ interval: 1000 / Agents.motion.frameRate
25
+ repeat: true
26
+ running: effect.visible
27
+ onTriggered: effect.time = Date.now() / 1000
28
+ }
29
+
30
+ readonly property var frame: Agents.effectFrame(status, time)
31
+
32
+ PixelGrid {
33
+ color: effect.color
34
+ cell: effect.cell
35
+ pixels: effect.frame.pixels
36
+ x: effect.frame.x * effect.cell
37
+ y: effect.frame.y * effect.cell
38
+ opacity: effect.frame.opacity
39
+ }
40
+ }
@@ -0,0 +1,54 @@
1
+ import QtQuick
2
+ import "ticket.js" as Ticket
3
+
4
+ // A strip of receipt paper: the face of every ticket in the Ticket style,
5
+ // torn in a zigzag along the bottom and casting a soft shadow. Lay what it
6
+ // says on top of it; leave `tooth` pixels free at the bottom.
7
+ Item {
8
+ id: paper
9
+ property color color: Ticket.paper
10
+ property bool torn: true
11
+ property bool shadow: true
12
+ readonly property int tooth: 8
13
+
14
+ Canvas {
15
+ id: face
16
+ z: -1
17
+ readonly property int bleed: paper.shadow ? 18 : 0
18
+ x: -bleed
19
+ y: -bleed
20
+ width: paper.width + 2 * bleed
21
+ height: paper.height + 2 * bleed
22
+ onPaint: {
23
+ const ctx = getContext("2d");
24
+ ctx.reset();
25
+ const b = bleed, w = paper.width, h = paper.height, t = paper.tooth;
26
+ ctx.beginPath();
27
+ ctx.moveTo(b, b);
28
+ ctx.lineTo(b + w, b);
29
+ if (paper.torn) {
30
+ ctx.lineTo(b + w, b + h - t);
31
+ const teeth = Math.max(1, Math.round(w / 12));
32
+ const step = w / teeth;
33
+ for (let i = teeth; i > 0; i--) {
34
+ ctx.lineTo(b + (i - 0.5) * step, b + h);
35
+ ctx.lineTo(b + (i - 1) * step, b + h - t);
36
+ }
37
+ } else {
38
+ ctx.lineTo(b + w, b + h);
39
+ ctx.lineTo(b, b + h);
40
+ }
41
+ ctx.closePath();
42
+ if (paper.shadow) {
43
+ ctx.shadowColor = "rgba(0, 0, 0, 0.45)";
44
+ ctx.shadowBlur = 14;
45
+ ctx.shadowOffsetY = 6;
46
+ }
47
+ ctx.fillStyle = paper.color;
48
+ ctx.fill();
49
+ }
50
+ }
51
+ onWidthChanged: face.requestPaint()
52
+ onHeightChanged: face.requestPaint()
53
+ onColorChanged: face.requestPaint()
54
+ }
@@ -0,0 +1,40 @@
1
+ import QtQuick
2
+
3
+ // Draws rows of "X" and "." as square cells in one color.
4
+ Canvas {
5
+ id: grid
6
+ property var pixels: []
7
+ property color color: "white"
8
+ property real cell: 1
9
+
10
+ antialiasing: false
11
+
12
+ implicitWidth: (pixels.length > 0 ? pixels[0].length : 0) * cell
13
+ implicitHeight: pixels.length * cell
14
+ width: implicitWidth
15
+ height: implicitHeight
16
+
17
+ onPixelsChanged: requestPaint()
18
+ onColorChanged: requestPaint()
19
+ onCellChanged: requestPaint()
20
+
21
+ onPaint: {
22
+ const ctx = getContext("2d");
23
+ ctx.reset();
24
+ ctx.fillStyle = color;
25
+ // Each run of "X" is one rectangle on whole pixels, so a fractional
26
+ // cell leaves no seams between neighbors.
27
+ for (let y = 0; y < pixels.length; y++) {
28
+ const top = Math.round(y * cell);
29
+ const bottom = Math.round((y + 1) * cell);
30
+ let x = 0;
31
+ while (x < pixels[y].length) {
32
+ if (pixels[y][x] !== "X") { x++; continue; }
33
+ const start = x;
34
+ while (x < pixels[y].length && pixels[y][x] === "X") x++;
35
+ const left = Math.round(start * cell);
36
+ ctx.fillRect(left, top, Math.round(x * cell) - left, bottom - top);
37
+ }
38
+ }
39
+ }
40
+ }