diff options
Diffstat (limited to 'examples/widgets/painting/pathstroke')
-rw-r--r-- | examples/widgets/painting/pathstroke/CMakeLists.txt | 103 | ||||
-rw-r--r-- | examples/widgets/painting/pathstroke/main.cpp | 53 | ||||
-rw-r--r-- | examples/widgets/painting/pathstroke/pathstroke.cpp | 118 | ||||
-rw-r--r-- | examples/widgets/painting/pathstroke/pathstroke.h | 55 |
4 files changed, 131 insertions, 198 deletions
diff --git a/examples/widgets/painting/pathstroke/CMakeLists.txt b/examples/widgets/painting/pathstroke/CMakeLists.txt new file mode 100644 index 0000000000..5c995617eb --- /dev/null +++ b/examples/widgets/painting/pathstroke/CMakeLists.txt @@ -0,0 +1,103 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(pathstroke LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) + +qt_standard_project_setup() + +qt_add_executable(pathstroke + main.cpp + pathstroke.cpp pathstroke.h +) + +set_target_properties(pathstroke PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +if(NOT TARGET painting_shared::painting_shared) + include(../shared/use_lib.cmake) +endif() + +target_link_libraries(pathstroke PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets + painting_shared::painting_shared +) + +# Resources: +set(shared_resource_files + "../shared/images/button_normal_cap_left.png" + "../shared/images/button_normal_cap_right.png" + "../shared/images/button_normal_stretch.png" + "../shared/images/button_pressed_cap_left.png" + "../shared/images/button_pressed_cap_right.png" + "../shared/images/button_pressed_stretch.png" + "../shared/images/frame_bottom.png" + "../shared/images/frame_bottomleft.png" + "../shared/images/frame_bottomright.png" + "../shared/images/frame_left.png" + "../shared/images/frame_right.png" + "../shared/images/frame_top.png" + "../shared/images/frame_topleft.png" + "../shared/images/frame_topright.png" + "../shared/images/groupframe_bottom_left.png" + "../shared/images/groupframe_bottom_right.png" + "../shared/images/groupframe_bottom_stretch.png" + "../shared/images/groupframe_left_stretch.png" + "../shared/images/groupframe_right_stretch.png" + "../shared/images/groupframe_top_stretch.png" + "../shared/images/groupframe_topleft.png" + "../shared/images/groupframe_topright.png" + "../shared/images/line_dash_dot.png" + "../shared/images/line_dash_dot_dot.png" + "../shared/images/line_dashed.png" + "../shared/images/line_dotted.png" + "../shared/images/line_solid.png" + "../shared/images/radiobutton-on.png" + "../shared/images/radiobutton_off.png" + "../shared/images/radiobutton_on.png" + "../shared/images/slider_bar.png" + "../shared/images/slider_thumb_on.png" + "../shared/images/title_cap_left.png" + "../shared/images/title_cap_right.png" + "../shared/images/title_stretch.png" +) + +qt_add_resources(pathstroke "shared" + PREFIX + "/res" + BASE + "../shared" + FILES + ${shared_resource_files} +) + +set(pathstroke_resource_files + "pathstroke.cpp" + "pathstroke.html" +) + +qt_add_resources(pathstroke "pathstroke" + PREFIX + "/res/pathstroke" + FILES + ${pathstroke_resource_files} +) + +install(TARGETS pathstroke + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_app_script( + TARGET pathstroke + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR +) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/painting/pathstroke/main.cpp b/examples/widgets/painting/pathstroke/main.cpp index 57c85d73a3..4f991e8a0a 100644 --- a/examples/widgets/painting/pathstroke/main.cpp +++ b/examples/widgets/painting/pathstroke/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 "pathstroke.h" @@ -54,8 +7,6 @@ int main(int argc, char **argv) { - Q_INIT_RESOURCE(pathstroke); - QApplication app(argc, argv); bool smallScreen = QApplication::arguments().contains("-small-screen"); diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index a850ce2672..cd54a7a8aa 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.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 "pathstroke.h" #include "arthurstyle.h" @@ -224,12 +177,6 @@ void PathStrokeControls::layoutForDesktop() 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(m_renderer->usesOpenGL()); -#endif QPushButton *whatsThisButton = new QPushButton(mainGroup); whatsThisButton->setText(tr("What's This?")); whatsThisButton->setCheckable(true); @@ -253,9 +200,6 @@ void PathStrokeControls::layoutForDesktop() mainGroupLayout->addWidget(animated); mainGroupLayout->addStretch(1); mainGroupLayout->addWidget(showSourceButton); -#if QT_CONFIG(opengl) - mainGroupLayout->addWidget(enableOpenGLButton); -#endif mainGroupLayout->addWidget(whatsThisButton); @@ -268,10 +212,6 @@ void PathStrokeControls::layoutForDesktop() connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource); -#if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, - m_renderer, &ArthurFrame::enableOpenGL); -#endif connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled); connect(m_renderer, &ArthurFrame::descriptionEnabledChanged, @@ -306,13 +246,6 @@ void PathStrokeControls::layoutForSmallScreens() penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); penWidth->setRange(0, 500); -#if QT_CONFIG(opengl) - QPushButton *enableOpenGLButton = new QPushButton(this); - enableOpenGLButton->setText(tr("Use OpenGL")); - enableOpenGLButton->setCheckable(true); - enableOpenGLButton->setChecked(m_renderer->usesOpenGL()); -#endif - // Layouts: QHBoxLayout *penWidthLayout = new QHBoxLayout; penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight); @@ -321,9 +254,6 @@ void PathStrokeControls::layoutForSmallScreens() QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addWidget(m_capGroup); leftLayout->addWidget(m_joinGroup); -#if QT_CONFIG(opengl) - leftLayout->addWidget(enableOpenGLButton); -#endif leftLayout->addLayout(penWidthLayout); QVBoxLayout *rightLayout = new QVBoxLayout; @@ -344,10 +274,6 @@ void PathStrokeControls::layoutForSmallScreens() mainLayout->addWidget(quitBtn, 2, 1, Qt::AlignHCenter | Qt::AlignTop); mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop); -#if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); -#endif - connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth); connect(quitBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitQuitSignal); connect(okBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitOkSignal); @@ -388,7 +314,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) connect(m_renderer, &PathStrokeRenderer::clicked, this, &PathStrokeWidget::showControls); connect(m_controls, &PathStrokeControls::okPressed, this, &PathStrokeWidget::hideControls); - connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit())); + connect(m_controls, &PathStrokeControls::quitPressed, QApplication::instance(), &QApplication::quit); } void PathStrokeWidget::showControls() @@ -470,7 +396,7 @@ void PathStrokeRenderer::paint(QPainter *painter) stroker.setJoinStyle(m_joinStyle); stroker.setCapStyle(m_capStyle); - QVector<qreal> dashes; + QList<qreal> dashes; qreal space = 4; dashes << 1 << space << 3 << space @@ -511,10 +437,10 @@ void PathStrokeRenderer::initializePoints() m_points.clear(); m_vectors.clear(); - QMatrix m; + QTransform m; qreal rot = 360.0 / count; QPointF center(width() / 2, height() / 2); - QMatrix vm; + QTransform vm; vm.shear(2, -1); vm.scale(3, 3); @@ -559,7 +485,7 @@ void PathStrokeRenderer::mousePressEvent(QMouseEvent *e) m_activePoint = -1; qreal distance = -1; for (int i = 0; i < m_points.size(); ++i) { - qreal d = QLineF(e->pos(), m_points.at(i)).length(); + qreal d = QLineF(e->position().toPoint(), m_points.at(i)).length(); if ((distance < 0 && d < 8 * m_pointSize) || d < distance) { distance = d; m_activePoint = i; @@ -574,7 +500,7 @@ void PathStrokeRenderer::mousePressEvent(QMouseEvent *e) // If we're not running in small screen mode, always assume we're dragging m_mouseDrag = !m_smallScreen; - m_mousePress = e->pos(); + m_mousePress = e->position().toPoint(); } void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e) @@ -582,11 +508,11 @@ void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e) if (!m_fingerPointMapping.isEmpty()) return; // If we've moved more then 25 pixels, assume user is dragging - if (!m_mouseDrag && QPoint(m_mousePress - e->pos()).manhattanLength() > 25) + if (!m_mouseDrag && QPoint(m_mousePress - e->position().toPoint()).manhattanLength() > 25) m_mouseDrag = true; if (m_mouseDrag && m_activePoint >= 0 && m_activePoint < m_points.size()) { - m_points[m_activePoint] = e->pos(); + m_points[m_activePoint] = e->position().toPoint(); update(); } } @@ -622,11 +548,11 @@ bool PathStrokeRenderer::event(QEvent *e) case QEvent::TouchUpdate: { const QTouchEvent *const event = static_cast<const QTouchEvent*>(e); - const QList<QTouchEvent::TouchPoint> points = event->touchPoints(); - for (const QTouchEvent::TouchPoint &touchPoint : points) { - const int id = touchPoint.id(); - switch (touchPoint.state()) { - case Qt::TouchPointPressed: + const auto points = event->points(); + for (const auto &point : points) { + const int id = point.id(); + switch (point.state()) { + case QEventPoint::Pressed: { // find the point, move it const auto mappedPoints = m_fingerPointMapping.values(); @@ -638,32 +564,32 @@ bool PathStrokeRenderer::event(QEvent *e) if (activePoints.contains(i)) continue; - qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); + qreal d = QLineF(point.position(), m_points.at(i)).length(); if ((distance < 0 && d < 12 * m_pointSize) || d < distance) { distance = d; activePoint = i; } } if (activePoint != -1) { - m_fingerPointMapping.insert(touchPoint.id(), activePoint); - m_points[activePoint] = touchPoint.pos(); + m_fingerPointMapping.insert(point.id(), activePoint); + m_points[activePoint] = point.position(); } break; } - case Qt::TouchPointReleased: + case QEventPoint::Released: { // move the point and release QHash<int,int>::iterator it = m_fingerPointMapping.find(id); - m_points[it.value()] = touchPoint.pos(); + m_points[it.value()] = point.position(); m_fingerPointMapping.erase(it); break; } - case Qt::TouchPointMoved: + case QEventPoint::Updated: { // move the point const int pointIdx = m_fingerPointMapping.value(id, -1); if (pointIdx >= 0) - m_points[pointIdx] = touchPoint.pos(); + m_points[pointIdx] = point.position(); break; } default: diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h index b559ed2ba0..05f678dcc6 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.h +++ b/examples/widgets/painting/pathstroke/pathstroke.h @@ -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 #ifndef PATHSTROKE_H #define PATHSTROKE_H @@ -119,8 +72,8 @@ private: int m_pointCount; int m_pointSize; int m_activePoint; - QVector<QPointF> m_points; - QVector<QPointF> m_vectors; + QList<QPointF> m_points; + QList<QPointF> m_vectors; Qt::PenJoinStyle m_joinStyle; Qt::PenCapStyle m_capStyle; |