|
6 | 6 | import QtQuick |
7 | 7 | import Victron.VenusOS |
8 | 8 |
|
9 | | -Column { |
| 9 | +/* |
| 10 | + A widget in the Brief side panel. |
| 11 | +
|
| 12 | + In landscape orientation, the layout is: |
| 13 | +
|
| 14 | + | Icon & Title | |
| 15 | + | Quantity label | Graph | |
| 16 | + | Footer | |
| 17 | +
|
| 18 | + In portrait orientation, the layout is: |
| 19 | +
|
| 20 | + | Icon & Title | Graph | Quantity label | |
| 21 | + | Footer | |
| 22 | +*/ |
| 23 | +Rectangle { |
10 | 24 | id: root |
11 | 25 |
|
12 | | - property alias title: header.title |
| 26 | + required property string title |
13 | 27 | property alias icon: header.icon |
14 | 28 | property alias quantityLabel: quantityLabel |
15 | | - property alias sideComponent: sideLoader.sourceComponent |
16 | | - property alias bottomComponent: bottomLoader.sourceComponent |
| 29 | + property alias graph: graphLoader.sourceComponent |
| 30 | + property alias footer: footerLoader.sourceComponent |
17 | 31 | property bool loadersActive |
18 | 32 |
|
19 | | - width: parent.width |
20 | | - bottomPadding: Theme.geometry_sidePanel_verticalMargin |
| 33 | + // True if the graph should be stretched to fill as much space as possible. |
| 34 | + property bool stretchGraph: true |
21 | 35 |
|
22 | | - WidgetHeader { |
23 | | - id: header |
24 | | - z: 1 // place the title above the side component if it overflows |
25 | | - } |
| 36 | + implicitWidth: parent?.width ?? Theme.geometry_briefPage_sidePanel_width |
| 37 | + implicitHeight: contentItem.height + (2 * Theme.geometry_sidePanel_sideWidget_verticalMargin) |
26 | 38 |
|
27 | | - Row { |
28 | | - width: parent.width |
29 | | - height: quantityLabel.height |
| 39 | + // In portrait layout, show a background and shrink the content area to fit within that |
| 40 | + // background, with some margin between the content and the background. |
| 41 | + color: Theme.screenSize === Theme.Portrait ? Theme.color_background_secondary : "transparent" |
| 42 | + radius: Theme.geometry_button_radius |
| 43 | + |
| 44 | + Item { |
| 45 | + id: contentItem |
| 46 | + |
| 47 | + anchors.centerIn: parent |
| 48 | + width: parent.width - (2 * Theme.geometry_sidePanel_sideWidget_horizontalMargin) |
| 49 | + implicitHeight: footerLoader.y + footerLoader.height |
| 50 | + |
| 51 | + WidgetHeader { |
| 52 | + id: header |
| 53 | + |
| 54 | + anchors.left: parent.left |
| 55 | + width: Theme.screenSize === Theme.Portrait |
| 56 | + ? root.stretchGraph |
| 57 | + ? implicitWidth |
| 58 | + : Math.min(implicitWidth, parent.width - quantityLabel.width - graphLoader.width - Theme.geometry_sidePanel_sideWidget_spacing) |
| 59 | + : parent.width |
| 60 | + height: Theme.screenSize === Theme.Portrait ? quantityLabel.height : implicitHeight |
| 61 | + rightPadding: Theme.screenSize === Theme.Portrait ? Theme.geometry_sidePanel_sideWidget_spacing : 0 |
| 62 | + text: root.title |
| 63 | + } |
30 | 64 |
|
31 | 65 | ElectricalQuantityLabel { |
32 | 66 | id: quantityLabel |
| 67 | + |
| 68 | + anchors { |
| 69 | + top: Theme.screenSize === Theme.Portrait ? undefined : header.bottom |
| 70 | + left: Theme.screenSize === Theme.Portrait ? undefined : parent.left |
| 71 | + right: Theme.screenSize === Theme.Portrait ? parent.right : undefined |
| 72 | + } |
| 73 | + rightPadding: Theme.screenSize === Theme.Portrait ? 0 : Theme.geometry_sidePanel_sideWidget_spacing |
33 | 74 | font.pixelSize: Theme.font_briefPage_sidePanel_quantityLabel_size |
34 | | - width: parent.width - sideLoader.width |
35 | | - alignment: Qt.AlignLeft |
| 75 | + alignment: Theme.screenSize === Theme.Portrait ? Qt.AlignRight : Qt.AlignLeft |
36 | 76 | } |
37 | 77 |
|
38 | 78 | Loader { |
39 | | - id: sideLoader |
| 79 | + id: graphLoader |
| 80 | + |
40 | 81 | anchors { |
41 | | - top: parent.top |
42 | | - bottom: parent.bottom |
43 | | - bottomMargin: Theme.geometry_sidePanel_sideWidget_bottomMargin |
| 82 | + left: root.stretchGraph ? (Theme.screenSize === Theme.Portrait ? header.right : quantityLabel.right) : undefined |
| 83 | + top: Theme.screenSize === Theme.Portrait ? quantityLabel.top : header.bottom |
| 84 | + bottom: Theme.screenSize === Theme.Portrait ? quantityLabel.bottom : footerLoader.top |
| 85 | + bottomMargin: Theme.screenSize === Theme.Portrait ? 0 : Theme.geometry_sidePanel_sideWidget_bottomMargin |
| 86 | + right: Theme.screenSize === Theme.Portrait ? quantityLabel.left : parent.right |
| 87 | + rightMargin: Theme.screenSize === Theme.Portrait ? Theme.geometry_sidePanel_sideWidget_spacing : 0 |
44 | 88 | } |
45 | | - width: Theme.geometry_sidePanel_sideWidget_width |
46 | 89 | active: root.loadersActive |
| 90 | + sourceComponent: root.graph |
47 | 91 | } |
48 | | - } |
49 | 92 |
|
50 | | - Item { |
51 | | - width: 1 |
52 | | - height: bottomLoader.status === Loader.Ready ? Theme.geometry_sidePanel_quantityLabel_bottomMargin : 0 |
53 | | - } |
54 | | - |
55 | | - Loader { |
56 | | - id: bottomLoader |
57 | | - width: parent.width |
58 | | - active: root.loadersActive |
| 93 | + Loader { |
| 94 | + id: footerLoader |
| 95 | + anchors { |
| 96 | + top: quantityLabel.bottom |
| 97 | + topMargin: status === Loader.Null ? 0 : Theme.geometry_sidePanel_quantityLabel_bottomMargin |
| 98 | + } |
| 99 | + width: parent.width |
| 100 | + active: root.loadersActive |
| 101 | + } |
59 | 102 | } |
60 | 103 | } |
0 commit comments