2
* Copyright 2015 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import Ubuntu.Components 1.3 as Toolkit
22
\inqmlmodule Ubuntu.Components 1.1
24
\brief The ScrollBar component provides scrolling functionality for
25
scrollable views (i.e. Flickable, ListView).
27
The ScrollBar can be set to any flickable and has built-in anchoring setup
28
to the attached flickable's front, rear, top or bottom. the scrollbar can
29
also be aligned using anchors, however the built-in align functionality
30
makes sure to have the proper alignemt applied based on theme and layout
31
direction (RTL or LTR).
33
The content position is driven through the attached Flickable. Therefore every
34
style implementation should drive the position through contentX/contentY
35
properties, depending on whether the orientation is vertical or horizontal.
46
width: ListView.view.width
50
text: "Item " + modelData
56
align: Qt.AlignTrailing
66
This property holds the flickable item (Flickable, ListView or GridView)
67
the Scrollbar is attached to.
69
property Flickable flickableItem: null
72
The property defines the alignment of the scrollbar to the flickableItem.
73
The implementation handles the alignment as follows:
75
\li Qt.AlignLeading anchors to the left on LTR and to the right on RTL layouts
76
\li Qt.AlignTrailing anchors to the right on LTR and to the left on RTL layouts
77
\li Qt.AlignTop anchors to the top
78
\li Qt.AlignBottom anchors to the bottom
80
The default value is \b Qt.AlignTrailing.
82
property int align: Qt.AlignTrailing
86
This property holds whether the scrollbar is active or passive. It is present
89
property bool __interactive: __styleInstance !== null && __styleInstance.interactive
91
implicitWidth: internals.vertical ? units.gu(4) : flickableItem.width
92
implicitHeight: !internals.vertical ? units.gu(4) : flickableItem.height
95
left: internals.leftAnchor(flickableItem)
96
right: internals.rightAnchor(flickableItem)
97
top: internals.topAnchor(flickableItem)
98
bottom: internals.bottomAnchor(flickableItem)
104
onAlignChanged: if (!internals.checkAlign()) console.log("Wrong alignment set to Scrollbar: "+align)
108
Internals: contains the common logic of the scrollbar like anchoring,
109
alignemt check, scrollability check.
111
property alias __private: internals
114
property bool vertical: (align === Qt.AlignLeading) || (align === Qt.AlignTrailing)
115
property bool scrollable: flickableItem && flickableItem.interactive && checkAlign()
117
function checkAlign()
119
return (align === Qt.AlignLeading) || (align === Qt.AlignTrailing) || (align === Qt.AlignTop) || (align === Qt.AlignBottom);
122
// LTR and RTL are provided by LayoutMirroring, so no need to check that
123
function leftAnchor(object)
125
if (!internals.vertical || (align == Qt.AlignLeading))
129
function rightAnchor(object)
131
if (!internals.vertical || (align == Qt.AlignTrailing))
135
function topAnchor(object)
137
if (internals.vertical || (align == Qt.AlignTop))
141
function bottomAnchor(object)
143
if (internals.vertical || (align == Qt.AlignBottom))
144
return object.bottom;
149
theme.version: Toolkit.Ubuntu.toolkitVersion
150
styleName: "ScrollbarStyle"