6#include "QskPageIndicator.h"
15static
int qskKeyIncrement(
18 if ( qskIsStandardKeyInput( event, QKeySequence::MoveToNextChar ) )
21 if ( qskIsStandardKeyInput( event, QKeySequence::MoveToPreviousChar ) )
24 const auto key =
event->key();
26 if ( indicator->orientation() == Qt::Horizontal )
28 const bool mirrored = indicator->layoutMirroring();
30 if ( key == Qt::Key_Left )
31 return mirrored ? 1 : -1;
33 if ( key == Qt::Key_Right )
34 return mirrored ? -1 : 1;
38 if ( key == Qt::Key_Up )
41 if ( key == Qt::Key_Down )
49class QskPageIndicator::PrivateData
52 PrivateData(
int count )
54 , orientation( Qt::Horizontal )
58 qreal currentIndex = -1;
59 int pressedIndex = -1;
62 Qt::Orientation orientation : 2;
65QskPageIndicator::QskPageIndicator(
int count, QQuickItem* parent )
67 , m_data( new PrivateData( count ) )
70 initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
73QskPageIndicator::QskPageIndicator( QQuickItem* parent )
78QskPageIndicator::~QskPageIndicator()
82int QskPageIndicator::count()
const
87qreal QskPageIndicator::currentIndex()
const
89 return m_data->currentIndex;
92Qt::Orientation QskPageIndicator::orientation()
const
94 return m_data->orientation;
97void QskPageIndicator::setOrientation( Qt::Orientation orientation )
99 if ( orientation != m_data->orientation )
101 m_data->orientation = orientation;
106 Q_EMIT orientationChanged( orientation );
110void QskPageIndicator::setCount(
int count )
112 if ( count != m_data->count )
114 m_data->count = count;
119 Q_EMIT countChanged( count );
123void QskPageIndicator::setCurrentIndex( qreal index )
125 if ( index < 0 || index >= m_data->count )
128 if ( index != m_data->currentIndex )
130 m_data->currentIndex = index;
133 Q_EMIT currentIndexChanged( index );
137qreal QskPageIndicator::valueRatioAt(
int index )
const
139 if ( m_data->currentIndex >= 0.0 && index >= 0 )
141 qreal pos = m_data->currentIndex;
143 if ( index == 0 && pos > m_data->count - 1 )
144 pos -= m_data->count;
146 const qreal diff = 1.0 - std::abs( pos - index );
147 return std::max( diff, 0.0 );
153QRectF QskPageIndicator::bulletRect(
int index )
const
156 this,
contentsRect(), QskPageIndicator::Bullet, index );
159int QskPageIndicator::indexAtPosition(
const QPointF& pos )
const
170void QskPageIndicator::mousePressEvent( QMouseEvent* event )
172 if ( event->button() == Qt::LeftButton )
181 const auto pos = qskMousePosition( event );
182 m_data->pressedIndex = indexAtPosition( pos );
187 Inherited::mousePressEvent( event );
190void QskPageIndicator::mouseUngrabEvent()
192 m_data->pressedIndex = -1;
195void QskPageIndicator::mouseReleaseEvent( QMouseEvent* event )
197 if ( event->button() == Qt::LeftButton )
199 const auto index = m_data->pressedIndex;
200 m_data->pressedIndex = -1;
204 const auto pos = qskMousePosition( event );
205 if ( indexAtPosition( pos ) == index )
206 Q_EMIT pageRequested( index );
212 Inherited::mouseReleaseEvent( event );
215void QskPageIndicator::keyPressEvent( QKeyEvent* event )
217 if (
const int increment = qskKeyIncrement(
this, event ) )
219 incrementRequested( increment );
223 Inherited::keyPressEvent( event );
226#ifndef QT_NO_WHEELEVENT
228void QskPageIndicator::wheelEvent( QWheelEvent* event )
230 incrementRequested( qskWheelSteps( event ) );
235void QskPageIndicator::incrementRequested(
int offset )
237 const auto n = m_data->count;
239 if ( offset == 0 || n == 0 )
242 int index = m_data->currentIndex;
243 if ( index < 0 && offset < 0 )
248 index = ( index + offset ) % n;
252 if ( index != m_data->currentIndex )
253 Q_EMIT pageRequested( index );
256#include "moc_QskPageIndicator.cpp"
Variation
Some sort of variation.
QRectF contentsRect() const
QskAspect::Variation effectiveVariation() const override
const QskSkinlet * effectiveSkinlet() const