|
| 1 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 2 | + |
| 3 | +import QtQuick |
| 4 | +import QtQuick.Layouts |
| 5 | +import ScratchCPP.Render |
| 6 | + |
| 7 | +// NOTE: All the values here make monitors look exactly |
| 8 | +// like on Scratch, so be careful when doing any changes. |
| 9 | +Rectangle { |
| 10 | + property ValueMonitorModel model: null |
| 11 | + |
| 12 | + color: model ? (model.mode === ValueMonitorModel.Large ? model.color : priv.bgColor) : priv.bgColor |
| 13 | + border.color: Qt.rgba(0.765, 0.8, 0.85, 1) |
| 14 | + radius: 5 |
| 15 | + width: layout.implicitWidth + priv.horizontalMargins * 2 |
| 16 | + height: layout.implicitHeight + priv.verticalMargins * 2 |
| 17 | + visible: model ? model.visible : true |
| 18 | + |
| 19 | + QtObject { |
| 20 | + id: priv |
| 21 | + readonly property int horizontalMargins: 9 |
| 22 | + readonly property double verticalMargins: 2.5 |
| 23 | + readonly property color bgColor: Qt.rgba(0.9, 0.94, 1, 1) |
| 24 | + } |
| 25 | + |
| 26 | + ColumnLayout { |
| 27 | + id: layout |
| 28 | + anchors.leftMargin: priv.horizontalMargins |
| 29 | + anchors.rightMargin: priv.horizontalMargins |
| 30 | + anchors.topMargin: priv.verticalMargins |
| 31 | + anchors.bottomMargin: priv.verticalMargins |
| 32 | + anchors.centerIn: parent |
| 33 | + spacing: 0 |
| 34 | + |
| 35 | + Loader { |
| 36 | + active: model ? model.mode !== ValueMonitorModel.Large : true |
| 37 | + sourceComponent: RowLayout { |
| 38 | + spacing: 9 |
| 39 | + |
| 40 | + Text { |
| 41 | + color: Qt.rgba(0.34, 0.37, 0.46, 1) |
| 42 | + text: model ? model.name : "" |
| 43 | + textFormat: Text.PlainText |
| 44 | + font.pointSize: 9 |
| 45 | + font.bold: true |
| 46 | + font.family: "Helvetica" |
| 47 | + } |
| 48 | + |
| 49 | + Text { |
| 50 | + id: valueText |
| 51 | + color: "white" |
| 52 | + text: model ? model.value : "" |
| 53 | + textFormat: Text.PlainText |
| 54 | + font.pointSize: 9 |
| 55 | + font.family: "Helvetica" |
| 56 | + leftPadding: 2 |
| 57 | + rightPadding: 2 |
| 58 | + topPadding: -2 |
| 59 | + bottomPadding: -1 |
| 60 | + horizontalAlignment: Qt.AlignHCenter |
| 61 | + Layout.minimumWidth: 40 |
| 62 | + |
| 63 | + Rectangle { |
| 64 | + color: model.color |
| 65 | + radius: 5 |
| 66 | + anchors.fill: parent |
| 67 | + anchors.margins: 0 |
| 68 | + z: -1 |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + Loader { |
| 75 | + active: model ? model.mode === ValueMonitorModel.Slider : false |
| 76 | + sourceComponent: MonitorSlider { |
| 77 | + from: model ? model.sliderMin : 0 |
| 78 | + to: model ? model.sliderMax : 0 |
| 79 | + discrete: model ? model.discrete : true |
| 80 | + value: model ? model.value : 0 |
| 81 | + Layout.fillWidth: true |
| 82 | + onMoved: { |
| 83 | + if(model) |
| 84 | + model.value = value; |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + Loader { |
| 90 | + active: model ? model.mode === ValueMonitorModel.Large : false |
| 91 | + sourceComponent: Text { |
| 92 | + color: "white" |
| 93 | + text: model ? model.value : "" |
| 94 | + textFormat: Text.PlainText |
| 95 | + font.pointSize: 12 |
| 96 | + font.family: "Helvetica" |
| 97 | + leftPadding: 2 |
| 98 | + rightPadding: 2 |
| 99 | + topPadding: -5 |
| 100 | + bottomPadding: 0 |
| 101 | + horizontalAlignment: Qt.AlignHCenter |
| 102 | + width: Math.max(31, implicitWidth) |
| 103 | + height: Math.max(14.46, implicitHeight) |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments