KNewStuff

GridTileDelegate.qml
1 /*
2  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-only
6 */
7 
8 import QtQuick 2.11
9 import QtQuick.Controls 2.11 as Controls
10 import QtQuick.Templates 2.11 as T2
11 import QtQuick.Layouts 1.11
12 import QtGraphicalEffects 1.11
13 
14 import org.kde.kirigami 2.12 as Kirigami
15 
23 T2.ItemDelegate {
24  id: delegate
25 
30  property string toolTip
31 
36  property alias tile: thumbnailArea.data
37 
43  property bool thumbnailAvailable: false
44 
50  property list<QtObject> actions
51 
56  property alias actionsAnchors: actionsScope.anchors
57 
58  width: GridView.view.cellWidth
59  height: GridView.view.cellHeight
60  hoverEnabled: true
61 
62  Kirigami.ShadowedRectangle {
63  id: tile
64  anchors.centerIn: parent
65  width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit)
66  height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit)
67  radius: Kirigami.Units.smallSpacing
68  Kirigami.Theme.inherit: false
69  Kirigami.Theme.colorSet: Kirigami.Theme.View
70 
71  shadow.xOffset: 0
72  shadow.yOffset: 2
73  shadow.size: 10
74  shadow.color: Qt.rgba(0, 0, 0, 0.3)
75 
76  color: {
77  // Otherwise the first item is focused, BUG: 417843
78  // We should rethink this when fixing the keyboard navigation
79  /*if (delegate.GridView.isCurrentItem) {
80  return Kirigami.Theme.highlightColor;
81  } else */ if (parent.hovered) {
82  return Kirigami.Theme.highlightColor;
83  } else {
84  return Kirigami.Theme.backgroundColor;
85  }
86  }
87  Behavior on color {
88  ColorAnimation {
89  duration: Kirigami.Units.longDuration
90  easing.type: Easing.OutQuad
91  }
92  }
93 
94  Rectangle {
95  id: thumbnailArea
96  radius: Kirigami.Units.smallSpacing/2
97  anchors {
98  fill: parent
99  margins: Kirigami.Units.smallSpacing
100  }
101 
102  color: Kirigami.Theme.backgroundColor
103  Kirigami.Icon {
104  visible: !delegate.thumbnailAvailable
105  anchors.centerIn: parent
106  width: Kirigami.Units.iconSizes.large
107  height: width
108  source: delegate.text === i18nd("knewstuff5", "None") ? "edit-none" : "view-preview"
109  }
110  }
111 
112  Rectangle {
113  anchors.fill: thumbnailArea
114  visible: actionsColumn.children.length > 0
115  opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0
116  radius: Kirigami.Units.smallSpacing
117  color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2)
118 
119  Behavior on opacity {
120  NumberAnimation {
121  duration: Kirigami.Units.longDuration
122  easing.type: Easing.OutQuad
123  }
124  }
125 
126  FocusScope {
127  id: actionsScope
128 
129  anchors {
130  right: parent.right
131  rightMargin: Kirigami.Units.smallSpacing
132  top: parent.top
133  topMargin: Kirigami.Units.smallSpacing
134  }
135  width: actionsColumn.width
136  height: actionsColumn.height
137 
138  ColumnLayout {
139  id: actionsColumn
140 
141  Repeater {
142  model: delegate.actions
143  delegate: Controls.Button {
144  icon.name: modelData.iconName
145  text: modelData.text
146  activeFocusOnTab: focus || delegate.focus
147  onClicked: modelData.trigger()
148  enabled: modelData.enabled
149  visible: modelData.visible
150  //NOTE: there aren't any global settings where to take "official" tooltip timeouts
151  Controls.ToolTip.delay: 1000
152  Controls.ToolTip.timeout: 5000
153  Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0
154  Controls.ToolTip.text: modelData.tooltip
155  }
156  }
157  }
158  }
159  }
160  }
161 
162  Controls.ToolTip.delay: 1000
163  Controls.ToolTip.timeout: 5000
164  Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0
165  Controls.ToolTip.text: toolTip
166 }
QString & fill(QChar ch, int size)
QTextStream & right(QTextStream &s)
int length() const const
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.