some improvememts for stack box flipping
This commit is contained in:
parent
168b8be9d0
commit
b6031f4703
@ -68,7 +68,10 @@ namespace
|
|||||||
if ( animator == nullptr )
|
if ( animator == nullptr )
|
||||||
{
|
{
|
||||||
animator = new QskStackBoxAnimator2( this );
|
animator = new QskStackBoxAnimator2( this );
|
||||||
animator->setDuration( 800 );
|
animator->setOrientation( Qt::Vertical );
|
||||||
|
animator->setInverted( true );
|
||||||
|
animator->setEasingCurve( QEasingCurve::InOutBack );
|
||||||
|
animator->setDuration( 2000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
setAnimator( animator );
|
setAnimator( animator );
|
||||||
|
@ -4,11 +4,14 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "TestRectangle.h"
|
#include "TestRectangle.h"
|
||||||
|
#include <QskSkin.h>
|
||||||
|
|
||||||
TestRectangle::TestRectangle( QQuickItem* parent )
|
TestRectangle::TestRectangle( QQuickItem* parent )
|
||||||
: QskTextLabel( parent )
|
: QskTextLabel( parent )
|
||||||
{
|
{
|
||||||
setAlignment( Qt::AlignCenter );
|
setAlignment( Qt::AlignCenter );
|
||||||
|
setFontRole( QskSkin::HugeFont );
|
||||||
|
setTextColor( Qt::white );
|
||||||
|
|
||||||
setPreferredSize( 10, 10 );
|
setPreferredSize( 10, 10 );
|
||||||
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
|
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
|
||||||
|
@ -62,23 +62,27 @@ static Qsk::Direction qskDirection(
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class Rotation : public QQuickTransform
|
class RotationTransform : public QQuickTransform
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Rotation( qreal angle, QQuickItem* item )
|
RotationTransform( Qt::Axis axis, qreal angle, QQuickItem* item )
|
||||||
: QQuickTransform( item )
|
: QQuickTransform( item )
|
||||||
|
, m_axis( axis )
|
||||||
, m_angle( angle )
|
, m_angle( angle )
|
||||||
{
|
{
|
||||||
prependToItem( item );
|
prependToItem( item );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAngle( qreal angle )
|
void setAngle( qreal angle )
|
||||||
|
{
|
||||||
|
if ( m_angle != angle )
|
||||||
{
|
{
|
||||||
m_angle = angle;
|
m_angle = angle;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void applyTo( QMatrix4x4* matrix) const override
|
void applyTo( QMatrix4x4* matrix) const override
|
||||||
{
|
{
|
||||||
@ -89,28 +93,30 @@ namespace
|
|||||||
|
|
||||||
QTransform transform;
|
QTransform transform;
|
||||||
transform.translate( dx, dy );
|
transform.translate( dx, dy );
|
||||||
transform.rotate( m_angle, Qt::XAxis );
|
transform.rotate( m_angle, m_axis );
|
||||||
transform.translate( -dx, -dy );
|
transform.translate( -dx, -dy );
|
||||||
|
|
||||||
*matrix *= transform;
|
*matrix *= transform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Rotation* find( const QQuickItem* item )
|
|
||||||
|
private:
|
||||||
|
const Qt::Axis m_axis;
|
||||||
|
qreal m_angle = 0.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static RotationTransform* qskFindRotationTransform( const QQuickItem* item )
|
||||||
{
|
{
|
||||||
const auto& transforms = QQuickItemPrivate::get( item )->transforms;
|
const auto& transforms = QQuickItemPrivate::get( item )->transforms;
|
||||||
for ( const auto& t : transforms )
|
for ( const auto& t : transforms )
|
||||||
{
|
{
|
||||||
if ( auto rotation = qobject_cast< Rotation* >( t ) )
|
if ( auto transform = qobject_cast< RotationTransform* >( t ) )
|
||||||
return rotation;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
qreal m_angle = 0.0;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QskStackBoxAnimator::QskStackBoxAnimator( QskStackBox* parent )
|
QskStackBoxAnimator::QskStackBoxAnimator( QskStackBox* parent )
|
||||||
@ -219,9 +225,7 @@ void QskStackBoxAnimator1::setOrientation( Qt::Orientation orientation )
|
|||||||
{
|
{
|
||||||
if ( m_orientation != orientation )
|
if ( m_orientation != orientation )
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
stop();
|
stop();
|
||||||
#endif
|
|
||||||
m_orientation = orientation;
|
m_orientation = orientation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,6 +336,8 @@ bool QskStackBoxAnimator1::eventFilter( QObject* object, QEvent* event )
|
|||||||
|
|
||||||
QskStackBoxAnimator2::QskStackBoxAnimator2( QskStackBox* parent )
|
QskStackBoxAnimator2::QskStackBoxAnimator2( QskStackBox* parent )
|
||||||
: QskStackBoxAnimator( parent )
|
: QskStackBoxAnimator( parent )
|
||||||
|
, m_orientation( Qt::Horizontal )
|
||||||
|
, m_inverted( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,23 +345,60 @@ QskStackBoxAnimator2::~QskStackBoxAnimator2()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskStackBoxAnimator2::setOrientation( Qt::Orientation orientation )
|
||||||
|
{
|
||||||
|
if ( m_orientation != orientation )
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
m_orientation = orientation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::Orientation QskStackBoxAnimator2::orientation() const
|
||||||
|
{
|
||||||
|
return m_orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskStackBoxAnimator2::setInverted( bool on )
|
||||||
|
{
|
||||||
|
if ( m_inverted != on )
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
m_inverted = on;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QskStackBoxAnimator2::isInverted() const
|
||||||
|
{
|
||||||
|
return m_inverted;
|
||||||
|
}
|
||||||
|
|
||||||
void QskStackBoxAnimator2::setup()
|
void QskStackBoxAnimator2::setup()
|
||||||
{
|
{
|
||||||
|
const auto axis = ( m_orientation == Qt::Horizontal )
|
||||||
|
? Qt::YAxis : Qt::XAxis;
|
||||||
|
|
||||||
if ( auto item = itemAt( 0 ) )
|
if ( auto item = itemAt( 0 ) )
|
||||||
( void ) new Rotation( 0.0, item );
|
( void ) new RotationTransform( axis, 0.0, item );
|
||||||
|
|
||||||
if ( auto item = itemAt( 1 ) )
|
if ( auto item = itemAt( 1 ) )
|
||||||
( void ) new Rotation( 90.0, item );
|
( void ) new RotationTransform( axis, 90.0, item );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskStackBoxAnimator2::advanceIndex( qreal value )
|
void QskStackBoxAnimator2::advanceIndex( qreal value )
|
||||||
{
|
{
|
||||||
if ( value < 0.5 )
|
auto degrees = value * 180.0;
|
||||||
|
|
||||||
|
if ( degrees < 90.0 && degrees > -90.0 )
|
||||||
{
|
{
|
||||||
if ( auto item = itemAt( 0 ) )
|
if ( auto item = itemAt( 0 ) )
|
||||||
{
|
{
|
||||||
auto rotation = Rotation::find( item );
|
if ( !m_inverted )
|
||||||
rotation->setAngle( value * 180.0 );
|
degrees = 360.0 - degrees;
|
||||||
|
|
||||||
|
auto rotation = qskFindRotationTransform( item );
|
||||||
|
rotation->setAngle( degrees );
|
||||||
|
|
||||||
item->setVisible( true );
|
item->setVisible( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,8 +416,12 @@ void QskStackBoxAnimator2::advanceIndex( qreal value )
|
|||||||
|
|
||||||
if ( auto item = itemAt( 1 ) )
|
if ( auto item = itemAt( 1 ) )
|
||||||
{
|
{
|
||||||
auto rotation = Rotation::find( item );
|
degrees = degrees - 180.0;
|
||||||
rotation->setAngle( ( 1.0 - value ) * -180.0 );
|
if ( !m_inverted )
|
||||||
|
degrees = 360.0 - degrees;
|
||||||
|
|
||||||
|
auto rotation = qskFindRotationTransform( item );
|
||||||
|
rotation->setAngle( degrees );
|
||||||
|
|
||||||
item->setVisible( true );
|
item->setVisible( true );
|
||||||
}
|
}
|
||||||
@ -387,8 +434,8 @@ void QskStackBoxAnimator2::done()
|
|||||||
{
|
{
|
||||||
if ( auto item = itemAt( i ) )
|
if ( auto item = itemAt( i ) )
|
||||||
{
|
{
|
||||||
delete Rotation::find( item );
|
delete qskFindRotationTransform( item );
|
||||||
item->setVisible( i == 1 ); // not here !!
|
item->setVisible( i == 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,8 @@ class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QskStackBoxAnimator1( QskStackBox* );
|
QskStackBoxAnimator1( QskStackBox* );
|
||||||
~QskStackBoxAnimator1() override;
|
~QskStackBoxAnimator1() override;
|
||||||
@ -75,14 +77,27 @@ class QSK_EXPORT QskStackBoxAnimator2 : public QskStackBoxAnimator
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation )
|
||||||
|
Q_PROPERTY( bool inverted READ isInverted WRITE setInverted )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QskStackBoxAnimator2( QskStackBox* );
|
QskStackBoxAnimator2( QskStackBox* );
|
||||||
~QskStackBoxAnimator2() override;
|
~QskStackBoxAnimator2() override;
|
||||||
|
|
||||||
|
void setOrientation( Qt::Orientation );
|
||||||
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
|
void setInverted( bool );
|
||||||
|
bool isInverted() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void advanceIndex( qreal value ) override;
|
void advanceIndex( qreal value ) override;
|
||||||
void done() override;
|
void done() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Qt::Orientation m_orientation : 2;
|
||||||
|
bool m_inverted : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QSK_EXPORT QskStackBoxAnimator3 : public QskStackBoxAnimator
|
class QSK_EXPORT QskStackBoxAnimator3 : public QskStackBoxAnimator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user