-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogWindow.qml
144 lines (125 loc) · 4.24 KB
/
LogWindow.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import QtQuick 2.13
import QtQuick.Window 2.3
import QtQuick.Controls 2.13
import BackEnd 1.0
import LogListModel 0.1
ApplicationWindow {
property int logMargin: 8
id: logWindow
title: qsTr("Log")
width: 455
height: 645
header: ToolBar {
id: logToolbar
contentHeight: toolButton.implicitHeight
ToolButton {
id: toolButton
text: "\u25C0"
onClicked: {
logWindow.close()
}
}
Label {
id: logHdrLabel
text: qsTr("Log")
anchors.centerIn: parent
font.capitalization: Font.AllUppercase
}
ToolButton {
id: statusButton
icon.source: "images/worldwide.svg"
icon.height: 20
icon.width: 20
icon.color: {
return uiState === BackEnd.Offline
? 'red'
: (uiState === BackEnd.Online
? '#ededed'
: (uiState === BackEnd.Connecting ? 'gray' : 'yellow'))
}
display: AbstractButton.IconOnly
anchors.left: logHdrLabel.right
ToolTip {
visible: parent.hovered
text: {
return qsTr(uiState === BackEnd.Offline
? "Log Not Connected\nData Not Connected"
: (uiState === BackEnd.Connecting
? 'Connecting'
: (uiState === BackEnd.NoLog
? 'Log Not Connected'
: (uiState === BackEnd.NoData ? 'Data Not Connected' : 'Connected')))) +
(uiState !== BackEnd.Online && uiState !== BackEnd.Connecting ? "\nClick to retry connection" : '')
}
}
onClicked: {
if (uiState !== BackEnd.Online && uiState !== BackEnd.Connecting) {
doReconnect();
}
}
}
}
ListView {
id: serialLog
anchors.fill: parent
// for top/bottom margin
header: Item {
height: logMargin
}
footer: Item {
height: logMargin
}
// allow scroll in both directions, display scrollbars
flickableDirection: Flickable.AutoFlickIfNeeded
ScrollBar.vertical: ScrollBar { }
ScrollBar.horizontal: ScrollBar { }
model: LogListModel {
id: serialLogModel
}
delegate: Text {
text: model.display
leftPadding: logMargin
rightPadding: logMargin
Component.onCompleted: {
serialLog.contentWidth = Math.max(serialLog.contentWidth, contentWidth + leftPadding + rightPadding)
}
}
Connections {
target: backEnd
onLogAppend: function(str) {
serialLogModel.add(str);
serialLog.positionViewAtIndex(serialLogModel.rowCount() - 1, ListView.End);
}
onHidConnectStatus: function(connecting, dataOnline, logOnline) {
if (!connecting && !dataOnline) {
serialLogModel.add('Data connection failed');
}
if (!connecting && !logOnline) {
serialLogModel.add('Log connection failed');
}
serialLog.positionViewAtIndex(serialLogModel.rowCount() - 1, ListView.End);
}
}
}
Rectangle {
visible: uiState === BackEnd.Connecting || uiState === BackEnd.Offline || uiState === BackEnd.NoLog
height: 25
width: 155
anchors.right: parent.right
anchors.top: logToolbar.bottom
color: "transparent"
Label {
text: qsTr("\u26a0 Not Connected")
color: "#333333"
anchors.centerIn: parent
font.capitalization: Font.AllUppercase
}
}
// Darken screen when log is Not Connected
Rectangle {
anchors.fill: parent
opacity: 0.35
color: 'gray'
visible: uiState !== BackEnd.Online && uiState !== BackEnd.NoData
}
}