diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-10-04 13:11:30 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-07 22:23:30 +0200 |
commit | c66b7cf55b6913dcf33d49d4f6bf9db51ccf39a8 (patch) | |
tree | 430983856f993de5618aa5d8d0198b2db98eda97 /examples/opengl/paintedwindow/paintedwindow.cpp | |
parent | 090d825e1d853a2ed875329a8350b0a727c3527e (diff) |
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>
Diffstat (limited to 'examples/opengl/paintedwindow/paintedwindow.cpp')
-rw-r--r-- | examples/opengl/paintedwindow/paintedwindow.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
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 <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); |