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