6#include "QskSwipeView.h"
10#include "QskPanGestureRecognizer.h"
11#include "QskStackBoxAnimator.h"
12#include "QskPlatform.h"
14class QskSwipeView::PrivateData
23QskSwipeView::QskSwipeView( QQuickItem* parent )
25 , m_data( new PrivateData() )
27 setFiltersChildMouseEvents(
true );
28 setAcceptedMouseButtons( Qt::LeftButton );
30 auto& recognizer = m_data->panRecognizer;
32 recognizer.setWatchedItem(
this );
35 recognizer.setOrientations( Qt::Horizontal );
36 recognizer.setTimeout( 100 );
42QskSwipeView::~QskSwipeView()
46void QskSwipeView::setOrientation( Qt::Orientation orientation )
48 if ( orientation != this->orientation() )
50 m_data->panRecognizer.setOrientations( orientation );
51 Q_EMIT orientationChanged( orientation );
55Qt::Orientation QskSwipeView::orientation()
const
57 return ( m_data->panRecognizer.orientations() == Qt::Vertical )
58 ? Qt::Vertical : Qt::Horizontal;
61int QskSwipeView::swipeDistance()
const
63 return m_data->panRecognizer.minDistance();
66void QskSwipeView::setSwipeDistance(
int distance )
68 const auto oldDistance = m_data->panRecognizer.minDistance();
69 m_data->panRecognizer.setMinDistance( distance );
71 if ( oldDistance != m_data->panRecognizer.minDistance() )
72 Q_EMIT swipeDistanceChanged( m_data->panRecognizer.minDistance() );
75void QskSwipeView::resetSwipeDistance()
77 setSwipeDistance( qRound( qskMMToPixels( window(), 8 ) ) );
80int QskSwipeView::duration()
const
82 return m_data->duration;
85void QskSwipeView::setDuration(
int duration )
87 if ( duration != m_data->duration )
89 m_data->duration = duration;
90 Q_EMIT durationChanged( duration );
94void QskSwipeView::resetDuration()
101 const auto gesture =
static_cast< const QskPanGesture*
>(
event->gesture().get() );
103 if( gesture->type() == QskGesture::Pan && gesture->state() == QskGesture::Started )
105 if ( itemCount() <= 1 )
110 if ( orientation() == Qt::Horizontal )
111 forwards = gesture->angle() >= 90.0 && gesture->angle() <= 270.0;
113 forwards = gesture->angle() >= 180.0;
115 auto animator = qobject_cast< QskStackBoxAnimator1* >( this->animator() );
117 if ( animator ==
nullptr )
120 if ( orientation() == Qt::Horizontal )
125 animator->setDuration( m_data->duration );
126 QskStackBox::setAnimator( animator );
128 auto newIndex = forwards ? currentIndex() + 1 : currentIndex() - 1;
130 newIndex += itemCount();
132 newIndex %= itemCount();
134 setCurrentIndex( newIndex );
138 Inherited::gestureEvent( event );
144 if ( subControl == QskBox::Panel )
145 return QskSwipeView::Panel;
151#include "moc_QskSwipeView.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QskAspect::Subcontrol effectiveSubcontrol(QskAspect::Subcontrol) const