~ubuntu-sdk-team/ubuntu-ui-toolkit/trunk

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Christian Dywan, Zsombor Egri, Zoltán Balogh, Tim Peeters, Albert Astals Cid, Michael Sheldon, Benjamin Zeller
  • Date: 2015-12-17 17:13:49 UTC
  • mfrom: (1000.739.27 OTA9-landing-2015-12-16)
  • Revision ID: ci-train-bot@canonical.com-20151217171349-8xwclnhnx8v9oz4m
OTA9-landing-2015-12-16
Approved by: Zoltan Balogh

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    id: scrollbar
64
64
 
65
65
    /*!
 
66
        \qmlproperty Flickable Scrollbar::flickableItem
66
67
        This property holds the flickable item (Flickable, ListView or GridView)
67
68
        the Scrollbar is attached to.
68
69
      */
69
70
    property Flickable flickableItem: null
70
71
 
 
72
    /*
 
73
        This property holds the other scrollbar that is attached to the same flickable,
 
74
        if any. For instance, if this scrollbar is horizontal, buddyScrollbar must be set
 
75
        to the vertical scrollbar, if any. This is to allow a correct layout of both
 
76
        horizontal and vertical scrollbars when a view is scrollable in both directions.
 
77
    */
 
78
    //can't use property Scrollbar here as it would complain "Scrollbar instantiated recursively"
 
79
    property var __buddyScrollbar: null
 
80
 
71
81
    /*!
 
82
      \qmlproperty int Scrollbar::align
72
83
      The property defines the alignment of the scrollbar to the flickableItem.
73
84
      The implementation handles the alignment as follows:
74
85
        \list
88
99
    */
89
100
    property bool __interactive: __styleInstance !== null && __styleInstance.interactive
90
101
 
91
 
    implicitWidth: internals.vertical ? units.gu(4) : flickableItem.width
92
 
    implicitHeight: !internals.vertical ? units.gu(4) : flickableItem.height
 
102
 
 
103
    /*!
 
104
      \internal
 
105
      This trough of the scrollbar, it is used to define the position of the slider.
 
106
    */
 
107
    property Item __trough: __styleInstance !== null && __styleInstance.trough
 
108
 
 
109
 
 
110
    /*!
 
111
      \internal
 
112
      simulate the system setting (which will be implemented in unity8, I guess)
 
113
      True --> Steppers style, non-overlay scrollbars
 
114
      False --> Indicator and Trough styles
 
115
    */
 
116
    property bool __alwaysOnScrollbars: false
 
117
 
 
118
    /*! internal
 
119
      Used by ScrollView to tweak Scrollbar's anchoring logic for the always-on scrollbars.
 
120
    */
 
121
    property Item __viewport: null
 
122
 
 
123
    //Disable the input handling to let the events pass through in case we have an
 
124
    //interactive scrollbar right below us (can happen with nested views)
 
125
    enabled: __interactive//&& __alwaysOnScrollbars
 
126
 
 
127
    implicitWidth: internals.vertical ? units.gu(3) : flickableItem.width
 
128
    implicitHeight: !internals.vertical ? units.gu(3) : flickableItem.height
93
129
 
94
130
    anchors {
95
 
        left: internals.leftAnchor(flickableItem)
96
 
        right: internals.rightAnchor(flickableItem)
97
 
        top: internals.topAnchor(flickableItem)
98
 
        bottom: internals.bottomAnchor(flickableItem)
 
131
        left: internals.leftAnchor(__viewport ? __viewport : flickableItem)
 
132
        leftMargin: internals.leftAnchorMargin()
 
133
        right: internals.rightAnchor(__viewport ? __viewport : flickableItem)
 
134
        rightMargin: internals.rightAnchorMargin()
 
135
        top: internals.topAnchor(__viewport ? __viewport : flickableItem)
 
136
        topMargin: internals.topAnchorMargin()
 
137
        bottom: internals.bottomAnchor(__viewport ? __viewport : flickableItem)
 
138
        bottomMargin: internals.bottomAnchorMargin()
99
139
    }
100
140
 
101
141
    /*!
113
153
        id: internals
114
154
        property bool vertical: (align === Qt.AlignLeading) || (align === Qt.AlignTrailing)
115
155
        property bool scrollable: flickableItem && flickableItem.interactive && checkAlign()
 
156
        property real nonOverlayScrollbarMargin: __styleInstance ? __styleInstance.nonOverlayScrollbarMargin : 0
116
157
 
117
158
        function checkAlign()
118
159
        {
122
163
        // LTR and RTL are provided by LayoutMirroring, so no need to check that
123
164
        function leftAnchor(object)
124
165
        {
125
 
            if (!internals.vertical || (align == Qt.AlignLeading))
 
166
            if (!internals.vertical || (align == Qt.AlignLeading)) {
126
167
                return object.left;
 
168
            }
127
169
            return undefined;
128
170
        }
 
171
        function leftAnchorMargin()
 
172
        {
 
173
            if (__styleInstance === null) return 0
 
174
 
 
175
            switch (align) {
 
176
            case Qt.AlignLeading:
 
177
                return __alwaysOnScrollbars ? -nonOverlayScrollbarMargin : 0
 
178
            case Qt.AlignBottom:
 
179
            case Qt.AlignTop:
 
180
                if (!__alwaysOnScrollbars && __buddyScrollbar !== null
 
181
                        && __buddyScrollbar.align === Qt.AlignLeading
 
182
                        && __buddyScrollbar.__styleInstance.isScrollable)
 
183
                    return __buddyScrollbar.__styleInstance.troughThicknessSteppersStyle
 
184
                    //return buddyScrollbar.__styleInstance.indicatorThickness
 
185
                // *ELSE FALLTHROUGH*
 
186
            default:
 
187
                return 0
 
188
            }
 
189
        }
129
190
        function rightAnchor(object)
130
191
        {
131
 
            if (!internals.vertical || (align == Qt.AlignTrailing))
 
192
            if (!internals.vertical || (align == Qt.AlignTrailing)) {
132
193
                return object.right;
 
194
            }
133
195
            return undefined;
134
196
        }
 
197
        function rightAnchorMargin()
 
198
        {
 
199
            if (__styleInstance === null) return 0
 
200
 
 
201
            switch (align) {
 
202
            case Qt.AlignTrailing:
 
203
                return __alwaysOnScrollbars ? -nonOverlayScrollbarMargin : 0
 
204
            case Qt.AlignBottom:
 
205
            case Qt.AlignTop:
 
206
                if (!__alwaysOnScrollbars && __buddyScrollbar !== null
 
207
                        && __buddyScrollbar.align === Qt.AlignTrailing
 
208
                        && __buddyScrollbar.__styleInstance.isScrollable)
 
209
                    return __buddyScrollbar.__styleInstance.troughThicknessSteppersStyle
 
210
                    //return buddyScrollbar.__styleInstance.indicatorThickness
 
211
                // *ELSE FALLTHROUGH*
 
212
            default:
 
213
                return 0
 
214
            }
 
215
        }
135
216
        function topAnchor(object)
136
217
        {
137
218
            if (internals.vertical || (align == Qt.AlignTop))
138
219
                return object.top;
139
220
            return undefined;
140
221
        }
 
222
        function topAnchorMargin()
 
223
        {
 
224
            if (__styleInstance === null) return 0
 
225
 
 
226
            switch (align) {
 
227
            case Qt.AlignTop:
 
228
                return __alwaysOnScrollbars ? -nonOverlayScrollbarMargin : 0
 
229
            case Qt.AlignLeading:
 
230
            case Qt.AlignTrailing:
 
231
                if (!__alwaysOnScrollbars && __buddyScrollbar !== null
 
232
                        && __buddyScrollbar.align === Qt.AlignTop
 
233
                        && __buddyScrollbar.__styleInstance.isScrollable)
 
234
                    return __buddyScrollbar.__styleInstance.troughThicknessSteppersStyle
 
235
                    //return buddyScrollbar.__styleInstance.indicatorThickness
 
236
                // *ELSE FALLTHROUGH*
 
237
 
 
238
            default:
 
239
                return 0
 
240
            }
 
241
        }
141
242
        function bottomAnchor(object)
142
243
        {
143
244
            if (internals.vertical || (align == Qt.AlignBottom))
144
245
                return object.bottom;
145
246
            return undefined;
146
247
        }
 
248
        function bottomAnchorMargin()
 
249
        {
 
250
            if (__styleInstance === null) return 0
 
251
 
 
252
            switch (align) {
 
253
            case Qt.AlignBottom:
 
254
                return __alwaysOnScrollbars ? -nonOverlayScrollbarMargin : 0
 
255
            case Qt.AlignLeading:
 
256
            case Qt.AlignTrailing:
 
257
                if (!__alwaysOnScrollbars && __buddyScrollbar !== null
 
258
                        && __buddyScrollbar.align === Qt.AlignBottom
 
259
                        && __buddyScrollbar.__styleInstance.isScrollable)
 
260
                    return __buddyScrollbar.__styleInstance.troughThicknessSteppersStyle
 
261
                    //return buddyScrollbar.__styleInstance.indicatorThickness
 
262
                // *ELSE FALLTHROUGH*
 
263
            default:
 
264
                return 0
 
265
            }
 
266
        }
147
267
    }
148
268
 
149
269
    styleName: "ScrollbarStyle"