mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-02-14 02:53:01 -05:00
Fix chat scrolling (#288)
* fix: Change chat scrolling behavior * feat: Add compact mode for chat blocks
This commit is contained in:
@ -28,11 +28,14 @@ Rectangle {
|
||||
|
||||
property string code: ""
|
||||
property string language: ""
|
||||
property bool expanded: false
|
||||
|
||||
enum DisplayMode { Collapsed, Compact, Expanded }
|
||||
property int displayMode: CodeBlock.DisplayMode.Compact
|
||||
property int compactHeight: 150
|
||||
|
||||
property alias codeFontFamily: codeText.font.family
|
||||
property alias codeFontSize: codeText.font.pointSize
|
||||
readonly property real collapsedHeight: copyButton.height + 10
|
||||
readonly property real headerHeight: copyButton.height + 10
|
||||
|
||||
color: palette.alternateBase
|
||||
border.color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.3)
|
||||
@ -46,6 +49,17 @@ Rectangle {
|
||||
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
|
||||
}
|
||||
|
||||
implicitHeight: {
|
||||
if (displayMode === CodeBlock.DisplayMode.Collapsed) {
|
||||
return headerHeight
|
||||
} else if (displayMode === CodeBlock.DisplayMode.Compact) {
|
||||
let fullHeight = headerHeight + codeText.implicitHeight + 20
|
||||
return Math.min(fullHeight, headerHeight + compactHeight)
|
||||
} else {
|
||||
return headerHeight + codeText.implicitHeight + 20
|
||||
}
|
||||
}
|
||||
|
||||
ChatUtils {
|
||||
id: utils
|
||||
}
|
||||
@ -59,9 +73,17 @@ Rectangle {
|
||||
id: header
|
||||
|
||||
width: parent.width
|
||||
height: root.collapsedHeight
|
||||
height: root.headerHeight
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.expanded = !root.expanded
|
||||
onClicked: {
|
||||
if (root.displayMode === CodeBlock.DisplayMode.Collapsed) {
|
||||
root.displayMode = CodeBlock.DisplayMode.Compact
|
||||
} else if (root.displayMode === CodeBlock.DisplayMode.Compact) {
|
||||
root.displayMode = CodeBlock.DisplayMode.Collapsed
|
||||
} else {
|
||||
root.displayMode = CodeBlock.DisplayMode.Compact
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: headerRow
|
||||
@ -83,33 +105,81 @@ Rectangle {
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.expanded ? "▼" : "▶"
|
||||
text: root.displayMode === CodeBlock.DisplayMode.Collapsed ? "▶" : "▼"
|
||||
font.pixelSize: 10
|
||||
color: palette.mid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextEdit {
|
||||
id: codeText
|
||||
Item {
|
||||
id: codeWrapper
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
top: header.bottom
|
||||
bottom: parent.bottom
|
||||
margins: 10
|
||||
bottomMargin: expandButton.visible ? expandButton.height + 15 : 10
|
||||
}
|
||||
clip: true
|
||||
visible: root.displayMode !== CodeBlock.DisplayMode.Collapsed
|
||||
|
||||
TextEdit {
|
||||
id: codeText
|
||||
|
||||
width: parent.width
|
||||
text: root.code
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
color: root.color.hslLightness > 0.5 ? "black" : "white"
|
||||
wrapMode: Text.WordWrap
|
||||
selectionColor: palette.highlight
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.RightButton
|
||||
onClicked: contextMenu.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: expandButton
|
||||
|
||||
property bool needsExpand: codeText.implicitHeight > compactHeight - 20
|
||||
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottomMargin: 5
|
||||
leftMargin: 10
|
||||
rightMargin: 10
|
||||
}
|
||||
height: 24
|
||||
radius: 4
|
||||
color: palette.button
|
||||
visible: needsExpand && root.displayMode !== CodeBlock.DisplayMode.Collapsed
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: root.displayMode === CodeBlock.DisplayMode.Expanded ? qsTr("▲ Show less") : qsTr("▼ Show more")
|
||||
font.pixelSize: 11
|
||||
color: palette.buttonText
|
||||
}
|
||||
text: root.code
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
color: parent.color.hslLightness > 0.5 ? "black" : "white"
|
||||
wrapMode: Text.WordWrap
|
||||
selectionColor: palette.highlight
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.RightButton
|
||||
onClicked: contextMenu.open()
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
if (root.displayMode === CodeBlock.DisplayMode.Expanded) {
|
||||
root.displayMode = CodeBlock.DisplayMode.Compact
|
||||
} else {
|
||||
root.displayMode = CodeBlock.DisplayMode.Expanded
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,8 +197,26 @@ Rectangle {
|
||||
Platform.MenuSeparator {}
|
||||
|
||||
Platform.MenuItem {
|
||||
text: root.expanded ? qsTr("Collapse") : qsTr("Expand")
|
||||
onTriggered: root.expanded = !root.expanded
|
||||
text: root.displayMode === CodeBlock.DisplayMode.Collapsed ? qsTr("Expand") : qsTr("Collapse")
|
||||
onTriggered: {
|
||||
if (root.displayMode === CodeBlock.DisplayMode.Collapsed) {
|
||||
root.displayMode = CodeBlock.DisplayMode.Compact
|
||||
} else {
|
||||
root.displayMode = CodeBlock.DisplayMode.Collapsed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Platform.MenuItem {
|
||||
text: root.displayMode === CodeBlock.DisplayMode.Expanded ? qsTr("Compact view") : qsTr("Full view")
|
||||
enabled: root.displayMode !== CodeBlock.DisplayMode.Collapsed
|
||||
onTriggered: {
|
||||
if (root.displayMode === CodeBlock.DisplayMode.Expanded) {
|
||||
root.displayMode = CodeBlock.DisplayMode.Compact
|
||||
} else {
|
||||
root.displayMode = CodeBlock.DisplayMode.Expanded
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,21 +241,4 @@ Rectangle {
|
||||
onTriggered: parent.text = qsTr("Copy")
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
when: !root.expanded
|
||||
PropertyChanges {
|
||||
target: root
|
||||
implicitHeight: root.collapsedHeight
|
||||
}
|
||||
},
|
||||
State {
|
||||
when: root.expanded
|
||||
PropertyChanges {
|
||||
target: root
|
||||
implicitHeight: header.height + codeText.implicitHeight + 10
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user