Index: sources/gui/qml/components/TouchRect.qml =================================================================== diff -u -r4714af95cde20bc704971c6749a288a21979c24f -rb543920c939d90945b271985dd9fbbae67e60b83 --- sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision 4714af95cde20bc704971c6749a288a21979c24f) +++ sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision b543920c939d90945b271985dd9fbbae67e60b83) @@ -29,7 +29,7 @@ property alias pixelSize : _text.font.pixelSize property alias fgColor : _text.color //TODO need to update code to use bgColor instead of backgroundColor property -// property alias bgColor : _root.color +// property alias bgColor : _root.color property alias textString : _text.text property bool touchable : true @@ -39,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 @@ -55,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 @@ -78,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() @@ -110,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 @@ -121,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(); } } }