MessageSource Line Numbers

Create a model for getting line numbers from a QQuickTextDocument and then add them to the MessageSource page
This commit is contained in:
James Graham
2024-01-26 15:58:12 +00:00
parent f9f678a801
commit 27662f9a4a
4 changed files with 202 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
@@ -11,6 +12,7 @@ import org.kde.syntaxhighlighting
import org.kde.neochat
Kirigami.Page {
id: root
property string sourceText
topPadding: 0
@@ -21,6 +23,7 @@ Kirigami.Page {
title: i18n("Event Source")
QQC2.ScrollView {
id: scrollView
anchors.fill: parent
contentWidth: availableWidth
@@ -29,24 +32,71 @@ Kirigami.Page {
QQC2.TextArea {
id: sourceTextArea
text: sourceText
Layout.fillWidth: true
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
text: root.sourceText
readOnly: true
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
// opt-out of whatever spell checker a styled TextArea might come with
Kirigami.SpellCheck.enabled: false
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
textEdit: sourceTextArea
definition: "JSON"
repository: Repository
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: sourceTextArea.top
topMargin: sourceTextArea.topPadding
left: sourceTextArea.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: LineModel {
id: lineModel
document: sourceTextArea.textDocument
}
delegate: QQC2.Label {
id: label
required property int index
required property int docLineHeight
Layout.fillWidth: true
Layout.preferredHeight: docLineHeight
topPadding: 1
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
}
}
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
}
}
Kirigami.Separator {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing
}
}
}