diff options
author | Jörg Schummer <ext-jorg.2.schummer@nokia.com> | 2010-02-16 17:24:18 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-02-16 16:39:32 +0100 |
commit | 2791cfbdd1d8c7a1c1d9201ae95e7ea3b4fa43de (patch) | |
tree | a51e8a9abd75b454fbeb671f5ae089d91b9f475f /src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml | |
parent | 6585742fc7fe9fe8453204558ce0d910b230396a (diff) | |
download | qt-creator-2791cfbdd1d8c7a1c1d9201ae95e7ea3b4fa43de.tar.gz |
QmlDesigner.ItemLibrary: integrated the new Qml-based item library
Task-number: BAUHAUS-204
Task-number: BAUHAUS-207
Task-number: BAUHAUS-339
Task-number: BAUHAUS-365
Task-number: BAUHAUS-374
Reviewed-by: kkoehne
Diffstat (limited to 'src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml')
-rw-r--r-- | src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml new file mode 100644 index 0000000000..cff81189a1 --- /dev/null +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml @@ -0,0 +1,151 @@ +import Qt 4.6 + +Item { + id: bar + + property var handleBar: handle + + property var scrollFlickable + property var style + + property bool scrolling: (scrollFlickable.viewportHeight > scrollFlickable.height) + property int scrollHeight: height - handle.height + + Binding { + target: scrollFlickable + property: "viewportY" + value: Math.max(0, scrollFlickable.viewportHeight - scrollFlickable.height) * + handle.y / scrollHeight + } + + Rectangle { + anchors.fill: parent; + anchors.rightMargin: 1 + anchors.bottomMargin: 1 + color: "transparent" + border.width: 1; + border.color: "#8F8F8F"; + } + + function moveHandle(viewportPos) { + var pos; + + if (bar.scrollFlickable) {//.visibleArea.yPosition) { + pos = bar.scrollHeight * viewportPos / (bar.scrollFlickable.viewportHeight - bar.scrollFlickable.height); + } else + pos = 0; + +// handleMoveAnimation.to = Math.min(bar.scrollHeight, pos) +// handleMoveAnimation.start(); + handle.y = Math.min(bar.scrollHeight, pos) + } + + function limitHandle() { + // the following "if" is needed to get around NaN when starting up + if (scrollFlickable) + handle.y = Math.min(handle.height * scrollFlickable.visibleArea.yPosition, + scrollHeight); + else + handle.y = 0; + } +/* + NumberAnimation { + id: handleResetAnimation + target: handle + property: "y" + from: handle.y + to: 0 + duration: 500 + } +*/ + Connection { + sender: scrollFlickable + signal: "heightChanged" + script: { + /* since binding loops prevent setting the handle properly, + let's animate it to 0 */ + if (scrollFlickable.viewportY > (scrollFlickable.viewportHeight - scrollFlickable.height)) +// handleResetAnimation.start() + handle.y = 0 + } + } + + onScrollFlickableChanged: handle.y = 0 + +/* + Rectangle { + anchors.fill: parent + anchors.leftMargin: 3 + anchors.rightMargin: 3 + anchors.topMargin: 2 + anchors.bottomMargin: 2 + radius: width / 2 + color: style.scrollbarBackgroundColor + } +*/ + MouseRegion { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: handle.top + onClicked: { +// handleMoveAnimation.to = Math.max(0, handle.y - 40) +// handleMoveAnimation.start(); + handle.y = Math.max(0, handle.y - 40) + } + } + + Item { + id: handle + + anchors.left: parent.left + anchors.right: parent.right + height: Math.max(width, bar.height * Math.min(1, scrollFlickable.visibleArea.heightRatio)) + +// radius: width / 2 +// color: style.scrollbarHandleColor + + Rectangle { + width: parent.height + height: parent.width + y: parent.height + + rotation: -90 + transformOrigin: Item.TopLeft + + gradient: Gradient { + GradientStop { position: 0.0; color: "#C6C6C6" } + GradientStop { position: 1.0; color: "#7E7E7E" } + } + } + + MouseRegion { + anchors.fill: parent + drag.target: parent + drag.axis: "YAxis" + drag.minimumY: 0 + drag.maximumY: scrollHeight + } + } + + MouseRegion { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: handle.bottom + anchors.bottom: parent.bottom + onClicked: { +// handleMoveAnimation.to = Math.min(scrollHeight, handle.y + 40) +// handleMoveAnimation.start(); + handle.y = Math.min(scrollHeight, handle.y + 40) + } + } +/* + NumberAnimation { + id: handleMoveAnimation + target: handle + property: "y" + duration: 200 + } +*/ +} + |