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