6#include "QskBoundedInput.h"
7#include "QskFunctions.h"
8#include "QskIntervalF.h"
21 bool snapping =
false;
24QskBoundedInput::QskBoundedInput( QQuickItem* parent )
26 , m_data( new PrivateData )
28 setFocusPolicy( Qt::StrongFocus );
29 setAcceptedMouseButtons( Qt::LeftButton );
30 setWheelEnabled(
true );
32 if ( isComponentComplete() )
34 connect(
this, &QskBoundedControl::boundariesChanged,
35 this, &QskBoundedInput::alignInput );
39QskBoundedInput::~QskBoundedInput()
43void QskBoundedInput::setStepSize( qreal stepSize )
45 if ( qFuzzyIsNull( stepSize ) )
48 if ( qFuzzyCompare( m_data->stepSize, stepSize ) )
51 m_data->stepSize = stepSize;
52 Q_EMIT stepSizeChanged( stepSize );
54 if ( isComponentComplete() )
56 if ( m_data->snapping && stepSize )
61qreal QskBoundedInput::stepSize()
const
63 return m_data->stepSize;
66void QskBoundedInput::setPageSteps( uint pageSteps )
68 if ( m_data->pageSteps == pageSteps )
71 m_data->pageSteps = pageSteps;
72 Q_EMIT pageStepsChanged( pageSteps );
75uint QskBoundedInput::pageSteps()
const
77 return m_data->pageSteps;
80qreal QskBoundedInput::pageSize()
const
82 return m_data->pageSteps * m_data->stepSize;
85void QskBoundedInput::stepUp()
87 increment( m_data->stepSize );
90void QskBoundedInput::stepDown()
92 increment( -m_data->stepSize );
95void QskBoundedInput::pageUp()
97 increment( pageSize() );
100void QskBoundedInput::pageDown()
102 increment( -pageSize() );
105void QskBoundedInput::setSnapping(
bool on )
107 if ( m_data->snapping == on )
110 m_data->snapping = on;
111 Q_EMIT snappingChanged( on );
113 if ( isComponentComplete() && m_data->snapping )
117bool QskBoundedInput::isSnapping()
const
119 return m_data->snapping;
122void QskBoundedInput::componentComplete()
124 if ( isComponentComplete() )
126 connect(
this, &QskBoundedControl::boundariesChanged,
127 this, &QskBoundedInput::alignInput, Qt::UniqueConnection );
130 Inherited::componentComplete();
133void QskBoundedInput::alignInput()
137void QskBoundedInput::setReadOnly(
bool readOnly )
139 if ( readOnly == isReadOnly() )
145 setFocusPolicy( readOnly ? Qt::NoFocus : Qt::StrongFocus );
146 setAcceptedMouseButtons( readOnly ? Qt::NoButton : Qt::LeftButton );
147 setWheelEnabled( !readOnly );
149 Q_EMIT readOnlyChanged( readOnly );
151 QEvent event( QEvent::ReadOnlyChange );
152 QCoreApplication::sendEvent(
this, &event );
155bool QskBoundedInput::isReadOnly()
const
157 return hasSkinState( ReadOnly );
160qreal QskBoundedInput::incrementForKey(
const QKeyEvent* event )
const
162 switch( event->key() )
165 return m_data->stepSize;
168 return -m_data->stepSize;
173 case Qt::Key_PageDown:
180void QskBoundedInput::keyPressEvent( QKeyEvent* event )
184 if (
const auto offset = incrementForKey( event ) )
191 Inherited::keyPressEvent( event );
194#ifndef QT_NO_WHEELEVENT
196void QskBoundedInput::wheelEvent( QWheelEvent* event )
200 Inherited::wheelEvent( event );
204 auto offset = qskWheelIncrement( event ) * m_data->stepSize;
205 if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
206 offset *= m_data->pageSteps;
213#include "moc_QskBoundedInput.cpp"
void setSkinStateFlag(QskAspect::State, bool on=true)