Add buttons to ScrollBar when stepSize is defined

Signed-off-by: Daker Fernandes Pinheiro <dakerfp@gmail.com>
This commit is contained in:
Daker Fernandes Pinheiro 2011-04-28 19:22:51 -03:00
parent 6b291d0ac6
commit 79d17528f6
2 changed files with 224 additions and 127 deletions

View File

@ -20,9 +20,6 @@
import QtQuick 1.0 import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 0.1 as PlasmaCore
import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
// TODO: add support mouse wheel and key events // TODO: add support mouse wheel and key events
Item { Item {
id: scrollbar id: scrollbar
@ -37,9 +34,14 @@ Item {
property bool updateValueWhileDragging: true property bool updateValueWhileDragging: true
property alias stepSize: range.stepSize property alias stepSize: range.stepSize
property alias pressed: mouseArea.pressed property alias pressed: mouseArea.pressed
property real scrollButtonInterval: 50
// Convinience API // Convinience API
property bool _isVertical: orientation == Qt.Vertical property bool _isVertical: orientation == Qt.Vertical
property bool _showButtons: stepSize != 0
property bool _inverted: _isVertical ?
!scrollbar.inverted : scrollbar.inverted
property alias _value: range.value
width: _isVertical ? 22 : 200 width: _isVertical ? 22 : 200
height: _isVertical ? 200 : 22 height: _isVertical ? 200 : 22
@ -47,13 +49,104 @@ Item {
visible: flickableItem && handle.width < contents.width visible: flickableItem && handle.width < contents.width
Item { Item {
id: contents
width: _isVertical ? scrollbar.height : scrollbar.width width: _isVertical ? scrollbar.height : scrollbar.width
height: _isVertical ? scrollbar.width : scrollbar.height height: _isVertical ? scrollbar.width : scrollbar.height
rotation: _isVertical ? -90 : 0 rotation: _isVertical ? -90 : 0
anchors.centerIn: parent anchors.centerIn: parent
PlasmaCore.Svg {
id: scrollbarSvg
imagePath: "widgets/scrollbar"
}
PlasmaCore.SvgItem {
id: leftButton
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
}
height: 18
width: _showButtons ? 18 : 0
svg: scrollbarSvg
elementId: {
if (leftMousArea.pressed)
return "sunken-arrow-left";
if (scrollbar.activeFocus || leftMousArea.containsMouse)
return "mouseover-arrow-left";
else
return "arrow-left";
}
MouseArea {
id: leftMousArea
anchors.fill: parent
Timer {
id: leftTimer
interval: scrollbar.scrollButtonInterval;
running: parent.pressed
repeat: true
onTriggered: {
if (_inverted)
_value += stepSize;
else
_value -= stepSize;
}
}
}
}
PlasmaCore.SvgItem {
id: rightButton
anchors {
right: parent.right
verticalCenter: parent.verticalCenter
}
height: 18
width: _showButtons ? 18 : 0
svg: scrollbarSvg
elementId: {
if (rightMousArea.pressed)
return "sunken-arrow-right";
if (scrollbar.activeFocus || rightMousArea.containsMouse)
return "mouseover-arrow-right";
else
return "arrow-right";
}
MouseArea {
id: rightMousArea
anchors.fill: parent
Timer {
id: rightTimer
interval: scrollbar.scrollButtonInterval;
running: parent.pressed;
repeat: true
onTriggered: {
if (_inverted)
_value -= stepSize
else
_value += stepSize;
}
}
}
}
Item {
id: contents
anchors {
left: leftButton.right
top: parent.top
bottom: parent.bottom
right: rightButton.left
}
PlasmaCore.RangeModel { PlasmaCore.RangeModel {
id: range id: range
@ -69,7 +162,7 @@ Item {
return Math.max(0, diff); return Math.max(0, diff);
} }
stepSize: 0.0 stepSize: 0.0
inverted: _isVertical ? !scrollbar.inverted : scrollbar.inverted inverted: _inverted
positionAtMinimum: 0 + handle.width / 2 positionAtMinimum: 0 + handle.width / 2
positionAtMaximum: contents.width - handle.width / 2 positionAtMaximum: contents.width - handle.width / 2
value: _isVertical ? flickableItem.contentY : flickableItem.contentX value: _isVertical ? flickableItem.contentY : flickableItem.contentX
@ -193,3 +286,4 @@ Item {
value: range.position value: range.position
} }
} }
}

View File

@ -233,31 +233,34 @@ Rectangle {
text: index text: index
} }
PlasmaComponents.ScrollBar {
orientation: Qt.Vertical
flickableItem: parent
animated: true
anchors {
top: parent.top
right: parent.right
bottom: horizontalScrollBar.top
}
}
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
color: "grey" color: "grey"
opacity: 0.3 opacity: 0.3
} }
} }
}
PlasmaComponents.ScrollBar {
orientation: Qt.Vertical
flickableItem: scrollList
animated: true
stepSize: 40
scrollButtonInterval: 50
anchors {
top: scrollList.top
right: scrollList.right
bottom: scrollList.bottom
}
}
}
} }
} }
PlasmaComponents.ScrollBar { PlasmaComponents.ScrollBar {
id: horizontalScrollBar id: horizontalScrollBar
stepSize: 30
flickableItem: page flickableItem: page
animated: true animated: true
anchors { anchors {