QskStackBox::transientindex introduced
This commit is contained in:
parent
84edabe8e3
commit
8ab578ff19
@ -168,6 +168,17 @@ void QskStackBox::setCurrentIndex( int index )
|
|||||||
Q_EMIT currentIndexChanged( m_data->currentIndex );
|
Q_EMIT currentIndexChanged( m_data->currentIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal QskStackBox::transientIndex() const
|
||||||
|
{
|
||||||
|
if ( auto animator = m_data->animator )
|
||||||
|
{
|
||||||
|
if ( animator->isRunning() )
|
||||||
|
return animator->transientIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentIndex();
|
||||||
|
}
|
||||||
|
|
||||||
void QskStackBox::setCurrentItem( const QQuickItem* item )
|
void QskStackBox::setCurrentItem( const QQuickItem* item )
|
||||||
{
|
{
|
||||||
setCurrentIndex( indexOf( item ) );
|
setCurrentIndex( indexOf( item ) );
|
||||||
|
@ -17,6 +17,9 @@ class QSK_EXPORT QskStackBox : public QskIndexedLayoutBox
|
|||||||
Q_PROPERTY( int currentIndex READ currentIndex
|
Q_PROPERTY( int currentIndex READ currentIndex
|
||||||
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( qreal transientIndex READ transientIndex
|
||||||
|
NOTIFY transientIndexChanged )
|
||||||
|
|
||||||
Q_PROPERTY( QQuickItem* currentItem READ currentItem
|
Q_PROPERTY( QQuickItem* currentItem READ currentItem
|
||||||
WRITE setCurrentItem NOTIFY currentItemChanged )
|
WRITE setCurrentItem NOTIFY currentItemChanged )
|
||||||
|
|
||||||
@ -46,6 +49,8 @@ class QSK_EXPORT QskStackBox : public QskIndexedLayoutBox
|
|||||||
QQuickItem* currentItem() const;
|
QQuickItem* currentItem() const;
|
||||||
int currentIndex() const;
|
int currentIndex() const;
|
||||||
|
|
||||||
|
qreal transientIndex() const;
|
||||||
|
|
||||||
void setDefaultAlignment( Qt::Alignment );
|
void setDefaultAlignment( Qt::Alignment );
|
||||||
Qt::Alignment defaultAlignment() const;
|
Qt::Alignment defaultAlignment() const;
|
||||||
|
|
||||||
@ -67,6 +72,7 @@ class QSK_EXPORT QskStackBox : public QskIndexedLayoutBox
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void currentIndexChanged( int index );
|
void currentIndexChanged( int index );
|
||||||
|
void transientIndexChanged( qreal index );
|
||||||
void currentItemChanged( QQuickItem* );
|
void currentItemChanged( QQuickItem* );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "QskStackBox.h"
|
#include "QskStackBox.h"
|
||||||
#include "QskEvent.h"
|
#include "QskEvent.h"
|
||||||
#include "QskQuick.h"
|
#include "QskQuick.h"
|
||||||
|
#include "QskFunctions.h"
|
||||||
|
|
||||||
static Qsk::Direction qskDirection(
|
static Qsk::Direction qskDirection(
|
||||||
Qt::Orientation orientation, int from, int to, int itemCount )
|
Qt::Orientation orientation, int from, int to, int itemCount )
|
||||||
@ -68,7 +69,7 @@ QskStackBoxAnimator::~QskStackBoxAnimator()
|
|||||||
|
|
||||||
void QskStackBoxAnimator::setStartIndex( int index )
|
void QskStackBoxAnimator::setStartIndex( int index )
|
||||||
{
|
{
|
||||||
m_startIndex = index;
|
m_transientIndex = m_startIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskStackBoxAnimator::setEndIndex( int index )
|
void QskStackBoxAnimator::setEndIndex( int index )
|
||||||
@ -97,6 +98,53 @@ QQuickItem* QskStackBoxAnimator::itemAt( int index ) const
|
|||||||
( index == 0 ) ? m_startIndex : m_endIndex );
|
( index == 0 ) ? m_startIndex : m_endIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal QskStackBoxAnimator::transientIndex() const
|
||||||
|
{
|
||||||
|
return m_transientIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskStackBoxAnimator::advance( qreal progress )
|
||||||
|
{
|
||||||
|
qreal transientIndex;
|
||||||
|
|
||||||
|
if ( qFuzzyIsNull( progress ) )
|
||||||
|
{
|
||||||
|
transientIndex = m_startIndex;
|
||||||
|
}
|
||||||
|
else if ( qFuzzyCompare( progress, 1.0 ) )
|
||||||
|
{
|
||||||
|
transientIndex = m_endIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto box = stackBox();
|
||||||
|
|
||||||
|
auto startIndex = m_startIndex;
|
||||||
|
auto endIndex = m_endIndex;
|
||||||
|
|
||||||
|
if ( startIndex == 0 )
|
||||||
|
{
|
||||||
|
if ( endIndex == box->itemCount() - 1 )
|
||||||
|
startIndex += box->itemCount();
|
||||||
|
}
|
||||||
|
else if ( startIndex == box->itemCount() - 1 )
|
||||||
|
{
|
||||||
|
if ( endIndex == 0 )
|
||||||
|
endIndex += box->itemCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
transientIndex = startIndex + ( endIndex - startIndex ) * progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !qskFuzzyCompare( m_transientIndex, transientIndex ) )
|
||||||
|
{
|
||||||
|
m_transientIndex = transientIndex;
|
||||||
|
advanceIndex( progress );
|
||||||
|
|
||||||
|
Q_EMIT stackBox()->transientIndexChanged( m_transientIndex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QskStackBoxAnimator1::QskStackBoxAnimator1( QskStackBox* parent )
|
QskStackBoxAnimator1::QskStackBoxAnimator1( QskStackBox* parent )
|
||||||
: QskStackBoxAnimator( parent )
|
: QskStackBoxAnimator( parent )
|
||||||
, m_orientation( Qt::Horizontal )
|
, m_orientation( Qt::Horizontal )
|
||||||
@ -141,7 +189,7 @@ void QskStackBoxAnimator1::setup()
|
|||||||
m_isDirty = true;
|
m_isDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskStackBoxAnimator1::advance( qreal value )
|
void QskStackBoxAnimator1::advanceIndex( qreal value )
|
||||||
{
|
{
|
||||||
auto stackBox = this->stackBox();
|
auto stackBox = this->stackBox();
|
||||||
const bool isHorizontal = m_orientation == Qt::Horizontal;
|
const bool isHorizontal = m_orientation == Qt::Horizontal;
|
||||||
@ -243,7 +291,7 @@ void QskStackBoxAnimator3::setup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskStackBoxAnimator3::advance( qreal value )
|
void QskStackBoxAnimator3::advanceIndex( qreal value )
|
||||||
{
|
{
|
||||||
if ( auto item1 = itemAt( 0 ) )
|
if ( auto item1 = itemAt( 0 ) )
|
||||||
item1->setOpacity( 1.0 - value );
|
item1->setOpacity( 1.0 - value );
|
||||||
|
@ -28,13 +28,20 @@ class QSK_EXPORT QskStackBoxAnimator : public QObject, public QskAnimator
|
|||||||
int startIndex() const;
|
int startIndex() const;
|
||||||
int endIndex() const;
|
int endIndex() const;
|
||||||
|
|
||||||
|
qreal transientIndex() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QskStackBox* stackBox() const;
|
QskStackBox* stackBox() const;
|
||||||
QQuickItem* itemAt( int index ) const;
|
QQuickItem* itemAt( int index ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void advance( qreal value ) override final;
|
||||||
|
virtual void advanceIndex( qreal value ) = 0;
|
||||||
|
|
||||||
int m_startIndex;
|
int m_startIndex;
|
||||||
int m_endIndex;
|
int m_endIndex;
|
||||||
|
|
||||||
|
qreal m_transientIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator
|
class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator
|
||||||
@ -52,7 +59,7 @@ class QSK_EXPORT QskStackBoxAnimator1 : public QskStackBoxAnimator
|
|||||||
bool eventFilter( QObject*, QEvent* ) override;
|
bool eventFilter( QObject*, QEvent* ) override;
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void advance( qreal value ) override;
|
void advanceIndex( qreal value ) override;
|
||||||
void done() override;
|
void done() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -74,7 +81,7 @@ class QSK_EXPORT QskStackBoxAnimator3 : public QskStackBoxAnimator
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void advance( qreal value ) override;
|
void advanceIndex( qreal value ) override;
|
||||||
void done() override;
|
void done() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user