Merge branch 'master' into features/slider

This commit is contained in:
Uwe Rathmann 2024-10-23 08:54:49 +02:00
commit e3b87338c0
6 changed files with 28 additions and 20 deletions

View File

@ -97,7 +97,7 @@ InputPage::InputPage( QQuickItem* parent )
struct struct
{ {
Slider* continous; Slider* continous;
Slider* descrete; Slider* discrete;
} sliders[2]; } sliders[2];
for ( int i = 0; i < 2; i++ ) for ( int i = 0; i < 2; i++ )
@ -105,7 +105,7 @@ InputPage::InputPage( QQuickItem* parent )
const auto orientation = static_cast< Qt::Orientation >( i + 1 ); const auto orientation = static_cast< Qt::Orientation >( i + 1 );
sliders[i].continous = new Slider( orientation, Slider::Continous ); sliders[i].continous = new Slider( orientation, Slider::Continous );
sliders[i].descrete = new Slider( orientation, Slider::Discrete ); sliders[i].discrete = new Slider( orientation, Slider::Discrete );
} }
auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0 ); auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0 );
@ -119,14 +119,14 @@ InputPage::InputPage( QQuickItem* parent )
vBox->setExtraSpacingAt( Qt::RightEdge | Qt::BottomEdge ); vBox->setExtraSpacingAt( Qt::RightEdge | Qt::BottomEdge );
vBox->addItem( sliders[0].continous ); vBox->addItem( sliders[0].continous );
vBox->addItem( sliders[0].descrete ); vBox->addItem( sliders[0].discrete );
vBox->addItem( inputBox ); vBox->addItem( inputBox );
vBox->addItem( spinBox ); vBox->addItem( spinBox );
auto mainBox = new QskLinearBox( Qt::Horizontal, this ); auto mainBox = new QskLinearBox( Qt::Horizontal, this );
mainBox->setSpacing( 30 ); mainBox->setSpacing( 30 );
mainBox->addItem( sliders[1].continous ); mainBox->addItem( sliders[1].continous );
mainBox->addItem( sliders[1].descrete ); mainBox->addItem( sliders[1].discrete );
mainBox->addItem( vBox ); mainBox->addItem( vBox );
auto inputs = findChildren< QskBoundedValueInput* >(); auto inputs = findChildren< QskBoundedValueInput* >();
@ -136,6 +136,8 @@ InputPage::InputPage( QQuickItem* parent )
connect( input, &QskBoundedValueInput::valueChanged, connect( input, &QskBoundedValueInput::valueChanged,
this, &InputPage::syncValues ); this, &InputPage::syncValues );
} }
spinBox->setValue( 30.0 );
} }
void InputPage::syncValues( qreal value ) void InputPage::syncValues( qreal value )

View File

@ -6,6 +6,8 @@
#include "QskBoundedValueInput.h" #include "QskBoundedValueInput.h"
#include "QskFunctions.h" #include "QskFunctions.h"
#include <qlocale.h>
QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent ) QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
: QskBoundedInput( parent ) : QskBoundedInput( parent )
{ {
@ -71,4 +73,14 @@ void QskBoundedValueInput::setValueInternal( qreal value )
} }
} }
QString QskBoundedValueInput::valueText() const
{
return textFromValue( value() );
}
QString QskBoundedValueInput::textFromValue( qreal value ) const
{
return locale().toString( value );
}
#include "moc_QskBoundedValueInput.cpp" #include "moc_QskBoundedValueInput.cpp"

View File

@ -18,6 +18,8 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
Q_PROPERTY( qreal valueAsRatio READ valueAsRatio Q_PROPERTY( qreal valueAsRatio READ valueAsRatio
WRITE setValueAsRatio NOTIFY valueChanged ) WRITE setValueAsRatio NOTIFY valueChanged )
Q_PROPERTY( QString valueText READ valueText NOTIFY valueChanged )
using Inherited = QskBoundedInput; using Inherited = QskBoundedInput;
public: public:
@ -30,20 +32,23 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
qreal valueAsRatio() const; qreal valueAsRatio() const;
using QskBoundedInput::valueAsRatio; using QskBoundedInput::valueAsRatio;
QString valueText() const;
virtual QString textFromValue( qreal ) const;
public Q_SLOTS: public Q_SLOTS:
void setValue( qreal ); void setValue( qreal );
void setValueAsRatio( qreal ); void setValueAsRatio( qreal );
void increment( qreal offset ) override; void increment( qreal ) override;
Q_SIGNALS: Q_SIGNALS:
void valueChanged( qreal ); void valueChanged( qreal );
protected: protected:
virtual qreal fixupValue( qreal value ) const; virtual qreal fixupValue( qreal ) const;
void alignInput() override; void alignInput() override;
private: private:
void setValueInternal( qreal value ); void setValueInternal( qreal );
void adjustValue(); void adjustValue();
qreal m_value = 0.0; qreal m_value = 0.0;

View File

@ -8,7 +8,6 @@
#include "QskFunctions.h" #include "QskFunctions.h"
#include <qbasictimer.h> #include <qbasictimer.h>
#include <qlocale.h>
#include <cfloat> #include <cfloat>
@ -143,8 +142,6 @@ QskSpinBox::QskSpinBox( qreal min, qreal max, qreal stepSize, QQuickItem* parent
setAcceptedMouseButtons( Qt::LeftButton ); setAcceptedMouseButtons( Qt::LeftButton );
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
connect( this, &QskSpinBox::valueChanged, this, &QskSpinBox::textChanged );
} }
QskSpinBox::QskSpinBox( QQuickItem* parent ) QskSpinBox::QskSpinBox( QQuickItem* parent )
@ -204,11 +201,6 @@ int QskSpinBox::decimals() const
return m_data->decimals; return m_data->decimals;
} }
QString QskSpinBox::text() const
{
return textFromValue( value() );
}
QString QskSpinBox::textFromValue( qreal value ) const QString QskSpinBox::textFromValue( qreal value ) const
{ {
return locale().toString( value, 'f', m_data->decimals ); return locale().toString( value, 'f', m_data->decimals );

View File

@ -22,8 +22,6 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
Q_PROPERTY( int decimals READ decimals Q_PROPERTY( int decimals READ decimals
WRITE setDecimals NOTIFY decimalsChanged ) WRITE setDecimals NOTIFY decimalsChanged )
Q_PROPERTY( QString text READ text NOTIFY textChanged )
public: public:
QSK_SUBCONTROLS( Panel, TextPanel, Text, QSK_SUBCONTROLS( Panel, TextPanel, Text,
UpPanel, UpIndicator, DownPanel, DownIndicator ) UpPanel, UpIndicator, DownPanel, DownIndicator )
@ -56,8 +54,7 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
void setDecimals( int ); void setDecimals( int );
int decimals() const; int decimals() const;
QString text() const; virtual QString textFromValue( qreal ) const override;
virtual QString textFromValue( qreal ) const;
void increment( qreal ) override; void increment( qreal ) override;

View File

@ -144,7 +144,7 @@ QSGNode* QskSpinBoxSkinlet::updateSubNode(
case TextRole: case TextRole:
{ {
auto spinBox = static_cast< const QskSpinBox* >( skinnable ); auto spinBox = static_cast< const QskSpinBox* >( skinnable );
return updateTextNode( spinBox, node, spinBox->text(), Q::Text ); return updateTextNode( spinBox, node, spinBox->valueText(), Q::Text );
} }
} }