~tpeeters/ubuntu-ui-toolkit/autorotate-popover

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/MainView.qml

  • Committer: Kaleo
  • Date: 2013-04-25 00:58:00 UTC
  • Revision ID: florian.boucault@canonical.com-20130425005800-e21rro5u3abingcu
Extracted rotation support into helper class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 */
16
16
 
17
17
import QtQuick 2.0
18
 
import QtQuick.Window 2.0
19
18
// FIXME: When a module contains QML, C++ and JavaScript elements exported,
20
19
// we need to use named imports otherwise namespace collision is reported
21
20
// by the QML engine. As workaround, we use Theming named import.
160
159
      device is.
161
160
 
162
161
      The default value is false.
163
 
      */
164
 
    property bool automaticOrientation: false
 
162
 
 
163
      \qmlproperty bool automaticOrientation
 
164
     */
 
165
    property alias automaticOrientation: canvas.automaticOrientation
165
166
 
166
167
    /*!
167
168
      \internal
168
169
      Use default property to ensure children added do not draw over the toolbar.
169
170
     */
170
171
    default property alias contentsItem: contents.data
171
 
    Item {
 
172
    OrientationHelper {
172
173
        id: canvas
173
 
        anchors.fill: parent
174
 
 
175
 
        // Orientation support
176
 
        property int orientationAngle: automaticOrientation ? Screen.angleBetween(Screen.primaryOrientation, Screen.orientation) : 0
177
 
        state: orientationAngle.toString()
178
 
 
179
 
        states: [
180
 
            State {
181
 
                name: "0"
182
 
                PropertyChanges {
183
 
                    target: canvas
184
 
                    rotation: 0
185
 
                }
186
 
            },
187
 
            State {
188
 
                name: "180"
189
 
                PropertyChanges {
190
 
                    target: canvas
191
 
                    rotation: 180
192
 
                }
193
 
            },
194
 
            State {
195
 
                name: "270"
196
 
                PropertyChanges {
197
 
                    target: canvas
198
 
                    rotation: 270
199
 
                    anchors {
200
 
                        leftMargin: (parent.width - parent.height) / 2
201
 
                        rightMargin: anchors.leftMargin
202
 
                        topMargin: -anchors.leftMargin
203
 
                        bottomMargin: anchors.topMargin
204
 
                    }
205
 
                }
206
 
            },
207
 
            State {
208
 
                name: "90"
209
 
                PropertyChanges {
210
 
                    target: canvas
211
 
                    rotation: 90
212
 
                    anchors {
213
 
                        leftMargin: (parent.width - parent.height) / 2
214
 
                        rightMargin: anchors.leftMargin
215
 
                        topMargin: -anchors.leftMargin
216
 
                        bottomMargin: anchors.topMargin
217
 
                    }
218
 
                }
219
 
            }
220
 
        ]
221
 
 
222
 
        transitions: [
223
 
            Transition {
224
 
                id: orientationTransition
225
 
                ParallelAnimation {
226
 
                    SequentialAnimation {
227
 
                        PauseAnimation {
228
 
                            duration: 25
229
 
                        }
230
 
                        PropertyAction {
231
 
                            target: canvas
232
 
                            properties: "anchors.topMargin,anchors.bottomMargin,anchors.rightMargin,anchors.leftMargin"
233
 
                        }
234
 
                    }
235
 
                    RotationAnimation {
236
 
                        target: canvas
237
 
                        properties: "rotation"
238
 
                        duration: 250
239
 
                        easing.type: Easing.OutQuint
240
 
                        direction: RotationAnimation.Shortest
241
 
                    }
242
 
                }
243
 
            }
244
 
        ]
 
174
 
 
175
        automaticOrientation: false
245
176
 
246
177
        Item {
247
178
            id: contents