Changeset View
Changeset View
Standalone View
Standalone View
org.kde.desktop/ScrollView.qml
Show All 16 Lines | |||||
17 | * the packaging of this file. Please review the following information to | 17 | * the packaging of this file. Please review the following information to | ||
18 | * ensure the GNU General Public License version 2.0 requirements will be | 18 | * ensure the GNU General Public License version 2.0 requirements will be | ||
19 | * met: http://www.gnu.org/licenses/gpl-2.0.html. | 19 | * met: http://www.gnu.org/licenses/gpl-2.0.html. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | 22 | | |||
23 | import QtQuick 2.9 | 23 | import QtQuick 2.9 | ||
24 | import QtQuick.Controls 2.2 | 24 | import QtQuick.Controls 2.2 | ||
25 | //import QtQuick.Controls.impl 2.2 | | |||
26 | import QtQuick.Templates 2.2 as T | 25 | import QtQuick.Templates 2.2 as T | ||
26 | import org.kde.kirigami 2.2 as Kirigami | ||||
27 | import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate | ||||
27 | 28 | | |||
28 | T.ScrollView { | 29 | T.ScrollView { | ||
29 | id: control | 30 | id: controlRoot | ||
30 | 31 | | |||
31 | clip: true | 32 | clip: true | ||
32 | 33 | | |||
33 | implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) | 34 | implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) | ||
34 | implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) | 35 | implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) | ||
35 | 36 | | |||
36 | contentWidth: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentWidth : 0 | 37 | contentWidth: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentWidth : 0 | ||
37 | contentHeight: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentHeight : 0 | 38 | contentHeight: scrollHelper.flickableItem ? scrollHelper.flickableItem.contentHeight : 0 | ||
38 | 39 | | |||
40 | Kirigami.Theme.colorSet: Kirigami.Theme.View | ||||
41 | Kirigami.Theme.inherit: background.visible | ||||
42 | | ||||
43 | //create a background only after Component.onCompleted, see on the component creation below for explanation | ||||
44 | Component.onCompleted: { | ||||
45 | if (!controlRoot.background) { | ||||
46 | controlRoot.background = backgroundComponent.createObject(controlRoot); | ||||
47 | print(controlRoot.background.width); | ||||
davidedmundson: As in a textedit?
The QQC1 code used "frame" which is semantically more appropriate.
Did you… | |||||
48 | } | ||||
49 | } | ||||
50 | | ||||
39 | onChildrenChanged: { | 51 | onChildrenChanged: { | ||
40 | if (control.children[control.children.length - 1].hasOwnProperty("contentY")) { | 52 | if (controlRoot.children[controlRoot.children.length - 1].hasOwnProperty("contentY")) { | ||
41 | scrollHelper.flickableItem = control.children[control.children.length - 1]; | 53 | scrollHelper.flickableItem = controlRoot.children[controlRoot.children.length - 1]; | ||
42 | } | 54 | } | ||
43 | } | 55 | } | ||
56 | | ||||
44 | children: [ | 57 | children: [ | ||
45 | MouseArea { | 58 | MouseArea { | ||
46 | id: scrollHelper | 59 | id: scrollHelper | ||
47 | anchors.fill: parent | 60 | anchors.fill: parent | ||
48 | drag.filterChildren: !isMobile | 61 | drag.filterChildren: !isMobile | ||
49 | property bool isMobile: !verticalScrollBar.interactive | 62 | property bool isMobile: !verticalScrollBar.interactive | ||
50 | onIsMobileChanged: { | 63 | onIsMobileChanged: { | ||
51 | flickableItem.boundsBehavior = scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; | 64 | flickableItem.boundsBehavior = scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; | ||
52 | flickableItem.interactive = scrollHelper.isMobile; | 65 | flickableItem.interactive = scrollHelper.isMobile; | ||
53 | } | 66 | } | ||
54 | property Flickable flickableItem | 67 | property Flickable flickableItem | ||
55 | onFlickableItemChanged: { | 68 | onFlickableItemChanged: { | ||
56 | flickableItem.parent = scrollHelper; | 69 | flickableItem.parent = scrollHelper; | ||
57 | flickableItem.boundsBehavior = scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; | 70 | flickableItem.boundsBehavior = Qt.binding(function() { return scrollHelper.isMobile ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds; }); | ||
58 | flickableItem.interactive = scrollHelper.isMobile; | 71 | flickableItem.interactive = Qt.binding(function() { return scrollHelper.isMobile; }); | ||
72 | | ||||
73 | flickableItem.anchors.fill = scrollHelper; | ||||
74 | //don't make the scrolling items overlap the background borders. | ||||
75 | flickableItem.anchors.margins = Qt.binding(function() { return controlRoot.background && controlRoot.background.visible ? 2 : 0; }); | ||||
76 | flickableItem.clip = true; | ||||
59 | } | 77 | } | ||
60 | onWheel: { | 78 | onWheel: { | ||
61 | if (isMobile || flickableItem.contentHeight < flickableItem.height) { | 79 | if (isMobile || flickableItem.contentHeight < flickableItem.height) { | ||
62 | return; | 80 | return; | ||
63 | } | 81 | } | ||
64 | //TODO: use kirigami for this more granular control | 82 | //TODO: use kirigami for this more granular control | ||
davidedmundson: :D
maybe don't find and replace this | |||||
65 | /* var sampleItem = flickableItem.itemAt ? flickableItem.itemAt(0,flickableItem.contentY) : null; | 83 | /* var sampleItem = flickableItem.itemAt ? flickableItem.itemAt(0,flickableItem.contentY) : null; | ||
66 | var step = Math.min((sampleItem ? sampleItem.height : (Units.gridUnit + Units.smallSpacing * 2)) * Units.wheelScrollLines, Units.gridUnit * 8); | 84 | var step = Math.min((sampleItem ? sampleItem.height : (Units.gridUnit + Units.smallSpacing * 2)) * Units.wheelScrollLines, Units.gridUnit * 8); | ||
67 | //TODO: config of how many lines the wheel scrolls | 85 | //TODO: config of how many lines the wheel scrolls | ||
68 | var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : (wheel.angleDelta.y > 0 ? step : -step)*/ | 86 | var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : (wheel.angleDelta.y > 0 ? step : -step)*/ | ||
69 | var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : wheel.angleDelta.y / 8 | 87 | var y = wheel.pixelDelta.y != 0 ? wheel.pixelDelta.y : wheel.angleDelta.y / 8 | ||
70 | 88 | | |||
71 | var minYExtent = flickableItem.topMargin - flickableItem.originY; | 89 | var minYExtent = flickableItem.topMargin - flickableItem.originY; | ||
72 | var maxYExtent = flickableItem.height - (flickableItem.contentHeight + flickableItem.bottomMargin + flickableItem.originY); | 90 | var maxYExtent = flickableItem.height - (flickableItem.contentHeight + flickableItem.bottomMargin + flickableItem.originY); | ||
73 | 91 | | |||
74 | flickableItem.contentY = Math.min(-maxYExtent, Math.max(-minYExtent, flickableItem.contentY - y)); | 92 | flickableItem.contentY = Math.min(-maxYExtent, Math.max(-minYExtent, flickableItem.contentY - y)); | ||
75 | 93 | | |||
76 | //this is just for making the scrollbar appear | 94 | //this is just for making the scrollbar appear | ||
77 | flickableItem.flick(0, 0); | 95 | flickableItem.flick(0, 0); | ||
78 | cancelFlickStateTimer.restart(); | 96 | cancelFlickStateTimer.restart(); | ||
79 | } | 97 | } | ||
80 | Timer { | 98 | Timer { | ||
81 | id: cancelFlickStateTimer | 99 | id: cancelFlickStateTimer | ||
82 | interval: 150 | 100 | interval: 150 | ||
83 | onTriggered: scrollHelper.flickableItem.cancelFlick() | 101 | onTriggered: scrollHelper.flickableItem.cancelFlick() | ||
84 | } | 102 | } | ||
103 | /*create a background only after Component.onCompleted because: | ||||
104 | * implementations can set their own background in a declarative way | ||||
105 | * ScrollView {background.visible: true} must *not* work, becasue all upstream styles don't have a background so applications using this would break with other styles | ||||
106 | * This is child of scrollHelper as it would break native scrollview finding of the flickable if it was a direct child | ||||
107 | */ | ||||
108 | Component { | ||||
109 | id: backgroundComponent | ||||
110 | StylePrivate.StyleItem { | ||||
111 | control: controlRoot | ||||
112 | elementType: "edit" | ||||
113 | //The default behavior goes from the following assumption: | ||||
114 | //if the scrollview takes all the possible space, the cutoff of the items scrolled away will be managed by the items nearby (or the window edge) | ||||
115 | //if the scrollview is smaller, we add a background to cleanly cut away | ||||
116 | //things half scrolled away | ||||
117 | visible: controlRoot.width < controlRoot.parent.width || controlRoot.height < controlRoot.parent.height | ||||
118 | sunken: true | ||||
119 | hasFocus: controlRoot.activeFocus || scrollHelper.flickableItem.activeFocus | ||||
120 | hover: controlRoot.hovered | ||||
121 | } | ||||
122 | } | ||||
85 | } | 123 | } | ||
86 | ] | 124 | ] | ||
87 | ScrollBar.vertical: ScrollBar { | 125 | ScrollBar.vertical: ScrollBar { | ||
88 | id: verticalScrollBar | 126 | id: verticalScrollBar | ||
89 | parent: control | 127 | parent: controlRoot | ||
90 | x: control.mirrored ? 0 : control.width - width | 128 | x: controlRoot.mirrored ? 0 : controlRoot.width - width | ||
91 | y: control.topPadding | 129 | y: controlRoot.topPadding | ||
92 | height: control.availableHeight | 130 | height: controlRoot.availableHeight | ||
93 | active: control.ScrollBar.horizontal || control.ScrollBar.horizontal.active | 131 | active: controlRoot.ScrollBar.horizontal || controlRoot.ScrollBar.horizontal.active | ||
94 | } | 132 | } | ||
95 | 133 | | |||
96 | ScrollBar.horizontal: ScrollBar { | 134 | ScrollBar.horizontal: ScrollBar { | ||
97 | parent: control | 135 | parent: controlRoot | ||
98 | x: control.leftPadding | 136 | x: controlRoot.leftPadding | ||
99 | y: control.height - height | 137 | y: controlRoot.height - height | ||
100 | width: control.availableWidth | 138 | width: controlRoot.availableWidth | ||
101 | active: control.ScrollBar.vertical || control.ScrollBar.vertical.active | 139 | active: controlRoot.ScrollBar.vertical || controlRoot.ScrollBar.vertical.active | ||
102 | } | 140 | } | ||
103 | } | 141 | } |
As in a textedit?
The QQC1 code used "frame" which is semantically more appropriate.
Did you do this to get the white background?
In QWidgets a scrollarea is transparent, and an itemview is white.
I think we might need some way (extra Kirigami class ?) to have both.
I suggest holding out on merging till we do a bit more KCM porting and figure that out.