making readOnly a state

This commit is contained in:
Uwe Rathmann 2019-09-27 07:34:25 +02:00
parent cbc5bb5b66
commit eb4cf2c2ae
2 changed files with 12 additions and 8 deletions

View File

@ -6,6 +6,8 @@
#include "QskRangeControl.h" #include "QskRangeControl.h"
#include "QskFunctions.h" #include "QskFunctions.h"
QSK_SYSTEM_STATE( QskRangeControl, ReadOnly, ( QskAspect::FirstSystemState << 1 ) )
class QskRangeControl::PrivateData class QskRangeControl::PrivateData
{ {
public: public:
@ -16,7 +18,6 @@ class QskRangeControl::PrivateData
, stepSize( 0.1 ) , stepSize( 0.1 )
, pageSize( 1 ) , pageSize( 1 )
, snap( false ) , snap( false )
, readOnly( false )
{ {
} }
@ -26,15 +27,15 @@ class QskRangeControl::PrivateData
qreal stepSize; qreal stepSize;
int pageSize; int pageSize;
bool snap : 1; bool snap : 1;
bool readOnly : 1;
}; };
QskRangeControl::QskRangeControl( QQuickItem* parent ) QskRangeControl::QskRangeControl( QQuickItem* parent )
: QskControl( parent ) : QskControl( parent )
, m_data( new PrivateData() ) , m_data( new PrivateData() )
{ {
m_data->readOnly = true; setFocusPolicy( Qt::StrongFocus );
setReadOnly( false ); setAcceptedMouseButtons( Qt::LeftButton );
setWheelEnabled( true );
} }
QskRangeControl::~QskRangeControl() QskRangeControl::~QskRangeControl()
@ -215,22 +216,22 @@ bool QskRangeControl::snap() const
void QskRangeControl::setReadOnly( bool readOnly ) void QskRangeControl::setReadOnly( bool readOnly )
{ {
if ( m_data->readOnly == readOnly ) if ( readOnly == isReadOnly() )
return; return;
m_data->readOnly = readOnly; setSkinStateFlag( ReadOnly, readOnly );
// we are killing user settings here !! // we are killing user settings here !!
setFocusPolicy( readOnly ? Qt::NoFocus : Qt::StrongFocus ); setFocusPolicy( readOnly ? Qt::NoFocus : Qt::StrongFocus );
setAcceptedMouseButtons( readOnly ? Qt::NoButton : Qt::LeftButton ); setAcceptedMouseButtons( readOnly ? Qt::NoButton : Qt::LeftButton );
setWheelEnabled( !m_data->readOnly ); setWheelEnabled( !readOnly );
Q_EMIT readOnlyChanged( readOnly ); Q_EMIT readOnlyChanged( readOnly );
} }
bool QskRangeControl::isReadOnly() const bool QskRangeControl::isReadOnly() const
{ {
return m_data->readOnly; return skinState() & ReadOnly;
} }
void QskRangeControl::stepUp() void QskRangeControl::stepUp()

View File

@ -21,10 +21,13 @@ class QSK_EXPORT QskRangeControl : public QskControl
Q_PROPERTY( int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged ) Q_PROPERTY( int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged )
Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged ) Q_PROPERTY( bool snap READ snap WRITE setSnap NOTIFY snapChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
using Inherited = QskControl; using Inherited = QskControl;
public: public:
QSK_STATES( ReadOnly )
QskRangeControl( QQuickItem* parent = nullptr ); QskRangeControl( QQuickItem* parent = nullptr );
~QskRangeControl() override; ~QskRangeControl() override;