| 1 |
/* |
| 2 |
* Copyright 2015 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 QtQml 2.15 |
| 19 |
import Lomiri.Components |
| 20 |
|
| 21 |
/* |
| 22 |
The visuals handle both active and passive modes. This behavior is driven yet by |
| 23 |
the styledItem's __interactive property, however should be detected upon runtime based on |
| 24 |
the device type. |
| 25 |
On active scrollbars, positioning is handled so that the logic updates the flickable's |
| 26 |
X/Y content positions, which is then synched with the contentPosition by the main |
| 27 |
element. |
| 28 |
|
| 29 |
Style properties used: |
| 30 |
- interactive: bool - drives the interactive behavior of the scrollbar |
| 31 |
- minimumSliderSize: real - specifies the minimum size of the slider |
| 32 |
* overlay |
| 33 |
- overlay: bool - true if the scrollbar is overlay type |
| 34 |
- overlayOpacityWhenHidden: opacity when hidden |
| 35 |
- overlayOpacityWhenShown: opacity when shown |
| 36 |
* trough |
| 37 |
- troughThicknessIndicatorStyle: real - thickness of the thumb in Indicator style |
| 38 |
- troughThicknessThumbStyle: real - thickness of the thumb in Thumb style |
| 39 |
- troughThicknessSteppersStyle: real - thickness of the thumb in Steppers style |
| 40 |
- troughColorThumbStyle: color - color of the trough in Thumb style |
| 41 |
- troughColorSteppersStyle: color - color of the trough in Steppers style |
| 42 |
* slider |
| 43 |
- sliderColor: color - color for the slider |
| 44 |
- sliderRadius: real - radius of of the slider rectangle |
| 45 |
- thumbThickness: real - thickness of the slider in Thumb style |
| 46 |
- indicatorThickness: real - thickness of the slider in Indicator style |
| 47 |
* animations - where duration and easing properties are used only |
| 48 |
- scrollbarThicknessAnimation: PropertyAnimation - animation used when changing |
| 49 |
the thickness of the slider |
| 50 |
- scrollbarFadeInAnimation: PropertyAnimation - animation used when fading in |
| 51 |
- scrollbarFadeOutAnimation: PropertyAnimation - animation used when fading out |
| 52 |
- scrollbarFadeOutPause: int - milliseconds to pause before fading out |
| 53 |
- scrollbarCollapsePause: int - milliseconds to pause at the beginning of the |
| 54 |
transition from Thumb to Indicator style |
| 55 |
* scrolling UX - the values are relative to the size of the view |
| 56 |
- shortScrollingRatio: real - how much to scroll when using arrow keys and steppers |
| 57 |
- longScrollingRatio: real - how much to scroll when using PageUp/Down |
| 58 |
* other styling properties |
| 59 |
- hintingStyle: string - the style to use for the hinting feature |
| 60 |
- thumbsExtremesMargin: real - This is the top/bottom (for the vertical scrollbar) |
| 61 |
and left/right (for horiz scrollbar) margin of the slider |
| 62 |
from the trough. |
| 63 |
It is supposed to be the same margin as the one that |
| 64 |
separates the thumb from the left/right (or top/bottom |
| 65 |
for horizontal scrollbar) edges of the screen. |
| 66 |
*/ |
| 67 |
|
| 68 |
Item { |
| 69 |
id: visuals |
| 70 |
|
| 71 |
property bool initialized: false |
| 72 |
|
| 73 |
/***************************************************** |
| 74 |
* STYLING PROPERTIES * |
| 75 |
*****************************************************/ |
| 76 |
property bool interactive: isMouseConnected || veryLongContentItem |
| 77 |
property real minimumSliderSize: __canFitSteppersAndTallerThumb |
| 78 |
? __minSliderSizeWhenUnrestrictedSize |
| 79 |
: __minSliderSizeWhenRestrictedSize |
| 80 |
|
| 81 |
property bool overlay: !alwaysOnScrollbars |
| 82 |
property real overlayOpacityWhenShown: 1.0 |
| 83 |
property real overlayOpacityWhenHidden: 0.0 |
| 84 |
|
| 85 |
property real troughThicknessSteppersStyle : units.dp(14) |
| 86 |
property real troughThicknessThumbStyle : units.dp(14) |
| 87 |
property real troughThicknessIndicatorStyle : units.dp(9) |
| 88 |
property color troughColorThumbStyle: theme.palette.normal.foreground |
| 89 |
property color troughColorSteppersStyle: theme.palette.normal.foreground |
| 90 |
|
| 91 |
property color sliderColor: theme.palette.normal.overlayText |
| 92 |
|
| 93 |
//used for hover and pressed states, otherwise they're transparent in order to show the same |
| 94 |
//background as the trough |
| 95 |
property color stepperBgColor: theme.palette.normal.base |
| 96 |
property real sliderRadius: units.dp(3) |
| 97 |
property real thumbThickness: units.gu(1) |
| 98 |
property real indicatorThickness : units.dp(3) |
| 99 |
|
| 100 |
property PropertyAnimation scrollbarThicknessAnimation: LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } |
| 101 |
property PropertyAnimation scrollbarFadeInAnimation: LomiriNumberAnimation { duration: LomiriAnimation.SlowDuration } |
| 102 |
property PropertyAnimation scrollbarFadeOutAnimation: LomiriNumberAnimation { duration: LomiriAnimation.SlowDuration } |
| 103 |
property int scrollbarFadeOutPause: 3000 |
| 104 |
property int scrollbarCollapsePause: 1000 |
| 105 |
|
| 106 |
//The ratio of page to scroll when using pg_down/up |
| 107 |
//and arrow_down/up keyboard keys (and steppers) |
| 108 |
property real shortScrollingRatio: 0.1 |
| 109 |
property real longScrollingRatio: 0.9 |
| 110 |
|
| 111 |
property string hintingStyle: veryLongContentItem ? 'thumb' : 'indicator' |
| 112 |
property real thumbsExtremesMargin: units.dp(4) |
| 113 |
|
| 114 |
/***************************************************** |
| 115 |
* HELPER PROPERTIES * |
| 116 |
*****************************************************/ |
| 117 |
property alias thumb: slider |
| 118 |
property alias trough: trough |
| 119 |
|
| 120 |
//helper properties to ease code readability |
| 121 |
property bool isScrollable: styledItem.__private.scrollable && pageSize > 0.0 |
| 122 |
&& contentSize > 0.0 && totalContentSize > pageSize |
| 123 |
property bool isVertical: (styledItem.align === Qt.AlignLeading) || (styledItem.align === Qt.AlignTrailing) |
| 124 |
property bool frontAligned: (styledItem.align === Qt.AlignLeading) |
| 125 |
property bool rearAligned: (styledItem.align === Qt.AlignTrailing) |
| 126 |
property bool topAligned: (styledItem.align === Qt.AlignTop) |
| 127 |
property bool bottomAligned: (styledItem.align === Qt.AlignBottom) |
| 128 |
|
| 129 |
//flickable helper properties |
| 130 |
//Don't do anything with the flickable until its Component.onCompleted is called, it's a waste of cycles |
| 131 |
property Flickable flickableItem: styledItem.__initializedFlickable |
| 132 |
property real pageSize: flickableItem |
| 133 |
? (isVertical ? flickableItem.height : flickableItem.width) |
| 134 |
: 0 |
| 135 |
property real contentSize: flickableItem |
| 136 |
? (isVertical ? flickableItem.contentHeight : flickableItem.contentWidth) |
| 137 |
: 0 |
| 138 |
property real leadingContentMargin: flickableItem |
| 139 |
? (isVertical ? flickableItem.topMargin : flickableItem.leftMargin) |
| 140 |
: 0 |
| 141 |
property real trailingContentMargin: flickableItem |
| 142 |
? (isVertical ? flickableItem.bottomMargin : flickableItem.rightMargin) |
| 143 |
: 0 |
| 144 |
//this size includes content margins |
| 145 |
property real totalContentSize: contentSize + leadingContentMargin + trailingContentMargin |
| 146 |
|
| 147 |
|
| 148 |
/***************************************************** |
| 149 |
* INTERNAL PROPERTIES AND FUNCTIONS * |
| 150 |
*****************************************************/ |
| 151 |
|
| 152 |
//special handling of situations where we don't have enough room to show both thumb and steppers |
| 153 |
property bool __canFitSteppers: visuals[scrollbarUtils.propSize] >= 2*__idealStepperSize |
| 154 |
property bool __canFitShorterThumb: visuals[scrollbarUtils.propSize] >= (__minSliderSizeWhenRestrictedSize |
| 155 |
+ 2*thumbsExtremesMargin) |
| 156 |
property bool __canFitSteppersAndShorterThumb: visuals[scrollbarUtils.propSize] >= (2*__idealStepperSize |
| 157 |
+ __minSliderSizeWhenRestrictedSize |
| 158 |
+ 2*thumbsExtremesMargin) |
| 159 |
property bool __canFitSteppersAndTallerThumb: visuals[scrollbarUtils.propSize] >= (2*__idealStepperSize |
| 160 |
+ __minSliderSizeWhenUnrestrictedSize |
| 161 |
+ 2*thumbsExtremesMargin) |
| 162 |
|
| 163 |
//the minimum slider size for common usecases, i.e. when there is enough space to show thumb + steppers |
| 164 |
property real __minSliderSizeWhenUnrestrictedSize: 3*thumbThickness |
| 165 |
property real __minSliderSizeWhenRestrictedSize: thumbThickness |
| 166 |
|
| 167 |
property real __targetStepperSize: !__canFitSteppers |
| 168 |
? visuals[scrollbarUtils.propSize]/2 |
| 169 |
: __idealStepperSize |
| 170 |
property real __idealStepperSize: troughThicknessSteppersStyle |
| 171 |
property real __stepperImgOpacityOnPressed: 1.0 |
| 172 |
property real __stepperImgOpacityOnHover: 0.7 |
| 173 |
property real __stepperImgOpacityNormal: 0.4 |
| 174 |
property real __stepperImgOpacityDisabled: 0.2 |
| 175 |
|
| 176 |
property real __stepperBgOpacityOnPressed: 1.0 |
| 177 |
property real __stepperBgOpacityOnHover: 0.63 |
| 178 |
|
| 179 |
//the stepper arrow svg is designed to scale nicely to the lowest |
| 180 |
//px-per-GU display (i.e. 8px/GU). Please consider updating the asset if |
| 181 |
//you change this size to avoid blurry steppers on low px-per-GU displays. |
| 182 |
property real __stepperAssetWidth: units.dp(8) |
| 183 |
readonly property url __stepperSvg: Qt.resolvedUrl("../artwork/toolkit_scrollbar-stepper.svg") |
| 184 |
|
| 185 |
//UX requested to disable this feature for the moment |
| 186 |
property bool __disableDragResetFeature: true |
| 187 |
|
| 188 |
property bool __recursionGuard: false |
| 189 |
property bool __disableStateBinding: false |
| 190 |
property alias __overshootTimer: overshootTimer |
| 191 |
property bool __hinting: false |
| 192 |
property bool draggingThumb: thumbArea.drag.active || slider.mouseDragging || slider.touchDragging |
| 193 |
//this is the condition that triggers "Thumb Style" |
| 194 |
//only show the thumb if the page AND the view is moving |
| 195 |
property bool thumbStyleFlag: veryLongContentItem && (flickableItem.moving || scrollAnimation.running) |
| 196 |
//we show thumb style instead of indicator style if the content item is very long on *any* of the 2 axes |
| 197 |
property bool veryLongContentItem: flickableItem && initialized |
| 198 |
&& ((flickableItem.contentHeight > flickableItem.height * 10) |
| 199 |
|| (flickableItem.contentWidth > flickableItem.width * 10)) |
| 200 |
|
| 201 |
//this will eventually come from QInputInfo |
| 202 |
property bool isMouseConnected: true |
| 203 |
//used to offset viewport and scrollbars to make space for non-overlay scrollbars |
| 204 |
property real nonOverlayScrollbarMargin: troughThicknessSteppersStyle |
| 205 |
//TODO: move to Scrollbar.qml? |
| 206 |
property bool useSteppers: true |
| 207 |
//the thumb will have a touchDragStartMargin margin on both sides |
| 208 |
//to be more easily draggable via touch |
| 209 |
property real touchDragStartMargin: units.gu(2) |
| 210 |
//NOTE: this is not used for Qt's drag.treshold, just for our logic! |
| 211 |
property real dragThreshold: units.dp(2) |
| 212 |
//this could eventually become a system setting |
| 213 |
//True --> Steppers style, non-overlay scrollbars |
| 214 |
//False --> Indicator, Trough and Steppers styles, overlaid to the content |
| 215 |
property bool alwaysOnScrollbars: styledItem.__alwaysOnScrollbars |
| 216 |
|
| 217 |
function scrollBy(amount, animate) { |
| 218 |
if (isNaN(amount)) { |
| 219 |
console.log("BUG: Invalid scrolling delta.") |
| 220 |
return |
| 221 |
} |
| 222 |
scrollTo(scrollbarUtils.scrollAndClamp( |
| 223 |
styledItem, amount, -leadingContentMargin, |
| 224 |
Math.max(contentSize + trailingContentMargin - pageSize, |
| 225 |
-leadingContentMargin)) |
| 226 |
, animate) |
| 227 |
} |
| 228 |
function scrollTo(value, animate) { |
| 229 |
if (isNaN(value)) { |
| 230 |
console.log("BUG: Invalid scrolling value.") |
| 231 |
return |
| 232 |
} |
| 233 |
//don't setup an animation with duration 0, if we just don't want the animation |
| 234 |
if (animate) { |
| 235 |
scrollAnimation.to = value |
| 236 |
scrollAnimation.restart() |
| 237 |
} else { |
| 238 |
if (scrollAnimation.running) scrollAnimation.stop() |
| 239 |
if (flickableItem) { |
| 240 |
flickableItem[scrollbarUtils.propContent] = value |
| 241 |
flickableItem.returnToBounds() |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
function scrollToBeginning(animate) { |
| 246 |
if (!flickableItem) return |
| 247 |
scrollTo(flickableItem[scrollbarUtils.propOrigin] - visuals.leadingContentMargin, animate) |
| 248 |
} |
| 249 |
function scrollToEnd(animate) { |
| 250 |
if (!flickableItem) return |
| 251 |
scrollTo((flickableItem[scrollbarUtils.propOrigin] |
| 252 |
+ totalContentSize - visuals.leadingContentMargin - pageSize), animate) |
| 253 |
} |
| 254 |
function drag() { |
| 255 |
scrollbarUtils.dragAndClamp(styledItem, slider.relThumbPosition, totalContentSize, pageSize); |
| 256 |
} |
| 257 |
function resetScrollingToPreDrag() { |
| 258 |
thumbArea.resetFlickableToPreDragState() |
| 259 |
} |
| 260 |
//As per spec, we show a hint of the scrollbars in indicator style whenever the |
| 261 |
//flickable item changes its size |
| 262 |
//NOTE: THIS IS ASSUMING THAT the transition to hidden state has a PauseAnimation, |
| 263 |
//otherwise the hinting would be too quick! |
| 264 |
function flashScrollbar() { |
| 265 |
//only show the hint if the scrollbar is currently hidden or its already showing the hint |
| 266 |
//(it could happen that while it is showing the hint the size of the flickable changes enough |
| 267 |
//to trigger the transition to thumb style, and in that case we want to hint again using thumb |
| 268 |
//style) |
| 269 |
if (initialized && isScrollable && !draggingThumb && !pressHoldTimer.running |
| 270 |
&& (state === '' || state === 'hidden' || (__disableStateBinding && visuals.state !== hintingStyle))) { |
| 271 |
__disableStateBinding = true |
| 272 |
__hinting = true |
| 273 |
visuals.state = hintingStyle |
| 274 |
hintingTimer.restart() |
| 275 |
} |
| 276 |
} |
| 277 |
//The definition of isScrollable includes a binding on totalContentSize: |
| 278 |
//when totalContentSizeChanged triggers flashScrollbar, isScrollable may |
| 279 |
//have not been reevaluated yet using the new totalContentSize value, and |
| 280 |
//that could make the logic ignore the hinting request. |
| 281 |
//We perform the checks inside the flashScrollbar function instead of each |
| 282 |
//time before calling flashScrollbar (though this comes at slightly higher cost) |
| 283 |
onIsScrollableChanged: flashScrollbar() |
| 284 |
onTotalContentSizeChanged: flashScrollbar() |
| 285 |
onHintingStyleChanged: flashScrollbar() |
| 286 |
|
| 287 |
anchors.fill: parent |
| 288 |
opacity: overlayOpacityWhenHidden |
| 289 |
Component.onCompleted: initialized = true |
| 290 |
|
| 291 |
//we can't use onRunningChanged in the state transitions to enable the state binding again |
| 292 |
//after hinting, because that was causing |
| 293 |
//"Can't apply a state change as part of a state definition." when the state it was transitioning |
| 294 |
//to was different from the one the binding evaluationg was returning |
| 295 |
//Instead we use a timer, tune it so that it lasts as long as needed, and then we reenable the |
| 296 |
//state binding once the transition has completed |
| 297 |
Timer { |
| 298 |
id: hintingTimer |
| 299 |
repeat: false |
| 300 |
//we assume thickness animation duration is enough to complete the |
| 301 |
//transition to the hinting style |
| 302 |
interval: scrollbarThicknessAnimation.duration |
| 303 |
onTriggered: { |
| 304 |
__hinting = false |
| 305 |
__disableStateBinding = false |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
/*! |
| 310 |
\internal |
| 311 |
Object storing property names used in calculations. |
| 312 |
*/ |
| 313 |
QtObject { |
| 314 |
id: scrollbarUtils |
| 315 |
objectName: "scrollbarUtils" |
| 316 |
property string propOrigin: (isVertical) ? "originY" : "originX" |
| 317 |
property string propContent: (isVertical) ? "contentY" : "contentX" |
| 318 |
property string propPosRatio: (isVertical) ? "yPosition" : "xPosition" |
| 319 |
property string propSizeRatio: (isVertical) ? "heightRatio" : "widthRatio" |
| 320 |
property string propCoordinate: (isVertical) ? "y" : "x" |
| 321 |
property string otherPropCoordinate: (isVertical) ? "x" : "y" |
| 322 |
property string propSize: (isVertical) ? "height" : "width" |
| 323 |
property string otherPropSize: (isVertical) ? "width" : "height" |
| 324 |
property string propAtBeginning: (isVertical) ? "atYBeginning" : "atXBeginning" |
| 325 |
property string propAtEnd: (isVertical) ? "atYEnd" : "atXEnd" |
| 326 |
|
| 327 |
/*! |
| 328 |
Calculates the slider position based on the visible area's ratios. |
| 329 |
*/ |
| 330 |
function sliderPos(scrollbar, min, max) { |
| 331 |
if (!scrollbar.__initializedFlickable) return min |
| 332 |
|
| 333 |
//the margin between the trough and the thumb min and max values |
| 334 |
var margin = scrollbar.__styleInstance.thumbsExtremesMargin |
| 335 |
|
| 336 |
//The total length of the path where the thumb can be positioned, from its min to its max value |
| 337 |
var draggableLength = visuals.trough[propSize] - margin*2 |
| 338 |
var maxPosRatio = 1.0 - (scrollbar.__initializedFlickable ? scrollbar.__initializedFlickable.visibleArea[propSizeRatio] : 1.0) |
| 339 |
|
| 340 |
//Example with x/width, same applies to y/height |
| 341 |
//xPosition is in the range [0...1 - widthRatio] |
| 342 |
//and we want the following mapping (xPosition --> thumb.x): |
| 343 |
// 0 ---> margin (margin is the min position for the thumb) |
| 344 |
// 1 - widthRatio ---> (draggableLength - scrollbar.__styleInstance.thumb[propSize]) + margin |
| 345 |
//So we scale the maximum thumb position by xPosition. But that's not enough, because that would mean |
| 346 |
//the maxPosition is reached when xPosition becomes 1, and that never happens. To compensate that, we |
| 347 |
//scale xPosition by ( 1 / ( 1 - widthRatio) ). This way, when xPosition reaches its max ( 1 - widthRatio ) |
| 348 |
//we get a multiplication factor of 1 |
| 349 |
return MathUtils.clamp(1.0 / maxPosRatio * (scrollbar.__initializedFlickable ? scrollbar.__initializedFlickable.visibleArea[propPosRatio] : 1.0) |
| 350 |
* (draggableLength - scrollbar.__styleInstance.thumb[propSize]) + margin, min, max); |
| 351 |
} |
| 352 |
|
| 353 |
/*! |
| 354 |
Calculates the slider size for ListViews based on the visible area's position |
| 355 |
and size ratios, clamping it between min and max. |
| 356 |
|
| 357 |
The function can be used in Scrollbar styles to calculate the size of the slider. |
| 358 |
|
| 359 |
NOTE: THIS CODE IS ASSUMING THAT "MAX" IS ALSO THE "SIZE" OF THE TROUGH THAT THE |
| 360 |
THUMB CAN MOVE INTO! (which is what you want in 99.9% of the cases, for a scrollbar) |
| 361 |
*/ |
| 362 |
function sliderSize(scrollbar, min, max) { |
| 363 |
if (!scrollbar.__initializedFlickable) return min |
| 364 |
|
| 365 |
var sizeRatio = scrollbar.__initializedFlickable ? scrollbar.__initializedFlickable.visibleArea[propSizeRatio] : 1.0; |
| 366 |
var posRatio = scrollbar.__initializedFlickable ? scrollbar.__initializedFlickable.visibleArea[propPosRatio] : 0.0; |
| 367 |
|
| 368 |
//(sizeRatio * max) is the current ideal size, as recommended by Flickable visibleArea props |
| 369 |
var sizeUnderflow = (sizeRatio * max) < min ? min - (sizeRatio * max) : 0 |
| 370 |
|
| 371 |
//we multiply by (max - sizeUndeflow) because we want to simulate a shorter trough. This is because |
| 372 |
//posRatio value is [0...1-sizeRatio] so it assumes the slider will be of size sizeRatio*size_of_the_trough |
| 373 |
//(because that's the only way to make the slider fill the remaining part of the trough when posRatio is |
| 374 |
//at its maximum value), while our slider could actually be bigger due to the imposed "min" value. |
| 375 |
//We will compensate for this shift by adding sizeUnderflow to endPos. |
| 376 |
var startPos = posRatio * (max - sizeUnderflow) |
| 377 |
var endPos = (posRatio + sizeRatio) * (max - sizeUnderflow) + sizeUnderflow |
| 378 |
var overshootStart = startPos < 0 ? -startPos : 0 |
| 379 |
var overshootEnd = endPos > max ? endPos - max : 0 |
| 380 |
|
| 381 |
// overshoot adjusted start and end |
| 382 |
var adjustedStartPos = startPos + overshootStart |
| 383 |
var adjustedEndPos = endPos - overshootStart - overshootEnd |
| 384 |
|
| 385 |
// final position and size of slider |
| 386 |
var position = adjustedStartPos + min > max ? max - min : adjustedStartPos |
| 387 |
var result = (adjustedEndPos - position) < min ? min : (adjustedEndPos - position) |
| 388 |
|
| 389 |
return result; |
| 390 |
} |
| 391 |
|
| 392 |
/*! |
| 393 |
The function calculates and clamps the position to be scrolled to the minimum |
| 394 |
and maximum values. |
| 395 |
|
| 396 |
The scroll and drag functions require a slider that does not have any minimum |
| 397 |
size set (meaning the minimum is set to 0.0). Implementations should consider |
| 398 |
using an invisible cursor to drag the slider and the ListView position. |
| 399 |
*/ |
| 400 |
function scrollAndClamp(scrollbar, amount, min, max) { |
| 401 |
if (!scrollbar.__initializedFlickable) return |
| 402 |
|
| 403 |
return scrollbar.__initializedFlickable[propOrigin] + |
| 404 |
MathUtils.clamp(scrollbar.__initializedFlickable[propContent] |
| 405 |
- scrollbar.__initializedFlickable[propOrigin] + amount, |
| 406 |
min, max); |
| 407 |
} |
| 408 |
|
| 409 |
/*! |
| 410 |
The function calculates the new position of the dragged slider. The amount is |
| 411 |
relative to the contentSize, which is either the flickable's contentHeight or |
| 412 |
contentWidth or other calculated value, depending on its orientation. The pageSize |
| 413 |
specifies the visibleArea, and it is usually the heigtht/width of the scrolling area. |
| 414 |
|
| 415 |
//FIXME: should we change the API and remove pageSize or just pass trough's size as pageSize par? |
| 416 |
|
| 417 |
NOTE: when flickable.topMargin is 5GU, contentY has to be -5GU (not 0!) to be at the top of the scrollable!! |
| 418 |
*/ |
| 419 |
function dragAndClamp(scrollbar, relThumbPosition, contentSize, pageSize) { |
| 420 |
if (!scrollbar.__initializedFlickable) return |
| 421 |
|
| 422 |
scrollbar.__initializedFlickable[propContent] = |
| 423 |
scrollbar.__initializedFlickable[propOrigin] + relThumbPosition * (contentSize - scrollbar.__initializedFlickable[propSize]) - leadingContentMargin; //don't use pageSize, we don't know if the scrollbar is edge to edge!; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
//each scrollbar connects to both width and height because |
| 428 |
//we want to show both the scrollbar in both cases |
| 429 |
Connections { |
| 430 |
target: (flickableItem && initialized) ? flickableItem : null |
| 431 |
function onHeightChanged() { flashScrollbar() } |
| 432 |
function onWidthChanged() { flashScrollbar() } |
| 433 |
//Use onTotalContentSizeChanged instead of binding to contentWidth/Height changes |
| 434 |
//to trigger the scrollbar hinting when the scrollable content is resized |
| 435 |
} |
| 436 |
|
| 437 |
SmoothedAnimation { |
| 438 |
id: scrollAnimation |
| 439 |
objectName: "scrollAnimation" |
| 440 |
|
| 441 |
//duration and easing coming from UX spec |
| 442 |
duration: LomiriAnimation.SlowDuration |
| 443 |
easing.type: Easing.InOutCubic |
| 444 |
target: flickableItem |
| 445 |
property: scrollbarUtils.propContent |
| 446 |
//when the listview has variable size delegates the contentHeight estimation done by ListView |
| 447 |
//could make us overshoot, especially when going from top to bottom of the list or viceversa. |
| 448 |
//We call returnToBounds to mitigate that. |
| 449 |
onRunningChanged: if (!running && flickableItem) { |
| 450 |
flickableItem.returnToBounds() |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
// The thumb appears whenever the mouse gets close enough to the scrollbar |
| 456 |
// and disappears after being for a long enough time far enough of it |
| 457 |
MouseArea { |
| 458 |
id: proximityArea |
| 459 |
|
| 460 |
//like containsMouse, but unlike it this property is not true when the user |
| 461 |
//taps on the area using touchscreen |
| 462 |
property bool containsMouseDevice: false |
| 463 |
|
| 464 |
anchors.fill: parent |
| 465 |
propagateComposedEvents: true |
| 466 |
preventStealing: false |
| 467 |
enabled: isScrollable && interactive |
| 468 |
hoverEnabled: isScrollable && interactive |
| 469 |
Mouse.ignoreSynthesizedEvents: true |
| 470 |
Mouse.onEntered: { |
| 471 |
isMouseConnected = true |
| 472 |
proximityArea.containsMouseDevice = true |
| 473 |
} |
| 474 |
Mouse.onExited: { |
| 475 |
overshootTimer.restart(); |
| 476 |
proximityArea.containsMouseDevice = false |
| 477 |
} |
| 478 |
onPressed: function(mouse) { mouse.accepted = false } |
| 479 |
|
| 480 |
Timer { |
| 481 |
id: overshootTimer |
| 482 |
interval: scrollbarThicknessAnimation.duration * 10 |
| 483 |
} |
| 484 |
|
| 485 |
// represents the visible area of the scrollbar where |
| 486 |
//slider and thumb connector are placed |
| 487 |
Rectangle { |
| 488 |
id: background |
| 489 |
anchors.fill: flowContainer |
| 490 |
objectName: "background" |
| 491 |
visible: flowContainer.showBackground |
| 492 |
} |
| 493 |
|
| 494 |
Flow { |
| 495 |
id: flowContainer |
| 496 |
property bool showSteppers: false |
| 497 |
property bool showBackground: false |
| 498 |
property bool showCornerRect: false |
| 499 |
//thickness of trough and thumb |
| 500 |
property real thickness: 0 |
| 501 |
property real thumbThickness: 0 |
| 502 |
|
| 503 |
property real proximityThickness: (isVertical) ? styledItem.width - thickness |
| 504 |
: styledItem.height - thickness |
| 505 |
anchors { |
| 506 |
fill: parent |
| 507 |
leftMargin: (!isVertical || frontAligned) ? 0.0 : flowContainer.proximityThickness |
| 508 |
rightMargin: (!isVertical || rearAligned) ? 0.0 : flowContainer.proximityThickness |
| 509 |
topMargin: (isVertical || topAligned) ? 0.0 : flowContainer.proximityThickness |
| 510 |
bottomMargin: (isVertical || bottomAligned) ? 0.0 : flowContainer.proximityThickness |
| 511 |
} |
| 512 |
clip: true |
| 513 |
flow: (isVertical) ? Flow.TopToBottom : Flow.LeftToRight |
| 514 |
|
| 515 |
Item { |
| 516 |
id: trough |
| 517 |
//account for 2 steppers at the end of the scrollbar |
| 518 |
width: isVertical ? parent.width |
| 519 |
: parent.width - steppersMouseArea.width |
| 520 |
height: isVertical ? parent.height - steppersMouseArea.height |
| 521 |
: parent.height |
| 522 |
objectName: "trough" |
| 523 |
|
| 524 |
Rectangle { |
| 525 |
id: slider |
| 526 |
objectName: "interactiveScrollbarThumb" |
| 527 |
|
| 528 |
//this property is true if the user could be starting a drag (i.e. pressed inside the thumb) |
| 529 |
//but drag.active is not true yet (because that requires dragging >0 pixels) |
| 530 |
//Usecase: thumb is at the top, user drags towards the top and |
| 531 |
//goes out of window -> drag.active won't trigger because the thumb can't move by even 1px, |
| 532 |
//but we still want the logic to know that user could be trying to drag (by moving the |
| 533 |
//mouse down again afterwards, for example) |
| 534 |
// |
| 535 |
//NOTE: starting a drag while the scrollbars are in steppers mode is considered a mouse drag |
| 536 |
//(because we want the style to stay to steppers) even when started with touch! |
| 537 |
property bool mouseDragging: false |
| 538 |
property bool touchDragging: false |
| 539 |
|
| 540 |
//the proportional position of the thumb relative to the trough it can move into |
| 541 |
//It is 0 when the thumb is at its minimum value, and 1 when it is at its maximum value |
| 542 |
property real relThumbPosition : isVertical |
| 543 |
? (slider.y - thumbsExtremesMargin) / (trough.height - 2*thumbsExtremesMargin - slider.height) |
| 544 |
: (slider.x - thumbsExtremesMargin) / (trough.width - 2*thumbsExtremesMargin - slider.width) |
| 545 |
|
| 546 |
//we just need to call this onPressed, so we shouldn't use a binding for it, which would get |
| 547 |
//reevaluated any time one of the properties changes. |
| 548 |
//+ having it as a binding has the sideeffect that when we query its value from inside onPressed |
| 549 |
//it may not be using the most up-to-date value for *all* the variables it uses, and that would |
| 550 |
//break the logic |
| 551 |
function containsTouch() { |
| 552 |
var touchX = slider.mapFromItem(thumbArea, thumbArea.mouseX, thumbArea.mouseY).x |
| 553 |
var touchY = slider.mapFromItem(thumbArea, thumbArea.mouseX, thumbArea.mouseY).y |
| 554 |
//relaxed checks on the position of the touch, to allow some error |
| 555 |
if (touchX >= -visuals.touchDragStartMargin |
| 556 |
&& touchX <= slider.width + visuals.touchDragStartMargin |
| 557 |
&& touchY >= -visuals.touchDragStartMargin |
| 558 |
&& touchY <= slider.height + visuals.touchDragStartMargin) { |
| 559 |
return true |
| 560 |
} else { |
| 561 |
return false |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
anchors { |
| 566 |
verticalCenter: (isVertical) ? undefined : trough.verticalCenter |
| 567 |
horizontalCenter: (isVertical) ? trough.horizontalCenter : undefined |
| 568 |
} |
| 569 |
x: (isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, thumbsExtremesMargin, trough.width - slider.width - thumbsExtremesMargin) |
| 570 |
y: (!isVertical) ? 0 : scrollbarUtils.sliderPos(styledItem, thumbsExtremesMargin, trough.height - slider.height - thumbsExtremesMargin) |
| 571 |
radius: visuals.sliderRadius |
| 572 |
color: Qt.rgba(sliderColor.r, sliderColor.g, sliderColor.b, |
| 573 |
sliderColor.a * (visuals.draggingThumb |
| 574 |
? 1.0 |
| 575 |
: (thumbArea.hoveringThumb ? 0.7 : 0.4 ))) |
| 576 |
|
| 577 |
//visible: HANDLED BY STATES |
| 578 |
|
| 579 |
//This is to stop the scrollbar from changing size while being dragged when we have listviews |
| 580 |
//with delegates of variable size (in those cases, contentWidth/height changes as the user scrolls |
| 581 |
//because of the way ListView estimates the size of the out-of-views delegates |
| 582 |
//and that would trigger resizing of the thumb) |
| 583 |
//NOTE: otoh, we want the x/y binding to apply (even though it will cause a small flickering occasionally) |
| 584 |
//even while dragging, because that guarantees the view is at the top when the user drags to the top |
| 585 |
Binding { |
| 586 |
when: !visuals.draggingThumb |
| 587 |
target: slider |
| 588 |
property: "width" |
| 589 |
value: (isVertical) ? flowContainer.thumbThickness |
| 590 |
: scrollbarUtils.sliderSize(styledItem, visuals.minimumSliderSize, trough.width - 2 * thumbsExtremesMargin) |
| 591 |
restoreMode: Binding.RestoreNone |
| 592 |
} |
| 593 |
Binding { |
| 594 |
when: !visuals.draggingThumb |
| 595 |
target: slider |
| 596 |
property: "height" |
| 597 |
value: (!isVertical) ? flowContainer.thumbThickness |
| 598 |
: scrollbarUtils.sliderSize(styledItem, visuals.minimumSliderSize, trough.height - 2 * thumbsExtremesMargin) |
| 599 |
restoreMode: Binding.RestoreNone |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
//we reuse the MouseArea for touch interactions as well, because MultiTouchPointArea |
| 604 |
//can't propagate touch events underneath, if not consumed |
| 605 |
//(it would also require implementing drag as it doesn't have it) |
| 606 |
MouseArea { |
| 607 |
id: thumbArea |
| 608 |
objectName: "thumbArea" |
| 609 |
|
| 610 |
property real originXAtDragStart: 0 |
| 611 |
property real originYAtDragStart: 0 |
| 612 |
property real contentXAtDragStart: 0 |
| 613 |
property real contentYAtDragStart: 0 |
| 614 |
|
| 615 |
//cache input device position in order to ignore mouse/touch |
| 616 |
//moves which are shorter than a threshold. This is needed due |
| 617 |
//to the low precision of some touchscreen devices, to avoid |
| 618 |
//shaking the view while slowly dragging via touch |
| 619 |
property real previousX: 0 |
| 620 |
property real previousY: 0 |
| 621 |
|
| 622 |
|
| 623 |
//THIS BEHAVIOUR IS CURRENTLY DISABLED, SEE __disableDragResetFeature |
| 624 |
//following UX spec, if during a drag the mouse goes far away from the scrollbar |
| 625 |
//we want to temporarily lock the drag and reset the scrollbar to where it was when |
| 626 |
//the drag started, WITHOUT losing the drag (if the mouse gets back within the distance |
| 627 |
//threshold, the drag has to resum without the need to release and pressHold again) |
| 628 |
property bool lockDrag: false |
| 629 |
|
| 630 |
property bool hoveringThumb: false |
| 631 |
|
| 632 |
function initDrag(isMouse) { |
| 633 |
__disableStateBinding = true |
| 634 |
thumbArea.saveFlickableScrollingState() |
| 635 |
if (isMouse) { |
| 636 |
slider.mouseDragging = true |
| 637 |
visuals.state = "steppers" |
| 638 |
} else { |
| 639 |
slider.touchDragging = true |
| 640 |
visuals.state = "thumb" |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
function resetDrag() { |
| 645 |
if (thumbArea.lockDrag) thumbArea.lockDrag = false |
| 646 |
slider.mouseDragging = false |
| 647 |
slider.touchDragging = false |
| 648 |
__disableStateBinding = false |
| 649 |
} |
| 650 |
|
| 651 |
function handlePress(mouseX, mouseY) { |
| 652 |
if (!thumbArea.pressed) return |
| 653 |
|
| 654 |
var mouseScrollingProp = isVertical ? mouseY : mouseX |
| 655 |
if (mouseScrollingProp < slider[scrollbarUtils.propCoordinate]) { |
| 656 |
scrollBy(-pageSize*visuals.longScrollingRatio, true) |
| 657 |
} else if (mouseScrollingProp > slider[scrollbarUtils.propCoordinate] + slider[scrollbarUtils.propSize]) { |
| 658 |
scrollBy(pageSize*visuals.longScrollingRatio, true) |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
//we consider hover if it's inside the TROUGH along the scrolling axis |
| 663 |
//and inside the THUMB along the non-scrolling axis |
| 664 |
//NOTE: mouseX and mouseY are assumed to be relative to thumbArea |
| 665 |
function handleHover(mouseX, mouseY) { |
| 666 |
//NOTE: we're assuming thumbArea has same size/position as the trough. |
| 667 |
//Use mapToItem to map the coordinates if that assumption falls (i.e. to implement |
| 668 |
//a larger touch detection area around the thumb) |
| 669 |
var mouseScrollingProp = isVertical ? mouseY : mouseX |
| 670 |
var otherProp = isVertical ? mouseX : mouseY |
| 671 |
|
| 672 |
//don't count as hover if the user is already press-and-holding |
| 673 |
//the trough to scroll page by page |
| 674 |
hoveringThumb = !(pressHoldTimer.running && pressHoldTimer.startedBy === thumbArea) |
| 675 |
&& mouseScrollingProp >= slider[scrollbarUtils.propCoordinate] && |
| 676 |
mouseScrollingProp <= slider[scrollbarUtils.propCoordinate] + slider[scrollbarUtils.propSize] && |
| 677 |
otherProp >= 0 && otherProp <= trough[scrollbarUtils.otherPropSize] |
| 678 |
} |
| 679 |
|
| 680 |
function saveFlickableScrollingState() { |
| 681 |
originXAtDragStart = flickableItem.originX |
| 682 |
originYAtDragStart = flickableItem.originY |
| 683 |
contentXAtDragStart = flickableItem.contentX |
| 684 |
contentYAtDragStart = flickableItem.contentY |
| 685 |
} |
| 686 |
|
| 687 |
function resetFlickableToPreDragState() { |
| 688 |
//NOTE: when dealing with ListViews which have |
| 689 |
//delegates that are highly variable in size originX/Y and contentWidth/Height |
| 690 |
//change based on "out-of-view delegates" size estimation done by ListView. |
| 691 |
//In that case, we can't do anything to bring back the view to where it was |
| 692 |
//when the drag started, so we'd better not do anything instead of doing something |
| 693 |
//which we're sure will be wrong |
| 694 |
if (originXAtDragStart !== flickableItem.originX |
| 695 |
|| originYAtDragStart !== flickableItem.originY) { |
| 696 |
return |
| 697 |
} |
| 698 |
flickableItem.contentX = contentXAtDragStart |
| 699 |
flickableItem.contentY = contentYAtDragStart |
| 700 |
} |
| 701 |
|
| 702 |
function cacheMousePosition(mouse) { |
| 703 |
previousX = mouse.x |
| 704 |
previousY = mouse.y |
| 705 |
} |
| 706 |
|
| 707 |
//NOTE: remember to update the handleHover check if you add anchor margins |
| 708 |
anchors.fill: trough |
| 709 |
|
| 710 |
enabled: isScrollable && interactive && __canFitSteppersAndShorterThumb |
| 711 |
onPressed: function(mouse){ |
| 712 |
cacheMousePosition(mouse) |
| 713 |
//potentially we allow using touch to trigger mouse interactions, in case the |
| 714 |
//mouse has previously hovered over the area and activated the steppers style |
| 715 |
//checking for the value of visuals.state wouldn't be useful here, the value could be |
| 716 |
//"hidden" even if the values have only just started transitioning from "steppers" state |
| 717 |
|
| 718 |
if (firstStepper.visible) { |
| 719 |
var mouseScrollingProp = isVertical ? mouseY : mouseX |
| 720 |
//don't start the press and hold timer to avoid conflicts with the drag |
| 721 |
if (mouseScrollingProp < slider[scrollbarUtils.propCoordinate] || |
| 722 |
mouseScrollingProp > (slider[scrollbarUtils.propCoordinate] + slider[scrollbarUtils.propSize])) { |
| 723 |
handlePress(mouseX, mouseY) |
| 724 |
pressHoldTimer.startTimer(thumbArea) |
| 725 |
} else { |
| 726 |
//we can't tell whether the drag is started from mouse or touch |
| 727 |
//(unless we add an additional multipointtoucharea and reimplement drag |
| 728 |
//but MPTArea can't ignore touch events so we wouldn't be able to propagate those) |
| 729 |
//so we assume that it's a mouse drag if the mouse is within the proximity area |
| 730 |
//when the mouse is dragged |
| 731 |
initDrag(true) |
| 732 |
} |
| 733 |
} else if (visuals.veryLongContentItem && slider.containsTouch()) { |
| 734 |
initDrag(false) |
| 735 |
} else { |
| 736 |
//propagate otherwise |
| 737 |
mouse.accepted = false |
| 738 |
} |
| 739 |
} |
| 740 |
onPositionChanged: function(mouse) { |
| 741 |
//avoid shaking the view when the user is draggin via touch |
| 742 |
if (Math.abs(mouse.x - previousX) < visuals.dragThreshold |
| 743 |
&& Math.abs(mouse.y - previousY) < visuals.dragThreshold) { |
| 744 |
return |
| 745 |
} |
| 746 |
cacheMousePosition(mouse) |
| 747 |
|
| 748 |
if (pressedButtons === Qt.LeftButton && (slider.mouseDragging || slider.touchDragging)) { |
| 749 |
if (!__disableDragResetFeature && |
| 750 |
((isVertical && Math.abs(mouse.x - thumbArea.x) >= flowContainer.thickness * 10) |
| 751 |
|| (!isVertical && Math.abs(mouse.y - thumbArea.y) >= flowContainer.thickness * 10))) { |
| 752 |
//don't reset it if the user is already scrolling the view (via keyboard or similar) |
| 753 |
if (!scrollAnimation.running) { |
| 754 |
resetFlickableToPreDragState() |
| 755 |
thumbArea.lockDrag = true |
| 756 |
} |
| 757 |
} else { |
| 758 |
//don't clash with scrolling animation |
| 759 |
if (scrollAnimation.running) scrollAnimation.stop() |
| 760 |
|
| 761 |
if (thumbArea.lockDrag) thumbArea.lockDrag = false |
| 762 |
visuals.drag() |
| 763 |
} |
| 764 |
} |
| 765 |
} |
| 766 |
onCanceled: { |
| 767 |
hoveringThumb = false |
| 768 |
resetDrag() |
| 769 |
pressHoldTimer.stop() |
| 770 |
} |
| 771 |
onReleased: function(mouse) { |
| 772 |
//don't call handleHover here as touch release also triggers this handler |
| 773 |
//see bug #1616868 |
| 774 |
resetDrag() |
| 775 |
pressHoldTimer.stop() |
| 776 |
} |
| 777 |
drag { |
| 778 |
//don't start a drag while we're scrolling using press and hold |
| 779 |
target: pressHoldTimer.running ? undefined : slider |
| 780 |
axis: (isVertical) ? Drag.YAxis : Drag.XAxis |
| 781 |
minimumY: lockDrag ? slider.y : thumbsExtremesMargin |
| 782 |
maximumY: lockDrag ? slider.y : trough.height - slider.height - thumbsExtremesMargin |
| 783 |
minimumX: lockDrag ? slider.x : thumbsExtremesMargin |
| 784 |
maximumX: lockDrag ? slider.x : trough.width - slider.width - thumbsExtremesMargin |
| 785 |
onActiveChanged: { |
| 786 |
if (drag.active) { |
| 787 |
//drag.active is true only when the target has been moved by >0 pixels (if threshold == 0) |
| 788 |
//that means if the bar is at the top and user drags it upwards, drag.active won't change, |
| 789 |
//but the user will still be able to leave the app window from above, move mouse to the left (or right) |
| 790 |
//enough to trigger the drag lock logic, and then come back in the window and move downwards. |
| 791 |
//At *that* point drag.active will become true, but we don't want to actually drag the thumb |
| 792 |
//because the mouse is still outside the area where thumb is follow input device movements |
| 793 |
if (!lockDrag) { |
| 794 |
visuals.drag() |
| 795 |
} |
| 796 |
} else { |
| 797 |
resetDrag() |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
//NOTE: we need threshold to be 0, otherwise it will be |
| 802 |
//impossible to drag contentItems which have a size so that |
| 803 |
//"flickableItem.height - contentItem.height < threshold"!!! |
| 804 |
threshold: 0 |
| 805 |
} |
| 806 |
|
| 807 |
//logic to support different colour on hovering |
| 808 |
hoverEnabled: true |
| 809 |
//This means this mouse filter will only handle real mouse events! |
| 810 |
//i.e. the synthesized mouse events created when you use |
| 811 |
//touchscreen will not trigger it! This way we can have logic that |
| 812 |
//will not trigger when using touch |
| 813 |
Mouse.ignoreSynthesizedEvents: true |
| 814 |
Mouse.enabled: true |
| 815 |
Mouse.onEntered: function(event) { |
| 816 |
hoveringThumb = false |
| 817 |
handleHover(event.x, event.y) |
| 818 |
} |
| 819 |
Mouse.onPositionChanged: function(mouse) { |
| 820 |
//We need to update the hover state also onPosChanged because this area |
| 821 |
//covers the whole trough, not just the thumb, so entered/exited are not enough |
| 822 |
//e.g. when mouse moves from inside the thumb to inside the trough, or when you |
| 823 |
//click on the trough and the thumb scrolls and goes under the mouse cursor |
| 824 |
handleHover(mouse.x, mouse.y) |
| 825 |
} |
| 826 |
Mouse.onExited: { |
| 827 |
hoveringThumb = false |
| 828 |
} |
| 829 |
Mouse.onReleased: function(mouse) { |
| 830 |
handleHover(mouse.x, mouse.y) |
| 831 |
} |
| 832 |
|
| 833 |
Timer { |
| 834 |
id: pressHoldTimer |
| 835 |
|
| 836 |
//This var is needed to reuse the same timer to handle |
| 837 |
//both thumb and steppers press-and-hold |
| 838 |
//NOTE: the item MUST provide a handlePress method |
| 839 |
property MouseArea startedBy |
| 840 |
property bool firstTrigger: true |
| 841 |
|
| 842 |
function startTimer(item) { |
| 843 |
startedBy = item |
| 844 |
start() |
| 845 |
} |
| 846 |
|
| 847 |
interval: firstTrigger ? 500 : 250 |
| 848 |
onTriggered: { |
| 849 |
if (firstTrigger) firstTrigger = false |
| 850 |
if (startedBy !== undefined) { |
| 851 |
startedBy.handlePress(startedBy.mouseX, startedBy.mouseY) |
| 852 |
} else { |
| 853 |
console.log("Congrats, you have just found a bug! Press and hold timer is running without knowing the item that started it. Please report this.") |
| 854 |
} |
| 855 |
} |
| 856 |
repeat: true |
| 857 |
onRunningChanged: { |
| 858 |
if (!running) { |
| 859 |
firstTrigger = true |
| 860 |
} |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
MouseArea { |
| 867 |
id: steppersMouseArea |
| 868 |
objectName: "steppersMouseArea" |
| 869 |
//size is handled by the states |
| 870 |
|
| 871 |
property bool hoveringFirstStepper: false |
| 872 |
property bool hoveringSecondStepper: false |
| 873 |
|
| 874 |
function handlePress() { |
| 875 |
var mappedCoordFirstStepper = mapToItem(firstStepper, mouseX, mouseY) |
| 876 |
var mappedCoordSecondStepper = mapToItem(secondStepper, mouseX, mouseY) |
| 877 |
|
| 878 |
if (firstStepper.contains(Qt.point(mappedCoordFirstStepper.x, mappedCoordFirstStepper.y))) { |
| 879 |
scrollBy(-pageSize * visuals.shortScrollingRatio, true) |
| 880 |
} else if (secondStepper.contains(Qt.point(mappedCoordSecondStepper.x, mappedCoordSecondStepper.y))) { |
| 881 |
scrollBy(pageSize * visuals.shortScrollingRatio, true) |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
function handleHover(event) { |
| 886 |
var mappedCoordFirstStepper = mapToItem(firstStepper, event.x, event.y) |
| 887 |
var mappedCoordSecondStepper = mapToItem(secondStepper, event.x, event.y) |
| 888 |
|
| 889 |
if (firstStepper.contains(Qt.point(mappedCoordFirstStepper.x, mappedCoordFirstStepper.y))) { |
| 890 |
hoveringFirstStepper = true |
| 891 |
hoveringSecondStepper = false |
| 892 |
} else if (secondStepper.contains(Qt.point(mappedCoordSecondStepper.x, mappedCoordSecondStepper.y))) { |
| 893 |
hoveringFirstStepper = false |
| 894 |
hoveringSecondStepper = true |
| 895 |
} else { |
| 896 |
hoveringFirstStepper = false |
| 897 |
hoveringSecondStepper = false |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
enabled: isScrollable && interactive |
| 902 |
visible: flowContainer.showSteppers |
| 903 |
|
| 904 |
preventStealing: true |
| 905 |
//Logic that handles hovering on steppers |
| 906 |
hoverEnabled: true |
| 907 |
Mouse.enabled: true |
| 908 |
Mouse.ignoreSynthesizedEvents: true |
| 909 |
Mouse.onEntered: function(event) { |
| 910 |
hoveringFirstStepper = false |
| 911 |
hoveringSecondStepper = false |
| 912 |
handleHover(event) |
| 913 |
} |
| 914 |
Mouse.onPositionChanged: function(mouse) { |
| 915 |
handleHover(mouse) |
| 916 |
} |
| 917 |
Mouse.onExited: { |
| 918 |
hoveringFirstStepper = false |
| 919 |
hoveringSecondStepper = false |
| 920 |
} |
| 921 |
Mouse.onPressed: function(mouse) { |
| 922 |
//This additional trigger of the hovering logic is useful especially in testing |
| 923 |
//environments, where simulating a click on the first stepper will generate onEntered, |
| 924 |
//but then clicking on the second one (without a mouseMove) won't, because they're |
| 925 |
//handled by the same mouse area, which is already hovered. With this trigger |
| 926 |
//we ensure that the hovering logic is correct even when there are no mouse moves between |
| 927 |
//clicks on different steppers (like it happens in tst_actionSteppers test). |
| 928 |
handleHover(mouse) |
| 929 |
} |
| 930 |
Mouse.onReleased: function(mouse) { |
| 931 |
handleHover(mouse) |
| 932 |
} |
| 933 |
|
| 934 |
//We don't change the size of the images because we let the image reader figure the size out, |
| 935 |
//though that means we have to hide the images somehow while the mousearea is visible but has |
| 936 |
//null size. We choose to enable clipping here instead of creating bindings on images' visible prop |
| 937 |
clip: true |
| 938 |
onPressed: { |
| 939 |
handlePress() |
| 940 |
pressHoldTimer.startTimer(steppersMouseArea) |
| 941 |
} |
| 942 |
onReleased: pressHoldTimer.stop() |
| 943 |
onCanceled: pressHoldTimer.stop() |
| 944 |
|
| 945 |
Rectangle { |
| 946 |
id: firstStepper |
| 947 |
objectName: "firstStepper" |
| 948 |
anchors { |
| 949 |
//it's left in both cases, otherwise using RTL |
| 950 |
//would break the layout of the arrow |
| 951 |
left: parent ? parent.left : undefined |
| 952 |
right: isVertical ? (parent ? parent.right : undefined) : undefined |
| 953 |
top: parent ? parent.top : undefined |
| 954 |
bottom: !isVertical ? (parent ? parent.bottom : undefined) : undefined |
| 955 |
} |
| 956 |
color: (steppersMouseArea.hoveringFirstStepper && flickableItem && !flickableItem[scrollbarUtils.propAtBeginning]) |
| 957 |
? Qt.rgba(stepperBgColor.r, stepperBgColor.g, stepperBgColor.b, |
| 958 |
stepperBgColor.a * (steppersMouseArea.pressed ? __stepperBgOpacityOnPressed : __stepperBgOpacityOnHover)) |
| 959 |
: "transparent" |
| 960 |
visible: parent.visible |
| 961 |
clip: true |
| 962 |
|
| 963 |
Binding { |
| 964 |
target: firstStepper |
| 965 |
property: "height" |
| 966 |
when: isVertical |
| 967 |
value: visible ? __targetStepperSize : 0 |
| 968 |
} |
| 969 |
Binding { |
| 970 |
target: firstStepper |
| 971 |
property: "width" |
| 972 |
when: !isVertical |
| 973 |
value: visible ? __targetStepperSize : 0 |
| 974 |
} |
| 975 |
Icon { |
| 976 |
objectName: "firstStepperIcon" |
| 977 |
anchors.centerIn: parent |
| 978 |
width: __stepperAssetWidth |
| 979 |
rotation: isVertical ? 180 : 90 |
| 980 |
source: visible ? __stepperSvg : "" |
| 981 |
asynchronous: true |
| 982 |
color: Qt.rgba(sliderColor.r, sliderColor.g, sliderColor.b, |
| 983 |
sliderColor.a * ((flickableItem && flickableItem[scrollbarUtils.propAtBeginning]) |
| 984 |
? __stepperImgOpacityDisabled |
| 985 |
: (steppersMouseArea.hoveringFirstStepper |
| 986 |
? (steppersMouseArea.pressed ? __stepperImgOpacityOnPressed : __stepperImgOpacityOnHover) |
| 987 |
: __stepperImgOpacityNormal))) |
| 988 |
} |
| 989 |
} |
| 990 |
Rectangle { |
| 991 |
id: secondStepper |
| 992 |
objectName: "secondStepper" |
| 993 |
anchors { |
| 994 |
left: isVertical ? parent.left : firstStepper.right |
| 995 |
right: isVertical ? parent.right : undefined |
| 996 |
top: !isVertical ? parent.top : firstStepper.bottom |
| 997 |
bottom: !isVertical ? parent.bottom : undefined |
| 998 |
} |
| 999 |
color: (steppersMouseArea.hoveringSecondStepper && flickableItem && !flickableItem[scrollbarUtils.propAtEnd]) |
| 1000 |
? Qt.rgba(stepperBgColor.r, stepperBgColor.g, stepperBgColor.b, |
| 1001 |
stepperBgColor.a * (steppersMouseArea.pressed ? __stepperBgOpacityOnPressed : __stepperBgOpacityOnHover)) |
| 1002 |
: "transparent" |
| 1003 |
clip: true |
| 1004 |
visible: parent.visible |
| 1005 |
|
| 1006 |
Binding { |
| 1007 |
target: secondStepper |
| 1008 |
property: "height" |
| 1009 |
when: isVertical |
| 1010 |
value: visible ? __targetStepperSize : 0 |
| 1011 |
} |
| 1012 |
Binding { |
| 1013 |
target: secondStepper |
| 1014 |
property: "width" |
| 1015 |
when: !isVertical |
| 1016 |
value: visible ? __targetStepperSize : 0 |
| 1017 |
} |
| 1018 |
Icon { |
| 1019 |
id: icon |
| 1020 |
objectName: "secondStepperIcon" |
| 1021 |
anchors.centerIn: parent |
| 1022 |
width: __stepperAssetWidth |
| 1023 |
rotation: isVertical ? 0 : -90 |
| 1024 |
source: visible ? __stepperSvg : "" |
| 1025 |
asynchronous: true |
| 1026 |
color: Qt.rgba(sliderColor.r, sliderColor.g, sliderColor.b, |
| 1027 |
sliderColor.a * ((flickableItem && flickableItem[scrollbarUtils.propAtEnd]) |
| 1028 |
? __stepperImgOpacityDisabled |
| 1029 |
: (steppersMouseArea.hoveringSecondStepper |
| 1030 |
? (steppersMouseArea.pressed ? __stepperImgOpacityOnPressed : __stepperImgOpacityOnHover) |
| 1031 |
: __stepperImgOpacityNormal))) |
| 1032 |
} |
| 1033 |
} |
| 1034 |
} |
| 1035 |
} |
| 1036 |
|
| 1037 |
//just a hack: a rectangle which covers the corner where scrollbars meet, when they're in steppers style |
| 1038 |
Rectangle { |
| 1039 |
id: cornerRect |
| 1040 |
//NOTE: I tried grouping styledItem.__buddyScrollbar && styledItem.__buddyScrollbar.__styleInstance |
| 1041 |
// && styledItem.__buddyScrollbar.__styleInstance.isScrollable in 1 property and use that for |
| 1042 |
//all the anchors, but it turned out it makes the instantiation 2-3% slower!!! |
| 1043 |
anchors.left: { |
| 1044 |
if (styledItem.__buddyScrollbar && styledItem.__buddyScrollbar.__styleInstance |
| 1045 |
&& styledItem.__buddyScrollbar.__styleInstance.isScrollable) { |
| 1046 |
if (isVertical) { |
| 1047 |
return flowContainer.left |
| 1048 |
} else { |
| 1049 |
if (styledItem.__buddyScrollbar.align === Qt.AlignTrailing) { |
| 1050 |
return flowContainer.right |
| 1051 |
} else |
| 1052 |
return undefined |
| 1053 |
} |
| 1054 |
} |
| 1055 |
} |
| 1056 |
anchors.right: { |
| 1057 |
if (styledItem.__buddyScrollbar && styledItem.__buddyScrollbar.__styleInstance |
| 1058 |
&& styledItem.__buddyScrollbar.__styleInstance.isScrollable) { |
| 1059 |
if (isVertical) { |
| 1060 |
return flowContainer.right |
| 1061 |
} else { |
| 1062 |
if (styledItem.__buddyScrollbar.align === Qt.AlignLeading) { |
| 1063 |
return flowContainer.left |
| 1064 |
} else { |
| 1065 |
return undefined |
| 1066 |
} |
| 1067 |
} |
| 1068 |
} |
| 1069 |
} |
| 1070 |
anchors.top: { |
| 1071 |
if (styledItem.__buddyScrollbar && styledItem.__buddyScrollbar.__styleInstance |
| 1072 |
&& styledItem.__buddyScrollbar.__styleInstance.isScrollable) { |
| 1073 |
if (isVertical) { |
| 1074 |
if (styledItem.__buddyScrollbar.align === Qt.AlignBottom) { |
| 1075 |
return flowContainer.bottom |
| 1076 |
} else { |
| 1077 |
return undefined |
| 1078 |
} |
| 1079 |
} else { |
| 1080 |
return undefined |
| 1081 |
} |
| 1082 |
} |
| 1083 |
} |
| 1084 |
anchors.bottom: { |
| 1085 |
if (styledItem.__buddyScrollbar && styledItem.__buddyScrollbar.__styleInstance |
| 1086 |
&& styledItem.__buddyScrollbar.__styleInstance.isScrollable) { |
| 1087 |
if (isVertical) { |
| 1088 |
if (styledItem.__buddyScrollbar.align === Qt.AlignTop) { |
| 1089 |
return flowContainer.top |
| 1090 |
} else { |
| 1091 |
return undefined |
| 1092 |
} |
| 1093 |
} else { |
| 1094 |
return flowContainer.bottom |
| 1095 |
} |
| 1096 |
} |
| 1097 |
} |
| 1098 |
//REMEMBER: the thickness animates during state changes, |
| 1099 |
//so we want to bind the right side to the thickness of the scrollbar |
| 1100 |
width: isVertical ? flowContainer.thickness : troughThicknessSteppersStyle |
| 1101 |
height: isVertical ? troughThicknessSteppersStyle : flowContainer.thickness |
| 1102 |
color: background.color |
| 1103 |
visible: flowContainer.showCornerRect |
| 1104 |
&& styledItem.__buddyScrollbar |
| 1105 |
&& styledItem.__buddyScrollbar.__styleInstance.isScrollable |
| 1106 |
} |
| 1107 |
} |
| 1108 |
|
| 1109 |
Binding { |
| 1110 |
when: !__disableStateBinding |
| 1111 |
target: visuals |
| 1112 |
property: 'state' |
| 1113 |
restoreMode: Binding.RestoreNone |
| 1114 |
value: { |
| 1115 |
if (!isScrollable && !alwaysOnScrollbars) { |
| 1116 |
return ''; |
| 1117 |
} |
| 1118 |
else if (overlay) { |
| 1119 |
//we use the check on running to avoid to make it so that the scrollbar completes the transition |
| 1120 |
//to the steppers (or thumb) state even when the mouse exits the area prematurely (e.g. when the mouse |
| 1121 |
//overshoots, without the .running check the scrollbar would stop the growing transition halfway and |
| 1122 |
//go back to hidden mode) |
| 1123 |
// NOTE: we use steppersMouseArea.pressed to keep steppers state even when the user presses on the steppers |
| 1124 |
// then holds and moves the pointer outside the window (probably by mistake) without releasing |
| 1125 |
if (proximityArea.containsMouseDevice || steppersMouseArea.pressed |
| 1126 |
//if the user is press-and-holding on the trough to scroll page by page |
| 1127 |
|| (pressHoldTimer.running && pressHoldTimer.startedBy === thumbArea) |
| 1128 |
|| (draggingThumb && slider.mouseDragging) || __overshootTimer.running) { |
| 1129 |
return 'steppers' |
| 1130 |
} else if (thumbStyleFlag |
| 1131 |
|| (draggingThumb && slider.touchDragging) || __overshootTimer.running) { |
| 1132 |
return 'thumb' |
| 1133 |
} else if ((flickableItem && flickableItem.moving) || scrollAnimation.running || transitionToIndicator.running) { |
| 1134 |
return 'indicator'; |
| 1135 |
} else return 'hidden'; |
| 1136 |
} else { |
| 1137 |
return 'steppers' |
| 1138 |
} |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
states: [ |
| 1143 |
State { |
| 1144 |
name: 'hidden' |
| 1145 |
extend: '' |
| 1146 |
PropertyChanges { |
| 1147 |
target: visuals |
| 1148 |
opacity: overlayOpacityWhenHidden |
| 1149 |
} |
| 1150 |
}, |
| 1151 |
State { |
| 1152 |
name: 'shown' |
| 1153 |
PropertyChanges { |
| 1154 |
target: visuals |
| 1155 |
opacity: overlayOpacityWhenShown |
| 1156 |
} |
| 1157 |
PropertyChanges { |
| 1158 |
target: slider |
| 1159 |
visible: __canFitShorterThumb |
| 1160 |
} |
| 1161 |
}, |
| 1162 |
State { |
| 1163 |
name: 'indicator' |
| 1164 |
extend: 'shown' |
| 1165 |
PropertyChanges { |
| 1166 |
target: flowContainer |
| 1167 |
thickness: troughThicknessIndicatorStyle |
| 1168 |
thumbThickness: indicatorThickness |
| 1169 |
showSteppers: false |
| 1170 |
showBackground: alwaysOnScrollbars |
| 1171 |
showCornerRect: false |
| 1172 |
} |
| 1173 |
PropertyChanges { |
| 1174 |
target: steppersMouseArea |
| 1175 |
width: 0 |
| 1176 |
height: 0 |
| 1177 |
} |
| 1178 |
PropertyChanges { |
| 1179 |
target: background |
| 1180 |
color: Qt.rgba(troughColorThumbStyle.r, |
| 1181 |
troughColorThumbStyle.g, |
| 1182 |
troughColorThumbStyle.b, |
| 1183 |
troughColorThumbStyle.a * 0.2) |
| 1184 |
} |
| 1185 |
}, |
| 1186 |
State { |
| 1187 |
name: 'thumb' |
| 1188 |
extend: 'shown' |
| 1189 |
PropertyChanges { |
| 1190 |
target: flowContainer |
| 1191 |
thickness: visuals.troughThicknessThumbStyle |
| 1192 |
thumbThickness: visuals.thumbThickness |
| 1193 |
showSteppers: false |
| 1194 |
showBackground: alwaysOnScrollbars |
| 1195 |
showCornerRect: false |
| 1196 |
} |
| 1197 |
PropertyChanges { |
| 1198 |
target: steppersMouseArea |
| 1199 |
width: 0 |
| 1200 |
height: 0 |
| 1201 |
} |
| 1202 |
PropertyChanges { |
| 1203 |
target: background |
| 1204 |
color: Qt.rgba(troughColorThumbStyle.r, |
| 1205 |
troughColorThumbStyle.g, |
| 1206 |
troughColorThumbStyle.b, |
| 1207 |
troughColorThumbStyle.a * 0.2) |
| 1208 |
} |
| 1209 |
}, |
| 1210 |
State { |
| 1211 |
name: 'steppers' |
| 1212 |
extend: 'shown' |
| 1213 |
PropertyChanges { |
| 1214 |
target: flowContainer |
| 1215 |
thickness: visuals.troughThicknessSteppersStyle |
| 1216 |
thumbThickness: visuals.thumbThickness |
| 1217 |
showSteppers: visuals.useSteppers |
| 1218 |
showBackground: true |
| 1219 |
showCornerRect: true |
| 1220 |
} |
| 1221 |
PropertyChanges { |
| 1222 |
target: steppersMouseArea |
| 1223 |
width: isVertical ? flowContainer.width |
| 1224 |
: (firstStepper.visible ? firstStepper.width : 0) |
| 1225 |
+ (secondStepper.visible ? secondStepper.width : 0) |
| 1226 |
height: isVertical ? (firstStepper.visible ? firstStepper.height : 0) |
| 1227 |
+ (secondStepper.visible ? secondStepper.height : 0) |
| 1228 |
: trough.height |
| 1229 |
} |
| 1230 |
PropertyChanges { |
| 1231 |
target: background |
| 1232 |
color: Qt.rgba(troughColorSteppersStyle.r, |
| 1233 |
troughColorSteppersStyle.g, |
| 1234 |
troughColorSteppersStyle.b, |
| 1235 |
troughColorSteppersStyle.a * 0.9) |
| 1236 |
} |
| 1237 |
PropertyChanges { |
| 1238 |
target: slider |
| 1239 |
visible: __canFitSteppersAndShorterThumb |
| 1240 |
} |
| 1241 |
} |
| 1242 |
] |
| 1243 |
transitions: [ |
| 1244 |
Transition { |
| 1245 |
from: '' |
| 1246 |
to: 'shown' |
| 1247 |
NumberAnimation { |
| 1248 |
target: visuals |
| 1249 |
property: "opacity" |
| 1250 |
duration: scrollbarFadeInAnimation.duration |
| 1251 |
easing: scrollbarFadeInAnimation.easing |
| 1252 |
} |
| 1253 |
}, |
| 1254 |
Transition { |
| 1255 |
from: 'thumb,steppers' |
| 1256 |
to: 'indicator' |
| 1257 |
id: collapsingTransition |
| 1258 |
SequentialAnimation { |
| 1259 |
//don't pause the animation if we're showing the *hint* and the hintingStyle changes from |
| 1260 |
//thumb/steppers to indicator |
| 1261 |
PauseAnimation { id: scrollbarCollapseAnim; duration: __disableStateBinding ? 0 : scrollbarCollapsePause } |
| 1262 |
PropertyAction { |
| 1263 |
target: steppersMouseArea |
| 1264 |
properties: isVertical ? "width" : "height" |
| 1265 |
} |
| 1266 |
ParallelAnimation { |
| 1267 |
NumberAnimation { |
| 1268 |
target: flowContainer |
| 1269 |
properties: "thickness,thumbThickness" |
| 1270 |
duration: scrollbarThicknessAnimation.duration |
| 1271 |
easing: scrollbarThicknessAnimation.easing |
| 1272 |
} |
| 1273 |
NumberAnimation { |
| 1274 |
target: steppersMouseArea |
| 1275 |
properties: isVertical ? "height" : "width" |
| 1276 |
duration: scrollbarThicknessAnimation.duration |
| 1277 |
easing: scrollbarThicknessAnimation.easing |
| 1278 |
} |
| 1279 |
ColorAnimation { target: background; duration: scrollbarThicknessAnimation.duration } |
| 1280 |
} |
| 1281 |
PropertyAction { |
| 1282 |
target: flowContainer |
| 1283 |
properties: "showSteppers,showBackground,showCornerRect" |
| 1284 |
} |
| 1285 |
PropertyAction { |
| 1286 |
target: slider |
| 1287 |
properties: "visible" |
| 1288 |
} |
| 1289 |
} |
| 1290 |
}, |
| 1291 |
Transition { |
| 1292 |
id: transitionToIndicator |
| 1293 |
from: '*' |
| 1294 |
to: 'indicator' |
| 1295 |
SequentialAnimation { |
| 1296 |
ParallelAnimation { |
| 1297 |
NumberAnimation { |
| 1298 |
target: visuals |
| 1299 |
property: "opacity" |
| 1300 |
duration: scrollbarThicknessAnimation.duration |
| 1301 |
easing: scrollbarThicknessAnimation.easing |
| 1302 |
} |
| 1303 |
NumberAnimation { |
| 1304 |
target: flowContainer |
| 1305 |
properties: "thickness,thumbThickness" |
| 1306 |
duration: scrollbarThicknessAnimation.duration |
| 1307 |
easing: scrollbarThicknessAnimation.easing |
| 1308 |
} |
| 1309 |
ColorAnimation { target: background; duration: scrollbarThicknessAnimation.duration } |
| 1310 |
} |
| 1311 |
//this covers the case when scrollbar is still transitioning from steppers style to hidden, |
| 1312 |
//but the transition is not yet finished, and we flick the view. At that point the state is "hidden" |
| 1313 |
//but the properties are still transitioning from steppers style to hidden. If a change to "indicator" |
| 1314 |
//style is triggered while the properties are still transitioning, we have to handle those properties |
| 1315 |
//as well to avoid immediate changes in the UI. |
| 1316 |
PropertyAction { |
| 1317 |
target: flowContainer |
| 1318 |
properties: "showSteppers,showBackground,showCornerRect" |
| 1319 |
} |
| 1320 |
PropertyAction { |
| 1321 |
target: slider |
| 1322 |
properties: "visible" |
| 1323 |
} |
| 1324 |
} |
| 1325 |
}, |
| 1326 |
Transition { |
| 1327 |
id: growingTransition |
| 1328 |
objectName: "indicatorToThumbSteppersTransition" |
| 1329 |
from: 'indicator' |
| 1330 |
to: 'thumb,steppers' |
| 1331 |
reversible: true |
| 1332 |
SequentialAnimation { |
| 1333 |
PropertyAction { |
| 1334 |
target: flowContainer |
| 1335 |
properties: "showSteppers,showBackground,showCornerRect" |
| 1336 |
} |
| 1337 |
PropertyAction { |
| 1338 |
target: steppersMouseArea |
| 1339 |
properties: isVertical ? "width" : "height" |
| 1340 |
} |
| 1341 |
ParallelAnimation { |
| 1342 |
NumberAnimation { |
| 1343 |
target: visuals |
| 1344 |
property: "opacity" |
| 1345 |
duration: scrollbarThicknessAnimation.duration |
| 1346 |
easing: scrollbarThicknessAnimation.easing |
| 1347 |
} |
| 1348 |
NumberAnimation { |
| 1349 |
target: flowContainer |
| 1350 |
properties: "thickness,thumbThickness" |
| 1351 |
duration: scrollbarThicknessAnimation.duration |
| 1352 |
easing: scrollbarThicknessAnimation.easing |
| 1353 |
} |
| 1354 |
NumberAnimation { |
| 1355 |
target: steppersMouseArea |
| 1356 |
properties: isVertical ? "height" : "width" |
| 1357 |
duration: scrollbarThicknessAnimation.duration |
| 1358 |
easing: scrollbarThicknessAnimation.easing |
| 1359 |
} |
| 1360 |
ColorAnimation { target: background; duration: scrollbarThicknessAnimation.duration } |
| 1361 |
} |
| 1362 |
PropertyAction { |
| 1363 |
target: slider |
| 1364 |
properties: "visible" |
| 1365 |
} |
| 1366 |
} |
| 1367 |
}, |
| 1368 |
Transition { |
| 1369 |
id: steppersTransition |
| 1370 |
objectName: "anythingToThumbSteppersTransition" |
| 1371 |
from: '*' |
| 1372 |
to: 'thumb,steppers' |
| 1373 |
SequentialAnimation { |
| 1374 |
PropertyAction { |
| 1375 |
target: flowContainer |
| 1376 |
properties: "showSteppers,showBackground,showCornerRect" |
| 1377 |
} |
| 1378 |
PropertyAction { |
| 1379 |
target: steppersMouseArea |
| 1380 |
properties: isVertical ? "width" : "height" |
| 1381 |
} |
| 1382 |
//hide the thumb (if needed) before the steppers expand (otherwise you'd see the |
| 1383 |
//thumb sliding out of screen before hiding) |
| 1384 |
PropertyAction { |
| 1385 |
target: slider |
| 1386 |
properties: "visible" |
| 1387 |
} |
| 1388 |
ParallelAnimation { |
| 1389 |
NumberAnimation { |
| 1390 |
target: visuals |
| 1391 |
property: "opacity" |
| 1392 |
duration: scrollbarThicknessAnimation.duration |
| 1393 |
easing: scrollbarThicknessAnimation.easing |
| 1394 |
} |
| 1395 |
NumberAnimation { |
| 1396 |
target: flowContainer |
| 1397 |
properties: "thickness,thumbThickness" |
| 1398 |
//the check on opacity is needed because this transition is also run when a transition to "hidden" |
| 1399 |
//is still in progress! For example: transition from indicator to hidden is started, the state is set to "hidden" |
| 1400 |
//immediately, but the transition still has to happen. If, in this situation, we trigger a state change from "hidden" |
| 1401 |
//to another state (thumb/steppers) this transition is fired, but the fact that state is "hidden" is not |
| 1402 |
//really informative, we need to know if the stuff is actually visible on screen, because we want different |
| 1403 |
//animation based on whether we're animating from visible or invisible content, even if in both cases the state is "hidden"! |
| 1404 |
duration: visuals.opacity > 0 ? scrollbarThicknessAnimation.duration : 0 |
| 1405 |
easing: scrollbarThicknessAnimation.easing |
| 1406 |
} |
| 1407 |
NumberAnimation { |
| 1408 |
target: steppersMouseArea |
| 1409 |
properties: isVertical ? "height" : "width" |
| 1410 |
duration: visuals.opacity > 0 ? scrollbarThicknessAnimation.duration : 0 |
| 1411 |
easing: scrollbarThicknessAnimation.easing |
| 1412 |
} |
| 1413 |
ColorAnimation { target: background; duration: visuals.opacity > 0 ? scrollbarThicknessAnimation.duration : 0 } |
| 1414 |
} |
| 1415 |
} |
| 1416 |
}, |
| 1417 |
Transition { |
| 1418 |
id: hidingAnimation |
| 1419 |
from: '*' |
| 1420 |
to: 'hidden' |
| 1421 |
SequentialAnimation { |
| 1422 |
PauseAnimation { id: fadeOutPauseAnim; duration: scrollbarFadeOutPause } |
| 1423 |
NumberAnimation { |
| 1424 |
target: visuals |
| 1425 |
property: "opacity" |
| 1426 |
duration: scrollbarFadeOutAnimation.duration |
| 1427 |
easing: scrollbarFadeOutAnimation.easing |
| 1428 |
} |
| 1429 |
PropertyAction { |
| 1430 |
target: steppersMouseArea |
| 1431 |
properties: "width,height" |
| 1432 |
} |
| 1433 |
PropertyAction { |
| 1434 |
target: flowContainer |
| 1435 |
properties: "thickness,thumbThickness,showSteppers,showBackground,showCornerRect" |
| 1436 |
} |
| 1437 |
PropertyAction { |
| 1438 |
target: background |
| 1439 |
properties: "color" |
| 1440 |
} |
| 1441 |
PropertyAction { |
| 1442 |
target: slider |
| 1443 |
properties: "visible" |
| 1444 |
} |
| 1445 |
PropertyAction { |
| 1446 |
target: visuals |
| 1447 |
properties: "state" |
| 1448 |
} |
| 1449 |
} |
| 1450 |
} |
| 1451 |
] |
| 1452 |
} |