|
| 1 | +import QtQuick |
| 2 | +import QtQuick.Controls |
| 3 | +import QtQuick.Layouts |
| 4 | +import MaterialIcons 2.2 |
| 5 | + |
| 6 | +import Utils 1.0 |
| 7 | + |
| 8 | +RowLayout { |
| 9 | + id: root |
| 10 | + |
| 11 | + property color defaultColor: Qt.darker(palette.text, 1.2) |
| 12 | + property string defaultIcon : MaterialIcons.circle |
| 13 | + property int interval : 5000 |
| 14 | + property bool logMessage : false |
| 15 | + |
| 16 | + TextField { |
| 17 | + id: statusBarField |
| 18 | + Layout.fillHeight: true |
| 19 | + readOnly: true |
| 20 | + selectByMouse: true |
| 21 | + text: statusBar.message |
| 22 | + color: defaultColor |
| 23 | + background: Item {} |
| 24 | + visible: statusBar.message !== "" |
| 25 | + } |
| 26 | + |
| 27 | + // TODO : Idea for later : implement a ProgressBar here |
| 28 | + |
| 29 | + MaterialToolButton { |
| 30 | + id: statusBarButton |
| 31 | + Layout.fillHeight: true |
| 32 | + Layout.preferredWidth: 17 |
| 33 | + visible: true |
| 34 | + font.pointSize: 8 |
| 35 | + text: defaultIcon |
| 36 | + ToolTip.text: "Open Messages UI" |
| 37 | + // TODO : Open messages UI |
| 38 | + // onClicked: statusBar.showMessage("NotImplementedError : Cannot open interface", "error", 2000) |
| 39 | + enabled: false // TODO: to remove when implemented |
| 40 | + ToolTip.visible: false // TODO: to remove when implemented |
| 41 | + Component.onCompleted: { |
| 42 | + statusBarButton.contentItem.color = defaultColor |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + Timer { |
| 47 | + id: statusBarTimer |
| 48 | + interval: root.interval |
| 49 | + running: false |
| 50 | + repeat: false |
| 51 | + onTriggered: { |
| 52 | + // Erase message and reset button icon |
| 53 | + statusBar.message = "" |
| 54 | + statusBarField.color = defaultColor |
| 55 | + statusBarButton.contentItem.color = defaultColor |
| 56 | + statusBarButton.text = defaultIcon |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + QtObject { |
| 61 | + id: statusBar |
| 62 | + property string message: "" |
| 63 | + |
| 64 | + function showMessage(msg, status=undefined, duration=root.interval) { |
| 65 | + var textColor = defaultColor |
| 66 | + var logLevel = "info" |
| 67 | + switch (status) { |
| 68 | + case "ok": { |
| 69 | + statusBarField.color = Colors.green |
| 70 | + statusBarButton.text = MaterialIcons.check_circle |
| 71 | + break |
| 72 | + } |
| 73 | + case "warning": { |
| 74 | + logLevel = "warn" |
| 75 | + statusBarField.color = Colors.orange |
| 76 | + statusBarButton.text = MaterialIcons.warning |
| 77 | + break |
| 78 | + } |
| 79 | + case "error": { |
| 80 | + logLevel = "error" |
| 81 | + statusBarField.color = Colors.red |
| 82 | + statusBarButton.text = MaterialIcons.error |
| 83 | + break |
| 84 | + } |
| 85 | + default: { |
| 86 | + statusBarButton.text = defaultIcon |
| 87 | + } |
| 88 | + } |
| 89 | + if (logMessage === true) { |
| 90 | + console.log("[Message][" + logLevel.toUpperCase().padEnd(5) + "] " + msg) |
| 91 | + } |
| 92 | + statusBarButton.contentItem.color = statusBarField.color |
| 93 | + statusBar.message = msg |
| 94 | + statusBarTimer.interval = duration |
| 95 | + statusBarTimer.restart() |
| 96 | + MeshroomApp.forceUIUpdate() |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + function showMessage(msg, status=undefined, duration=root.interval) { |
| 101 | + statusBar.showMessage(msg, status, duration) |
| 102 | + } |
| 103 | + |
| 104 | + Connections { |
| 105 | + target: _messageController |
| 106 | + function onMessage(message, color, duration) { |
| 107 | + showMessage(message, color, duration) |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments