--- a/qtmobility/src/multimedia/qvideowidget.cpp Fri Apr 16 15:51:22 2010 +0300
+++ b/qtmobility/src/multimedia/qvideowidget.cpp Mon May 03 13:18:40 2010 +0300
@@ -39,16 +39,16 @@
**
****************************************************************************/
-#include <qvideowidget_p.h>
+#include "qvideowidget_p.h"
-#include <qmediaobject.h>
-#include <qmediaservice.h>
-#include <qvideooutputcontrol.h>
-#include <qvideowindowcontrol.h>
-#include <qvideowidgetcontrol.h>
+#include "qmediaobject.h"
+#include "qmediaservice.h"
+#include "qvideooutputcontrol.h"
+#include "qvideowindowcontrol.h"
+#include "qvideowidgetcontrol.h"
-#include <qpaintervideosurface_p.h>
-#include <qvideorenderercontrol.h>
+#include "qpaintervideosurface_p.h"
+#include "qvideorenderercontrol.h"
#include <QtMultimedia/qvideosurfaceformat.h>
#include <qpainter.h>
@@ -106,12 +106,12 @@
}
-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);
}
@@ -121,16 +121,16 @@
: 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);
}
@@ -173,12 +173,12 @@
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;
@@ -208,6 +208,7 @@
void QRendererVideoWidgetBackend::resizeEvent(QResizeEvent *)
{
+ updateRects();
}
void QRendererVideoWidgetBackend::moveEvent(QMoveEvent *)
@@ -218,13 +219,23 @@
{
QPainter painter(m_widget);
- if (m_surface->isActive()) {
- m_surface->paint(&painter, displayRect());
+ if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) {
+ QRegion borderRegion = event->region();
+ borderRegion = borderRegion.subtracted(m_boundingRect);
+
+ QBrush brush = m_widget->palette().window();
+
+ QVector<QRect> rects = borderRegion.rects();
+ for (QVector<QRect>::iterator it = rects.begin(), end = rects.end(); it != end; ++it) {
+ painter.fillRect(*it, brush);
+ }
+ }
+
+ if (m_surface->isActive() && m_boundingRect.intersects(event->rect())) {
+ m_surface->paint(&painter, m_boundingRect, m_sourceRect);
m_surface->setReady(true);
} else {
- painter.fillRect(event->rect(), m_widget->palette().background());
-
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
if (m_updatePaintDevice && (painter.paintEngine()->type() == QPaintEngine::OpenGL
|| painter.paintEngine()->type() == QPaintEngine::OpenGL2)) {
@@ -239,35 +250,57 @@
}
#endif
}
+
+}
+
+void QRendererVideoWidgetBackend::formatChanged(const QVideoSurfaceFormat &format)
+{
+ m_nativeSize = format.sizeHint();
+
+ updateRects();
+
+ m_widget->updateGeometry();
+ m_widget->update();
+}
+
+void QRendererVideoWidgetBackend::frameChanged()
+{
+ m_widget->update(m_boundingRect);
}
-QRect QRendererVideoWidgetBackend::displayRect() const
+void QRendererVideoWidgetBackend::updateRects()
{
- QRect displayRect = m_widget->rect();
+ QRect rect = m_widget->rect();
- if (m_aspectRatioMode != QVideoWidget::IgnoreAspectRatio) {
- QVideoSurfaceFormat format = m_surface->surfaceFormat();
-
- QSize aspectRatio = format.pixelAspectRatio();
+ 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);
- QSize size = format.viewport().size();
- size.rwidth() *= aspectRatio.width();
- size.rheight() *= aspectRatio.height();
- size.scale(displayRect.size(), Qt::KeepAspectRatio);
+ m_boundingRect = QRect(0, 0, size.width(), size.height());
+ m_boundingRect.moveCenter(rect.center());
+
+ m_sourceRect = QRectF(0, 0, 1, 1);
+ } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
+ m_boundingRect = rect;
- QPoint center = displayRect.center();
+ QSizeF size = rect.size();
+ size.scale(m_nativeSize, Qt::KeepAspectRatio);
- displayRect = QRect(QPoint(0, 0), size);
- displayRect.moveCenter(center);
+ m_sourceRect = QRectF(
+ 0, 0, size.width() / m_nativeSize.width(), size.height() / m_nativeSize.height());
+ m_sourceRect.moveCenter(QPointF(0.5, 0.5));
}
-
- return displayRect;
}
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)));
@@ -306,12 +339,12 @@
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);
}
@@ -344,6 +377,12 @@
void QWindowVideoWidgetBackend::paintEvent(QPaintEvent *event)
{
+ if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) {
+ QPainter painter(m_widget);
+
+ painter.fillRect(event->rect(), m_widget->palette().window());
+ }
+
m_windowControl->repaint();
event->accept();
@@ -484,6 +523,7 @@
void QVideoWidgetPrivate::_q_dimensionsChanged()
{
q_func()->updateGeometry();
+ q_func()->update();
}
/*!
@@ -516,16 +556,6 @@
*/
/*!
- \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.
@@ -535,10 +565,6 @@
, d_ptr(new QVideoWidgetPrivate)
{
d_ptr->q_ptr = this;
-
- QPalette palette = QWidget::palette();
- palette.setColor(QPalette::Background, Qt::black);
- setPalette(palette);
}
/*!
@@ -618,12 +644,12 @@
\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);
@@ -869,9 +895,6 @@
if (d->currentBackend)
d->currentBackend->hideEvent(event);
- if (d->outputControl)
- d->outputControl->setOutput(QVideoOutputControl::NoOutput);
-
QWidget::hideEvent(event);
}
@@ -906,8 +929,13 @@
{
Q_D(QVideoWidget);
- if (d->currentBackend)
+ if (d->currentBackend) {
d->currentBackend->paintEvent(event);
+ } else if (testAttribute(Qt::WA_OpaquePaintEvent)) {
+ QPainter painter(this);
+
+ painter.fillRect(event->rect(), palette().window());
+ }
}
#include "moc_qvideowidget.cpp"