From 619d682b5bac6bc773950381688c9d60c2ad5320 Mon Sep 17 00:00:00 2001
From: Vitor Vieira <155513369+VitorVieiraZ@users.noreply.github.com>
Date: Fri, 19 Jul 2024 12:20:18 -0300
Subject: [PATCH] Handling accidental double-taps on buttons with
MMSingleClickMouseArea (#3532)
* updating all versions after release
* MMSingleClickMouseArea draft
* code adjustments
* preventing click from propagating to the background
* adding new SingleClickMouseArea to photo procedures
* new component description and added to gallery qrc, timer set to 2 seconds
* how-to use new component
* version fix
* post review fixes
* small code layout fix
* MMSingleClickMouseArea on openLinkedFeature
* adding MMSingleClickMouseArea to MMPhoto
---
app/qml/CMakeLists.txt | 1 +
app/qml/components/MMPhoto.qml | 4 +-
app/qml/components/MMSingleClickMouseArea.qml | 38 +++++++++++++++++++
.../components/photo/MMPhotoAttachment.qml | 8 ++--
app/qml/form/editors/MMFormGalleryEditor.qml | 4 +-
app/qml/form/editors/MMFormRelationEditor.qml | 8 ++--
gallery/qml.qrc | 1 +
7 files changed, 52 insertions(+), 12 deletions(-)
create mode 100644 app/qml/components/MMSingleClickMouseArea.qml
diff --git a/app/qml/CMakeLists.txt b/app/qml/CMakeLists.txt
index 04fb07a7c..bf848bd61 100644
--- a/app/qml/CMakeLists.txt
+++ b/app/qml/CMakeLists.txt
@@ -50,6 +50,7 @@ set(MM_QML
components/MMText.qml
components/MMToolbar.qml
components/MMToolbarButton.qml
+ components/MMSingleClickMouseArea.qml
components/private/MMBaseInput.qml
components/private/MMBaseSingleLineInput.qml
components/private/MMToolbarLongButton.qml
diff --git a/app/qml/components/MMPhoto.qml b/app/qml/components/MMPhoto.qml
index 5f5e71669..bb01ffa89 100644
--- a/app/qml/components/MMPhoto.qml
+++ b/app/qml/components/MMPhoto.qml
@@ -52,9 +52,9 @@ Image {
}
}
- MouseArea {
+ MMSingleClickMouseArea {
anchors.fill: parent
- onClicked: root.clicked(root.photoUrl)
+ onSingleClicked: root.clicked(root.photoUrl)
}
onStatusChanged: {
diff --git a/app/qml/components/MMSingleClickMouseArea.qml b/app/qml/components/MMSingleClickMouseArea.qml
new file mode 100644
index 000000000..39320cd14
--- /dev/null
+++ b/app/qml/components/MMSingleClickMouseArea.qml
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+import QtQuick
+
+/**
+ * MMSingleClickMouseArea enhances MouseArea by preventing multiple clicks within a
+ * specified time frame, ensuring consistent behavior and avoiding unintended actions
+ * Similar to MouseArea, but it should be used with onSingleClicked signal handling instead of onClicked
+*/
+
+MouseArea {
+ id: root
+
+ signal singleClicked()
+
+ onClicked: {
+ if ( timer.running ) {
+ mouse.accepted = true;
+ return;
+ }
+
+ singleClicked()
+ timer.start()
+ }
+
+ Timer {
+ id: timer
+ interval: 2000
+ repeat: false
+ }
+}
diff --git a/app/qml/form/components/photo/MMPhotoAttachment.qml b/app/qml/form/components/photo/MMPhotoAttachment.qml
index c5ecd8f2d..255204539 100644
--- a/app/qml/form/components/photo/MMPhotoAttachment.qml
+++ b/app/qml/form/components/photo/MMPhotoAttachment.qml
@@ -63,9 +63,9 @@ Rectangle {
}
}
- MouseArea {
+ MMComponents.MMSingleClickMouseArea{
anchors.fill: parent
- onClicked: root.capturePhotoClicked()
+ onSingleClicked: root.capturePhotoClicked()
}
}
@@ -102,9 +102,9 @@ Rectangle {
}
}
- MouseArea {
+ MMComponents.MMSingleClickMouseArea{
anchors.fill: parent
- onClicked: root.chooseFromGalleryClicked()
+ onSingleClicked: root.chooseFromGalleryClicked()
}
}
}
diff --git a/app/qml/form/editors/MMFormGalleryEditor.qml b/app/qml/form/editors/MMFormGalleryEditor.qml
index 648b02c8e..2008dcf4a 100644
--- a/app/qml/form/editors/MMFormGalleryEditor.qml
+++ b/app/qml/form/editors/MMFormGalleryEditor.qml
@@ -89,9 +89,9 @@ MMPrivateComponents.MMBaseInput {
size: __style.icon32
}
- MouseArea {
+ MMComponents.MMSingleClickMouseArea {
anchors.fill: parent
- onClicked: {
+ onSingleClicked: {
root.createLinkedFeature( root._fieldFeatureLayerPair, root._fieldAssociatedRelation )
}
}
diff --git a/app/qml/form/editors/MMFormRelationEditor.qml b/app/qml/form/editors/MMFormRelationEditor.qml
index c2743f8f3..faf393017 100644
--- a/app/qml/form/editors/MMFormRelationEditor.qml
+++ b/app/qml/form/editors/MMFormRelationEditor.qml
@@ -85,9 +85,9 @@ MMPrivateComponents.MMBaseInput {
height: width
}
- MouseArea {
+ MMComponents.MMSingleClickMouseArea{
anchors.fill: parent
- onClicked: {
+ onSingleClicked: {
root.forceActiveFocus() // clear focus from all elements to prevent freezing #3483
root.createLinkedFeature( root._fieldFeatureLayerPair, root._fieldAssociatedRelation )
}
@@ -135,9 +135,9 @@ MMPrivateComponents.MMBaseInput {
verticalAlignment: Text.AlignVCenter
}
- MouseArea {
+ MMComponents.MMSingleClickMouseArea {
anchors.fill: parent
- onClicked: root.openLinkedFeature( model.FeaturePair )
+ onSingleClicked: root.openLinkedFeature( model.FeaturePair )
}
onVisibleChanged: root.recalculateVisibleItems()
diff --git a/gallery/qml.qrc b/gallery/qml.qrc
index 24feb29bb..b54c2ff92 100644
--- a/gallery/qml.qrc
+++ b/gallery/qml.qrc
@@ -75,6 +75,7 @@
../app/qml/components/MMDrawer.qml
../app/qml/components/MMDrawerHeader.qml
../app/qml/components/MMBusyIndicator.qml
+ ../app/qml/components/MMSingleClickMouseArea.qml
../app/qml/account/components/MMAccountPageItem.qml
../app/qml/account/components/MMIconCheckBoxHorizontal.qml
../app/qml/account/components/MMIconCheckBoxVertical.qml