QskStackBoxAnimator1::setOrientation replaced by QskStackBoxAnimator1::setDirection.
Autodetection the direction from the indexes did not work when having only 2 items.
This commit is contained in:
parent
27f41dd5f6
commit
267c559330
@ -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 ) );
|
||||
|
@ -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();
|
||||
|
||||
|
@ -13,53 +13,6 @@ QSK_QT_PRIVATE_BEGIN
|
||||
#include <private/qquickitem_p.h>
|
||||
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++ )
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user