Merge pull request #54 from direc85/colored-log
Add some color to the in-application log view
This commit is contained in:
commit
ce9bf65f8a
1 changed files with 81 additions and 24 deletions
|
@ -20,30 +20,45 @@ import Sailfish.Silica 1.0
|
||||||
import "../components"
|
import "../components"
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: logPage
|
|
||||||
|
|
||||||
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
|
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
|
||||||
|
|
||||||
|
// Invisible; used to determine
|
||||||
|
// the ColumnView delegate size.
|
||||||
|
Label {
|
||||||
|
id: metrics
|
||||||
|
text: "X"
|
||||||
|
font.pixelSize: Theme.fontSizeTiny
|
||||||
|
opacity: 0
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
id: logFlickable
|
id: flickable
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
contentHeight: header.height + column.height
|
contentHeight: header.height
|
||||||
|
+ flow.height
|
||||||
|
+ Theme.paddingLarge
|
||||||
|
+ logView.height
|
||||||
|
|
||||||
|
ScrollDecorator {
|
||||||
|
flickable: flickable
|
||||||
|
}
|
||||||
|
|
||||||
PageHeader {
|
PageHeader {
|
||||||
id: header
|
id: header
|
||||||
title: qsTr("View log")
|
title: qsTr("View log")
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
// Layout the ComboBox and the buttons either
|
||||||
id: column
|
// on top each other (portait) or
|
||||||
anchors {
|
// next to each other (landscape)
|
||||||
top: header.bottom
|
Flow {
|
||||||
horizontalCenter: parent.horizontalCenter
|
id: flow
|
||||||
}
|
anchors.top: header.bottom
|
||||||
width: parent.width - 2*Theme.horizontalPageMargin
|
width: parent.width
|
||||||
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 +71,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 +80,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,19 +89,64 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MyLabel {
|
ColumnView {
|
||||||
id: logLabel
|
id: logView
|
||||||
text: logger.readLogfile(settings.logFilename)
|
anchors {
|
||||||
font.pixelSize: Theme.fontSizeTiny
|
top: flow.bottom
|
||||||
function updateText() {
|
topMargin: Theme.paddingLarge
|
||||||
logLabel.text = logger.readLogfile(settings.logFilename)
|
left: parent.left
|
||||||
|
right: parent.right
|
||||||
|
leftMargin: Theme.horizontalPageMargin
|
||||||
|
}
|
||||||
|
itemHeight: metrics.height
|
||||||
|
clip: true
|
||||||
|
model: ListModel {}
|
||||||
|
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("yellow", Theme.colorScheme)
|
||||||
|
case "State:":
|
||||||
|
return Theme.highlightFromColor("red", Theme.colorScheme)
|
||||||
|
case "Temperature:":
|
||||||
|
return Theme.highlightFromColor("orange", Theme.colorScheme)
|
||||||
|
case "Health:":
|
||||||
|
return Theme.highlightFromColor("blue", Theme.colorScheme)
|
||||||
|
case "Battery:":
|
||||||
|
return Theme.highlightFromColor("green", Theme.colorScheme)
|
||||||
|
}
|
||||||
|
font.bold = false
|
||||||
|
return Theme.secondaryColor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ColumnView only instantiates and renders delegates
|
||||||
|
// as they are about to be shown, so we can
|
||||||
|
// simply dump the full log at it.
|
||||||
|
Component.onCompleted: updateText()
|
||||||
|
property string text: ""
|
||||||
|
function updateText() {
|
||||||
|
logView.text = logger.readLogfile(settings.logFilename)
|
||||||
|
logView.text.split("\n").forEach(
|
||||||
|
function(str) {
|
||||||
|
model.append({ "line": str })
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue