1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
35 // scrollbar for the items view
42 property variant flickable
44 function scroll(delta) {
45 handle.y = Math.max(0, Math.min(scrollHeight, handle.y + delta))
54 ItemsViewStyle { id: style }
56 onFlickableChanged: reset()
58 property int scrollHeight: height - handle.height
63 anchors.top: parent.top
65 anchors.bottom: parent.bottom
66 anchors.bottomMargin: 3
67 anchors.horizontalCenter: parent.horizontalCenter
70 color: style.scrollbarColor
72 border.color: style.scrollbarBorderColor
75 function updateHandle() {
76 handle.updateFlickable = false
79 handle.y = scrollHeight * Math.min(
80 flickable.contentY / (flickable.contentHeight - flickable.height),
85 handle.updateFlickable = true
88 onHeightChanged: updateHandle()
92 onHeightChanged: updateHandle()
97 onContentHeightChanged: updateHandle()
102 onContentYChanged: updateHandle()
106 anchors.left: parent.left
107 anchors.right: parent.right
108 anchors.top: parent.top
109 anchors.bottom: handle.top
110 onClicked: scroll(-style.scrollbarClickScrollAmount)
116 anchors.left: parent.left
117 anchors.right: parent.right
118 height: Math.max(width, bar.height * Math.min(1, flickable.height / flickable.contentHeight))
120 property bool updateFlickable: true
124 flickable.contentY = Math.max(0, flickable.contentHeight * y / bar.height)
134 transformOrigin: Item.BottomLeft
136 border.color: style.scrollbarBorderColor
141 GradientStop { position: 0.15; color: style.scrollbarGradientStartColor }
142 GradientStop { position: 0.78; color: style.scrollbarGradientMiddleColor }
143 GradientStop { position: 0.80; color: style.scrollbarGradientEndColor }
152 drag.maximumY: scrollHeight
157 anchors.left: parent.left
158 anchors.right: parent.right
159 anchors.top: handle.bottom
160 anchors.bottom: parent.bottom
161 onClicked: scroll(style.scrollbarClickScrollAmount)