2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "StackLayoutPage.h"
|
|
|
|
#include "ButtonBox.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "TestRectangle.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include <QskAspect.h>
|
|
|
|
#include <QskPageIndicator.h>
|
2020-08-06 09:28:38 +02:00
|
|
|
#include <QskProgressBar.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskRgbValue.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskStackBox.h>
|
|
|
|
#include <QskStackBoxAnimator.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskTextLabel.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
#include <QElapsedTimer>
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
namespace
|
|
|
|
{
|
2019-05-17 22:33:20 +02:00
|
|
|
class StackBox : public QskStackBox
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-08-06 09:28:38 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2019-05-17 22:33:20 +02:00
|
|
|
StackBox( QQuickItem* parent = nullptr )
|
2018-08-03 08:15:28 +02:00
|
|
|
: QskStackBox( parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setObjectName( "StackBox" );
|
|
|
|
|
|
|
|
setBackgroundColor( Qt::white );
|
2019-09-05 11:45:25 +02:00
|
|
|
setDefaultAlignment( Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
addRectangle( "Gold" );
|
|
|
|
addRectangle( "SeaGreen" );
|
|
|
|
addRectangle( "SlateBlue" );
|
|
|
|
addRectangle( "Peru" );
|
|
|
|
|
|
|
|
for ( int i = 0; i < itemCount(); i += 2 )
|
|
|
|
{
|
2019-04-26 11:56:09 +02:00
|
|
|
if ( auto control = qskControlCast( itemAtIndex( i ) ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
control->setFixedSize( 200, 200 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void incrementFading( int offset )
|
|
|
|
{
|
|
|
|
auto animator = dynamic_cast< QskStackBoxAnimator3* >( this->animator() );
|
|
|
|
|
|
|
|
if ( animator == nullptr )
|
|
|
|
{
|
|
|
|
animator = new QskStackBoxAnimator3( this );
|
|
|
|
animator->setEasingCurve( QEasingCurve::InQuad );
|
|
|
|
animator->setDuration( 500 );
|
|
|
|
}
|
|
|
|
|
|
|
|
setAnimator( animator );
|
|
|
|
setCurrentIndex( incrementedIndex( offset ) );
|
2020-08-06 09:28:38 +02:00
|
|
|
|
|
|
|
Q_EMIT transitionStarted( animator->duration() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void incrementScrolling( Qt::Orientation orientation, int offset )
|
|
|
|
{
|
|
|
|
auto animator = dynamic_cast< QskStackBoxAnimator1* >( this->animator() );
|
|
|
|
|
|
|
|
if ( animator == nullptr )
|
|
|
|
{
|
|
|
|
animator = new QskStackBoxAnimator1( this );
|
|
|
|
animator->setDuration( 1000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
animator->setOrientation( orientation );
|
|
|
|
setAnimator( animator );
|
|
|
|
|
|
|
|
setCurrentIndex( incrementedIndex( offset ) );
|
2020-08-06 09:28:38 +02:00
|
|
|
|
|
|
|
Q_EMIT transitionStarted( animator->duration() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
void transitionStarted( int ms );
|
2020-12-05 15:09:31 +01:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2017-07-21 18:21:34 +02:00
|
|
|
void addRectangle( const char* colorName )
|
|
|
|
{
|
|
|
|
auto rect = new TestRectangle( colorName );
|
|
|
|
rect->setText( QString::number( itemCount() + 1 ) );
|
2019-09-05 11:45:25 +02:00
|
|
|
addItem( rect );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int incrementedIndex( int offset ) const
|
|
|
|
{
|
|
|
|
int index = currentIndex();
|
|
|
|
if ( index < 0 )
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
int newIndex = ( index + offset ) % itemCount();
|
|
|
|
if ( newIndex < 0 )
|
|
|
|
newIndex += itemCount();
|
|
|
|
|
|
|
|
return newIndex;
|
|
|
|
}
|
|
|
|
};
|
2020-08-06 09:28:38 +02:00
|
|
|
|
|
|
|
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
|
2020-12-05 15:09:31 +01:00
|
|
|
setValue( m_elapsed.elapsed() / m_duration * 100.0 );
|
2020-08-06 09:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
StackLayoutPage::StackLayoutPage( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Vertical, parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setObjectName( "StackLayoutPage" );
|
|
|
|
|
|
|
|
setMargins( 10 );
|
2020-08-15 13:29:17 +02:00
|
|
|
setBackgroundColor( QskRgb::LightSteelBlue );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
auto box = new StackBox();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
auto buttonBox = new ButtonBox();
|
2019-09-05 10:46:42 +02:00
|
|
|
|
|
|
|
buttonBox->setLayoutAlignmentHint( Qt::AlignTop | Qt::AlignLeft );
|
2017-12-14 09:41:41 +01:00
|
|
|
buttonBox->addButton( "<<", [ box ]() { box->incrementScrolling( Qt::Horizontal, +1 ); } );
|
|
|
|
buttonBox->addButton( ">>", [ box ]() { box->incrementScrolling( Qt::Horizontal, -1 ); } );
|
|
|
|
buttonBox->addButton( "^", [ box ]() { box->incrementScrolling( Qt::Vertical, -1 ); } );
|
|
|
|
buttonBox->addButton( "v", [ box ]() { box->incrementScrolling( Qt::Vertical, +1 ); } );
|
|
|
|
buttonBox->addButton( "Fading", [ box ]() { box->incrementFading( +1 ); } );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
// page indicator
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
auto pageIndicator = new QskPageIndicator();
|
|
|
|
pageIndicator->setCount( box->itemCount() );
|
|
|
|
pageIndicator->setCurrentIndex( box->currentIndex() );
|
2019-09-05 10:46:42 +02:00
|
|
|
pageIndicator->setLayoutAlignmentHint( Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-08-06 09:28:38 +02:00
|
|
|
// progress bar
|
|
|
|
auto progressBar = new ProgressBar();
|
|
|
|
progressBar->setMargins( QMarginsF( 0, 0, 10, 0 ) );
|
|
|
|
|
|
|
|
|
2019-09-05 10:46:42 +02:00
|
|
|
addItem( buttonBox );
|
|
|
|
addItem( pageIndicator );
|
2017-07-21 18:21:34 +02:00
|
|
|
addItem( box );
|
2020-08-06 09:28:38 +02:00
|
|
|
addItem( progressBar, Qt::AlignRight );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
connect( box, &QskStackBox::currentIndexChanged,
|
|
|
|
pageIndicator, &QskPageIndicator::setCurrentIndex );
|
2020-08-06 09:28:38 +02:00
|
|
|
|
|
|
|
connect( box, &StackBox::transitionStarted,
|
|
|
|
progressBar, &ProgressBar::startProgressing );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
2020-08-06 09:28:38 +02:00
|
|
|
|
|
|
|
#include "StackLayoutPage.moc"
|