Plasma

ScrollViewStyle.qml
1 /*
2  SPDX-FileCopyrightText: 2012 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2014 David Edmundson <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 import QtQuick 2.0
9 import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
10 import QtQuick.Controls.Private 1.0
11 
12 import org.kde.plasma.core 2.0 as PlasmaCore
13 import org.kde.plasma.components 2.0 as PlasmaComponents
14 
15 QtQuickControlStyle.ScrollViewStyle {
16  property Flickable flickableItem: control.flickableItem
17 
18  property real widthHint: Math.round( (scrollbarSvg.hasElement("hint-scrollbar-size") ? scrollbarSvg.elementSize("hint-scrollbar-size").width : scrollbarSvg.elementSize("arrow-up").width))
19 
20  property StyleItem __styleitem: StyleItem { elementType: "frame" }
21  readonly property int __wheelScrollLines: __styleitem.styleHint("wheelScrollLines")
22 
23  transientScrollBars: Settings.hasTouchScreen && Settings.isMobile
24 
25  padding {
26  top: 0
27  left: 0
28  right: 0
29  bottom: 0
30  }
31 
32  function syncVelocity() {
33  if (!control.flickableItem) {
34  return;
35  }
36 
37  // QTBUG-35608
38  // default values are hardcoded in qtdeclarative/src/quick/items/qquickflickablebehavior_p.h
39  control.flickableItem.flickDeceleration = Math.round(1500 * units.devicePixelRatio);
40  // double maximum speed so it feels better
41  control.flickableItem.maximumFlickVelocity = Math.round(2500 * units.devicePixelRatio);
42 
43  control.flickableItem.interactive = true;
44  }
45 
46  Component.onCompleted: syncVelocity()
47  Connections {
48  target: control
49  onContentItemChanged: syncVelocity()
50  }
51 
52  frame: Item {
53  visible: frameVisible
54 
55  PlasmaCore.Svg {
56  id: borderSvg
57  imagePath: "widgets/scrollwidget"
58  colorGroup: PlasmaCore.ColorScope.colorGroup
59  }
60 
61  PlasmaCore.SvgItem {
62  visible: {
63  if (flickableItem.hasOwnProperty("orientation")) {
64  return (flickableItem.orientation === Qt.Vertical);
65  }
66 
67  return false;
68  }
69  svg: borderSvg
70  z: 1000
71  elementId: "border-top"
72  width: 100
73  height: naturalSize.height
74  opacity: !visible || flickableItem.atYBeginning ? 0 : 1
75  Behavior on opacity {
76  NumberAnimation {
77  duration: units.longDuration
78  easing.type: Easing.InOutQuad
79  }
80  }
81  anchors {
82  left: parent.left
83  top: parent.top
84  right: parent.right
85  }
86  }
87  PlasmaCore.SvgItem {
88  visible: {
89  if (flickableItem.hasOwnProperty("orientation")) {
90  return (flickableItem.orientation === Qt.Vertical);
91  }
92 
93  return false;
94  }
95  svg: borderSvg
96  z: 1000
97  elementId: "border-bottom"
98  width: 100
99  height: naturalSize.height
100  opacity: !visible || flickableItem.atYEnd ? 0 : 1
101  Behavior on opacity {
102  NumberAnimation {
103  duration: units.longDuration
104  easing.type: Easing.InOutQuad
105  }
106  }
107  anchors {
108  left: parent.left
109  bottom: parent.bottom
110  right: parent.right
111  }
112  }
113  PlasmaCore.SvgItem {
114  visible: {
115  if (flickableItem.hasOwnProperty("orientation")) {
116  return (flickableItem.orientation === Qt.Horizontal);
117  }
118 
119  return false;
120  }
121  svg: borderSvg
122  z: 1000
123  elementId: "border-left"
124  width: naturalSize.width
125  opacity: !visible || flickableItem.atXBeginning ? 0 : 1
126  Behavior on opacity {
127  NumberAnimation {
128  duration: units.longDuration
129  easing.type: Easing.InOutQuad
130  }
131  }
132  anchors {
133  left: parent.left
134  top: parent.top
135  bottom: parent.bottom
136  }
137  }
138  PlasmaCore.SvgItem {
139  visible: {
140  if (flickableItem.hasOwnProperty("orientation")) {
141  return (flickableItem.orientation === Qt.Horizontal);
142  }
143 
144  return false;
145  }
146  svg: borderSvg
147  z: 1000
148  elementId: "border-right"
149  width: naturalSize.width
150  opacity: !visible || flickableItem.atXEnd ? 0 : 1
151  Behavior on opacity {
152  NumberAnimation {
153  duration: units.longDuration
154  easing.type: Easing.InOutQuad
155  }
156  }
157  anchors {
158  top: parent.top
159  bottom: parent.bottom
160  right: parent.right
161  }
162  }
163  }
164 
165  scrollBarBackground: PlasmaCore.FrameSvgItem {
166  imagePath:"widgets/scrollbar"
167  prefix: styleData.horizontal ? "background-horizontal" : "background-vertical"
168  implicitWidth: widthHint
169  colorGroup: PlasmaCore.ColorScope.colorGroup
170  opacity: styleData.hovered ? 1 : 0
171  Behavior on opacity {
172  NumberAnimation {
173  duration: units.longDuration
174  easing.type: Easing.InOutQuad
175  }
176  }
177  }
178 
179  handle: PlasmaCore.FrameSvgItem {
180  imagePath:"widgets/scrollbar"
181  implicitWidth: widthHint
182  implicitHeight: widthHint
183  colorGroup: PlasmaCore.ColorScope.colorGroup
184 
185  prefix: {
186  if (styleData.hovered) {
187  return "sunken-slider"
188  }
189  if (styleData.pressed) {
190  return "mouseover-slider"
191  } else {
192  return "slider"
193  }
194  }
195  }
196 
197  incrementControl: PlasmaCore.SvgItem {
198  svg: scrollbarSvg
199  visible: scrollbarSvg.arrowPresent
200  //if there is no arrow we don't want to waste space, a tiny margin does look better though
201  implicitWidth: scrollbarSvg.arrowPresent ? widthHint : units.smallSpacing
202  implicitHeight: scrollbarSvg.arrowPresent ? widthHint : units.smallSpacing
203  elementId: {
204  if (styleData.pressed) {
205  return styleData.horizontal ? "sunken-arrow-right" : "sunken-arrow-down"
206  }
207  if (styleData.hovered) {
208  return styleData.horizontal ? "mouseover-arrow-right" : "mouseover-arrow-down"
209  } else {
210  return styleData.horizontal ? "arrow-right" : "arrow-down"
211  }
212  }
213  }
214 
215  decrementControl: PlasmaCore.SvgItem {
216  svg: scrollbarSvg
217  visible: scrollbarSvg.arrowPresent
218  implicitWidth: scrollbarSvg.arrowPresent ? widthHint : units.smallSpacing
219  implicitHeight: scrollbarSvg.arrowPresent ? widthHint : units.smallSpacing
220  elementId: {
221  if (styleData.pressed) {
222  return styleData.horizontal ? "sunken-arrow-left" : "sunken-arrow-up"
223  }
224  if (styleData.hovered) {
225  return styleData.horizontal ? "mouseover-arrow-left" : "mouseover-arrow-up"
226  } else {
227  return styleData.horizontal ? "arrow-left" : "arrow-up"
228  }
229  }
230  }
231 
232  PlasmaCore.Svg {
233  id: scrollbarSvg
234  imagePath: "widgets/scrollbar"
235  property bool arrowPresent: scrollbarSvg.hasElement("arrow-up")
236  //new theme may be different
237  onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up")
238  }
239 }
QTextStream & left(QTextStream &s)
bool isMobile
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Sep 20 2020 22:40:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.