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
99
Object storing property names used in calculations.
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"
113
Calculates the slider position based on the visible area's ratios.
115
function sliderPos(min, max) {
116
return MathUtils.clamp(styledItem.flickableItem.visibleArea[propPosRatio] * styledItem.flickableItem[propSize], min, max);
121
Calculates the slider size for ListViews based on the visible area's position
122
and size ratios, clamping it between min and max.
124
The function can be used in Scrollbar styles to calculate the size of the slider.
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
135
// overshoot adjusted start and end
136
var adjustedStartPos = startPos + overshootStart
137
var adjustedEndPos = endPos - overshootStart - overshootEnd
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)
148
The function calculates and clamps the position to be scrolled to the minimum
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.
155
function scrollAndClamp(amount, min, max) {
156
return styledItem.flickableItem[propOrigin] +
157
MathUtils.clamp(styledItem.flickableItem[propContent] - styledItem.flickableItem[propOrigin] + amount,
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.
168
function dragAndClamp(cursor, contentSize, pageSize) {
169
styledItem.flickableItem[propContent] =
170
styledItem.flickableItem[propOrigin] + cursor[propCoordinate] * contentSize / pageSize;
97
174
/*****************************************
99
176
*****************************************/
231
308
// total size of the flickable.
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)
239
316
function drag() {
240
ScrollbarUtils.dragAndClamp(styledItem, scrollCursor, contentSize, pageSize);
317
scrollbarUtils.dragAndClamp(styledItem, scrollCursor, contentSize, pageSize);
253
330
bottom: (!isVertical) ? scrollbarArea.bottom : undefined
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
262
339
Behavior on width {