DiagramDesigner/PropertyEditor/resources/Qml/ValueEditor/MultiLineTextBox.qml

84 lines
2.6 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import QtQuick;
import QtQuick.Controls;
import ColorPalette
Item{
id: control
property var value
implicitHeight: lineEditor.implicitHeight + 2
signal asValueChanged(text:var)
function setValue(newText:var){
if(newText !== value){
value = newText
asValueChanged(value)
}
}
Rectangle {
anchors.fill: parent
border.color: ColorPalette.theme.textBoxBackground
color: ColorPalette.theme.textBoxBackground
border.width: 1
clip: true
TextArea{
id: lineEditor
enabled: true
clip: true
padding: 3
anchors.fill: parent
anchors.leftMargin: 2
anchors.rightMargin: 2
text: control.value
color: ColorPalette.theme.textPrimary
wrapMode: TextInput.WordWrap
verticalAlignment: Text.AlignVCenter
onEditingFinished:{
setValue(lineEditor.text)
}
Keys.onPressed: {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (event.modifiers & Qt.ShiftModifier) {
// Shift+Enter保留换行不处理事件
} else {
// 单独按Enter触发编辑完成不换行
event.accepted = true;
lineEditor.editingFinished();
}
}
}
}
MouseArea{
id: hoverArea
hoverEnabled: true
propagateComposedEvents: true
anchors.fill: parent
onEntered:{
exitAnimation.stop()
enterAnimation.start()
hoverArea.cursorShape = Qt.IBeamCursor
}
onExited:{
enterAnimation.stop()
exitAnimation.start()
hoverArea.cursorShape = Qt.ArrowCursor
}
onPressed: (mouse)=> mouse.accepted = false
onReleased:(mouse)=> mouse.accepted = false
onClicked:(mouse)=> mouse.accepted = false
onDoubleClicked:(mouse)=> mouse.accepted = false
}
ColorAnimation on border.color{
id: enterAnimation
to: ColorPalette.theme.boxHover
duration: 100
running: false
}
ColorAnimation on border.color{
id: exitAnimation
to: ColorPalette.theme.textBoxBackground
duration: 100
running: false
}
}
}