diff --git a/examples/iotdashboard/LightDisplay.cpp b/examples/iotdashboard/LightDisplay.cpp index 7f3e9ca7..b2b3fdb9 100644 --- a/examples/iotdashboard/LightDisplay.cpp +++ b/examples/iotdashboard/LightDisplay.cpp @@ -6,17 +6,7 @@ #include "LightDisplay.h" #include "Skin.h" -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include QSK_SUBCONTROL( LightDisplay, Panel ) QSK_SUBCONTROL( LightDisplay, Groove ) @@ -26,6 +16,8 @@ QSK_SUBCONTROL( LightDisplay, LeftLabel ) QSK_SUBCONTROL( LightDisplay, RightLabel ) QSK_SUBCONTROL( LightDisplay, Knob ) +QSK_STATE( LightDisplay, Pressed, ( QskAspect::FirstUserState << 1 ) ) + LightDisplay::LightDisplay( QQuickItem* parent ) : QskBoundedValueInput( parent ) { @@ -39,6 +31,11 @@ LightDisplay::LightDisplay( QQuickItem* parent ) setShadowColor( 0xe5e5e5 ); } +bool LightDisplay::isPressed() const +{ + return hasSkinState( Pressed ); +} + void LightDisplay::setShadow( const QskShadowMetrics& shadow ) { m_shadow = shadow; @@ -72,4 +69,38 @@ QColor LightDisplay::shadowColor() const return m_shadowColor; } +void LightDisplay::mousePressEvent( QMouseEvent* event ) +{ + QRectF handleRect = subControlRect( LightDisplay::Knob ); + + if ( handleRect.contains( event->pos() ) ) + { + setSkinStateFlag( Pressed ); + } + else + { + QskBoundedValueInput::mousePressEvent( event ); + } +} + +void LightDisplay::mouseMoveEvent( QMouseEvent* event ) +{ + if ( !isPressed() ) + return; + + // ### check if arc contains the position + + const auto mousePos = qskMousePosition( event ); + const auto rect = subControlRect( ColdAndWarmArc ); + + const qreal ratioX = ( mousePos.x() - rect.x() ) / rect.width(); + + setValueAsRatio( ratioX ); +} + +void LightDisplay::mouseReleaseEvent( QMouseEvent* /*event*/ ) +{ + setSkinStateFlag( Pressed, false ); +} + #include "moc_LightDisplay.cpp" diff --git a/examples/iotdashboard/LightDisplay.h b/examples/iotdashboard/LightDisplay.h index 29409524..ba62c7ac 100644 --- a/examples/iotdashboard/LightDisplay.h +++ b/examples/iotdashboard/LightDisplay.h @@ -15,10 +15,13 @@ class LightDisplay : public QskBoundedValueInput public: QSK_SUBCONTROLS( Panel, Groove, ColdAndWarmArc, ValueText, LeftLabel, - RightLabel, Knob ) + RightLabel, Knob ) // ### rename knob to handle? + QSK_STATES( Pressed ) LightDisplay( QQuickItem* parent = nullptr ); + bool isPressed() const; + void setShadow( const QskShadowMetrics& ); const QskShadowMetrics& shadow() const; @@ -28,6 +31,11 @@ class LightDisplay : public QskBoundedValueInput void setShadowColor( const QColor& ); QColor shadowColor() const; + protected: + void mousePressEvent( QMouseEvent* e ) override; + void mouseMoveEvent( QMouseEvent* e ) override; + void mouseReleaseEvent( QMouseEvent* e ) override; + private: QskShadowMetrics m_shadow; QColor m_shadowColor = Qt::black;