Index: sources/gui/qml/components/TouchRect.qml =================================================================== diff -u -r7f984daf450d01b14495eca7c47c96d936f8b32b -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 --- sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision 7f984daf450d01b14495eca7c47c96d936f8b32b) +++ sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file TouchRect.qml * \author (last) Behrouz NematiPour - * \date (last) 30-Sep-2022 + * \date (last) 03-Nov-2023 * \author (original) Behrouz NematiPour * \date (original) 18-Oct-2019 * @@ -28,7 +28,8 @@ property alias text : _text property alias pixelSize : _text.font.pixelSize property alias fgColor : _text.color - property alias bgColor : _root.color + //TODO need to update code to use bgColor instead of backgroundColor property +// property alias bgColor : _root.color property alias textString : _text.text property bool touchable : true @@ -38,7 +39,7 @@ property bool selected : false property bool fading : false - + property int debouncingTime : 350 readonly property alias isPressed : _mouseArea.pressed property color textColor : Colors.textButton @@ -54,6 +55,12 @@ Colors.backgroundButtonSelectDark : Qt.darker (_root.backgroundColor, 1.15) + Timer { id: clickDebounceTimer + interval: _root.debouncingTime // ms + } + Timer { id: pressDebounceTimer + interval: _root.debouncingTime // ms + } QtObject { id: _private function color() { var mBackgroundColor = _root.backgroundColor @@ -77,6 +84,10 @@ } return _root.borderColor } + + property bool clickDebouncing: clickDebounceTimer.running // if a click/press happens the timer starts, meaning we have to debounce. + property bool pressDebouncing: pressDebounceTimer.running // if a click/press happens the timer starts, meaning we have to debounce. + property bool pressed : false // this will take care of releases happening during debounced press, therefor no release should happen as well. } color : _private.color() @@ -109,6 +120,10 @@ radius : Variables.touchRectRadius border.width: Variables.borderWidth + function onMouseEventLog(vMsg) { + // DEBUG: console.log(vMsg, _text.text, Qt.formatTime(new Date(), "hh:mm:ss.zzz")) + } + Text { id: _text anchors.verticalCenter : parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter @@ -120,9 +135,9 @@ enabled : _root.touchable anchors.fill : parent anchors.margins : touchExpanding * -1 - onClicked : _root.clicked() - onPressed : _root.pressed() - onReleased : _root.released() - onPressAndHold : _root.pressAndHold() + onClicked : { if ( ! _private.clickDebouncing ) { onMouseEventLog("Clicked ") ; _root.clicked (); clickDebounceTimer.start(); } } + onPressed : { if ( ! _private.pressDebouncing ) { onMouseEventLog("Pressed ") ; _private.pressed = true ; _root.pressed (); pressDebounceTimer.start(); } } + onReleased : { if ( _private.pressed ) { onMouseEventLog("Released ") ; _private.pressed = false; _root.released (); pressDebounceTimer.start(); } } + onPressAndHold : { onMouseEventLog("PressAndHold ") ; _root.pressAndHold(); } } }