Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling accidental double-taps on buttons with MMSingleClickMouseArea #3532

Merged
merged 12 commits into from
Jul 19, 2024
1 change: 1 addition & 0 deletions app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(MM_QML
components/MMText.qml
components/MMToolbar.qml
components/MMToolbarButton.qml
components/MMSingleClickMouseArea.qml
VitorVieiraZ marked this conversation as resolved.
Show resolved Hide resolved
components/private/MMBaseInput.qml
components/private/MMBaseSingleLineInput.qml
components/private/MMToolbarLongButton.qml
Expand Down
38 changes: 38 additions & 0 deletions app/qml/components/MMSingleClickMouseArea.qml
Original file line number Diff line number Diff line change
@@ -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

VitorVieiraZ marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
}
}
8 changes: 4 additions & 4 deletions app/qml/form/components/photo/MMPhotoAttachment.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ Rectangle {
}
}

MouseArea {
MMComponents.MMSingleClickMouseArea{
anchors.fill: parent
onClicked: root.capturePhotoClicked()
onSingleClicked: root.capturePhotoClicked()
}
}

Expand Down Expand Up @@ -102,9 +102,9 @@ Rectangle {
}
}

MouseArea {
MMComponents.MMSingleClickMouseArea{
anchors.fill: parent
onClicked: root.chooseFromGalleryClicked()
onSingleClicked: root.chooseFromGalleryClicked()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/qml/form/editors/MMFormGalleryEditor.qml
tomasMizera marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ MMPrivateComponents.MMBaseInput {
size: __style.icon32
}

MouseArea {
MMComponents.MMSingleClickMouseArea {
anchors.fill: parent
onClicked: {
onSingleClicked: {
root.createLinkedFeature( root._fieldFeatureLayerPair, root._fieldAssociatedRelation )
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/qml/form/editors/MMFormRelationEditor.qml
VitorVieiraZ marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
}
Expand Down
1 change: 1 addition & 0 deletions gallery/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<file>../app/qml/components/MMDrawer.qml</file>
<file>../app/qml/components/MMDrawerHeader.qml</file>
<file>../app/qml/components/MMBusyIndicator.qml</file>
<file>../app/qml/components/MMSingleClickMouseArea.qml</file>
<file>../app/qml/account/components/MMAccountPageItem.qml</file>
<file>../app/qml/account/components/MMIconCheckBoxHorizontal.qml</file>
<file>../app/qml/account/components/MMIconCheckBoxVertical.qml</file>
Expand Down
Loading