QskSwipeView improvements
This commit is contained in:
parent
6db7024cb4
commit
bf2c2b981e
@ -23,6 +23,7 @@ class SwipeView : public QskSwipeView
|
|||||||
|
|
||||||
setBackgroundColor( Qt::white );
|
setBackgroundColor( Qt::white );
|
||||||
setDefaultAlignment( Qt::AlignCenter );
|
setDefaultAlignment( Qt::AlignCenter );
|
||||||
|
setOrientation( Qt::Horizontal );
|
||||||
|
|
||||||
addRectangle( "Gold" );
|
addRectangle( "Gold" );
|
||||||
addRectangle( "SeaGreen" );
|
addRectangle( "SeaGreen" );
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "QskGesture.h"
|
#include "QskGesture.h"
|
||||||
#include "QskPanGestureRecognizer.h"
|
#include "QskPanGestureRecognizer.h"
|
||||||
#include "QskStackBoxAnimator.h"
|
#include "QskStackBoxAnimator.h"
|
||||||
|
#include "QskPlatform.h"
|
||||||
|
|
||||||
class QskSwipeView::PrivateData
|
class QskSwipeView::PrivateData
|
||||||
{
|
{
|
||||||
@ -30,11 +31,11 @@ QskSwipeView::QskSwipeView( QQuickItem* parent )
|
|||||||
|
|
||||||
recognizer.setWatchedItem( this );
|
recognizer.setWatchedItem( this );
|
||||||
|
|
||||||
// should be skin hints
|
// should be skin hints, TODO
|
||||||
recognizer.setOrientations( Qt::Horizontal );
|
recognizer.setOrientations( Qt::Horizontal );
|
||||||
recognizer.setMinDistance( 50 );
|
|
||||||
recognizer.setTimeout( 100 );
|
recognizer.setTimeout( 100 );
|
||||||
|
|
||||||
|
resetSwipeDistance();
|
||||||
resetDuration();
|
resetDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,13 +43,38 @@ QskSwipeView::~QskSwipeView()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QskAspect::Subcontrol QskSwipeView::effectiveSubcontrol(
|
void QskSwipeView::setOrientation( Qt::Orientation orientation )
|
||||||
QskAspect::Subcontrol subControl ) const
|
|
||||||
{
|
{
|
||||||
if ( subControl == QskBox::Panel )
|
if ( orientation != this->orientation() )
|
||||||
return QskSwipeView::Panel;
|
{
|
||||||
|
m_data->panRecognizer.setOrientations( orientation );
|
||||||
|
Q_EMIT orientationChanged( orientation );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Inherited::effectiveSubcontrol( subControl );
|
Qt::Orientation QskSwipeView::orientation() const
|
||||||
|
{
|
||||||
|
return ( m_data->panRecognizer.orientations() == Qt::Vertical )
|
||||||
|
? Qt::Vertical : Qt::Horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
int QskSwipeView::swipeDistance() const
|
||||||
|
{
|
||||||
|
return m_data->panRecognizer.minDistance();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskSwipeView::setSwipeDistance( int distance )
|
||||||
|
{
|
||||||
|
const auto oldDistance = m_data->panRecognizer.minDistance();
|
||||||
|
m_data->panRecognizer.setMinDistance( distance );
|
||||||
|
|
||||||
|
if ( oldDistance != m_data->panRecognizer.minDistance() )
|
||||||
|
Q_EMIT swipeDistanceChanged( m_data->panRecognizer.minDistance() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskSwipeView::resetSwipeDistance()
|
||||||
|
{
|
||||||
|
setSwipeDistance( qRound( qskDpToPixels( 40 ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskSwipeView::duration() const
|
int QskSwipeView::duration() const
|
||||||
@ -57,13 +83,17 @@ int QskSwipeView::duration() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QskSwipeView::setDuration( int duration )
|
void QskSwipeView::setDuration( int duration )
|
||||||
|
{
|
||||||
|
if ( duration != m_data->duration )
|
||||||
{
|
{
|
||||||
m_data->duration = duration;
|
m_data->duration = duration;
|
||||||
|
Q_EMIT durationChanged( duration );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSwipeView::resetDuration()
|
void QskSwipeView::resetDuration()
|
||||||
{
|
{
|
||||||
m_data->duration = 500;
|
setDuration( 500 );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QskSwipeView::gestureFilter( const QQuickItem* item, const QEvent* event )
|
bool QskSwipeView::gestureFilter( const QQuickItem* item, const QEvent* event )
|
||||||
@ -94,16 +124,20 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
|||||||
if ( animator == nullptr )
|
if ( animator == nullptr )
|
||||||
{
|
{
|
||||||
animator = new QskStackBoxAnimator1( this );
|
animator = new QskStackBoxAnimator1( this );
|
||||||
animator->setOrientation( Qt::Horizontal );
|
animator->setOrientation( orientation() );
|
||||||
}
|
}
|
||||||
|
|
||||||
animator->setDuration( m_data->duration );
|
animator->setDuration( m_data->duration );
|
||||||
QskStackBox::setAnimator( animator );
|
QskStackBox::setAnimator( animator );
|
||||||
|
|
||||||
const auto direction = ( ( gesture->angle() < 90.0 ) || ( gesture->angle() > 270.0 ) )
|
bool forwards;
|
||||||
? Qsk::LeftToRight : Qsk::RightToLeft;
|
|
||||||
|
|
||||||
auto newIndex = ( direction == Qsk::LeftToRight ) ? currentIndex() - 1 : currentIndex() + 1;
|
if ( orientation() == Qt::Horizontal )
|
||||||
|
forwards = gesture->angle() >= 90.0 && gesture->angle() <= 270.0;
|
||||||
|
else
|
||||||
|
forwards = gesture->angle() >= 180.0;
|
||||||
|
|
||||||
|
auto newIndex = forwards ? currentIndex() + 1 : currentIndex() - 1;
|
||||||
|
|
||||||
if( newIndex < 0 )
|
if( newIndex < 0 )
|
||||||
newIndex += itemCount();
|
newIndex += itemCount();
|
||||||
@ -117,4 +151,14 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
|||||||
Inherited::gestureEvent( event );
|
Inherited::gestureEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QskAspect::Subcontrol QskSwipeView::effectiveSubcontrol(
|
||||||
|
QskAspect::Subcontrol subControl ) const
|
||||||
|
{
|
||||||
|
if ( subControl == QskBox::Panel )
|
||||||
|
return QskSwipeView::Panel;
|
||||||
|
|
||||||
|
return Inherited::effectiveSubcontrol( subControl );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "moc_QskSwipeView.cpp"
|
#include "moc_QskSwipeView.cpp"
|
||||||
|
@ -12,7 +12,14 @@ class QSK_EXPORT QskSwipeView : public QskStackBox
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY( int duration READ duration WRITE setDuration RESET resetDuration )
|
Q_PROPERTY( int duration READ duration
|
||||||
|
WRITE setDuration RESET resetDuration NOTIFY durationChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( int swipeDistance READ swipeDistance
|
||||||
|
WRITE setSwipeDistance RESET resetSwipeDistance NOTIFY swipeDistanceChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( Qt::Orientation orientation READ orientation
|
||||||
|
WRITE setOrientation NOTIFY orientationChanged )
|
||||||
|
|
||||||
using Inherited = QskStackBox;
|
using Inherited = QskStackBox;
|
||||||
|
|
||||||
@ -22,12 +29,33 @@ class QSK_EXPORT QskSwipeView : public QskStackBox
|
|||||||
QskSwipeView( QQuickItem* parent = nullptr );
|
QskSwipeView( QQuickItem* parent = nullptr );
|
||||||
~QskSwipeView() override;
|
~QskSwipeView() override;
|
||||||
|
|
||||||
|
void setOrientation( Qt::Orientation );
|
||||||
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
|
// Duration is the time ( in ms ) used for changing between pages
|
||||||
|
|
||||||
int duration() const;
|
int duration() const;
|
||||||
void setDuration( int );
|
void setDuration( int );
|
||||||
void resetDuration();
|
void resetDuration();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Even if called "swipe view" we use a pan - no swipe - gesture.
|
||||||
|
( = pages are moved before the gesture has been confirmed )
|
||||||
|
|
||||||
|
The swipe distance is the minimum distance in pixels of the pan gesture
|
||||||
|
*/
|
||||||
|
|
||||||
|
int swipeDistance() const;
|
||||||
|
void setSwipeDistance( int );
|
||||||
|
void resetSwipeDistance();
|
||||||
|
|
||||||
QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol ) const;
|
QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol ) const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void orientationChanged( Qt::Orientation );
|
||||||
|
void durationChanged( int );
|
||||||
|
void swipeDistanceChanged( int );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool gestureFilter( const QQuickItem*, const QEvent* ) override;
|
bool gestureFilter( const QQuickItem*, const QEvent* ) override;
|
||||||
void gestureEvent( QskGestureEvent* ) override;
|
void gestureEvent( QskGestureEvent* ) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user