mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-24 22:42:27 +00:00
Start to deduplicate code in qml.
This commit is contained in:
parent
11984de7e7
commit
22fdccbdc0
@ -84,6 +84,8 @@ qt_add_qml_module(chat
|
|||||||
qml/PopupDialog.qml
|
qml/PopupDialog.qml
|
||||||
qml/AboutDialog.qml
|
qml/AboutDialog.qml
|
||||||
qml/Theme.qml
|
qml/Theme.qml
|
||||||
|
qml/MyButton.qml
|
||||||
|
qml/MyComboBox.qml
|
||||||
RESOURCES
|
RESOURCES
|
||||||
icons/send_message.svg
|
icons/send_message.svg
|
||||||
icons/stop_generating.svg
|
icons/stop_generating.svg
|
||||||
|
@ -136,67 +136,20 @@ Window {
|
|||||||
horizontalAlignment: TextInput.AlignRight
|
horizontalAlignment: TextInput.AlignRight
|
||||||
}
|
}
|
||||||
|
|
||||||
ComboBox {
|
MyComboBox {
|
||||||
id: comboBox
|
id: comboBox
|
||||||
width: 350
|
width: 350
|
||||||
anchors.top: modelLabel.top
|
anchors.top: modelLabel.top
|
||||||
anchors.bottom: modelLabel.bottom
|
anchors.bottom: modelLabel.bottom
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
enabled: !currentChat.isServer
|
enabled: !currentChat.isServer
|
||||||
font.pixelSize: theme.fontSizeLarge
|
|
||||||
spacing: 0
|
|
||||||
model: currentChat.modelList
|
model: currentChat.modelList
|
||||||
Accessible.role: Accessible.ComboBox
|
Accessible.role: Accessible.ComboBox
|
||||||
Accessible.name: qsTr("ComboBox for displaying/picking the current model")
|
Accessible.name: qsTr("ComboBox for displaying/picking the current model")
|
||||||
Accessible.description: qsTr("Use this for picking the current model to use; the first item is the current model")
|
Accessible.description: qsTr("Use this for picking the current model to use; the first item is the current model")
|
||||||
contentItem: Text {
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
leftPadding: 10
|
|
||||||
rightPadding: 10
|
|
||||||
text: comboBox.displayText
|
|
||||||
font: comboBox.font
|
|
||||||
color: theme.textColor
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
elide: Text.ElideRight
|
|
||||||
}
|
|
||||||
delegate: ItemDelegate {
|
|
||||||
width: comboBox.width
|
|
||||||
contentItem: Text {
|
|
||||||
text: modelData
|
|
||||||
color: theme.textColor
|
|
||||||
font: comboBox.font
|
|
||||||
elide: Text.ElideRight
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
}
|
|
||||||
background: Rectangle {
|
|
||||||
color: highlighted ? theme.backgroundLight : theme.backgroundDark
|
|
||||||
}
|
|
||||||
highlighted: comboBox.highlightedIndex === index
|
|
||||||
}
|
|
||||||
popup: Popup {
|
|
||||||
y: comboBox.height - 1
|
|
||||||
width: comboBox.width
|
|
||||||
implicitHeight: contentItem.implicitHeight
|
|
||||||
padding: 0
|
|
||||||
|
|
||||||
contentItem: ListView {
|
|
||||||
clip: true
|
|
||||||
implicitHeight: contentHeight
|
|
||||||
model: comboBox.popup.visible ? comboBox.delegateModel : null
|
|
||||||
currentIndex: comboBox.highlightedIndex
|
|
||||||
ScrollIndicator.vertical: ScrollIndicator { }
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: theme.backgroundDark
|
color: theme.backgroundDark
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: theme.backgroundDark
|
|
||||||
}
|
|
||||||
|
|
||||||
onActivated: {
|
onActivated: {
|
||||||
currentChat.stopGenerating()
|
currentChat.stopGenerating()
|
||||||
currentChat.reset();
|
currentChat.reset();
|
||||||
|
23
gpt4all-chat/qml/MyButton.qml
Normal file
23
gpt4all-chat/qml/MyButton.qml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import QtCore
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Controls.Basic
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: myButton
|
||||||
|
padding: 10
|
||||||
|
contentItem: Text {
|
||||||
|
text: myButton.text
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
color: theme.textColor
|
||||||
|
Accessible.role: Accessible.Button
|
||||||
|
Accessible.name: text
|
||||||
|
}
|
||||||
|
background: Rectangle {
|
||||||
|
opacity: .5
|
||||||
|
border.color: theme.backgroundLightest
|
||||||
|
border.width: 1
|
||||||
|
radius: 10
|
||||||
|
color: theme.backgroundLight
|
||||||
|
}
|
||||||
|
}
|
59
gpt4all-chat/qml/MyComboBox.qml
Normal file
59
gpt4all-chat/qml/MyComboBox.qml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Controls.Basic
|
||||||
|
|
||||||
|
ComboBox {
|
||||||
|
font.pixelSize: theme.fontSizeLarge
|
||||||
|
spacing: 0
|
||||||
|
padding: 10
|
||||||
|
Accessible.role: Accessible.ComboBox
|
||||||
|
contentItem: Text {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
leftPadding: 10
|
||||||
|
rightPadding: 10
|
||||||
|
text: comboBox.displayText
|
||||||
|
font: comboBox.font
|
||||||
|
color: theme.textColor
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
delegate: ItemDelegate {
|
||||||
|
width: comboBox.width
|
||||||
|
contentItem: Text {
|
||||||
|
text: modelData
|
||||||
|
color: theme.textColor
|
||||||
|
font: comboBox.font
|
||||||
|
elide: Text.ElideRight
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
background: Rectangle {
|
||||||
|
color: highlighted ? theme.backgroundLight : theme.backgroundDark
|
||||||
|
}
|
||||||
|
highlighted: comboBox.highlightedIndex === index
|
||||||
|
}
|
||||||
|
popup: Popup {
|
||||||
|
y: comboBox.height - 1
|
||||||
|
width: comboBox.width
|
||||||
|
implicitHeight: contentItem.implicitHeight
|
||||||
|
padding: 0
|
||||||
|
|
||||||
|
contentItem: ListView {
|
||||||
|
clip: true
|
||||||
|
implicitHeight: contentHeight
|
||||||
|
model: comboBox.popup.visible ? comboBox.delegateModel : null
|
||||||
|
currentIndex: comboBox.highlightedIndex
|
||||||
|
ScrollIndicator.vertical: ScrollIndicator { }
|
||||||
|
}
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
color: theme.backgroundDark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
background: Rectangle {
|
||||||
|
color: theme.backgroundDark
|
||||||
|
border.width: 1
|
||||||
|
border.color: theme.backgroundLightest
|
||||||
|
radius: 10
|
||||||
|
}
|
||||||
|
}
|
@ -550,27 +550,14 @@ Dialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
MyButton {
|
||||||
Layout.row: 8
|
Layout.row: 8
|
||||||
Layout.column: 1
|
Layout.column: 1
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
padding: 10
|
|
||||||
contentItem: Text {
|
|
||||||
text: qsTr("Restore Defaults")
|
text: qsTr("Restore Defaults")
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
color: theme.textColor
|
|
||||||
Accessible.role: Accessible.Button
|
Accessible.role: Accessible.Button
|
||||||
Accessible.name: text
|
Accessible.name: text
|
||||||
Accessible.description: qsTr("Restores the settings dialog to a default state")
|
Accessible.description: qsTr("Restores the settings dialog to a default state")
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
opacity: .5
|
|
||||||
border.color: theme.backgroundLightest
|
|
||||||
border.width: 1
|
|
||||||
radius: 10
|
|
||||||
color: theme.backgroundLight
|
|
||||||
}
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
settingsDialog.restoreGenerationDefaults()
|
settingsDialog.restoreGenerationDefaults()
|
||||||
}
|
}
|
||||||
@ -606,14 +593,11 @@ Dialog {
|
|||||||
Layout.row: 1
|
Layout.row: 1
|
||||||
Layout.column: 0
|
Layout.column: 0
|
||||||
}
|
}
|
||||||
ComboBox {
|
MyComboBox {
|
||||||
id: comboBox
|
id: comboBox
|
||||||
Layout.row: 1
|
Layout.row: 1
|
||||||
Layout.column: 1
|
Layout.column: 1
|
||||||
Layout.minimumWidth: 350
|
Layout.minimumWidth: 350
|
||||||
font.pixelSize: theme.fontSizeLarge
|
|
||||||
spacing: 0
|
|
||||||
padding: 10
|
|
||||||
model: modelList
|
model: modelList
|
||||||
Accessible.role: Accessible.ComboBox
|
Accessible.role: Accessible.ComboBox
|
||||||
Accessible.name: qsTr("ComboBox for displaying/picking the default model")
|
Accessible.name: qsTr("ComboBox for displaying/picking the default model")
|
||||||
@ -641,57 +625,6 @@ Dialog {
|
|||||||
comboBox.updateModel(currentChat.modelList)
|
comboBox.updateModel(currentChat.modelList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentItem: Text {
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
leftPadding: 10
|
|
||||||
rightPadding: 10
|
|
||||||
text: comboBox.displayText
|
|
||||||
font: comboBox.font
|
|
||||||
color: theme.textColor
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
elide: Text.ElideRight
|
|
||||||
}
|
|
||||||
delegate: ItemDelegate {
|
|
||||||
width: comboBox.width
|
|
||||||
contentItem: Text {
|
|
||||||
text: modelData
|
|
||||||
color: theme.textColor
|
|
||||||
font: comboBox.font
|
|
||||||
elide: Text.ElideRight
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
}
|
|
||||||
background: Rectangle {
|
|
||||||
color: highlighted ? theme.backgroundLight : theme.backgroundDark
|
|
||||||
}
|
|
||||||
highlighted: comboBox.highlightedIndex === index
|
|
||||||
}
|
|
||||||
popup: Popup {
|
|
||||||
y: comboBox.height - 1
|
|
||||||
width: comboBox.width
|
|
||||||
implicitHeight: contentItem.implicitHeight
|
|
||||||
padding: 0
|
|
||||||
|
|
||||||
contentItem: ListView {
|
|
||||||
clip: true
|
|
||||||
implicitHeight: contentHeight
|
|
||||||
model: comboBox.popup.visible ? comboBox.delegateModel : null
|
|
||||||
currentIndex: comboBox.highlightedIndex
|
|
||||||
ScrollIndicator.vertical: ScrollIndicator { }
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: theme.backgroundDark
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: theme.backgroundDark
|
|
||||||
border.width: 1
|
|
||||||
border.color: theme.backgroundLightest
|
|
||||||
radius: 10
|
|
||||||
}
|
|
||||||
|
|
||||||
onActivated: {
|
onActivated: {
|
||||||
settingsDialog.userDefaultModel = comboBox.currentText
|
settingsDialog.userDefaultModel = comboBox.currentText
|
||||||
settings.sync()
|
settings.sync()
|
||||||
@ -734,25 +667,13 @@ Dialog {
|
|||||||
radius: 10
|
radius: 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
MyButton {
|
||||||
Layout.row: 2
|
Layout.row: 2
|
||||||
Layout.column: 2
|
Layout.column: 2
|
||||||
text: qsTr("Browse")
|
text: qsTr("Browse")
|
||||||
contentItem: Text {
|
|
||||||
text: qsTr("Browse")
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
color: theme.textColor
|
|
||||||
Accessible.role: Accessible.Button
|
Accessible.role: Accessible.Button
|
||||||
Accessible.name: text
|
Accessible.name: text
|
||||||
Accessible.description: qsTr("Opens a folder picker dialog to choose where to save model files")
|
Accessible.description: qsTr("Opens a folder picker dialog to choose where to save model files")
|
||||||
}
|
|
||||||
background: Rectangle {
|
|
||||||
opacity: .5
|
|
||||||
border.color: theme.backgroundLightest
|
|
||||||
border.width: 1
|
|
||||||
radius: 10
|
|
||||||
color: theme.backgroundLight
|
|
||||||
}
|
|
||||||
onClicked: modelPathDialog.open()
|
onClicked: modelPathDialog.open()
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
@ -947,27 +868,14 @@ Dialog {
|
|||||||
leftPadding: serverChatBox.indicator.width + serverChatBox.spacing
|
leftPadding: serverChatBox.indicator.width + serverChatBox.spacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
MyButton {
|
||||||
Layout.row: 7
|
Layout.row: 7
|
||||||
Layout.column: 1
|
Layout.column: 1
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
padding: 10
|
|
||||||
contentItem: Text {
|
|
||||||
text: qsTr("Restore Defaults")
|
text: qsTr("Restore Defaults")
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
color: theme.textColor
|
|
||||||
Accessible.role: Accessible.Button
|
Accessible.role: Accessible.Button
|
||||||
Accessible.name: text
|
Accessible.name: text
|
||||||
Accessible.description: qsTr("Restores the settings dialog to a default state")
|
Accessible.description: qsTr("Restores the settings dialog to a default state")
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
opacity: .5
|
|
||||||
border.color: theme.backgroundLightest
|
|
||||||
border.width: 1
|
|
||||||
radius: 10
|
|
||||||
color: theme.backgroundLight
|
|
||||||
}
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
settingsDialog.restoreApplicationDefaults()
|
settingsDialog.restoreApplicationDefaults()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user