• 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
  • private
ScrollBarDelegate.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 
24 
25 PlasmaCore.FrameSvgItem {
26  id: background
27  anchors.fill: parent
28  imagePath:"widgets/scrollbar"
29  prefix: internalLoader.isVertical ? "background-vertical" : "background-horizontal"
30 
31  property int implicitWidth: scrollbarSvg.hasElement("hint-scrollbar-size") ? scrollbarSvg.elementSize("hint-scrollbar-size").width : scrollbarSvg.elementSize("arrow-up").width
32  property int implicitHeight: scrollbarSvg.hasElement("hint-scrollbar-size") ? scrollbarSvg.elementSize("hint-scrollbar-size").height : scrollbarSvg.elementSize("arrow-left").height
33 
34  Keys.onUpPressed: {
35  if (!enabled || !internalLoader.isVertical)
36  return;
37 
38  if (inverted)
39  internalLoader.incrementValue(stepSize);
40  else
41  internalLoader.incrementValue(-stepSize);
42  }
43 
44  Keys.onDownPressed: {
45  if (!enabled || !internalLoader.isVertical)
46  return;
47 
48  if (inverted)
49  internalLoader.incrementValue(-stepSize);
50  else
51  internalLoader.incrementValue(stepSize);
52  }
53 
54  Keys.onLeftPressed: {
55  if (!enabled || internalLoader.isVertical)
56  return;
57 
58  if (inverted)
59  internalLoader.incrementValue(stepSize);
60  else
61  internalLoader.incrementValue(-stepSize);
62  }
63 
64  Keys.onRightPressed: {
65  if (!enabled || internalLoader.isVertical)
66  return;
67 
68  if (inverted)
69  internalLoader.incrementValue(-stepSize);
70  else
71  internalLoader.incrementValue(stepSize);
72  }
73 
74  property Item handle: handle
75 
76  property Item contents: contents
77  Item {
78  id: contents
79  anchors {
80  fill: parent
81  leftMargin: (!internalLoader.isVertical && leftButton.visible) ? leftButton.width : 0
82  rightMargin: (!internalLoader.isVertical && rightButton.visible) ? rightButton.width : 0
83  topMargin: (internalLoader.isVertical && leftButton.visible) ? leftButton.height : 0
84  bottomMargin: (internalLoader.isVertical && rightButton.visible) ? rightButton.height : 0
85  }
86 
87  PlasmaCore.FrameSvgItem {
88  id: handle
89  imagePath:"widgets/scrollbar"
90  prefix: {
91  if (mouseArea.pressed) {
92  return "sunken-slider"
93  }
94 
95  if (scrollbar.activeFocus || mouseArea.containsMouse) {
96  return "mouseover-slider"
97  } else {
98  return "slider"
99  }
100  }
101 
102  property int length: internalLoader.isVertical? flickableItem.visibleArea.heightRatio * parent.height : flickableItem.visibleArea.widthRatio * parent.width
103 
104  width: internalLoader.isVertical ? parent.width : length
105  height: internalLoader.isVertical ? length : parent.height
106  }
107  }
108 
109  PlasmaCore.Svg {
110  id: scrollbarSvg
111  imagePath: "widgets/scrollbar"
112  property bool arrowPresent: scrollbarSvg.hasElement("arrow-up")
113  //new theme may be different
114  onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up")
115  }
116 
117  PlasmaCore.SvgItem {
118  id: leftButton
119  visible: stepSize > 0 && scrollbarSvg.arrowPresent
120 
121  anchors {
122  left: internalLoader.isVertical ? undefined : parent.left
123  verticalCenter: internalLoader.isVertical ? undefined : parent.verticalCenter
124  top: internalLoader.isVertical ? parent.top : undefined
125  horizontalCenter: internalLoader.isVertical ? parent.horizontalCenter : undefined
126  }
127  width: 18
128  height: 18
129  svg: scrollbarSvg
130  elementId: {
131  if (leftMouseArea.pressed) {
132  return internalLoader.isVertical ? "sunken-arrow-up" : "sunken-arrow-left"
133  }
134 
135  if (scrollbar.activeFocus || leftMouseArea.containsMouse) {
136  return internalLoader.isVertical ? "mouseover-arrow-up" : "mouseover-arrow-left"
137  } else {
138  return internalLoader.isVertical ? "arrow-up" : "arrow-left"
139  }
140  }
141 
142  MouseArea {
143  id: leftMouseArea
144 
145  anchors.fill: parent
146  enabled: scrollbar.enabled
147  hoverEnabled: true
148 
149  Timer {
150  id: leftTimer
151  interval: scrollbar.scrollButtonInterval;
152  running: parent.pressed
153  repeat: true
154  triggeredOnStart: true
155  onTriggered: {
156  background.forceActiveFocus()
157  if (inverted) {
158  internalLoader.incrementValue(stepSize);
159  } else {
160  internalLoader.incrementValue(-stepSize);
161  }
162  }
163  }
164  }
165  }
166 
167  PlasmaCore.SvgItem {
168  id: rightButton
169  visible: leftButton.visible
170 
171  anchors {
172  right: internalLoader.isVertical ? undefined : parent.right
173  verticalCenter: internalLoader.isVertical ? undefined : parent.verticalCenter
174  bottom: internalLoader.isVertical ? parent.bottom : undefined
175  horizontalCenter: internalLoader.isVertical ? parent.horizontalCenter : undefined
176  }
177  width: 18
178  height: 18
179  svg: scrollbarSvg
180  elementId: {
181  if (rightMouseArea.pressed) {
182  return internalLoader.isVertical ? "sunken-arrow-down" : "sunken-arrow-right"
183  }
184 
185  if (scrollbar.activeFocus || rightMouseArea.containsMouse) {
186  return internalLoader.isVertical ? "mouseover-arrow-down" : "mouseover-arrow-right"
187  } else {
188  return internalLoader.isVertical ? "arrow-down" : "arrow-right"
189  }
190  }
191 
192  MouseArea {
193  id: rightMouseArea
194 
195  anchors.fill: parent
196  enabled: scrollbar.enabled
197  hoverEnabled: true
198 
199  Timer {
200  id: rightTimer
201  interval: scrollbar.scrollButtonInterval;
202  running: parent.pressed;
203  repeat: true
204  triggeredOnStart: true
205  onTriggered: {
206  background.forceActiveFocus();
207  if (inverted)
208  internalLoader.incrementValue(-stepSize);
209  else
210  internalLoader.incrementValue(stepSize);
211  }
212  }
213  }
214  }
215 
216  property MouseArea mouseArea: mouseArea
217  MouseArea {
218  id: mouseArea
219 
220  anchors.fill: contents
221  enabled: scrollbar.enabled
222  hoverEnabled: true
223  drag {
224  target: handle
225  axis: internalLoader.isVertical ? Drag.YAxis : Drag.XAxis
226  minimumX: range.positionAtMinimum
227  maximumX: range.positionAtMaximum
228  minimumY: range.positionAtMinimum
229  maximumY: range.positionAtMaximum
230  }
231 
232  onPressed: {
233  if (internalLoader.isVertical) {
234  // Clamp the value
235  var newY = Math.max(mouse.y, drag.minimumY);
236  newY = Math.min(newY, drag.maximumY);
237 
238  // Debounce the press: a press event inside the handler will not
239  // change its position, the user needs to drag it.
240  if (newY > handle.y + handle.height) {
241  handle.y = mouse.y - handle.height
242  } else if (newY < handle.y) {
243  handle.y = mouse.y
244  }
245  } else {
246  // Clamp the value
247  var newX = Math.max(mouse.x, drag.minimumX);
248  newX = Math.min(newX, drag.maximumX);
249 
250  // Debounce the press: a press event inside the handler will not
251  // change its position, the user needs to drag it.
252  if (newX > handle.x + handle.width) {
253  handle.x = mouse.x - handle.width
254  } else if (newX < handle.x) {
255  handle.x = mouse.x
256  }
257  }
258 
259  background.forceActiveFocus();
260  }
261 
262  Component.onCompleted: {
263  acceptedButtons |= Qt.MiddleButton
264  }
265  }
266 }
267 
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