Selector.qml 3.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import Qt 4.6

Item {
    id: selector

    property var style
    property var scrollFlickable

    signal moveScrollbarHandle(int viewportPos)

    visible: false

    property var section: null
    property var item: null
    property int sectionXOffset: 0
    property int sectionYOffset: 0

    property real staticX: (section && item)? (section.x + item.x + sectionXOffset):0;
    property real staticY: (section && item)? (section.y + style.selectionSectionOffset + item.y + sectionYOffset):0;

    property bool animateMove: true

    Connection {
        sender: itemLibraryModel
        signal: "visibilityUpdated()"
        script: selector.unselectNow()
    }

    function select(section, item, sectionXOffset, sectionYOffset) {

        if (!selector.visible) {
            selector.animateMove = false
        }

        selector.item = item
        selector.section = section
        selector.sectionXOffset = sectionXOffset
        selector.sectionYOffset = sectionYOffset

        if (!selector.visible) {
//            print("no prev selection");

//            selector.opacity = 0
            selector.visible = true
//            selectAnimation.start();
        }

        focusSelection();
    }

    function focusSelection() {
        var pos = -1;

        if (selector.staticY < scrollFlickable.viewportY)
            pos = selector.staticY
        else if ((selector.staticY + selector.height) >
                 (scrollFlickable.viewportY + scrollFlickable.height - 1))
            pos = selector.staticY + selector.height - scrollFlickable.height + 1

        if (pos >= 0) {
/*
            followSelectionAnimation.to = pos
            followSelectionAnimation.start()
*/
            scrollFlickable.viewportY = pos;
            selector.moveScrollbarHandle(pos)
        }
    }

    function unselect() {
//        unselectAnimation.start();
        unselectNow();
    }

    function unselectNow() {
        selector.section = null
        selector.item = null
        selector.sectionXOffset = 0
        selector.sectionYOffset = 0
        selector.visible = false
        selector.opacity = 1
    }
/*
    NumberAnimation {
        id: selectAnimation
        target: selector
        property: "opacity"
        from: 0
        to: 1
        duration: 200
        onRunningChanged: {
            if (!running)
                selector.animateMove = true
        }
    }

    NumberAnimation {
        id: unselectAnimation
        target: selector
        property: "opacity"
        from: 1
        to: 0
        duration: 150
        onRunningChanged: {
            if (!running)
                selector.unselectNow();
        }
    }

    NumberAnimation {
        id: followSelectionAnimation
        target: scrollFlickable
        property: "viewportY"
        duration: 200
    }

    x: SpringFollow {
        source: selector.staticX;
        spring: selector.animateMove? 3.0:0.0;
        damping: 0.35
        epsilon: 0.25
    }

    y: SpringFollow {
        source: selector.staticY;
        spring: selector.animateMove? 3.0:0.0;
        damping: 0.35
        epsilon: 0.25
    }
*/

    x: selector.staticX
    y: selector.staticY

135
136
    SystemPalette { id:systemPalette }

137
138
    Rectangle {
        anchors.fill: parent
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        color: systemPalette.highlight
        clip:true
        Rectangle {
            width:parent.width-1
            x:1
            y:-parent.height/2
            height:parent.height
            gradient: Gradient {
                GradientStop { position: 0.0; color: Qt.lighter(systemPalette.highlight) }
                GradientStop { position: 1.0; color: systemPalette.highlight }
            }
        }

        Rectangle {
            width:parent.width-1
            x:1
            y:parent.height/2
            height:parent.height
            gradient: Gradient {
                GradientStop { position: 0.0; color: systemPalette.highlight }
                GradientStop { position: 1.0; color: Qt.darker(systemPalette.highlight) }
            }
        }
162
163
164
    }
}