From b495a61c6b0c79d20d98428a34750ad30839e7e4 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 15 Oct 2012 17:18:46 +0200 Subject: [PATCH] QQuickScreen attached obj handles screenChanged and geometryChanged MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit sizeChanged is replaced with geometryChanged. Given a Window, it also needs to connect to the Window's screenChanged signal. The result is that if the screen is changed after the QQuickView is created, the Screen attached object will be updated. Change-Id: I64473dd960376b861eb50e3e5a1a296d0030e766 Reviewed-by: Samuel Rødal --- src/quick/items/qquickscreen.cpp | 25 ++++++++++++++++++------- src/quick/items/qquickscreen_p.h | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index faada2d..139cd72 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -102,7 +102,8 @@ QT_BEGIN_NAMESPACE QQuickScreenAttached::QQuickScreenAttached(QObject* attachee) : QObject(attachee) - , m_screen(0) + , m_screen(NULL) + , m_window(NULL) { m_attachee = qobject_cast(attachee); @@ -149,17 +150,27 @@ int QQuickScreenAttached::angleBetween(int a, int b) return m_screen->angleBetween((Qt::ScreenOrientation)a,(Qt::ScreenOrientation)b); } -void QQuickScreenAttached::windowChanged(QQuickWindow* c)//Called by QQuickItemPrivate::initWindow +void QQuickScreenAttached::windowChanged(QQuickWindow* c) { - QScreen* screen = c ? c->screen() : 0; + if (m_window) + disconnect(m_window, SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged(QScreen*))); + m_window = c; + screenChanged(c ? c->screen() : NULL); + if (c) + connect(c, SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged(QScreen*))); +} + +void QQuickScreenAttached::screenChanged(QScreen *screen) +{ + //qDebug() << "QQuickScreenAttached::screenChanged" << (screen ? screen->name() : QString::fromLatin1("null")); if (screen != m_screen) { QScreen* oldScreen = m_screen; m_screen = screen; if (oldScreen) { - disconnect(oldScreen, SIGNAL(sizeChanged(QSize)), + disconnect(oldScreen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(widthChanged())); - disconnect(oldScreen, SIGNAL(sizeChanged(QSize)), + disconnect(oldScreen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(heightChanged())); disconnect(oldScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SIGNAL(orientationChanged())); @@ -181,9 +192,9 @@ void QQuickScreenAttached::windowChanged(QQuickWindow* c)//Called by QQuickItemP emit primaryOrientationChanged(); - connect(screen, SIGNAL(sizeChanged(QSize)), + connect(screen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(widthChanged())); - connect(screen, SIGNAL(sizeChanged(QSize)), + connect(screen, SIGNAL(geometryChanged(QRect)), this, SIGNAL(heightChanged())); connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SIGNAL(orientationChanged())); diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 55ac979..46ea7ee 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -84,8 +84,12 @@ Q_SIGNALS: void primaryOrientationChanged(); void orientationChanged(); +protected slots: + void screenChanged(QScreen*); + private: QScreen* m_screen; + QQuickWindow* m_window; QQuickItem* m_attachee; }; -- 2.7.4