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
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtQuick.Window
import QtQuick.Controls
Window {
id: window
width: 640
height: 480
visible: true
Rectangle {
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
Text {
anchors.centerIn: parent
text: "Screen orientation: " + orientationName(Screen.orientation) + "\n" +
"Content orientation: " + orientationName(window.contentOrientation)
}
}
Row {
Button {
text: "Toggle"
onClicked: popup.visible ? popup.close() : popup.open()
focus: true
}
ComboBox {
id: orientationSelection
model: ListModel {
ListElement {
name: "Primary"
value: Qt.PrimaryOrientation
}
ListElement {
name: "Portrait"
value: Qt.PortraitOrientation
}
ListElement {
name: "Landscape"
value: Qt.LandscapeOrientation
}
ListElement {
name: "Inverted Portrait"
value: Qt.InvertedPortraitOrientation
}
ListElement {
name: "Inverted Landscape"
value: Qt.InvertedLandscapeOrientation
}
}
textRole: "name"
valueRole: "value"
onActivated: updateOrientation()
}
Keys.onLeftPressed: (event) => {
window.contentItem.rotation -= event.modifiers & Qt.ShiftModifier ? 10 : 1;
}
Keys.onRightPressed: (event) => {
window.contentItem.rotation += event.modifiers & Qt.ShiftModifier ? 10 : 1;
}
}
Popup {
id: popup
anchors.centerIn: parent
width: 320
height: 240
modal: false
dim: true
Text {
text: "Hello Popup"
anchors.fill: parent
}
Overlay.modeless: Rectangle {
opacity: 0.5
color: "blue"
}
}
Drawer {
Text {
anchors.centerIn: parent
text: "Hello Left Drawer"
}
edge: Qt.LeftEdge
height: parent.height
}
Drawer {
Text {
anchors.centerIn: parent
text: "Hello Right Drawer"
}
edge: Qt.RightEdge
height: parent.height
}
function updateOrientation() {
window.contentOrientation = orientationSelection.currentValue;
let angle = Screen.angleBetween(Screen.orientation, window.contentOrientation);
console.log("Rotation between " + Screen.orientation + " and " + window.contentOrientation + " should be " + angle);
window.contentItem.rotation = angle;
}
function orientationName(orientation) {
for (let i = 0; i < orientationSelection.model.count; i++) {
let entry = orientationSelection.model.get(i);
if (entry.value === orientation)
return entry.name
}
}
Component.onCompleted: {
Screen.orientationChanged.connect(updateOrientation);
updateOrientation();
}
}
|