confusing event filtering and forwarding simplified
This commit is contained in:
parent
bf2c2b981e
commit
65e3290fc4
|
@ -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() );
|
||||
|
@ -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 )
|
||||
|
@ -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 ?
|
||||
|
||||
Qsk::Direction direction;
|
||||
|
||||
switch( event->key() )
|
||||
{
|
||||
QCoreApplication::sendEvent( m_cube, event );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
|
@ -356,10 +342,8 @@ 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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue