8#include "QskFunctions.h"
10#include <qbasictimer.h>
30 if ( spinBox->
subControlRect( QskSpinBox::UpPanel ).contains( pos ) )
31 return QskSpinBox::UpPanel;
33 if ( spinBox->
subControlRect( QskSpinBox::DownPanel ).contains( pos ) )
34 return QskSpinBox::DownPanel;
36 return QskAspect::NoSubcontrol;
45class QskSpinBox::PrivateData
53 inline bool isActivatedByMouse()
const
55 return this->repeatTimer.isActive() && ( this->key == Qt::Key_unknown );
58 inline bool isTimerBlocked(
QskSpinBox* spinBox, qreal offset )
const
60 if ( !this->wrapping )
63 return spinBox->value() >= spinBox->maximum();
65 return spinBox->value() <= spinBox->minimum();
71 inline void setAutoRepeat(
QskSpinBox* spinBox, qreal offset )
73 this->autoRepeatIncrement = offset;
74 this->key = Qt::Key_unknown;
78 if ( spinBox->hasSkinState( QskSpinBox::Increasing ) )
81 if ( !spinBox->hasSkinState( QskSpinBox::Decreasing ) )
84 this->repeatTimer.start( autoRepeatDelay, spinBox );
92 if ( spinBox->hasSkinState( QskSpinBox::Decreasing ) )
95 if ( !spinBox->hasSkinState( QskSpinBox::Increasing ) )
98 this->repeatTimer.start( autoRepeatDelay, spinBox );
107 this->repeatTimer.stop();
110 int autoRepeatDelay = 300;
111 int autoRepeatInterval = 100;
113 qreal autoRepeatIncrement = 0.0;
115 QBasicTimer repeatTimer;
117 int key = Qt::Key_unknown;
124 bool accelerating : 1;
129 : Inherited( parent )
130 , m_data( new PrivateData )
132 initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
134 setBoundaries( min, max );
135 setStepSize( stepSize );
137 setAcceptHoverEvents(
true );
139 setAcceptedMouseButtons( Qt::LeftButton );
140 setFocusPolicy( Qt::StrongFocus );
148QskSpinBox::~QskSpinBox()
152void QskSpinBox::setDecoration( Decoration decoration )
154 if (
setFlagHint( aspectDecoration(), decoration ) )
155 Q_EMIT decorationChanged( decoration );
158void QskSpinBox::resetDecoration()
161 Q_EMIT decorationChanged( decoration() );
164QskSpinBox::Decoration QskSpinBox::decoration()
const
166 return flagHint< QskSpinBox::Decoration >( aspectDecoration(), ButtonsLeftAndRight );
169void QskSpinBox::setWrapping(
bool on )
171 if ( on != m_data->wrapping )
173 m_data->wrapping = on;
174 Q_EMIT wrappingChanged( on );
178bool QskSpinBox::isWrapping()
const
180 return m_data->wrapping;
183void QskSpinBox::increment( qreal offset )
185 if ( m_data->wrapping )
187 const auto v = value();
189 if ( offset > 0.0 && qskFuzzyCompare( v, maximum() ) )
191 setValue( minimum() );
195 if ( offset < 0.0 && qskFuzzyCompare( v, minimum() ) )
197 setValue( maximum() );
202 Inherited::increment( offset );
205void QskSpinBox::mousePressEvent( QMouseEvent* event )
209 if (
auto subcontrol = buttonAt(
this, qskMousePosition( event ) ) )
211 bool acceptPress = !m_data->repeatTimer.isActive();
213 if ( acceptPress && !m_data->wrapping )
215 if ( subcontrol == QskSpinBox::DownPanel )
216 acceptPress = value() > minimum();
218 acceptPress = value() < maximum();
223 auto offset = stepSize();
224 if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
225 offset *= pageSteps();
227 if ( subcontrol == QskSpinBox::DownPanel )
232 if ( !m_data->isTimerBlocked(
this, offset ) )
233 m_data->setAutoRepeat(
this, offset );
239 Inherited::mousePressEvent( event );
242void QskSpinBox::mouseReleaseEvent( QMouseEvent* )
244 if ( m_data->isActivatedByMouse() )
245 m_data->setAutoRepeat(
this, 0.0 );
248void QskSpinBox::mouseMoveEvent( QMouseEvent* event )
250 if ( m_data->isActivatedByMouse() )
252 const auto subcontrol = buttonAt(
this, qskMousePosition( event ) );
254 if ( m_data->autoRepeatIncrement >= 0.0 )
256 if ( subcontrol != QskSpinBox::UpPanel )
257 m_data->setAutoRepeat(
this, 0.0 );
261 if ( subcontrol != QskSpinBox::DownPanel )
262 m_data->setAutoRepeat(
this, 0.0 );
267void QskSpinBox::mouseUngrabEvent()
269 if ( m_data->isActivatedByMouse() )
270 m_data->setAutoRepeat(
this, 0.0 );
273void QskSpinBox::hoverMoveEvent( QHoverEvent* event )
275 Inherited::hoverMoveEvent( event );
279void QskSpinBox::keyPressEvent( QKeyEvent* event )
281 if ( !isReadOnly() && !m_data->repeatTimer.isActive() )
283 const auto offset = incrementForKey( event );
286 if ( !m_data->repeatTimer.isActive() )
290 if ( !m_data->isTimerBlocked(
this, offset ) )
292 m_data->setAutoRepeat(
this, offset );
293 m_data->key =
event->key();
300 Inherited::keyPressEvent( event );
303void QskSpinBox::keyReleaseEvent( QKeyEvent* event )
305 if ( m_data->key == event->key() )
307 m_data->setAutoRepeat(
this, 0.0 );
311 Inherited::keyReleaseEvent( event );
314void QskSpinBox::timerEvent( QTimerEvent* event )
316 if ( event->timerId() == m_data->repeatTimer.timerId() )
318 if ( skinStates() & ( QskSpinBox::Increasing | QskSpinBox::Decreasing ) )
320 increment( m_data->autoRepeatIncrement );
322 if ( m_data->isTimerBlocked(
this, m_data->autoRepeatIncrement ) )
323 m_data->setAutoRepeat(
this, 0.0 );
325 m_data->repeatTimer.start( m_data->autoRepeatInterval,
this );
331 Inherited::timerEvent( event );
334#include "moc_QskSpinBox.cpp"
Lookup key for a QskSkinHintTable.
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
bool resetSkinHint(QskAspect)
Remove a hint from the local hint table.
void setSkinStateFlag(QskAspect::State, bool on=true)
bool setFlagHint(QskAspect, int flag)
Sets a flag hint.
A control to edit, increment and decrement number values.
QskSpinBox(QQuickItem *parent=nullptr)