Warning, /plasma/plasma-workspace/wallpapers/image/imagepackage/contents/ui/ThumbnailsComponent.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de>
0004     SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 import QtQuick
0010 import QtQuick.Controls as QQC2
0011 
0012 import org.kde.kcmutils as KCM
0013 import org.kde.kirigami as Kirigami
0014 import org.kde.newstuff as NewStuff
0015 
0016 Item {
0017     id: thumbnailsComponent
0018     anchors.fill: parent
0019 
0020     property alias view: wallpapersGrid.view
0021     property var screenSize: Qt.size(Screen.width, Screen.height)
0022 
0023     readonly property QtObject imageModel: (configDialog.currentWallpaper === "org.kde.image") ? imageWallpaper.wallpaperModel : imageWallpaper.slideFilterModel
0024 
0025     Connections {
0026         target: imageWallpaper
0027         function onLoadingChanged(loading: bool) {
0028             if (loading) {
0029                 return;
0030             }
0031             if (configDialog.currentWallpaper === "org.kde.image" && imageModel.indexOf(cfg_Image) < 0) {
0032                 imageWallpaper.addUsersWallpaper(cfg_Image);
0033             }
0034             wallpapersGrid.resetCurrentIndex();
0035         }
0036     }
0037 
0038     Connections {
0039         target: root
0040         function onWallpaperBrowseCompleted() {
0041             // Scroll to top to view added images
0042             wallpapersGrid.view.positionViewAtIndex(0, GridView.Beginning);
0043             wallpapersGrid.resetCurrentIndex(); // BUG 455129
0044         }
0045     }
0046 
0047     KCM.GridView {
0048         id: wallpapersGrid
0049         anchors.fill: parent
0050 
0051         function resetCurrentIndex() {
0052             //that min is needed as the module will be populated in an async way
0053             //and only on demand so we can't ensure it already exists
0054             if (configDialog.currentWallpaper === "org.kde.image") {
0055                 wallpapersGrid.view.currentIndex = Qt.binding(() => configDialog.currentWallpaper === "org.kde.image" ?  Math.min(imageModel.indexOf(cfg_Image), imageModel.count - 1) : 0);
0056             }
0057         }
0058 
0059         // FIXME: this scrolls out of view due to the lack of a headerPositioning: property
0060         // in GridView, which is an omission; see https://bugreports.qt.io/browse/QTBUG-117035.
0061         // Once that's added, uncomment this line to fix it!
0062         // view.headerPositioning: GridView.OverlayHeader
0063         // Alternatively, make the page frameless, have the views touch the edges,
0064         // and just stick the header in a ColumnLayout with the view below it.
0065         view.header: Kirigami.InlineViewHeader {
0066             width: {
0067                 const scrollBar = wallpapersGrid.QQC2.ScrollBar.vertical;
0068                 return wallpapersGrid.width - scrollBar.width - scrollBar.leftPadding - scrollBar.rightPadding - Kirigami.Units.smallSpacing;
0069             }
0070             text: i18nd("plasma_wallpaper_org.kde.image", "Images")
0071             actions: [
0072                 Kirigami.Action {
0073                     icon.name: "insert-image-symbolic"
0074                     text: i18ndc("plasma_wallpaper_org.kde.image", "@action:button the thing being added is an image file", "Add…")
0075                     visible: configDialog.currentWallpaper == "org.kde.image"
0076                     onTriggered: root.openChooserDialog();
0077                 },
0078                 NewStuff.Action {
0079                     configFile: Kirigami.Settings.isMobile ? "wallpaper-mobile.knsrc" : "wallpaper.knsrc"
0080                     text: i18ndc("plasma_wallpaper_org.kde.image", "@action:button the new things being gotten are wallpapers", "Get New…")
0081                     viewMode: NewStuff.Page.ViewMode.Preview
0082                 }
0083             ]
0084         }
0085         //kill the space for label under thumbnails
0086         view.model: thumbnailsComponent.imageModel
0087 
0088         //set the size of the cell, depending on Screen resolution to respect the aspect ratio
0089         view.implicitCellWidth: screenSize.width / 10 + Kirigami.Units.smallSpacing * 2
0090         view.implicitCellHeight: screenSize.height / 10 + Kirigami.Units.smallSpacing * 2 + Kirigami.Units.gridUnit * 3
0091 
0092         view.reuseItems: true
0093 
0094         view.delegate: WallpaperDelegate {
0095             color: cfg_Color
0096         }
0097     }
0098 
0099     KCM.SettingHighlighter {
0100         target: wallpapersGrid
0101         highlight: configDialog.currentWallpaper === "org.kde.image" && cfg_Image != cfg_ImageDefault
0102     }
0103 }