OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / itemlibrary / qml / Scrollbar.qml
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 import Qt 4.7
34
35 // scrollbar for the items view
36
37 Item {
38     id: bar
39
40     // public
41
42     property variant flickable
43
44     function scroll(delta) {
45         handle.y = Math.max(0, Math.min(scrollHeight, handle.y + delta))
46     }
47
48     function reset() {
49         handle.y = 0
50     }
51
52     // internal
53
54     ItemsViewStyle { id: style }
55
56     onFlickableChanged: reset()
57
58     property int scrollHeight: height - handle.height
59
60     clip: true
61
62     Rectangle {
63         anchors.top: parent.top
64         anchors.topMargin: 2
65         anchors.bottom: parent.bottom
66         anchors.bottomMargin: 3
67         anchors.horizontalCenter: parent.horizontalCenter
68         width: 6
69         radius: 3
70         color: style.scrollbarColor
71         border.width: 1
72         border.color: style.scrollbarBorderColor
73     }
74
75     function updateHandle() {
76         handle.updateFlickable = false
77
78         if (flickable)
79             handle.y = scrollHeight * Math.min(
80                     flickable.contentY / (flickable.contentHeight - flickable.height),
81         1)
82             else
83                 handle.y = 0
84
85         handle.updateFlickable = true
86     }
87
88     onHeightChanged: updateHandle()
89
90     Connections {
91         target: flickable
92         onHeightChanged: updateHandle()
93     }
94
95     Connections {
96         target: flickable
97         onContentHeightChanged: updateHandle()
98     }
99
100     Connections {
101         target: flickable
102         onContentYChanged: updateHandle()
103     }
104
105     MouseArea {
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)
111     }
112
113     Item {
114         id: handle
115
116         anchors.left: parent.left
117         anchors.right: parent.right
118         height: Math.max(width, bar.height * Math.min(1, flickable.height / flickable.contentHeight))
119
120         property bool updateFlickable: true
121
122         onYChanged: {
123             if (updateFlickable)
124                 flickable.contentY = Math.max(0, flickable.contentHeight * y / bar.height)
125             }
126                         
127                 Rectangle {
128                     width: parent.height
129                     height: parent.width
130                     y: -height - 2
131                     x: -2
132
133                     rotation: 90
134                     transformOrigin: Item.BottomLeft
135
136                     border.color: style.scrollbarBorderColor
137                     border.width: 1
138                     radius: 3
139
140                     gradient: Gradient {
141                         GradientStop { position: 0.15; color: style.scrollbarGradientStartColor }
142                         GradientStop { position: 0.78; color: style.scrollbarGradientMiddleColor }
143                         GradientStop { position: 0.80; color: style.scrollbarGradientEndColor }
144                     }
145                 }
146
147                 MouseArea {
148                     anchors.fill: parent
149                     drag.target: parent
150                     drag.axis: "YAxis"
151                     drag.minimumY: 0
152                     drag.maximumY: scrollHeight
153                 }
154             }
155
156     MouseArea {
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)
162     }
163 }