aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/quickcontrols/swipetoremove
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/quickcontrols/swipetoremove')
-rw-r--r--tests/manual/quickcontrols/swipetoremove/CMakeLists.txt40
-rw-r--r--tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.gifbin0 -> 371365 bytes
-rw-r--r--tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.pngbin0 -> 22511 bytes
-rw-r--r--tests/manual/quickcontrols/swipetoremove/doc/src/qtquickcontrols-swipetoremove.qdoc42
-rw-r--r--tests/manual/quickcontrols/swipetoremove/fonts/LICENSE.txt12
-rw-r--r--tests/manual/quickcontrols/swipetoremove/fonts/fontello.ttfbin0 -> 5164 bytes
-rw-r--r--tests/manual/quickcontrols/swipetoremove/swipetoremove.cpp20
-rw-r--r--tests/manual/quickcontrols/swipetoremove/swipetoremove.pro10
-rw-r--r--tests/manual/quickcontrols/swipetoremove/swipetoremove.qml130
9 files changed, 254 insertions, 0 deletions
diff --git a/tests/manual/quickcontrols/swipetoremove/CMakeLists.txt b/tests/manual/quickcontrols/swipetoremove/CMakeLists.txt
new file mode 100644
index 0000000000..4500695355
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/CMakeLists.txt
@@ -0,0 +1,40 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(swipetoremove LANGUAGES CXX)
+
+set(CMAKE_AUTOMOC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols/swipetoremove")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
+
+qt_add_executable(swipetoremoveexample WIN32 MACOSX_BUNDLE
+ swipetoremove.cpp
+)
+target_link_libraries(swipetoremoveexample PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+)
+
+# Resources:
+qt_add_qml_module(swipetoremoveexample
+ URI swipetoremove
+ NO_RESOURCE_TARGET_PATH
+ QML_FILES
+ "swipetoremove.qml"
+ RESOURCES
+ "fonts/fontello.ttf"
+)
+
+install(TARGETS swipetoremoveexample
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.gif b/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.gif
new file mode 100644
index 0000000000..6142831356
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.gif
Binary files differ
diff --git a/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.png b/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.png
new file mode 100644
index 0000000000..07a200fe92
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/doc/images/qtquickcontrols-swipetoremove.png
Binary files differ
diff --git a/tests/manual/quickcontrols/swipetoremove/doc/src/qtquickcontrols-swipetoremove.qdoc b/tests/manual/quickcontrols/swipetoremove/doc/src/qtquickcontrols-swipetoremove.qdoc
new file mode 100644
index 0000000000..29f4e652b1
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/doc/src/qtquickcontrols-swipetoremove.qdoc
@@ -0,0 +1,42 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example swipetoremove
+ \keyword Qt Quick Controls - Swipe to Remove
+ \title Qt Quick Controls - Swipe to Remove
+ \ingroup qtquickcontrols-examples
+ \brief Demonstrates removal of list items by swipe gesture.
+
+ This example demonstrates how \l SwipeDelegate can be used to implement
+ removal of list items by swiping. This UI pattern is often used in touch
+ user interfaces.
+
+ \image qtquickcontrols-swipetoremove.png "Screen shot of the app"
+
+ Each list item can be swiped to the left, which reveals a label on the
+ \l {SwipeDelegate::swipe}{right} side indicating that the item will be
+ removed if the swipe is completed.
+
+ \image qtquickcontrols-swipetoremove.gif "Animation of the app working"
+
+ The following snippet contains the implementation of the side item.
+
+ \snippet swipetoremove/swipetoremove.qml delegate
+
+ The following snippet presents how the logic of removing items is
+ implemented. When the swipe is \l {SwipeDelegate::swipe}{completed}, it
+ starts a timer that waits a few seconds to let the user undo the remove
+ action. Once the undo timer triggers, the item is removed from the list:
+
+ \snippet swipetoremove/swipetoremove.qml removal
+
+ Finally, the removal of an item triggers the following transitions. The
+ \l {ListView::} {remove} transition applies to the item that is removed,
+ and the \l {ListView::}{displaced} transition applies to the other items
+ that got displaced due to the removal:
+
+ \snippet swipetoremove/swipetoremove.qml transitions
+
+ \include examples-run.qdocinc
+*/
diff --git a/tests/manual/quickcontrols/swipetoremove/fonts/LICENSE.txt b/tests/manual/quickcontrols/swipetoremove/fonts/LICENSE.txt
new file mode 100644
index 0000000000..7394a58ddf
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/fonts/LICENSE.txt
@@ -0,0 +1,12 @@
+Font license info
+
+
+## Elusive
+
+ Copyright (C) 2013 by Aristeides Stathopoulos
+
+ Author: Aristeides Stathopoulos
+ License: SIL (http://scripts.sil.org/OFL)
+ Homepage: http://aristeides.com/
+
+
diff --git a/tests/manual/quickcontrols/swipetoremove/fonts/fontello.ttf b/tests/manual/quickcontrols/swipetoremove/fonts/fontello.ttf
new file mode 100644
index 0000000000..553fd2efca
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/fonts/fontello.ttf
Binary files differ
diff --git a/tests/manual/quickcontrols/swipetoremove/swipetoremove.cpp b/tests/manual/quickcontrols/swipetoremove/swipetoremove.cpp
new file mode 100644
index 0000000000..c46926e2b2
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/swipetoremove.cpp
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QFontDatabase>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QFontDatabase::addApplicationFont(":/fonts/fontello.ttf");
+
+ QQmlApplicationEngine engine;
+ engine.load(QUrl("qrc:/swipetoremove.qml"));
+ if (engine.rootObjects().isEmpty())
+ return -1;
+
+ return app.exec();
+}
diff --git a/tests/manual/quickcontrols/swipetoremove/swipetoremove.pro b/tests/manual/quickcontrols/swipetoremove/swipetoremove.pro
new file mode 100644
index 0000000000..e16ff8145f
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/swipetoremove.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = swipetoremove
+QT += qml
+
+SOURCES += swipetoremove.cpp
+
+RESOURCES += swipetoremove.qml
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols/swipetoremove
+INSTALLS += target
diff --git a/tests/manual/quickcontrols/swipetoremove/swipetoremove.qml b/tests/manual/quickcontrols/swipetoremove/swipetoremove.qml
new file mode 100644
index 0000000000..dd2d9d3ecf
--- /dev/null
+++ b/tests/manual/quickcontrols/swipetoremove/swipetoremove.qml
@@ -0,0 +1,130 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Controls.Material
+
+ApplicationWindow {
+ id: window
+ width: 300
+ height: 400
+ visible: true
+ title: qsTr("Swipe to Remove")
+
+ ListView {
+ id: listView
+ anchors.fill: parent
+
+ delegate: SwipeDelegate {
+ id: delegate
+
+ text: modelData
+ width: listView.width
+
+ //! [delegate]
+ swipe.right: Rectangle {
+ width: parent.width
+ height: parent.height
+
+ clip: true
+ color: SwipeDelegate.pressed ? "#555" : "#666"
+
+ Label {
+ font.family: "Fontello"
+ text: delegate.swipe.complete ? "\ue805" // icon-cw-circled
+ : "\ue801" // icon-cancel-circled-1
+
+ padding: 20
+ anchors.fill: parent
+ horizontalAlignment: Qt.AlignRight
+ verticalAlignment: Qt.AlignVCenter
+
+ opacity: 2 * -delegate.swipe.position
+
+ color: Material.color(delegate.swipe.complete ? Material.Green : Material.Red, Material.Shade200)
+ Behavior on color { ColorAnimation { } }
+ }
+
+ Label {
+ text: qsTr("Removed")
+ color: "white"
+
+ padding: 20
+ anchors.fill: parent
+ horizontalAlignment: Qt.AlignLeft
+ verticalAlignment: Qt.AlignVCenter
+
+ opacity: delegate.swipe.complete ? 1 : 0
+ Behavior on opacity { NumberAnimation { } }
+ }
+
+ SwipeDelegate.onClicked: delegate.swipe.close()
+ SwipeDelegate.onPressedChanged: undoTimer.stop()
+ }
+ //! [delegate]
+
+ //! [removal]
+ Timer {
+ id: undoTimer
+ interval: 3600
+ onTriggered: listModel.remove(index)
+ }
+
+ swipe.onCompleted: undoTimer.start()
+ //! [removal]
+ }
+
+ model: ListModel {
+ id: listModel
+ ListElement { text: "Lorem ipsum dolor sit amet" }
+ ListElement { text: "Curabitur sit amet risus" }
+ ListElement { text: "Suspendisse vehicula nisi" }
+ ListElement { text: "Mauris imperdiet libero" }
+ ListElement { text: "Sed vitae dui aliquet augue" }
+ ListElement { text: "Praesent in elit eu nulla" }
+ ListElement { text: "Etiam vitae magna" }
+ ListElement { text: "Pellentesque eget elit euismod" }
+ ListElement { text: "Nulla at enim porta" }
+ ListElement { text: "Fusce tincidunt odio" }
+ ListElement { text: "Ut non ex a ligula molestie" }
+ ListElement { text: "Nam vitae justo scelerisque" }
+ ListElement { text: "Vestibulum pulvinar tellus" }
+ ListElement { text: "Quisque dignissim leo sed gravida" }
+ }
+
+ //! [transitions]
+ remove: Transition {
+ SequentialAnimation {
+ PauseAnimation { duration: 125 }
+ NumberAnimation { property: "height"; to: 0; easing.type: Easing.InOutQuad }
+ }
+ }
+
+ displaced: Transition {
+ SequentialAnimation {
+ PauseAnimation { duration: 125 }
+ NumberAnimation { property: "y"; easing.type: Easing.InOutQuad }
+ }
+ }
+ //! [transitions]
+
+ ScrollIndicator.vertical: ScrollIndicator { }
+ }
+
+ Label {
+ id: placeholder
+ text: qsTr("Swipe no more")
+
+ anchors.margins: 60
+ anchors.fill: parent
+
+ opacity: 0.5
+ visible: listView.count === 0
+
+ horizontalAlignment: Qt.AlignHCenter
+ verticalAlignment: Qt.AlignVCenter
+ wrapMode: Label.WordWrap
+ font.pixelSize: 18
+ }
+}