summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-03-22 17:04:18 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-03-23 15:13:02 +0100
commit9daf2744b284413c8ca6df18bd48082bb7405bf8 (patch)
tree1fd8e933e81acac9ffa231292b12488961507450 /examples/opengl
parent3b015718b0d156bbedafd3f83f069ce5a360d5cb (diff)
Change paintedwindow example to be a manual test
Pick-to: 6.5 Change-Id: I25a0f491f824c43fc75ba6358518133ede09adcd Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/CMakeLists.txt1
-rw-r--r--examples/opengl/opengl.pro3
-rw-r--r--examples/opengl/paintedwindow/CMakeLists.txt37
-rw-r--r--examples/opengl/paintedwindow/main.cpp18
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.cpp185
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.h62
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.pro8
7 files changed, 1 insertions, 313 deletions
diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt
index 721cfec8c8..e9bc975e72 100644
--- a/examples/opengl/CMakeLists.txt
+++ b/examples/opengl/CMakeLists.txt
@@ -1,7 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-qt_internal_add_example(paintedwindow)
qt_internal_add_example(openglwindow)
if(TARGET Qt6::Widgets)
qt_internal_add_example(contextinfo)
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
index 84b34c0ceb..3a60b887ef 100644
--- a/examples/opengl/opengl.pro
+++ b/examples/opengl/opengl.pro
@@ -1,7 +1,6 @@
TEMPLATE = subdirs
-SUBDIRS = paintedwindow \
- openglwindow
+SUBDIRS = openglwindow
qtHaveModule(widgets) {
SUBDIRS += contextinfo \
diff --git a/examples/opengl/paintedwindow/CMakeLists.txt b/examples/opengl/paintedwindow/CMakeLists.txt
deleted file mode 100644
index b5a005242b..0000000000
--- a/examples/opengl/paintedwindow/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(paintedwindow LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/paintedwindow")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL)
-
-qt_standard_project_setup()
-
-qt_add_executable(paintedwindow
- main.cpp
- paintedwindow.cpp paintedwindow.h
-)
-
-set_target_properties(paintedwindow PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(paintedwindow PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::OpenGL
-)
-
-install(TARGETS paintedwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/opengl/paintedwindow/main.cpp b/examples/opengl/paintedwindow/main.cpp
deleted file mode 100644
index e055e92812..0000000000
--- a/examples/opengl/paintedwindow/main.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QGuiApplication>
-#include <QRect>
-
-#include "paintedwindow.h"
-
-int main(int argc, char **argv)
-{
- QGuiApplication app(argc, argv);
-
- PaintedWindow window;
- window.show();
-
- return app.exec();
-}
-
diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp
deleted file mode 100644
index d0b8284157..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "paintedwindow.h"
-
-#include <QGuiApplication>
-#include <QOpenGLContext>
-#include <QOpenGLPaintDevice>
-#include <QPainter>
-#include <QPainterPath>
-#include <QScreen>
-#include <QTimer>
-
-#include <qmath.h>
-
-PaintedWindow::PaintedWindow()
-{
- QSurfaceFormat format;
- format.setStencilBufferSize(8);
- format.setSamples(4);
-
- setSurfaceType(QWindow::OpenGLSurface);
- setFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
- setFormat(format);
-
- create();
-
- m_context = new QOpenGLContext(this);
- m_context->setFormat(format);
- m_context->create();
-
- m_animation = new QPropertyAnimation(this, "rotation");
- m_animation->setStartValue(qreal(0));
- m_animation->setEndValue(qreal(1));
- m_animation->setDuration(500);
-
- QRect screenGeometry = screen()->availableGeometry();
-
- QPoint center = screenGeometry.center();
- QRect windowRect = screen()->isLandscape(screen()->orientation()) ? QRect(0, 0, 640, 480) : QRect(0, 0, 480, 640);
- setGeometry(QRect(center - windowRect.center(), windowRect.size()));
-
- m_rotation = 0;
-
- reportContentOrientationChange(screen()->orientation());
-
- m_targetOrientation = contentOrientation();
- m_nextTargetOrientation = Qt::PrimaryOrientation;
-
- connect(screen(), &QScreen::orientationChanged, this, &PaintedWindow::orientationChanged);
- connect(m_animation, &QAbstractAnimation::finished, this, &PaintedWindow::rotationDone);
- connect(this, &PaintedWindow::rotationChanged, this, QOverload<>::of(&PaintedWindow::paint));
-}
-
-void PaintedWindow::exposeEvent(QExposeEvent *)
-{
- if (isExposed())
- paint();
-}
-
-void PaintedWindow::mousePressEvent(QMouseEvent *)
-{
- Qt::ScreenOrientation o = contentOrientation();
- switch (o) {
- case Qt::LandscapeOrientation:
- orientationChanged(Qt::PortraitOrientation);
- break;
- case Qt::PortraitOrientation:
- orientationChanged(Qt::InvertedLandscapeOrientation);
- break;
- case Qt::InvertedLandscapeOrientation:
- orientationChanged(Qt::InvertedPortraitOrientation);
- break;
- case Qt::InvertedPortraitOrientation:
- orientationChanged(Qt::LandscapeOrientation);
- break;
- default:
- Q_ASSERT(false);
- }
-
- paint();
-}
-
-void PaintedWindow::orientationChanged(Qt::ScreenOrientation newOrientation)
-{
- if (contentOrientation() == newOrientation)
- return;
-
- if (m_animation->state() == QAbstractAnimation::Running) {
- m_nextTargetOrientation = newOrientation;
- return;
- }
-
- QRect rect(0, 0, width(), height());
-
- m_prevImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
- m_nextImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
- m_prevImage.fill(0);
- m_nextImage.fill(0);
-
- QPainter p;
- p.begin(&m_prevImage);
- p.setTransform(screen()->transformBetween(contentOrientation(), screen()->orientation(), rect));
- paint(&p, screen()->mapBetween(contentOrientation(), screen()->orientation(), rect));
- p.end();
-
- p.begin(&m_nextImage);
- p.setTransform(screen()->transformBetween(newOrientation, screen()->orientation(), rect));
- paint(&p, screen()->mapBetween(newOrientation, screen()->orientation(), rect));
- p.end();
-
- m_deltaRotation = screen()->angleBetween(newOrientation, contentOrientation());
- if (m_deltaRotation > 180)
- m_deltaRotation = 180 - m_deltaRotation;
-
- m_targetOrientation = newOrientation;
- m_animation->start();
-}
-
-void PaintedWindow::rotationDone()
-{
- reportContentOrientationChange(m_targetOrientation);
- if (m_nextTargetOrientation != Qt::PrimaryOrientation) {
- Q_ASSERT(m_animation->state() != QAbstractAnimation::Running);
- orientationChanged(m_nextTargetOrientation);
- m_nextTargetOrientation = Qt::PrimaryOrientation;
- }
-}
-
-void PaintedWindow::setRotation(qreal r)
-{
- if (r != m_rotation) {
- m_rotation = r;
- emit rotationChanged(r);
- }
-}
-
-void PaintedWindow::paint()
-{
- m_context->makeCurrent(this);
-
- QRect rect(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
-
- QOpenGLPaintDevice device(size() * devicePixelRatio());
- QPainter painter(&device);
-
- QPainterPath path;
- path.addEllipse(rect);
- painter.setCompositionMode(QPainter::CompositionMode_Source);
- painter.fillRect(rect, Qt::transparent);
- painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
- painter.fillPath(path, Qt::blue);
-
- if (contentOrientation() != m_targetOrientation) {
- painter.setRenderHint(QPainter::SmoothPixmapTransform);
- painter.save();
- painter.translate(width() / 2, height() / 2);
- painter.rotate(m_deltaRotation * m_rotation);
- painter.translate(-width() / 2, -height() / 2);
- painter.drawImage(0, 0, m_prevImage);
- painter.restore();
- painter.translate(width() / 2, height() / 2);
- painter.rotate(m_deltaRotation * m_rotation - m_deltaRotation);
- painter.translate(-width() / 2, -height() / 2);
- painter.setOpacity(m_rotation);
- painter.drawImage(0, 0, m_nextImage);
- } else {
- QRect mapped = screen()->mapBetween(contentOrientation(), screen()->orientation(), rect);
-
- painter.setTransform(screen()->transformBetween(contentOrientation(), screen()->orientation(), rect));
- paint(&painter, mapped);
- painter.end();
- }
-
- m_context->swapBuffers(this);
-}
-
-void PaintedWindow::paint(QPainter *painter, const QRect &rect)
-{
- painter->setRenderHint(QPainter::Antialiasing);
- QFont font;
- font.setPixelSize(64);
- painter->setFont(font);
- painter->drawText(rect, Qt::AlignCenter, "Hello");
-}
diff --git a/examples/opengl/paintedwindow/paintedwindow.h b/examples/opengl/paintedwindow/paintedwindow.h
deleted file mode 100644
index 11a76a3056..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PAINTEDWINDOW_H
-#define PAINTEDWINDOW_H
-
-#include <QWindow>
-
-#include <QtGui/qopengl.h>
-#include <QtOpenGL/qopenglshaderprogram.h>
-#include <QtOpenGL/qopenglframebufferobject.h>
-
-#include <QPropertyAnimation>
-
-#include <QColor>
-#include <QImage>
-#include <QTime>
-
-QT_BEGIN_NAMESPACE
-class QOpenGLContext;
-QT_END_NAMESPACE
-
-class PaintedWindow : public QWindow
-{
- Q_OBJECT
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
-
-public:
- PaintedWindow();
-
- qreal rotation() const { return m_rotation; }
-
-signals:
- void rotationChanged(qreal rotation);
-
-private slots:
- void paint();
- void setRotation(qreal r);
- void orientationChanged(Qt::ScreenOrientation newOrientation);
- void rotationDone();
-
-private:
- void exposeEvent(QExposeEvent *) override;
- void mousePressEvent(QMouseEvent *) override;
-
- void paint(QPainter *painter, const QRect &rect);
-
- QOpenGLContext *m_context;
- qreal m_rotation;
-
- QImage m_prevImage;
- QImage m_nextImage;
- qreal m_deltaRotation;
-
- Qt::ScreenOrientation m_targetOrientation;
- Qt::ScreenOrientation m_nextTargetOrientation;
-
- QPropertyAnimation *m_animation;
- QTimer *m_paintTimer;
-};
-
-#endif // PAINTEDWINDOW_H
diff --git a/examples/opengl/paintedwindow/paintedwindow.pro b/examples/opengl/paintedwindow/paintedwindow.pro
deleted file mode 100644
index 569eebe674..0000000000
--- a/examples/opengl/paintedwindow/paintedwindow.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += opengl
-
-HEADERS += paintedwindow.h
-SOURCES += paintedwindow.cpp main.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/opengl/paintedwindow
-INSTALLS += target