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 Qt5Compat.GraphicalEffects 6.0
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: contentArea.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 /**
0059 * thumbnailArea: Item
0060 * The item that will contain the thumbnail within the delegate
0061 */
0062 property Item thumbnailArea : contentArea
0063
0064 width: GridView.view.cellWidth
0065 height: GridView.view.cellHeight
0066 hoverEnabled: true
0067
0068 Kirigami.ShadowedRectangle {
0069 id: tile
0070 anchors.centerIn: parent
0071 width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
0072 height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit)
0073 radius: Kirigami.Units.smallSpacing
0074 Kirigami.Theme.inherit: false
0075 Kirigami.Theme.colorSet: Kirigami.Theme.View
0076
0077 shadow.xOffset: 0
0078 shadow.yOffset: 2
0079 shadow.size: 10
0080 shadow.color: Qt.rgba(0, 0, 0, 0.3)
0081
0082 color: {
0083 // Otherwise the first item is focused, BUG: 417843
0084 // We should rethink this when fixing the keyboard navigation
0085 /*if (delegate.GridView.isCurrentItem) {
0086 return Kirigami.Theme.highlightColor;
0087 } else */ if (parent.hovered) {
0088 // Match appearance of hovered list items
0089 return Qt.rgba(Kirigami.Theme.highlightColor.r,
0090 Kirigami.Theme.highlightColor.g,
0091 Kirigami.Theme.highlightColor.b,
0092 0.5);
0093
0094 } else {
0095 return Kirigami.Theme.backgroundColor;
0096 }
0097 }
0098 Behavior on color {
0099 ColorAnimation {
0100 duration: Kirigami.Units.longDuration
0101 easing.type: Easing.OutQuad
0102 }
0103 }
0104
0105 Rectangle {
0106 id: contentArea
0107 radius: Kirigami.Units.smallSpacing/2
0108 anchors {
0109 fill: parent
0110 margins: Kirigami.Units.smallSpacing
0111 }
0112
0113 color: Kirigami.Theme.backgroundColor
0114 }
0115
0116 Kirigami.Icon {
0117 parent: thumbnailArea
0118 visible: !delegate.thumbnailAvailable
0119 anchors.centerIn: parent
0120 width: Kirigami.Units.iconSizes.large
0121 height: width
0122 source: delegate.text === i18nd("knewstuff6", "None") ? "edit-none" : "view-preview"
0123 }
0124
0125 Rectangle {
0126 anchors.fill: contentArea
0127 visible: actionsColumn.children.length > 0
0128 opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0
0129 radius: Kirigami.Units.smallSpacing
0130 color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
0131
0132 Behavior on opacity {
0133 NumberAnimation {
0134 duration: Kirigami.Units.longDuration
0135 easing.type: Easing.OutQuad
0136 }
0137 }
0138
0139 FocusScope {
0140 id: actionsScope
0141
0142 anchors {
0143 right: parent.right
0144 rightMargin: Kirigami.Units.smallSpacing
0145 top: parent.top
0146 topMargin: Kirigami.Units.smallSpacing
0147 }
0148 width: actionsColumn.width
0149 height: actionsColumn.height
0150
0151 ColumnLayout {
0152 id: actionsColumn
0153
0154 Repeater {
0155 model: delegate.actions
0156 delegate: Controls.Button {
0157 icon.name: modelData.iconName
0158 text: modelData.text
0159 activeFocusOnTab: focus || delegate.focus
0160 onClicked: modelData.trigger()
0161 enabled: modelData.enabled
0162 visible: modelData.visible
0163 //NOTE: there aren't any global settings where to take "official" tooltip timeouts
0164 Controls.ToolTip.delay: 1000
0165 Controls.ToolTip.timeout: 5000
0166 Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
0167 Controls.ToolTip.text: modelData.tooltip
0168 }
0169 }
0170 }
0171 }
0172 }
0173 }
0174
0175 Controls.ToolTip.delay: 1000
0176 Controls.ToolTip.timeout: 5000
0177 Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0
0178 Controls.ToolTip.text: toolTip
0179 }