From decf76214c242a8cf2ad4b0a5f473dbc31a12f0b Mon Sep 17 00:00:00 2001 From: Daker Fernandes Pinheiro Date: Thu, 7 Jul 2011 20:43:24 -0300 Subject: [PATCH] Add keyboard events support in ScrollBar Pressing up/down/left/right keys makes the ScrollBar move Signed-off-by: Daker Fernandes Pinheiro --- .../plasmacomponents/ScrollBar.qml | 43 +++++++++++++++++++ declarativeimports/test/Gallery.qml | 4 ++ 2 files changed, 47 insertions(+) diff --git a/declarativeimports/plasmacomponents/ScrollBar.qml b/declarativeimports/plasmacomponents/ScrollBar.qml index c5addc9d2..a2635540c 100644 --- a/declarativeimports/plasmacomponents/ScrollBar.qml +++ b/declarativeimports/plasmacomponents/ScrollBar.qml @@ -48,6 +48,47 @@ Item { visible: flickableItem && handle.width < contents.width + Keys.onUpPressed: { + if (!_isVertical) + return; + + if (_inverted) + range.value -= stepSize; + else + range.value += stepSize; + } + + Keys.onDownPressed: { + if (!_isVertical) + return; + + if (_inverted) + range.value += stepSize; + else + range.value -= stepSize; + } + + Keys.onLeftPressed: { + if (_isVertical) + return; + + if (_inverted) + range.value += stepSize; + else + range.value -= stepSize; + } + + Keys.onRightPressed: { + if (_isVertical) + return; + + if (_inverted) + range.value -= stepSize; + else + range.value += stepSize; + } + + Item { width: _isVertical ? scrollbar.height : scrollbar.width @@ -90,6 +131,7 @@ Item { running: parent.pressed repeat: true onTriggered: { + scrollbar.forceActiveFocus(); if (_inverted) _value += stepSize; else @@ -129,6 +171,7 @@ Item { running: parent.pressed; repeat: true onTriggered: { + scrollbar.forceActiveFocus(); if (_inverted) _value -= stepSize else diff --git a/declarativeimports/test/Gallery.qml b/declarativeimports/test/Gallery.qml index 35fe13ff0..9fdc5a28c 100644 --- a/declarativeimports/test/Gallery.qml +++ b/declarativeimports/test/Gallery.qml @@ -31,6 +31,7 @@ Rectangle { anchors.fill: parent contentWidth: 2200 contentHeight: 600 + contentX: 500 Row { x: 30 @@ -168,6 +169,7 @@ Rectangle { PlasmaComponents.BusyIndicator { id: busy running: mouse.pressed + smoothAnimation: true MouseArea { id: mouse anchors.fill: parent @@ -318,6 +320,8 @@ Rectangle { PlasmaComponents.ScrollBar { id: verticalScrollBar + stepSize: 30 + orientation: Qt.Vertical flickableItem: page animated: true