Merge branch 'master' into features/slider
This commit is contained in:
commit
b53f60dd0e
|
@ -7,9 +7,18 @@
|
||||||
#include "QskFunctions.h"
|
#include "QskFunctions.h"
|
||||||
|
|
||||||
#include <qlocale.h>
|
#include <qlocale.h>
|
||||||
|
#include <cfloat>
|
||||||
|
|
||||||
|
class QskBoundedValueInput::PrivateData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
qreal value = 0.0;
|
||||||
|
int decimals = 2;
|
||||||
|
};
|
||||||
|
|
||||||
QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
|
QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
|
||||||
: QskBoundedInput( parent )
|
: Inherited( parent )
|
||||||
|
, m_data( new PrivateData )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +26,26 @@ QskBoundedValueInput::~QskBoundedValueInput()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskBoundedValueInput::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 QskBoundedValueInput::decimals() const
|
||||||
|
{
|
||||||
|
return m_data->decimals;
|
||||||
|
}
|
||||||
|
|
||||||
void QskBoundedValueInput::alignInput()
|
void QskBoundedValueInput::alignInput()
|
||||||
{
|
{
|
||||||
auto value = alignedValue( m_value );
|
auto value = alignedValue( m_data->value );
|
||||||
value = fixupValue( value );
|
value = fixupValue( value );
|
||||||
|
|
||||||
setValueInternal( value );
|
setValueInternal( value );
|
||||||
|
@ -38,7 +64,7 @@ void QskBoundedValueInput::setValueAsRatio( qreal ratio )
|
||||||
|
|
||||||
qreal QskBoundedValueInput::valueAsRatio() const
|
qreal QskBoundedValueInput::valueAsRatio() const
|
||||||
{
|
{
|
||||||
return valueAsRatio( m_value );
|
return valueAsRatio( m_data->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskBoundedValueInput::setValue( qreal value )
|
void QskBoundedValueInput::setValue( qreal value )
|
||||||
|
@ -54,19 +80,19 @@ void QskBoundedValueInput::setValue( qreal value )
|
||||||
|
|
||||||
qreal QskBoundedValueInput::value() const
|
qreal QskBoundedValueInput::value() const
|
||||||
{
|
{
|
||||||
return m_value;
|
return m_data->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskBoundedValueInput::increment( qreal offset )
|
void QskBoundedValueInput::increment( qreal offset )
|
||||||
{
|
{
|
||||||
setValue( m_value + offset );
|
setValue( m_data->value + offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskBoundedValueInput::setValueInternal( qreal value )
|
void QskBoundedValueInput::setValueInternal( qreal value )
|
||||||
{
|
{
|
||||||
if ( !qskFuzzyCompare( value, m_value ) )
|
if ( !qskFuzzyCompare( value, m_data->value ) )
|
||||||
{
|
{
|
||||||
m_value = value;
|
m_data->value = value;
|
||||||
Q_EMIT valueChanged( value );
|
Q_EMIT valueChanged( value );
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -74,13 +100,13 @@ void QskBoundedValueInput::setValueInternal( qreal value )
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskBoundedValueInput::valueText() const
|
QString QskBoundedValueInput::valueText() const
|
||||||
{
|
{
|
||||||
return textFromValue( value() );
|
return textFromValue( value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskBoundedValueInput::textFromValue( qreal value ) const
|
QString QskBoundedValueInput::textFromValue( qreal value ) const
|
||||||
{
|
{
|
||||||
return locale().toString( value );
|
return locale().toString( value, 'f', m_data->decimals );
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_QskBoundedValueInput.cpp"
|
#include "moc_QskBoundedValueInput.cpp"
|
||||||
|
|
|
@ -20,6 +20,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||||
|
|
||||||
Q_PROPERTY( QString valueText READ valueText NOTIFY valueChanged )
|
Q_PROPERTY( QString valueText READ valueText NOTIFY valueChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( int decimals READ decimals
|
||||||
|
WRITE setDecimals NOTIFY decimalsChanged )
|
||||||
|
|
||||||
using Inherited = QskBoundedInput;
|
using Inherited = QskBoundedInput;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -35,6 +38,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||||
QString valueText() const;
|
QString valueText() const;
|
||||||
virtual QString textFromValue( qreal ) const;
|
virtual QString textFromValue( qreal ) const;
|
||||||
|
|
||||||
|
void setDecimals( int );
|
||||||
|
int decimals() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setValue( qreal );
|
void setValue( qreal );
|
||||||
void setValueAsRatio( qreal );
|
void setValueAsRatio( qreal );
|
||||||
|
@ -42,6 +48,7 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void valueChanged( qreal );
|
void valueChanged( qreal );
|
||||||
|
void decimalsChanged( int );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual qreal fixupValue( qreal ) const;
|
virtual qreal fixupValue( qreal ) const;
|
||||||
|
@ -49,9 +56,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setValueInternal( qreal );
|
void setValueInternal( qreal );
|
||||||
void adjustValue();
|
|
||||||
|
|
||||||
qreal m_value = 0.0;
|
class PrivateData;
|
||||||
|
std::unique_ptr< PrivateData > m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
#include <qbasictimer.h>
|
#include <qbasictimer.h>
|
||||||
|
|
||||||
#include <cfloat>
|
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskSpinBox, Panel )
|
QSK_SUBCONTROL( QskSpinBox, Panel )
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskSpinBox, TextPanel )
|
QSK_SUBCONTROL( QskSpinBox, TextPanel )
|
||||||
|
@ -109,8 +107,6 @@ class QskSpinBox::PrivateData
|
||||||
this->repeatTimer.stop();
|
this->repeatTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int decimals = 2;
|
|
||||||
|
|
||||||
int autoRepeatDelay = 300;
|
int autoRepeatDelay = 300;
|
||||||
int autoRepeatInterval = 100;
|
int autoRepeatInterval = 100;
|
||||||
|
|
||||||
|
@ -184,28 +180,6 @@ bool QskSpinBox::isWrapping() const
|
||||||
return m_data->wrapping;
|
return m_data->wrapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
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::textFromValue( qreal value ) const
|
|
||||||
{
|
|
||||||
return locale().toString( value, 'f', m_data->decimals );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskSpinBox::increment( qreal offset )
|
void QskSpinBox::increment( qreal offset )
|
||||||
{
|
{
|
||||||
if ( m_data->wrapping )
|
if ( m_data->wrapping )
|
||||||
|
|
|
@ -19,9 +19,6 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||||
Q_PROPERTY( Decoration decoration READ decoration
|
Q_PROPERTY( Decoration decoration READ decoration
|
||||||
WRITE setDecoration RESET resetDecoration NOTIFY decorationChanged )
|
WRITE setDecoration RESET resetDecoration NOTIFY decorationChanged )
|
||||||
|
|
||||||
Q_PROPERTY( int decimals READ decimals
|
|
||||||
WRITE setDecimals NOTIFY decimalsChanged )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Panel, TextPanel, Text,
|
QSK_SUBCONTROLS( Panel, TextPanel, Text,
|
||||||
UpPanel, UpIndicator, DownPanel, DownIndicator )
|
UpPanel, UpIndicator, DownPanel, DownIndicator )
|
||||||
|
@ -51,18 +48,11 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||||
void setWrapping( bool );
|
void setWrapping( bool );
|
||||||
bool isWrapping() const;
|
bool isWrapping() const;
|
||||||
|
|
||||||
void setDecimals( int );
|
|
||||||
int decimals() const;
|
|
||||||
|
|
||||||
virtual QString textFromValue( qreal ) const override;
|
|
||||||
|
|
||||||
void increment( qreal ) override;
|
void increment( qreal ) override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void decorationChanged( Decoration );
|
void decorationChanged( Decoration );
|
||||||
void wrappingChanged( bool );
|
void wrappingChanged( bool );
|
||||||
void decimalsChanged( int );
|
|
||||||
void textChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent( QTimerEvent* ) override;
|
void timerEvent( QTimerEvent* ) override;
|
||||||
|
|
Loading…
Reference in New Issue