Changeset View
Changeset View
Standalone View
Standalone View
src/qml/ViewSelectorDelegate.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016-2019 Matthieu Gallien <matthieu_gallien@yahoo.fr> | ||||
3 | * | ||||
4 | * This program is free software: you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 3 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This program 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 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public License | ||||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | import QtQuick 2.7 | ||||
19 | import QtQuick.Controls 2.2 | ||||
20 | import QtGraphicalEffects 1.0 | ||||
21 | | ||||
22 | FocusScope { | ||||
23 | id: rootItem | ||||
24 | | ||||
25 | property var viewType: model.type | ||||
26 | property bool isSelected | ||||
27 | | ||||
28 | signal clicked() | ||||
29 | | ||||
30 | Rectangle { | ||||
31 | id: backgroundHighlight | ||||
32 | | ||||
33 | anchors.fill: parent | ||||
34 | z: 1 | ||||
35 | | ||||
36 | color: "transparent" | ||||
37 | } | ||||
38 | | ||||
39 | MouseArea { | ||||
40 | id: hoverArea | ||||
41 | | ||||
42 | anchors.fill: parent | ||||
43 | z: 2 | ||||
44 | | ||||
45 | hoverEnabled: true | ||||
46 | acceptedButtons: Qt.LeftButton | ||||
47 | | ||||
48 | onClicked: { | ||||
49 | rootItem.clicked() | ||||
50 | } | ||||
51 | | ||||
52 | Loader { | ||||
53 | id: hoverLoader | ||||
54 | | ||||
55 | anchors.fill: parent | ||||
56 | active: false | ||||
57 | | ||||
58 | sourceComponent: ToolTip { | ||||
59 | delay: Qt.styleHints.mousePressAndHoldInterval | ||||
60 | text: model.display | ||||
61 | visible: hoverArea && hoverArea.containsMouse && !nameLabel.visible | ||||
62 | | ||||
63 | contentItem: Label { | ||||
64 | text: model.display | ||||
65 | color: myPalette.highlightedText | ||||
66 | } | ||||
67 | | ||||
68 | enter: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 0.0; to: 1.0; duration: 300; } } | ||||
69 | exit: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 1.0; to: 0.0; duration: 300; } } | ||||
70 | | ||||
71 | background: Rectangle { | ||||
72 | color: myPalette.shadow | ||||
73 | radius: elisaTheme.tooltipRadius | ||||
74 | | ||||
75 | layer.enabled: true | ||||
76 | layer.effect: DropShadow { | ||||
77 | horizontalOffset: elisaTheme.shadowOffset | ||||
78 | verticalOffset: elisaTheme.shadowOffset | ||||
79 | radius: 8 | ||||
80 | samples: 17 | ||||
81 | color: myPalette.shadow | ||||
82 | } | ||||
83 | } | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
87 | Image { | ||||
88 | id: viewIcon | ||||
89 | | ||||
90 | z: 2 | ||||
91 | | ||||
92 | anchors { | ||||
93 | verticalCenter: parent.verticalCenter | ||||
94 | leftMargin: elisaTheme.layoutHorizontalMargin | ||||
95 | left: parent.left | ||||
96 | } | ||||
97 | | ||||
98 | height: elisaTheme.viewSelectorDelegateHeight | ||||
99 | width: elisaTheme.viewSelectorDelegateHeight | ||||
100 | | ||||
101 | sourceSize { | ||||
102 | width: elisaTheme.viewSelectorDelegateHeight | ||||
103 | height: elisaTheme.viewSelectorDelegateHeight | ||||
104 | } | ||||
105 | | ||||
106 | source: model.image | ||||
107 | | ||||
108 | layer.enabled: true | ||||
109 | layer.effect: ColorOverlay { | ||||
110 | color: nameLabel.color | ||||
111 | } | ||||
112 | } | ||||
113 | | ||||
114 | LabelWithToolTip { | ||||
115 | id: nameLabel | ||||
116 | | ||||
117 | z: 2 | ||||
118 | | ||||
119 | anchors.verticalCenter: parent.verticalCenter | ||||
120 | anchors.leftMargin: elisaTheme.layoutHorizontalMargin | ||||
121 | anchors.left: viewIcon.right | ||||
122 | anchors.right: parent.right | ||||
123 | anchors.rightMargin: elisaTheme.layoutHorizontalMargin | ||||
124 | verticalAlignment: "AlignVCenter" | ||||
125 | | ||||
126 | font.pointSize: Math.round(elisaTheme.defaultFontPointSize * 1.1) | ||||
127 | | ||||
128 | text: model.display | ||||
129 | elide: Text.ElideRight | ||||
130 | | ||||
131 | opacity: textOpacity | ||||
132 | visible: opacity > 0 | ||||
133 | | ||||
134 | color: (viewModeView.currentIndex === index || hoverArea.containsMouse ? myPalette.highlight : myPalette.text) | ||||
135 | } | ||||
136 | } | ||||
137 | | ||||
138 | states: [ | ||||
139 | State { | ||||
140 | name: 'notSelected' | ||||
141 | when: !rootItem.activeFocus && !hoverArea.containsMouse && !rootItem.isSelected | ||||
142 | PropertyChanges { | ||||
143 | target: hoverLoader | ||||
144 | active: false | ||||
145 | } | ||||
146 | PropertyChanges { | ||||
147 | target: hoverLoader | ||||
148 | opacity: 0.0 | ||||
149 | } | ||||
150 | PropertyChanges { | ||||
151 | target: viewIcon | ||||
152 | opacity: 1 | ||||
153 | } | ||||
154 | PropertyChanges { | ||||
155 | target: nameLabel | ||||
156 | color: myPalette.buttonText | ||||
157 | } | ||||
158 | PropertyChanges { | ||||
159 | target: backgroundHighlight | ||||
160 | color: 'transparent' | ||||
161 | } | ||||
162 | }, | ||||
163 | State { | ||||
164 | name: 'hovered' | ||||
165 | when: !rootItem.activeFocus && hoverArea.containsMouse | ||||
166 | PropertyChanges { | ||||
167 | target: hoverLoader | ||||
168 | active: true | ||||
169 | } | ||||
170 | PropertyChanges { | ||||
171 | target: hoverLoader | ||||
172 | opacity: 1.0 | ||||
173 | } | ||||
174 | PropertyChanges { | ||||
175 | target: viewIcon | ||||
176 | opacity: 0.4 | ||||
177 | } | ||||
178 | PropertyChanges { | ||||
179 | target: nameLabel | ||||
180 | color: myPalette.buttonText | ||||
181 | } | ||||
182 | PropertyChanges { | ||||
183 | target: backgroundHighlight | ||||
184 | color: Qt.rgba(myPalette.highlight.r, myPalette.highlight.g, myPalette.highlight.b, 0.2) | ||||
185 | } | ||||
186 | }, | ||||
187 | State { | ||||
188 | name: 'selected' | ||||
189 | when: !rootItem.activeFocus && rootItem.isSelected | ||||
190 | PropertyChanges { | ||||
191 | target: hoverLoader | ||||
192 | active: false | ||||
193 | } | ||||
194 | PropertyChanges { | ||||
195 | target: hoverLoader | ||||
196 | opacity: 0.0 | ||||
197 | } | ||||
198 | PropertyChanges { | ||||
199 | target: viewIcon | ||||
200 | opacity: 1 | ||||
201 | } | ||||
202 | PropertyChanges { | ||||
203 | target: nameLabel | ||||
204 | color: myPalette.buttonText | ||||
205 | } | ||||
206 | PropertyChanges { | ||||
207 | target: backgroundHighlight | ||||
208 | color: myPalette.mid | ||||
209 | } | ||||
210 | }, | ||||
211 | State { | ||||
212 | name: 'focused' | ||||
213 | when: rootItem.activeFocus | ||||
214 | PropertyChanges { | ||||
215 | target: hoverLoader | ||||
216 | active: false | ||||
217 | } | ||||
218 | PropertyChanges { | ||||
219 | target: hoverLoader | ||||
220 | opacity: 0.0 | ||||
221 | } | ||||
222 | PropertyChanges { | ||||
223 | target: viewIcon | ||||
224 | opacity: 1. | ||||
225 | } | ||||
226 | PropertyChanges { | ||||
227 | target: nameLabel | ||||
228 | color: myPalette.highlightedText | ||||
229 | } | ||||
230 | PropertyChanges { | ||||
231 | target: backgroundHighlight | ||||
232 | color: myPalette.highlight | ||||
233 | } | ||||
234 | } | ||||
235 | ] | ||||
236 | | ||||
237 | transitions: [ | ||||
238 | Transition { | ||||
239 | ParallelAnimation { | ||||
240 | NumberAnimation { | ||||
241 | properties: "opacity" | ||||
242 | easing.type: Easing.InOutQuad | ||||
243 | duration: 200 | ||||
244 | } | ||||
245 | ColorAnimation { | ||||
246 | properties: "color" | ||||
247 | duration: 250 | ||||
248 | } | ||||
249 | } | ||||
250 | } | ||||
251 | ] | ||||
252 | } |