Changeset View
Changeset View
Standalone View
Standalone View
kcmcontrols/GridDelegate.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2015 Marco Martin <mart@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License version 2 as published by the Free Software Foundation. | ||||
7 | | ||||
8 | This library is distributed in the hope that it will be useful, | ||||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
11 | Library General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU Library General Public License | ||||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
16 | Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | import QtQuick 2.1 | ||||
20 | import QtQuick.Layouts 1.1 | ||||
21 | import QtQuick.Controls 2.2 as Controls | ||||
22 | import QtQuick.Templates 2.2 as T2 | ||||
23 | import QtGraphicalEffects 1.0 | ||||
24 | | ||||
25 | import org.kde.kirigami 2.2 as Kirigami | ||||
26 | | ||||
27 | | ||||
28 | T2.ItemDelegate { | ||||
29 | id: delegate | ||||
30 | | ||||
31 | property string toolTip | ||||
32 | property alias thumbnail: thumbnailArea.data | ||||
33 | property list<QtObject> actions | ||||
34 | | ||||
35 | width: view.cellWidth | ||||
36 | height: view.cellHeight | ||||
37 | hoverEnabled: true | ||||
38 | | ||||
39 | Rectangle { | ||||
40 | id: thumbnail | ||||
41 | anchors { | ||||
42 | left: parent.left | ||||
43 | right: parent.right | ||||
44 | top: parent.top | ||||
45 | margins: Kirigami.Units.smallSpacing * 2 | ||||
46 | } | ||||
47 | height: width/1.6 | ||||
48 | radius: Kirigami.Units.smallSpacing | ||||
49 | Kirigami.Theme.inherit: false | ||||
50 | Kirigami.Theme.colorSet: Kirigami.Theme.View | ||||
51 | | ||||
52 | color: { | ||||
53 | if (delegate.GridView.isCurrentItem) { | ||||
54 | return Kirigami.Theme.highlightColor; | ||||
55 | } else if (parent.hovered) { | ||||
56 | return Qt.tint(Kirigami.Theme.backgroundColor, Qt.rgba(Kirigami.Theme.highlightColor.r, Kirigami.Theme.highlightColor.g, Kirigami.Theme.highlightColor.b, 0.3)) | ||||
57 | } else { | ||||
58 | return Kirigami.Theme.backgroundColor | ||||
59 | } | ||||
60 | } | ||||
61 | Behavior on color { | ||||
62 | ColorAnimation { | ||||
63 | duration: Kirigami.Units.longDuration | ||||
64 | easing.type: Easing.OutQuad | ||||
65 | } | ||||
66 | } | ||||
67 | Rectangle { | ||||
68 | id: thumbnailArea | ||||
69 | radius: Kirigami.Units.smallSpacing/2 | ||||
70 | anchors { | ||||
71 | fill: parent | ||||
72 | margins: Kirigami.Units.smallSpacing | ||||
73 | } | ||||
74 | | ||||
75 | color: Kirigami.Theme.backgroundColor | ||||
76 | } | ||||
77 | | ||||
78 | Rectangle { | ||||
79 | anchors.fill: parent | ||||
80 | visible: actionsRow.children.length > 0 | ||||
81 | opacity: delegate.hovered || (actionsScope.focus) ? 1 : 0 | ||||
82 | radius: Kirigami.Units.smallSpacing | ||||
83 | color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.4) | ||||
84 | | ||||
85 | Kirigami.Theme.inherit: false | ||||
86 | Kirigami.Theme.colorSet: Kirigami.Theme.Complementary | ||||
87 | | ||||
88 | Behavior on opacity { | ||||
89 | PropertyAnimation { | ||||
90 | duration: Kirigami.Units.longDuration | ||||
91 | easing.type: Easing.OutQuad | ||||
92 | } | ||||
93 | } | ||||
94 | | ||||
95 | FocusScope { | ||||
96 | id: actionsScope | ||||
97 | anchors { | ||||
98 | right: parent.right | ||||
99 | bottom: parent.bottom | ||||
100 | margins: Kirigami.Units.smallSpacing | ||||
101 | } | ||||
102 | width: actionsRow.width | ||||
103 | height: actionsRow.height | ||||
104 | RowLayout { | ||||
105 | id: actionsRow | ||||
106 | | ||||
107 | Repeater { | ||||
108 | model: delegate.actions | ||||
109 | delegate: Controls.ToolButton { | ||||
110 | Kirigami.Icon { | ||||
111 | anchors.centerIn: parent | ||||
112 | width: Kirigami.Units.iconSizes.smallMedium | ||||
113 | height: width | ||||
114 | source: modelData.iconName | ||||
115 | } | ||||
116 | activeFocusOnTab: focus || delegate.focus | ||||
117 | onClicked: modelData.trigger() | ||||
118 | enabled: modelData.enabled | ||||
119 | Controls.ToolTip.delay: 1000 | ||||
120 | Controls.ToolTip.timeout: 5000 | ||||
121 | Controls.ToolTip.visible: hovered | ||||
122 | Controls.ToolTip.text: modelData.tooltip | ||||
123 | } | ||||
124 | } | ||||
125 | } | ||||
126 | } | ||||
127 | } | ||||
128 | layer.enabled: true | ||||
129 | layer.effect: DropShadow { | ||||
130 | horizontalOffset: 0 | ||||
131 | verticalOffset: 2 | ||||
132 | radius: 10 | ||||
133 | samples: 32 | ||||
134 | color: Qt.rgba(0, 0, 0, 0.3) | ||||
135 | } | ||||
136 | } | ||||
137 | | ||||
138 | Controls.Label { | ||||
139 | anchors { | ||||
140 | left: parent.left | ||||
141 | right: parent.right | ||||
142 | top: thumbnail.bottom | ||||
143 | topMargin: Kirigami.Units.smallSpacing | ||||
144 | } | ||||
145 | text: delegate.text | ||||
146 | horizontalAlignment: Text.AlignHCenter | ||||
147 | elide: Text.ElideRight | ||||
148 | } | ||||
149 | Controls.ToolTip.delay: 1000 | ||||
150 | Controls.ToolTip.timeout: 5000 | ||||
151 | Controls.ToolTip.visible: hovered | ||||
152 | Controls.ToolTip.text: toolTip | ||||
153 | } |