FreeKill/Fk/Common/LogEdit.qml
notify 82a1c5f5d5
UI (#297)
修ui小bug
2023-12-12 19:22:18 +08:00

56 lines
1.2 KiB
QML

// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
ListView {
id: root
clip: true
highlight: Rectangle { color: "#EEEEEE"; radius: 5 }
highlightMoveDuration: 500
ScrollBar.vertical: ScrollBar {
parent: root.parent
anchors.top: root.top
anchors.right: root.right
anchors.bottom: root.bottom
}
model: ListModel { id: logModel }
delegate: TextEdit {
id: textEdit
text: logText
width: root.width
clip: true
readOnly: true
selectByKeyboard: true
selectByMouse: false
wrapMode: TextEdit.WrapAnywhere
textFormat: TextEdit.RichText
font.pixelSize: 16
TapHandler {
// acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.NoButton
// gesturePolicy: TapHandler.WithinBounds
onTapped: root.currentIndex = index;
}
}
Button {
text: "Return to Bottom"
visible: root.currentIndex !== logModel.count - 1
onClicked: root.currentIndex = logModel.count - 1;
}
function append(data) {
const autoScroll = root.currentIndex === logModel.count - 1;
logModel.append(data);
if (autoScroll) {
root.currentIndex = logModel.count - 1;
}
}
}