WallpaperDelegate.qml 4.07 KB
Newer Older
1
/*
2
3
4
5
6
    SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
    SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/
7
8

import QtQuick 2.0
9
import QtQuick.Controls.Private 1.0
10
import QtQuick.Controls 2.3 as QtControls2
11
import QtGraphicalEffects 1.0
12
13
14

import org.kde.plasma.core 2.0 as PlasmaCore

15
import org.kde.kquickcontrolsaddons 2.0
16
17
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kcm 1.1 as KCM
18

19
KCM.GridDelegate {
20
21
    id: wallpaperDelegate

22
    property alias color: backgroundRect.color
23
    opacity: model.pendingDeletion ? 0.5 : 1
24
25

    text: model.display
26
    subtitle: model.author
27

28
29
    hoverEnabled: true

30
31
32
    actions: [
        Kirigami.Action {
            icon.name: "document-open-folder"
33
            tooltip: i18nd("plasma_wallpaper_org.kde.image", "Open Containing Folder")
34
            onTriggered: imageModel.openContainingFolder(index)
35
36
37
38
        },
        Kirigami.Action {
            icon.name: "edit-undo"
            visible: model.pendingDeletion
39
            tooltip: i18nd("plasma_wallpaper_org.kde.image", "Restore wallpaper")
40
            onTriggered: model.pendingDeletion = false
41
42
43
        },
        Kirigami.Action {
            icon.name: "edit-delete"
44
            tooltip: i18nd("plasma_wallpaper_org.kde.image", "Remove Wallpaper")
45
            visible: model.removable && !model.pendingDeletion && configDialog.currentWallpaper == "org.kde.image"
46
            onTriggered: {
47
48
49
50
51
                model.pendingDeletion = true;

                if (wallpapersGrid.view.currentIndex === index) {
                    const newIndex = (index + 1) % (imageModel.count - 1);
                    wallpapersGrid.view.itemAtIndex(newIndex).clicked();
52
53
                } else {
                    root.configurationChanged();
54
                }
55
            }
56
        }
57
58
59
60
61
62
63
64
65
    ]

    thumbnail: Rectangle {
        id: backgroundRect
        color: cfg_Color
        anchors.fill: parent

        QIconItem {
            anchors.centerIn: parent
66
            width: PlasmaCore.Units.iconSizes.large
67
68
69
            height: width
            icon: "view-preview"
            visible: !walliePreview.visible
70
71
        }

72
73
74
75
76
77
78
79
        QPixmapItem {
            id: blurBackgroundSource
            visible: cfg_Blur
            anchors.fill: parent
            smooth: true
            pixmap: model.screenshot
            fillMode: QPixmapItem.PreserveAspectCrop
        }
80

81
82
83
84
85
86
        FastBlur {
            visible: cfg_Blur
            anchors.fill: parent
            source: blurBackgroundSource
            radius: 4
        }
87

88
89
90
        QPixmapItem {
            id: walliePreview
            anchors.fill: parent
Laurent Montel's avatar
Laurent Montel committed
91
            visible: model.screenshot !== null
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
            smooth: true
            pixmap: model.screenshot
            fillMode: {
                if (cfg_FillMode == Image.Stretch) {
                    return QPixmapItem.Stretch;
                } else if (cfg_FillMode == Image.PreserveAspectFit) {
                    return QPixmapItem.PreserveAspectFit;
                } else if (cfg_FillMode == Image.PreserveAspectCrop) {
                    return QPixmapItem.PreserveAspectCrop;
                } else if (cfg_FillMode == Image.Tile) {
                    return QPixmapItem.Tile;
                } else if (cfg_FillMode == Image.TileVertically) {
                    return QPixmapItem.TileVertically;
                } else if (cfg_FillMode == Image.TileHorizontally) {
                    return QPixmapItem.TileHorizontally;
                }
                return QPixmapItem.PreserveAspectFit;
109
            }
110
        }
111
112
113
114
115
        QtControls2.CheckBox {
            visible: configDialog.currentWallpaper == "org.kde.slideshow"
            anchors.right: parent.right
            anchors.top: parent.top
            checked: visible ? model.checked : false
116
            onToggled: model.checked = checked
117
        }
118
119
    }

120
    onClicked: {
121
        if (configDialog.currentWallpaper == "org.kde.image") {
122
            cfg_Image = model.packageName || model.path;
123
            wallpaper.configuration.PreviewImage = cfg_Image;
124
        }
125
        GridView.currentIndex = index;
126
    }
127
}