Skip to content

Commit

Permalink
forwarding of mouse events fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Dec 19, 2024
1 parent a91dcd5 commit a6f91ea
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/controls/QskTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
QSK_QT_PRIVATE_BEGIN
#include <private/qquicktextinput_p.h>
#include <private/qquicktextinput_p_p.h>

#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <private/qeventpoint_p.h>
#endif

QSK_QT_PRIVATE_END

QSK_SUBCONTROL( QskTextInput, Text )
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/controls/QskTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down

0 comments on commit a6f91ea

Please sign in to comment.