confusing event filtering and forwarding simplified

This commit is contained in:
Uwe Rathmann 2023-09-13 18:01:46 +02:00
parent bf2c2b981e
commit 65e3290fc4
2 changed files with 35 additions and 53 deletions

View File

@ -193,35 +193,6 @@ void Cube::switchToPosition( const Position position )
doSwitch( direction, nextPosition ); 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 Cube::Position Cube::currentPosition() const
{ {
return static_cast< Position >( currentIndex() ); return static_cast< Position >( currentIndex() );
@ -304,8 +275,6 @@ MainItem::MainItem( QQuickItem* parent )
// the current item needs to be the one at the Front: // the current item needs to be the one at the Front:
m_cube->setCurrentItem( dashboardPage ); m_cube->setCurrentItem( dashboardPage );
installEventFilter( this );
} }
void MainItem::gestureEvent( QskGestureEvent* event ) void MainItem::gestureEvent( QskGestureEvent* event )
@ -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 ) // maybe using shortcuts ?
{
QCoreApplication::sendEvent( m_cube, event );
return true;
}
else
{
return QObject::eventFilter( object, 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;
}
m_cube->switchPosition( direction );
}
bool MainItem::gestureFilter( const QQuickItem* item, const QEvent* event ) bool MainItem::gestureFilter( const QQuickItem* item, const QEvent* event )
{ {
auto& recognizer = m_panRecognizer; auto& recognizer = m_panRecognizer;
@ -356,9 +342,7 @@ bool MainItem::gestureFilter( const QQuickItem* item, const QEvent* event )
if( ( item != this ) || ( recognizer.timeout() < 0 ) ) if( ( item != this ) || ( recognizer.timeout() < 0 ) )
{ {
if( recognizer.hasProcessedBefore( mouseEvent ) ) if( recognizer.hasProcessedBefore( mouseEvent ) )
{
return false; return false;
}
} }
recognizer.setTimeout( ( item == this ) ? -1 : 100 ); recognizer.setTimeout( ( item == this ) ? -1 : 100 );

View File

@ -40,22 +40,19 @@ class Cube : public QskStackBox
explicit Cube( QQuickItem* parent = nullptr ); explicit Cube( QQuickItem* parent = nullptr );
public Q_SLOTS: public Q_SLOTS:
void switchPosition( const Qsk::Direction direction ); void switchPosition( const Qsk::Direction );
void switchToPosition( const Cube::Position position ); void switchToPosition( const Cube::Position );
Q_SIGNALS: Q_SIGNALS:
// might be different from indexChanged: // might be different from indexChanged:
void cubeIndexChanged( const int index ); void cubeIndexChanged( const int index );
protected:
void keyPressEvent( QKeyEvent* event ) override;
private: private:
Position currentPosition() const; 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; Qsk::Direction direction( const Position from, const Position to ) const;
void updateEdge( Qsk::Direction direction, Position position ); void updateEdge( Qsk::Direction, Position );
void doSwitch( Qsk::Direction direction, Position position ); void doSwitch( Qsk::Direction, Position );
Position m_destination; Position m_destination;
Edge m_currentEdge; Edge m_currentEdge;
@ -73,7 +70,8 @@ class MainItem : public QskControl
MainItem( QQuickItem* parent = nullptr ); MainItem( QQuickItem* parent = nullptr );
protected: protected:
bool eventFilter(QObject* obj, QEvent* event) override final; void keyPressEvent( QKeyEvent* ) override final;
bool gestureFilter( const QQuickItem*, const QEvent* ) override final; bool gestureFilter( const QQuickItem*, const QEvent* ) override final;
void gestureEvent( QskGestureEvent* ) override final; void gestureEvent( QskGestureEvent* ) override final;