Start to deduplicate code in qml.

This commit is contained in:
Adam Treat 2023-05-22 09:01:46 -04:00 committed by AT
parent 11984de7e7
commit 22fdccbdc0
5 changed files with 100 additions and 155 deletions

View File

@ -84,6 +84,8 @@ qt_add_qml_module(chat
qml/PopupDialog.qml
qml/AboutDialog.qml
qml/Theme.qml
qml/MyButton.qml
qml/MyComboBox.qml
RESOURCES
icons/send_message.svg
icons/stop_generating.svg

View File

@ -136,67 +136,20 @@ Window {
horizontalAlignment: TextInput.AlignRight
}
ComboBox {
MyComboBox {
id: comboBox
width: 350
anchors.top: modelLabel.top
anchors.bottom: modelLabel.bottom
anchors.horizontalCenter: parent.horizontalCenter
enabled: !currentChat.isServer
font.pixelSize: theme.fontSizeLarge
spacing: 0
model: currentChat.modelList
Accessible.role: Accessible.ComboBox
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")
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
}
onActivated: {
currentChat.stopGenerating()
currentChat.reset();

View 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
}
}

View 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
}
}

View File

@ -550,27 +550,14 @@ Dialog {
}
}
}
Button {
MyButton {
Layout.row: 8
Layout.column: 1
Layout.fillWidth: true
padding: 10
contentItem: Text {
text: qsTr("Restore Defaults")
horizontalAlignment: Text.AlignHCenter
color: theme.textColor
Accessible.role: Accessible.Button
Accessible.name: text
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
}
text: qsTr("Restore Defaults")
Accessible.role: Accessible.Button
Accessible.name: text
Accessible.description: qsTr("Restores the settings dialog to a default state")
onClicked: {
settingsDialog.restoreGenerationDefaults()
}
@ -606,14 +593,11 @@ Dialog {
Layout.row: 1
Layout.column: 0
}
ComboBox {
MyComboBox {
id: comboBox
Layout.row: 1
Layout.column: 1
Layout.minimumWidth: 350
font.pixelSize: theme.fontSizeLarge
spacing: 0
padding: 10
model: modelList
Accessible.role: Accessible.ComboBox
Accessible.name: qsTr("ComboBox for displaying/picking the default model")
@ -641,57 +625,6 @@ Dialog {
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: {
settingsDialog.userDefaultModel = comboBox.currentText
settings.sync()
@ -734,25 +667,13 @@ Dialog {
radius: 10
}
}
Button {
MyButton {
Layout.row: 2
Layout.column: 2
text: qsTr("Browse")
contentItem: Text {
text: qsTr("Browse")
horizontalAlignment: Text.AlignHCenter
color: theme.textColor
Accessible.role: Accessible.Button
Accessible.name: text
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
}
Accessible.role: Accessible.Button
Accessible.name: text
Accessible.description: qsTr("Opens a folder picker dialog to choose where to save model files")
onClicked: modelPathDialog.open()
}
Label {
@ -947,27 +868,14 @@ Dialog {
leftPadding: serverChatBox.indicator.width + serverChatBox.spacing
}
}
Button {
MyButton {
Layout.row: 7
Layout.column: 1
Layout.fillWidth: true
padding: 10
contentItem: Text {
text: qsTr("Restore Defaults")
horizontalAlignment: Text.AlignHCenter
color: theme.textColor
Accessible.role: Accessible.Button
Accessible.name: text
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
}
text: qsTr("Restore Defaults")
Accessible.role: Accessible.Button
Accessible.name: text
Accessible.description: qsTr("Restores the settings dialog to a default state")
onClicked: {
settingsDialog.restoreApplicationDefaults()
}