From 3c0411c97389bcaa791cf83f78b31dbe95956b40 Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 9 Jan 2024 18:21:12 +0100 Subject: qtsvg: add very basic QSvgWidget based example, with an animated SVG The only example or manual test using QSvgWidget was delayedencoding which isn't about animations at all. This example can serve as basis for testing more QSvgWidget features in the future. It includes a tabwidget with a second QSvgWidget in order to test the showing/hiding of QSvgWidget. Change-Id: I9c26f91e7f966fbc15e6a873ae44d35cb98adb07 Reviewed-by: Eirik Aavitsland Reviewed-by: Qt CI Bot --- tests/manual/examples/CMakeLists.txt | 1 + tests/manual/examples/svgwidget/CMakeLists.txt | 51 +++++ tests/manual/examples/svgwidget/files/bubbles.svg | 215 ++++++++++++++++++++++ tests/manual/examples/svgwidget/files/spheres.svg | 72 ++++++++ tests/manual/examples/svgwidget/main.cpp | 40 ++++ tests/manual/examples/svgwidget/svgwidget.pro | 10 + tests/manual/examples/svgwidget/svgwidget.qrc | 7 + 7 files changed, 396 insertions(+) create mode 100644 tests/manual/examples/svgwidget/CMakeLists.txt create mode 100644 tests/manual/examples/svgwidget/files/bubbles.svg create mode 100644 tests/manual/examples/svgwidget/files/spheres.svg create mode 100644 tests/manual/examples/svgwidget/main.cpp create mode 100644 tests/manual/examples/svgwidget/svgwidget.pro create mode 100644 tests/manual/examples/svgwidget/svgwidget.qrc (limited to 'tests') diff --git a/tests/manual/examples/CMakeLists.txt b/tests/manual/examples/CMakeLists.txt index 4ef9fca..4b24fe2 100644 --- a/tests/manual/examples/CMakeLists.txt +++ b/tests/manual/examples/CMakeLists.txt @@ -6,6 +6,7 @@ if(TARGET Qt::Widgets) add_subdirectory(embedded) add_subdirectory(svggenerator) add_subdirectory(svgviewer) + add_subdirectory(svgwidget) add_subdirectory(embeddedsvgviewer) add_subdirectory(textobject) endif() diff --git a/tests/manual/examples/svgwidget/CMakeLists.txt b/tests/manual/examples/svgwidget/CMakeLists.txt new file mode 100644 index 0000000..96b91fb --- /dev/null +++ b/tests/manual/examples/svgwidget/CMakeLists.txt @@ -0,0 +1,51 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(svgwidget LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/svg/svgwidget") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Svg SvgWidgets Widgets) + +qt_add_executable(svgwidget + main.cpp +) + +set_target_properties(svgwidget PROPERTIES + WIN32_EXECUTABLE FALSE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(svgwidget PUBLIC + Qt::Core + Qt::Gui + Qt::Svg + Qt::SvgWidgets + Qt::Widgets +) + +# Resources: +set(svgwidget_resource_files + "files/bubbles.svg" + "files/spheres.svg" +) + +qt6_add_resources(svgwidget "svgwidget" + PREFIX + "/" + FILES + ${svgwidget_resource_files} +) + +install(TARGETS svgwidget + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/tests/manual/examples/svgwidget/files/bubbles.svg b/tests/manual/examples/svgwidget/files/bubbles.svg new file mode 100644 index 0000000..5173012 --- /dev/null +++ b/tests/manual/examples/svgwidget/files/bubbles.svg @@ -0,0 +1,215 @@ + + + + Spheres + Semi-transparent bubbles on a colored background. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/manual/examples/svgwidget/files/spheres.svg b/tests/manual/examples/svgwidget/files/spheres.svg new file mode 100644 index 0000000..b23164b --- /dev/null +++ b/tests/manual/examples/svgwidget/files/spheres.svg @@ -0,0 +1,72 @@ + + + Spheres + Gradient filled spheres with different colors. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/manual/examples/svgwidget/main.cpp b/tests/manual/examples/svgwidget/main.cpp new file mode 100644 index 0000000..0a536ce --- /dev/null +++ b/tests/manual/examples/svgwidget/main.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QCoreApplication::setApplicationName("SVG Widget"); + QGuiApplication::setApplicationDisplayName(QCoreApplication::applicationName()); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + + QCommandLineParser parser; + parser.setApplicationDescription("Qt SVG Widget"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("file", "The file to open."); + parser.process(app); + + const QString fileName = parser.positionalArguments().value(0, QLatin1String(":/files/bubbles.svg")); + + QTabWidget top; + + auto widget = new QSvgWidget(&top); + top.addTab(widget, "Bubbles"); + widget->load(fileName); + + auto otherWidget = new QSvgWidget(&top); + top.addTab(otherWidget, "Spheres"); + otherWidget->load(QLatin1String(":/files/spheres.svg")); + + top.show(); + return app.exec(); +} diff --git a/tests/manual/examples/svgwidget/svgwidget.pro b/tests/manual/examples/svgwidget/svgwidget.pro new file mode 100644 index 0000000..abff58e --- /dev/null +++ b/tests/manual/examples/svgwidget/svgwidget.pro @@ -0,0 +1,10 @@ +HEADERS = +RESOURCES = svgwidget.qrc +SOURCES = main.cpp +QT += widgets svg svgwidgets + +CONFIG += console + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/svg/svgwidget +INSTALLS += target diff --git a/tests/manual/examples/svgwidget/svgwidget.qrc b/tests/manual/examples/svgwidget/svgwidget.qrc new file mode 100644 index 0000000..126c0a3 --- /dev/null +++ b/tests/manual/examples/svgwidget/svgwidget.qrc @@ -0,0 +1,7 @@ + + + files/bubbles.svg + files/spheres.svg + + + -- cgit v1.2.3