Made it possible to report screen changes through QWindowSystemInterface.

This makes it possible for platform plugin independent code (such as
generic plugins) to report changes to screen properties. An example
would be an accelerometer plugin that reports orientation changes
without knowing anything about the windowing system.

Change-Id: I984984b6d064327772c264bc942269422451da37
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
Samuel Rødal 2012-01-11 13:16:24 +01:00 committed by Qt by Nokia
parent 738896d6b9
commit 16c2622fe7
13 changed files with 222 additions and 57 deletions

View File

@ -13,6 +13,7 @@ HEADERS += \
kernel/qplatformintegration_qpa.h \
kernel/qplatformdrag_qpa.h \
kernel/qplatformscreen_qpa.h \
kernel/qplatformscreen_qpa_p.h \
kernel/qplatforminputcontext_qpa.h \
kernel/qplatformintegrationfactory_qpa_p.h \
kernel/qplatformintegrationplugin_qpa.h \
@ -50,6 +51,7 @@ HEADERS += \
kernel/qsessionmanager.h \
kernel/qwindowdefs.h \
kernel/qscreen.h \
kernel/qscreen_p.h \
kernel/qstylehints.h \
kernel/qtouchdevice.h \
kernel/qtouchdevice_p.h

View File

@ -57,6 +57,7 @@
#include <QtDebug>
#include <qpalette.h>
#include <qscreen.h>
#include <private/qscreen_p.h>
#include <QtGui/QPlatformIntegration>
#include <QtGui/QGenericPluginFactory>
@ -1021,6 +1022,8 @@ void QGuiApplicationPrivate::reportScreenOrientationChange(QWindowSystemInterfac
return;
QScreen *s = e->screen.data();
s->d_func()->currentOrientation = e->orientation;
emit s->currentOrientationChanged(s->currentOrientation());
QScreenOrientationChangeEvent event(s, s->currentOrientation());
@ -1037,6 +1040,7 @@ void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate:
return;
QScreen *s = e->screen.data();
s->d_func()->geometry = e->geometry;
emit s->sizeChanged(s->size());
emit s->geometryChanged(s->geometry());
@ -1058,6 +1062,7 @@ void QGuiApplicationPrivate::reportAvailableGeometryChange(
return;
QScreen *s = e->screen.data();
s->d_func()->availableGeometry = e->availableGeometry;
emit s->availableSizeChanged(s->availableSize());
emit s->availableGeometryChanged(s->availableGeometry());
@ -1073,6 +1078,7 @@ void QGuiApplicationPrivate::reportLogicalDotsPerInchChange(QWindowSystemInterfa
return;
QScreen *s = e->screen.data();
s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
emit s->logicalDotsPerInchXChanged(s->logicalDotsPerInchX());
emit s->logicalDotsPerInchYChanged(s->logicalDotsPerInchY());

View File

@ -46,6 +46,7 @@
#include <QtGui/QPlatformAccessibility>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qplatformscreen_qpa_p.h>
#include <private/qdnd_p.h>
QT_BEGIN_NAMESPACE
@ -255,11 +256,10 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
*/
void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
{
QScreen *screen = ps ? ps->screen() : 0;
if (screen && !QGuiApplicationPrivate::screen_list.contains(screen)) {
QGuiApplicationPrivate::screen_list << screen;
emit qGuiApp->screenAdded(screen);
}
QScreen *screen = new QScreen(ps);
ps->d_func()->screen = screen;
QGuiApplicationPrivate::screen_list << screen;
emit qGuiApp->screenAdded(screen);
}
class QPlatformTheme *QPlatformIntegration::platformTheme() const

View File

@ -42,23 +42,18 @@
#include "qplatformscreen_qpa.h"
#include <QtGui/qguiapplication.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qplatformscreen_qpa_p.h>
#include <QtGui/qplatformintegration_qpa.h>
#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
QT_BEGIN_NAMESPACE
class QPlatformScreenPrivate
{
public:
QScreen *screen;
};
QPlatformScreen::QPlatformScreen()
: d_ptr(new QPlatformScreenPrivate)
{
Q_D(QPlatformScreen);
d->screen = new QScreen(this);
d->screen = 0;
}
QPlatformScreen::~QPlatformScreen()

View File

@ -120,6 +120,8 @@ protected:
private:
Q_DISABLE_COPY(QPlatformScreen)
friend class QPlatformIntegration;
};
QT_END_NAMESPACE

View File

@ -0,0 +1,74 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPLATFORMSCREEN_QPA_P_H
#define QPLATFORMSCREEN_QPA_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QScreen;
class QPlatformScreenPrivate
{
public:
QScreen *screen;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QPLATFORMSCREEN_QPA_P_H

View File

@ -40,23 +40,13 @@
****************************************************************************/
#include "qscreen.h"
#include "qscreen_p.h"
#include "qplatformscreen_qpa.h"
#include <QtCore/private/qobject_p.h>
QT_BEGIN_NAMESPACE
class QScreenPrivate : public QObjectPrivate
{
public:
QScreenPrivate(QPlatformScreen *screen)
: platformScreen(screen)
{
}
QPlatformScreen *platformScreen;
};
/*!
\class QScreen
\brief The QScreen class is used to query screen properties.
@ -119,7 +109,7 @@ int QScreen::depth() const
QSize QScreen::size() const
{
Q_D(const QScreen);
return d->platformScreen->geometry().size();
return d->geometry.size();
}
/*!
@ -184,7 +174,7 @@ qreal QScreen::physicalDotsPerInch() const
qreal QScreen::logicalDotsPerInchX() const
{
Q_D(const QScreen);
return d->platformScreen->logicalDpi().first;
return d->logicalDpi.first;
}
/*!
@ -198,7 +188,7 @@ qreal QScreen::logicalDotsPerInchX() const
qreal QScreen::logicalDotsPerInchY() const
{
Q_D(const QScreen);
return d->platformScreen->logicalDpi().second;
return d->logicalDpi.second;
}
/*!
@ -216,7 +206,7 @@ qreal QScreen::logicalDotsPerInchY() const
qreal QScreen::logicalDotsPerInch() const
{
Q_D(const QScreen);
QDpi dpi = d->platformScreen->logicalDpi();
QDpi dpi = d->logicalDpi;
return (dpi.first + dpi.second) * qreal(0.5);
}
@ -246,7 +236,7 @@ QSizeF QScreen::physicalSize() const
QSize QScreen::availableSize() const
{
Q_D(const QScreen);
return d->platformScreen->availableGeometry().size();
return d->availableGeometry.size();
}
/*!
@ -259,7 +249,7 @@ QSize QScreen::availableSize() const
QRect QScreen::geometry() const
{
Q_D(const QScreen);
return d->platformScreen->geometry();
return d->geometry;
}
/*!
@ -272,7 +262,7 @@ QRect QScreen::geometry() const
QRect QScreen::availableGeometry() const
{
Q_D(const QScreen);
return d->platformScreen->availableGeometry();
return d->availableGeometry;
}
/*!
@ -315,10 +305,9 @@ QSize QScreen::virtualSize() const
*/
QRect QScreen::virtualGeometry() const
{
Q_D(const QScreen);
QRect result;
foreach (QPlatformScreen *platformScreen, d->platformScreen->virtualSiblings())
result |= platformScreen->geometry();
foreach (QScreen *screen, virtualSiblings())
result |= screen->geometry();
return result;
}
@ -347,10 +336,9 @@ QSize QScreen::availableVirtualSize() const
*/
QRect QScreen::availableVirtualGeometry() const
{
Q_D(const QScreen);
QRect result;
foreach (QPlatformScreen *platformScreen, d->platformScreen->virtualSiblings())
result |= platformScreen->availableGeometry();
foreach (QScreen *screen, virtualSiblings())
result |= screen->availableGeometry();
return result;
}
@ -383,7 +371,7 @@ Qt::ScreenOrientation QScreen::primaryOrientation() const
Qt::ScreenOrientation QScreen::currentOrientation() const
{
Q_D(const QScreen);
return d->platformScreen->currentOrientation();
return d->currentOrientation;
}
// i must be power of two

View File

@ -140,6 +140,7 @@ private:
Q_DISABLE_COPY(QScreen)
friend class QGuiApplicationPrivate;
friend class QPlatformIntegration;
friend class QPlatformScreen;
};

View File

@ -0,0 +1,80 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSCREEN_P_H
#define QSCREEN_P_H
#include <QtGui/qscreen.h>
#include <QtGui/qplatformscreen_qpa.h>
#include <QtCore/private/qobject_p.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QScreenPrivate : public QObjectPrivate
{
public:
QScreenPrivate(QPlatformScreen *screen)
: platformScreen(screen)
{
currentOrientation = screen->currentOrientation();
geometry = screen->geometry();
availableGeometry = screen->availableGeometry();
logicalDpi = screen->logicalDpi();
}
Qt::ScreenOrientation currentOrientation;
QRect geometry;
QRect availableGeometry;
QDpi logicalDpi;
QPlatformScreen *platformScreen;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QSCREEN_P_H

View File

@ -275,31 +275,31 @@ void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QTo
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen)
void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
{
QWindowSystemInterfacePrivate::ScreenOrientationEvent *e =
new QWindowSystemInterfacePrivate::ScreenOrientationEvent(screen);
new QWindowSystemInterfacePrivate::ScreenOrientationEvent(screen, orientation);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen)
void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const QRect &geometry)
{
QWindowSystemInterfacePrivate::ScreenGeometryEvent *e =
new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screen);
new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screen, geometry);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenAvailableGeometryChange(QScreen *screen)
void QWindowSystemInterface::handleScreenAvailableGeometryChange(QScreen *screen, const QRect &availableGeometry)
{
QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e =
new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screen);
new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screen, availableGeometry);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen)
void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
{
QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e =
new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen);
new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, dpiX, dpiY);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}

View File

@ -122,10 +122,10 @@ public:
static Qt::DropAction handleDrop(QWindow *w, QMimeData *dropData, const QPoint &p);
// Changes to the screen
static void handleScreenOrientationChange(QScreen *screen);
static void handleScreenGeometryChange(QScreen *screen);
static void handleScreenAvailableGeometryChange(QScreen *screen);
static void handleScreenLogicalDotsPerInchChange(QScreen *screen);
static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation);
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry);
static void handleScreenAvailableGeometryChange(QScreen *screen, const QRect &newAvailableGeometry);
static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
// For event dispatcher implementations
static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags);

View File

@ -197,30 +197,35 @@ public:
class ScreenOrientationEvent : public WindowSystemEvent {
public:
ScreenOrientationEvent(QScreen *s)
: WindowSystemEvent(ScreenOrientation), screen(s) { }
ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
: WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
QWeakPointer<QScreen> screen;
Qt::ScreenOrientation orientation;
};
class ScreenGeometryEvent : public WindowSystemEvent {
public:
ScreenGeometryEvent(QScreen *s)
: WindowSystemEvent(ScreenGeometry), screen(s) { }
ScreenGeometryEvent(QScreen *s, const QRect &g)
: WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
QWeakPointer<QScreen> screen;
QRect geometry;
};
class ScreenAvailableGeometryEvent : public WindowSystemEvent {
public:
ScreenAvailableGeometryEvent(QScreen *s)
: WindowSystemEvent(ScreenAvailableGeometry), screen(s) { }
ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
: WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
QWeakPointer<QScreen> screen;
QRect availableGeometry;
};
class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
public:
ScreenLogicalDotsPerInchEvent(QScreen *s)
: WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s) { }
ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
: WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
QWeakPointer<QScreen> screen;
qreal dpiX;
qreal dpiY;
};
class MapEvent : public WindowSystemEvent {

View File

@ -52,6 +52,7 @@ private slots:
void angleBetween();
void transformBetween_data();
void transformBetween();
void orientationChange();
};
void tst_QScreen::angleBetween_data()
@ -163,5 +164,16 @@ void tst_QScreen::transformBetween()
QCOMPARE(QScreen::transformBetween(a, b, rect), expected);
}
void tst_QScreen::orientationChange()
{
QScreen *screen = QGuiApplication::primaryScreen();
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
QTRY_COMPARE(screen->currentOrientation(), Qt::LandscapeOrientation);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
QTRY_COMPARE(screen->currentOrientation(), Qt::PortraitOrientation);
}
#include <tst_qscreen.moc>
QTEST_MAIN(tst_QScreen);