mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
brmbar v3 BarScrollBar: New widget
This commit is contained in:
parent
9afd1788d0
commit
99cbefbb21
1 changed files with 40 additions and 0 deletions
40
brmbar3/brmbar-gui-qt4/BarScrollBar.qml
Normal file
40
brmbar3/brmbar-gui-qt4/BarScrollBar.qml
Normal file
|
@ -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 }}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue