gpt4all/gpt4all-chat/qml/ChatDrawer.qml

292 lines
12 KiB
QML
Raw Normal View History

import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts
2023-06-22 15:44:49 -04:00
import chatlistmodel
import llm
import download
import network
import mysettings
Drawer {
id: chatDrawer
modal: false
opacity: 0.9
Theme {
id: theme
}
signal downloadClicked
2023-05-05 10:47:05 -04:00
signal aboutClicked
background: Rectangle {
height: parent.height
color: theme.backgroundDarkest
}
Item {
anchors.fill: parent
2023-05-01 17:13:20 -04:00
anchors.margins: 10
Accessible.role: Accessible.Pane
Accessible.name: qsTr("Drawer on the left of the application")
Accessible.description: qsTr("Drawer that is revealed by pressing the hamburger button")
2023-05-22 14:17:45 -04:00
MyButton {
2023-05-01 17:13:20 -04:00
id: newChat
anchors.left: parent.left
anchors.right: parent.right
font.pixelSize: theme.fontSizeLarger
2023-05-31 20:42:00 -04:00
topPadding: 20
bottomPadding: 20
text: qsTr("\uFF0B New chat")
Accessible.description: qsTr("Use this to create a new chat")
2023-05-31 20:42:00 -04:00
background: Rectangle {
border.color: newChat.down ? theme.backgroundLightest : theme.buttonBorder
border.width: 2
radius: 10
color: newChat.hovered ? theme.backgroundDark : theme.backgroundDarkest
}
2023-05-01 17:13:20 -04:00
onClicked: {
2023-06-22 15:44:49 -04:00
ChatListModel.addChat();
Network.sendNewChat(ChatListModel.count)
2023-05-01 17:13:20 -04:00
}
}
ScrollView {
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: -10
2023-05-01 17:13:20 -04:00
anchors.topMargin: 10
anchors.top: newChat.bottom
anchors.bottom: checkForUpdatesButton.top
anchors.bottomMargin: 10
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
clip: true
2023-05-01 17:13:20 -04:00
ListView {
id: conversationList
anchors.fill: parent
anchors.rightMargin: 10
2023-06-22 15:44:49 -04:00
model: ChatListModel
ScrollBar.vertical: ScrollBar { policy: ScrollBar.AlwaysOn }
delegate: Rectangle {
id: chatRectangle
2023-05-01 20:56:53 -04:00
width: conversationList.width
height: chatName.height
opacity: 0.9
2023-06-22 15:44:49 -04:00
property bool isCurrent: ChatListModel.currentChat === ChatListModel.get(index)
property bool isServer: ChatListModel.get(index) && ChatListModel.get(index).isServer
property bool trashQuestionDisplayed: false
visible: !isServer || MySettings.serverChat
z: isCurrent ? 199 : 1
2023-05-11 16:46:25 -04:00
color: isServer ? theme.backgroundDarkest : (index % 2 === 0 ? theme.backgroundLight : theme.backgroundLighter)
border.width: isCurrent
border.color: chatName.readOnly ? theme.assistantColor : theme.userColor
2023-05-02 11:19:17 -04:00
TextField {
id: chatName
anchors.left: parent.left
2023-05-01 20:56:53 -04:00
anchors.right: buttons.left
color: theme.textColor
padding: 15
focus: false
readOnly: true
wrapMode: Text.NoWrap
hoverEnabled: false // Disable hover events on the TextArea
selectByMouse: false // Disable text selection in the TextArea
font.pixelSize: theme.fontSizeLarger
2023-05-02 11:19:17 -04:00
text: readOnly ? metrics.elidedText : name
horizontalAlignment: TextInput.AlignLeft
opacity: trashQuestionDisplayed ? 0.5 : 1.0
2023-05-02 11:19:17 -04:00
TextMetrics {
id: metrics
font: chatName.font
text: name
elide: Text.ElideRight
elideWidth: chatName.width - 25
}
background: Rectangle {
color: "transparent"
}
onEditingFinished: {
// Work around a bug in qml where we're losing focus when the whole window
// goes out of focus even though this textfield should be marked as not
// having focus
if (chatName.readOnly)
return;
changeName();
Network.sendRenameChat()
}
function changeName() {
2023-06-22 15:44:49 -04:00
ChatListModel.get(index).name = chatName.text
chatName.focus = false
chatName.readOnly = true
2023-05-02 11:19:17 -04:00
chatName.selectByMouse = false
}
TapHandler {
onTapped: {
if (isCurrent)
return;
2023-06-22 15:44:49 -04:00
ChatListModel.currentChat = ChatListModel.get(index);
}
}
Accessible.role: Accessible.Button
Accessible.name: qsTr("Select the current chat")
Accessible.description: qsTr("Provides a button to select the current chat or edit the chat when in edit mode")
}
2023-05-01 20:56:53 -04:00
Row {
id: buttons
anchors.verticalCenter: chatName.verticalCenter
anchors.right: chatRectangle.right
anchors.rightMargin: 10
2023-05-01 20:56:53 -04:00
spacing: 10
MyToolButton {
2023-05-01 20:56:53 -04:00
id: editButton
width: 30
height: 30
2023-05-11 16:46:25 -04:00
visible: isCurrent && !isServer
opacity: trashQuestionDisplayed ? 0.5 : 1.0
source: "qrc:/gpt4all/icons/edit.svg"
2023-05-01 20:56:53 -04:00
onClicked: {
chatName.focus = true
chatName.readOnly = false
2023-05-02 11:19:17 -04:00
chatName.selectByMouse = true
2023-05-01 20:56:53 -04:00
}
Accessible.name: qsTr("Edit the chat name")
Accessible.description: qsTr("Provides a button to edit the chat name")
}
MyToolButton {
2023-05-11 16:46:25 -04:00
id: trashButton
2023-05-01 20:56:53 -04:00
width: 30
height: 30
2023-05-11 16:46:25 -04:00
visible: isCurrent && !isServer
source: "qrc:/gpt4all/icons/trash.svg"
2023-05-01 20:56:53 -04:00
onClicked: {
trashQuestionDisplayed = true
timer.start()
2023-05-01 20:56:53 -04:00
}
Accessible.name: qsTr("Delete of the chat")
Accessible.description: qsTr("Provides a button to delete the chat")
}
}
Rectangle {
id: trashSureQuestion
anchors.top: buttons.bottom
anchors.topMargin: 10
anchors.right: buttons.right
width: childrenRect.width
height: childrenRect.height
color: chatRectangle.color
visible: isCurrent && trashQuestionDisplayed
opacity: 1.0
radius: 10
z: 200
Row {
spacing: 10
Button {
id: checkMark
width: 30
height: 30
contentItem: Text {
color: theme.textErrorColor
text: "\u2713"
font.pixelSize: theme.fontSizeLarger
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
width: 30
height: 30
color: "transparent"
}
onClicked: {
2023-06-22 15:44:49 -04:00
ChatListModel.removeChat(ChatListModel.get(index))
Network.sendRemoveChat()
}
Accessible.role: Accessible.Button
Accessible.name: qsTr("Confirm delete of the chat")
Accessible.description: qsTr("Provides a button to confirm delete of the chat")
}
Button {
id: cancel
width: 30
height: 30
contentItem: Text {
color: theme.textColor
text: "\u2715"
font.pixelSize: theme.fontSizeLarger
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
width: 30
height: 30
color: "transparent"
}
onClicked: {
trashQuestionDisplayed = false
}
Accessible.role: Accessible.Button
Accessible.name: qsTr("Cancel the delete of the chat")
Accessible.description: qsTr("Provides a button to cancel delete of the chat")
}
}
}
Timer {
id: timer
interval: 3000; running: false; repeat: false
onTriggered: trashQuestionDisplayed = false
}
2023-05-01 17:13:20 -04:00
}
Accessible.role: Accessible.List
Accessible.name: qsTr("List of chats")
Accessible.description: qsTr("List of chats in the drawer dialog")
}
}
2023-05-22 14:17:45 -04:00
MyButton {
2023-05-01 17:13:20 -04:00
id: checkForUpdatesButton
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: downloadButton.top
2023-05-01 17:13:20 -04:00
anchors.bottomMargin: 10
2023-05-22 14:17:45 -04:00
text: qsTr("Updates")
2023-08-07 13:54:13 -04:00
font.pixelSize: theme.fontSizeLarge
2023-05-22 14:17:45 -04:00
Accessible.description: qsTr("Use this to launch an external application that will check for updates to the installer")
onClicked: {
if (!LLM.checkForUpdates())
checkForUpdatesError.open()
}
}
2023-05-22 14:17:45 -04:00
MyButton {
id: downloadButton
anchors.left: parent.left
anchors.right: parent.right
2023-05-05 10:47:05 -04:00
anchors.bottom: aboutButton.top
anchors.bottomMargin: 10
2023-05-22 14:17:45 -04:00
text: qsTr("Downloads")
Accessible.description: qsTr("Use this to launch a dialog to download new models")
onClicked: {
downloadClicked()
}
}
2023-05-05 10:47:05 -04:00
2023-05-22 14:17:45 -04:00
MyButton {
2023-05-05 10:47:05 -04:00
id: aboutButton
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
2023-05-22 14:17:45 -04:00
text: qsTr("About")
Accessible.description: qsTr("Use this to launch a dialog to show the about page")
2023-05-05 10:47:05 -04:00
onClicked: {
aboutClicked()
}
}
}
}