Kstars

ScrollBar.qml
1/*
2 SPDX-License-Identifier: GPL-2.0-or-later
3*/
4
5/** This qml code implements a vertical scrollbar which shall be displayed in listview of sky-objects.
6 * This piece of code is based on this example code:
7 * https://projects.forum.nokia.com/qmluiexamples/browser/qml/qmluiexamples/Scrollable/ScrollBar.qml
8 */
10import QtQuick 1.0
11
12Rectangle {
13 // The flickable to which the scrollbar is attached to, must be set
14 property variant flickable
15
16 // If set to false, scrollbar is visible even when not scrolling
17 property bool hideScrollBarsWhenStopped: true
18
19 // Thickness of the scrollbar, in pixels
20 property int scrollbarWidth: 10
21
22 color: "gray"
23 radius: width/2
24
25 function sbOpacity()
26 {
27 if (!hideScrollBarsWhenStopped || height < parent.height)
28 {
29 return 0.5;
30 }
31
32 return (flickable.flicking || flickable.moving) ? (height >= parent.height ? 0 : 0.5) : 0;
33 }
34
35 // Scrollbar appears automatically when content is bigger than the Flickable
36 opacity: sbOpacity()
37
38 width: scrollbarWidth
39 height: flickable.visibleArea.heightRatio * parent.height
40 x: parent.width - width
41 y: flickable.visibleArea.yPosition * parent.height
42
43 // Animate scrollbar appearing/disappearing
44 Behavior on opacity { NumberAnimation { duration: 200 }}
45}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.