1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
36 // scrollbar for the items view
43 property variant flickable
45 function scroll(delta) {
46 handle.y = Math.max(0, Math.min(scrollHeight, handle.y + delta))
55 ItemsViewStyle { id: style }
57 onFlickableChanged: reset()
59 property int scrollHeight: height - handle.height
64 anchors.top: parent.top
66 anchors.bottom: parent.bottom
67 anchors.bottomMargin: 3
68 anchors.horizontalCenter: parent.horizontalCenter
71 color: style.scrollbarColor
73 border.color: style.scrollbarBorderColor
76 function updateHandle() {
77 handle.updateFlickable = false
80 handle.y = scrollHeight * Math.min(
81 flickable.contentY / (flickable.contentHeight - flickable.height),
86 handle.updateFlickable = true
89 onHeightChanged: updateHandle()
93 onHeightChanged: updateHandle()
98 onContentHeightChanged: updateHandle()
103 onContentYChanged: updateHandle()
107 anchors.left: parent.left
108 anchors.right: parent.right
109 anchors.top: parent.top
110 anchors.bottom: handle.top
111 onClicked: scroll(-style.scrollbarClickScrollAmount)
117 anchors.left: parent.left
118 anchors.right: parent.right
119 height: Math.max(width, bar.height * Math.min(1, flickable.height / flickable.contentHeight))
121 property bool updateFlickable: true
125 flickable.contentY = Math.max(0, flickable.contentHeight * y / bar.height)
135 transformOrigin: Item.BottomLeft
137 border.color: style.scrollbarBorderColor
142 GradientStop { position: 0.15; color: style.scrollbarGradientStartColor }
143 GradientStop { position: 0.78; color: style.scrollbarGradientMiddleColor }
144 GradientStop { position: 0.80; color: style.scrollbarGradientEndColor }
153 drag.maximumY: scrollHeight
158 anchors.left: parent.left
159 anchors.right: parent.right
160 anchors.top: handle.bottom
161 anchors.bottom: parent.bottom
162 onClicked: scroll(style.scrollbarClickScrollAmount)