/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components/Themes/Ambiance/1.2/PullToRefreshStyle.qml is in ubuntu-ui-toolkit-theme 1.3.1918+16.04.20160404-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | /*
* Copyright 2014 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Ubuntu.Components 1.2
import Ubuntu.Components.Styles 1.2 as Style
Style.PullToRefreshStyle {
id: style
implicitHeight: refreshIndicatorItem.height + units.gu(5)
defaultContent: Label {
id: labelComponent
visible: control.enabled
text: releaseToRefresh ? i18n.tr("Release to refresh...") : i18n.tr("Pull to refresh...")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Behavior on text {
SequentialAnimation {
UbuntuNumberAnimation {
target: labelComponent
property: "opacity"
from: 1.0
to: 0.0
}
UbuntuNumberAnimation {
target: labelComponent
property: "opacity"
from: 0.0
to: 1.0
}
}
}
}
// additional configuration properties provided by the Ambiance theme
// these properties can be used by the deriving themes to configure the label
// and the activity indicator
property Item label: contentLoader.item
property alias refreshIndicator: refreshIndicatorItem
/*
Local properties
*/
readonly property PullToRefresh control: styledItem
// property to store Flickable's toipMargin at the time the pull or auto-refresh is started
property real flickableTopMargin: 0.0
// store when the drag has happened at the beginning of the Flickable's content
property bool wasAtYBeginning: false
// initial contentY value when pull started
property real initialContentY: 0.0
// drives the refreshing state
property bool refreshing: false
// point of release used in rebind animation between the ready-to-refresh and refreshing states
property real pointOfRelease
// specifies the component completion
property bool ready: false
// root item
property Item rootItem: QuickUtils.rootItem(control)
anchors.fill: parent
Component.onCompleted: {
/*
When the model attached to the component is refreshing during initialization,
this refresh will happen after the style gets completed. This refresh will
cause the style to enter in refreshing state, which alters the topMargin.
However in the same time the MainView Header will be also updated, so that
will also alter the topMargin. But when refreshing completes, the topMargin
will be restored to the default value before the animation, and the content
will be pushed under the header. We need to connect to the header changes
so we can reset the state and the topMargin.
*/
if (rootItem && rootItem.__propagated && rootItem.__propagated.header) {
rootItem.__propagated.header.visibleChanged.connect(fixTopMargin);
rootItem.__propagated.header.heightChanged.connect(fixTopMargin);
}
ready = true;
}
function fixTopMargin() {
if (style.state === "refreshing") {
/*
Fetch the topMargin, force state to disabled (idle will be turned on
automatically when refreshing completes) and set the topMargin from
the header change.
*/
var topMargin = control.target.topMargin;
style.state = "disabled";
control.target.topMargin = topMargin;
}
}
// visuals
Loader {
id: contentLoader
sourceComponent: control.content
onItemChanged: {
if (item) {
item.parent = style;
item.anchors.fill = style;
}
}
asynchronous: false
}
ActivityIndicator {
id: refreshIndicatorItem
running: false
anchors.centerIn: parent
}
// state and content controlling
Connections {
target: control
onRefreshingChanged: {
if (!ready || !control.enabled) {
return;
}
if (!style.releaseToRefresh && target.refreshing) {
// not a manual refresh, update flickable's starting topMargin
style.flickableTopMargin = control.target.topMargin;
style.wasAtYBeginning = control.target.atYBeginning;
}
/*
We cannot bind refreshing state activation clause with the
control.refreshing property dirrectly as when the model is
refreshed automatically (not manually via the component), we
need to remember the flickable's topMargin in order to proceed
with a proper Flickable rebinding. If we use property binding,
the Connections' onRefreshingChanged will update the flickableTopMargin
only after the binding is evaluated.
*/
style.refreshing = target.refreshing;
}
}
Connections {
target: control.target
onMovementStarted: {
style.wasAtYBeginning = control.target.atYBeginning;
style.initialContentY = control.target.contentY;
style.refreshing = false;
style.releaseToRefresh = false;
}
onMovementEnded: style.wasAtYBeginning = control.target.atYBeginning
// catch when to initiate refresh
onDraggingChanged: {
if (!control.parent.dragging && style.releaseToRefresh) {
pointOfRelease = -(control.target.contentY - control.target.originY)
style.flickableTopMargin = control.target.topMargin;
style.refreshing = true;
style.releaseToRefresh = false;
}
}
onContentYChanged: {
if (style.wasAtYBeginning && control.enabled && control.target.dragging) {
style.releaseToRefresh = ((style.initialContentY - control.target.contentY) > style.activationThreshold);
}
}
}
onStateChanged: {
/*
Label might not be ready when the component enters in refreshing
state, therefore the visible property will not be properly returned to
true. Because of the same reason we cannot have a PropertyChanges either
as the target is not yet ready at that point.
*/
if (label) {
label.visible = (state === "idle" || state === "ready-to-refresh");
}
}
states: [
State {
name: "disabled"
when: !control.enabled
},
State {
name: "idle"
extend: ""
when: ready && control.enabled && !style.refreshing && !style.releaseToRefresh
},
State {
name: "ready-to-refresh"
when: ready && control.enabled && style.releaseToRefresh && !style.refreshing
},
State {
name: "refreshing"
when: ready && control.enabled && style.wasAtYBeginning && style.refreshing
PropertyChanges {
target: refreshIndicatorItem
running: true
}
PropertyChanges {
target: control.target
topMargin: style.flickableTopMargin + control.height
}
}
]
transitions: [
Transition {
from: "ready-to-refresh"
to: "refreshing"
SequentialAnimation {
UbuntuNumberAnimation {
target: control.target
property: "topMargin"
from: style.pointOfRelease
to: style.flickableTopMargin + control.height
}
ScriptAction {
script: control.refresh()
}
}
},
// transition to be applied when the model is auto-updating
Transition {
from: "idle"
to: "refreshing"
UbuntuNumberAnimation {
target: control.target
property: "contentY"
from: -style.flickableTopMargin
to: -style.flickableTopMargin - control.height
}
},
Transition {
from: "refreshing"
to: "idle"
UbuntuNumberAnimation {
target: control.target
property: "topMargin"
}
}
]
}
|