diff --git a/examples/layouts/StackLayoutPage.cpp b/examples/layouts/StackLayoutPage.cpp index 550359e6..39241fb4 100644 --- a/examples/layouts/StackLayoutPage.cpp +++ b/examples/layouts/StackLayoutPage.cpp @@ -101,7 +101,7 @@ namespace void incrementScrolling( Qt::Orientation orientation, int offset ) { - auto animator = dynamic_cast< QskStackBoxAnimator1* >( this->animator() ); + auto animator = qobject_cast< QskStackBoxAnimator1* >( this->animator() ); if ( animator == nullptr ) { @@ -109,7 +109,11 @@ namespace animator->setDuration( 1000 ); } - animator->setOrientation( orientation ); + if ( orientation == Qt::Horizontal ) + animator->setDirection( offset > 0 ? Qsk::LeftToRight : Qsk::RightToLeft ); + else + animator->setDirection( offset > 0 ? Qsk::TopToBottom : Qsk::BottomToTop ); + setAnimator( animator ); setCurrentIndex( incrementedIndex( offset ) ); diff --git a/src/controls/QskSwipeView.cpp b/src/controls/QskSwipeView.cpp index c71b0f07..ebe702e7 100644 --- a/src/controls/QskSwipeView.cpp +++ b/src/controls/QskSwipeView.cpp @@ -122,17 +122,6 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event ) if ( itemCount() <= 1 ) return; - auto animator = dynamic_cast< QskStackBoxAnimator1* >( this->animator() ); - - if ( animator == nullptr ) - { - animator = new QskStackBoxAnimator1( this ); - animator->setOrientation( orientation() ); - } - - animator->setDuration( m_data->duration ); - QskStackBox::setAnimator( animator ); - bool forwards; if ( orientation() == Qt::Horizontal ) @@ -140,8 +129,20 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event ) else forwards = gesture->angle() >= 180.0; - auto newIndex = forwards ? currentIndex() + 1 : currentIndex() - 1; + auto animator = qobject_cast< QskStackBoxAnimator1* >( this->animator() ); + if ( animator == nullptr ) + animator = new QskStackBoxAnimator1( this ); + + if ( orientation() == Qt::Horizontal ) + animator->setDirection( forwards ? Qsk::LeftToRight : Qsk::RightToLeft ); + else + animator->setDirection( forwards ? Qsk::TopToBottom : Qsk::BottomToTop ); + + animator->setDuration( m_data->duration ); + QskStackBox::setAnimator( animator ); + + auto newIndex = forwards ? currentIndex() + 1 : currentIndex() - 1; if( newIndex < 0 ) newIndex += itemCount(); diff --git a/src/layouts/QskStackBoxAnimator.cpp b/src/layouts/QskStackBoxAnimator.cpp index e95b022a..5171537b 100644 --- a/src/layouts/QskStackBoxAnimator.cpp +++ b/src/layouts/QskStackBoxAnimator.cpp @@ -13,53 +13,6 @@ QSK_QT_PRIVATE_BEGIN #include QSK_QT_PRIVATE_END -static Qsk::Direction qskDirection( - Qt::Orientation orientation, int from, int to, int itemCount ) -{ - Qsk::Direction direction; - - if ( orientation == Qt::Horizontal ) - { - direction = Qsk::RightToLeft; - - if ( to > from ) - { - const bool isWrapping = ( from == 0 ) && ( to == itemCount - 1 ); - - if ( !isWrapping ) - direction = Qsk::LeftToRight; - } - else - { - const bool isWrapping = ( to == 0 ) && ( from == itemCount - 1 ); - - if ( isWrapping ) - direction = Qsk::LeftToRight; - } - } - else - { - direction = Qsk::BottomToTop; - - if ( to > from ) - { - const bool isWrapping = ( from == 0 ) && ( to == itemCount - 1 ); - - if ( !isWrapping ) - direction = Qsk::TopToBottom; - } - else - { - const bool isWrapping = ( to == 0 ) && ( from == itemCount - 1 ); - - if ( isWrapping ) - direction = Qsk::TopToBottom; - } - } - - return direction; -} - namespace { class RotationTransform : public QQuickTransform @@ -240,7 +193,7 @@ void QskStackBoxAnimator::advance( qreal progress ) QskStackBoxAnimator1::QskStackBoxAnimator1( QskStackBox* parent ) : QskStackBoxAnimator( parent ) - , m_orientation( Qt::Horizontal ) + , m_direction( Qsk::LeftToRight ) , m_isDirty( false ) , m_hasClip( false ) { @@ -251,27 +204,24 @@ QskStackBoxAnimator1::~QskStackBoxAnimator1() { } -void QskStackBoxAnimator1::setOrientation( Qt::Orientation orientation ) +void QskStackBoxAnimator1::setDirection( Qsk::Direction direction ) { - if ( m_orientation != orientation ) + if ( m_direction != direction ) { stop(); - m_orientation = orientation; + m_direction = direction; } } -Qt::Orientation QskStackBoxAnimator1::orientation() const +Qsk::Direction QskStackBoxAnimator1::direction() const { - return m_orientation; + return m_direction; } void QskStackBoxAnimator1::setup() { auto stackBox = this->stackBox(); - m_direction = qskDirection( m_orientation, - startIndex(), endIndex(), stackBox->itemCount() ); - m_hasClip = stackBox->clip(); if ( !m_hasClip ) stackBox->setClip( true ); @@ -283,7 +233,9 @@ void QskStackBoxAnimator1::setup() void QskStackBoxAnimator1::advanceIndex( qreal value ) { auto stackBox = this->stackBox(); - const bool isHorizontal = m_orientation == Qt::Horizontal; + + const bool isHorizontal = ( m_direction == Qsk::LeftToRight ) + || ( m_direction == Qsk::RightToLeft ); for ( int i = 0; i < 2; i++ ) { diff --git a/src/layouts/QskStackBoxAnimator.h b/src/layouts/QskStackBoxAnimator.h index c0fb07f2..8fd0d994 100644 --- a/src/layouts/QskStackBoxAnimator.h +++ b/src/layouts/QskStackBoxAnimator.h @@ -49,14 +49,14 @@ class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator { Q_OBJECT - Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation ) + Q_PROPERTY( Qsk::Direction direction READ direction WRITE setDirection ) public: QskStackBoxAnimator1( QskStackBox* ); ~QskStackBoxAnimator1() override; - void setOrientation( Qt::Orientation ); - Qt::Orientation orientation() const; + void setDirection( Qsk::Direction ); + Qsk::Direction direction() const; protected: bool eventFilter( QObject*, QEvent* ) override; @@ -68,7 +68,6 @@ class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator private: qreal m_itemOffset[ 2 ]; - Qt::Orientation m_orientation : 2; Qsk::Direction m_direction : 4; bool m_isDirty : 1; bool m_hasClip : 1;