2011-04-21 17:01:42 +02:00
|
|
|
/*
|
2011-04-28 12:50:31 +02:00
|
|
|
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
|
2011-11-09 14:34:53 +01:00
|
|
|
* Copyright (C) 2011 Marco Martin <mart@kde.org>
|
2011-04-21 17:01:42 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-12-22 11:53:15 +01:00
|
|
|
/**Documented API
|
2011-11-06 22:24:03 +01:00
|
|
|
Inherits:
|
|
|
|
Item
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-11-06 22:24:03 +01:00
|
|
|
Imports:
|
|
|
|
org.kde.plasma.core
|
|
|
|
QtQuick 1.1
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-11-06 22:24:03 +01:00
|
|
|
Description:
|
2011-12-17 21:24:58 +01:00
|
|
|
Just a simple Scroll Bar which is using the plasma theme.
|
2012-02-04 22:05:45 +01:00
|
|
|
This component does not belong to the QtComponents API specification
|
2011-12-17 21:24:58 +01:00
|
|
|
but it was base on ScrollDecorator component.
|
|
|
|
You should not use it for touch interfaces, use a flickable and a
|
|
|
|
ScrollDecorator instead.
|
2011-12-22 16:45:25 +01:00
|
|
|
By default, this component will look and behave like a scroll decorator
|
|
|
|
on touchscreens
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-11-06 22:24:03 +01:00
|
|
|
Properties:
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
enumeration orientation:
|
|
|
|
This property holds the orientation where the ScrollBar will scroll.
|
2011-12-22 16:45:25 +01:00
|
|
|
The orientation can be either Qt.Horizontal or Qt.Vertical
|
|
|
|
The default value is Qt.Vertical.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
|
|
|
bool inverted:
|
2011-12-17 21:24:58 +01:00
|
|
|
This property holds if the ScrollBar will increase the Flickable
|
2011-12-22 16:45:25 +01:00
|
|
|
content in the normal direction (Left to Right or Top to Bottom) or
|
|
|
|
if this will be inverted.
|
|
|
|
The default value is false.
|
2011-12-17 21:24:58 +01:00
|
|
|
|
|
|
|
bool updateValueWhileDragging:
|
|
|
|
This property holds if the Scrollbar will update the Flickeble
|
2011-12-22 16:45:25 +01:00
|
|
|
position while dragging or only when released.
|
|
|
|
The default value is true.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
real stepSize:
|
|
|
|
This property holds how many steps exists while moving the handler.
|
2011-12-22 16:45:25 +01:00
|
|
|
If you want the ScrollBar buttons to appear you must set this property
|
|
|
|
with a value bigger than 0.
|
|
|
|
The default value is 0.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
bool pressed:
|
|
|
|
This property holds if the ScrollBar is pressed.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
real scrollButtonInterval:
|
|
|
|
This property holds the interval time used by the ScrollBar button
|
2011-12-22 16:45:25 +01:00
|
|
|
to increase or decrease steps.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
Flickable flickableItem:
|
|
|
|
This property holds the Flickable component which the ScrollBar will
|
2011-12-22 16:45:25 +01:00
|
|
|
interact with.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
bool interactive:
|
|
|
|
This property holds if the ScrollBar is interactive.
|
2011-12-22 16:45:25 +01:00
|
|
|
The default value is true.
|
2011-11-02 02:29:15 +01:00
|
|
|
|
2011-12-17 21:24:58 +01:00
|
|
|
bool enabeld:
|
|
|
|
This property holds if the button will be enabled for user
|
2011-12-22 16:45:25 +01:00
|
|
|
interaction.
|
|
|
|
The default value is true.
|
2011-11-02 02:29:15 +01:00
|
|
|
**/
|
|
|
|
|
2011-05-18 21:38:21 +02:00
|
|
|
import QtQuick 1.1
|
2011-04-21 17:01:42 +02:00
|
|
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
2011-12-22 14:16:01 +01:00
|
|
|
import "private" as Private
|
2011-11-09 15:28:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic ScrollBar/ScrollDecorator component:
|
2012-02-04 22:05:45 +01:00
|
|
|
* Always prefer this to ScrollDecorator that is not available on desktop.
|
2011-11-09 15:28:21 +01:00
|
|
|
* By default, this component will look and behave like a scroll decorator on touchscreens
|
|
|
|
*/
|
|
|
|
// TODO: add support mouse wheel events
|
2011-04-28 12:50:31 +02:00
|
|
|
Item {
|
|
|
|
id: scrollbar
|
|
|
|
|
|
|
|
// Common API
|
|
|
|
property Flickable flickableItem: null
|
2011-11-09 14:21:54 +01:00
|
|
|
property int orientation: Qt.Vertical
|
|
|
|
property bool interactive: true
|
2011-04-28 12:50:31 +02:00
|
|
|
|
|
|
|
// Plasma API
|
|
|
|
property bool inverted: false
|
|
|
|
property alias stepSize: range.stepSize
|
2011-11-09 16:53:58 +01:00
|
|
|
property bool pressed: internalLoader.item.mouseArea?internalLoader.item.mouseArea.pressed:false
|
2011-04-29 00:22:51 +02:00
|
|
|
property real scrollButtonInterval: 50
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-12-14 13:46:11 +01:00
|
|
|
implicitWidth: internalLoader.isVertical ? (interactive ? 16 : 12) : 200
|
|
|
|
implicitHeight: internalLoader.isVertical ? 200 : (interactive ? 16 : 12)
|
2011-07-19 00:17:19 +02:00
|
|
|
// TODO: needs to define if there will be specific graphics for
|
|
|
|
// disabled scroll bars
|
|
|
|
opacity: enabled ? 1.0 : 0.5
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
visible: flickableItem && internalLoader.handleEnabled
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-10-28 22:32:45 +02:00
|
|
|
anchors {
|
|
|
|
right: flickableItem.right
|
2011-11-02 02:29:15 +01:00
|
|
|
left: (orientation == Qt.Vertical) ? undefined : flickableItem.left
|
2011-10-28 22:32:45 +02:00
|
|
|
top: (orientation == Qt.Vertical) ? flickableItem.top : undefined
|
|
|
|
bottom: flickableItem.bottom
|
|
|
|
}
|
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
Loader {
|
|
|
|
id: internalLoader
|
|
|
|
anchors.fill: parent
|
2011-11-09 17:05:21 +01:00
|
|
|
//property bool handleEnabled: internalLoader.isVertical ? item.handle.height < item.contents.height : item.handle.width < item.contents.width
|
|
|
|
property bool handleEnabled: internalLoader.isVertical ? flickableItem.contentHeight > flickableItem.height : flickableItem.contentWidth > flickableItem.width
|
|
|
|
property bool isVertical: orientation == Qt.Vertical
|
2011-11-09 14:21:54 +01:00
|
|
|
|
|
|
|
function incrementValue(increment)
|
|
|
|
{
|
|
|
|
if (!flickableItem)
|
|
|
|
return;
|
|
|
|
|
2011-11-09 17:05:21 +01:00
|
|
|
if (internalLoader.isVertical) {
|
2011-11-09 14:21:54 +01:00
|
|
|
flickableItem.contentY = Math.max(0, Math.min(flickableItem.contentHeight,
|
|
|
|
flickableItem.contentY + increment))
|
|
|
|
} else {
|
|
|
|
flickableItem.contentX = Math.max(0, Math.min(flickableItem.contentWidth,
|
|
|
|
flickableItem.contentX + increment))
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2012-01-05 02:27:39 +01:00
|
|
|
// FIXME: there's a binding loop occurrence here somewhere...(RangeModel) : property: value
|
|
|
|
// try flicking a view with a scrollbar in it, and flick it past it's contents
|
|
|
|
// a few times and try using the mousewheel..you'll find the warning then..
|
2011-11-09 14:21:54 +01:00
|
|
|
RangeModel {
|
|
|
|
id: range
|
2011-04-29 00:22:51 +02:00
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
minimumValue: 0
|
|
|
|
maximumValue: {
|
|
|
|
var diff;
|
2011-11-09 17:05:21 +01:00
|
|
|
if (internalLoader.isVertical) {
|
2011-11-09 14:21:54 +01:00
|
|
|
diff = flickableItem.contentHeight - flickableItem.height
|
|
|
|
} else {
|
|
|
|
diff = flickableItem.contentWidth - flickableItem.width
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
return Math.max(0, diff)
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
stepSize: 10
|
|
|
|
inverted: scrollbar.inverted
|
|
|
|
positionAtMinimum: 0
|
|
|
|
positionAtMaximum: {
|
2011-11-09 17:05:21 +01:00
|
|
|
if (internalLoader.isVertical) {
|
2011-11-09 14:21:54 +01:00
|
|
|
internalLoader.item.contents.height - internalLoader.item.handle.height
|
|
|
|
} else {
|
|
|
|
internalLoader.item.contents.width - internalLoader.item.handle.width
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
2011-04-21 17:01:42 +02:00
|
|
|
}
|
2011-11-09 17:05:21 +01:00
|
|
|
value: internalLoader.isVertical ? flickableItem.contentY : flickableItem.contentX
|
2011-11-09 14:21:54 +01:00
|
|
|
onValueChanged: {
|
|
|
|
if (flickableItem.moving) {
|
|
|
|
return
|
2011-04-28 12:50:31 +02:00
|
|
|
}
|
|
|
|
|
2011-11-09 17:05:21 +01:00
|
|
|
if (internalLoader.isVertical) {
|
2011-11-09 14:21:54 +01:00
|
|
|
flickableItem.contentY = value
|
|
|
|
} else {
|
|
|
|
flickableItem.contentX = value
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 17:05:21 +01:00
|
|
|
position: internalLoader.isVertical ? internalLoader.item.handle.y : internalLoader.item.handle.x
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 14:21:54 +01:00
|
|
|
onPositionChanged: {
|
2011-11-09 15:03:29 +01:00
|
|
|
if (internalLoader.item.mouseArea && internalLoader.item.mouseArea.pressed) {
|
2011-11-09 14:21:54 +01:00
|
|
|
return
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
2011-04-28 12:50:31 +02:00
|
|
|
|
2011-11-09 17:05:21 +01:00
|
|
|
if (internalLoader.isVertical) {
|
2011-11-09 14:21:54 +01:00
|
|
|
internalLoader.item.handle.y = position
|
|
|
|
} else {
|
|
|
|
internalLoader.item.handle.x = position
|
2011-04-29 00:22:51 +02:00
|
|
|
}
|
2011-04-21 17:01:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:34:09 +01:00
|
|
|
source: interactive ? "private/ScrollBarDelegate.qml" : "private/ScrollDecoratorDelegate.qml"
|
2011-04-28 12:50:31 +02:00
|
|
|
}
|
|
|
|
}
|