diff options
Diffstat (limited to 'examples/widgets/painting/composition')
-rw-r--r-- | examples/widgets/painting/composition/CMakeLists.txt | 53 | ||||
-rw-r--r-- | examples/widgets/painting/composition/composition.cpp | 164 | ||||
-rw-r--r-- | examples/widgets/painting/composition/composition.h | 65 | ||||
-rw-r--r-- | examples/widgets/painting/composition/main.cpp | 51 |
4 files changed, 38 insertions, 295 deletions
diff --git a/examples/widgets/painting/composition/CMakeLists.txt b/examples/widgets/painting/composition/CMakeLists.txt index 252b46daca..b88ee42e41 100644 --- a/examples/widgets/painting/composition/CMakeLists.txt +++ b/examples/widgets/painting/composition/CMakeLists.txt @@ -1,21 +1,14 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + cmake_minimum_required(VERSION 3.16) project(composition LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/composition") - find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) +qt_standard_project_setup() + qt_add_executable(composition - # remove files from ../shared - #../shared/arthurstyle.cpp ../shared/arthurstyle.h - #../shared/arthurwidgets.cpp ../shared/arthurwidgets.h - #../shared/hoverpoints.cpp ../shared/hoverpoints.h composition.cpp composition.h main.cpp ) @@ -25,18 +18,14 @@ set_target_properties(composition PROPERTIES MACOSX_BUNDLE TRUE ) -target_include_directories(composition PUBLIC - ../shared -) - if(NOT TARGET painting_shared::painting_shared) include(../shared/use_lib.cmake) endif() -target_link_libraries(composition PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets +target_link_libraries(composition PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets painting_shared::painting_shared ) @@ -102,19 +91,15 @@ qt_add_resources(composition "composition" ${composition_resource_files} ) -# remove files from ../shared -#if(QT_FEATURE_opengl) - #target_sources(affine PUBLIC - #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h - #) - - #target_link_libraries(affine PUBLIC - #Qt::OpenGL - #) -#endif() - install(TARGETS composition - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_app_script( + TARGET composition + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR ) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp index a220fb42fa..b4fb4fa3f7 100644 --- a/examples/widgets/painting/composition/composition.cpp +++ b/examples/widgets/painting/composition/composition.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "composition.h" #include <QBoxLayout> @@ -57,11 +10,6 @@ #include <QMouseEvent> #include <qmath.h> -#if QT_CONFIG(opengl) -#include <QOpenGLFunctions> -#include <QOpenGLWindow> -#endif - const int animationInterval = 15; // update every 16 ms = ~60FPS CompositionWidget::CompositionWidget(QWidget *parent) @@ -141,12 +89,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) QPushButton *showSourceButton = new QPushButton(mainGroup); showSourceButton->setText(tr("Show Source")); -#if QT_CONFIG(opengl) - QPushButton *enableOpenGLButton = new QPushButton(mainGroup); - enableOpenGLButton->setText(tr("Use OpenGL")); - enableOpenGLButton->setCheckable(true); - enableOpenGLButton->setChecked(view->usesOpenGL()); -#endif QPushButton *whatsThisButton = new QPushButton(mainGroup); whatsThisButton->setText(tr("What's This?")); whatsThisButton->setCheckable(true); @@ -168,9 +110,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) mainGroupLayout->addWidget(animateButton); mainGroupLayout->addWidget(whatsThisButton); mainGroupLayout->addWidget(showSourceButton); -#if QT_CONFIG(opengl) - mainGroupLayout->addWidget(enableOpenGLButton); -#endif QGridLayout *modesLayout = new QGridLayout(modesGroup); modesLayout->addWidget(rbClear, 0, 0); @@ -212,9 +151,6 @@ CompositionWidget::CompositionWidget(QWidget *parent) connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled); connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked); connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource); -#if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL); -#endif connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled); circleColorSlider->setValue(270); @@ -264,9 +200,6 @@ CompositionRenderer::CompositionRenderer(QWidget *parent) m_circle_pos = QPoint(200, 100); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); -#if QT_CONFIG(opengl) - m_pbuffer_size = 1024; -#endif } CompositionRenderer::~CompositionRenderer() @@ -359,86 +292,25 @@ void CompositionRenderer::drawSource(QPainter &p) void CompositionRenderer::paint(QPainter *painter) { -#if QT_CONFIG(opengl) - if (usesOpenGL() && glWindow()->isValid()) { - - if (!m_blitter.isCreated()) - m_blitter.create(); - - int new_pbuf_size = m_pbuffer_size; - while (size().width() > new_pbuf_size || size().height() > new_pbuf_size) - new_pbuf_size *= 2; - - while (size().width() < new_pbuf_size/2 && size().height() < new_pbuf_size/2) - new_pbuf_size /= 2; - - if (!m_fbo || new_pbuf_size != m_pbuffer_size) { - m_fbo.reset(new QFboPaintDevice(QSize(new_pbuf_size, new_pbuf_size), false, false)); - m_pbuffer_size = new_pbuf_size; - } - - if (size() != m_previous_size) { - m_previous_size = size(); - QPainter p(m_fbo.get()); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(QRect(QPoint(0, 0), size()), Qt::transparent); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - drawBase(p); - p.end(); - m_base_tex = m_fbo->takeTexture(); - } - - painter->beginNativePainting(); - { - QPainter p(m_fbo.get()); - p.beginNativePainting(); - m_blitter.bind(); - const QRect targetRect(QPoint(0, 0), m_fbo->size()); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size())); - m_blitter.blit(m_base_tex, target, QOpenGLTextureBlitter::OriginBottomLeft); - m_blitter.release(); - p.endNativePainting(); - drawSource(p); - p.end(); - m_compositing_tex = m_fbo->takeTexture(); - } - painter->endNativePainting(); - - painter->beginNativePainting(); - auto *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glEnable(GL_BLEND); - funcs->glBlendEquation(GL_FUNC_ADD); - funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - m_blitter.bind(); - const QRect targetRect(QPoint(0, 0), m_fbo->size()); - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size())); - m_blitter.blit(m_compositing_tex, target, QOpenGLTextureBlitter::OriginBottomLeft); - m_blitter.release(); - painter->endNativePainting(); - } else -#endif - { - // using a QImage - if (m_buffer.size() != size()) { - m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); - m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); + if (m_buffer.size() != size()) { + m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); + m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); - m_base_buffer.fill(0); + m_base_buffer.fill(0); - QPainter p(&m_base_buffer); + QPainter p(&m_base_buffer); - drawBase(p); - } - - memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes()); + drawBase(p); + } - { - QPainter p(&m_buffer); - drawSource(p); - } + memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes()); - painter->drawImage(0, 0, m_buffer); + { + QPainter p(&m_buffer); + drawSource(p); } + + painter->drawImage(0, 0, m_buffer); } void CompositionRenderer::mousePressEvent(QMouseEvent *e) @@ -486,12 +358,6 @@ void CompositionRenderer::setCirclePos(const QPointF &pos) const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect(); m_circle_pos = pos; const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect(); -#if QT_CONFIG(opengl) - if (usesOpenGL()) { - update(); - return; - } -#endif update(oldRect | newRect); } diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h index 52ca7919b0..6a5206da08 100644 --- a/examples/widgets/painting/composition/composition.h +++ b/examples/widgets/painting/composition/composition.h @@ -1,63 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef COMPOSITION_H #define COMPOSITION_H #include "arthurwidgets.h" -#if QT_CONFIG(opengl) -#include "fbopaintdevice.h" -#include <QOpenGLTextureBlitter> -#endif - #include <QPainter> #include <QEvent> @@ -190,15 +138,6 @@ private: ObjectType m_current_object; bool m_animation_enabled; int m_animationTimer; - -#if QT_CONFIG(opengl) - std::unique_ptr<QFboPaintDevice> m_fbo; - int m_pbuffer_size; // width==height==size of pbuffer - uint m_base_tex; - uint m_compositing_tex; - QSize m_previous_size; - QOpenGLTextureBlitter m_blitter; -#endif }; #endif // COMPOSITION_H diff --git a/examples/widgets/painting/composition/main.cpp b/examples/widgets/painting/composition/main.cpp index 1ffa29dddc..bc468d0424 100644 --- a/examples/widgets/painting/composition/main.cpp +++ b/examples/widgets/painting/composition/main.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "composition.h" |