KNewStuff

GridTileDelegate.qml
1/*
2 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8import QtQuick 2.11
9import QtQuick.Controls 2.11 as Controls
10import QtQuick.Templates 2.11 as T2
11import QtQuick.Layouts 1.11
12
13import org.kde.kirigami 2.12 as Kirigami
14
15/**
16 * Base delegate for KControlmodules based on Grid views of thumbnails
17 * Use the onClicked signal handler for managing the main action when
18 * the user clicks on the tile, modified from the original GridDelegate
19 * from the KCM module
20 * @inherits QtQuick.Templates.ItemDelegate
21 */
22T2.ItemDelegate {
23 id: delegate
24
25 /**
26 * toolTip: string
27 * string for a tooltip for the whole delegate
28 */
29 property string toolTip
31 /**
32 * tile: Item
33 * the item actually implementing the tile: the visualization is up to the implementation
34 */
35 property alias tile: contentArea.data
37 /**
38 * thumbnailAvailable: bool
39 * Set it to true when a tile is actually available: when false,
40 * a default icon will be shown instead of the actual tile.
41 */
42 property bool thumbnailAvailable: false
43
44 /**
45 * actions: list<Action>
46 * A list of extra actions for the thumbnails. They will be shown as
47 * icons on the bottom-right corner of the tile on mouse over
48 */
49 property list<QtObject> actions
50
51 /**
52 * actionsAnchors: anchors
53 * The anchors of the actions listing
54 */
55 property alias actionsAnchors: actionsScope.anchors
56
57 /**
58 * thumbnailArea: Item
59 * The item that will contain the thumbnail within the delegate
60 */
61 property Item thumbnailArea : contentArea
62
63 width: GridView.view.cellWidth
64 height: GridView.view.cellHeight
65 hoverEnabled: true
66
67 Kirigami.ShadowedRectangle {
68 id: tile
69 anchors.centerIn: parent
70 width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
71 height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit)
72 radius: Kirigami.Units.smallSpacing
73 Kirigami.Theme.inherit: false
74 Kirigami.Theme.colorSet: Kirigami.Theme.View
75
76 shadow.xOffset: 0
77 shadow.yOffset: 2
78 shadow.size: 10
79 shadow.color: Qt.rgba(0, 0, 0, 0.3)
80
81 color: {
82 // Otherwise the first item is focused, BUG: 417843
83 // We should rethink this when fixing the keyboard navigation
84 /*if (delegate.GridView.isCurrentItem) {
85 return Kirigami.Theme.highlightColor;
86 } else */ if (parent.hovered) {
87 // Match appearance of hovered list items
88 return Qt.rgba(Kirigami.Theme.highlightColor.r,
89 Kirigami.Theme.highlightColor.g,
90 Kirigami.Theme.highlightColor.b,
91 0.5);
92
93 } else {
94 return Kirigami.Theme.backgroundColor;
95 }
96 }
97 Behavior on color {
99 duration: Kirigami.Units.longDuration
100 easing.type: Easing.OutQuad
101 }
102 }
103
104 Rectangle {
105 id: contentArea
106 radius: Kirigami.Units.smallSpacing/2
107 anchors {
108 fill: parent
109 margins: Kirigami.Units.smallSpacing
110 }
111
112 color: Kirigami.Theme.backgroundColor
113 }
114
115 Kirigami.Icon {
116 parent: thumbnailArea
117 visible: !delegate.thumbnailAvailable
118 anchors.centerIn: parent
119 width: Kirigami.Units.iconSizes.large
120 height: width
121 source: delegate.text === i18nd("knewstuff6", "None") ? "edit-none" : "view-preview"
122 }
123
124 Rectangle {
125 anchors.fill: contentArea
126 visible: actionsColumn.children.length > 0
127 opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0
128 radius: Kirigami.Units.smallSpacing
129 color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
130
131 Behavior on opacity {
133 duration: Kirigami.Units.longDuration
134 easing.type: Easing.OutQuad
135 }
136 }
137
138 FocusScope {
139 id: actionsScope
140
141 anchors {
142 right: parent.right
143 rightMargin: Kirigami.Units.smallSpacing
144 top: parent.top
145 topMargin: Kirigami.Units.smallSpacing
146 }
147 width: actionsColumn.width
148 height: actionsColumn.height
149
150 ColumnLayout {
151 id: actionsColumn
152
153 Repeater {
154 model: delegate.actions
155 delegate: Controls.Button {
156 icon.name: modelData.iconName
157 text: modelData.text
158 activeFocusOnTab: focus || delegate.focus
159 onClicked: modelData.trigger()
160 enabled: modelData.enabled
161 visible: modelData.visible
162 //NOTE: there aren't any global settings where to take "official" tooltip timeouts
163 Controls.ToolTip.delay: 1000
164 Controls.ToolTip.timeout: 5000
165 Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
166 Controls.ToolTip.text: modelData.tooltip
167 }
168 }
169 }
170 }
171 }
172 }
173
174 Controls.ToolTip.delay: 1000
175 Controls.ToolTip.timeout: 5000
176 Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0
177 Controls.ToolTip.text: toolTip
178}
alias view
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString & fill(QChar ch, qsizetype size)
qsizetype length() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.