| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: MIT |
| 3 | |
| 4 | import { DemoPalette, Page, PushButton } from "./common.slint" ; |
| 5 | import { CopyPage } from "./copy_page.slint" ; |
| 6 | import { ScanPage } from "./scan_page.slint" ; |
| 7 | import { PrintPage } from "./print_page.slint" ; |
| 8 | import { PrinterQueueView } from "./printer_queue.slint" ; |
| 9 | import { UsbPage } from "./usb_page.slint" ; |
| 10 | |
| 11 | |
| 12 | |
| 13 | enum SubPage { None, Print, Scan, Copy, Usb } |
| 14 | |
| 15 | component ActionButton inherits Rectangle { |
| 16 | in property <image> icon <=> img.source; |
| 17 | in property <string> text <=> label.text; |
| 18 | width: DemoPalette.button-width; |
| 19 | height: DemoPalette.button-height; |
| 20 | |
| 21 | callback clicked; |
| 22 | |
| 23 | VerticalLayout { |
| 24 | spacing: 10px; |
| 25 | |
| 26 | Rectangle { |
| 27 | border-radius: 25px; |
| 28 | border-width: 5px; |
| 29 | border-color: DemoPalette.secondary; |
| 30 | background: DemoPalette.dark-mode ? DemoPalette.primary : DemoPalette.background; |
| 31 | width: DemoPalette.button-width; |
| 32 | height: self.width; |
| 33 | |
| 34 | img := Image { |
| 35 | colorize: DemoPalette.text-primary; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | label := Text { |
| 40 | font-size: DemoPalette.base-font-size * 1.375; |
| 41 | font-weight: 800; |
| 42 | horizontal-alignment: center; |
| 43 | color: DemoPalette.text-primary; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | TouchArea { clicked => { root.clicked() } } |
| 48 | } |
| 49 | |
| 50 | export component HomePage inherits Page { |
| 51 | in-out property <length> header-row-height: 40px; |
| 52 | in-out property <length> button-spacing: 35px; |
| 53 | in-out property <SubPage> current-subpage: SubPage.None; |
| 54 | |
| 55 | header: @tr("Slint Printer Demo" ); |
| 56 | |
| 57 | for action[idx] in [ |
| 58 | { name: @tr("Print" ), id: SubPage.Print, icon: @image-url("images/print.svg" ) }, |
| 59 | { name: @tr("Scan" ), id: SubPage.Scan, icon: @image-url("images/scan.svg" ) }, |
| 60 | { name: @tr("Copy" ), id: SubPage.Copy, icon: @image-url("images/copy.svg" ) }, |
| 61 | { name: @tr("USB" ), id: SubPage.Usb, icon: @image-url("images/usb.svg" ) }, |
| 62 | ]: ActionButton { |
| 63 | x: mod(idx, 2) * (DemoPalette.button-width + root.button-spacing); |
| 64 | y: floor(idx / 2) * (DemoPalette.button-height + root.button-spacing) |
| 65 | + /* header row height */ 46px |
| 66 | + /* top-padding of printer queue */ 27px; |
| 67 | icon: action.icon; |
| 68 | text: action.name; |
| 69 | |
| 70 | clicked => { root.current-subpage = action.id; } |
| 71 | } |
| 72 | |
| 73 | queue-view := PrinterQueueView { |
| 74 | show-job-details(idx) => { |
| 75 | root.current-subpage = SubPage.Print; |
| 76 | } |
| 77 | |
| 78 | x: parent.width - self.width; |
| 79 | width: 313px; |
| 80 | } |
| 81 | |
| 82 | PrintPage { |
| 83 | back => { root.current-subpage = SubPage.None; } |
| 84 | x: root.current-subpage == SubPage.Print ? 0 : parent.width + parent.x + 2px; |
| 85 | animate x { duration: 125ms; easing: ease; } |
| 86 | } |
| 87 | |
| 88 | ScanPage { |
| 89 | back => { root.current-subpage = SubPage.None; } |
| 90 | x: root.current-subpage == SubPage.Scan ? 0 : parent.width + parent.x + 2px; |
| 91 | animate x { duration: 125ms; easing: ease; } |
| 92 | } |
| 93 | |
| 94 | CopyPage { |
| 95 | back => { root.current-subpage = SubPage.None; } |
| 96 | x: root.current-subpage == SubPage.Copy ? 0 : parent.width + parent.x + 2px; |
| 97 | animate x { duration: 125ms; easing: ease; } |
| 98 | } |
| 99 | |
| 100 | UsbPage { |
| 101 | back => { root.current-subpage = SubPage.None; } |
| 102 | x: root.current-subpage == SubPage.Usb ? 0 : parent.width + parent.x + 2px; |
| 103 | animate x { duration: 125ms; easing: ease; } |
| 104 | } |
| 105 | } |
| 106 | |