Warning, /frameworks/knewstuff/src/qtquick/qml/private/GridTileDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 import QtQuick 2.11
0009 import QtQuick.Controls 2.11 as Controls
0010 import QtQuick.Templates 2.11 as T2
0011 import QtQuick.Layouts 1.11
0012 import QtGraphicalEffects 1.11
0013 
0014 import org.kde.kirigami 2.12 as Kirigami
0015 
0016 /**
0017  * Base delegate for KControlmodules based on Grid views of thumbnails
0018  * Use the onClicked signal handler for managing the main action when
0019  * the user clicks on the tile, modified from the original GridDelegate
0020  * from the KCM module
0021  * @inherits QtQuick.Templates.ItemDelegate
0022  */
0023 T2.ItemDelegate {
0024     id: delegate
0025 
0026     /**
0027      * toolTip: string
0028      * string for a tooltip for the whole delegate
0029      */
0030     property string toolTip
0031 
0032     /**
0033      * tile: Item
0034      * the item actually implementing the tile: the visualization is up to the implementation
0035      */
0036     property alias tile: thumbnailArea.data
0037 
0038     /**
0039      * thumbnailAvailable: bool
0040      * Set it to true when a tile is actually available: when false,
0041      * a default icon will be shown instead of the actual tile.
0042      */
0043     property bool thumbnailAvailable: false
0044 
0045     /**
0046      * actions: list<Action>
0047      * A list of extra actions for the thumbnails. They will be shown as
0048      * icons on the bottom-right corner of the tile on mouse over
0049      */
0050     property list<QtObject> actions
0051 
0052     /**
0053      * actionsAnchors: anchors
0054      * The anchors of the actions listing
0055      */
0056     property alias actionsAnchors: actionsScope.anchors
0057 
0058     width: GridView.view.cellWidth
0059     height: GridView.view.cellHeight
0060     hoverEnabled: true
0061 
0062     Kirigami.ShadowedRectangle {
0063         id: tile
0064         anchors.centerIn: parent
0065         width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
0066         height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit)
0067         radius: Kirigami.Units.smallSpacing
0068         Kirigami.Theme.inherit: false
0069         Kirigami.Theme.colorSet: Kirigami.Theme.View
0070 
0071         shadow.xOffset: 0
0072         shadow.yOffset: 2
0073         shadow.size: 10
0074         shadow.color: Qt.rgba(0, 0, 0, 0.3)
0075 
0076         color: {
0077             // Otherwise the first item is focused, BUG: 417843
0078             // We should rethink this when fixing the keyboard navigation
0079             /*if (delegate.GridView.isCurrentItem) {
0080                 return Kirigami.Theme.highlightColor;
0081             } else */ if (parent.hovered) {
0082                 // Match appearance of hovered list items
0083                 return Qt.rgba(Kirigami.Theme.highlightColor.r,
0084                                Kirigami.Theme.highlightColor.g,
0085                                Kirigami.Theme.highlightColor.b,
0086                                0.5);
0087 
0088             } else {
0089                 return Kirigami.Theme.backgroundColor;
0090             }
0091         }
0092         Behavior on color {
0093             ColorAnimation {
0094                 duration: Kirigami.Units.longDuration
0095                 easing.type: Easing.OutQuad
0096             }
0097         }
0098 
0099         Rectangle {
0100             id: thumbnailArea
0101             radius: Kirigami.Units.smallSpacing/2
0102             anchors {
0103                 fill: parent
0104                 margins: Kirigami.Units.smallSpacing
0105             }
0106 
0107             color: Kirigami.Theme.backgroundColor
0108             Kirigami.Icon {
0109                 visible: !delegate.thumbnailAvailable
0110                 anchors.centerIn: parent
0111                 width: Kirigami.Units.iconSizes.large
0112                 height: width
0113                 source: delegate.text === i18nd("knewstuff5", "None") ? "edit-none" : "view-preview"
0114             }
0115         }
0116 
0117         Rectangle {
0118             anchors.fill: thumbnailArea
0119             visible: actionsColumn.children.length > 0
0120             opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0
0121             radius: Kirigami.Units.smallSpacing
0122             color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
0123 
0124             Behavior on opacity {
0125                 NumberAnimation {
0126                     duration: Kirigami.Units.longDuration
0127                     easing.type: Easing.OutQuad
0128                 }
0129             }
0130 
0131             FocusScope {
0132                 id: actionsScope
0133 
0134                 anchors {
0135                     right: parent.right
0136                     rightMargin: Kirigami.Units.smallSpacing
0137                     top: parent.top
0138                     topMargin: Kirigami.Units.smallSpacing
0139                 }
0140                 width: actionsColumn.width
0141                 height: actionsColumn.height
0142 
0143                 ColumnLayout {
0144                     id: actionsColumn
0145 
0146                     Repeater {
0147                         model: delegate.actions
0148                         delegate: Controls.Button {
0149                             icon.name: modelData.iconName
0150                             text: modelData.text
0151                             activeFocusOnTab: focus || delegate.focus
0152                             onClicked: modelData.trigger()
0153                             enabled: modelData.enabled
0154                             visible: modelData.visible
0155                             //NOTE: there aren't any global settings where to take "official" tooltip timeouts
0156                             Controls.ToolTip.delay: 1000
0157                             Controls.ToolTip.timeout: 5000
0158                             Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
0159                             Controls.ToolTip.text: modelData.tooltip
0160                         }
0161                     }
0162                 }
0163             }
0164         }
0165     }
0166 
0167     Controls.ToolTip.delay: 1000
0168     Controls.ToolTip.timeout: 5000
0169     Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0
0170     Controls.ToolTip.text: toolTip
0171 }