~ubuntu-branches/ubuntu/wily/ubuntu-ui-toolkit/wily-proposed

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/1.3/Scrollbar.qml

  • Committer: Package Import Robot
  • Author(s): CI Train Bot, Florian Boucault, Loïc Molinari, Benjamin Zeller, Richard Huddie, Tim Peeters, Zsombor Egri, Timo Jyrinki, Christian Dywan, Albert Astals Cid
  • Date: 2015-07-30 13:04:18 UTC
  • mfrom: (1.1.126)
  • Revision ID: package-import@ubuntu.com-20150730130418-nxjr780u6wqcdqeh
Tags: 1.3.1584+15.10.20150730-0ubuntu1
[ Florian Boucault ]
* New BottomEdgeHint component to represent extra features available from the 
  bottom edge of an application.

[ Loïc Molinari ]
* [UbuntuShape] Added a big radius.
* [UbuntuShape] Added relative radius support. Fixes LP: #1478124.
* Ensured components, styles, examples and tests use the new UbuntuShape 
  properties (not deprecated). Fixes LP: #1437412.

[ Benjamin Zeller ]
* Make use of the official qt build macros to blend into the Qt buildprocess.
* Fix debug builds, optimization is always enabled by the system qt build.

[ Richard Huddie ]
* Fix for autopilot bug lp:1476715. Don't throw an exception if maliit-server
  is not found. Fixes LP: #1476715.

[ Tim Peeters ]
* Clean up the MainView docs.
* Set theme version for Sections component.
* Implement AdaptivePageLayout.

[ Zsombor Egri ]
* Fix width for trailing and leading actions of a ListItem. Fixes LP: #1465582.
* Button and Haptics import wrong toolkit versions, thus they break style 
  versioning. Moving Icon and ProgressBar to 1.0 and 1.1 version source folder.
* SuruDark theme for ListItem style. Fixes LP: #1451225.
* Swiping ListItem when no actions are defined for the gesture breaks 
  selectMode. Fixes LP: #1468100.
* Fixing selected connection with the ListItem's select mode checkbox state. 
  Fixes LP: #1461501, LP: #1469471.

[ Timo Jyrinki ]
* Fix ucstylehints.cpp compilation with Qt 5.5. Fixes LP: #1473873.
* Add PageHeadStyle 1.3 reference to fix install_plugins_qmltypes failure with 
  Qt 5.5. Fixes LP: #1466484.

[ Christian Dywan ]
* Avoid hard-coded skipping of members by name "type" can be a property name 
  regardless of also being a field in the JSON description of a property.
* Add apicheck unit test for QML and Javascript.
* Remove "do cleanup" comments. Fixes LP: #1369874.
* Initialize defaultTypes later to avoid bogus types.
* Implement Action.shortcut property. Fixes LP: #1202464.
* Update text handler to 3gu assert.
* Add a deprecated note to ListItems.ThinDivider. Fixes LP: #1470951.
* Don't include overridden properties in API.
* Clean-up API check wrapper scripts.
* Track version members were introduced.
* Implement ListItemPopover on right-click. Fixes LP: #1452676.
* Move delegate's chevron into the row and size it explicitly. 
  Fixes LP: #1474418.
* Enable (Shift)Tab via activeFocusOnTab. Fixes LP: #1276797.
* Only swipe with left button and block timer otherwise. 
  Fixes LP: #1476300, LP: #1476310.
* Include Javascript libraries in QML documentation. Fixes LP: #1466058.

[ Albert Astals Cid ]
* Fix warning if there's no __propagated
* TypeError: Cannot call method 'hasOwnProperty' of null.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import Ubuntu.Components 1.3 as Toolkit
 
19
 
 
20
/*!
 
21
    \qmltype ScrollBar
 
22
    \inqmlmodule Ubuntu.Components 1.1
 
23
    \ingroup ubuntu
 
24
    \brief The ScrollBar component provides scrolling functionality for
 
25
    scrollable views (i.e. Flickable, ListView).
 
26
 
 
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).
 
32
 
 
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.
 
36
 
 
37
    Example:
 
38
    \qml
 
39
    Item {
 
40
        ListView {
 
41
            id: list
 
42
            width: units.gu(37)
 
43
            height: units.gu(37)
 
44
            model: 30
 
45
            delegate: Rectangle {
 
46
                width: ListView.view.width
 
47
                height: units.gu(5)
 
48
                Text {
 
49
                    anchors.fill: parent
 
50
                    text: "Item " + modelData
 
51
                }
 
52
            }
 
53
        }
 
54
        Scrollbar {
 
55
            flickableItem: list
 
56
            align: Qt.AlignTrailing
 
57
        }
 
58
    }
 
59
    \endqml
 
60
  */
 
61
 
 
62
Toolkit.StyledItem {
 
63
    id: scrollbar
 
64
 
 
65
    /*!
 
66
        This property holds the flickable item (Flickable, ListView or GridView)
 
67
        the Scrollbar is attached to.
 
68
      */
 
69
    property Flickable flickableItem: null
 
70
 
 
71
    /*!
 
72
      The property defines the alignment of the scrollbar to the flickableItem.
 
73
      The implementation handles the alignment as follows:
 
74
        \list
 
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
 
79
        \endlist
 
80
        The default value is \b Qt.AlignTrailing.
 
81
      */
 
82
    property int align: Qt.AlignTrailing
 
83
 
 
84
    /*!
 
85
      \internal
 
86
      This property holds whether the scrollbar is active or passive. It is present
 
87
      for testing purposes.
 
88
    */
 
89
    property bool __interactive: __styleInstance !== null && __styleInstance.interactive
 
90
 
 
91
    implicitWidth: internals.vertical ? units.gu(4) : flickableItem.width
 
92
    implicitHeight: !internals.vertical ? units.gu(4) : flickableItem.height
 
93
 
 
94
    anchors {
 
95
        left: internals.leftAnchor(flickableItem)
 
96
        right: internals.rightAnchor(flickableItem)
 
97
        top: internals.topAnchor(flickableItem)
 
98
        bottom: internals.bottomAnchor(flickableItem)
 
99
    }
 
100
 
 
101
    /*!
 
102
      \internal
 
103
      */
 
104
    onAlignChanged: if (!internals.checkAlign()) console.log("Wrong alignment set to Scrollbar: "+align)
 
105
 
 
106
    /*!
 
107
      \internal
 
108
      Internals: contains the common logic of the scrollbar like anchoring,
 
109
      alignemt check, scrollability check.
 
110
    */
 
111
    property alias __private: internals
 
112
    QtObject {
 
113
        id: internals
 
114
        property bool vertical: (align === Qt.AlignLeading) || (align === Qt.AlignTrailing)
 
115
        property bool scrollable: flickableItem && flickableItem.interactive && checkAlign()
 
116
 
 
117
        function checkAlign()
 
118
        {
 
119
            return (align === Qt.AlignLeading) || (align === Qt.AlignTrailing) || (align === Qt.AlignTop) || (align === Qt.AlignBottom);
 
120
        }
 
121
 
 
122
        // LTR and RTL are provided by LayoutMirroring, so no need to check that
 
123
        function leftAnchor(object)
 
124
        {
 
125
            if (!internals.vertical || (align == Qt.AlignLeading))
 
126
                return object.left;
 
127
            return undefined;
 
128
        }
 
129
        function rightAnchor(object)
 
130
        {
 
131
            if (!internals.vertical || (align == Qt.AlignTrailing))
 
132
                return object.right;
 
133
            return undefined;
 
134
        }
 
135
        function topAnchor(object)
 
136
        {
 
137
            if (internals.vertical || (align == Qt.AlignTop))
 
138
                return object.top;
 
139
            return undefined;
 
140
        }
 
141
        function bottomAnchor(object)
 
142
        {
 
143
            if (internals.vertical || (align == Qt.AlignBottom))
 
144
                return object.bottom;
 
145
            return undefined;
 
146
        }
 
147
    }
 
148
 
 
149
    theme.version: Toolkit.Ubuntu.toolkitVersion
 
150
    styleName: "ScrollbarStyle"
 
151
}