diff options
Diffstat (limited to 'examples/widgets/draganddrop')
40 files changed, 168 insertions, 2318 deletions
diff --git a/examples/widgets/draganddrop/CMakeLists.txt b/examples/widgets/draganddrop/CMakeLists.txt index fbad523a73..bdc6480790 100644 --- a/examples/widgets/draganddrop/CMakeLists.txt +++ b/examples/widgets/draganddrop/CMakeLists.txt @@ -1,7 +1,6 @@ -# Generated from draganddrop.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -add_subdirectory(draggableicons) -add_subdirectory(draggabletext) -add_subdirectory(dropsite) -add_subdirectory(fridgemagnets) -add_subdirectory(puzzle) +qt_internal_add_example(draggableicons) +qt_internal_add_example(draggabletext) +qt_internal_add_example(dropsite) diff --git a/examples/widgets/draganddrop/draganddrop.pro b/examples/widgets/draganddrop/draganddrop.pro index 1ecafd33a1..ad56f3f677 100644 --- a/examples/widgets/draganddrop/draganddrop.pro +++ b/examples/widgets/draganddrop/draganddrop.pro @@ -1,6 +1,4 @@ TEMPLATE = subdirs SUBDIRS = draggableicons \ draggabletext \ - dropsite \ - fridgemagnets \ - puzzle + dropsite diff --git a/examples/widgets/draganddrop/draggableicons/CMakeLists.txt b/examples/widgets/draganddrop/draggableicons/CMakeLists.txt index 894f8ba520..c1fac8da6b 100644 --- a/examples/widgets/draganddrop/draggableicons/CMakeLists.txt +++ b/examples/widgets/draganddrop/draggableicons/CMakeLists.txt @@ -1,38 +1,33 @@ -# Generated from draggableicons.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(draggableicons LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/draggableicons") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +qt_standard_project_setup() qt_add_executable(draggableicons dragwidget.cpp dragwidget.h main.cpp ) + set_target_properties(draggableicons PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(draggableicons PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets + +target_link_libraries(draggableicons PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets ) +if(EMSCRIPTEN) + target_link_options(draggableicons PUBLIC -sASYNCIFY -Os) +endif() + # Resources: set(draggableicons_resource_files @@ -41,7 +36,7 @@ set(draggableicons_resource_files "images/house.png" ) -qt6_add_resources(draggableicons "draggableicons" +qt_add_resources(draggableicons "draggableicons" PREFIX "/" FILES @@ -49,7 +44,14 @@ qt6_add_resources(draggableicons "draggableicons" ) install(TARGETS draggableicons - 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 draggableicons + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR ) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.pro b/examples/widgets/draganddrop/draggableicons/draggableicons.pro index f87ec4ad60..e43df790b4 100644 --- a/examples/widgets/draganddrop/draggableicons/draggableicons.pro +++ b/examples/widgets/draganddrop/draggableicons/draggableicons.pro @@ -4,7 +4,9 @@ HEADERS = dragwidget.h RESOURCES = draggableicons.qrc SOURCES = dragwidget.cpp \ main.cpp - +wasm { + QMAKE_LFLAGS += -sASYNCIFY -Os +} # install target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/draggableicons INSTALLS += target diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp index 1b3774db4f..ba06c836d4 100644 --- a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp +++ b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QtWidgets> @@ -142,7 +95,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event) if (!child) return; - QPixmap pixmap = child->pixmap(Qt::ReturnByValue); + QPixmap pixmap = child->pixmap(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.h b/examples/widgets/draganddrop/draggableicons/dragwidget.h index 98e623a5e3..d849985981 100644 --- a/examples/widgets/draganddrop/draggableicons/dragwidget.h +++ b/examples/widgets/draganddrop/draggableicons/dragwidget.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 DRAGWIDGET_H #define DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/draggableicons/main.cpp b/examples/widgets/draganddrop/draggableicons/main.cpp index f23dd203b4..fe92708594 100644 --- a/examples/widgets/draganddrop/draggableicons/main.cpp +++ b/examples/widgets/draganddrop/draggableicons/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 examples 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 <QApplication> #include <QHBoxLayout> @@ -55,8 +8,6 @@ int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(draggableicons); - QApplication app(argc, argv); QWidget mainWidget; diff --git a/examples/widgets/draganddrop/draggabletext/CMakeLists.txt b/examples/widgets/draganddrop/draggabletext/CMakeLists.txt index d2da6acddb..bc1e72db80 100644 --- a/examples/widgets/draganddrop/draggabletext/CMakeLists.txt +++ b/examples/widgets/draganddrop/draggabletext/CMakeLists.txt @@ -1,45 +1,39 @@ -# Generated from draggabletext.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(draggabletext LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/draggabletext") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +qt_standard_project_setup() qt_add_executable(draggabletext dragwidget.cpp dragwidget.h main.cpp ) + set_target_properties(draggabletext PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(draggabletext PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets + +target_link_libraries(draggabletext PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets ) +if(EMSCRIPTEN) + target_link_options(draggabletext PUBLIC -sASYNCIFY -Os) +endif() # Resources: set(draggabletext_resource_files "words.txt" ) -qt6_add_resources(draggabletext "draggabletext" +qt_add_resources(draggabletext "draggabletext" PREFIX "/dictionary" FILES @@ -47,7 +41,14 @@ qt6_add_resources(draggabletext "draggabletext" ) install(TARGETS draggabletext - 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 draggabletext + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR ) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.pro b/examples/widgets/draganddrop/draggabletext/draggabletext.pro index 1add2a270e..007b9d834e 100644 --- a/examples/widgets/draganddrop/draggabletext/draggabletext.pro +++ b/examples/widgets/draganddrop/draggabletext/draggabletext.pro @@ -4,6 +4,9 @@ HEADERS = dragwidget.h RESOURCES = draggabletext.qrc SOURCES = dragwidget.cpp \ main.cpp +wasm { + QMAKE_LFLAGS += -sASYNCIFY -Os +} # install target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/draggabletext diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp index 1f1889c7cf..d56f91e900 100644 --- a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp +++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QtWidgets> diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.h b/examples/widgets/draganddrop/draggabletext/dragwidget.h index 38abb0ceb8..dfbe3beb4e 100644 --- a/examples/widgets/draganddrop/draggabletext/dragwidget.h +++ b/examples/widgets/draganddrop/draggabletext/dragwidget.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 DRAGWIDGET_H #define DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/draggabletext/main.cpp b/examples/widgets/draganddrop/draggabletext/main.cpp index e10b537ff5..ebfd481e62 100644 --- a/examples/widgets/draganddrop/draggabletext/main.cpp +++ b/examples/widgets/draganddrop/draggabletext/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 examples 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 <QApplication> @@ -54,8 +7,6 @@ int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(draggabletext); - QApplication app(argc, argv); DragWidget window; window.show(); diff --git a/examples/widgets/draganddrop/draggabletext/words.txt b/examples/widgets/draganddrop/draggabletext/words.txt index 19b8b0325b..78bf304fa9 100644 --- a/examples/widgets/draganddrop/draggabletext/words.txt +++ b/examples/widgets/draganddrop/draggabletext/words.txt @@ -1,41 +1,35 @@ Qt -Quarterly +Academy is -a -paper -based -newsletter -exclusively -available -to +where +you +begin +your +journey +into Qt -customers -Every -quarter -we -mail -out -an -issue +It +is +a +learning +platform that -we -hope -will -bring -added -insight +can +teach +you +everything +from +the +basics +to +the +details and -pleasure +is +open to -your -Qt -programming -with -high -quality -technical -articles -written -by -Qt -experts +students +and +experienced +programmers +alike diff --git a/examples/widgets/draganddrop/dropsite/CMakeLists.txt b/examples/widgets/draganddrop/dropsite/CMakeLists.txt index aac6d005b7..ae8d00eb91 100644 --- a/examples/widgets/draganddrop/dropsite/CMakeLists.txt +++ b/examples/widgets/draganddrop/dropsite/CMakeLists.txt @@ -1,41 +1,39 @@ -# Generated from dropsite.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(dropsite LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/dropsite") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +qt_standard_project_setup() qt_add_executable(dropsite droparea.cpp droparea.h dropsitewindow.cpp dropsitewindow.h main.cpp ) + set_target_properties(dropsite PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(dropsite PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets + +target_link_libraries(dropsite PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets ) install(TARGETS dropsite - 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 dropsite + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR ) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp index 19644ed573..1b2ff1820d 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.cpp +++ b/examples/widgets/draganddrop/dropsite/droparea.cpp @@ -1,58 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 "droparea.h" #include <QDragEnterEvent> #include <QMimeData> +using namespace Qt::StringLiterals; + //! [DropArea constructor] DropArea::DropArea(QWidget *parent) : QLabel(parent) @@ -93,8 +48,8 @@ void DropArea::dropEvent(QDropEvent *event) //! [dropEvent() function part2] if (mimeData->hasImage()) { setPixmap(qvariant_cast<QPixmap>(mimeData->imageData())); - } else if (mimeData->hasFormat(QLatin1String("text/markdown"))) { - setText(QString::fromUtf8(mimeData->data(QLatin1String("text/markdown")))); + } else if (mimeData->hasFormat(u"text/markdown"_s)) { + setText(QString::fromUtf8(mimeData->data(u"text/markdown"_s))); setTextFormat(Qt::MarkdownText); } else if (mimeData->hasHtml()) { setText(mimeData->html()); @@ -105,8 +60,8 @@ void DropArea::dropEvent(QDropEvent *event) } else if (mimeData->hasUrls()) { QList<QUrl> urlList = mimeData->urls(); QString text; - for (int i = 0; i < urlList.size() && i < 32; ++i) - text += urlList.at(i).path() + QLatin1Char('\n'); + for (qsizetype i = 0, count = qMin(urlList.size(), qsizetype(32)); i < count; ++i) + text += urlList.at(i).path() + u'\n'; setText(text); } else { setText(tr("Cannot display data")); diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h index ab1de8ea44..3e5947b236 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.h +++ b/examples/widgets/draganddrop/dropsite/droparea.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 DROPAREA_H #define DROPAREA_H @@ -78,9 +31,6 @@ protected: void dragMoveEvent(QDragMoveEvent *event) override; void dragLeaveEvent(QDragLeaveEvent *event) override; void dropEvent(QDropEvent *event) override; - -private: - QLabel *label; }; //! [DropArea header part2] diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp index d96ebce2e3..2969fdf7ae 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp @@ -1,58 +1,23 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include <QtWidgets> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QPushButton> +#include <QDialogButtonBox> +#include <QHeaderView> +#include <QTableWidget> +#include <QTableWidgetItem> +#include <QVBoxLayout> + +#include <QClipboard> +#include <QGuiApplication> + +#include <QMimeData> #include "droparea.h" #include "dropsitewindow.h" +using namespace Qt::StringLiterals; + //! [constructor part1] DropSiteWindow::DropSiteWindow() { @@ -70,13 +35,10 @@ DropSiteWindow::DropSiteWindow() //! [constructor part2] //! [constructor part3] - QStringList labels; - labels << tr("Format") << tr("Content"); - formatsTable = new QTableWidget; formatsTable->setColumnCount(2); formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - formatsTable->setHorizontalHeaderLabels(labels); + formatsTable->setHorizontalHeaderLabels({tr("Format"), tr("Content")}); formatsTable->horizontalHeader()->setStretchLastSection(true); //! [constructor part3] @@ -107,7 +69,7 @@ DropSiteWindow::DropSiteWindow() mainLayout->addWidget(buttonBox); setWindowTitle(tr("Drop Site")); - setMinimumSize(350, 500); + resize(700, 500); } //! [constructor part5] @@ -130,20 +92,21 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) //! [updateFormatsTable() part3] QString text; - if (format == QLatin1String("text/plain")) { + if (format == u"text/plain") { text = mimeData->text().simplified(); - } else if (format == QLatin1String("text/markdown")) { - text = QString::fromUtf8(mimeData->data(QLatin1String("text/markdown"))); - } else if (format == QLatin1String("text/html")) { + } else if (format == u"text/markdown") { + text = QString::fromUtf8(mimeData->data(u"text/markdown"_s)); + } else if (format == u"text/html") { text = mimeData->html().simplified(); - } else if (format == QLatin1String("text/uri-list")) { + } else if (format == u"text/uri-list") { QList<QUrl> urlList = mimeData->urls(); - for (int i = 0; i < urlList.size() && i < 32; ++i) - text.append(urlList.at(i).toString() + QLatin1Char(' ')); + for (qsizetype i = 0, count = qMin(urlList.size(), qsizetype(32)); i < count; ++i) + text.append(urlList.at(i).toString() + u' '); } else { QByteArray data = mimeData->data(format); - for (int i = 0; i < data.size() && i < 32; ++i) - text.append(QStringLiteral("%1 ").arg(uchar(data[i]), 2, 16, QLatin1Char('0')).toUpper()); + if (data.size() > 32) + data.truncate(32); + text = QString::fromLatin1(data.toHex(' ')).toUpper(); } //! [updateFormatsTable() part3] diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h index a40b481637..942736a3c2 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 DROPSITEWINDOW_H #define DROPSITEWINDOW_H diff --git a/examples/widgets/draganddrop/dropsite/main.cpp b/examples/widgets/draganddrop/dropsite/main.cpp index 70ba55a57c..201bac1ce5 100644 --- a/examples/widgets/draganddrop/dropsite/main.cpp +++ b/examples/widgets/draganddrop/dropsite/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 examples 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 <QApplication> diff --git a/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt b/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt deleted file mode 100644 index 3f8b9108ae..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# Generated from fridgemagnets.pro. - -cmake_minimum_required(VERSION 3.14) -project(fridgemagnets LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/fridgemagnets") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(fridgemagnets - draglabel.cpp draglabel.h - dragwidget.cpp dragwidget.h - main.cpp -) -set_target_properties(fridgemagnets PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(fridgemagnets PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - - -# Resources: -set(fridgemagnets_resource_files - "words.txt" -) - -qt6_add_resources(fridgemagnets "fridgemagnets" - PREFIX - "/dictionary" - FILES - ${fridgemagnets_resource_files} -) - -install(TARGETS fridgemagnets - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp deleted file mode 100644 index 8cdf34ad1e..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "draglabel.h" - -#include <QtWidgets> - -//! [0] -DragLabel::DragLabel(const QString &text, QWidget *parent) - : QLabel(parent) -{ - QFontMetrics metric(font()); - QSize size = metric.size(Qt::TextSingleLine, text); - - QImage image(size.width() + 12, size.height() + 12, QImage::Format_ARGB32_Premultiplied); - image.fill(qRgba(0, 0, 0, 0)); - - QFont font; - font.setStyleStrategy(QFont::ForceOutline); -//! [0] - -//! [1] - QLinearGradient gradient(0, 0, 0, image.height()-1); - gradient.setColorAt(0.0, Qt::white); - gradient.setColorAt(0.2, QColor(200, 200, 255)); - gradient.setColorAt(0.8, QColor(200, 200, 255)); - gradient.setColorAt(1.0, QColor(127, 127, 200)); - - QPainter painter; - painter.begin(&image); - painter.setRenderHint(QPainter::Antialiasing); - painter.setBrush(gradient); - painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1), - 25, 25, Qt::RelativeSize); - - painter.setFont(font); - painter.setBrush(Qt::black); - painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text); - painter.end(); -//! [1] - -//! [2] - setPixmap(QPixmap::fromImage(image)); - m_labelText = text; -} -//! [2] - -QString DragLabel::labelText() const -{ - return m_labelText; -} diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.h b/examples/widgets/draganddrop/fridgemagnets/draglabel.h deleted file mode 100644 index 805009cb9c..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/draglabel.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef DRAGLABEL_H -#define DRAGLABEL_H - -#include <QLabel> - -QT_BEGIN_NAMESPACE -class QDragEnterEvent; -class QDragMoveEvent; -class QFrame; -QT_END_NAMESPACE - -//! [0] -class DragLabel : public QLabel -{ -public: - DragLabel(const QString &text, QWidget *parent); - QString labelText() const; - -private: - QString m_labelText; -}; -//! [0] - -#endif // DRAGLABEL_H diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp deleted file mode 100644 index 14e8a1a879..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "draglabel.h" -#include "dragwidget.h" - -#include <QtWidgets> - -static inline QString fridgetMagnetsMimeType() { return QStringLiteral("application/x-fridgemagnet"); } - -//! [0] -DragWidget::DragWidget(QWidget *parent) - : QWidget(parent) -{ - QFile dictionaryFile(QStringLiteral(":/dictionary/words.txt")); - dictionaryFile.open(QFile::ReadOnly); - QTextStream inputStream(&dictionaryFile); -//! [0] - -//! [1] - int x = 5; - int y = 5; - - while (!inputStream.atEnd()) { - QString word; - inputStream >> word; - if (!word.isEmpty()) { - DragLabel *wordLabel = new DragLabel(word, this); - wordLabel->move(x, y); - wordLabel->show(); - wordLabel->setAttribute(Qt::WA_DeleteOnClose); - x += wordLabel->width() + 2; - if (x >= 245) { - x = 5; - y += wordLabel->height() + 2; - } - } - } -//! [1] - -//! [2] - QPalette newPalette = palette(); - newPalette.setColor(QPalette::Window, Qt::white); - setPalette(newPalette); - - setMinimumSize(400, qMax(200, y)); - setWindowTitle(tr("Fridge Magnets")); -//! [2] //! [3] - setAcceptDrops(true); -} -//! [3] - -//! [4] -void DragWidget::dragEnterEvent(QDragEnterEvent *event) -{ -//! [4] //! [5] - if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) { - if (children().contains(event->source())) { - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - event->acceptProposedAction(); -//! [5] //! [6] - } -//! [6] //! [7] - } else if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } else { - event->ignore(); - } -} -//! [7] - -//! [8] -void DragWidget::dragMoveEvent(QDragMoveEvent *event) -{ - if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) { - if (children().contains(event->source())) { - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - event->acceptProposedAction(); - } - } else if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } else { - event->ignore(); - } -} -//! [8] - -//! [9] -void DragWidget::dropEvent(QDropEvent *event) -{ - if (event->mimeData()->hasFormat(fridgetMagnetsMimeType())) { - const QMimeData *mime = event->mimeData(); -//! [9] //! [10] - QByteArray itemData = mime->data(fridgetMagnetsMimeType()); - QDataStream dataStream(&itemData, QIODevice::ReadOnly); - - QString text; - QPoint offset; - dataStream >> text >> offset; -//! [10] -//! [11] - DragLabel *newLabel = new DragLabel(text, this); - newLabel->move(event->position().toPoint() - offset); - newLabel->show(); - newLabel->setAttribute(Qt::WA_DeleteOnClose); - - if (event->source() == this) { - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - event->acceptProposedAction(); - } -//! [11] //! [12] - } else if (event->mimeData()->hasText()) { - QStringList pieces = event->mimeData()->text().split( - QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts); - QPoint position = event->position().toPoint(); - - for (const QString &piece : pieces) { - DragLabel *newLabel = new DragLabel(piece, this); - newLabel->move(position); - newLabel->show(); - newLabel->setAttribute(Qt::WA_DeleteOnClose); - - position += QPoint(newLabel->width(), 0); - } - - event->acceptProposedAction(); - } else { - event->ignore(); - } -} -//! [12] - -//! [13] -void DragWidget::mousePressEvent(QMouseEvent *event) -{ -//! [13] -//! [14] - DragLabel *child = static_cast<DragLabel*>(childAt(event->position().toPoint())); - if (!child) - return; - - QPoint hotSpot = event->position().toPoint() - child->pos(); - - QByteArray itemData; - QDataStream dataStream(&itemData, QIODevice::WriteOnly); - dataStream << child->labelText() << QPoint(hotSpot); -//! [14] - -//! [15] - QMimeData *mimeData = new QMimeData; - mimeData->setData(fridgetMagnetsMimeType(), itemData); - mimeData->setText(child->labelText()); -//! [15] - -//! [16] - QDrag *drag = new QDrag(this); - drag->setMimeData(mimeData); - drag->setPixmap(child->pixmap(Qt::ReturnByValue)); - drag->setHotSpot(hotSpot); - - child->hide(); -//! [16] - -//! [17] - if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) - child->close(); - else - child->show(); -} -//! [17] diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h deleted file mode 100644 index ff513a33d8..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef DRAGWIDGET_H -#define DRAGWIDGET_H - -#include <QWidget> - -QT_BEGIN_NAMESPACE -class QDragEnterEvent; -class QDropEvent; -QT_END_NAMESPACE - -//! [0] -class DragWidget : public QWidget -{ -public: - explicit DragWidget(QWidget *parent = nullptr); - -protected: - void dragEnterEvent(QDragEnterEvent *event) override; - void dragMoveEvent(QDragMoveEvent *event) override; - void dropEvent(QDropEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; -}; -//! [0] - -#endif // DRAGWIDGET_H diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro deleted file mode 100644 index 2c3165d1c5..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += widgets - -HEADERS = draglabel.h \ - dragwidget.h -RESOURCES = fridgemagnets.qrc -SOURCES = draglabel.cpp \ - dragwidget.cpp \ - main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/fridgemagnets -INSTALLS += target diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc deleted file mode 100644 index b72217d701..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/dictionary"> - <file>words.txt</file> -</qresource> -</RCC> diff --git a/examples/widgets/draganddrop/fridgemagnets/main.cpp b/examples/widgets/draganddrop/fridgemagnets/main.cpp deleted file mode 100644 index 4c575f50b3..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/main.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include <QApplication> - -#include "dragwidget.h" - -int main(int argc, char *argv[]) -{ - Q_INIT_RESOURCE(fridgemagnets); - - QApplication app(argc, argv); -#ifdef QT_KEYPAD_NAVIGATION - QApplication::setNavigationMode(Qt::NavigationModeCursorAuto); -#endif - DragWidget window; - - bool smallScreen = QApplication::arguments().contains(QStringLiteral("-small-screen")); - if (smallScreen) - window.showFullScreen(); - else - window.show(); - - return app.exec(); -} diff --git a/examples/widgets/draganddrop/fridgemagnets/words.txt b/examples/widgets/draganddrop/fridgemagnets/words.txt deleted file mode 100644 index a7e1632b09..0000000000 --- a/examples/widgets/draganddrop/fridgemagnets/words.txt +++ /dev/null @@ -1,48 +0,0 @@ -Colorless -green -ideas -sleep -furiously -A -colorless -green -idea -is -a -new -untried -idea -that -is -without -vividness -dull -and -unexciting -To -sleep -furiously -may -seem -a -puzzling -turn -of -phrase -but -the -mind -in -sleep -often -indeed -moves -furiously -with -ideas -and -images -flickering -in -and -out diff --git a/examples/widgets/draganddrop/puzzle/.prev_CMakeLists.txt b/examples/widgets/draganddrop/puzzle/.prev_CMakeLists.txt deleted file mode 100644 index bcc7708662..0000000000 --- a/examples/widgets/draganddrop/puzzle/.prev_CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Generated from puzzle.pro. - -cmake_minimum_required(VERSION 3.14) -project(puzzle LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop/puzzle") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(puzzle - main.cpp - mainwindow.cpp mainwindow.h - pieceslist.cpp pieceslist.h - puzzlewidget.cpp puzzlewidget.h -) -set_target_properties(puzzle PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(puzzle PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - - -# Resources: -set(puzzle_resource_files - "example.jpg" -) - -qt6_add_resources(puzzle "puzzle" - PREFIX - "/images" - FILES - ${puzzle_resource_files} -) - -install(TARGETS puzzle - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/draganddrop/puzzle/CMakeLists.txt b/examples/widgets/draganddrop/puzzle/CMakeLists.txt deleted file mode 100644 index b7569fb0d2..0000000000 --- a/examples/widgets/draganddrop/puzzle/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Generated from puzzle.pro. - -cmake_minimum_required(VERSION 3.14) -project(puzzle LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/draganddrop_puzzle") # special case - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(draganddrop_puzzle # special case: renamed puzzle - main.cpp - mainwindow.cpp mainwindow.h - pieceslist.cpp pieceslist.h - puzzlewidget.cpp puzzlewidget.h -) -set_target_properties(draganddrop_puzzle PROPERTIES # special case - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(draganddrop_puzzle PUBLIC # special case - Qt::Core - Qt::Gui - Qt::Widgets -) - - -# Resources: -set(puzzle_resource_files - "example.jpg" -) - -qt6_add_resources(draganddrop_puzzle "puzzle" # special case - PREFIX - "/images" - FILES - ${puzzle_resource_files} -) - -install(TARGETS draganddrop_puzzle # special case: renamed puzzle - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/draganddrop/puzzle/example.jpg b/examples/widgets/draganddrop/puzzle/example.jpg Binary files differdeleted file mode 100644 index 023203c57a..0000000000 --- a/examples/widgets/draganddrop/puzzle/example.jpg +++ /dev/null diff --git a/examples/widgets/draganddrop/puzzle/main.cpp b/examples/widgets/draganddrop/puzzle/main.cpp deleted file mode 100644 index d013bf078d..0000000000 --- a/examples/widgets/draganddrop/puzzle/main.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "mainwindow.h" - -#include <QApplication> - -int main(int argc, char *argv[]) -{ - Q_INIT_RESOURCE(puzzle); - - QApplication app(argc, argv); - MainWindow window; - window.loadImage(QStringLiteral(":/images/example.jpg")); - window.show(); - return app.exec(); -} diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.cpp b/examples/widgets/draganddrop/puzzle/mainwindow.cpp deleted file mode 100644 index 98a7cd4265..0000000000 --- a/examples/widgets/draganddrop/puzzle/mainwindow.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "mainwindow.h" -#include "pieceslist.h" -#include "puzzlewidget.h" - -#include <QtWidgets> -#include <stdlib.h> - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ - setupMenus(); - setupWidgets(); - - setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - setWindowTitle(tr("Puzzle")); -} - -void MainWindow::openImage() -{ - const QString directory = - QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::homePath()); - QFileDialog dialog(this, tr("Open Image"), directory); - dialog.setAcceptMode(QFileDialog::AcceptOpen); - dialog.setFileMode(QFileDialog::ExistingFile); - QStringList mimeTypeFilters; - for (const QByteArray &mimeTypeName : QImageReader::supportedMimeTypes()) - mimeTypeFilters.append(mimeTypeName); - mimeTypeFilters.sort(); - dialog.setMimeTypeFilters(mimeTypeFilters); - dialog.selectMimeTypeFilter("image/jpeg"); - if (dialog.exec() == QDialog::Accepted) - loadImage(dialog.selectedFiles().constFirst()); -} - -void MainWindow::loadImage(const QString &fileName) -{ - QPixmap newImage; - if (!newImage.load(fileName)) { - QMessageBox::warning(this, tr("Open Image"), - tr("The image file could not be loaded."), - QMessageBox::Close); - return; - } - puzzleImage = newImage; - setupPuzzle(); -} - -void MainWindow::setCompleted() -{ - QMessageBox::information(this, tr("Puzzle Completed"), - tr("Congratulations! You have completed the puzzle!\n" - "Click OK to start again."), - QMessageBox::Ok); - - setupPuzzle(); -} - -void MainWindow::setupPuzzle() -{ - int size = qMin(puzzleImage.width(), puzzleImage.height()); - puzzleImage = puzzleImage.copy((puzzleImage.width() - size) / 2, - (puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->width(), - puzzleWidget->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - - piecesList->clear(); - - for (int y = 0; y < 5; ++y) { - for (int x = 0; x < 5; ++x) { - int pieceSize = puzzleWidget->pieceSize(); - QPixmap pieceImage = puzzleImage.copy(x * pieceSize, y * pieceSize, pieceSize, pieceSize); - piecesList->addPiece(pieceImage, QPoint(x, y)); - } - } - - for (int i = 0; i < piecesList->count(); ++i) { - if (QRandomGenerator::global()->bounded(2) == 1) { - QListWidgetItem *item = piecesList->takeItem(i); - piecesList->insertItem(0, item); - } - } - - puzzleWidget->clear(); -} - -void MainWindow::setupMenus() -{ - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - - QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openImage); - openAction->setShortcuts(QKeySequence::Open); - - QAction *exitAction = fileMenu->addAction(tr("E&xit"), qApp, &QCoreApplication::quit); - exitAction->setShortcuts(QKeySequence::Quit); - - QMenu *gameMenu = menuBar()->addMenu(tr("&Game")); - - gameMenu->addAction(tr("&Restart"), this, &MainWindow::setupPuzzle); -} - -void MainWindow::setupWidgets() -{ - QFrame *frame = new QFrame; - QHBoxLayout *frameLayout = new QHBoxLayout(frame); - puzzleWidget = new PuzzleWidget(400); - - piecesList = new PiecesList(puzzleWidget->pieceSize(), this); - - - connect(puzzleWidget, &PuzzleWidget::puzzleCompleted, - this, &MainWindow::setCompleted, Qt::QueuedConnection); - - frameLayout->addWidget(piecesList); - frameLayout->addWidget(puzzleWidget); - setCentralWidget(frame); -} diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.h b/examples/widgets/draganddrop/puzzle/mainwindow.h deleted file mode 100644 index 626612ebe8..0000000000 --- a/examples/widgets/draganddrop/puzzle/mainwindow.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include <QMainWindow> -#include <QPixmap> - -class PiecesList; -class PuzzleWidget; -QT_BEGIN_NAMESPACE -class QListWidgetItem; -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = nullptr); - void loadImage(const QString &path); - -public slots: - void openImage(); - void setupPuzzle(); - -private slots: - void setCompleted(); - -private: - void setupMenus(); - void setupWidgets(); - - QPixmap puzzleImage; - PiecesList *piecesList; - PuzzleWidget *puzzleWidget; -}; - -#endif // MAINWINDOW_H diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.cpp b/examples/widgets/draganddrop/puzzle/pieceslist.cpp deleted file mode 100644 index 7846d37ed2..0000000000 --- a/examples/widgets/draganddrop/puzzle/pieceslist.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "pieceslist.h" - -#include <QDrag> -#include <QDragEnterEvent> -#include <QMimeData> - -PiecesList::PiecesList(int pieceSize, QWidget *parent) - : QListWidget(parent), m_PieceSize(pieceSize) -{ - setDragEnabled(true); - setViewMode(QListView::IconMode); - setIconSize(QSize(m_PieceSize, m_PieceSize)); - setSpacing(10); - setAcceptDrops(true); - setDropIndicatorShown(true); -} - -void PiecesList::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) - event->accept(); - else - event->ignore(); -} - -void PiecesList::dragMoveEvent(QDragMoveEvent *event) -{ - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) { - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - event->ignore(); - } -} - -void PiecesList::dropEvent(QDropEvent *event) -{ - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) { - QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType()); - QDataStream dataStream(&pieceData, QIODevice::ReadOnly); - QPixmap pixmap; - QPoint location; - dataStream >> pixmap >> location; - - addPiece(pixmap, location); - - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - event->ignore(); - } -} - -void PiecesList::addPiece(const QPixmap &pixmap, const QPoint &location) -{ - QListWidgetItem *pieceItem = new QListWidgetItem(this); - pieceItem->setIcon(QIcon(pixmap)); - pieceItem->setData(Qt::UserRole, QVariant(pixmap)); - pieceItem->setData(Qt::UserRole+1, location); - pieceItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); -} - -void PiecesList::startDrag(Qt::DropActions /*supportedActions*/) -{ - QListWidgetItem *item = currentItem(); - - QByteArray itemData; - QDataStream dataStream(&itemData, QIODevice::WriteOnly); - QPixmap pixmap = qvariant_cast<QPixmap>(item->data(Qt::UserRole)); - QPoint location = item->data(Qt::UserRole+1).toPoint(); - - dataStream << pixmap << location; - - QMimeData *mimeData = new QMimeData; - mimeData->setData(PiecesList::puzzleMimeType(), itemData); - - QDrag *drag = new QDrag(this); - drag->setMimeData(mimeData); - drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)); - drag->setPixmap(pixmap); - - if (drag->exec(Qt::MoveAction) == Qt::MoveAction) - delete takeItem(row(item)); -} diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h deleted file mode 100644 index a508d17d72..0000000000 --- a/examples/widgets/draganddrop/puzzle/pieceslist.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef PIECESLIST_H -#define PIECESLIST_H - -#include <QListWidget> - -class PiecesList : public QListWidget -{ - Q_OBJECT - -public: - explicit PiecesList(int pieceSize, QWidget *parent = nullptr); - void addPiece(const QPixmap &pixmap, const QPoint &location); - - static QString puzzleMimeType() { return QStringLiteral("image/x-puzzle-piece"); } - -protected: - void dragEnterEvent(QDragEnterEvent *event) override; - void dragMoveEvent(QDragMoveEvent *event) override; - void dropEvent(QDropEvent *event) override; - void startDrag(Qt::DropActions supportedActions) override; - - int m_PieceSize; -}; - -#endif // PIECESLIST_H diff --git a/examples/widgets/draganddrop/puzzle/puzzle.pro b/examples/widgets/draganddrop/puzzle/puzzle.pro deleted file mode 100644 index c462ba1bb8..0000000000 --- a/examples/widgets/draganddrop/puzzle/puzzle.pro +++ /dev/null @@ -1,17 +0,0 @@ -QT += widgets -requires(qtConfig(filedialog)) - -HEADERS = mainwindow.h \ - pieceslist.h \ - puzzlewidget.h -RESOURCES = puzzle.qrc -SOURCES = main.cpp \ - mainwindow.cpp \ - pieceslist.cpp \ - puzzlewidget.cpp - -QMAKE_PROJECT_NAME = dndpuzzle - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/draganddrop/puzzle -INSTALLS += target diff --git a/examples/widgets/draganddrop/puzzle/puzzle.qrc b/examples/widgets/draganddrop/puzzle/puzzle.qrc deleted file mode 100644 index 4076cec026..0000000000 --- a/examples/widgets/draganddrop/puzzle/puzzle.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/images"> - <file>example.jpg</file> -</qresource> -</RCC> diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp deleted file mode 100644 index 06dda9c29f..0000000000 --- a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#include "puzzlewidget.h" -#include "pieceslist.h" - -#include <QDrag> -#include <QDragEnterEvent> -#include <QMimeData> -#include <QPainter> - -PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent) - : QWidget(parent), m_ImageSize(imageSize) -{ - setAcceptDrops(true); - setMinimumSize(m_ImageSize, m_ImageSize); - setMaximumSize(m_ImageSize, m_ImageSize); -} - -void PuzzleWidget::clear() -{ - pieces.clear(); - highlightedRect = QRect(); - inPlace = 0; - update(); -} - -void PuzzleWidget::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())) - event->accept(); - else - event->ignore(); -} - -void PuzzleWidget::dragLeaveEvent(QDragLeaveEvent *event) -{ - QRect updateRect = highlightedRect; - highlightedRect = QRect(); - update(updateRect); - event->accept(); -} - -void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event) -{ - QRect updateRect = highlightedRect.united(targetSquare(event->position().toPoint())); - - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType()) - && findPiece(targetSquare(event->position().toPoint())) == -1) { - - highlightedRect = targetSquare(event->position().toPoint()); - event->setDropAction(Qt::MoveAction); - event->accept(); - } else { - highlightedRect = QRect(); - event->ignore(); - } - - update(updateRect); -} - -void PuzzleWidget::dropEvent(QDropEvent *event) -{ - if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType()) - && findPiece(targetSquare(event->position().toPoint())) == -1) { - - QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType()); - QDataStream dataStream(&pieceData, QIODevice::ReadOnly); - Piece piece; - piece.rect = targetSquare(event->position().toPoint()); - dataStream >> piece.pixmap >> piece.location; - - pieces.append(piece); - - highlightedRect = QRect(); - update(piece.rect); - - event->setDropAction(Qt::MoveAction); - event->accept(); - - if (piece.location == piece.rect.topLeft() / pieceSize()) { - inPlace++; - if (inPlace == 25) - emit puzzleCompleted(); - } - } else { - highlightedRect = QRect(); - event->ignore(); - } -} - -int PuzzleWidget::findPiece(const QRect &pieceRect) const -{ - for (int i = 0, size = pieces.size(); i < size; ++i) { - if (pieces.at(i).rect == pieceRect) - return i; - } - return -1; -} - -void PuzzleWidget::mousePressEvent(QMouseEvent *event) -{ - QRect square = targetSquare(event->position().toPoint()); - const int found = findPiece(square); - - if (found == -1) - return; - - Piece piece = pieces.takeAt(found); - - if (piece.location == square.topLeft() / pieceSize()) - inPlace--; - - update(square); - - QByteArray itemData; - QDataStream dataStream(&itemData, QIODevice::WriteOnly); - - dataStream << piece.pixmap << piece.location; - - QMimeData *mimeData = new QMimeData; - mimeData->setData(PiecesList::puzzleMimeType(), itemData); - - QDrag *drag = new QDrag(this); - drag->setMimeData(mimeData); - drag->setHotSpot(event->position().toPoint() - square.topLeft()); - drag->setPixmap(piece.pixmap); - - if (drag->exec(Qt::MoveAction) != Qt::MoveAction) { - pieces.insert(found, piece); - update(targetSquare(event->position().toPoint())); - - if (piece.location == square.topLeft() / pieceSize()) - inPlace++; - } -} - -void PuzzleWidget::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - painter.fillRect(event->rect(), Qt::white); - - if (highlightedRect.isValid()) { - painter.setBrush(QColor("#ffcccc")); - painter.setPen(Qt::NoPen); - painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1)); - } - - for (const Piece &piece : pieces) - painter.drawPixmap(piece.rect, piece.pixmap); -} - -const QRect PuzzleWidget::targetSquare(const QPoint &position) const -{ - return QRect(position / pieceSize() * pieceSize(), - QSize(pieceSize(), pieceSize())); -} - -int PuzzleWidget::pieceSize() const -{ - return m_ImageSize / 5; -} - -int PuzzleWidget::imageSize() const -{ - return m_ImageSize; -} diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h deleted file mode 100644 index 0ac4719d74..0000000000 --- a/examples/widgets/draganddrop/puzzle/puzzlewidget.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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$ -** -****************************************************************************/ - -#ifndef PUZZLEWIDGET_H -#define PUZZLEWIDGET_H - -#include <QPoint> -#include <QPixmap> -#include <QList> -#include <QWidget> - -QT_BEGIN_NAMESPACE -class QDragEnterEvent; -class QDropEvent; -class QMouseEvent; -QT_END_NAMESPACE - -class PuzzleWidget : public QWidget -{ - Q_OBJECT - -public: - explicit PuzzleWidget(int imageSize, QWidget *parent = nullptr); - void clear(); - - int pieceSize() const; - int imageSize() const; - -signals: - void puzzleCompleted(); - -protected: - void dragEnterEvent(QDragEnterEvent *event) override; - void dragLeaveEvent(QDragLeaveEvent *event) override; - void dragMoveEvent(QDragMoveEvent *event) override; - void dropEvent(QDropEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; - -private: - struct Piece { - QPixmap pixmap; - QRect rect; - QPoint location; - }; - - int findPiece(const QRect &pieceRect) const; - const QRect targetSquare(const QPoint &position) const; - - QList<Piece> pieces; - QRect highlightedRect; - int inPlace; - int m_ImageSize; -}; - -#endif // PUZZLEWIDGET_H |