QskSpinBox bugs fixed, QskSpinBox::wrapping mode implemented

This commit is contained in:
Uwe Rathmann 2023-03-01 13:58:10 +01:00
parent 28432446e6
commit 55d6aa6d5e
3 changed files with 32 additions and 4 deletions

View File

@ -64,6 +64,7 @@ namespace
{ {
auto spinBox = new QskSpinBox( this ); auto spinBox = new QskSpinBox( this );
spinBox->setPageSize( 10 );
spinBox->setDecoration( QskSpinBox::NoDecoration ); spinBox->setDecoration( QskSpinBox::NoDecoration );
spinBox->setValue( 50 ); spinBox->setValue( 50 );
} }

View File

@ -5,6 +5,7 @@
#include "QskSpinBox.h" #include "QskSpinBox.h"
#include "QskEvent.h" #include "QskEvent.h"
#include "QskFunctions.h"
#include <qbasictimer.h> #include <qbasictimer.h>
#include <qlocale.h> #include <qlocale.h>
@ -244,6 +245,28 @@ QString QskSpinBox::textFromValue( qreal value ) const
return locale().toString( value, 'f', m_data->decimals ); return locale().toString( value, 'f', m_data->decimals );
} }
void QskSpinBox::increment( qreal offset )
{
if ( m_data->wrapping )
{
const auto v = value();
if ( offset > 0.0 && qskFuzzyCompare( v, maximum() ) )
{
setValue( minimum() );
return;
}
if ( offset < 0.0 && qskFuzzyCompare( v, minimum() ) )
{
setValue( maximum() );
return;
}
}
Inherited::increment( offset );
}
void QskSpinBox::mousePressEvent( QMouseEvent* event ) void QskSpinBox::mousePressEvent( QMouseEvent* event )
{ {
if ( !isReadOnly() ) if ( !isReadOnly() )
@ -252,13 +275,15 @@ void QskSpinBox::mousePressEvent( QMouseEvent* event )
{ {
if ( !m_data->repeatTimer.isActive() ) if ( !m_data->repeatTimer.isActive() )
{ {
auto increment = ( event->modifiers() == Qt::ControlModifier ) auto offset = stepSize();
? stepSize() : pageSize(); if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
offset *= pageSize();
if ( subcontrol == QskSpinBox::DownPanel ) if ( subcontrol == QskSpinBox::DownPanel )
increment = -increment; offset = -offset;
m_data->setAutoRepeat( this, increment ); increment( offset );
m_data->setAutoRepeat( this, offset );
} }
return; return;
} }

View File

@ -78,6 +78,8 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
QString text() const; QString text() const;
virtual QString textFromValue( qreal ) const; virtual QString textFromValue( qreal ) const;
void increment( qreal ) override;
Q_SIGNALS: Q_SIGNALS:
void decorationChanged( Decoration ); void decorationChanged( Decoration );
void textAlignmentChanged( Qt::Alignment ); void textAlignmentChanged( Qt::Alignment );