Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/private/GridTileDelegate.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2015 Marco Martin <mart@kde.org> | ||||
3 | Copyright (c) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Library General Public | ||||
7 | License version 2 as published by the Free Software Foundation. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.11 | ||||
21 | import QtQuick.Controls 2.11 as Controls | ||||
22 | import QtQuick.Templates 2.11 as T2 | ||||
23 | import QtQuick.Layouts 1.11 | ||||
24 | import QtGraphicalEffects 1.11 | ||||
25 | | ||||
26 | import org.kde.kirigami 2.2 as Kirigami | ||||
27 | | ||||
28 | /** | ||||
29 | * Base delegate for KControlmodules based on Grid views of thumbnails | ||||
30 | * Use the onClicked signal handler for managing the main action when | ||||
31 | * the user clicks on the tile, modified from the original GridDelegate | ||||
32 | * from the KCM module | ||||
33 | * @inherits QtQuick.Templates.ItemDelegate | ||||
34 | */ | ||||
35 | T2.ItemDelegate { | ||||
36 | id: delegate | ||||
37 | | ||||
38 | /** | ||||
39 | * toolTip: string | ||||
40 | * string for a tooltip for the whole delegate | ||||
41 | */ | ||||
42 | property string toolTip | ||||
43 | | ||||
44 | /** | ||||
45 | * tile: Item | ||||
46 | * the item actually implementing the tile: the visualization is up to the implementation | ||||
47 | */ | ||||
48 | property alias tile: thumbnailArea.data | ||||
49 | | ||||
50 | /** | ||||
51 | * thumbnailAvailable: bool | ||||
52 | * Set it to true when a tile is actually available: when false, | ||||
53 | * a default icon will be shown instead of the actual tile. | ||||
54 | */ | ||||
55 | property bool thumbnailAvailable: false | ||||
56 | | ||||
57 | /** | ||||
58 | * actions: list<Action> | ||||
59 | * A list of extra actions for the thumbnails. They will be shown as | ||||
60 | * icons on the bottom-right corner of the tile on mouse over | ||||
61 | */ | ||||
62 | property list<QtObject> actions | ||||
63 | | ||||
64 | /** | ||||
65 | * actionsAnchors: anchors | ||||
66 | * The anchors of the actions listing | ||||
67 | */ | ||||
68 | property alias actionsAnchors: actionsScope.anchors | ||||
69 | | ||||
70 | width: GridView.view.cellWidth | ||||
71 | height: GridView.view.cellHeight | ||||
72 | hoverEnabled: true | ||||
73 | | ||||
74 | Rectangle { | ||||
75 | id: tile | ||||
76 | anchors.centerIn: parent | ||||
77 | width: Kirigami.Settings.isMobile ? delegate.width - Kirigami.Units.gridUnit : Math.min(delegate.GridView.view.implicitCellWidth, delegate.width - Kirigami.Units.gridUnit) | ||||
78 | height: Math.min(delegate.GridView.view.implicitCellHeight, delegate.height - Kirigami.Units.gridUnit) | ||||
79 | radius: Kirigami.Units.smallSpacing | ||||
80 | Kirigami.Theme.inherit: false | ||||
81 | Kirigami.Theme.colorSet: Kirigami.Theme.View | ||||
82 | | ||||
83 | color: { | ||||
84 | if (delegate.GridView.isCurrentItem) { | ||||
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 | Behavior on color { | ||||
93 | ColorAnimation { | ||||
94 | duration: Kirigami.Units.longDuration | ||||
95 | easing.type: Easing.OutQuad | ||||
96 | } | ||||
97 | } | ||||
98 | | ||||
99 | Rectangle { | ||||
100 | id: thumbnailArea | ||||
101 | radius: Kirigami.Units.smallSpacing/2 | ||||
102 | anchors { | ||||
103 | fill: parent | ||||
104 | margins: Kirigami.Units.smallSpacing | ||||
105 | } | ||||
106 | | ||||
107 | color: Kirigami.Theme.backgroundColor | ||||
108 | Kirigami.Icon { | ||||
109 | visible: !delegate.thumbnailAvailable | ||||
110 | anchors.centerIn: parent | ||||
111 | width: Kirigami.Units.iconSizes.large | ||||
112 | height: width | ||||
113 | source: delegate.text === i18n("None") ? "edit-none" : "view-preview" | ||||
114 | } | ||||
115 | } | ||||
116 | | ||||
117 | Rectangle { | ||||
118 | anchors.fill: thumbnailArea | ||||
119 | visible: actionsColumn.children.length > 0 | ||||
120 | opacity: Kirigami.Settings.isMobile || delegate.hovered || (actionsScope.focus) ? 1 : 0 | ||||
121 | radius: Kirigami.Units.smallSpacing | ||||
122 | color: Kirigami.Settings.isMobile ? "transparent" : Qt.rgba(1, 1, 1, 0.2) | ||||
123 | | ||||
124 | Behavior on opacity { | ||||
125 | NumberAnimation { | ||||
126 | duration: Kirigami.Units.longDuration | ||||
127 | easing.type: Easing.OutQuad | ||||
128 | } | ||||
129 | } | ||||
130 | | ||||
131 | FocusScope { | ||||
132 | id: actionsScope | ||||
133 | | ||||
134 | anchors { | ||||
135 | right: parent.right | ||||
136 | rightMargin: Kirigami.Units.smallSpacing | ||||
137 | top: parent.top | ||||
138 | topMargin: Kirigami.Units.smallSpacing | ||||
139 | } | ||||
140 | width: actionsColumn.width | ||||
141 | height: actionsColumn.height | ||||
142 | | ||||
143 | ColumnLayout { | ||||
144 | id: actionsColumn | ||||
145 | | ||||
146 | Repeater { | ||||
147 | model: delegate.actions | ||||
148 | delegate: Controls.Button { | ||||
149 | icon.name: modelData.iconName | ||||
150 | text: modelData.text | ||||
151 | activeFocusOnTab: focus || delegate.focus | ||||
152 | onClicked: { | ||||
153 | delegate.clicked() | ||||
154 | modelData.trigger() | ||||
155 | } | ||||
156 | enabled: modelData.enabled | ||||
157 | visible: modelData.visible | ||||
158 | //NOTE: there aren't any global settings where to take "official" tooltip timeouts | ||||
159 | Controls.ToolTip.delay: 1000 | ||||
160 | Controls.ToolTip.timeout: 5000 | ||||
161 | Controls.ToolTip.visible: (Kirigami.Settings.isMobile ? pressed : hovered) && modelData.tooltip.length > 0 | ||||
162 | Controls.ToolTip.text: modelData.tooltip | ||||
163 | } | ||||
164 | } | ||||
165 | } | ||||
166 | } | ||||
167 | } | ||||
168 | // Bug 397367: explicitly using "delegate" as otherwise it crashes when switching between KCMs | ||||
169 | layer.enabled: delegate.GraphicsInfo.api === GraphicsInfo.OpenGL | ||||
170 | layer.effect: DropShadow { | ||||
171 | horizontalOffset: 0 | ||||
172 | verticalOffset: 2 | ||||
173 | radius: 10 | ||||
174 | samples: 32 | ||||
175 | color: Qt.rgba(0, 0, 0, 0.3) | ||||
176 | } | ||||
177 | } | ||||
178 | | ||||
179 | Controls.ToolTip.delay: 1000 | ||||
180 | Controls.ToolTip.timeout: 5000 | ||||
181 | Controls.ToolTip.visible: hovered && delegate.toolTip.length > 0 | ||||
182 | Controls.ToolTip.text: toolTip | ||||
183 | } |