QskSpinBox API improved
This commit is contained in:
parent
06ba85605b
commit
a3e749157f
@ -7,6 +7,9 @@
|
||||
#include "QskEvent.h"
|
||||
|
||||
#include <qbasictimer.h>
|
||||
#include <qlocale.h>
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
QSK_SUBCONTROL( QskSpinBox, Panel )
|
||||
|
||||
@ -86,6 +89,8 @@ class QskSpinBox::PrivateData
|
||||
this->repeatTimer.stop();
|
||||
}
|
||||
|
||||
int decimals = 2;
|
||||
|
||||
int autoRepeatDelay = 300;
|
||||
int autoRepeatInterval = 100;
|
||||
|
||||
@ -111,6 +116,8 @@ QskSpinBox::QskSpinBox( QQuickItem* parent )
|
||||
|
||||
setAcceptedMouseButtons( Qt::LeftButton );
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
|
||||
connect( this, &QskSpinBox::valueChanged, this, &QskSpinBox::textChanged );
|
||||
}
|
||||
|
||||
QskSpinBox::~QskSpinBox()
|
||||
@ -173,6 +180,33 @@ bool QskSpinBox::isAccelerating() const
|
||||
return m_data->accelerating;
|
||||
}
|
||||
|
||||
void QskSpinBox::setDecimals( int decimals )
|
||||
{
|
||||
decimals = qBound( 0, decimals, DBL_MAX_10_EXP + DBL_DIG );
|
||||
if ( decimals != m_data->decimals )
|
||||
{
|
||||
m_data->decimals = decimals;
|
||||
|
||||
update();
|
||||
resetImplicitSize();
|
||||
}
|
||||
}
|
||||
|
||||
int QskSpinBox::decimals() const
|
||||
{
|
||||
return m_data->decimals;
|
||||
}
|
||||
|
||||
QString QskSpinBox::text() const
|
||||
{
|
||||
return textFromValue( value() );
|
||||
}
|
||||
|
||||
QString QskSpinBox::textFromValue( qreal value ) const
|
||||
{
|
||||
return locale().toString( value, 'f', m_data->decimals );
|
||||
}
|
||||
|
||||
void QskSpinBox::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
if ( !isReadOnly() )
|
||||
|
@ -25,6 +25,11 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||
Q_PROPERTY( bool buttons READ hasButtons
|
||||
WRITE setButtons NOTIFY buttonsChanged )
|
||||
|
||||
Q_PROPERTY( int decimals READ decimals
|
||||
WRITE setDecimals NOTIFY decimalsChanged )
|
||||
|
||||
Q_PROPERTY( QString text READ text NOTIFY textChanged )
|
||||
|
||||
public:
|
||||
QSK_SUBCONTROLS( Panel, TextPanel, Text,
|
||||
UpPanel, UpIndicator, DownPanel, DownIndicator )
|
||||
@ -46,11 +51,23 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||
void setAccelerating( bool );
|
||||
bool isAccelerating() const;
|
||||
|
||||
void setDecimals( int );
|
||||
int decimals() const;
|
||||
|
||||
QString text() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void buttonsChanged( bool );
|
||||
|
||||
void trackingChanged( bool );
|
||||
void wrappingChanged( bool );
|
||||
void acceleratingChanged( bool );
|
||||
void buttonsChanged( bool );
|
||||
|
||||
void decimalsChanged( int );
|
||||
void textChanged();
|
||||
|
||||
protected:
|
||||
virtual QString textFromValue( qreal ) const;
|
||||
|
||||
private:
|
||||
void timerEvent( QTimerEvent* ) override;
|
||||
|
@ -229,9 +229,7 @@ QSGNode* QskSpinBoxSkinlet::updateSubNode(
|
||||
case Text:
|
||||
{
|
||||
const auto* const spinbox = static_cast< const QskSpinBox* >( skinnable );
|
||||
|
||||
return updateTextNode( skinnable, node,
|
||||
QString::number( spinbox->value() ), Q::Text );
|
||||
return updateTextNode( skinnable, node, spinbox->text(), Q::Text );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user