using QskBoundedValueInput as base class

This commit is contained in:
Vogel, Rick 2023-02-17 14:57:33 +01:00
parent 04fa1c6dd6
commit 890ae64652
2 changed files with 3 additions and 35 deletions

View File

@ -45,19 +45,6 @@ public:
{ {
} }
void setValue(qreal value)
{
value = qBound(q->minimum(), value, q->maximum());
if(!qFuzzyCompare(m_value, value))
{
m_value = value;
Q_EMIT q->valueChanged(m_value);
q->update();
}
}
qreal value() const { return m_value; }
FocusIndeces defaultFocusIndex() const FocusIndeces defaultFocusIndex() const
{ {
const auto layout = q->alignmentHint(QskSpinBox::Layout); const auto layout = q->alignmentHint(QskSpinBox::Layout);
@ -170,7 +157,6 @@ public:
} }
private: private:
qreal m_value{0.0f};
QskSpinBox* const q; QskSpinBox* const q;
FocusIndeces m_focusIndex = FocusIndeces::None; FocusIndeces m_focusIndex = FocusIndeces::None;
}; };
@ -187,8 +173,6 @@ QskSpinBox::QskSpinBox(QQuickItem* const parent)
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
connect( this, &S::focusIndexChanged, this, &S::focusIndicatorRectChanged ); connect( this, &S::focusIndexChanged, this, &S::focusIndicatorRectChanged );
connect( this, &S::boundariesChanged, this, [this](const QskIntervalF& interval){ if(!interval.contains(value())) m_data->setValue(minimum()); });
connect( this, &S::valueChanged, this, [this](){ polish(); });
} }
QskSpinBox::~QskSpinBox() = default; QskSpinBox::~QskSpinBox() = default;
@ -364,16 +348,6 @@ QRectF QskSpinBox::focusIndicatorRect() const
return rect; return rect;
} }
void QskSpinBox::increment(qreal offset)
{
m_data->setValue(m_data->value() + offset);
}
qreal QskSpinBox::value() const
{
return m_data->value();
}
QskSpinBox::FocusIndeces QskSpinBox::focusIndex() const QskSpinBox::FocusIndeces QskSpinBox::focusIndex() const
{ {
return m_data->focusIndex(); return m_data->focusIndex();

View File

@ -7,31 +7,25 @@
#include <QskControl.h> #include <QskControl.h>
#include <QskPushButton.h> #include <QskPushButton.h>
#include <QskBoundedInput.h> #include <QskBoundedValueInput.h>
class QSK_EXPORT QskSpinBox : public QskBoundedInput class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
{ {
Q_OBJECT Q_OBJECT
using Inherited = QskBoundedInput; using Inherited = QskBoundedValueInput;
public: public:
enum FocusIndeces : int { Decrement = 0, Textbox = 1, Increment = 2, None = 3 }; enum FocusIndeces : int { Decrement = 0, Textbox = 1, Increment = 2, None = 3 };
Q_ENUM(FocusIndeces) Q_ENUM(FocusIndeces)
Q_PROPERTY(qreal value READ value NOTIFY valueChanged)
Q_PROPERTY(FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged) Q_PROPERTY(FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged)
QSK_SUBCONTROLS(IncrementPanel, DecrementPanel, IncrementText, DecrementText, TextPanel, Text, Layout) QSK_SUBCONTROLS(IncrementPanel, DecrementPanel, IncrementText, DecrementText, TextPanel, Text, Layout)
QSK_STATES( Pressed ) QSK_STATES( Pressed )
explicit QskSpinBox( QQuickItem* parent = nullptr ); explicit QskSpinBox( QQuickItem* parent = nullptr );
~QskSpinBox() override; ~QskSpinBox() override;
void increment( qreal offset ) override;
qreal value() const;
FocusIndeces focusIndex() const; FocusIndeces focusIndex() const;
Q_SIGNALS: Q_SIGNALS:
void valueChanged(qreal value);
void focusIndexChanged(int index); void focusIndexChanged(int index);
private: private: