From eb4cf2c2ae45f5113f72f3b0b2f2a8e16e3cd1c8 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 27 Sep 2019 07:34:25 +0200 Subject: [PATCH] making readOnly a state --- src/controls/QskRangeControl.cpp | 17 +++++++++-------- src/controls/QskRangeControl.h | 3 +++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/controls/QskRangeControl.cpp b/src/controls/QskRangeControl.cpp index 29483b7a..c7797050 100644 --- a/src/controls/QskRangeControl.cpp +++ b/src/controls/QskRangeControl.cpp @@ -6,6 +6,8 @@ #include "QskRangeControl.h" #include "QskFunctions.h" +QSK_SYSTEM_STATE( QskRangeControl, ReadOnly, ( QskAspect::FirstSystemState << 1 ) ) + class QskRangeControl::PrivateData { public: @@ -16,7 +18,6 @@ class QskRangeControl::PrivateData , stepSize( 0.1 ) , pageSize( 1 ) , snap( false ) - , readOnly( false ) { } @@ -26,15 +27,15 @@ class QskRangeControl::PrivateData qreal stepSize; int pageSize; bool snap : 1; - bool readOnly : 1; }; QskRangeControl::QskRangeControl( QQuickItem* parent ) : QskControl( parent ) , m_data( new PrivateData() ) { - m_data->readOnly = true; - setReadOnly( false ); + setFocusPolicy( Qt::StrongFocus ); + setAcceptedMouseButtons( Qt::LeftButton ); + setWheelEnabled( true ); } QskRangeControl::~QskRangeControl() @@ -215,22 +216,22 @@ bool QskRangeControl::snap() const void QskRangeControl::setReadOnly( bool readOnly ) { - if ( m_data->readOnly == readOnly ) + if ( readOnly == isReadOnly() ) return; - m_data->readOnly = readOnly; + setSkinStateFlag( ReadOnly, readOnly ); // we are killing user settings here !! setFocusPolicy( readOnly ? Qt::NoFocus : Qt::StrongFocus ); setAcceptedMouseButtons( readOnly ? Qt::NoButton : Qt::LeftButton ); - setWheelEnabled( !m_data->readOnly ); + setWheelEnabled( !readOnly ); Q_EMIT readOnlyChanged( readOnly ); } bool QskRangeControl::isReadOnly() const { - return m_data->readOnly; + return skinState() & ReadOnly; } void QskRangeControl::stepUp() diff --git a/src/controls/QskRangeControl.h b/src/controls/QskRangeControl.h index e8057653..72f9f2dc 100644 --- a/src/controls/QskRangeControl.h +++ b/src/controls/QskRangeControl.h @@ -21,10 +21,13 @@ class QSK_EXPORT QskRangeControl : public QskControl Q_PROPERTY( int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged ) Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged ) + Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged ) using Inherited = QskControl; public: + QSK_STATES( ReadOnly ) + QskRangeControl( QQuickItem* parent = nullptr ); ~QskRangeControl() override;