Warning, /network/tokodon/src/content/ui/Settings/SonnetPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 import QtQml
0005 import QtQuick
0006 import QtQuick.Controls 2 as QQC2
0007 import QtQuick.Layouts
0008 import org.kde.kirigami 2 as Kirigami
0009 import org.kde.kirigami.delegates as KirigamiDelegates
0010 import org.kde.sonnet 1 as Sonnet
0011 import org.kde.kirigamiaddons.formcard 1 as FormCard
0012 import org.kde.kirigamiaddons.delegates 1 as Delegates
0013 
0014 FormCard.FormCardPage {
0015     FormCard.FormCard {
0016         id: card
0017 
0018         Layout.topMargin: Kirigami.Units.largeSpacing
0019 
0020         readonly
0021         property
0022         Sonnet.Settings
0023         settings: Sonnet.Settings
0024         {
0025             id: settings
0026         }
0027 
0028         FormCard.FormCheckDelegate {
0029             id: enable
0030             checked: settings.checkerEnabledByDefault
0031             text: i18n("Enable automatic spell checking")
0032             onCheckedChanged: {
0033                 settings.checkerEnabledByDefault = checked;
0034                 settings.save();
0035             }
0036         }
0037 
0038         FormCard.FormDelegateSeparator {
0039             below: enable; above: skipUppercase
0040         }
0041 
0042         FormCard.FormCheckDelegate {
0043             id: skipUppercase
0044             checked: settings.skipUppercase
0045             text: i18n("Ignore uppercase words")
0046             onCheckedChanged: {
0047                 settings.skipUppercase = checked;
0048                 settings.save();
0049             }
0050         }
0051 
0052         FormCard.FormDelegateSeparator {
0053             below: skipUppercase; above: skipRunTogether
0054         }
0055 
0056         FormCard.FormCheckDelegate {
0057             id: skipRunTogether
0058             checked: settings.skipRunTogether
0059             text: i18n("Ignore hyphenated words")
0060             onCheckedChanged: {
0061                 settings.skipRunTogether = checked;
0062                 settings.save();
0063             }
0064         }
0065 
0066         FormCard.FormDelegateSeparator {
0067             below: skipRunTogether; above: autodetectLanguageCheckbox
0068         }
0069 
0070         FormCard.FormCheckDelegate {
0071             id: autodetectLanguageCheckbox
0072             checked: settings.autodetectLanguage
0073             text: i18n("Detect language automatically")
0074             onCheckedChanged: {
0075                 settings.autodetectLanguage = checked;
0076                 settings.save();
0077             }
0078         }
0079 
0080         FormCard.FormDelegateSeparator {
0081             below: autodetectLanguageCheckbox; above: selectedDefaultLanguage
0082         }
0083 
0084         FormCard.FormComboBoxDelegate {
0085             id: selectedDefaultLanguage
0086             text: i18n("Selected default language:")
0087             model: isEmpty ? [{"display": i18n("None")}] : settings.dictionaryModel
0088             textRole: "display"
0089             displayMode: Kirigami.Settings.isMobile ? FormCard.FormComboBoxDelegate.Dialog : FormCard.FormComboBoxDelegate.Page
0090             valueRole: "languageCode"
0091             property bool isEmpty: false
0092             Component.onCompleted: {
0093                 if (settings.dictionaryModel.rowCount() === 0) {
0094                     isEmpty = true;
0095                 } else {
0096                     currentIndex = indexOfValue(settings.defaultLanguage);
0097                 }
0098             }
0099             onActivated: settings.defaultLanguage = currentValue;
0100         }
0101 
0102         FormCard.FormDelegateSeparator {
0103             below: selectedDefaultLanguage; above: spellCheckingLanguage
0104         }
0105 
0106         FormCard.FormButtonDelegate {
0107             id: spellCheckingLanguage
0108             text: i18n("Additional Spell Checking Languages")
0109             description: i18n("%1 will provide spell checking and suggestions for the languages listed here when autodetection is enabled.", Qt.application.displayName)
0110             onClicked: pageStack.pushDialogLayer(spellCheckingLanguageList, {}, {
0111                 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0112                 height: pageStack.height - Kirigami.Units.gridUnit * 5,
0113             })
0114         }
0115 
0116         FormCard.FormDelegateSeparator {
0117             below: spellCheckingLanguage; above: personalDictionary
0118         }
0119 
0120         FormCard.FormButtonDelegate {
0121             id: personalDictionary
0122             text: i18n("Open Personal Dictionary")
0123             onClicked: pageStack.pushDialogLayer(dictionaryPage, {}, {
0124                 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0125                 height: pageStack.height - Kirigami.Units.gridUnit * 5,
0126             })
0127         }
0128 
0129         data: [
0130             Component {
0131                 id: spellCheckingLanguageList
0132                 Kirigami.ScrollablePage {
0133                     id: scroll
0134                     title: i18nc("@title:window", "Spell checking languages")
0135                     enabled: autodetectLanguageCheckbox.checked
0136                     ListView {
0137                         clip: true
0138                         model: settings.dictionaryModel
0139                         delegate: KirigamiDelegates.CheckSubtitleDelegate {
0140                             width: ListView.view.width
0141 
0142                             text: model.display
0143                             action: Kirigami.Action {
0144                                 onTriggered: model.checked = checked
0145                             }
0146                             Accessible.description: model.isDefault ? i18n("Default Language") : ''
0147                             checked: model.checked
0148 
0149                             icon.source: model.isDefault ? "favorite" : undefined
0150                         }
0151                     }
0152                 }
0153             },
0154 
0155             Component {
0156                 id: dictionaryPage
0157                 Kirigami.ScrollablePage {
0158                     title: i18n("Spell checking dictionary")
0159                     footer: QQC2.ToolBar {
0160                         contentItem: RowLayout {
0161                             QQC2.TextField {
0162                                 id: dictionaryField
0163                                 Layout.fillWidth: true
0164                                 Accessible.name: placeholderText
0165                                 placeholderText: i18n("Add a new word to your personal dictionary…")
0166                             }
0167                             QQC2.Button {
0168                                 text: i18nc("@action:button", "Add Word")
0169                                 icon.name: "list-add"
0170                                 enabled: dictionaryField.text.length > 0
0171                                 onClicked: {
0172                                     add(dictionaryField.text);
0173                                     dictionaryField.clear();
0174                                     if (instantApply) {
0175                                         settings.save();
0176                                     }
0177                                 }
0178                                 Layout.rightMargin: Kirigami.Units.largeSpacing
0179                             }
0180                         }
0181                     }
0182                     ListView {
0183                         topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0184                         bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0185 
0186                         model: settings.currentIgnoreList
0187                         delegate: Delegates.RoundedItemDelegate {
0188                             id: wordDelegate
0189 
0190                             required property var modelData
0191 
0192                             text: modelData
0193 
0194                             contentItem: RowLayout {
0195                                 spacing: Kirigami.Units.smallSpacing
0196 
0197                                 Delegates.DefaultContentItem {
0198                                     itemDelegate: wordDelegate
0199                                     Layout.fillWidth: true
0200                                 }
0201 
0202                                 QQC2.ToolButton {
0203                                     text: i18nc("@action:button", "Delete word")
0204                                     icon.name: "delete"
0205                                     display: QQC2.ToolButton.IconOnly
0206                                     onClicked: {
0207                                         remove(wordDelegate.modelData);
0208                                         if (instantApply) {
0209                                             settings.save();
0210                                         }
0211                                     }
0212 
0213                                     QQC2.ToolTip.text: text
0214                                     QQC2.ToolTip.visible: hovered
0215                                     QQC2.ToolTip.delay: Kirigami.ToolTip.toolTipDelay
0216                                 }
0217                             }
0218                         }
0219                     }
0220                 }
0221             }
0222         ]
0223 
0224         function add(word: string) {
0225             const dictionary = settings.currentIgnoreList;
0226             dictionary.push(word);
0227             settings.currentIgnoreList = dictionary;
0228         }
0229 
0230         function remove(word: string) {
0231             settings.currentIgnoreList = settings.currentIgnoreList.filter((value, _, _) => {
0232                 return value !== word;
0233             });
0234         }
0235     }
0236 }