summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/base/qvideowidget.cpp87
-rw-r--r--src/multimedia/base/qvideowidget.h9
-rw-r--r--src/multimedia/base/qvideowidget_p.h34
-rw-r--r--src/multimedia/base/qvideowidgetcontrol.cpp2
-rw-r--r--src/multimedia/base/qvideowidgetcontrol.h4
-rw-r--r--src/multimedia/base/qvideowindowcontrol.cpp4
-rw-r--r--src/multimedia/base/qvideowindowcontrol.h4
7 files changed, 79 insertions, 65 deletions
diff --git a/src/multimedia/base/qvideowidget.cpp b/src/multimedia/base/qvideowidget.cpp
index aabfefc..3820af9 100644
--- a/src/multimedia/base/qvideowidget.cpp
+++ b/src/multimedia/base/qvideowidget.cpp
@@ -105,12 +105,12 @@ void QVideoWidgetControlBackend::setFullScreen(bool fullScreen)
}
-QVideoWidget::AspectRatioMode QVideoWidgetControlBackend::aspectRatioMode() const
+Qt::AspectRatioMode QVideoWidgetControlBackend::aspectRatioMode() const
{
return m_widgetControl->aspectRatioMode();
}
-void QVideoWidgetControlBackend::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+void QVideoWidgetControlBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
{
m_widgetControl->setAspectRatioMode(mode);
}
@@ -120,16 +120,16 @@ QRendererVideoWidgetBackend::QRendererVideoWidgetBackend(
: m_rendererControl(control)
, m_widget(widget)
, m_surface(new QPainterVideoSurface)
- , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
+ , m_aspectRatioMode(Qt::KeepAspectRatio)
, m_updatePaintDevice(true)
{
connect(this, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int)));
connect(this, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int)));
connect(this, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int)));
connect(this, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int)));
- connect(m_surface, SIGNAL(frameChanged()), m_widget, SLOT(update()));
+ connect(m_surface, SIGNAL(frameChanged()), this, SLOT(frameChanged()));
connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)),
- m_widget, SLOT(_q_dimensionsChanged()));
+ this, SLOT(formatChanged(QVideoSurfaceFormat)));
m_rendererControl->setSurface(m_surface);
}
@@ -172,12 +172,12 @@ void QRendererVideoWidgetBackend::setSaturation(int saturation)
emit saturationChanged(saturation);
}
-QVideoWidget::AspectRatioMode QRendererVideoWidgetBackend::aspectRatioMode() const
+Qt::AspectRatioMode QRendererVideoWidgetBackend::aspectRatioMode() const
{
return m_aspectRatioMode;
}
-void QRendererVideoWidgetBackend::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+void QRendererVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
{
m_aspectRatioMode = mode;
@@ -207,6 +207,7 @@ void QRendererVideoWidgetBackend::hideEvent(QHideEvent *)
void QRendererVideoWidgetBackend::resizeEvent(QResizeEvent *)
{
+ updateRects();
}
void QRendererVideoWidgetBackend::moveEvent(QMoveEvent *)
@@ -217,8 +218,8 @@ void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event)
{
QPainter painter(m_widget);
- if (m_surface->isActive()) {
- m_surface->paint(&painter, displayRect());
+ if (m_surface->isActive() && m_boundingRect.intersects(event->rect())) {
+ m_surface->paint(&painter, m_boundingRect, m_sourceRect);
m_surface->setReady(true);
} else {
@@ -240,33 +241,53 @@ void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event)
}
}
-QRect QRendererVideoWidgetBackend::displayRect() const
+void QRendererVideoWidgetBackend::formatChanged(const QVideoSurfaceFormat &format)
{
- QRect displayRect = m_widget->rect();
+ m_nativeSize = format.sizeHint();
- if (m_aspectRatioMode != QVideoWidget::IgnoreAspectRatio) {
- QVideoSurfaceFormat format = m_surface->surfaceFormat();
+ updateRects();
- QSize aspectRatio = format.pixelAspectRatio();
+ m_widget->updateGeometry();
+}
+
+void QRendererVideoWidgetBackend::frameChanged()
+{
+ m_widget->update(m_boundingRect);
+}
+
+void QRendererVideoWidgetBackend::updateRects()
+{
+ QRect rect = m_widget->rect();
- QSize size = format.viewport().size();
- size.rwidth() *= aspectRatio.width();
- size.rheight() *= aspectRatio.height();
- size.scale(displayRect.size(), Qt::KeepAspectRatio);
+ if (m_nativeSize.isEmpty()) {
+ m_boundingRect = QRect();
+ } else if (m_aspectRatioMode == Qt::IgnoreAspectRatio) {
+ m_boundingRect = rect;
+ m_sourceRect = QRectF(0, 0, 1, 1);
+ } else if (m_aspectRatioMode == Qt::KeepAspectRatio) {
+ QSize size = m_nativeSize;
+ size.scale(rect.size(), Qt::KeepAspectRatio);
- QPoint center = displayRect.center();
+ m_boundingRect = QRect(0, 0, size.width(), size.height());
+ m_boundingRect.moveCenter(rect.center());
- displayRect = QRect(QPoint(0, 0), size);
- displayRect.moveCenter(center);
- }
+ m_sourceRect = QRectF(0, 0, 1, 1);
+ } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
+ m_boundingRect = rect;
- return displayRect;
+ QSizeF size = rect.size();
+ size.scale(m_nativeSize, Qt::KeepAspectRatio);
+
+ m_sourceRect = QRectF(
+ 0, 0, size.width() / m_nativeSize.width(), size.height() / m_nativeSize.height());
+ m_sourceRect.moveCenter(QPointF(0.5, 0.5));
+ }
}
QWindowVideoWidgetBackend::QWindowVideoWidgetBackend(QVideoWindowControl *control, QWidget *widget)
: m_windowControl(control)
, m_widget(widget)
- , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
+ , m_aspectRatioMode(Qt::KeepAspectRatio)
{
connect(control, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int)));
connect(control, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int)));
@@ -305,12 +326,12 @@ void QWindowVideoWidgetBackend::setFullScreen(bool fullScreen)
m_windowControl->setFullScreen(fullScreen);
}
-QVideoWidget::AspectRatioMode QWindowVideoWidgetBackend::aspectRatioMode() const
+Qt::AspectRatioMode QWindowVideoWidgetBackend::aspectRatioMode() const
{
return m_windowControl->aspectRatioMode();
}
-void QWindowVideoWidgetBackend::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+void QWindowVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
{
m_windowControl->setAspectRatioMode(mode);
}
@@ -515,16 +536,6 @@ void QVideoWidgetPrivate::_q_dimensionsChanged()
*/
/*!
- \enum QVideoWidget::AspectRatioMode
-
- Specfies how video is scaled with respect to its aspect ratio.
-
- \value IgnoreAspectRatio The video is scaled to fill the widget ignoring its aspect ratio.
- \value KeepAspectRatio The video is scaled to the largest rectangle that will fit within the
- widget's dimensions while still retaining its original aspect ratio.
-*/
-
-/*!
Constructs a new video widget.
The \a parent is passed to QWidget.
@@ -617,12 +628,12 @@ void QVideoWidget::setMediaObject(QMediaObject *object)
\brief how video is scaled with respect to its aspect ratio.
*/
-QVideoWidget::AspectRatioMode QVideoWidget::aspectRatioMode() const
+Qt::AspectRatioMode QVideoWidget::aspectRatioMode() const
{
return d_func()->aspectRatioMode;
}
-void QVideoWidget::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
{
Q_D(QVideoWidget);
diff --git a/src/multimedia/base/qvideowidget.h b/src/multimedia/base/qvideowidget.h
index 4e6cf2e..4b24bcb 100644
--- a/src/multimedia/base/qvideowidget.h
+++ b/src/multimedia/base/qvideowidget.h
@@ -60,16 +60,13 @@ class Q_MULTIMEDIA_EXPORT QVideoWidget : public QWidget
Q_OBJECT
Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject)
Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
- Q_PROPERTY(AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged)
+ Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged)
Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
- Q_ENUMS(AspectRatio)
public:
- enum AspectRatioMode { IgnoreAspectRatio, KeepAspectRatio };
-
QVideoWidget(QWidget *parent = 0);
~QVideoWidget();
@@ -80,7 +77,7 @@ public:
bool isFullScreen() const;
#endif
- AspectRatioMode aspectRatioMode() const;
+ Qt::AspectRatioMode aspectRatioMode() const;
int brightness() const;
int contrast() const;
@@ -91,7 +88,7 @@ public:
public Q_SLOTS:
void setFullScreen(bool fullScreen);
- void setAspectRatioMode(QVideoWidget::AspectRatioMode mode);
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
void setBrightness(int brightness);
void setContrast(int contrast);
void setHue(int hue);
diff --git a/src/multimedia/base/qvideowidget_p.h b/src/multimedia/base/qvideowidget_p.h
index 4227afd..44fd1cd 100644
--- a/src/multimedia/base/qvideowidget_p.h
+++ b/src/multimedia/base/qvideowidget_p.h
@@ -78,8 +78,8 @@ public:
virtual void setFullScreen(bool fullScreen) = 0;
- virtual QVideoWidget::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) = 0;
+ virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
+ virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
};
class QVideoWidgetBackend : public QObject, public QVideoWidgetControlInterface
@@ -111,8 +111,8 @@ public:
void setFullScreen(bool fullScreen);
- QVideoWidget::AspectRatioMode aspectRatioMode() const;
- void setAspectRatioMode(QVideoWidget::AspectRatioMode mode);
+ Qt::AspectRatioMode aspectRatioMode() const;
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
private:
QVideoWidgetControl *m_widgetControl;
@@ -137,8 +137,8 @@ public:
void setFullScreen(bool fullScreen);
- QVideoWidget::AspectRatioMode aspectRatioMode() const;
- void setAspectRatioMode(QVideoWidget::AspectRatioMode mode);
+ Qt::AspectRatioMode aspectRatioMode() const;
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
QSize sizeHint() const;
@@ -155,14 +155,20 @@ Q_SIGNALS:
void hueChanged(int hue);
void saturationChanged(int saturation);
+private Q_SLOTS:
+ void formatChanged(const QVideoSurfaceFormat &format);
+ void frameChanged();
+
private:
- QRect displayRect() const;
+ void updateRects();
QVideoRendererControl *m_rendererControl;
QWidget *m_widget;
QPainterVideoSurface *m_surface;
- QVideoWidget::AspectRatioMode m_aspectRatioMode;
- QSize m_aspectRatio;
+ Qt::AspectRatioMode m_aspectRatioMode;
+ QRect m_boundingRect;
+ QRectF m_sourceRect;
+ QSize m_nativeSize;
bool m_updatePaintDevice;
};
@@ -182,8 +188,8 @@ public:
void setFullScreen(bool fullScreen);
- QVideoWidget::AspectRatioMode aspectRatioMode() const;
- void setAspectRatioMode(QVideoWidget::AspectRatioMode mode);
+ Qt::AspectRatioMode aspectRatioMode() const;
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
QSize sizeHint() const;
@@ -196,7 +202,7 @@ public:
private:
QVideoWindowControl *m_windowControl;
QWidget *m_widget;
- QVideoWidget::AspectRatioMode m_aspectRatioMode;
+ Qt::AspectRatioMode m_aspectRatioMode;
QSize m_pixelAspectRatio;
};
@@ -221,7 +227,7 @@ public:
, contrast(0)
, hue(0)
, saturation(0)
- , aspectRatioMode(QVideoWidget::KeepAspectRatio)
+ , aspectRatioMode(Qt::KeepAspectRatio)
, nonFullScreenFlags(0)
, wasFullScreen(false)
{
@@ -240,7 +246,7 @@ public:
int contrast;
int hue;
int saturation;
- QVideoWidget::AspectRatioMode aspectRatioMode;
+ Qt::AspectRatioMode aspectRatioMode;
Qt::WindowFlags nonFullScreenFlags;
bool wasFullScreen;
diff --git a/src/multimedia/base/qvideowidgetcontrol.cpp b/src/multimedia/base/qvideowidgetcontrol.cpp
index c53c77b..e8957dc 100644
--- a/src/multimedia/base/qvideowidgetcontrol.cpp
+++ b/src/multimedia/base/qvideowidgetcontrol.cpp
@@ -126,7 +126,7 @@ QVideoWidgetControl::~QVideoWidgetControl()
*/
/*!
- \fn QVideoWidgetControl::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+ \fn QVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode)
Sets the aspect ratio \a mode which determines how video is scaled to the fit the widget with
respect to its aspect ratio.
diff --git a/src/multimedia/base/qvideowidgetcontrol.h b/src/multimedia/base/qvideowidgetcontrol.h
index 6981e89..4c0a6c6 100644
--- a/src/multimedia/base/qvideowidgetcontrol.h
+++ b/src/multimedia/base/qvideowidgetcontrol.h
@@ -66,8 +66,8 @@ public:
virtual QWidget *videoWidget() = 0;
- virtual QVideoWidget::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) = 0;
+ virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
+ virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
virtual bool isFullScreen() const = 0;
virtual void setFullScreen(bool fullScreen) = 0;
diff --git a/src/multimedia/base/qvideowindowcontrol.cpp b/src/multimedia/base/qvideowindowcontrol.cpp
index da46823..c74a0d5 100644
--- a/src/multimedia/base/qvideowindowcontrol.cpp
+++ b/src/multimedia/base/qvideowindowcontrol.cpp
@@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE
QVideoWindowControl *windowControl = mediaService->control<QVideoWindowControl *>();
windowControl->setWinId(widget->winId());
windowControl->setDisplayRect(widget->rect());
- windowControl->setAspectRatioMode(QVideoWidget::KeepAspectRatio);
+ windowControl->setAspectRatioMode(Qt::KeepAspectRatio);
\endcode
QVideoWindowControl is one of number of possible video output controls,
@@ -176,7 +176,7 @@ QVideoWindowControl::~QVideoWindowControl()
*/
/*!
- \fn QVideoWindowControl::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
+ \fn QVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
Sets the aspect ratio \a mode which determines how video is scaled to the fit the display region
with respect to its aspect ratio.
diff --git a/src/multimedia/base/qvideowindowcontrol.h b/src/multimedia/base/qvideowindowcontrol.h
index 9ee96ab..53f7b0e 100644
--- a/src/multimedia/base/qvideowindowcontrol.h
+++ b/src/multimedia/base/qvideowindowcontrol.h
@@ -74,8 +74,8 @@ public:
virtual QSize nativeSize() const = 0;
- virtual QVideoWidget::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) = 0;
+ virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
+ virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
virtual int brightness() const = 0;
virtual void setBrightness(int brightness) = 0;