Files
qbz/crates/qbz-slint/ui/album/AlbumBookletModal.slint
T
vicrodh 74880009f6 feat(slint): AlbumView polish — booklet reader, carousels, external links
- Booklet: new frontend-agnostic qbz-booklet crate (MuPDF render to PNG;
  the Tauri Cargo stanza + device_rgb/alpha=false render workaround ported
  verbatim). In-app reader modal (paginate/zoom/rotate/download) driven by
  BookletState/BookletActions; header booklet button now opens it.
- "From the same artist" carousel (/artist/getReleasesGrid) and "Listening
  suggestions" carousel (/album/suggest), reusing the Discover Carousel,
  appended below the track list with their own artwork pipeline targets.
- External Links sidebar block (Last.fm / Discogs / MusicBrainz) built from
  artist + title, opening in the system browser.

cc
2026-06-22 01:27:12 -06:00

310 lines
13 KiB
Plaintext

// Album Booklet modal — in-app PDF reader for the digital booklet that
// ships with some Qobuz albums. Opened from the AlbumPageView header
// (book-open) button via media-action("album", id, "booklet"); the Rust
// controller (crate qbz-booklet) downloads the PDF, renders the current
// page to a PNG, and feeds BookletState. Mirrors AlbumCreditsModal's
// scrim + centered card pattern (ADR-009/010). The page area is a
// Flickable sized to the rendered pixel dimensions: centered when the
// page is smaller than the viewport, scrolling when larger.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { BookletState, BookletActions } from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
// One toolbar button — a small square with a centered icon, hover fill,
// disable support (dims + gates the click).
component ToolbarButton inherits Rectangle {
in property <image> icon;
in property <bool> enabled: true;
callback clicked();
width: 32px;
height: 32px;
border-radius: Radius.sm;
opacity: root.enabled ? 1.0 : 0.4;
background: (ta.has-hover && root.enabled) ? Theme.surface-hover : transparent;
QbzIcon {
source: root.icon;
width: 16px;
height: 16px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: ta.has-hover && root.enabled ? Theme.text-primary : Theme.text-secondary;
}
ta := TouchArea {
mouse-cursor: root.enabled ? pointer : default;
clicked => {
if (root.enabled) {
root.clicked();
}
}
}
}
export component AlbumBookletModal inherits Rectangle {
visible: BookletState.open;
if BookletState.open: Rectangle {
background: #000000bf;
// Scrim — a click outside the card dismisses.
TouchArea {
mouse-cursor: default;
clicked => {
BookletActions.close();
}
}
Rectangle {
width: Math.min(root.width - 40px, 980px);
height: root.height - 80px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.md;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: Theme.card-shadow;
clip: true;
// Swallow clicks so they don't reach the scrim.
TouchArea { }
fs := FocusScope {
Timer {
interval: 30ms;
running: true;
triggered => {
self.running = false;
fs.focus();
}
}
key-pressed(event) => {
if (event.text == Key.Escape) {
BookletActions.close();
return accept;
}
return reject;
}
VerticalLayout {
spacing: 0px;
// ---- Header: title + close ----------------------------
HorizontalLayout {
padding-left: 24px;
padding-right: 24px;
padding-top: 16px;
padding-bottom: 16px;
spacing: 16px;
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
Text {
text: BookletState.title;
color: Theme.text-primary;
font-size: 16px;
font-weight: Typography.semibold;
overflow: elide;
}
}
close-x := TouchArea {
width: 32px;
height: 32px;
mouse-cursor: pointer;
clicked => {
BookletActions.close();
}
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 18px;
height: 18px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
}
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
// ---- Toolbar: paging, zoom, fit, rotate, download -----
HorizontalLayout {
padding-left: 24px;
padding-right: 24px;
padding-top: 10px;
padding-bottom: 10px;
spacing: 6px;
alignment: start;
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/chevron-left.svg");
enabled: BookletState.current-page > 1;
clicked => {
BookletActions.prev-page();
}
}
}
VerticalLayout {
alignment: center;
Text {
text: BookletState.current-page + " / " + BookletState.num-pages;
color: Theme.text-secondary;
font-size: 13px;
vertical-alignment: center;
horizontal-alignment: center;
min-width: 64px;
}
}
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/chevron-right.svg");
enabled: BookletState.current-page < BookletState.num-pages;
clicked => {
BookletActions.next-page();
}
}
}
// Spacer between paging and zoom controls.
Rectangle { width: 16px; }
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/minus.svg");
clicked => {
BookletActions.zoom-out();
}
}
}
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/plus.svg");
clicked => {
BookletActions.zoom-in();
}
}
}
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/maximize-2.svg");
clicked => {
BookletActions.fit-width();
}
}
}
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/rotate-ccw.svg");
clicked => {
BookletActions.rotate();
}
}
}
Rectangle { horizontal-stretch: 1; }
VerticalLayout {
alignment: center;
ToolbarButton {
icon: @image-url("../assets/icons/cloud-download.svg");
clicked => {
BookletActions.download();
}
}
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
// ---- Page area ----------------------------------------
// A neutral viewport holding a Flickable sized to the
// rendered page pixels. When the page is smaller than the
// viewport it centers; when larger, the Flickable scrolls.
Rectangle {
vertical-stretch: 1;
background: Theme.surface-main;
clip: true;
page-flick := Flickable {
viewport-width: Math.max(self.width, BookletState.page-pixel-width * 1px);
viewport-height: Math.max(self.height, BookletState.page-pixel-height * 1px);
Image {
source: BookletState.page-image;
width: BookletState.page-pixel-width * 1px;
height: BookletState.page-pixel-height * 1px;
x: Math.max(0px, (parent.width - self.width) / 2);
y: Math.max(0px, (parent.height - self.height) / 2);
}
}
// Loading overlay — spinner + label while the PDF
// downloads or a page renders.
if BookletState.loading: Rectangle {
background: Theme.surface-main;
TouchArea { }
VerticalLayout {
alignment: center;
spacing: 14px;
HorizontalLayout {
alignment: center;
LoadingSpinner { size: 36px; }
}
Text {
text: @tr("Loading…");
color: Theme.text-muted;
font-size: Typography.body;
horizontal-alignment: center;
}
}
}
// Error overlay.
if BookletState.error: Rectangle {
background: Theme.surface-main;
TouchArea { }
VerticalLayout {
alignment: center;
spacing: 8px;
Text {
text: @tr("Failed to load booklet");
color: Theme.text-muted;
font-size: Typography.body;
horizontal-alignment: center;
}
if BookletState.error-text != "": Text {
text: BookletState.error-text;
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-alignment: center;
wrap: word-wrap;
}
}
}
}
}
}
}
}
}