IOT dashboard: fix swiping over 2 hops
This commit is contained in:
parent
978183916f
commit
83a9d835b5
|
@ -63,6 +63,7 @@ Cube::Cube( QQuickItem* parent )
|
||||||
: QskStackBox( false, parent )
|
: QskStackBox( false, parent )
|
||||||
, m_destination( FrontPos )
|
, m_destination( FrontPos )
|
||||||
, m_previousPosition( FrontPos )
|
, m_previousPosition( FrontPos )
|
||||||
|
, m_isIntermediateHop( false )
|
||||||
{
|
{
|
||||||
// The code below covers the case where we need 2 cube movements to get
|
// The code below covers the case where we need 2 cube movements to get
|
||||||
// to the desired position.
|
// to the desired position.
|
||||||
|
@ -73,15 +74,11 @@ Cube::Cube( QQuickItem* parent )
|
||||||
{
|
{
|
||||||
const bool animationIsFinished = ( position == qFloor( position ) );
|
const bool animationIsFinished = ( position == qFloor( position ) );
|
||||||
|
|
||||||
if( animationIsFinished)
|
|
||||||
{
|
|
||||||
qDebug() << "finished." << position << m_destination << ( position == m_destination );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( animationIsFinished && position != m_destination )
|
if( animationIsFinished && position != m_destination )
|
||||||
{
|
{
|
||||||
QTimer::singleShot( 0, this, [this]()
|
QTimer::singleShot( 0, this, [this]()
|
||||||
{
|
{
|
||||||
|
m_isIntermediateHop = true;
|
||||||
switchToPosition( m_destination );
|
switchToPosition( m_destination );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -90,8 +87,6 @@ Cube::Cube( QQuickItem* parent )
|
||||||
|
|
||||||
void Cube::doSwitch( Qsk::Direction direction, Position position )
|
void Cube::doSwitch( Qsk::Direction direction, Position position )
|
||||||
{
|
{
|
||||||
m_previousPosition = m_destination;
|
|
||||||
|
|
||||||
using Animator = QskStackBoxAnimator4;
|
using Animator = QskStackBoxAnimator4;
|
||||||
|
|
||||||
auto animator = qobject_cast< Animator* >( this->animator() );
|
auto animator = qobject_cast< Animator* >( this->animator() );
|
||||||
|
@ -99,12 +94,26 @@ void Cube::doSwitch( Qsk::Direction direction, Position position )
|
||||||
if ( animator == nullptr )
|
if ( animator == nullptr )
|
||||||
{
|
{
|
||||||
animator = new Animator( this );
|
animator = new Animator( this );
|
||||||
animator->setEasingCurve( QEasingCurve::InOutQuad );
|
|
||||||
animator->setDuration( 1000 );
|
animator->setDuration( 1000 );
|
||||||
|
|
||||||
setAnimator( animator );
|
setAnimator( animator );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( position == m_destination && !m_isIntermediateHop ) // 1 hop
|
||||||
|
{
|
||||||
|
animator->setEasingCurve( QEasingCurve::InOutQuad );
|
||||||
|
}
|
||||||
|
else if( !m_isIntermediateHop ) // 1st of 2 hops
|
||||||
|
{
|
||||||
|
animator->setEasingCurve( QEasingCurve::InQuad );
|
||||||
|
}
|
||||||
|
else // 2nd of 2 hops
|
||||||
|
{
|
||||||
|
animator->setEasingCurve( QEasingCurve::OutQuad );
|
||||||
|
m_isIntermediateHop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_previousPosition = m_destination;
|
||||||
|
|
||||||
const auto orientation = ( direction == Qsk::LeftToRight || direction == Qsk::RightToLeft )
|
const auto orientation = ( direction == Qsk::LeftToRight || direction == Qsk::RightToLeft )
|
||||||
? Qt::Horizontal : Qt::Vertical;
|
? Qt::Horizontal : Qt::Vertical;
|
||||||
animator->setOrientation( orientation );
|
animator->setOrientation( orientation );
|
||||||
|
@ -140,19 +149,23 @@ void Cube::switchPosition( const Qsk::Direction direction )
|
||||||
|
|
||||||
void Cube::switchToPosition( const Position position )
|
void Cube::switchToPosition( const Position position )
|
||||||
{
|
{
|
||||||
if( currentIndex() == position )
|
if( currentPosition() == position )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_destination = position;
|
m_destination = position;
|
||||||
|
|
||||||
const auto from = static_cast< Position >( currentIndex() );
|
const auto from = static_cast< Position >( currentIndex() );
|
||||||
const auto direction = this->direction( from, position );
|
const auto direction = this->direction( from, position );
|
||||||
const auto currentPosition = static_cast< Position >( currentIndex() );
|
const auto intermediatePosition = neighbor( currentPosition(), direction );
|
||||||
const auto intermediatePosition = neighbor( currentPosition, direction );
|
|
||||||
|
|
||||||
doSwitch( direction, intermediatePosition );
|
doSwitch( direction, intermediatePosition );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cube::Position Cube::currentPosition() const
|
||||||
|
{
|
||||||
|
return static_cast< Position >( currentIndex() );
|
||||||
|
}
|
||||||
|
|
||||||
Cube::Position Cube::neighbor( const Position position, const Qsk::Direction direction ) const
|
Cube::Position Cube::neighbor( const Position position, const Qsk::Direction direction ) const
|
||||||
{
|
{
|
||||||
const auto n = s_neighbors[ position ][ direction ];
|
const auto n = s_neighbors[ position ][ direction ];
|
||||||
|
|
|
@ -37,12 +37,14 @@ class Cube : public QskStackBox
|
||||||
void cubeIndexChanged( const int index );
|
void cubeIndexChanged( const int index );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Position currentPosition() const;
|
||||||
Position neighbor( const Position position, const Qsk::Direction direction ) const;
|
Position neighbor( const Position position, const Qsk::Direction direction ) const;
|
||||||
Qsk::Direction direction( const Position from, const Position to ) const;
|
Qsk::Direction direction( const Position from, const Position to ) const;
|
||||||
void doSwitch( Qsk::Direction direction, Position position );
|
void doSwitch( Qsk::Direction direction, Position position );
|
||||||
|
|
||||||
Position m_destination;
|
Position m_destination;
|
||||||
Position m_previousPosition;
|
Position m_previousPosition;
|
||||||
|
bool m_isIntermediateHop;
|
||||||
|
|
||||||
static Position s_neighbors[ NumPositions ][ 4 ];
|
static Position s_neighbors[ NumPositions ][ 4 ];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue