• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaExtraComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmaextracomponents
  • qml
ScrollArea.qml
Go to the documentation of this file.
1 /*
2 * Copyright 2012 Marco Martin <mart@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 import QtQuick 1.1
21 import org.kde.plasma.components 0.1 as PlasmaComponents
22 import org.kde.plasma.core 0.1 as PlasmaCore
23 
30 Item {
31  id: root
32 
37  property Flickable flickableItem
38  //FIXME: this alias seems necessary for it to correctly parse
39  default property alias flickableItemDefault: root.flickableItem
40 
41  Connections {
42  target: root
43  onFlickableItemChanged: {
44  root.flickableItem.parent = root
45  root.flickableItem.anchors.fill = root
46  root.flickableItem.clip = true
47  internal.checkVerticalScrollBar()
48  internal.checkHorizontalScrollBar()
49  }
50  }
51  Component.onCompleted: {
52  root.flickableItem.parent = root
53  root.flickableItem.anchors.fill = root
54  root.flickableItem.clip = true
55  internal.checkVerticalScrollBar()
56  internal.checkHorizontalScrollBar()
57  }
58  Connections {
59  target: flickableItem
60  onContentHeightChanged: internal.checkVerticalScrollBar()
61  onHeightChanged: internal.checkVerticalScrollBar()
62  onContentWidthChanged: internal.checkHorizontalScrollBar()
63  onWidthChanged: internal.checkHorizontalScrollBar()
64  }
65  QtObject {
66  id: internal
67  property Item verticalScrollBar
68  property Item horizontalScrollBar
69 
70  function checkVerticalScrollBar() {
71  if (!flickableItem) {
72  return
73  }
74 
75  if (flickableItem.contentHeight > flickableItem.height) {
76  //Do we have to change the type?
77  //from section to normal
78  if ((!flickableItem.model || flickableItem.model.get === undefined || !flickableItem.section || !flickableItem.section.property) &&
79  (!verticalScrollBar || verticalScrollBar.orientation === undefined)) {
80  if (verticalScrollBar) verticalScrollBar.destroy()
81  verticalScrollBar = verticalScrollBarComponent.createObject(root)
82  //from normal to section
83  } else if (flickableItem.section && flickableItem.section.property &&
84  flickableItem.model.get !== undefined &&
85  (!verticalScrollBar || verticalScrollBar.orientation !== undefined)) {
86  if (verticalScrollBar) verticalScrollBar.destroy()
87  verticalScrollBar = sectionScrollerComponent.createObject(root)
88  }
89  }
90  checkVerticalScrollBarMargins()
91  }
92 
93  function checkVerticalScrollBarMargins() {
94  //undefined in case of SectionScroller
95  if ((flickableItem.contentHeight > flickableItem.height) && verticalScrollBar &&
96  ((verticalScrollBar.interactive && verticalScrollBar.visible) || (verticalScrollBar.orientation === undefined &&
97  //FIXME: heuristic on width to distinguish the touch sectionscroller
98  verticalScrollBar.width < 30))) {
99  flickableItem.anchors.rightMargin = verticalScrollBar.width
100  } else {
101  flickableItem.anchors.rightMargin = 0
102  }
103  }
104 
105  function checkHorizontalScrollBar() {
106  if (!flickableItem || horizontalScrollBar) {
107  return
108  }
109 
110  if (flickableItem.contentWidth > flickableItem.width) {
111  if (!horizontalScrollBar) {
112  horizontalScrollBar = horizontalScrollBarComponent.createObject(root)
113  }
114  }
115  checkHorizontalScrollBarMargins()
116  }
117 
118  function checkHorizontalScrollBarMargins() {
119  if ((flickableItem.contentWidth > flickableItem.width) &&
120  horizontalScrollBar && horizontalScrollBar.interactive && horizontalScrollBar.visible) {
121  flickableItem.anchors.bottomMargin = horizontalScrollBar.height
122  } else {
123  flickableItem.anchors.bottomMargin = 0
124  }
125  }
126  }
127  Component {
128  id: verticalScrollBarComponent
129  PlasmaComponents.ScrollBar {
130  flickableItem: root.flickableItem
131  orientation: Qt.Vertical
132  property bool isScrollBar: true
133  z: root.flickableItem.z + 1
134  anchors {
135  left: undefined
136  top: root.top
137  right: root.right
138  bottom: root.bottom
139  bottomMargin: root.height - root.flickableItem.height
140  }
141  onVisibleChanged: internal.checkVerticalScrollBarMargins()
142  }
143  }
144  Component {
145  id: horizontalScrollBarComponent
146  PlasmaComponents.ScrollBar {
147  flickableItem: root.flickableItem
148  orientation: Qt.Horizontal
149  z: root.flickableItem.z + 1
150  anchors {
151  left: root.left
152  top: undefined
153  right: root.right
154  bottom: root.bottom
155  rightMargin: root.width - root.flickableItem.width
156  }
157  onVisibleChanged: internal.checkHorizontalScrollBarMargins()
158  }
159  }
160  Component {
161  id: sectionScrollerComponent
162  PlasmaComponents.SectionScroller {
163  listView: root.flickableItem
164  property bool isScrollBar: false
165  z: root.flickableItem.z + 1
166  anchors {
167  left: undefined
168  top: root.top
169  right: root.right
170  bottom: root.bottom
171  bottomMargin: root.height - root.flickableItem.height
172  }
173  onVisibleChanged: internal.checkVerticalScrollBarMargins()
174  }
175  }
176  //FIXME: create all this stuff only on demand, like scrollbars?
177  PlasmaCore.Svg {
178  id: borderSvg
179  imagePath: "widgets/scrollwidget"
180  }
181  PlasmaCore.SvgItem {
182  svg: borderSvg
183  z: 1000
184  elementId: "border-top"
185  width: 100
186  height: naturalSize.height
187  opacity: flickableItem.atYBeginning ? 0 : 1
188  Behavior on opacity {
189  NumberAnimation {
190  duration: 250
191  easing.type: Easing.InOutQuad
192  }
193  }
194  anchors {
195  left: parent.left
196  top: parent.top
197  right: parent.right
198  topMargin: flickableItem.anchors.topMargin
199  }
200  }
201  PlasmaCore.SvgItem {
202  svg: borderSvg
203  z: 1000
204  elementId: "border-bottom"
205  width: 100
206  height: naturalSize.height
207  opacity: flickableItem.atYEnd ? 0 : 1
208  Behavior on opacity {
209  NumberAnimation {
210  duration: 250
211  easing.type: Easing.InOutQuad
212  }
213  }
214  anchors {
215  left: parent.left
216  bottom: parent.bottom
217  right: parent.right
218  bottomMargin: flickableItem.anchors.bottomMargin
219  }
220  }
221  PlasmaCore.SvgItem {
222  svg: borderSvg
223  z: 1000
224  elementId: "border-left"
225  width: naturalSize.width
226  opacity: flickableItem.atXBeginning ? 0 : 1
227  Behavior on opacity {
228  NumberAnimation {
229  duration: 250
230  easing.type: Easing.InOutQuad
231  }
232  }
233  anchors {
234  left: parent.left
235  top: parent.top
236  bottom: parent.bottom
237  leftMargin: flickableItem.anchors.leftMargin
238  }
239  }
240  PlasmaCore.SvgItem {
241  svg: borderSvg
242  z: 1000
243  elementId: "border-right"
244  width: naturalSize.width
245  opacity: flickableItem.atXEnd ? 0 : 1
246  Behavior on opacity {
247  NumberAnimation {
248  duration: 250
249  easing.type: Easing.InOutQuad
250  }
251  }
252  anchors {
253  top: parent.top
254  bottom: parent.bottom
255  right: parent.right
256  rightMargin: flickableItem.anchors.rightMargin
257  }
258  }
259 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:46 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaExtraComponents

Skip menu "PlasmaExtraComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal