Fix scrolling and tweak layout

This commit is contained in:
Matti Viljanen 2022-08-10 21:34:10 +03:00
parent 615998d5a2
commit 143d9b376a
No known key found for this signature in database
GPG key ID: CF32A1495158F888

View file

@ -24,26 +24,38 @@ Page {
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
Label {
id: labelMetrics
text: "X"
font.pixelSize: Theme.fontSizeTiny
opacity: 0
enabled: false
}
SilicaFlickable { SilicaFlickable {
id: logFlickable id: logFlickable
anchors.fill: parent anchors.fill: parent
contentHeight: header.height + column.height contentHeight: header.height
+ flow.height
+ Theme.paddingLarge
+ logView.height
ScrollDecorator {
flickable: logFlickable
}
PageHeader { PageHeader {
id: header id: header
title: qsTr("View log") title: qsTr("View log")
} }
Column { Flow {
id: column id: flow
anchors { anchors.top: header.bottom
top: header.bottom width: parent.width
horizontalCenter: parent.horizontalCenter
}
width: parent.width - 2*Theme.horizontalPageMargin
spacing: Theme.paddingLarge
ComboBox { ComboBox {
width: page.isPortrait ? page.width : page.width / 2
label: qsTr("Log level") label: qsTr("Log level")
currentIndex: 0 currentIndex: 0
menu: ContextMenu { menu: ContextMenu {
@ -56,10 +68,7 @@ Page {
} }
Row { Row {
anchors { width: page.isPortrait ? page.width : page.width / 2
left: parent.left
right: parent.right
}
height: updateButton.height height: updateButton.height
Column { Column {
@ -68,7 +77,7 @@ Page {
id: updateButton id: updateButton
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Update") text: qsTr("Update")
onClicked: logLabel.updateText() onClicked: logView.updateText()
} }
} }
Column { Column {
@ -77,72 +86,61 @@ Page {
id: daemonStopButton id: daemonStopButton
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Copy") text: qsTr("Copy")
onClicked: Clipboard.text = logLabel.text onClicked: Clipboard.text = logView.text
} }
} }
} }
}
/* ColumnView {
MyLabel { id: logView
id: logLabel anchors {
text: logger.readLogfile(settings.logFilename) top: flow.bottom
font.pixelSize: Theme.fontSizeTiny topMargin: Theme.paddingLarge
function updateText() { left: parent.left
logLabel.text = logger.readLogfile(settings.logFilename) right: parent.right
} leftMargin: Theme.horizontalPageMargin
} }
*/ itemHeight: labelMetrics.height
ColumnView { id: logLabel
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - Theme.horizontalPageMargin
itemHeight: Math.floor(Theme.itemSizeExtraSmall / 3) // determined by debug output
clip: true clip: true
model: ListModel {} model: ListModel {}
delegate: Component { Label { delegate: Component {
// print height to adjust logLabel.itemHeight Label {
// on my test system, height is 41, itemSizeExtraSmall is 122 ( 122/3=40, good enough ) clip: true
// Component.onCompleted: console.debug("real height:", height, "item height:", logLabel.itemHeight, "theme height:", Theme.itemSizeExtraSmall, "font height:", font.pixelSize) text: line
clip: true width: logView.width
text: line wrapMode: TextEdit.NoWrap
width: ListView.view.width truncationMode: TruncationMode.Fade
wrapMode: TextEdit.NoWrap font.bold: true
truncationMode: TruncationMode.Fade font.pixelSize: Theme.fontSizeTiny
font.bold:(/%$/.test(text)) // bold if it's a percentage color: {
font.pixelSize: Theme.fontSizeTiny switch (text.split(" ")[1]) {
color: {
if (/%$/.test(text)) return Theme.primaryColor
// TODO: use a more sophisticated matching method:
// [HH:MM:HH] Word: value value
const token = text.split(" ")[1]
switch (token) {
case "Charger:": case "Charger:":
return Theme.highlightFromColor("green", Theme.colorScheme)
break;
case "State:":
return Theme.highlightFromColor("yellow", Theme.colorScheme) return Theme.highlightFromColor("yellow", Theme.colorScheme)
break; case "State:":
return Theme.highlightFromColor("red", Theme.colorScheme)
case "Temperature:": case "Temperature:":
return Theme.highlightFromColor("orange", Theme.colorScheme) return Theme.highlightFromColor("orange", Theme.colorScheme)
break;
case "Health:": case "Health:":
return Theme.highlightFromColor("lightblue", Theme.colorScheme) return Theme.highlightFromColor("blue", Theme.colorScheme)
break; case "Battery:":
default: return Theme.highlightFromColor("green", Theme.colorScheme)
}
font.bold = false
return Theme.secondaryColor return Theme.secondaryColor
} }
return Theme.secondaryColor
} }
} }
} Component.onCompleted: updateText()
property string text: "" property string text: ""
function updateText() { function updateText() {
logLabel.text = logger.readLogfile(settings.logFilename) logView.text = logger.readLogfile(settings.logFilename)
logLabel.text.split("\n").forEach( logView.text.split("\n").forEach(
function(l) { model.append({ "line": l }); } function(str) {
model.append({ "line": str })
}
); );
} }
}
} }
} }
} }