KDeclarative

GridDelegate.qml
1 /*
2  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 import QtQuick 2.8
8 import QtQuick.Layouts 1.1
9 import QtQuick.Controls 2.2 as Controls
10 import QtQuick.Templates 2.2 as T2
11 import QtGraphicalEffects 1.0
12 
13 import org.kde.kirigami 2.12 as Kirigami
14 
21 T2.ItemDelegate {
22  id: delegate
23 
28  property string toolTip
29 
34  property string subtitle
35 
40  property alias thumbnail: thumbnailArea.data
41 
48  property bool thumbnailAvailable: false
49 
55  property list<QtObject> actions
56 
57  width: GridView.view.cellWidth
58  height: GridView.view.cellHeight
59  hoverEnabled: true
60 
61  Kirigami.ShadowedRectangle {
62  id: thumbnail
63  anchors {
64  centerIn: parent
65  verticalCenterOffset: Math.ceil(-labelLayout.height/2)
66  }
67  width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
68  height: Kirigami.Settings.isMobile ? Math.round((delegate.width - Kirigami.Units.gridUnit) / 1.6)
69  : Math.min(delegate.GridView.view.implicitCellHeight - Kirigami.Units.gridUnit * 3,
70  delegate.height - Kirigami.Units.gridUnit)
71  radius: Kirigami.Units.smallSpacing
72  Kirigami.Theme.inherit: false
73  Kirigami.Theme.colorSet: Kirigami.Theme.View
74 
75  shadow.xOffset: 0
76  shadow.yOffset: 2
77  shadow.size: 10
78  shadow.color: Qt.rgba(0, 0, 0, 0.3)
79 
80  color: {
81  if (delegate.GridView.isCurrentItem) {
82  if (delegate.GridView.view.neutralHighlight) {
83  return Kirigami.Theme.neutralTextColor;
84  }
85  return Kirigami.Theme.highlightColor;
86  } else if (parent.hovered) {
87  return Kirigami.Theme.highlightColor;
88  } else {
89  return Kirigami.Theme.backgroundColor;
90  }
91  }
92 
93  Rectangle {
94  id: thumbnailArea
95  radius: Kirigami.Units.smallSpacing/2
96  anchors {
97  fill: parent
98  margins: Kirigami.Units.smallSpacing
99  }
100 
101  color: Kirigami.Theme.backgroundColor
102  Kirigami.Icon {
103  visible: !delegate.thumbnailAvailable
104  anchors.centerIn: parent
105  width: Kirigami.Units.iconSizes.large
106  height: width
107  source: typeof pluginName === "string" && pluginName === "None" ? "edit-none" : "view-preview"
108  }
109  }
110 
111  Rectangle {
112  anchors.fill: thumbnailArea
113  visible: actionsRow.children.length > 0 && (Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus))
114  radius: delegate.thumbnailAvailable ? 0 : thumbnailArea.radius
115  color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
116 
117  FocusScope {
118  id: actionsScope
119 
120  anchors {
121  right: parent.right
122  rightMargin: Kirigami.Units.smallSpacing
123  bottom: parent.bottom
124  bottomMargin: Kirigami.Units.smallSpacing
125  }
126  width: actionsRow.width
127  height: actionsRow.height
128 
129  RowLayout {
130  id: actionsRow
131 
132  Repeater {
133  model: delegate.actions
134  delegate: Controls.Button {
135  icon.name: modelData.iconName
136  activeFocusOnTab: focus || delegate.focus
137  onClicked: modelData.trigger()
138  enabled: modelData.enabled
139  visible: modelData.visible
140  //NOTE: there aren't any global settings where to take "official" tooltip timeouts
141  Controls.ToolTip.delay: 1000
142  Controls.ToolTip.timeout: 5000
143  Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
144  Controls.ToolTip.text: modelData.tooltip
145  }
146  }
147  }
148  }
149  }
150  }
151 
152  ColumnLayout {
153  id: labelLayout
154  spacing: 0
155  anchors {
156  left: thumbnail.left
157  right: thumbnail.right
158  top: thumbnail.bottom
159  topMargin: caption.visible ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing
160  }
161 
162  // FIXME: These labels are center-aligned with a maximum width instead
163  // of the more conventional combination of "Layout.fillWidth: true"
164  // and "horizontalAlignment: Text.AlignHCenter" because that combination
165  // triggers https://bugreports.qt.io/browse/QTBUG-49646
166  Controls.Label {
167  Layout.alignment: Qt.AlignHCenter
168  Layout.maximumWidth: labelLayout.width
169  text: delegate.text
170  elide: Text.ElideRight
171  }
172  Controls.Label {
173  id: caption
174  Layout.alignment: Qt.AlignHCenter
175  Layout.maximumWidth: labelLayout.width
176  visible: delegate.subtitle.length > 0
177  opacity: 0.6
178  text: delegate.subtitle
179  font.pointSize: theme.smallestFont.pointSize
180  elide: Text.ElideRight
181  }
182  }
183 
184  Controls.ToolTip.delay: 1000
185  Controls.ToolTip.timeout: 5000
186  Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0
187  Controls.ToolTip.text: toolTip
188 }
A ScrollView containing a GridView, with the default behavior about sizing and background as recommen...
Definition: GridView.qml:19
QTextStream & left(QTextStream &s)
alias view
view: GridView Exposes the internal GridView: in order to set a model or a delegate to it...
Definition: GridView.qml:33
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.