From a6f91ea8630eac1983d3e671b129b98774557e85 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 19 Dec 2024 15:23:22 +0100 Subject: [PATCH] forwarding of mouse events fixed --- src/controls/QskTextInput.cpp | 56 ++++++++++++++++++++++++++++++++++- src/controls/QskTextInput.h | 2 ++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/controls/QskTextInput.cpp b/src/controls/QskTextInput.cpp index 1dc3897f0..c3e397616 100644 --- a/src/controls/QskTextInput.cpp +++ b/src/controls/QskTextInput.cpp @@ -11,6 +11,11 @@ QSK_QT_PRIVATE_BEGIN #include #include + +#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) +#include +#endif + QSK_QT_PRIVATE_END QSK_SUBCONTROL( QskTextInput, Text ) @@ -28,6 +33,19 @@ static inline void qskPropagateReadOnly( QskTextInput* input ) QCoreApplication::sendEvent( input, &event ); } +static inline void qskTranslateMouseEventPosition( + QMouseEvent* mouseEvent, const QPointF& offset ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) + auto& point = mouseEvent->point(0); + + QMutableEventPoint::setPosition( + point, point.position() + offset ); +#else + mouseEvent->setLocalPos( mouseEvent->localPos() + offset ); +#endif +} + static inline void qskBindSignals( const QQuickTextInput* wrappedInput, QskTextInput* input ) { @@ -161,7 +179,33 @@ namespace inline bool handleEvent( QEvent* event ) { - return this->event( event ); + bool ok; + + switch( static_cast< int >( event->type() ) ) + { + case QEvent::MouseButtonDblClick: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + { + auto mouseEvent = static_cast< QMouseEvent* >( event ); + + /* + As the event was sent for the parent item + we have to translate the position into + our coordinate system. + */ + qskTranslateMouseEventPosition( mouseEvent, -position() ); + ok = this->event( mouseEvent ); + qskTranslateMouseEventPosition( mouseEvent, position() ); + + break; + } + default: + ok = this->event( event ); + } + + return ok; } protected: @@ -491,6 +535,16 @@ void QskTextInput::setText( const QString& text ) m_data->wrappedInput->setText( text ); } +void QskTextInput::clear() +{ + m_data->wrappedInput->clear(); +} + +void QskTextInput::selectAll() +{ + m_data->wrappedInput->selectAll(); +} + QskTextInput::ActivationModes QskTextInput::activationModes() const { return static_cast< QskTextInput::ActivationModes >( m_data->activationModes ); diff --git a/src/controls/QskTextInput.h b/src/controls/QskTextInput.h index f13e50d3b..c3da9ae61 100644 --- a/src/controls/QskTextInput.h +++ b/src/controls/QskTextInput.h @@ -147,6 +147,8 @@ class QSK_EXPORT QskTextInput : public QskControl void ensureVisible( int position ); public Q_SLOTS: + void clear(); + void selectAll(); void setText( const QString& ); void setEditing( bool );