progress br added
This commit is contained in:
parent
27a95ee60f
commit
85b6a4cf57
@ -9,15 +9,20 @@
|
|||||||
|
|
||||||
#include <QskAspect.h>
|
#include <QskAspect.h>
|
||||||
#include <QskPageIndicator.h>
|
#include <QskPageIndicator.h>
|
||||||
|
#include <QskProgressBar.h>
|
||||||
#include <QskRgbValue.h>
|
#include <QskRgbValue.h>
|
||||||
#include <QskStackBox.h>
|
#include <QskStackBox.h>
|
||||||
#include <QskStackBoxAnimator.h>
|
#include <QskStackBoxAnimator.h>
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
|
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class StackBox : public QskStackBox
|
class StackBox : public QskStackBox
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StackBox( QQuickItem* parent = nullptr )
|
StackBox( QQuickItem* parent = nullptr )
|
||||||
: QskStackBox( parent )
|
: QskStackBox( parent )
|
||||||
@ -27,8 +32,6 @@ namespace
|
|||||||
setBackgroundColor( Qt::white );
|
setBackgroundColor( Qt::white );
|
||||||
setDefaultAlignment( Qt::AlignCenter );
|
setDefaultAlignment( Qt::AlignCenter );
|
||||||
|
|
||||||
setMargins( 30 );
|
|
||||||
|
|
||||||
addRectangle( "Gold" );
|
addRectangle( "Gold" );
|
||||||
addRectangle( "SeaGreen" );
|
addRectangle( "SeaGreen" );
|
||||||
addRectangle( "SlateBlue" );
|
addRectangle( "SlateBlue" );
|
||||||
@ -41,7 +44,6 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
void incrementFading( int offset )
|
void incrementFading( int offset )
|
||||||
{
|
{
|
||||||
auto animator = dynamic_cast< QskStackBoxAnimator3* >( this->animator() );
|
auto animator = dynamic_cast< QskStackBoxAnimator3* >( this->animator() );
|
||||||
@ -55,6 +57,8 @@ namespace
|
|||||||
|
|
||||||
setAnimator( animator );
|
setAnimator( animator );
|
||||||
setCurrentIndex( incrementedIndex( offset ) );
|
setCurrentIndex( incrementedIndex( offset ) );
|
||||||
|
|
||||||
|
Q_EMIT transitionStarted( animator->duration() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void incrementScrolling( Qt::Orientation orientation, int offset )
|
void incrementScrolling( Qt::Orientation orientation, int offset )
|
||||||
@ -71,8 +75,13 @@ namespace
|
|||||||
setAnimator( animator );
|
setAnimator( animator );
|
||||||
|
|
||||||
setCurrentIndex( incrementedIndex( offset ) );
|
setCurrentIndex( incrementedIndex( offset ) );
|
||||||
|
|
||||||
|
Q_EMIT transitionStarted( animator->duration() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void transitionStarted( int ms );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addRectangle( const char* colorName )
|
void addRectangle( const char* colorName )
|
||||||
{
|
{
|
||||||
@ -94,6 +103,55 @@ namespace
|
|||||||
return newIndex;
|
return newIndex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ProgressBar : public QskProgressBar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProgressBar( QQuickItem* parent = nullptr )
|
||||||
|
: QskProgressBar( parent )
|
||||||
|
{
|
||||||
|
setValue( 0.0 );
|
||||||
|
setMaximumWidth( 200 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void startProgressing( int ms )
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
|
||||||
|
if ( ms > 0 )
|
||||||
|
{
|
||||||
|
m_duration = ms;
|
||||||
|
m_elapsed.start();
|
||||||
|
m_timerId = startTimer( 5 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void timerEvent( QTimerEvent* ) override
|
||||||
|
{
|
||||||
|
if ( m_elapsed.elapsed() >= m_duration )
|
||||||
|
reset();
|
||||||
|
else
|
||||||
|
setValue( m_elapsed.elapsed() / m_duration * 100.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
if ( m_timerId )
|
||||||
|
{
|
||||||
|
killTimer( m_timerId );
|
||||||
|
m_timerId = 0;
|
||||||
|
}
|
||||||
|
setValue( 0.0 );
|
||||||
|
m_duration = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_timerId = 0;
|
||||||
|
qreal m_duration = 0.0;
|
||||||
|
QElapsedTimer m_elapsed;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
StackLayoutPage::StackLayoutPage( QQuickItem* parent )
|
StackLayoutPage::StackLayoutPage( QQuickItem* parent )
|
||||||
@ -104,9 +162,9 @@ StackLayoutPage::StackLayoutPage( QQuickItem* parent )
|
|||||||
setMargins( 10 );
|
setMargins( 10 );
|
||||||
setBackgroundColor( QskRgbValue::LightSteelBlue );
|
setBackgroundColor( QskRgbValue::LightSteelBlue );
|
||||||
|
|
||||||
auto* box = new StackBox();
|
auto box = new StackBox();
|
||||||
|
|
||||||
auto* buttonBox = new ButtonBox();
|
auto buttonBox = new ButtonBox();
|
||||||
|
|
||||||
buttonBox->setLayoutAlignmentHint( Qt::AlignTop | Qt::AlignLeft );
|
buttonBox->setLayoutAlignmentHint( Qt::AlignTop | Qt::AlignLeft );
|
||||||
buttonBox->addButton( "<<", [ box ]() { box->incrementScrolling( Qt::Horizontal, +1 ); } );
|
buttonBox->addButton( "<<", [ box ]() { box->incrementScrolling( Qt::Horizontal, +1 ); } );
|
||||||
@ -115,15 +173,28 @@ StackLayoutPage::StackLayoutPage( QQuickItem* parent )
|
|||||||
buttonBox->addButton( "v", [ box ]() { box->incrementScrolling( Qt::Vertical, +1 ); } );
|
buttonBox->addButton( "v", [ box ]() { box->incrementScrolling( Qt::Vertical, +1 ); } );
|
||||||
buttonBox->addButton( "Fading", [ box ]() { box->incrementFading( +1 ); } );
|
buttonBox->addButton( "Fading", [ box ]() { box->incrementFading( +1 ); } );
|
||||||
|
|
||||||
|
// page indicator
|
||||||
|
|
||||||
auto pageIndicator = new QskPageIndicator();
|
auto pageIndicator = new QskPageIndicator();
|
||||||
pageIndicator->setCount( box->itemCount() );
|
pageIndicator->setCount( box->itemCount() );
|
||||||
pageIndicator->setCurrentIndex( box->currentIndex() );
|
pageIndicator->setCurrentIndex( box->currentIndex() );
|
||||||
pageIndicator->setLayoutAlignmentHint( Qt::AlignCenter );
|
pageIndicator->setLayoutAlignmentHint( Qt::AlignCenter );
|
||||||
|
|
||||||
|
// progress bar
|
||||||
|
auto progressBar = new ProgressBar();
|
||||||
|
progressBar->setMargins( QMarginsF( 0, 0, 10, 0 ) );
|
||||||
|
|
||||||
|
|
||||||
addItem( buttonBox );
|
addItem( buttonBox );
|
||||||
addItem( pageIndicator );
|
addItem( pageIndicator );
|
||||||
addItem( box );
|
addItem( box );
|
||||||
|
addItem( progressBar, Qt::AlignRight );
|
||||||
|
|
||||||
connect( box, &QskStackBox::currentIndexChanged,
|
connect( box, &QskStackBox::currentIndexChanged,
|
||||||
pageIndicator, &QskPageIndicator::setCurrentIndex );
|
pageIndicator, &QskPageIndicator::setCurrentIndex );
|
||||||
|
|
||||||
|
connect( box, &StackBox::transitionStarted,
|
||||||
|
progressBar, &ProgressBar::startProgressing );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "StackLayoutPage.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user