From 99cbefbb21cdecbfb4624628bc2d2c84a2a70f6d Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 24 Sep 2012 03:54:23 +0200 Subject: [PATCH] brmbar v3 BarScrollBar: New widget --- brmbar3/brmbar-gui-qt4/BarScrollBar.qml | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 brmbar3/brmbar-gui-qt4/BarScrollBar.qml diff --git a/brmbar3/brmbar-gui-qt4/BarScrollBar.qml b/brmbar3/brmbar-gui-qt4/BarScrollBar.qml new file mode 100644 index 0000000..d93a9d1 --- /dev/null +++ b/brmbar3/brmbar-gui-qt4/BarScrollBar.qml @@ -0,0 +1,40 @@ +// Based on https://projects.forum.nokia.com/qmluiexamples/browser/qml/qmluiexamples/Scrollable/ScrollBar.qml +import Qt 4.7 + +Rectangle { + // The flickable to which the scrollbar is attached to, must be set + property variant flickableItem + + // True for vertical ScrollBar, false for horizontal + property bool vertical: true + + property int scrollbarWidth: 20 + + property variant color: "white" + property variant baseOpacityOff: 0.4 + property variant baseOpacityOn: 0.9 + + radius: vertical ? width/2 : height/2 + + function sbOpacity() + { + if (vertical ? (height >= parent.height) : (width >= parent.width)) { + return 0; + } else { + return (flickableItem.flicking || flickableItem.moving) ? baseOpacityOn : baseOpacityOff; + } + } + + // Scrollbar appears automatically when content is bigger than the Flickable + opacity: sbOpacity() + + // Calculate width/height and position based on the content size and position of + // the Flickable + width: vertical ? scrollbarWidth : flickableItem.visibleArea.widthRatio * parent.width + height: vertical ? flickableItem.visibleArea.heightRatio * parent.height : scrollbarWidth + x: vertical ? parent.width - width : flickableItem.visibleArea.xPosition * parent.width + y: vertical ? flickableItem.visibleArea.yPosition * parent.height : parent.height - height + + // Animate scrollbar appearing/disappearing + Behavior on opacity { NumberAnimation { duration: 200 }} +}