basic adjustments
This commit is contained in:
parent
2514005120
commit
b6b9cf0039
|
@ -14,8 +14,7 @@ class QskSwipeView::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QskPanGestureRecognizer panRecognizer;
|
QskPanGestureRecognizer panRecognizer;
|
||||||
int panRecognizerTimeout = 100;
|
int duration = -1; // should be a skinHint
|
||||||
int duration = 500;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskSwipeView, Panel )
|
QSK_SUBCONTROL( QskSwipeView, Panel )
|
||||||
|
@ -24,21 +23,33 @@ QskSwipeView::QskSwipeView( QQuickItem* parent )
|
||||||
: Inherited( parent )
|
: Inherited( parent )
|
||||||
, m_data( new PrivateData() )
|
, m_data( new PrivateData() )
|
||||||
{
|
{
|
||||||
setSubcontrolProxy( QskBox::Panel, Panel );
|
|
||||||
|
|
||||||
setFiltersChildMouseEvents( true );
|
setFiltersChildMouseEvents( true );
|
||||||
|
|
||||||
setAcceptedMouseButtons( Qt::LeftButton );
|
setAcceptedMouseButtons( Qt::LeftButton );
|
||||||
|
|
||||||
m_data->panRecognizer.setWatchedItem( this );
|
auto& recognizer = m_data->panRecognizer;
|
||||||
m_data->panRecognizer.setOrientations( Qt::Horizontal );
|
|
||||||
m_data->panRecognizer.setMinDistance( 50 );
|
recognizer.setWatchedItem( this );
|
||||||
|
|
||||||
|
// should be skin hints
|
||||||
|
recognizer.setOrientations( Qt::Horizontal );
|
||||||
|
recognizer.setMinDistance( 50 );
|
||||||
|
recognizer.setTimeout( 100 );
|
||||||
|
|
||||||
|
resetDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
QskSwipeView::~QskSwipeView()
|
QskSwipeView::~QskSwipeView()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QskAspect::Subcontrol QskSwipeView::effectiveSubcontrol(
|
||||||
|
QskAspect::Subcontrol subControl ) const
|
||||||
|
{
|
||||||
|
if ( subControl == QskBox::Panel )
|
||||||
|
return QskSwipeView::Panel;
|
||||||
|
|
||||||
|
return Inherited::effectiveSubcontrol( subControl );
|
||||||
|
}
|
||||||
|
|
||||||
int QskSwipeView::duration() const
|
int QskSwipeView::duration() const
|
||||||
{
|
{
|
||||||
|
@ -50,8 +61,12 @@ void QskSwipeView::setDuration( int duration )
|
||||||
m_data->duration = duration;
|
m_data->duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskSwipeView::resetDuration()
|
||||||
|
{
|
||||||
|
m_data->duration = 500;
|
||||||
|
}
|
||||||
|
|
||||||
bool QskSwipeView::gestureFilter( QQuickItem* item, QEvent* event )
|
bool QskSwipeView::gestureFilter( const QQuickItem* item, const QEvent* event )
|
||||||
{
|
{
|
||||||
// see QskScrollBox.cpp
|
// see QskScrollBox.cpp
|
||||||
|
|
||||||
|
@ -59,26 +74,21 @@ bool QskSwipeView::gestureFilter( QQuickItem* item, QEvent* event )
|
||||||
|
|
||||||
if ( event->type() == QEvent::MouseButtonPress )
|
if ( event->type() == QEvent::MouseButtonPress )
|
||||||
{
|
{
|
||||||
if ( ( item != this ) && ( recognizer.timeout() < 0 ) )
|
auto mouseEvent = static_cast< const QMouseEvent* >( event );
|
||||||
{
|
|
||||||
const auto mouseEvent = static_cast< QMouseEvent* >( event );
|
|
||||||
|
|
||||||
if ( recognizer.hasProcessedBefore( mouseEvent ) )
|
if ( recognizer.hasProcessedBefore( mouseEvent ) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
recognizer.setTimeout( ( item == this ) ? -1 : m_data->panRecognizerTimeout );
|
return recognizer.processEvent( item, event );
|
||||||
}
|
|
||||||
|
|
||||||
return m_data->panRecognizer.processEvent( item, event );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
||||||
{
|
|
||||||
if( event->gesture()->type() == QskGesture::Pan && event->gesture()->state() == QskGesture::Started )
|
|
||||||
{
|
{
|
||||||
const auto gesture = static_cast< const QskPanGesture* >( event->gesture().get() );
|
const auto gesture = static_cast< const QskPanGesture* >( event->gesture().get() );
|
||||||
|
|
||||||
|
if( gesture->type() == QskGesture::Pan && gesture->state() == QskGesture::Started )
|
||||||
|
{
|
||||||
auto animator = dynamic_cast< QskStackBoxAnimator1* >( this->animator() );
|
auto animator = dynamic_cast< QskStackBoxAnimator1* >( this->animator() );
|
||||||
|
|
||||||
if ( animator == nullptr )
|
if ( animator == nullptr )
|
||||||
|
@ -88,7 +98,7 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
||||||
}
|
}
|
||||||
|
|
||||||
animator->setDuration( m_data->duration );
|
animator->setDuration( m_data->duration );
|
||||||
setAnimator( animator );
|
QskStackBox::setAnimator( animator );
|
||||||
|
|
||||||
const auto direction = ( ( gesture->angle() < 90.0 ) || ( gesture->angle() > 270.0 ) )
|
const auto direction = ( ( gesture->angle() < 90.0 ) || ( gesture->angle() > 270.0 ) )
|
||||||
? Qsk::LeftToRight : Qsk::RightToLeft;
|
? Qsk::LeftToRight : Qsk::RightToLeft;
|
||||||
|
@ -101,12 +111,10 @@ void QskSwipeView::gestureEvent( QskGestureEvent* event )
|
||||||
newIndex %= itemCount();
|
newIndex %= itemCount();
|
||||||
|
|
||||||
setCurrentIndex( newIndex );
|
setCurrentIndex( newIndex );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Inherited::gestureEvent( event );
|
Inherited::gestureEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_QskSwipeView.cpp"
|
#include "moc_QskSwipeView.cpp"
|
||||||
|
|
|
@ -8,14 +8,13 @@
|
||||||
|
|
||||||
#include "QskStackBox.h"
|
#include "QskStackBox.h"
|
||||||
|
|
||||||
class QskTabBar;
|
|
||||||
class QskTabButton;
|
|
||||||
|
|
||||||
class QSK_EXPORT QskSwipeView : public QskStackBox
|
class QSK_EXPORT QskSwipeView : public QskStackBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
typedef QskStackBox Inherited;
|
Q_PROPERTY( int duration READ duration WRITE setDuration RESET resetDuration )
|
||||||
|
|
||||||
|
using Inherited = QskStackBox;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Panel )
|
QSK_SUBCONTROLS( Panel )
|
||||||
|
@ -25,12 +24,17 @@ class QSK_EXPORT QskSwipeView : public QskStackBox
|
||||||
|
|
||||||
int duration() const;
|
int duration() const;
|
||||||
void setDuration( int );
|
void setDuration( int );
|
||||||
|
void resetDuration();
|
||||||
|
|
||||||
|
QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol ) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool gestureFilter( QQuickItem*, QEvent* ) override final;
|
bool gestureFilter( const QQuickItem*, const QEvent* ) override;
|
||||||
void gestureEvent( QskGestureEvent* ) override final;
|
void gestureEvent( QskGestureEvent* ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setAnimator( QskStackBoxAnimator* ) = delete;
|
||||||
|
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
std::unique_ptr< PrivateData > m_data;
|
std::unique_ptr< PrivateData > m_data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue