Warning, /plasma/plasma-mobile/containments/homescreens/folio/package/contents/ui/settings/SettingsWindow.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Window
0006 import QtQuick.Layouts
0007 import QtQuick.Dialogs
0008 import QtQuick.Controls as QQC2
0009 
0010 import org.kde.kirigami 2.20 as Kirigami
0011 
0012 import org.kde.private.mobile.homescreen.folio 1.0 as Folio
0013 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0014 
0015 import '../delegate'
0016 
0017 Window {
0018     id: root
0019     flags: Qt.FramelessWindowHint
0020     color: 'transparent'
0021 
0022     onVisibleChanged: {
0023         if (visible) {
0024             opacityAnim.to = 1;
0025             opacityAnim.restart();
0026         }
0027     }
0028 
0029     onClosing: (close) => {
0030         if (applicationItem.opacity !== 0) {
0031             close.accepted = false;
0032             opacityAnim.to = 0;
0033             opacityAnim.restart();
0034         }
0035     }
0036 
0037     signal requestConfigureMenu()
0038 
0039     Kirigami.ApplicationItem {
0040         id: applicationItem
0041         anchors.fill: parent
0042 
0043         opacity: 0
0044 
0045         NumberAnimation on opacity {
0046             id: opacityAnim
0047             duration: 200
0048             easing.type: Easing.OutCubic
0049             onFinished: {
0050                 if (applicationItem.opacity === 0) {
0051                     root.close();
0052                 }
0053             }
0054         }
0055 
0056         scale: 0.7 + 0.3 * applicationItem.opacity
0057 
0058         pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar
0059         pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.NoNavigationButtons;
0060 
0061         pageStack.initialPage: Kirigami.ScrollablePage {
0062             id: page
0063             opacity: applicationItem.opacity
0064 
0065             titleDelegate: RowLayout {
0066                 QQC2.ToolButton {
0067                     Layout.leftMargin: -Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing
0068                     icon.name: "arrow-left"
0069                     onClicked: root.close()
0070                 }
0071 
0072                 Kirigami.Heading {
0073                     level: 1
0074                     text: page.title
0075                 }
0076             }
0077 
0078             title: i18n("Homescreen Settings")
0079 
0080             topPadding: 0
0081             bottomPadding: 0
0082             leftPadding: 0
0083             rightPadding: 0
0084 
0085             ColumnLayout {
0086                 FormCard.FormHeader {
0087                     title: i18n("Icons")
0088                 }
0089 
0090                 FormCard.FormCard {
0091                     Kirigami.Theme.inherit: false
0092                     Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
0093 
0094                     Item {
0095                         Layout.preferredHeight: Folio.HomeScreenState.pageCellHeight
0096                         Layout.fillWidth: true
0097 
0098                         AbstractDelegate {
0099                             anchors.centerIn: parent
0100                             implicitHeight: Folio.HomeScreenState.pageCellHeight
0101                             implicitWidth: Folio.HomeScreenState.pageCellWidth
0102                             name: i18n('Application')
0103 
0104                             contentItem: DelegateAppIcon {
0105                                 height: Folio.FolioSettings.delegateIconSize
0106                                 width: Folio.FolioSettings.delegateIconSize
0107                                 source: 'applications-system'
0108                             }
0109                         }
0110                     }
0111                 }
0112 
0113                 FormCard.FormCard {
0114                     id: iconsCard
0115                     readonly property bool isVerticalOrientation: Folio.HomeScreenState.pageOrientation === Folio.HomeScreenState.RegularPosition ||
0116                                                                 Folio.HomeScreenState.pageOrientation === Folio.HomeScreenState.RotateUpsideDown
0117 
0118                     readonly property string numOfRowsText: i18n("Number of rows")
0119                     readonly property string numOfColumnsText: i18n("Number of columns")
0120 
0121                     FormCard.FormSpinBoxDelegate {
0122                         id: iconSizeSpinBox
0123                         label: i18n("Size of icons on homescreen")
0124                         from: 16
0125                         to: 128
0126                         value: Folio.FolioSettings.delegateIconSize
0127                         onValueChanged: {
0128                             if (value !== Folio.FolioSettings.delegateIconSize) {
0129                                 Folio.FolioSettings.delegateIconSize = value;
0130                             }
0131                         }
0132                     }
0133 
0134                     FormCard.FormSpinBoxDelegate {
0135                         id: rowsSpinBox
0136                         label: iconsCard.isVerticalOrientation ? iconsCard.numOfRowsText : iconsCard.numOfColumnsText
0137                         from: 3
0138                         to: 10
0139                         value: Folio.FolioSettings.homeScreenRows
0140                         onValueChanged: {
0141                             if (value !== Folio.FolioSettings.homeScreenRows) {
0142                                 Folio.FolioSettings.homeScreenRows = value;
0143                             }
0144                         }
0145                     }
0146 
0147                     FormCard.FormSpinBoxDelegate {
0148                         id: columnsSpinBox
0149                         label: iconsCard.isVerticalOrientation ? iconsCard.numOfColumnsText : iconsCard.numOfRowsText
0150                         from: 3
0151                         to: 10
0152                         value: Folio.FolioSettings.homeScreenColumns
0153                         onValueChanged: {
0154                             if (value !== Folio.FolioSettings.homeScreenColumns) {
0155                                 Folio.FolioSettings.homeScreenColumns = value;
0156                             }
0157                         }
0158                     }
0159                 }
0160 
0161                 FormCard.FormSectionText {
0162                     text: i18n("The rows and columns will swap depending on the screen rotation.")
0163                 }
0164 
0165                 FormCard.FormHeader {
0166                     title: i18n("Homescreen")
0167                 }
0168 
0169                 FormCard.FormCard {
0170                     FormCard.FormSwitchDelegate {
0171                         id: showLabelsOnHomeScreen
0172                         text: i18n("Show labels on homescreen")
0173                         checked: Folio.FolioSettings.showPagesAppLabels
0174                         onCheckedChanged: {
0175                             if (checked != Folio.FolioSettings.showPagesAppLabels) {
0176                                 Folio.FolioSettings.showPagesAppLabels = checked;
0177                             }
0178                         }
0179                     }
0180 
0181                     FormCard.FormDelegateSeparator { above: showLabelsOnHomeScreen; below: showLabelsInFavourites }
0182 
0183                     FormCard.FormSwitchDelegate {
0184                         id: showLabelsInFavourites
0185                         text: i18n("Show labels in favorites bar")
0186                         checked: Folio.FolioSettings.showFavouritesAppLabels
0187                         onCheckedChanged: {
0188                             if (checked != Folio.FolioSettings.showFavouritesAppLabels) {
0189                                 Folio.FolioSettings.showFavouritesAppLabels = checked;
0190                             }
0191                         }
0192                     }
0193 
0194                     FormCard.FormDelegateSeparator { above: showLabelsInFavourites; below: pageTransitionCombobox }
0195 
0196                     FormCard.FormComboBoxDelegate {
0197                         id: pageTransitionCombobox
0198                         text: i18n("Page transition effect")
0199 
0200                         currentIndex: indexOfValue(Folio.FolioSettings.pageTransitionEffect)
0201                         model: ListModel {
0202                             // we can't use i18n with ListElement
0203                             Component.onCompleted: {
0204                                 append({"name": i18n("Slide"), "value": Folio.FolioSettings.SlideTransition});
0205                                 append({"name": i18n("Cube"), "value": Folio.FolioSettings.CubeTransition});
0206                                 append({"name": i18n("Fade"), "value": Folio.FolioSettings.FadeTransition});
0207                                 append({"name": i18n("Stack"), "value": Folio.FolioSettings.StackTransition});
0208                                 append({"name": i18n("Rotation"), "value": Folio.FolioSettings.RotationTransition});
0209 
0210                                 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
0211                                 pageTransitionCombobox.currentIndex = pageTransitionCombobox.indexOfValue(Folio.FolioSettings.pageTransitionEffect)
0212                             }
0213                         }
0214 
0215                         textRole: "name"
0216                         valueRole: "value"
0217 
0218                         onCurrentValueChanged: Folio.FolioSettings.pageTransitionEffect = currentValue
0219                     }
0220                 }
0221 
0222                 FormCard.FormHeader {
0223                     title: i18n("Favorites Bar")
0224                 }
0225 
0226                 FormCard.FormCard {
0227                     FormCard.FormSwitchDelegate {
0228                         text: i18n('Show background')
0229                         icon.name: 'draw-rectangle'
0230                         checked: Folio.FolioSettings.showFavouritesBarBackground
0231                         onCheckedChanged: {
0232                             if (checked !== Folio.FolioSettings.showFavouritesBarBackground) {
0233                                 Folio.FolioSettings.showFavouritesBarBackground = checked;
0234                             }
0235                         }
0236                     }
0237                 }
0238 
0239                 FormCard.FormHeader {
0240                     title: i18nc("@title:group settings group", "Wallpaper")
0241                 }
0242 
0243                 FormCard.FormCard {
0244                     FormCard.FormSwitchDelegate {
0245                         id: showWallpaperBlur
0246                         text: i18nc("@option:check", "Show wallpaper blur effect")
0247                         checked: Folio.FolioSettings.showWallpaperBlur
0248                         onCheckedChanged: {
0249                             if (checked != Folio.FolioSettings.showWallpaperBlur) {
0250                                 Folio.FolioSettings.showWallpaperBlur = checked;
0251                             }
0252                         }
0253                     }
0254                 }
0255 
0256                 FormCard.FormHeader {
0257                     title: i18n("General")
0258                 }
0259 
0260                 FormCard.FormCard {
0261                     Layout.bottomMargin: Kirigami.Units.gridUnit
0262                     FormCard.FormButtonDelegate {
0263                         id: containmentSettings
0264                         text: i18nc("@action:button", "Switch between homescreens and more wallpaper options")
0265                         icon.name: 'settings-configure'
0266                         onClicked: root.requestConfigureMenu()
0267                     }
0268 
0269                     FormCard.FormDelegateSeparator { above: containmentSettings; below: exportSettings }
0270 
0271                     FormCard.FormButtonDelegate {
0272                         id: exportSettings
0273                         text: i18n('Export layout')
0274                         icon.name: 'document-export'
0275                         onClicked: exportFileDialog.open()
0276                     }
0277 
0278                     FormCard.FormDelegateSeparator { above: exportSettings; below: importSettings }
0279 
0280                     FormCard.FormButtonDelegate {
0281                         id: importSettings
0282                         text: i18n('Import layout')
0283                         icon.name: 'document-import'
0284                         onClicked: importFileDialog.open()
0285                     }
0286                 }
0287             }
0288 
0289             FileDialog {
0290                 id: exportFileDialog
0291                 title: i18n("Export layout to")
0292                 fileMode: FileDialog.SaveFile
0293                 defaultSuffix: 'json'
0294                 nameFilters: ["JSON files (*.json)"]
0295                 onAccepted: {
0296                     console.log('saving layout to ' + selectedFile);
0297                     if (selectedFile) {
0298                         let status = Folio.FolioSettings.saveLayoutToFile(selectedFile);
0299                         if (status) {
0300                             exportedSuccessfullyPrompt.open();
0301                         } else {
0302                             exportFailedPrompt.open();
0303                         }
0304                     }
0305                 }
0306             }
0307 
0308             FileDialog {
0309                 id: importFileDialog
0310                 title: i18n("Import layout from")
0311                 fileMode: FileDialog.OpenFile
0312                 nameFilters: ["JSON files (*.json)"]
0313                 onAccepted: {
0314                     console.log('about to load layout from ' + selectedFile);
0315                     confirmImportPrompt.open();
0316                 }
0317             }
0318 
0319             Kirigami.PromptDialog {
0320                 id: exportFailedPrompt
0321                 title: i18n("Export Status")
0322                 subtitle: i18n("Failed to export to %1", String(exportFileDialog.selectedFile).substring('file://'.length))
0323                 standardButtons: Kirigami.Dialog.Close
0324             }
0325 
0326             Kirigami.PromptDialog {
0327                 id: exportedSuccessfullyPrompt
0328                 title: i18n("Export Status")
0329                 subtitle: i18n("Homescreen layout exported successfully to %1", String(exportFileDialog.selectedFile).substring('file://'.length))
0330                 standardButtons: Kirigami.Dialog.Close
0331             }
0332 
0333             Kirigami.PromptDialog {
0334                 id: confirmImportPrompt
0335                 title: i18n("Confirm Import")
0336                 subtitle: i18n("This will overwrite your existing homescreen layout!")
0337                 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
0338                 onAccepted: Folio.FolioSettings.loadLayoutFromFile(importFileDialog.selectedFile);
0339             }
0340         }
0341     }
0342 }