1 | // Copyright (C) 2016 Research In Motion |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qvideooutputorientationhandler_p.h" |
5 | |
6 | #include <QGuiApplication> |
7 | #include <QScreen> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | bool QVideoOutputOrientationHandler::m_isRecording = false; |
12 | |
13 | QVideoOutputOrientationHandler::QVideoOutputOrientationHandler(QObject *parent) |
14 | : QObject(parent) |
15 | , m_currentOrientation(0) |
16 | { |
17 | QScreen *screen = QGuiApplication::primaryScreen(); |
18 | if (!screen) |
19 | return; |
20 | |
21 | connect(sender: screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), |
22 | receiver: this, SLOT(screenOrientationChanged(Qt::ScreenOrientation))); |
23 | |
24 | screenOrientationChanged(orientation: screen->orientation()); |
25 | } |
26 | |
27 | int QVideoOutputOrientationHandler::currentOrientation() const |
28 | { |
29 | return m_currentOrientation; |
30 | } |
31 | |
32 | void QVideoOutputOrientationHandler::screenOrientationChanged(Qt::ScreenOrientation orientation) |
33 | { |
34 | if (m_isRecording) |
35 | return; |
36 | |
37 | const QScreen *screen = QGuiApplication::primaryScreen(); |
38 | if (!screen) |
39 | return; |
40 | |
41 | const int angle = (360 - screen->angleBetween(a: screen->nativeOrientation(), b: orientation)) % 360; |
42 | |
43 | if (angle == m_currentOrientation) |
44 | return; |
45 | |
46 | m_currentOrientation = angle; |
47 | emit orientationChanged(angle: m_currentOrientation); |
48 | } |
49 | |
50 | QT_END_NAMESPACE |
51 | |
52 | #include "moc_qvideooutputorientationhandler_p.cpp" |
53 |