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

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
  • qml
ScrollBar.qml
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
3 * Copyright (C) 2011 Marco Martin <mart@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as
7 * published by the Free Software Foundation; either version 2, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 import QtQuick 1.1
22 import org.kde.plasma.core 0.1 as PlasmaCore
23 import "private" as Private
24 
35 // TODO: add support mouse wheel events
36 Item {
37  id: scrollbar
38 
39  // Common API
43  property Flickable flickableItem: null
50  property int orientation: Qt.Vertical
51 
57  property bool interactive: true
58 
59  // Plasma API
66  property bool inverted: false
67 
76  property alias stepSize: range.stepSize
77 
81  property bool pressed: internalLoader.item.mouseArea?internalLoader.item.mouseArea.pressed:false
82 
87  property real scrollButtonInterval: 50
88 
89  implicitWidth: internalLoader.isVertical ? (internalLoader.item ? internalLoader.item.implicitWidth : 12) : 200
90  implicitHeight: internalLoader.isVertical ? 200 : (internalLoader.item ? internalLoader.item.implicitHeight : 12)
91  // TODO: needs to define if there will be specific graphics for
92  // disabled scroll bars
93  opacity: enabled ? 1.0 : 0.5
94 
95  visible: flickableItem && internalLoader.handleEnabled
96 
97  anchors {
98  right: internalLoader.anchorableWithFlickable ? flickableItem.right : undefined
99  left: (orientation == Qt.Vertical) ? undefined : (internalLoader.anchorableWithFlickable ? flickableItem.left : undefined)
100  top: (orientation == Qt.Vertical) ? (internalLoader.anchorableWithFlickable ? flickableItem.top : undefined) : undefined
101  bottom: internalLoader.anchorableWithFlickable ? flickableItem.bottom : undefined
102  }
103 
104  Loader {
105  id: internalLoader
106  anchors.fill: parent
107  //property bool handleEnabled: internalLoader.isVertical ? item.handle.height < item.contents.height : item.handle.width < item.contents.width
108  property bool handleEnabled: internalLoader.isVertical ? flickableItem.contentHeight > flickableItem.height : flickableItem.contentWidth > flickableItem.width
109  property bool isVertical: orientation == Qt.Vertical
110  property bool anchorableWithFlickable: scrollbar.parent == flickableItem || scrollbar.parent == flickableItem.parent
111 
112  function incrementValue(increment)
113  {
114  if (!flickableItem) {
115  return;
116  }
117 
118  if (internalLoader.isVertical) {
119  flickableItem.contentY = Math.max(0, Math.min(flickableItem.contentHeight - flickableItem.height,
120  flickableItem.contentY + increment));
121  } else {
122  flickableItem.contentX = Math.max(0, Math.min(flickableItem.contentWidth - flickableItem.width,
123  flickableItem.contentX + increment));
124  }
125  }
126 
127 
128  Connections {
129  target: flickableItem
130  onContentHeightChanged: {
131  range.value = flickableItem.contentY;
132  }
133  onContentYChanged: {
134  if (internalLoader.isVertical) {
135  range.value = flickableItem.contentY;
136  }
137  }
138  onContentXChanged: {
139  if (!internalLoader.isVertical) {
140  range.value = flickableItem.contentX;
141  }
142  }
143  }
144  Connections {
145  target: internalLoader.item.handle
146  onYChanged: updateFromHandleTimer.running = true
147  onXChanged: updateFromHandleTimer.running = true
148  }
149  RangeModel {
150  id: range
151 
152  minimumValue: 0
153  maximumValue: {
154  var diff;
155  if (internalLoader.isVertical) {
156  diff = flickableItem.contentHeight - flickableItem.height;
157  } else {
158  diff = flickableItem.contentWidth - flickableItem.width;
159  }
160 
161  return Math.max(0, diff);
162  }
163 
164  stepSize: 10
165  inverted: scrollbar.inverted
166  positionAtMinimum: 0
167  positionAtMaximum: {
168  if (internalLoader.isVertical) {
169  internalLoader.item.contents.height - internalLoader.item.handle.height;
170  } else {
171  internalLoader.item.contents.width - internalLoader.item.handle.width;
172  }
173  }
174 
175  onValueChanged: {
176  if (flickableItem.moving) {
177  return;
178  }
179 
180  if (internalLoader.isVertical) {
181  flickableItem.contentY = value;
182  } else {
183  flickableItem.contentX = value;
184  }
185  }
186 
187 
188  onPositionChanged: {
189  if (internalLoader.item.mouseArea && internalLoader.item.mouseArea.pressed) {
190  return;
191  }
192 
193  if (internalLoader.isVertical) {
194  internalLoader.item.handle.y = position;
195  } else {
196  internalLoader.item.handle.x = position; }
197  }
198  }
199 
200  Timer {
201  id: updateFromHandleTimer
202  interval: 10
203  onTriggered: {
204  if (!enabled || !interactive) {
205  return;
206  }
207 
208  if (internalLoader.isVertical) {
209  range.position = internalLoader.item.handle.y;
210  } else {
211  range.position = internalLoader.item.handle.x;
212  }
213  }
214  }
215 
216  source: interactive ? "private/ScrollBarDelegate.qml" : "private/ScrollDecoratorDelegate.qml"
217  }
218 }
Item
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

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

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