Warning, /plasma/kdeplasma-addons/wallpapers/potd/package/contents/ui/WallpaperDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 2.15 0009 import Qt5Compat.GraphicalEffects as GE 0010 import QtQuick.Controls 2.15 as QQC2 0011 import QtQuick.Layouts 1.15 0012 0013 import org.kde.kirigami 2.15 as Kirigami 0014 0015 FocusScope { 0016 // FocusScope can pass Tab to inline buttons 0017 id: delegate 0018 0019 readonly property int shadowOffset: thumbnail.shadow.size - thumbnail.shadow.yOffset 0020 readonly property bool isNull: wallpaperImage.status !== Image.Ready 0021 0022 /** 0023 * The background color of the preview area when the image is loaded 0024 */ 0025 property color backgroundColor 0026 0027 /** 0028 * The local path of the wallpaper 0029 */ 0030 property url localUrl 0031 0032 /** 0033 * The website of the wallpaper 0034 */ 0035 property url infoUrl 0036 0037 /** 0038 * The title of the wallpaper 0039 */ 0040 property string title 0041 0042 /** 0043 * The author of the wallpaper 0044 */ 0045 property string author 0046 0047 /** 0048 * Set it to true when a thumbnail is actually available: when false, 0049 * only an icon ("edit-none") will be shown instead of the actual thumbnail. 0050 */ 0051 property bool thumbnailAvailable: false 0052 0053 /** 0054 * Set it to true when a thumbnail is still being loaded: when false, 0055 * the BusyIndicator will be shown. 0056 */ 0057 property bool thumbnailLoading: false 0058 0059 /** 0060 * A list of extra actions for the thumbnails. They will be shown as 0061 * icons on the bottom-right corner of the thumbnail on mouse over 0062 */ 0063 property list<QtObject> actions 0064 0065 ActionContextMenu { 0066 id: contextMenu 0067 showAllActions: thumbnailAvailable 0068 actions: delegate.actions 0069 } 0070 0071 Keys.onMenuPressed: contextMenu.popup(delegate, thumbnail.x, thumbnail.y + thumbnail.height) 0072 Keys.onSpacePressed: contextMenu.popup(delegate, thumbnail.x, thumbnail.y + thumbnail.height) 0073 0074 onThumbnailLoadingChanged: { 0075 if (!thumbnailLoading) { 0076 if (wallpaperImage.source === Qt.resolvedUrl(delegate.localUrl)) { 0077 wallpaperImage.source = ""; 0078 } 0079 wallpaperImage.source = delegate.localUrl; 0080 } else { 0081 wallpaperImage.source = delegate.localUrl; 0082 } 0083 } 0084 0085 TapHandler { 0086 acceptedButtons: Qt.RightButton 0087 onTapped: contextMenu.popup() 0088 } 0089 0090 TapHandler { 0091 id: openUrlTapHandler 0092 enabled: hoverHandler.enabled 0093 acceptedButtons: Qt.LeftButton 0094 onTapped: Qt.openUrlExternally(delegate.infoUrl) 0095 } 0096 0097 HoverHandler { 0098 id: hoverHandler 0099 enabled: delegate.thumbnailAvailable && delegate.infoUrl.toString().length > 0 0100 cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor 0101 } 0102 0103 QQC2.ToolTip { 0104 text: delegate.infoUrl.toString() 0105 visible: hoverHandler.enabled && !contextMenu.opened 0106 && (hoverHandler.hovered 0107 || thumbnailArea.activeFocus 0108 || (Kirigami.Settings.isMobile && openUrlTapHandler.pressed)) 0109 } 0110 0111 // From kdeclarative/src/qmlcontrols/kcmcontrols/qml/GridDelegate.qml 0112 Kirigami.ShadowedRectangle { 0113 id: thumbnail 0114 anchors.fill: parent 0115 radius: Kirigami.Units.smallSpacing 0116 Kirigami.Theme.inherit: false 0117 Kirigami.Theme.colorSet: Kirigami.Theme.View 0118 0119 shadow.xOffset: 0 0120 shadow.yOffset: 2 0121 shadow.size: 10 0122 shadow.color: Qt.rgba(0, 0, 0, 0.3) 0123 0124 color: thumbnailArea.activeFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor 0125 0126 Rectangle { 0127 id: thumbnailArea 0128 radius: Math.round(Kirigami.Units.smallSpacing / 2) 0129 anchors { 0130 fill: parent 0131 margins: Kirigami.Units.smallSpacing 0132 } 0133 0134 color: !delegate.thumbnailAvailable || delegate.thumbnailLoading ? Kirigami.Theme.backgroundColor : delegate.backgroundColor 0135 0136 activeFocusOnTab: true 0137 Accessible.name: delegate.thumbnailAvailable ? i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis", "Today's picture") 0138 : delegate.thumbnailLoading ? i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis", "Loading") 0139 : i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis", "Unavailable") 0140 Accessible.description: delegate.thumbnailAvailable ? i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis for an image %1 title %2 author", "%1 Author: %2. Right-click on the image to see more actions.", delegate.title, delegate.author) 0141 : delegate.thumbnailLoading ? i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis", "The wallpaper is being fetched from the Internet.") 0142 : i18ndc("plasma_wallpaper_org.kde.potd", "@info:whatsthis", "Failed to fetch the wallpaper from the Internet.") 0143 0144 Image { 0145 id: wallpaperImage 0146 0147 anchors.fill: parent 0148 autoTransform: false 0149 cache: false 0150 fillMode: wallpaper.configuration.FillMode || Image.PreserveAspectCrop 0151 smooth: true 0152 0153 Drag.dragType: Drag.Automatic 0154 Drag.supportedActions: Qt.CopyAction 0155 Drag.mimeData: { 0156 "text/uri-list" : delegate.localUrl, 0157 "text/plain": delegate.title, 0158 } 0159 0160 DragHandler { 0161 id: dragHandler 0162 0163 onActiveChanged: if (active) { 0164 parent.grabToImage((result) => { 0165 parent.Drag.imageSource = result.url; 0166 parent.Drag.active = dragHandler.active; 0167 }); 0168 } else { 0169 parent.Drag.active = false; 0170 parent.Drag.imageSource = ""; 0171 } 0172 } 0173 0174 // CachedProvider will load the image from cache, but we would like to show the real loading status. 0175 layer.enabled: delegate.thumbnailLoading 0176 layer.effect: GE.HueSaturation { 0177 cached: true 0178 0179 lightness: 0.5 0180 saturation: 0.9 0181 0182 layer.enabled: true 0183 layer.effect: GE.GaussianBlur { 0184 cached: true 0185 0186 radius: 128 0187 deviation: 12 0188 samples: 63 0189 0190 transparentBorder: false 0191 } 0192 } 0193 } 0194 0195 Loader { 0196 active: delegate.thumbnailLoading || !delegate.thumbnailAvailable 0197 0198 anchors.centerIn: parent 0199 opacity: 0.5 0200 visible: active 0201 0202 width: Kirigami.Units.iconSizes.large 0203 height: width 0204 0205 sourceComponent: delegate.thumbnailLoading ? busyIndicator : fallbackIcon 0206 0207 Component { 0208 id: busyIndicator 0209 0210 QQC2.BusyIndicator { 0211 anchors.fill: parent 0212 } 0213 } 0214 0215 // "None/There's nothing here" indicator 0216 Component { 0217 id: fallbackIcon 0218 0219 Kirigami.Icon { 0220 anchors.fill: parent 0221 source: "edit-none" 0222 } 0223 } 0224 } 0225 0226 RowLayout { 0227 anchors { 0228 right: parent.right 0229 rightMargin: Kirigami.Units.smallSpacing 0230 bottom: parent.bottom 0231 bottomMargin: Kirigami.Units.smallSpacing 0232 } 0233 0234 // Always show above thumbnail content 0235 z: 9999 0236 0237 Repeater { 0238 model: delegate.actions 0239 delegate: QQC2.Button { 0240 icon.name: modelData.icon.name 0241 activeFocusOnTab: visible 0242 onClicked: modelData.trigger() 0243 enabled: modelData.enabled 0244 visible: modelData.visible 0245 0246 Accessible.name: modelData.tooltip 0247 Accessible.description: modelData.Accessible.description 0248 0249 QQC2.ToolTip { 0250 visible: modelData.tooltip.length > 0 0251 && ((Kirigami.Settings.isMobile ? parent.pressed : parent.hovered) 0252 || (parent.activeFocus && (parent.focusReason === Qt.TabFocusReason || parent.focusReason === Qt.BacktabFocusReason))) 0253 text: modelData.tooltip 0254 } 0255 } 0256 } 0257 } 0258 } 0259 } 0260 }