Expose screen change event to widgets so that they can check the dpr

Unlike ordinary widgets, the ones that have OpenGL framebuffers must know
about screen changes because the device pixel ratio may be different on
the new screen. Add an internal event, ScreenChangeInternal, as the
counterpart to WindowChangeInternal.

Change-Id: I5e55999838e4c0284e7d9832299f7cc6b541ee3f
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
This commit is contained in:
Laszlo Agocs 2014-09-10 11:42:55 +02:00
parent 8610534f53
commit 49194275e0
5 changed files with 30 additions and 4 deletions

View File

@ -278,6 +278,7 @@ QT_BEGIN_NAMESPACE
\omitvalue FutureCallOut
\omitvalue NativeGesture
\omitvalue WindowChangeInternal
\omitvalue ScreenChangeInternal
*/
/*!

View File

@ -281,6 +281,7 @@ public:
ApplicationStateChange = 214,
WindowChangeInternal = 215, // internal for QQuickWidget
ScreenChangeInternal = 216,
// 512 reserved for Qt Jambi's MetaCall event
// 513 reserved for Qt Jambi's DeleteOnMainThread event

View File

@ -1061,6 +1061,10 @@ bool QOpenGLWidget::event(QEvent *e)
d->recreateFbo();
}
break;
case QEvent::ScreenChangeInternal:
if (d->initialized && d->paintDevice->devicePixelRatio() != devicePixelRatio())
d->recreateFbo();
break;
default:
break;
}

View File

@ -99,7 +99,7 @@ QWidgetWindow::QWidgetWindow(QWidget *widget)
setSurfaceType(QSurface::RasterGLSurface);
}
connect(m_widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName);
connect(this, SIGNAL(screenChanged(QScreen*)), this, SLOT(repaintWindow()));
connect(this, SIGNAL(screenChanged(QScreen*)), this, SLOT(handleScreenChange()));
}
QWidgetWindow::~QWidgetWindow()
@ -558,8 +558,27 @@ void QWidgetWindow::updateGeometry()
m_widget->data->fstrut_dirty = false;
}
// Invalidates the backing store buffer and repaints immediately.
// ### Qt 5.4: replace with QUpdateWindowRequestEvent.
static void sendScreenChangeRecursively(QWidget *widget)
{
QEvent e(QEvent::ScreenChangeInternal);
QApplication::sendEvent(widget, &e);
QWidgetPrivate *d = QWidgetPrivate::get(widget);
for (int i = 0; i < d->children.size(); ++i) {
QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
if (w)
sendScreenChangeRecursively(w);
}
}
void QWidgetWindow::handleScreenChange()
{
// Send an event recursively to the widget and its children.
sendScreenChangeRecursively(m_widget);
// Invalidate the backing store buffer and repaint immediately.
repaintWindow();
}
void QWidgetWindow::repaintWindow()
{
if (!m_widget->isVisible() || !m_widget->updatesEnabled())

View File

@ -101,9 +101,10 @@ protected:
private slots:
void updateObjectName();
void repaintWindow();
void handleScreenChange();
private:
void repaintWindow();
void updateGeometry();
void updateNormalGeometry();