~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/Themes/Ambiance/1.2/ScrollbarStyle.qml

  • Committer: Zsombor Egri
  • Date: 2015-11-20 16:37:59 UTC
  • mfrom: (1662.2.62 staging)
  • Revision ID: zsombor.egri@canonical.com-20151120163759-8p94jar0o53nbu95
staging sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
    property Flickable flickableItem: styledItem.flickableItem
86
86
    property bool isScrollable: styledItem.__private.scrollable && pageSize > 0.0
87
87
                                && contentSize > 0.0 && contentSize > pageSize
88
 
    property bool isVertical: ScrollbarUtils.isVertical(styledItem)
 
88
    property bool isVertical: (styledItem.align === Qt.AlignLeading) || (styledItem.align === Qt.AlignTrailing)
89
89
    property bool frontAligned: (styledItem.align === Qt.AlignLeading)
90
90
    property bool rearAligned: (styledItem.align === Qt.AlignTrailing)
91
91
    property bool topAligned: (styledItem.align === Qt.AlignTop)
94
94
    property real pageSize: (isVertical) ? styledItem.height : styledItem.width
95
95
    property real contentSize: (isVertical) ? styledItem.flickableItem.contentHeight : styledItem.flickableItem.contentWidth
96
96
 
 
97
    /*!
 
98
      \internal
 
99
      Object storing property names used in calculations.
 
100
    */
 
101
    QtObject {
 
102
        id: scrollbarUtils
 
103
 
 
104
        property string propOrigin: (isVertical) ? "originY" : "originX"
 
105
        property string propContent: (isVertical) ? "contentY" : "contentX"
 
106
        property string propPosRatio: (isVertical) ? "yPosition" : "xPosition"
 
107
        property string propSizeRatio: (isVertical) ? "heightRatio" : "widthRatio"
 
108
        property string propCoordinate: (isVertical) ? "y" : "x"
 
109
        property string propSize: (isVertical) ? "height" : "width"
 
110
 
 
111
        /*!
 
112
          \internal
 
113
          Calculates the slider position based on the visible area's ratios.
 
114
          */
 
115
        function sliderPos(min, max) {
 
116
            return MathUtils.clamp(styledItem.flickableItem.visibleArea[propPosRatio] * styledItem.flickableItem[propSize], min, max);
 
117
        }
 
118
 
 
119
        /*!
 
120
          \internal
 
121
          Calculates the slider size for ListViews based on the visible area's position
 
122
          and size ratios, clamping it between min and max.
 
123
 
 
124
          The function can be used in Scrollbar styles to calculate the size of the slider.
 
125
          */
 
126
        function sliderSize(min, max) {
 
127
            var sizeRatio = styledItem.flickableItem.visibleArea[propSizeRatio];
 
128
            var posRatio = styledItem.flickableItem.visibleArea[propPosRatio];
 
129
            var sizeUnderflow = (sizeRatio * max) < min ? min - (sizeRatio * max) : 0
 
130
            var startPos = posRatio * (max - sizeUnderflow)
 
131
            var endPos = (posRatio + sizeRatio) * (max - sizeUnderflow) + sizeUnderflow
 
132
            var overshootStart = startPos < 0 ? -startPos : 0
 
133
            var overshootEnd = endPos > max ? endPos - max : 0
 
134
 
 
135
            // overshoot adjusted start and end
 
136
            var adjustedStartPos = startPos + overshootStart
 
137
            var adjustedEndPos = endPos - overshootStart - overshootEnd
 
138
 
 
139
            // final position and size of thumb
 
140
            var position = adjustedStartPos + min > max ? max - min : adjustedStartPos
 
141
            var result = (adjustedEndPos - position) < min ? min : (adjustedEndPos - position)
 
142
 
 
143
            return result;
 
144
        }
 
145
 
 
146
        /*!
 
147
          \internal
 
148
          The function calculates and clamps the position to be scrolled to the minimum
 
149
          and maximum values.
 
150
 
 
151
          The scroll and drag functions require a slider that does not have any minimum
 
152
          size set (meaning the minimum is set to 0.0). Implementations should consider
 
153
          using an invisible cursor to drag the slider and the ListView position.
 
154
          */
 
155
        function scrollAndClamp(amount, min, max) {
 
156
            return styledItem.flickableItem[propOrigin] +
 
157
                    MathUtils.clamp(styledItem.flickableItem[propContent] - styledItem.flickableItem[propOrigin] + amount,
 
158
                          min, max);
 
159
        }
 
160
 
 
161
        /*!
 
162
          \internal
 
163
          The function calculates the new position of the dragged slider. The amount is
 
164
          relative to the contentSize, which is either the flickable's contentHeight or
 
165
          contentWidth or other calculated value, depending on its orientation. The pageSize
 
166
          specifies the visibleArea, and it is usually the heigtht/width of the scrolling area.
 
167
          */
 
168
        function dragAndClamp(cursor, contentSize, pageSize) {
 
169
            styledItem.flickableItem[propContent] =
 
170
                    styledItem.flickableItem[propOrigin] + cursor[propCoordinate] * contentSize / pageSize;
 
171
        }
 
172
    }
 
173
 
97
174
    /*****************************************
98
175
      Visuals
99
176
     *****************************************/
231
308
    // total size of the flickable.
232
309
    Item {
233
310
        id: scrollCursor
234
 
        x: (isVertical) ? 0 : ScrollbarUtils.sliderPos(styledItem, 0.0, styledItem.width - scrollCursor.width)
235
 
        y: (!isVertical) ? 0 : ScrollbarUtils.sliderPos(styledItem, 0.0, styledItem.height - scrollCursor.height)
236
 
        width: (isVertical) ? scrollbarArea.thickness : ScrollbarUtils.sliderSize(styledItem, 0.0, flickableItem.width)
237
 
        height: (!isVertical) ? scrollbarArea.thickness : ScrollbarUtils.sliderSize(styledItem, 0.0, flickableItem.height)
 
311
        x: (isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, 0.0, styledItem.width - scrollCursor.width)
 
312
        y: (!isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, 0.0, styledItem.height - scrollCursor.height)
 
313
        width: (isVertical) ? scrollbarArea.thickness : scrollbarUtils.sliderSize(styledItem, 0.0, flickableItem.width)
 
314
        height: (!isVertical) ? scrollbarArea.thickness : scrollbarUtils.sliderSize(styledItem, 0.0, flickableItem.height)
238
315
 
239
316
        function drag() {
240
 
            ScrollbarUtils.dragAndClamp(styledItem, scrollCursor, contentSize, pageSize);
 
317
            scrollbarUtils.dragAndClamp(styledItem, scrollCursor, contentSize, pageSize);
241
318
        }
242
319
    }
243
320
 
253
330
            bottom: (!isVertical) ? scrollbarArea.bottom : undefined
254
331
        }
255
332
 
256
 
        x: (isVertical) ? 0 : ScrollbarUtils.sliderPos(styledItem, 0.0, styledItem.width - slider.width)
257
 
        y: (!isVertical) ? 0 : ScrollbarUtils.sliderPos(styledItem, 0.0, styledItem.height - slider.height)
258
 
        width: (isVertical) ? scrollbarArea.thickness : ScrollbarUtils.sliderSize(styledItem, minimumSliderSize, flickableItem.width)
259
 
        height: (!isVertical) ? scrollbarArea.thickness : ScrollbarUtils.sliderSize(styledItem, minimumSliderSize, flickableItem.height)
 
333
        x: (isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, 0.0, styledItem.width - slider.width)
 
334
        y: (!isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, 0.0, styledItem.height - slider.height)
 
335
        width: (isVertical) ? scrollbarArea.thickness : scrollbarUtils.sliderSize(styledItem, minimumSliderSize, flickableItem.width)
 
336
        height: (!isVertical) ? scrollbarArea.thickness : scrollbarUtils.sliderSize(styledItem, minimumSliderSize, flickableItem.height)
260
337
        radius: visuals.sliderRadius
261
338
 
262
339
        Behavior on width {
275
352
        }
276
353
 
277
354
        function scroll(amount) {
278
 
            scrollAnimation.to = ScrollbarUtils.scrollAndClamp(styledItem, amount, 0.0, contentSize - pageSize);
 
355
            scrollAnimation.to = scrollbarUtils.scrollAndClamp(styledItem, amount, 0.0, contentSize - pageSize);
279
356
            scrollAnimation.restart();
280
357
        }
281
358
    }