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
qcapturablewindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 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
7
9
10QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QCapturableWindowPrivate)
11
12/*!
13 \class QCapturableWindow
14 \inmodule QtMultimedia
15 \ingroup multimedia
16 \ingroup multimedia_video
17 \since 6.6
18
19 \brief Used for getting the basic information of a capturable window.
20
21 The class contains a set of window information, except the method
22 QCapturableWindow::isValid which pulls the current state
23 whenever it's called.
24
25 \sa QWindowCapture
26*/
27/*!
28 \qmlvaluetype CapturableWindow
29 \nativetype QCapturableWindow
30 \brief The CapturableWindow type is used getting basic
31 of a window that is available for capturing via WindowCapture.
32
33 \inqmlmodule QtMultimedia
34 \ingroup multimedia_qml
35 \ingroup multimedia_video_qml
36 \since 6.6
37
38 The class contains a dump of window information, except the property
39 'isValid' which pulls the actual window state every time.
40
41 A CapturableWindow instance can be implicitly constructed from a
42 \l [QML] Window. Application developers can utilize this by passing
43 a QML Window into the 'window' property of a \l WindowCapture. See
44 the following example.
45 \qml
46 Window {
47 id: topWindow
48
49 WindowCapture {
50 window: topWindow
51 }
52 }
53 \endqml
54
55 \sa WindowCapture
56*/
57
58/*!
59 \fn QCapturableWindow::QCapturableWindow(QCapturableWindow &&other)
60
61 Constructs a QCapturableWindow by moving from \a other.
62*/
63
64/*!
65 \fn void QCapturableWindow::swap(QCapturableWindow &other) noexcept
66
67 Swaps the current window information with \a other.
68*/
69
70/*!
71 \fn QCapturableWindow &QCapturableWindow::operator=(QCapturableWindow &&other)
72
73 Moves \a other into this QCapturableWindow.
74*/
75
76/*!
77 Constructs a null capturable window information that doesn't refer to any window.
78*/
79QCapturableWindow::QCapturableWindow() = default;
80
81/*!
82 Constructs a QCapturableWindow instance that maps to the given window.
83
84 The description of the QCapturableWindow will match the title of the given QWindow.
85
86 Note, the constructor may create an invalid instance if the specified \c QWindow
87 has not been presented yet. Thus, if the Qt application is not running, an
88 invalid \c QCapturableWindow instance is expected. The validity of the instance
89 can be tracked by querying \l isValid over time.
90
91 If given a nullptr as input, this method will return an instance that will never become valid.
92
93 If given a window that is not top-level, this method will return an instance will never become
94 valid.
95
96 \since 6.10
97*/
98QCapturableWindow::QCapturableWindow(QWindow *window)
99{
100 q23::expected<QCapturableWindow, QString> capturableWindow =
101 QPlatformMediaIntegration::instance()->capturableWindowFromQWindow(window);
102 if (capturableWindow)
103 *this = std::move(capturableWindow.value());
104}
105
106/*!
107 Destroys the window information.
108 */
110
111/*!
112 Construct a new window information using \a other QCapturableWindow.
113*/
114QCapturableWindow::QCapturableWindow(const QCapturableWindow &other) = default;
115
116/*!
117 Assigns the \a other window information to this QCapturableWindow.
118*/
119QCapturableWindow& QCapturableWindow::operator=(const QCapturableWindow &other) = default;
120
121/*!
122 \fn bool QCapturableWindow::operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs)
123
124 Returns \c true if window information \a lhs and \a rhs refer to the same window,
125 otherwise returns \c false.
126*/
127
128/*!
129 \fn bool QCapturableWindow::operator!=(const QCapturableWindow &lhs, const QCapturableWindow &rhs)
130
131 Returns \c true if window information \a lhs and \a rhs refer to different windows,
132 otherwise returns \c false.
133*/
134bool operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs) noexcept
135{
136 return lhs.d == rhs.d || (lhs.d && rhs.d && lhs.d->id == rhs.d->id);
137}
138
139/*!
140 \qmlproperty string QtMultimedia::CapturableWindow::isValid
141
142 This property identifies whether a window information is valid.
143
144 An invalid window information refers to non-existing window or doesn't refer to any one.
145*/
146
147/*!
148 \property QCapturableWindow::isValid
149 \brief whether information about the window is valid.
150
151 An invalid window information refers to non-existing window or doesn't refer to any one.
152*/
154{
155 return d && QPlatformMediaIntegration::instance()->isCapturableWindowValid(*d);
156}
157
158/*!
159 \qmlproperty string QtMultimedia::CapturableWindow::description
160
161 This property holds the description of the window.
162 In most cases it represents the window title.
163*/
164
165/*!
166 \property QCapturableWindow::description
167 \brief a description of the window.
168
169 In most cases it represents the window title.
170*/
171QString QCapturableWindow::description() const
172{
173 if (!d)
174 return {};
175
176 if (d->description.isEmpty() && d->id)
177 return QLatin1String("Window 0x") + QString::number(d->id, 16);
178
179 return d->description;
180}
181
182QCapturableWindow::QCapturableWindow(QCapturableWindowPrivate *capturablePrivate)
183 : d(capturablePrivate)
184{
185}
186
187#ifndef QT_NO_DEBUG_STREAM
188QDebug operator<<(QDebug dbg, const QCapturableWindow &window)
189{
190 dbg << QStringLiteral("Capturable window '%1'").arg(window.description());
191 return dbg;
192}
193#endif
194
195
196QT_END_NAMESPACE
197
198#include "moc_qcapturablewindow.cpp"
\inmodule QtMultimedia
Q_MULTIMEDIA_EXPORT ~QCapturableWindow()
Destroys the window information.
Q_MULTIMEDIA_EXPORT bool isValid() const
QDebug operator<<(QDebug dbg, const QCapturableWindow &window)
bool operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs) noexcept