Fix chat scrolling (#288)

* fix: Change chat scrolling behavior
* feat: Add compact mode for chat blocks
This commit is contained in:
Petr Mironychev
2025-12-04 20:00:53 +01:00
committed by GitHub
parent fc33bb60d0
commit 5c8a8f305d
4 changed files with 382 additions and 170 deletions

View File

@ -24,7 +24,10 @@ Rectangle {
id: root
property string toolContent: ""
property bool expanded: false
enum DisplayMode { Collapsed, Compact, Expanded }
property int displayMode: ToolBlock.DisplayMode.Compact
property int compactHeight: 120
property alias headerOpacity: headerRow.opacity
@ -40,13 +43,32 @@ Rectangle {
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
}
implicitHeight: {
if (displayMode === ToolBlock.DisplayMode.Collapsed) {
return header.height
} else if (displayMode === ToolBlock.DisplayMode.Compact) {
let fullHeight = header.height + contentColumn.height + 20
return Math.min(fullHeight, header.height + compactHeight)
} else {
return header.height + contentColumn.height + 20
}
}
MouseArea {
id: header
width: parent.width
height: headerRow.height + 10
cursorShape: Qt.PointingHandCursor
onClicked: root.expanded = !root.expanded
onClicked: {
if (root.displayMode === ToolBlock.DisplayMode.Collapsed) {
root.displayMode = ToolBlock.DisplayMode.Compact
} else if (root.displayMode === ToolBlock.DisplayMode.Compact) {
root.displayMode = ToolBlock.DisplayMode.Collapsed
} else {
root.displayMode = ToolBlock.DisplayMode.Compact
}
}
Row {
id: headerRow
@ -68,36 +90,84 @@ Rectangle {
Text {
anchors.verticalCenter: parent.verticalCenter
text: root.expanded ? "" : ""
text: root.displayMode === ToolBlock.DisplayMode.Collapsed ? "" : ""
font.pixelSize: 10
color: palette.mid
}
}
}
Column {
id: contentColumn
Item {
id: contentWrapper
anchors {
left: parent.left
right: parent.right
top: header.bottom
bottom: parent.bottom
margins: 10
bottomMargin: expandButton.visible ? expandButton.height + 15 : 10
}
spacing: 8
clip: true
visible: root.displayMode !== ToolBlock.DisplayMode.Collapsed
TextEdit {
id: resultText
Column {
id: contentColumn
width: parent.width
text: root.toolResult
readOnly: true
selectByMouse: true
color: palette.text
wrapMode: Text.WordWrap
font.family: "monospace"
spacing: 8
TextEdit {
id: resultText
width: parent.width
text: root.toolResult
readOnly: true
selectByMouse: true
color: palette.text
wrapMode: Text.WordWrap
font.family: "monospace"
font.pixelSize: 11
selectionColor: palette.highlight
}
}
}
Rectangle {
id: expandButton
property bool needsExpand: contentColumn.height > 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 !== ToolBlock.DisplayMode.Collapsed
Text {
anchors.centerIn: parent
text: root.displayMode === ToolBlock.DisplayMode.Expanded ? qsTr("▲ Show less") : qsTr("▼ Show more")
font.pixelSize: 11
selectionColor: palette.highlight
color: palette.buttonText
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
if (root.displayMode === ToolBlock.DisplayMode.Expanded) {
root.displayMode = ToolBlock.DisplayMode.Compact
} else {
root.displayMode = ToolBlock.DisplayMode.Expanded
}
}
}
}
@ -126,8 +196,26 @@ Rectangle {
Platform.MenuSeparator {}
Platform.MenuItem {
text: root.expanded ? qsTr("Collapse") : qsTr("Expand")
onTriggered: root.expanded = !root.expanded
text: root.displayMode === ToolBlock.DisplayMode.Collapsed ? qsTr("Expand") : qsTr("Collapse")
onTriggered: {
if (root.displayMode === ToolBlock.DisplayMode.Collapsed) {
root.displayMode = ToolBlock.DisplayMode.Compact
} else {
root.displayMode = ToolBlock.DisplayMode.Collapsed
}
}
}
Platform.MenuItem {
text: root.displayMode === ToolBlock.DisplayMode.Expanded ? qsTr("Compact view") : qsTr("Full view")
enabled: root.displayMode !== ToolBlock.DisplayMode.Collapsed
onTriggered: {
if (root.displayMode === ToolBlock.DisplayMode.Expanded) {
root.displayMode = ToolBlock.DisplayMode.Compact
} else {
root.displayMode = ToolBlock.DisplayMode.Expanded
}
}
}
}
@ -141,22 +229,4 @@ Rectangle {
: Qt.lighter(palette.alternateBase, 1.3)
radius: root.radius
}
states: [
State {
when: !root.expanded
PropertyChanges {
target: root
implicitHeight: header.height
}
},
State {
when: root.expanded
PropertyChanges {
target: root
implicitHeight: header.height + contentColumn.height + 20
}
}
]
}