summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <sergio.martins.qnx@kdab.com>2012-12-06 10:45:02 +0000
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2012-12-11 13:48:57 +0100
commit806b4da112b35313b7e674a2735d888809f74288 (patch)
tree206c54252f719399f8428600e094ba4be9e70e02 /src
parente35a77af29a48b9d2dbc4495e1d40495bde80e6c (diff)
Fallback to the native parent if winId() is 0.
In Qt 4.8 QPA promotion of alien to native is broken so we need to handle the case where winId is 0. Change-Id: Icc87253dce40294a646d63ed341fad31b38a84de Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/multimedia/qgraphicsvideoitem_overlay.cpp27
-rw-r--r--src/multimedia/qvideowidget.cpp28
-rw-r--r--src/multimedia/qvideowidget_p.h2
3 files changed, 54 insertions, 3 deletions
diff --git a/src/multimedia/qgraphicsvideoitem_overlay.cpp b/src/multimedia/qgraphicsvideoitem_overlay.cpp
index b01a385987..1bcd329083 100644
--- a/src/multimedia/qgraphicsvideoitem_overlay.cpp
+++ b/src/multimedia/qgraphicsvideoitem_overlay.cpp
@@ -103,6 +103,7 @@ public:
void clearService();
void updateRects();
void updateLastFrame();
+ void updateWindowId();
void _q_present();
void _q_updateNativeSize();
@@ -115,6 +116,30 @@ void QGraphicsVideoItemPrivate::_q_present()
}
+void QGraphicsVideoItemPrivate::updateWindowId()
+{
+ const WId winId = videoWidget->winId();
+
+ // If the window ID is 0, it was not possible to promote the video widget from an alien widget
+ // to a native widget. As a last resort use the native ancestor instead.
+ if (winId == 0) {
+ // Do not use videoWidget->effectiveWinId(), it will assert inside qtwidget
+ // This stuff is broken in QPA.
+ QWidget *parent = videoWidget;
+ while (parent && !parent->winId()) {
+ parent = parent->parentWidget();
+ }
+
+ if (parent) {
+ windowControl->setWinId(parent->winId());
+ QPoint topLeft = videoWidget->mapTo(parent, QPoint(0, 0));
+ windowControl->setDisplayRect(QRect(topLeft, videoWidget->size()));
+ }
+ } else {
+ windowControl->setWinId(winId);
+ }
+}
+
bool QGraphicsVideoItemPrivate::eventFilter(QObject *object, QEvent *event)
{
if (windowControl && object == videoWidget && QEvent::WinIdChange == event->type()) {
@@ -152,7 +177,7 @@ void QGraphicsVideoItemPrivate::setWidget(QWidget *widget)
if (videoWidget != widget) {
videoWidget = widget;
if (widget) {
- windowControl->setWinId(widget->winId());
+ updateWindowId();
widget->installEventFilter(this);
}
}
diff --git a/src/multimedia/qvideowidget.cpp b/src/multimedia/qvideowidget.cpp
index 58a37b45e8..c25bafc38e 100644
--- a/src/multimedia/qvideowidget.cpp
+++ b/src/multimedia/qvideowidget.cpp
@@ -329,7 +329,7 @@ QWindowVideoWidgetBackend::QWindowVideoWidgetBackend(
connect(control, SIGNAL(fullScreenChanged(bool)), m_widget, SLOT(_q_fullScreenChanged(bool)));
connect(control, SIGNAL(nativeSizeChanged()), m_widget, SLOT(_q_dimensionsChanged()));
- control->setWinId(widget->winId());
+ updateWindowId();
}
QWindowVideoWidgetBackend::~QWindowVideoWidgetBackend()
@@ -383,7 +383,7 @@ QSize QWindowVideoWidgetBackend::sizeHint() const
void QWindowVideoWidgetBackend::showEvent()
{
- m_windowControl->setWinId(m_widget->winId());
+ updateWindowId();
m_windowControl->setDisplayRect(m_widget->rect());
@@ -422,6 +422,30 @@ void QWindowVideoWidgetBackend::paintEvent(QPaintEvent *event)
event->accept();
}
+void QWindowVideoWidgetBackend::updateWindowId()
+{
+ const WId winId = m_widget->winId();
+
+ // If the window ID is 0, it was not possible to promote the video widget from an alien widget
+ // to a native widget. As a last resort use the native ancestor instead.
+ if (winId == 0) {
+ // Do not use m_widget->effectiveWinId(), it will assert inside qtwidget
+ // This stuff is broken in QPA.
+ QWidget *parent = m_widget;
+ while (parent && !parent->winId()) {
+ parent = parent->parentWidget();
+ }
+
+ if (parent) {
+ m_windowControl->setWinId(parent->winId());
+ QPoint topLeft = m_widget->mapTo(parent, QPoint(0, 0));
+ m_windowControl->setDisplayRect(QRect(topLeft, m_widget->size()));
+ }
+ } else {
+ m_windowControl->setWinId(winId);
+ }
+}
+
#if defined(Q_WS_WIN)
bool QWindowVideoWidgetBackend::winEvent(MSG *message, long *)
{
diff --git a/src/multimedia/qvideowidget_p.h b/src/multimedia/qvideowidget_p.h
index 88c35b737a..0177d23f95 100644
--- a/src/multimedia/qvideowidget_p.h
+++ b/src/multimedia/qvideowidget_p.h
@@ -212,6 +212,8 @@ public:
#endif
private:
+ void updateWindowId();
+
QMediaService *m_service;
QVideoWindowControl *m_windowControl;
QWidget *m_widget;