Added screenChanged() signal and handle screen destruction in QWindow.

It can be useful to get a signal when the QScreen changes, for example
when having bindings to QScreen properties in QML.

Change-Id: I919dd12c656485b28b393aec5eedac4c01593afc
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
This commit is contained in:
Samuel Rødal 2011-11-28 15:58:03 +01:00 committed by Qt by Nokia
parent 3d3fdcd3a5
commit 4db95ffd7d
2 changed files with 28 additions and 2 deletions

View File

@ -69,6 +69,7 @@ QWindow::QWindow(QScreen *targetScreen)
//screen list is populated.
Q_ASSERT(d->screen);
connect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
QGuiApplicationPrivate::window_list.prepend(this);
}
@ -674,12 +675,33 @@ void QWindow::setScreen(QScreen *newScreen)
const bool wasCreated = d->platformWindow != 0;
if (wasCreated)
destroy();
if (d->screen)
disconnect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
d->screen = newScreen;
if (wasCreated)
create();
if (newScreen) {
connect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
if (wasCreated)
create();
}
emit screenChanged(newScreen);
}
}
void QWindow::screenDestroyed(QObject *object)
{
Q_D(QWindow);
if (object == static_cast<QObject *>(d->screen))
setScreen(0);
}
/*!
\fn QWindow::screenChanged(QScreen *screen)
This signal is emitted when a window's screen changes, either
by being set explicitly with setScreen(), or automatically when
the window's screen is removed.
*/
/*!
Returns the accessibility interface for the object that the window represents
\preliminary

View File

@ -248,6 +248,7 @@ public Q_SLOTS:
Q_SIGNALS:
void backBufferReady();
void screenChanged(QScreen *screen);
void xChanged(int arg);
@ -261,6 +262,9 @@ Q_SIGNALS:
void orientationChanged(Qt::ScreenOrientation arg);
private Q_SLOTS:
void screenDestroyed(QObject *screen);
protected:
virtual void exposeEvent(QExposeEvent *);
virtual void resizeEvent(QResizeEvent *);