summaryrefslogtreecommitdiffstats
path: root/examples/widgets/draganddrop
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/draganddrop')
-rw-r--r--examples/widgets/draganddrop/CMakeLists.txt11
-rw-r--r--examples/widgets/draganddrop/draganddrop.pro4
-rw-r--r--examples/widgets/draganddrop/draggableicons/CMakeLists.txt52
-rw-r--r--examples/widgets/draganddrop/draggableicons/draggableicons.pro4
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.cpp61
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.h51
-rw-r--r--examples/widgets/draganddrop/draggableicons/main.cpp53
-rw-r--r--examples/widgets/draganddrop/draggabletext/CMakeLists.txt51
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.pro3
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.cpp57
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.h51
-rw-r--r--examples/widgets/draganddrop/draggabletext/main.cpp53
-rw-r--r--examples/widgets/draganddrop/draggabletext/words.txt64
-rw-r--r--examples/widgets/draganddrop/dropsite/CMakeLists.txt46
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.cpp60
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.h54
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp91
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.h51
-rw-r--r--examples/widgets/draganddrop/dropsite/main.cpp51
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt46
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.cpp98
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.h74
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp223
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.h75
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro12
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc5
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/main.cpp72
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/words.txt48
-rw-r--r--examples/widgets/draganddrop/puzzle/.prev_CMakeLists.txt47
-rw-r--r--examples/widgets/draganddrop/puzzle/CMakeLists.txt47
-rw-r--r--examples/widgets/draganddrop/puzzle/example.jpgbin42654 -> 0 bytes
-rw-r--r--examples/widgets/draganddrop/puzzle/main.cpp64
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.cpp165
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.h87
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.cpp134
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.h75
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.pro17
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.qrc5
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.cpp214
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.h103
40 files changed, 191 insertions, 2288 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 5695657792..c1fac8da6b 100644
--- a/examples/widgets/draganddrop/draggableicons/CMakeLists.txt
+++ b/examples/widgets/draganddrop/draggableicons/CMakeLists.txt
@@ -1,30 +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)
+qt_standard_project_setup()
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/draggableicons")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(draggableicons
+qt_add_executable(draggableicons
dragwidget.cpp dragwidget.h
main.cpp
)
-target_link_libraries(draggableicons PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
+
+set_target_properties(draggableicons PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+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
@@ -33,7 +36,7 @@ set(draggableicons_resource_files
"images/house.png"
)
-qt6_add_resources(draggableicons "draggableicons"
+qt_add_resources(draggableicons "draggableicons"
PREFIX
"/"
FILES
@@ -41,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 00671dcf7e..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>
@@ -120,7 +73,7 @@ void DragWidget::dropEvent(QDropEvent *event)
QLabel *newIcon = new QLabel(this);
newIcon->setPixmap(pixmap);
- newIcon->move(event->pos() - offset);
+ newIcon->move(event->position().toPoint() - offset);
newIcon->show();
newIcon->setAttribute(Qt::WA_DeleteOnClose);
@@ -138,15 +91,15 @@ void DragWidget::dropEvent(QDropEvent *event)
//! [1]
void DragWidget::mousePressEvent(QMouseEvent *event)
{
- QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
+ QLabel *child = static_cast<QLabel*>(childAt(event->position().toPoint()));
if (!child)
return;
- QPixmap pixmap = child->pixmap(Qt::ReturnByValue);
+ QPixmap pixmap = child->pixmap();
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << pixmap << QPoint(event->pos() - child->pos());
+ dataStream << pixmap << QPoint(event->position().toPoint() - child->pos());
//! [1]
//! [2]
@@ -158,7 +111,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
- drag->setHotSpot(event->pos() - child->pos());
+ drag->setHotSpot(event->position().toPoint() - child->pos());
//! [3]
QPixmap tempPixmap = pixmap;
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 d3dfc125b2..bc1e72db80 100644
--- a/examples/widgets/draganddrop/draggabletext/CMakeLists.txt
+++ b/examples/widgets/draganddrop/draggabletext/CMakeLists.txt
@@ -1,37 +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)
+qt_standard_project_setup()
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/draggabletext")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(draggabletext
+qt_add_executable(draggabletext
dragwidget.cpp dragwidget.h
main.cpp
)
-target_link_libraries(draggabletext PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
+
+set_target_properties(draggabletext PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
)
+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
@@ -39,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 4a430ebf56..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>
@@ -114,7 +67,7 @@ void DragWidget::dropEvent(QDropEvent *event)
const QMimeData *mime = event->mimeData();
QStringList pieces = mime->text().split(QRegularExpression(QStringLiteral("\\s+")),
Qt::SkipEmptyParts);
- QPoint position = event->pos();
+ QPoint position = event->position().toPoint();
QPoint hotSpot;
QByteArrayList hotSpotPos = mime->data(hotSpotMimeDataKey()).split(' ');
@@ -149,11 +102,11 @@ void DragWidget::dropEvent(QDropEvent *event)
void DragWidget::mousePressEvent(QMouseEvent *event)
{
- QLabel *child = qobject_cast<QLabel*>(childAt(event->pos()));
+ QLabel *child = qobject_cast<QLabel*>(childAt(event->position().toPoint()));
if (!child)
return;
- QPoint hotSpot = event->pos() - child->pos();
+ QPoint hotSpot = event->position().toPoint() - child->pos();
QMimeData *mimeData = new QMimeData;
mimeData->setText(child->text());
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 7d6ce02b4b..ae8d00eb91 100644
--- a/examples/widgets/draganddrop/dropsite/CMakeLists.txt
+++ b/examples/widgets/draganddrop/dropsite/CMakeLists.txt
@@ -1,33 +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)
+qt_standard_project_setup()
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/dropsite")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(dropsite
+qt_add_executable(dropsite
droparea.cpp droparea.h
dropsitewindow.cpp dropsitewindow.h
main.cpp
)
-target_link_libraries(dropsite PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
+
+set_target_properties(dropsite PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+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 886bfd6890..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,6 +48,9 @@ void DropArea::dropEvent(QDropEvent *event)
//! [dropEvent() function part2]
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
+ } 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());
setTextFormat(Qt::RichText);
@@ -102,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 a937e24a4c..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,18 +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/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 31441ab7cb..0000000000
--- a/examples/widgets/draganddrop/fridgemagnets/CMakeLists.txt
+++ /dev/null
@@ -1,46 +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)
-
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/fridgemagnets")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(fridgemagnets
- draglabel.cpp draglabel.h
- dragwidget.cpp dragwidget.h
- main.cpp
-)
-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 a02b1cb42a..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->pos() - 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->pos();
-
- 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->pos()));
- if (!child)
- return;
-
- QPoint hotSpot = event->pos() - 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 148f386115..0000000000
--- a/examples/widgets/draganddrop/puzzle/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,47 +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)
-
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/puzzle")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(puzzle
- main.cpp
- mainwindow.cpp mainwindow.h
- pieceslist.cpp pieceslist.h
- puzzlewidget.cpp puzzlewidget.h
-)
-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 b181efd090..0000000000
--- a/examples/widgets/draganddrop/puzzle/CMakeLists.txt
+++ /dev/null
@@ -1,47 +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)
-
-set(INSTALL_EXAMPLEDIR "examples/widgets/draganddrop/draganddrop_puzzle") # special case
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
-
-add_qt_gui_executable(draganddrop_puzzle # special case: renamed puzzle
- main.cpp
- mainwindow.cpp mainwindow.h
- pieceslist.cpp pieceslist.h
- puzzlewidget.cpp puzzlewidget.h
-)
-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
deleted file mode 100644
index 023203c57a..0000000000
--- a/examples/widgets/draganddrop/puzzle/example.jpg
+++ /dev/null
Binary files differ
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 72f2662bce..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->pos()));
-
- if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())
- && findPiece(targetSquare(event->pos())) == -1) {
-
- highlightedRect = targetSquare(event->pos());
- 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->pos())) == -1) {
-
- QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType());
- QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
- Piece piece;
- piece.rect = targetSquare(event->pos());
- 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->pos());
- 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->pos() - square.topLeft());
- drag->setPixmap(piece.pixmap);
-
- if (drag->exec(Qt::MoveAction) != Qt::MoveAction) {
- pieces.insert(found, piece);
- update(targetSquare(event->pos()));
-
- 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 40dd654af6..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 <QVector>
-#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;
-
- QVector<Piece> pieces;
- QRect highlightedRect;
- int inPlace;
- int m_ImageSize;
-};
-
-#endif // PUZZLEWIDGET_H