feat(qt): custom-theme editor, artist portrait, playlist rail, About/What's New and diagnostics

Five surfaces the Qt frontend was missing, landed together because they share
five wiring files (build.rs, main.rs, shell_bridge.rs, AppShell.qml,
HeaderBar.qml) and splitting them would produce commits that do not build.

ARTIST PAGE
- The Playlists section used a hand-rolled Rectangle delegate: a MouseArea with
  no onClicked, and a RoundedImage with no fit:, so the default crop blew an
  800x380 playlist banner up inside a 200x200 box and showed the middle 47% at
  2.1x. Replaced by the real cards/PlaylistCard.qml — already live on five other
  surfaces — mounted in a new views/PlaylistRail.qml modelled on SectionRail.
  ArtistPlaylist publishes the five roles the card reads.
- The portrait gains what the album cover has: the right-click menu the Slint
  reference already has (Add/Change/Remove image, Open in browser, Save as…) and
  the lightbox this port invented for albums and playlists. Custom images are
  keyed by artist NAME into the same custom_artwork.json the Slint build writes,
  so they round-trip between the two.
- CoverLightbox is now aspect-aware. It forced a square box on the premise that
  covers are square; artist portraits are not (1080x720 measured in the cache).
- Removing an override invalidates the pipeline's resolved path for that url:
  artwork_qt::cached_path consults the override FIRST, so coverMap held the
  custom file and the header kept showing the picture the user had just deleted.
- artwork_qt::local_path is the inverse of file_url. trim_start_matches("file://")
  is not: it leaves the percent-escapes in place, so any path holding % # or ?
  came back as a name that does not exist on disk.
- One new msgid, "View image", in the seven non-en locales — matching its sibling
  "View cover", since en carries none of that family and falls back to the msgid.

CUSTOM THEME
- The editor, the colour picker and the swatch grid, ported 1:1 from
  AppearanceSettings.slint and ColorPicker.slint. The 11 editable base tokens,
  their expansion into the full 55-value palette and the on-disk format all stay
  in the shared qbz-theme crate, so a theme authored in the shipping Slint build
  already rendered here and now round-trips both ways.
- Hue is normalised 0..1 at every Qt.hsva boundary; the reference stores 0..360,
  and porting the number instead of the domain would render every swatch red.
- The first-selection seed is captured BEFORE set_theme persists the slug,
  because current_slug() re-reads it from disk — a seed taken afterwards would
  resolve "custom", find no file and snapshot the default it was meant to replace.
- The in-memory base is dropped when the theme row enters "custom": it is
  memoized for the life of the process and filled at bridge construction, so a
  process that booted without the file would keep serving the OLED default even
  after the shipping Slint build wrote the user's theme.
- The disk write is debounced to drag-end and atomic; the reference persists on
  every drag frame with a truncating write, on a file the other build has open.

ABOUT + WHAT'S NEW
- Both modals, with their producers. render_markdown is transcribed line for line
  from the reference: h1 and h2 collapse to one level, an indent-0 bullet becomes
  a section plus a TOC entry, bold and backticks are stripped rather than styled.
  Text.MarkdownText is a different subset and would have rendered a different
  document from the same source. Pinned by tests, including the real 2.0.2 body.
- The codename is a single const, so the release checklist has one Qt-side place
  to bump.

DIAGNOSTICS
- The panel in Settings > Developer, the Report an Issue modal and its menu row.
- The log bundle carried eight hand-built header fields where the reference
  carries about seventy, so every issue filed from a Qt build arrived with no
  kernel, no distro, no install method, no GPU, no exclusive-mode / DAC /
  sample-rate state and no playback context. The report is injected INTO
  qbz_log::bundle rather than replacing it, keeping the <details> wrapper that
  makes a pasted bundle readable.
- The GTK / WebKit / GSK / GDK rows are CUT. In a Qt process those libraries are
  not mapped, so their runtime column can only read "—", and their saved column
  would come from a graphics.json this binary never reads or writes — foreign
  state presented as this app's configuration.

SHELL
- The four always-on-top overlays (toast, tooltip, art preview, immersive) relied
  on declaration order and carried no z, so any z-bearing modal buried them: a
  toast raised by a background event behind an opaque panel is never seen. They
  now sit in a band above the modals, keeping their relative order.
- build.rs asked cargo to watch ../../.git/HEAD, which does not exist in a git
  worktree (.git is a file). Cargo treats a missing rerun-if-changed target as
  always-dirty, so the whole build script — per-shader qsb, the recursive asset
  sweep, cxx-qt/moc codegen — re-ran on every cargo invocation.

Verified: cargo test -p qbz-qt 343 passed, cargo test -p qbz-library 83 passed,
qml_singleton_xref and qml_resolution_audit clean over 35 bridges and 265 QML
files, and qmlcachegen compiles every one of them. Smoke-tested by hand.

Contracts, recon and adversarial reviews:
qbz-nix-docs/qt-frontend/2026-08-14-six-item-round/

cc
This commit is contained in:
vicrodh committed 2026-08-15 00:52:25 -06:00
1 parent 4bfd8b30e2
commit 8bd02e35d3
46 files changed
+6365 -148

No files matched your search

@@ -0,0 +1,271 @@
// QbzColorPicker — the QML port of primitives/ColorPicker.slint: an inline,
// expandable HSV colour picker (SV square + hue strip + preview + editable
// HEX field). Used by the custom-theme editor; one instance is mounted at a
// time, behind the open swatch.
//
// Design decisions carried over from the reference, and one that is NOT:
//
// - INLINE, never a Popup. The parent mounts exactly one picker at a time,
// so there is no z-order or positioning fight (ColorPicker.slint:4-6).
// - The picker OWNS its hue/sat/val state, seeded from `value` on mount and
// on EXTERNAL change only. A fully derived model would lose the hue at
// s == 0 or v == 0 (ColorPicker.slint:7-9). Two guards keep it: `dragging`
// skips mid-drag feedback, and a hex compare skips the parent's own
// round-tripped colour.
// - NO Timer / NumberAnimation / Behavior. The reference has none, and the
// shell's repaint-pulse rule forbids adding any: the picker repaints on
// user input and costs nothing at rest. (The reference's stated reason is
// a Slint compiler panic on Timer-in-`if`; ours is the pulse contract.
// Same conclusion, different rationale — do not "restore" an animation.)
//
// HUE DOMAIN. The Slint stores hue in 0..360 (`Colors.hsv`). `Qt.hsva()` takes
// ALL FOUR arguments in 0..1, so `hue` here is NORMALISED 0..1 and every
// boundary — the SV base colour, the strip marker position, the pointer maths
// — works in that domain. Feeding 217 into Qt.hsva clamps to 1.0 and paints
// every swatch red.
//
// ENCODING. `picked(hex)` and the HEX field speak 6-digit `#rrggbb` — the
// EDIT/PERSIST encoding of the custom-theme base tokens (qbz_theme
// Rgba::to_hex). `value` comes in as a `color`, so it accepts the
// `#aarrggbb` render encoding the bridge publishes; the alpha is ignored,
// base tokens being opaque by contract.
import QtQuick
import com.blitzfc.qbz
import "../theme"
Rectangle {
id: root
/// The current value, driven by the parent. Read on mount + external change.
property color value: "#ff4285f4"
/// Emitted live (drag included) with a 6-digit `#rrggbb` string. Named
/// `picked`, not the reference's `changed`: in QML `changed` collides
/// visually with the auto-generated `<property>Changed` handlers and reads
/// as one at every call site. Same semantics.
signal picked(string hex)
/// Emitted when a colour drag ENDS — the owner persists here, so a settled
/// drag does not wait out the write debounce.
signal released()
/// Emitted when the HEX field is committed (the parent parses + feeds back).
signal hexCommitted(string hex)
QbzTheme { id: theme }
// --- owned HSV state -------------------------------------------------
property real hue: 0.6028 // 0..1 (Qt.hsva domain — see the header)
property real sat: 0.74 // 0..1
property real val: 0.96 // 0..1
// True only while an SV/hue drag is in flight, so the round-tripped colour
// the parent feeds back does not fight the crosshair mid-drag.
property bool dragging: false
readonly property color current: Qt.hsva(root.hue, root.sat, root.val, 1)
readonly property string currentHex: _hex(root.current)
/// A QML `color` to 6-digit `#rrggbb`. `.r/.g/.b` are 0..1 floats that came
/// from 8-bit channels, so this round-trips exactly.
function _hex(c) {
function b(x) {
var v = Math.max(0, Math.min(255, Math.round(x * 255)))
return (v < 16 ? "0" : "") + v.toString(16)
}
return "#" + b(c.r) + b(c.g) + b(c.b)
}
/// Seed the owned HSV from `value` (mount + external change). Mirrors
/// ColorPicker.slint:51-69, with hue normalised to 0..1.
function decompose() {
var r = root.value.r, g = root.value.g, b = root.value.b
var mx = Math.max(r, Math.max(g, b))
var mn = Math.min(r, Math.min(g, b))
var d = mx - mn
root.val = mx
root.sat = mx <= 0 ? 0 : d / mx
if (d <= 0)
root.hue = 0 // gray: hue undefined -> 0
else if (mx === r)
root.hue = ((((g - b) / d) % 6) + 6) % 6 / 6 // JS % keeps the sign
else if (mx === g)
root.hue = (((b - r) / d) + 2) / 6
else
root.hue = (((r - g) / d) + 4) / 6
}
Component.onCompleted: root.decompose()
// Reseed on EXTERNAL changes only. The comparison is on the 8-bit HEX and
// not on the colours themselves: `value` is our own emitted hex parsed
// back, so it is byte-quantised, while `current` is float HSV output —
// comparing those directly would report a difference for every edit and
// re-decompose (resetting the hue whenever s or v hits 0), which is the
// exact failure ColorPicker.slint:74-79 documents.
onValueChanged: {
if (!root.dragging && root._hex(root.value) !== root.currentHex)
root.decompose()
}
// --- layout ----------------------------------------------------------
color: theme.surfaceCard
radius: theme.radiusSm
border.width: 1
border.color: theme.borderSubtle
implicitHeight: col.implicitHeight + 24
height: implicitHeight
Column {
id: col
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 12
spacing: 10
// Saturation / Value square.
Rectangle {
id: sv
width: parent.width
height: 140
radius: theme.radiusSm
clip: true
// Base: the pure hue.
color: Qt.hsva(root.hue, 1, 1, 1)
// Both overlays carry the parent's radius: Qt's `clip` scissors to
// the bounding RECT, unlike Slint's, which honours border-radius —
// so a square-cornered child paints over the rounded corners the
// reference renders (ColorPicker.slint:118-124).
//
// White -> transparent (left to right) = saturation.
Rectangle {
anchors.fill: parent
radius: sv.radius
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 0.0; color: "#ffffffff" }
GradientStop { position: 1.0; color: "#00ffffff" }
}
}
// Transparent -> black (top to bottom) = value.
Rectangle {
anchors.fill: parent
radius: sv.radius
gradient: Gradient {
GradientStop { position: 0.0; color: "#00000000" }
GradientStop { position: 1.0; color: "#ff000000" }
}
}
// Crosshair: x = saturation, y = (1 - value).
Rectangle {
width: 14
height: 14
radius: 7
x: Math.max(0, Math.min(sv.width - width, root.sat * sv.width))
y: Math.max(0, Math.min(sv.height - height, (1 - root.val) * sv.height))
color: "transparent"
border.width: 2
border.color: "#ffffffff"
Rectangle {
x: 2
y: 2
width: parent.width - 4
height: parent.height - 4
radius: width / 2
color: "transparent"
border.width: 1
border.color: "#80000000"
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.CrossCursor
onPressed: function (m) { root.dragging = true; root._pickSv(m.x, m.y) }
onPositionChanged: function (m) { if (root.dragging) root._pickSv(m.x, m.y) }
onReleased: { root.dragging = false; root.released() }
onCanceled: { root.dragging = false; root.released() }
}
}
// Hue strip.
Rectangle {
id: hueStrip
width: parent.width
height: 14
radius: 7
clip: true
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 0.0000; color: "#ffff0000" }
GradientStop { position: 0.1666; color: "#ffffff00" }
GradientStop { position: 0.3333; color: "#ff00ff00" }
GradientStop { position: 0.5000; color: "#ff00ffff" }
GradientStop { position: 0.6666; color: "#ff0000ff" }
GradientStop { position: 0.8333; color: "#ffff00ff" }
GradientStop { position: 1.0000; color: "#ffff0000" }
}
// Marker.
Rectangle {
width: 4
height: parent.height + 4
y: -2
x: Math.max(0, Math.min(hueStrip.width - width, root.hue * hueStrip.width))
radius: 2
color: "#ffffffff"
border.width: 1
border.color: "#80000000"
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onPressed: function (m) { root.dragging = true; root._pickHue(m.x) }
onPositionChanged: function (m) { if (root.dragging) root._pickHue(m.x) }
onReleased: { root.dragging = false; root.released() }
onCanceled: { root.dragging = false; root.released() }
}
}
// Preview swatch + editable HEX field.
Row {
width: parent.width
spacing: 10
Rectangle {
width: 40
height: 34
radius: theme.radiusSm
border.width: 1
border.color: theme.borderSubtle
color: root.current
}
QbzLineEdit {
// The plain arm is a fixed 240 wide; the picker spans the
// settings column, so the field takes what the swatch leaves.
width: Math.max(120, parent.width - 50)
anchors.verticalCenter: parent.verticalCenter
text: root.currentHex
placeholder: "#rrggbb"
// Enter commits. No hotkey-guard wiring is needed: the shell
// derives "a text input has focus" structurally from the
// active focus item (AppShell.qml, the `afi instanceof
// TextInput` gate inside Keys.onPressed), so the Slint
// UiFocusState dance (ColorPicker.slint:229-234, a workaround
// for #619) has no counterpart here.
onAccepted: function (v) { root.hexCommitted(v) }
// Commit only well-formed #rrggbb (7 chars); a shorter string
// is an in-progress edit and is ignored until it is valid.
onEdited: function (v) { if (v.length === 7) root.hexCommitted(v) }
}
}
}
// Both pointer handlers build the hex from the values they just assigned
// rather than reading `currentHex`, so the emission cannot depend on
// binding evaluation order.
function _pickSv(mx, my) {
root.sat = Math.max(0, Math.min(1, mx / sv.width))
root.val = Math.max(0, Math.min(1, 1 - my / sv.height))
root.picked(root._hex(Qt.hsva(root.hue, root.sat, root.val, 1)))
}
function _pickHue(mx) {
root.hue = Math.max(0, Math.min(1, mx / hueStrip.width))
root.picked(root._hex(Qt.hsva(root.hue, root.sat, root.val, 1)))
}
}