Added Orientation API to QScreen and QWindow.

QScreen now has a primary and current orientation, and a QWindow can set
its orientation as well. The current screen orientation is just a hint
to the application.

Change-Id: I4635982cfac2d16634d4edd5c6ab78e9d0ac55a4
Reviewed-on: http://codereview.qt-project.org/5988
Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Samuel Rødal 2011-10-04 13:11:30 +02:00 committed by Qt by Nokia
parent 090d825e1d
commit c66b7cf55b
23 changed files with 521 additions and 106 deletions

View File

@ -40,9 +40,11 @@
#include "paintedwindow.h"
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QOpenGLPaintDevice>
#include <QPainter>
#include <QScreen>
#include <QTimer>
#include <qmath.h>
@ -74,19 +76,56 @@ void PaintedWindow::exposeEvent(QExposeEvent *)
paint();
}
void PaintedWindow::mousePressEvent(QMouseEvent *)
{
Qt::ScreenOrientation o = orientation();
if (o == Qt::UnknownOrientation)
o = QGuiApplication::primaryScreen()->primaryOrientation();
switch (o) {
case Qt::LandscapeOrientation:
setOrientation(Qt::PortraitOrientation);
break;
case Qt::PortraitOrientation:
setOrientation(Qt::InvertedLandscapeOrientation);
break;
case Qt::InvertedLandscapeOrientation:
setOrientation(Qt::InvertedPortraitOrientation);
break;
case Qt::InvertedPortraitOrientation:
setOrientation(Qt::LandscapeOrientation);
break;
default:
Q_ASSERT(false);
}
paint();
}
void PaintedWindow::paint()
{
m_context->makeCurrent(this);
QPainterPath path;
path.addEllipse(0, 0, width(), height());
QOpenGLPaintDevice device(size());
Qt::ScreenOrientation screenOrientation = QGuiApplication::primaryScreen()->primaryOrientation();
Qt::ScreenOrientation appOrientation = orientation();
QRect rect(0, 0, width(), height());
QRect mapped = QScreen::mapBetween(appOrientation, screenOrientation, rect);
QPainterPath path;
path.addEllipse(mapped);
QPainter painter(&device);
painter.fillRect(0, 0, width(), height(), Qt::white);
painter.setTransform(QScreen::transformBetween(appOrientation, screenOrientation, rect));
painter.fillRect(mapped, Qt::white);
painter.setRenderHint(QPainter::Antialiasing);
painter.fillPath(path, Qt::blue);
QFont font;
font.setPixelSize(64);
painter.setFont(font);
painter.drawText(mapped, Qt::AlignCenter, "Hello");
painter.end();
m_context->swapBuffers(this);

View File

@ -63,6 +63,7 @@ private slots:
private:
void resizeEvent(QResizeEvent *);
void exposeEvent(QExposeEvent *);
void mousePressEvent(QMouseEvent *);
QOpenGLContext *m_context;
};

View File

@ -283,6 +283,14 @@ public:
Q_DECLARE_FLAGS(WindowStates, WindowState)
enum ScreenOrientation {
UnknownOrientation,
LandscapeOrientation,
PortraitOrientation,
InvertedLandscapeOrientation,
InvertedPortraitOrientation
};
enum WidgetAttribute {
WA_Disabled = 0,
WA_UnderMouse = 1,

View File

@ -1825,6 +1825,19 @@
*/
/*!
\enum Qt::ScreenOrientation
This enum type specifies the various orientations a screen might have.
\value UnknownOrientation The orientation is unknown or the platform doesn't support orientations.
\value LandscapeOrientation Landscape orientation, display width is greater than display height.
\value PortraitOrientation Portrait orientation, display height is greater than display width,
rotated 90 degree clockwise relative to landscape.
\value InvertedLandscapeOrientation Inverted landscape orientation, rotated 180 degrees relative to landscape.
\value InvertedPortraitOrientation Inverted portrait orientation, rotated 180 degrees relative to portrait.
*/
/*!
\enum Qt::ContextMenuPolicy

View File

@ -4327,59 +4327,16 @@ const QScrollEventPrivate *QScrollEvent::d_func() const
return reinterpret_cast<const QScrollEventPrivate *>(d);
}
/*!
\enum QScreenOrientationChangeEvent::Orientation
This enum describes the orientations that a device can have.
\value Portrait The device is in a position where its top edge is pointing up.
\value Landscape The device is rotated clockwise 90 degrees, so that its left edge is pointing up.
\value PortraitInverted The device is rotated 180 degrees, so that its bottom edge is pointing up.
\value LandscapeInverted The device is counterclockwise 90 degrees, so that its right edge is pointing up.
\sa QScreenOrientationChangeEvent::orientation()
\sa QScreenOrientationChangeEvent::orientationInDegrees()
*/
/*!
Creates a new QScreenOrientationChangeEvent
\a screenOrientationInDegrees is the new screen orientation, expressed in degrees.
The orientation must be expressed in steps of 90 degrees.
*/
QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(qint32 screenOrientationInDegrees)
: QEvent(QEvent::OrientationChange)
{
d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate());
d_func()->orientationInDegrees = screenOrientationInDegrees;
qint32 orientationIndex = (qAbs(screenOrientationInDegrees) % 360) / 90;
// flip around the negative coords to correct order.
if (screenOrientationInDegrees < 0) {
if (orientationIndex == 1)
orientationIndex = 3;
else if (orientationIndex == 3)
orientationIndex = 1;
}
orientationIndex = qPow(2, orientationIndex);
d_func()->orientation = (QScreenOrientationChangeEvent::Orientation)(orientationIndex);
d_func()->isValid = (screenOrientationInDegrees % 90 == 0);
}
/*!
Creates a new QScreenOrientationChangeEvent
\a orientation is the new orientation of the screen.
*/
QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreenOrientationChangeEvent::Orientation screenOrientation)
QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation)
: QEvent(QEvent::OrientationChange)
{
d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate());
d_func()->screen = screen;
d_func()->orientation = screenOrientation;
d_func()->orientationInDegrees = 90 * ((uint)screenOrientation);
d_func()->isValid = true;
}
/*!
@ -4391,21 +4348,19 @@ QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent()
}
/*!
Returns the orientation of the screen.
Returns the screen whose orientation changed.
*/
QScreenOrientationChangeEvent::Orientation QScreenOrientationChangeEvent::orientation() const
QScreen *QScreenOrientationChangeEvent::screen() const
{
return d_func()->orientation;
return d_func()->screen;
}
/*!
Returns the screen orientation in degrees.
The orientation is expressed in steps of 90 degrees and depends on the previous value of the orientation.
This is intended to allow for smooth animations from one orientation to the other.
Returns the orientation of the screen.
*/
qint32 QScreenOrientationChangeEvent::orientationInDegrees() const
Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
{
return d_func()->orientationInDegrees;
return d_func()->orientation;
}
/*!

View File

@ -69,6 +69,7 @@ class QAction;
#ifndef QT_NO_GESTURES
class QGesture;
#endif
class QScreen;
class Q_GUI_EXPORT QInputEvent : public QEvent
{
@ -840,24 +841,15 @@ class QScreenOrientationChangeEventPrivate;
class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
{
public:
enum Orientation {
Portrait = 1,
Landscape = 2,
PortraitInverted = 4,
LandscapeInverted = 8
};
QScreenOrientationChangeEvent(qint32 screenOrientationInDegrees);
QScreenOrientationChangeEvent(Orientation screenOrientation);
QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation);
~QScreenOrientationChangeEvent();
bool isValid() const;
qint32 orientationInDegrees() const;
Orientation orientation() const;
QScreen *screen() const;
Qt::ScreenOrientation orientation() const;
private:
QScreenOrientationChangeEventPrivate *d_func();
const QScreenOrientationChangeEventPrivate *d_func() const;
};
QT_END_NAMESPACE

View File

@ -159,9 +159,9 @@ public:
inline QScreenOrientationChangeEventPrivate()
{
}
QScreenOrientationChangeEvent::Orientation orientation;
qint32 orientationInDegrees;
bool isValid;
QScreen *screen;
Qt::ScreenOrientation orientation;
};
QT_END_NAMESPACE

View File

@ -533,9 +533,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
QGuiApplicationPrivate::processCloseEvent(
static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
break;
case QWindowSystemInterfacePrivate::ScreenCountChange:
QGuiApplicationPrivate::reportScreenCount(
static_cast<QWindowSystemInterfacePrivate::ScreenCountEvent *>(e));
case QWindowSystemInterfacePrivate::ScreenOrientation:
QGuiApplicationPrivate::reportScreenOrientationChange(
static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
break;
case QWindowSystemInterfacePrivate::ScreenGeometry:
QGuiApplicationPrivate::reportGeometryChange(
@ -919,16 +919,20 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
}
}
void QGuiApplicationPrivate::reportScreenCount(QWindowSystemInterfacePrivate::ScreenCountEvent *)
void QGuiApplicationPrivate::reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
{
// This operation only makes sense after the QGuiApplication constructor runs
if (QCoreApplication::startingUp())
return;
//QGuiApplication::desktop()->d_func()->updateScreenList();
// signal anything listening for creation or deletion of screens
//QDesktopWidget *desktop = QGuiApplication::desktop();
//emit desktop->screenCountChanged(e->count);
if (!e->screen)
return;
QScreen *s = e->screen.data();
emit s->currentOrientationChanged(s->currentOrientation());
QScreenOrientationChangeEvent event(s, s->currentOrientation());
QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
}
void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *)

View File

@ -114,7 +114,7 @@ public:
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
static void reportScreenCount(QWindowSystemInterfacePrivate::ScreenCountEvent *e);
static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e);

View File

@ -164,6 +164,39 @@ QDpi QPlatformScreen::logicalDpi() const
25.4 * s.height() / ps.height());
}
/*!
Reimplement this function in subclass to return the primary orientation
of the screen, i.e. the orientation the display controller or equivalent
expects.
The default implementation returns Qt::PortraitOrientation if the
geometry's height is greater or Qt::LandscapeOrientation if the geometry's
width is greater.
*/
Qt::ScreenOrientation QPlatformScreen::primaryOrientation() const
{
return geometry().height() > geometry().width() ? Qt::PortraitOrientation :
Qt::LandscapeOrientation;
}
/*!
Reimplement this function in subclass to return the current orientation
of the screen, for example based on accelerometer data to determine
the physical screen orientation.
The current orientation is only a hint to the application saying
what the preferred application orientation should be, the application
is free to limit itself to a certain set of supported orientations.
The default implementation returns the same as primaryOrientation().
\sa primaryOrientation()
*/
Qt::ScreenOrientation QPlatformScreen::currentOrientation() const
{
return primaryOrientation();
}
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)
{
return window->screen()->handle();

View File

@ -99,6 +99,9 @@ public:
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
virtual Qt::ScreenOrientation currentOrientation() const;
virtual Qt::ScreenOrientation primaryOrientation() const;
virtual QWindow *topLevelAt(const QPoint &point) const;
virtual QList<QPlatformScreen *> virtualSiblings() const;

View File

@ -231,6 +231,20 @@ void QPlatformWindow::requestActivateWindow()
QWindowSystemInterface::handleWindowActivated(window());
}
/*!
Set the orientation of the platform window's contents.
This is a hint to the window manager in case it needs to display
additional content like popups, dialogs, status bars, or similar
in relation to the window.
\sa QWindow::setOrientation()
*/
void QPlatformWindow::setOrientation(Qt::ScreenOrientation orientation)
{
Q_UNUSED(orientation);
}
bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
{
Q_UNUSED(grab);

View File

@ -95,6 +95,8 @@ public:
virtual void setOpacity(qreal level);
virtual void requestActivateWindow();
virtual void setOrientation(Qt::ScreenOrientation orientation);
virtual bool setKeyboardGrabEnabled(bool grab);
virtual bool setMouseGrabEnabled(bool grab);

View File

@ -278,4 +278,122 @@ QRect QScreen::availableVirtualGeometry() const
return result;
}
/*!
Gets the primary screen orientation.
The primary screen orientation is the orientation that corresponds
to an un-rotated screen buffer. When the current orientation is equal
to the primary orientation no rotation needs to be done by the
application.
*/
Qt::ScreenOrientation QScreen::primaryOrientation() const
{
Q_D(const QScreen);
return d->platformScreen->primaryOrientation();
}
/*!
Gets the current orientation of the screen.
The current orientation is a hint to the application saying
what the preferred application orientation should be, based on the
current orientation of the physical display and / or other factors.
\sa primaryOrientation()
\sa currentOrientationChanged()
*/
Qt::ScreenOrientation QScreen::currentOrientation() const
{
Q_D(const QScreen);
return d->platformScreen->currentOrientation();
}
/*!
Convenience function to compute the angle of rotation to get from
rotation \a a to rotation \a b.
The result will be 0, 90, 180, or 270.
*/
int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
{
if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
return 0;
int delta = int(b) - int(a);
if (delta < 0)
delta = delta + 4;
int angles[] = { 0, 90, 180, 270 };
return angles[delta];
}
/*!
Convenience function to compute a transform that maps from the coordinate system
defined by orientation \a a into the coordinate system defined by orientation
\a b and target dimensions \a target.
Example, \a a is Qt::Landscape, \a b is Qt::Portrait, and \a target is QRect(0, 0, w, h)
the resulting transform will be such that the point QPoint(0, 0) is mapped to QPoint(0, w),
and QPoint(h, w) is mapped to QPoint(0, h). Thus, the landscape coordinate system QRect(0, 0, h, w)
is mapped (with a 90 degree rotation) into the portrait coordinate system QRect(0, 0, w, h).
*/
QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target)
{
if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
return QTransform();
int angle = angleBetween(a, b);
QTransform result;
switch (angle) {
case 90:
result.translate(target.width(), 0);
break;
case 180:
result.translate(target.width(), target.height());
break;
case 270:
result.translate(0, target.height());
break;
default:
Q_ASSERT(false);
}
result.rotate(angle);
return result;
}
/*!
Maps the rect between two screen orientations.
This will flip the x and y dimensions of the rectangle if orientation \a is
Qt::PortraitOrientation or Qt::InvertedPortraitOrientation and orientation \b is
Qt::LandscapeOrientation or Qt::InvertedLandscapeOrientation, or vice versa.
*/
QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect)
{
if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
return rect;
if ((a == Qt::PortraitOrientation || a == Qt::InvertedPortraitOrientation)
!= (b == Qt::PortraitOrientation || b == Qt::InvertedPortraitOrientation))
{
return QRect(rect.y(), rect.x(), rect.height(), rect.width());
}
return rect;
}
/*!
\fn QScreen::currentOrientationChanged()
This signal is emitted when the current orientation of the screen
changes. The current orientation is a hint to the application saying
what the preferred application orientation should be, based on the
current orientation of the physical display and / or other factors.
\sa currentOrientation()
*/
QT_END_NAMESPACE

View File

@ -48,6 +48,10 @@
#include <QtCore/QSize>
#include <QtCore/QSizeF>
#include <QtGui/QTransform>
#include <QtCore/qnamespace.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@ -93,10 +97,21 @@ public:
QSize availableVirtualSize() const;
QRect availableVirtualGeometry() const;
Qt::ScreenOrientation primaryOrientation() const;
Qt::ScreenOrientation currentOrientation() const;
static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b);
static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
Q_SIGNALS:
void currentOrientationChanged(Qt::ScreenOrientation orientation);
private:
QScreen(QPlatformScreen *screen);
Q_DISABLE_COPY(QScreen)
friend class QGuiApplicationPrivate;
friend class QPlatformScreen;
};

View File

@ -349,6 +349,41 @@ bool QWindow::isActive() const
}
}
/*!
Returns the window's currently set orientation.
The default value is Qt::UnknownOrientation.
\sa setOrientation(), QScreen::currentOrientation()
*/
Qt::ScreenOrientation QWindow::orientation() const
{
Q_D(const QWindow);
return d->orientation;
}
/*!
Set the orientation of the window's contents.
This is a hint to the window manager in case it needs to display
additional content like popups, dialogs, status bars, or similar
in relation to the window.
The recommended orientation is QScreen::currentOrientation() but
an application doesn't have to support all possible orientations,
and thus can opt to ignore the current screen orientation.
\sa QScreen::currentOrientation()
*/
void QWindow::setOrientation(Qt::ScreenOrientation orientation)
{
Q_D(QWindow);
d->orientation = orientation;
if (d->platformWindow) {
d->platformWindow->setOrientation(orientation);
}
}
Qt::WindowState QWindow::windowState() const
{
Q_D(const QWindow);

View File

@ -47,6 +47,8 @@
#include <QtCore/QMargins>
#include <QtCore/QRect>
#include <QtCore/qnamespace.h>
#include <QtGui/qsurface.h>
#include <QtGui/qsurfaceformat.h>
#include <QtGui/qwindowdefs.h>
@ -126,6 +128,9 @@ public:
bool isActive() const;
Qt::ScreenOrientation orientation() const;
void setOrientation(Qt::ScreenOrientation orientation);
Qt::WindowState windowState() const;
void setWindowState(Qt::WindowState state);

View File

@ -76,6 +76,7 @@ public:
, windowState(Qt::WindowNoState)
, resizeEventPending(true)
, positionPolicy(WindowFrameExclusive)
, orientation(Qt::UnknownOrientation)
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
, transientParent(0)
@ -110,6 +111,7 @@ public:
Qt::WindowState windowState;
bool resizeEventPending;
PositionPolicy positionPolicy;
Qt::ScreenOrientation orientation;
QSize minimumSize;
QSize maximumSize;

View File

@ -249,24 +249,24 @@ void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEv
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenGeometryChange(int screenIndex)
void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen)
{
QWindowSystemInterfacePrivate::ScreenOrientationEvent *e =
new QWindowSystemInterfacePrivate::ScreenOrientationEvent(screen);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen)
{
QWindowSystemInterfacePrivate::ScreenGeometryEvent *e =
new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screenIndex);
new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screen);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenAvailableGeometryChange(int screenIndex)
void QWindowSystemInterface::handleScreenAvailableGeometryChange(QScreen *screen)
{
QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e =
new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screenIndex);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
void QWindowSystemInterface::handleScreenCountChange(int count)
{
QWindowSystemInterfacePrivate::ScreenCountEvent *e =
new QWindowSystemInterfacePrivate::ScreenCountEvent(count);
new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screen);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}

View File

@ -45,6 +45,7 @@
#include <QtGui/qwindowdefs.h>
#include <QtCore/QEvent>
#include <QtCore/QAbstractEventDispatcher>
#include <QtGui/QScreen>
#include <QtGui/QWindow>
#include <QtCore/QWeakPointer>
#include <QtCore/QMutex>
@ -112,9 +113,9 @@ public:
static Qt::DropAction handleDrop(QWindow *w, QMimeData *dropData, const QPoint &p);
// Changes to the screen
static void handleScreenGeometryChange(int screenIndex);
static void handleScreenAvailableGeometryChange(int screenIndex);
static void handleScreenCountChange(int count);
static void handleScreenOrientationChange(QScreen *screen);
static void handleScreenGeometryChange(QScreen *screen);
static void handleScreenAvailableGeometryChange(QScreen *screen);
// For event dispatcher implementations
static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags);

View File

@ -60,9 +60,9 @@ public:
Wheel,
Key,
Touch,
ScreenOrientation,
ScreenGeometry,
ScreenAvailableGeometry,
ScreenCountChange,
Map,
Unmap,
Expose
@ -194,25 +194,25 @@ public:
};
class ScreenCountEvent : public WindowSystemEvent {
class ScreenOrientationEvent : public WindowSystemEvent {
public:
ScreenCountEvent (int count)
: WindowSystemEvent(ScreenCountChange) , count(count) { }
int count;
ScreenOrientationEvent(QScreen *s)
: WindowSystemEvent(ScreenOrientation), screen(s) { }
QWeakPointer<QScreen> screen;
};
class ScreenGeometryEvent : public WindowSystemEvent {
public:
ScreenGeometryEvent(int index)
: WindowSystemEvent(ScreenGeometry), index(index) { }
int index;
ScreenGeometryEvent(QScreen *s)
: WindowSystemEvent(ScreenGeometry), screen(s) { }
QWeakPointer<QScreen> screen;
};
class ScreenAvailableGeometryEvent : public WindowSystemEvent {
public:
ScreenAvailableGeometryEvent(int index)
: WindowSystemEvent(ScreenAvailableGeometry), index(index) { }
int index;
ScreenAvailableGeometryEvent(QScreen *s)
: WindowSystemEvent(ScreenAvailableGeometry), screen(s) { }
QWeakPointer<QScreen> screen;
};
class MapEvent : public WindowSystemEvent {

View File

@ -0,0 +1,6 @@
load(qttest_p4)
QT += core-private gui-private
SOURCES += tst_qscreen.cpp

View File

@ -0,0 +1,169 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite 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$
**
****************************************************************************/
#include <qscreen.h>
#include <QtTest/QtTest>
#include "../../shared/util.h"
class tst_QScreen: public QObject
{
Q_OBJECT
private slots:
void angleBetween_data();
void angleBetween();
void transformBetween_data();
void transformBetween();
};
void tst_QScreen::angleBetween_data()
{
QTest::addColumn<uint>("oa");
QTest::addColumn<uint>("ob");
QTest::addColumn<int>("expected");
QTest::newRow("Portrait Portrait")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::PortraitOrientation)
<< 0;
QTest::newRow("Portrait Landscape")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::LandscapeOrientation)
<< 270;
QTest::newRow("Portrait InvertedPortrait")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::InvertedPortraitOrientation)
<< 180;
QTest::newRow("Portrait InvertedLandscape")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::InvertedLandscapeOrientation)
<< 90;
QTest::newRow("InvertedLandscape InvertedPortrait")
<< uint(Qt::InvertedLandscapeOrientation)
<< uint(Qt::InvertedPortraitOrientation)
<< 90;
QTest::newRow("InvertedLandscape Landscape")
<< uint(Qt::InvertedLandscapeOrientation)
<< uint(Qt::LandscapeOrientation)
<< 180;
}
void tst_QScreen::angleBetween()
{
QFETCH( uint, oa );
QFETCH( uint, ob );
QFETCH( int, expected );
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
QCOMPARE(QScreen::angleBetween(a, b), expected);
QCOMPARE(QScreen::angleBetween(b, a), (360 - expected) % 360);
}
void tst_QScreen::transformBetween_data()
{
QTest::addColumn<uint>("oa");
QTest::addColumn<uint>("ob");
QTest::addColumn<QRect>("rect");
QTest::addColumn<QTransform>("expected");
QRect rect(0, 0, 480, 640);
QTest::newRow("Portrait Portrait")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::PortraitOrientation)
<< rect
<< QTransform();
QTest::newRow("Portrait Landscape")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::LandscapeOrientation)
<< rect
<< QTransform(0, -1, 1, 0, 0, rect.height());
QTest::newRow("Portrait InvertedPortrait")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::InvertedPortraitOrientation)
<< rect
<< QTransform(-1, 0, 0, -1, rect.width(), rect.height());
QTest::newRow("Portrait InvertedLandscape")
<< uint(Qt::PortraitOrientation)
<< uint(Qt::InvertedLandscapeOrientation)
<< rect
<< QTransform(0, 1, -1, 0, rect.width(), 0);
QTest::newRow("InvertedLandscape InvertedPortrait")
<< uint(Qt::InvertedLandscapeOrientation)
<< uint(Qt::InvertedPortraitOrientation)
<< rect
<< QTransform(0, 1, -1, 0, rect.width(), 0);
QTest::newRow("InvertedLandscape Landscape")
<< uint(Qt::InvertedLandscapeOrientation)
<< uint(Qt::LandscapeOrientation)
<< rect
<< QTransform(-1, 0, 0, -1, rect.width(), rect.height());
}
void tst_QScreen::transformBetween()
{
QFETCH( uint, oa );
QFETCH( uint, ob );
QFETCH( QRect, rect );
QFETCH( QTransform, expected );
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
QCOMPARE(QScreen::transformBetween(a, b, rect), expected);
}
#include <tst_qscreen.moc>
QTEST_MAIN(tst_QScreen);