diff --git a/application/qml/pages/LogPage.qml b/application/qml/pages/LogPage.qml index 32ea0ea..9aa419e 100644 --- a/application/qml/pages/LogPage.qml +++ b/application/qml/pages/LogPage.qml @@ -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) - clip: true - text: line - width: ListView.view.width - wrapMode: TextEdit.NoWrap - truncationMode: TruncationMode.Fade - font.bold:(/%$/.test(text)) // bold if it's a percentage - 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) { + delegate: Component { + Label { + clip: true + text: line + width: logView.width + wrapMode: TextEdit.NoWrap + truncationMode: TruncationMode.Fade + font.bold: true + font.pixelSize: Theme.fontSizeTiny + color: { + 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.highlightFromColor("blue", Theme.colorScheme) + case "Battery:": + return Theme.highlightFromColor("green", Theme.colorScheme) + } + font.bold = false return Theme.secondaryColor } - 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 }) + } ); } - - } } } }