Debian Codegraph @

src/imports/Components/Themes/Ambiance/2.0/PickerDelegateStyle.qml

raw
1 /*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program 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
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components
19
20 Item {
21 property real minFade: 0.2
22 property real maxFade: 0.95
23 property bool fadingEnabled: true
24
25 property bool inListView: !!styledItem.ListView.view
26 property Item itemList: inListView ? styledItem.ListView.view : styledItem.PathView.view
27 property Item picker: styledItem.picker
28 property Item highlightItem: itemList.highlightItem
29
30 implicitHeight: picker.itemHeight
31 implicitWidth: itemList.width
32
33 Binding {
34 target: styledItem
35 when: fadingEnabled
36 property: "opacity"
37 value: opacityCalc()
38 }
39
40 function opacityCalc() {
41 if (!picker || !highlightItem || (index === itemList.currentIndex)) return 1.0;
42 var highlightY = highlightItem.y;
43 var delegateY = styledItem.y;
44 if (inListView) {
45 highlightY -= itemList.contentY;
46 delegateY -= itemList.contentY;
47 }
48 var midY = delegateY + styledItem.height / 2;
49 if (delegateY < highlightY) {
50 return MathUtils.clamp(MathUtils.projectValue(midY, 0, highlightY, minFade, maxFade), minFade, maxFade);
51 }
52 var highlightH = highlightY + highlightItem.height;
53 if (delegateY >= highlightH) {
54 delegateY -= highlightH;
55 midY = delegateY + styledItem.height / 2;
56 return MathUtils.clamp(1.0 - MathUtils.projectValue(midY, 0, highlightY, minFade, maxFade), minFade, maxFade);
57 }
58 return 1.0;
59 }
60 }