Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgraphicsvideoitem.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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#include "qvideosink.h"
6
7#include <qobject.h>
8#include <qvideoframe.h>
9#include <qvideoframeformat.h>
10
11#include <QtCore/qcoreevent.h>
12#include <QtCore/qpointer.h>
13
15
37
39{
40 q_ptr->prepareGeometryChange();
41
43 if (nativeSize.isEmpty())
44 return;
45
49
50 boundingRect = QRectF(0, 0, size.width(), size.height());
52 }
53}
54
56{
57 m_frame = frame;
58 q_ptr->update(boundingRect);
59
60 if (frame.isValid()) {
61 const QSize &size = frame.surfaceFormat().viewport().size();
62 if (nativeSize != size) {
64
66 emit q_ptr->nativeSizeChanged(nativeSize);
67 }
68 }
69}
70
95QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent)
96 : QGraphicsObject(parent)
97 , d_ptr(new QGraphicsVideoItemPrivate)
98{
99 d_ptr->q_ptr = this;
100 d_ptr->sink = new QVideoSink(this);
101
102 connect(d_ptr->sink, SIGNAL(videoFrameChanged(const QVideoFrame &)), this, SLOT(_q_present(const QVideoFrame &)));
103}
104
108QGraphicsVideoItem::~QGraphicsVideoItem()
109{
110 delete d_ptr;
111}
112
124QVideoSink *QGraphicsVideoItem::videoSink() const
125{
126 return d_func()->sink;
127}
128
134Qt::AspectRatioMode QGraphicsVideoItem::aspectRatioMode() const
135{
136 return d_func()->m_aspectRatioMode;
137}
138
139void QGraphicsVideoItem::setAspectRatioMode(Qt::AspectRatioMode mode)
140{
142 if (d->m_aspectRatioMode == mode)
143 return;
144
145 d->m_aspectRatioMode = mode;
146 d->updateRects();
147}
148
157QPointF QGraphicsVideoItem::offset() const
158{
159 return d_func()->rect.topLeft();
160}
161
162void QGraphicsVideoItem::setOffset(const QPointF &offset)
163{
165
166 d->rect.moveTo(offset);
167 d->updateRects();
168}
169
178QSizeF QGraphicsVideoItem::size() const
179{
180 return d_func()->rect.size();
181}
182
183void QGraphicsVideoItem::setSize(const QSizeF &size)
184{
186
187 d->rect.setSize(size.isValid() ? size : QSizeF(0, 0));
188 d->updateRects();
189}
190
196QSizeF QGraphicsVideoItem::nativeSize() const
197{
198 return d_func()->nativeSize;
199}
200
204QRectF QGraphicsVideoItem::boundingRect() const
205{
206 return d_func()->boundingRect;
207}
208
212void QGraphicsVideoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
213{
215
218
219 d->m_frame.paint(painter, d->rect, { Qt::transparent, d->m_aspectRatioMode });
220}
221
243QVariant QGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value)
244{
245 return QGraphicsItem::itemChange(change, value);
246}
247
251void QGraphicsVideoItem::timerEvent(QTimerEvent *event)
252{
254}
255
257
258#include "moc_qgraphicsvideoitem.cpp"
259
260
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item's ...
The QGraphicsObject class provides a base class for all graphics items that require signals,...
void _q_present(const QVideoFrame &)
Qt::AspectRatioMode m_aspectRatioMode
The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaPlayer ...
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Definition qobject.cpp:1470
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr void moveCenter(const QPointF &p) noexcept
Moves the rectangle, leaving the center point at the given position.
Definition qrect.h:726
constexpr QPointF center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:699
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:735
\inmodule QtCore
Definition qsize.h:208
void scale(qreal w, qreal h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode.
Definition qsize.h:347
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:326
\inmodule QtCore
Definition qsize.h:25
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
\inmodule QtCore
Definition qcoreevent.h:366
\inmodule QtCore
Definition qvariant.h:65
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:27
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QOpenGLWidget * widget
[1]
Combined button and popup list for selecting options.
AspectRatioMode
@ KeepAspectRatio
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLintptr offset
struct _cl_event * event
GLsizei GLenum GLboolean sink
GLuint GLenum option
#define emit
#define Q_UNUSED(x)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QPainter painter(this)
[7]
QFrame frame
[0]