mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-02-15 03:23:05 -05:00
refactor: Fix copy button and add context menu to code block
This commit is contained in:
@ -21,6 +21,7 @@ import QtQuick
|
|||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import ChatView
|
import ChatView
|
||||||
import UIControls
|
import UIControls
|
||||||
|
import Qt.labs.platform as Platform
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: root
|
id: root
|
||||||
@ -104,6 +105,28 @@ Rectangle {
|
|||||||
color: parent.color.hslLightness > 0.5 ? "black" : "white"
|
color: parent.color.hslLightness > 0.5 ? "black" : "white"
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
selectionColor: palette.highlight
|
selectionColor: palette.highlight
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
acceptedButtons: Qt.RightButton
|
||||||
|
onClicked: contextMenu.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform.Menu {
|
||||||
|
id: contextMenu
|
||||||
|
|
||||||
|
Platform.MenuItem {
|
||||||
|
text: qsTr("Copy")
|
||||||
|
onTriggered: utils.copyToClipboard(root.code)
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform.MenuSeparator {}
|
||||||
|
|
||||||
|
Platform.MenuItem {
|
||||||
|
text: root.expanded ? qsTr("Collapse") : qsTr("Expand")
|
||||||
|
onTriggered: root.expanded = !root.expanded
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QoAButton {
|
QoAButton {
|
||||||
@ -112,25 +135,7 @@ Rectangle {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: 5
|
anchors.rightMargin: 5
|
||||||
|
|
||||||
y: {
|
y: 5
|
||||||
if (!hoverHandler.hovered || !root.expanded) {
|
|
||||||
return 5
|
|
||||||
}
|
|
||||||
|
|
||||||
let mouseY = hoverHandler.point.position.y
|
|
||||||
let minY = header.height + 5
|
|
||||||
let maxY = root.height - copyButton.height - 5
|
|
||||||
return Math.max(minY, Math.min(mouseY - copyButton.height / 2, maxY))
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on y {
|
|
||||||
NumberAnimation { duration: 100; easing.type: Easing.OutQuad }
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on opacity {
|
|
||||||
NumberAnimation { duration: 150 }
|
|
||||||
}
|
|
||||||
|
|
||||||
text: qsTr("Copy")
|
text: qsTr("Copy")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|||||||
Reference in New Issue
Block a user