Warning, /graphics/koko/src/qml/SettingsPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Mikel Johnson <mikel5764@gmail.com>
0002 // SPDX-FileCopyrightText: 2023 Carl Schwan <carlschwan@kde.org>
0003 // SPDX-License-Identifier: LGPL-2.0-or-later
0004 
0005 import QtQuick 2.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import org.kde.kirigami 2.18 as Kirigami
0008 import QtQuick.Layouts 1.15
0009 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0010 
0011 Kirigami.PageRow {
0012     id: settingsPage
0013 
0014     globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar
0015 
0016     initialPage: FormCard.FormCardPage {
0017         title: i18nc("@title:window", "Settings")
0018 
0019         FormCard.FormHeader {
0020             title: i18n("General")
0021         }
0022 
0023         FormCard.FormCard {
0024             FormCard.AbstractFormDelegate {
0025                 Layout.fillWidth: true
0026                 contentItem: ColumnLayout {
0027                     QQC2.Label {
0028                         text: i18n("Thumbnails size:")
0029                         Layout.fillWidth: true
0030                     }
0031                     QQC2.Slider {
0032                         Layout.fillWidth: true
0033                         from: Kirigami.Units.gridUnit * 4
0034                         to: Kirigami.Units.gridUnit * 8
0035                         value: kokoConfig.iconSize
0036                         onMoved: kokoConfig.iconSize = value;
0037                     }
0038                 }
0039             }
0040         }
0041 
0042         FormCard.FormHeader {
0043             title: i18nc("@title:group", "Slideshow settings:")
0044             visible: !Kirigami.Settings.isMobile
0045         }
0046 
0047         FormCard.FormCard {
0048             visible: !Kirigami.Settings.isMobile
0049             FormCard.FormCheckDelegate {
0050                 id: randomizeImagesCheckbox
0051                 text: i18nc("@option:check", "Randomize")
0052                 checked: kokoConfig.randomizeImages
0053                 onCheckedChanged: kokoConfig.randomizeImages = checked
0054             }
0055 
0056             FormCard.FormDelegateSeparator { above: randomizeImagesCheckbox}
0057 
0058             FormCard.AbstractFormDelegate {
0059                 Layout.fillWidth: true
0060                 background: Item {}
0061                 contentItem: RowLayout {
0062                     QQC2.Label {
0063                         text: i18nc("@label:spinbox Slideshow image changing interval", "Slideshow interval:")
0064                         Layout.fillWidth: true
0065                     }
0066                     QQC2.SpinBox {
0067                         id: intervalSpinBox
0068                         from: 1
0069                         // limited to hundreds for now because I don't want
0070                         // to deal with regexing for locale formatted numbers
0071                         to: 999
0072                         value: kokoConfig.nextImageInterval
0073                         editable: true
0074                         textFromValue: (value) => i18ncp("Slideshow image changing interval",
0075                                                             "1 second", "%1 seconds", value)
0076                         valueFromText: (text) => {
0077                             const match = text.match(/\d{1,3}/)
0078                             return match !== null ? match[0] : intervalSpinBox.value
0079                         }
0080                         TextMetrics {
0081                             id: intervalMetrics
0082                             text: intervalSpinBox.textFromValue(intervalSpinBox.to)
0083                         }
0084                         wheelEnabled: true
0085                         contentItem: QQC2.TextField {
0086                             property int oldCursorPosition: cursorPosition
0087                             implicitWidth: intervalMetrics.width + leftPadding + rightPadding
0088                             implicitHeight: Math.ceil(contentHeight) + topPadding + bottomPadding
0089                             palette: parent.palette
0090                             leftPadding: parent.spacing
0091                             rightPadding: parent.spacing
0092                             topPadding: 0
0093                             bottomPadding: 0
0094                             font: parent.font
0095                             color: palette.text
0096                             selectionColor: palette.highlight
0097                             selectedTextColor: palette.highlightedText
0098                             horizontalAlignment: Qt.AlignHCenter
0099                             verticalAlignment: Qt.AlignVCenter
0100                             readOnly: !parent.editable
0101                             validator: parent.validator
0102                             inputMethodHints: parent.inputMethodHints
0103                             selectByMouse: true
0104                             background: null
0105                             // Trying to mimic some of QSpinBox's behavior with suffixes
0106                             onTextChanged: if (!inputMethodComposing) {
0107                                 const valueText = parent.valueFromText(text).toString()
0108                                 const valueIndex = parent.displayText.indexOf(valueText)
0109                                 if (valueIndex >= 0) {
0110                                     console.log(valueIndex, cursorPosition)
0111                                     cursorPosition = Math.min(Math.max(valueIndex, oldCursorPosition), valueIndex + valueText.length)
0112                                 }
0113                             }
0114                             Component.onCompleted: oldCursorPosition = cursorPosition
0115                         }
0116                         // Can't just use a binding because modifying the text
0117                         // elsewhere will break bindings.
0118                         onValueChanged: {
0119                             contentItem.oldCursorPosition = contentItem.cursorPosition
0120                             contentItem.text = displayText
0121                         }
0122                         onValueModified: kokoConfig.nextImageInterval = value
0123                     }
0124                 }
0125             }
0126         }
0127 
0128         FormCard.FormCard {
0129             Layout.topMargin: Kirigami.Units.gridUnit
0130             FormCard.FormButtonDelegate {
0131                 text: i18n("About Koko")
0132                 onClicked: pageStack.layers.push(Qt.resolvedUrl("AboutPage.qml"));
0133 
0134                 Component {
0135                     id: aboutPage
0136                     FormCard.AboutPage {
0137                         aboutData: About
0138                     }
0139                 }
0140             }
0141         }
0142     }
0143 }