fix(settings): align settings pages with KDE HIG
This commit is contained in:
1 parent
de9e6484ee
commit
3d8f644d8d
10 files changed
+200
-186
No files matched your search
@@ -13,44 +13,73 @@ SettingsBasePage {
|
||||
required property TranslationService translator
|
||||
|
||||
ColumnLayout {
|
||||
spacing: Kirigami.Units.largeSpacing
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@info", "Use an OpenAI-compatible API to translate subtitles. Tracks are translated in batches and saved for reuse.")
|
||||
wrapMode: Text.WordWrap
|
||||
Layout.preferredWidth: form.implicitWidth
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: form.implicitWidth
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
type: Kirigami.MessageType.Error
|
||||
text: root.translator.errorText || ApiKeyStore.error
|
||||
text: root.translator.errorText
|
||||
visible: text.length > 0
|
||||
showCloseButton: true
|
||||
onVisibleChanged: if (!visible) root.translator.clearError()
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
columns: 2
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:textbox", "API base URL")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
}
|
||||
Kirigami.FormLayout {
|
||||
id: form
|
||||
|
||||
TextField {
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "API base URL")
|
||||
id: apiUrlField
|
||||
// Keep an invalid draft in the field; only valid URLs reach KConfig.
|
||||
property bool edited: false
|
||||
readonly property bool valid: /^https?:\/\/(?:\[[0-9a-f:.]+\]|[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.?)(?::[0-9]+)?(?:[/?#][^\s]*)?$/i.test(text.trim())
|
||||
|
||||
function saveUrl() {
|
||||
if (valid) {
|
||||
QtPotatoSettings.apiBaseUrl = text.trim()
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
placeholderText: "https://example.com/v1"
|
||||
text: QtPotatoSettings.apiBaseUrl
|
||||
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
|
||||
Layout.fillWidth: true
|
||||
onTextEdited: QtPotatoSettings.apiBaseUrl = text.trim()
|
||||
onEditingFinished: QtPotatoSettings.save()
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
onTextEdited: edited = true
|
||||
onEditingFinished: saveUrl()
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:textbox", "API key")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
type: Kirigami.MessageType.Error
|
||||
text: KI18n.i18nc("@info", "Enter a valid API base URL with http:// or https:// and a host name.")
|
||||
visible: !apiUrlField.valid && (apiUrlField.edited || apiUrlField.text.length > 0)
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "API key")
|
||||
Kirigami.FormData.buddyFor: apiKeyField
|
||||
Kirigami.PasswordField {
|
||||
id: apiKeyField
|
||||
enabled: !ApiKeyStore.busy
|
||||
placeholderText: ApiKeyStore.hasKey
|
||||
? KI18n.i18nc("@info:placeholder", "Saved in the wallet. Type a new key to replace it.")
|
||||
: KI18n.i18nc("@info:placeholder", "Not set")
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
onEditingFinished: {
|
||||
if (text.trim().length > 0) {
|
||||
ApiKeyStore.setKey(text)
|
||||
@@ -61,6 +90,7 @@ SettingsBasePage {
|
||||
|
||||
Button {
|
||||
visible: ApiKeyStore.hasKey
|
||||
enabled: !ApiKeyStore.busy
|
||||
icon.name: "edit-delete-remove"
|
||||
text: KI18n.i18nc("@action:button", "Remove")
|
||||
onClicked: ApiKeyStore.setKey("")
|
||||
@@ -71,12 +101,26 @@ SettingsBasePage {
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:listbox", "Model")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
type: Kirigami.MessageType.Error
|
||||
text: ApiKeyStore.error
|
||||
visible: text.length > 0
|
||||
actions: Kirigami.Action {
|
||||
text: KI18n.i18nc("@action:button", "Retry")
|
||||
icon.name: "view-refresh"
|
||||
enabled: !ApiKeyStore.busy
|
||||
onTriggered: ApiKeyStore.retry()
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:listbox", "Model")
|
||||
Kirigami.FormData.buddyFor: modelCombo
|
||||
ComboBox {
|
||||
id: modelCombo
|
||||
|
||||
@@ -95,6 +139,7 @@ SettingsBasePage {
|
||||
|
||||
editable: true
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
onEditTextChanged: if (!updatingList) QtPotatoSettings.model = editText.trim()
|
||||
onActivated: QtPotatoSettings.save()
|
||||
Component.onCompleted: showModels()
|
||||
@@ -112,8 +157,11 @@ SettingsBasePage {
|
||||
text: root.translator.fetchingModels
|
||||
? KI18n.i18nc("@action:button", "Loading…")
|
||||
: KI18n.i18nc("@action:button", "Load Models")
|
||||
enabled: !root.translator.fetchingModels
|
||||
onClicked: root.translator.fetchModels()
|
||||
enabled: apiUrlField.valid && !root.translator.fetchingModels
|
||||
onClicked: {
|
||||
apiUrlField.saveUrl()
|
||||
root.translator.fetchModels()
|
||||
}
|
||||
|
||||
ToolTip.text: KI18n.i18nc("@info:tooltip", "Ask the API which models it offers")
|
||||
ToolTip.visible: hovered
|
||||
@@ -121,11 +169,6 @@ SettingsBasePage {
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: 1
|
||||
visible: modelCountLabel.visible
|
||||
}
|
||||
|
||||
Label {
|
||||
id: modelCountLabel
|
||||
visible: root.translator.availableModels.length > 0
|
||||
@@ -133,26 +176,20 @@ SettingsBasePage {
|
||||
opacity: 0.7
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:textbox", "Translate into")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
}
|
||||
|
||||
TextField {
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "Translate into")
|
||||
text: QtPotatoSettings.targetLanguage
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
onTextEdited: QtPotatoSettings.targetLanguage = text.trim()
|
||||
onEditingFinished: QtPotatoSettings.save()
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:listbox", "Preset")
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:listbox", "Preset")
|
||||
id: presetCombo
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
model: root.translator.translationPresets
|
||||
textRole: "name"
|
||||
valueRole: "id"
|
||||
@@ -163,46 +200,49 @@ SettingsBasePage {
|
||||
}
|
||||
}
|
||||
|
||||
Item { Layout.preferredWidth: 1 }
|
||||
|
||||
Label {
|
||||
text: presetCombo.currentIndex >= 0 ? presetCombo.model[presetCombo.currentIndex].description : ""
|
||||
wrapMode: Text.WordWrap
|
||||
opacity: 0.7
|
||||
font: Kirigami.Theme.smallFont
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:textbox", "Additional instructions")
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignBaseline
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
}
|
||||
|
||||
TextArea {
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "Additional instructions")
|
||||
text: QtPotatoSettings.customInstructions
|
||||
placeholderText: KI18n.i18nc("@info:placeholder", "e.g. Translate 'Young Master' as 'Thiếu gia'. Use 'ta/ngươi' between enemies.")
|
||||
wrapMode: TextArea.Wrap
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignBaseline
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 4
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
Kirigami.FormData.labelAlignment: Qt.AlignTop
|
||||
implicitHeight: Math.max(contentHeight + topPadding + bottomPadding, Kirigami.Units.gridUnit * 4)
|
||||
// TextArea has no textEdited before Qt 6.9.
|
||||
onTextChanged: QtPotatoSettings.customInstructions = text
|
||||
onEditingFinished: QtPotatoSettings.save()
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
text: KI18n.i18nc("@option:check", "Build a glossary automatically before translating")
|
||||
Switch {
|
||||
text: KI18n.i18nc("@option:check", "Build glossary automatically")
|
||||
checked: QtPotatoSettings.autoBuildGlossary
|
||||
Layout.columnSpan: 2
|
||||
onToggled: { QtPotatoSettings.autoBuildGlossary = checked; QtPotatoSettings.save() }
|
||||
onClicked: {
|
||||
QtPotatoSettings.autoBuildGlossary = checked
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@label:spinbox", "Lines per request")
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: KI18n.i18nc("@info", "Collect names and terms before translating.")
|
||||
wrapMode: Text.WordWrap
|
||||
font: Kirigami.Theme.smallFont
|
||||
color: Kirigami.Theme.disabledTextColor
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 19
|
||||
}
|
||||
|
||||
SpinBox {
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:spinbox", "Lines per request")
|
||||
from: 5
|
||||
to: 200
|
||||
stepSize: 5
|
||||
@@ -212,16 +252,6 @@ SettingsBasePage {
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
Item { Layout.preferredWidth: 1 }
|
||||
|
||||
Label {
|
||||
text: KI18n.i18nc("@info", "Works with any OpenAI-compatible API. The whole subtitle track is translated in batches before it is shown, and the result is kept so the same track is never translated twice.")
|
||||
wrapMode: Text.WordWrap
|
||||
opacity: 0.7
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: Kirigami.Units.largeSpacing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user