From c66b7cf55b6913dcf33d49d4f6bf9db51ccf39a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 4 Oct 2011 13:11:30 +0200 Subject: 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 Sanity-Review: Qt Sanity Bot Reviewed-by: Lars Knoll --- examples/opengl/paintedwindow/paintedwindow.cpp | 47 ++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'examples/opengl/paintedwindow/paintedwindow.cpp') diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp index 88a8f74f91..543c13eab3 100644 --- a/examples/opengl/paintedwindow/paintedwindow.cpp +++ b/examples/opengl/paintedwindow/paintedwindow.cpp @@ -40,9 +40,11 @@ #include "paintedwindow.h" +#include #include #include #include +#include #include #include @@ -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); -- cgit v1.2.3