Skip to content

Commit

Permalink
confusing event filtering and forwarding simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Sep 13, 2023
1 parent bf2c2b9 commit 65e3290
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
68 changes: 26 additions & 42 deletions examples/iotdashboard/MainItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,6 @@ void Cube::switchToPosition( const Position position )
doSwitch( direction, nextPosition );
}

void Cube::keyPressEvent( QKeyEvent* event )
{
Qsk::Direction direction;

switch( event->key() )
{
case Qt::Key_Up:
direction = Qsk::TopToBottom;
break;

case Qt::Key_Down:
direction = Qsk::BottomToTop;
break;

case Qt::Key_Left:
direction = Qsk::LeftToRight;
break;

case Qt::Key_Right:
direction = Qsk::RightToLeft;
break;

default:
return;
}

switchPosition( direction );
}

Cube::Position Cube::currentPosition() const
{
return static_cast< Position >( currentIndex() );
Expand Down Expand Up @@ -304,8 +275,6 @@ MainItem::MainItem( QQuickItem* parent )

// the current item needs to be the one at the Front:
m_cube->setCurrentItem( dashboardPage );

installEventFilter( this );
}

void MainItem::gestureEvent( QskGestureEvent* event )
Expand All @@ -332,19 +301,36 @@ void MainItem::gestureEvent( QskGestureEvent* event )
}
}

bool MainItem::eventFilter( QObject* object, QEvent* event )
void MainItem::keyPressEvent( QKeyEvent* event )
{
if ( event->type() == QEvent::KeyPress )
{
QCoreApplication::sendEvent( m_cube, event );
return true;
}
else
// maybe using shortcuts ?

Qsk::Direction direction;

switch( event->key() )
{
return QObject::eventFilter( object, event );
case Qt::Key_Up:
direction = Qsk::TopToBottom;
break;

case Qt::Key_Down:
direction = Qsk::BottomToTop;
break;

case Qt::Key_Left:
direction = Qsk::LeftToRight;
break;

case Qt::Key_Right:
direction = Qsk::RightToLeft;
break;

default:
return;
}
}

m_cube->switchPosition( direction );
}
bool MainItem::gestureFilter( const QQuickItem* item, const QEvent* event )
{
auto& recognizer = m_panRecognizer;
Expand All @@ -356,9 +342,7 @@ bool MainItem::gestureFilter( const QQuickItem* item, const QEvent* event )
if( ( item != this ) || ( recognizer.timeout() < 0 ) )
{
if( recognizer.hasProcessedBefore( mouseEvent ) )
{
return false;
}
}

recognizer.setTimeout( ( item == this ) ? -1 : 100 );
Expand Down
16 changes: 7 additions & 9 deletions examples/iotdashboard/MainItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,19 @@ class Cube : public QskStackBox
explicit Cube( QQuickItem* parent = nullptr );

public Q_SLOTS:
void switchPosition( const Qsk::Direction direction );
void switchToPosition( const Cube::Position position );
void switchPosition( const Qsk::Direction );
void switchToPosition( const Cube::Position );

Q_SIGNALS:
// might be different from indexChanged:
void cubeIndexChanged( const int index );

protected:
void keyPressEvent( QKeyEvent* event ) override;

private:
Position currentPosition() const;
Position neighbor( const Position position, const Qsk::Direction direction ) const;
Position neighbor( const Position, const Qsk::Direction ) const;
Qsk::Direction direction( const Position from, const Position to ) const;
void updateEdge( Qsk::Direction direction, Position position );
void doSwitch( Qsk::Direction direction, Position position );
void updateEdge( Qsk::Direction, Position );
void doSwitch( Qsk::Direction, Position );

Position m_destination;
Edge m_currentEdge;
Expand All @@ -73,7 +70,8 @@ class MainItem : public QskControl
MainItem( QQuickItem* parent = nullptr );

protected:
bool eventFilter(QObject* obj, QEvent* event) override final;
void keyPressEvent( QKeyEvent* ) override final;

bool gestureFilter( const QQuickItem*, const QEvent* ) override final;
void gestureEvent( QskGestureEvent* ) override final;

Expand Down

0 comments on commit 65e3290

Please sign in to comment.