/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components/1.2/OrientationHelper.qml is in qml-module-ubuntu-components 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 | /*
* Copyright 2013 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 QtQuick.Window 2.0
import Ubuntu.Components 1.2
/*!
\qmltype OrientationHelper
\inqmlmodule Ubuntu.Components 1.1
\ingroup ubuntu
\brief The OrientationHelper automatically rotates its children following the
orientation of the device.
Any Item placed inside an Orientation Helper will be automatically rotated
following the orientation of the device.
Note that OrientationHelper is always filling its parent (anchors.parent: fill).
Example:
\qml
Item {
OrientationHelper {
Label {
text: "Automatically rotated"
}
Button {
text: "Automatically rotated"
}
}
}
\endqml
*/
Item {
id: orientationHelper
/*!
Sets whether it will be automatically rotating when the device is.
The default value is true.
\qmlproperty bool automaticOrientation
*/
property bool automaticOrientation: true
/*!
Sets whether the rotation transition is performed.
The default value is true.
\qmlproperty bool transitionEnabled
*/
property bool transitionEnabled: true
/*!
Exposes whether the orientationTransition is running.
\qmlproperty alias rotating
*/
readonly property bool rotating: d.transitioning
/*!
\qmlproperty int __orientationAngle
\deprecated
Use orientationAngle instead.
*/
property alias __orientationAngle: orientationHelper.orientationAngle
/*!
\qmlproperty int orientationAngle
Calculates the current orientation angle.
*/
property int orientationAngle: automaticOrientation ? Screen.angleBetween(Screen.primaryOrientation, Screen.orientation) : 0
// Screen.primaryOrientation and Screen.orientation can change one right after the other,
// causing orientationAngle to momentarily change. To avoid responding to such
// intermediate states, wait for its value to stabilize before rotating to it.
onOrientationAngleChanged: { automaticOrientation ? stableOrientationAngleTimer.restart() : d.tryUpdateState(); }
/*!
The property holds if the OrientationHelper should automatically resize the
contents when the input method appears
The default value is false.
*/
property bool anchorToKeyboard: false
x: parent ? (parent.width - width) / 2 : 0
y: parent ? (d.availableParentHeight - height) / 2 : 0
width: parent ? (d.flipDimensions ? d.availableParentHeight : parent.width) : 0
height: parent ? (d.flipDimensions ? parent.width : d.availableParentHeight) : 0
/*
The attached property Screen.orientation is only valid inside Item or
derived components. Inside Object it evaluates to 0 with no error.
Also be aware that some apps eg. webbrowser-app set window.contentOrientation
and thus can hide failure to update it from this code.
See http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick-window2-screen.html
*/
Item {
id: d
property real availableParentHeight: {
if (!orientationHelper.parent)
return 0;
var availableHeight = orientationHelper.parent.height;
if (d.stateAngle === 0 && UbuntuApplication.inputMethod.visible && anchorToKeyboard)
availableHeight -= UbuntuApplication.inputMethod.keyboardRectangle.height;
return availableHeight;
}
/*!
'window' is defined by QML between startup and showing on the screen.
There is no signal for when it becomes available and re-declaring it is not safe.
http://qt-project.org/doc/qt-5.1/qtqml/qml-qtqml2-qt.html
http://qt-project.org/doc/qt-5.1/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html
*/
property bool windowActive: typeof window != 'undefined'
/*!
Report the current orientation of the application via QWindow::contentOrientation.
http://qt-project.org/doc/qt-5.0/qtgui/qwindow.html#contentOrientation-prop
*/
function applyOrientation() {
if (windowActive && window)
window.contentOrientation = Screen.orientation
}
onWindowActiveChanged: {
if (automaticOrientation)
applyOrientation();
}
Timer {
id: stableOrientationAngleTimer
interval: 250
onTriggered: { d.tryUpdateState(); }
}
readonly property bool flipDimensions: d.stateAngle == 90 || d.stateAngle == 270
property bool transitioning: false
onTransitioningChanged: { d.tryUpdateState(); }
// NB: Using a binding would cause QML to detect a
// binding loop and break the binding, thus the imperative code to update the state.
function tryUpdateState() {
if (!d.transitioning) {
d.oldAngle = d.stateAngle;
d.stateAngle = orientationHelper.orientationAngle;
d.state = orientationHelper.orientationAngle.toString();
d.applyOrientation();
}
}
state: "0"
states: [
State { name: "0" },
State { name: "90" },
State { name: "180" },
State { name: "270" }
]
property int stateAngle: 0
property int oldAngle: 0
transitions: [
Transition {
id: animatedTransition
enabled: orientationHelper.transitionEnabled
SequentialAnimation {
ScriptAction { script: { d.transitioning = true; } }
RotationAnimator {
target: orientationHelper
duration: UbuntuAnimation.FastDuration
easing: UbuntuAnimation.StandardEasing
direction: RotationAnimation.Shortest
from: d.oldAngle
to: d.stateAngle
}
ScriptAction { script: { d.transitioning = false; } }
}
},
Transition {
enabled: !orientationHelper.transitionEnabled
ScriptAction { script: { orientationHelper.rotation = d.stateAngle; } }
}
]
}
}
|