summaryrefslogtreecommitdiffstats
path: root/tests/manual/qscreen/main.cpp
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2014-06-25 15:09:09 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-02 23:14:19 +0200
commit5f504166203d9562ef5b41a0f18ae191aa34ee63 (patch)
treea9e528110a7fd16a06e07b94659f70a33be81e4e /tests/manual/qscreen/main.cpp
parent0541516907da117c391b6c8d9820209673fcd9cd (diff)
Make it possible to know when a screen is being removed
So far, we had to listen to the QObject::destroyed signal from the QScreen class to figure out whether a screen was removed. Often, this is already too late, given that most of the QWindows have been moved by then and we don't get to react before the windows are being set to the primary screen. This patch introduces a new signal that will notify about a screen removal before the screen is started to be destroyed, so that the application gets to decide what to do with the screens before Qt decides to move things around. [ChangeLog][QtGui][QGuiApplication] Added QGuiApplication::screenRemoved signal to inform that a screen has been removed, before Qt reacts to it. Change-Id: I99304179f4d345cae581a87baac6cff7b8773dea Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/manual/qscreen/main.cpp')
-rw-r--r--tests/manual/qscreen/main.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp
index 905c7d6f77..c085d3fd5b 100644
--- a/tests/manual/qscreen/main.cpp
+++ b/tests/manual/qscreen/main.cpp
@@ -49,6 +49,9 @@
int i = 0;
+typedef QHash<QScreen*, PropertyWatcher*> ScreensHash;
+Q_GLOBAL_STATIC(ScreensHash, props);
+
void updateSiblings(PropertyWatcher* w)
{
QLineEdit *siblingsField = w->findChild<QLineEdit *>("siblings");
@@ -88,12 +91,19 @@ void screenAdded(QScreen* screen)
geom.moveCenter(screen->geometry().center());
w->move(geom.topLeft());
+ props->insert(screen, w);
+
// workaround for the fact that virtualSiblings is not a property,
// thus there is no change notification:
// allow the user to update the field manually
QObject::connect(w, &PropertyWatcher::updatedAllFields, &updateSiblings);
}
+void screenRemoved(QScreen* screen)
+{
+ delete props->take(screen);
+}
+
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
@@ -101,5 +111,6 @@ int main(int argc, char *argv[])
foreach (QScreen *screen, screens)
screenAdded(screen);
QObject::connect((const QGuiApplication*)QGuiApplication::instance(), &QGuiApplication::screenAdded, &screenAdded);
+ QObject::connect((const QGuiApplication*)QGuiApplication::instance(), &QGuiApplication::screenRemoved, &screenRemoved);
return a.exec();
}