1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: MIT |
3 | |
4 | #include "printerdemo.h" |
5 | #include <iostream> |
6 | |
7 | struct InkLevelModel : slint::Model<InkLevel> |
8 | { |
9 | size_t row_count() const override { return m_data.size(); } |
10 | std::optional<InkLevel> row_data(size_t i) const override |
11 | { |
12 | if (i < row_count()) |
13 | return { m_data[i] }; |
14 | return {}; |
15 | } |
16 | |
17 | std::vector<InkLevel> m_data = { { slint::Color::from_rgb_uint8(255, 255, 0), 0.9 }, |
18 | { slint::Color::from_rgb_uint8(0, 255, 255), 0.5 }, |
19 | { slint::Color::from_rgb_uint8(255, 0, 255), 0.8 }, |
20 | { slint::Color::from_rgb_uint8(0, 0, 0), 0.1 } }; |
21 | }; |
22 | |
23 | int main() |
24 | { |
25 | auto printer_demo = MainWindow::create(); |
26 | printer_demo->set_ink_levels(std::make_shared<InkLevelModel>()); |
27 | printer_demo->on_quit([] { std::exit(status: 0); }); |
28 | |
29 | printer_demo->on_fax_number_erase([printer_demo = slint::ComponentWeakHandle(printer_demo)] { |
30 | std::string fax_number { (*printer_demo.lock())->get_fax_number() }; |
31 | fax_number.pop_back(); |
32 | (*printer_demo.lock())->set_fax_number(fax_number.data()); |
33 | }); |
34 | |
35 | printer_demo->on_fax_send([printer_demo = slint::ComponentWeakHandle(printer_demo)] { |
36 | std::cout << "Sending a fax to " << (*printer_demo.lock())->get_fax_number() << std::endl; |
37 | (*printer_demo.lock())->set_fax_number({}); |
38 | }); |
39 | |
40 | printer_demo->run(); |
41 | } |
42 | |