summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2013-07-23 10:17:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-26 06:31:33 +0200
commit4b3346145543f5fd2ebc83c329a60407058468db (patch)
tree6e0da07e09863ad554e17b0c0b52758f0a9bdacc /src
parent34d2abe3093a71ca098dd35bd6ac0aa78fe42249 (diff)
Fix updating of screens in QDesktopWidget.
Task-number: QTBUG-32567 Change-Id: Ib7442aed518427aa995cfc365ade6e6ffaf9c428 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qdesktopwidget.h1
-rw-r--r--src/widgets/kernel/qdesktopwidget_qpa.cpp44
-rw-r--r--src/widgets/kernel/qdesktopwidget_qpa_p.h2
3 files changed, 35 insertions, 12 deletions
diff --git a/src/widgets/kernel/qdesktopwidget.h b/src/widgets/kernel/qdesktopwidget.h
index da44242b86..42c338f696 100644
--- a/src/widgets/kernel/qdesktopwidget.h
+++ b/src/widgets/kernel/qdesktopwidget.h
@@ -92,6 +92,7 @@ protected:
private:
Q_DISABLE_COPY(QDesktopWidget)
Q_DECLARE_PRIVATE(QDesktopWidget)
+ Q_PRIVATE_SLOT(d_func(), void _q_updateScreens())
friend class QApplication;
friend class QApplicationPrivate;
diff --git a/src/widgets/kernel/qdesktopwidget_qpa.cpp b/src/widgets/kernel/qdesktopwidget_qpa.cpp
index 64236321a4..015573dfbe 100644
--- a/src/widgets/kernel/qdesktopwidget_qpa.cpp
+++ b/src/widgets/kernel/qdesktopwidget_qpa.cpp
@@ -49,12 +49,13 @@ QT_BEGIN_NAMESPACE
QT_USE_NAMESPACE
-void QDesktopWidgetPrivate::updateScreenList()
+void QDesktopWidgetPrivate::_q_updateScreens()
{
Q_Q(QDesktopWidget);
- QList<QScreen *> screenList = QGuiApplication::screens();
- int targetLength = screenList.length();
- int currentLength = screens.length();
+ const QList<QScreen *> screenList = QGuiApplication::screens();
+ const int targetLength = screenList.length();
+ const int oldLength = screens.length();
+ int currentLength = oldLength;
// Add or remove screen widgets as necessary
if(currentLength > targetLength) {
@@ -65,23 +66,41 @@ void QDesktopWidgetPrivate::updateScreenList()
}
}
else if (currentLength < targetLength) {
- QDesktopScreenWidget *screen;
while (currentLength < targetLength) {
- screen = new QDesktopScreenWidget(currentLength++);
- screens.append(screen);
+ QScreen *qScreen = screenList.at(currentLength);
+ QDesktopScreenWidget *screenWidget = new QDesktopScreenWidget(currentLength++);
+ screenWidget->setGeometry(qScreen->geometry());
+ QObject::connect(qScreen, SIGNAL(geometryChanged(QRect)),
+ q, SLOT(_q_updateScreens()), Qt::QueuedConnection);
+ QObject::connect(qScreen, SIGNAL(destroyed()),
+ q, SLOT(_q_updateScreens()), Qt::QueuedConnection);
+ screens.append(screenWidget);
}
}
QRegion virtualGeometry;
- // update the geometry of each screen widget
+ // update the geometry of each screen widget, determine virtual geometry
+ // and emit change signals afterwards.
+ QList<int> changedScreens;
for (int i = 0; i < screens.length(); i++) {
- QRect screenGeometry = screenList.at(i)->geometry();
- screens.at(i)->setGeometry(screenGeometry);
+ const QRect screenGeometry = screenList.at(i)->geometry();
+ if (screenGeometry != screens.at(i)->geometry()) {
+ screens.at(i)->setGeometry(screenGeometry);
+ changedScreens.push_back(i);
+ }
virtualGeometry += screenGeometry;
}
q->setGeometry(virtualGeometry.boundingRect());
+
+ if (oldLength != targetLength)
+ emit q->screenCountChanged(targetLength);
+
+ foreach (int changedScreen, changedScreens) {
+ emit q->resized(changedScreen);
+ emit q->workAreaResized(changedScreen);
+ }
}
QDesktopWidget::QDesktopWidget()
@@ -89,7 +108,8 @@ QDesktopWidget::QDesktopWidget()
{
Q_D(QDesktopWidget);
setObjectName(QLatin1String("desktop"));
- d->updateScreenList();
+ d->_q_updateScreens();
+ connect(qApp, SIGNAL(screenAdded(QScreen*)), this, SLOT(_q_updateScreens()));
}
QDesktopWidget::~QDesktopWidget()
@@ -169,3 +189,5 @@ void QDesktopWidget::resizeEvent(QResizeEvent *)
}
QT_END_NAMESPACE
+
+#include "moc_qdesktopwidget.cpp"
diff --git a/src/widgets/kernel/qdesktopwidget_qpa_p.h b/src/widgets/kernel/qdesktopwidget_qpa_p.h
index 017934fbf1..f461869f1b 100644
--- a/src/widgets/kernel/qdesktopwidget_qpa_p.h
+++ b/src/widgets/kernel/qdesktopwidget_qpa_p.h
@@ -74,7 +74,7 @@ class QDesktopWidgetPrivate : public QWidgetPrivate {
public:
~QDesktopWidgetPrivate() {foreach(QDesktopScreenWidget *s, screens) delete s; }
- void updateScreenList();
+ void _q_updateScreens();
QList<QDesktopScreenWidget *> screens;
};