Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickscreencapture.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7
8static qreal screenFrameRateToReal(std::optional<qreal> frameRate)
9{
10 return frameRate.value_or(-1.f);
11}
12
13QQuickScreenCapture::QQuickScreenCapture(QObject *parent) : QScreenCapture(parent)
14{
15 connect(this, &QScreenCapture::screenChanged, this, [this] {
16 emit qmlScreenChanged(ensureQmlScreen());
17 });
18
19 connect(this, &QScreenCapture::maximumFrameRateChanged, this,
20 [this](std::optional<qreal> frameRate) {
21 emit QQuickScreenCapture::maximumFrameRateChanged(screenFrameRateToReal(frameRate));
22 });
23}
24
25void QQuickScreenCapture::qmlSetScreen(QQuickScreenInfo *qmlScreen)
26{
27 setScreen(qmlScreen ? qmlScreen->wrappedScreen() : nullptr);
28}
29
30QQuickScreenInfo *QQuickScreenCapture::ensureQmlScreen()
31{
32 // Note QQuickApplication may recreate QQuickScreenInfo
33 // so we implement creating our own instance.
34 // TODO: perhaps, we should return null QQuickScreenInfo for null QScreen
35 if (!m_qmlScreen || m_qmlScreen->wrappedScreen() != screen()) {
36 m_ownQmlScreen = std::make_unique<QQuickScreenInfo>(this, screen());
37 m_qmlScreen = m_ownQmlScreen.get();
38 }
39
40 return m_qmlScreen;
41}
42
43/*!
44 \since 6.12
45 \qmlproperty real QtMultimedia::ScreenCapture::maximumFrameRate
46
47 The screen capture frame rate upper limit.
48
49 This can be set to override the capture frame rate used by default based on
50 e.g. display refresh rate, but only as an upper limit since screen capture
51 produces frames at a variable rate. Setting this higher than the display
52 refresh rate is not recommended and can cause errors.
53
54 If -1, a platform-dependent default is used.
55
56 Any changes to this property are applied the next time the ScreenCapture
57 goes active.
58*/
59
60void QQuickScreenCapture::qmlSetMaximumFrameRate(qreal frameRate)
61{
62 if (qFuzzyCompare(frameRate, static_cast<qreal>(-1.f)))
63 setMaximumFrameRate(std::nullopt);
64 else if (frameRate > 0.f)
65 setMaximumFrameRate(frameRate);
66}
67
68qreal QQuickScreenCapture::qmlMaximumFrameRate() const
69{
70 return screenFrameRateToReal(maximumFrameRate());
71}
72
73void QQuickScreenCapture::qmlResetMaximumFrameRate()
74{
75 setMaximumFrameRate(std::nullopt);
76}
77
78QT_END_NAMESPACE
79
80#include "moc_qquickscreencapture_p.cpp"
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE qreal screenFrameRateToReal(std::optional< qreal > frameRate)