2022-12-18 12:52:52 +08:00
|
|
|
import QtQuick
|
2023-01-29 18:11:41 +08:00
|
|
|
import QtQuick.Controls
|
2022-12-18 12:52:52 +08:00
|
|
|
|
|
|
|
Flickable {
|
|
|
|
id: root
|
|
|
|
property alias font: textEdit.font
|
|
|
|
property alias text: textEdit.text
|
|
|
|
property alias color: textEdit.color
|
|
|
|
property alias textFormat: textEdit.textFormat
|
|
|
|
|
|
|
|
flickableDirection: Flickable.VerticalFlick
|
|
|
|
contentWidth: textEdit.width
|
|
|
|
contentHeight: textEdit.height
|
|
|
|
clip: true
|
2023-01-29 18:11:41 +08:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
|
|
parent: root.parent
|
|
|
|
anchors.top: root.top
|
|
|
|
anchors.right: root.right
|
|
|
|
anchors.bottom: root.bottom
|
|
|
|
}
|
2022-12-18 12:52:52 +08:00
|
|
|
|
|
|
|
TextEdit {
|
|
|
|
id: textEdit
|
|
|
|
|
|
|
|
width: root.width
|
|
|
|
clip: true
|
|
|
|
readOnly: true
|
|
|
|
selectByKeyboard: true
|
|
|
|
selectByMouse: true
|
|
|
|
wrapMode: TextEdit.WrapAnywhere
|
|
|
|
textFormat: TextEdit.RichText
|
2023-02-15 19:54:35 +08:00
|
|
|
font.pixelSize: 16
|
2022-12-18 12:52:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function append(text) {
|
|
|
|
let autoScroll = atYEnd;
|
|
|
|
textEdit.append(text);
|
|
|
|
if (autoScroll && contentHeight > contentY + height) {
|
|
|
|
contentY = contentHeight - height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|