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
9import QtQuick.Controls as QQC2
10import QtQuick.Layouts
11import QtQuick.Templates as T
12
13import org.kde.kirigami 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 */
22T.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
71 ? delegate.width - Kirigami.Units.gridUnit
72 : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
73 height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit)
74 radius: Kirigami.Units.smallSpacing
75 Kirigami.Theme.inherit: false
76 Kirigami.Theme.colorSet: Kirigami.Theme.View
77
78 shadow.xOffset: 0
79 shadow.yOffset: 2
80 shadow.size: 10
81 shadow.color: Qt.rgba(0, 0, 0, 0.3)
82
83 color: {
84 // Otherwise the first item is focused, BUG: 417843
85 // We should rethink this when fixing the keyboard navigation
86 /*if (delegate.GridView.isCurrentItem) {
87 return Kirigami.Theme.highlightColor;
88 } else */ if (parent.hovered) {
89 // Match appearance of hovered list items
90 return Qt.alpha(Kirigami.Theme.highlightColor, 0.5);
91
92 } else {
93 return Kirigami.Theme.backgroundColor;
94 }
95 }
96 Behavior on color {
97 ColorAnimation {
98 duration: Kirigami.Units.longDuration
99 easing.type: Easing.OutQuad
100 }
101 }
102
103 Rectangle {
104 id: contentArea
105 radius: Kirigami.Units.smallSpacing/2
106 anchors {
107 fill: parent
108 margins: Kirigami.Units.smallSpacing
109 }
110
111 color: Kirigami.Theme.backgroundColor
112 }
113
114 Kirigami.Icon {
115 parent: thumbnailArea
116 visible: !delegate.thumbnailAvailable
117 anchors.centerIn: parent
118 width: Kirigami.Units.iconSizes.large
119 height: width
120 source: delegate.text === i18nd("knewstuff6", "None") ? "edit-none" : "view-preview"
121 }
122
123 Rectangle {
124 anchors.fill: contentArea
125 visible: actionsColumn.children.length > 0
126 opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0
127 radius: Kirigami.Units.smallSpacing
128 color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
129
130 Behavior on opacity {
131 NumberAnimation {
132 duration: Kirigami.Units.longDuration
133 easing.type: Easing.OutQuad
134 }
135 }
136
137 FocusScope {
138 id: actionsScope
139
140 anchors {
141 right: parent.right
142 rightMargin: Kirigami.Units.smallSpacing
143 top: parent.top
144 topMargin: Kirigami.Units.smallSpacing
145 }
146 width: actionsColumn.width
147 height: actionsColumn.height
148
149 ColumnLayout {
150 id: actionsColumn
151
152 Repeater {
153 model: delegate.actions
154 delegate: QQC2.Button {
155 icon.name: modelData.iconName
156 text: modelData.text
157 activeFocusOnTab: focus || delegate.focus
158 onClicked: modelData.trigger()
159 enabled: modelData.enabled
160 visible: modelData.visible
161 //NOTE: there aren't any global settings where to take "official" tooltip timeouts
162 QQC2.ToolTip.delay: 1000
163 QQC2.ToolTip.timeout: 5000
164 QQC2.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
165 QQC2.ToolTip.text: modelData.tooltip
166 }
167 }
168 }
169 }
170 }
171 }
172
173 QQC2.ToolTip.delay: 1000
174 QQC2.ToolTip.timeout: 5000
175 QQC2.ToolTip.visible: hovered && delegate.toolTip.length > 0
176 QQC2.ToolTip.text: toolTip
177}
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 Fri Jul 26 2024 11:56:35 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.