handle input
This commit is contained in:
parent
b5cafb2161
commit
78bc34743b
|
@ -6,17 +6,7 @@
|
|||
#include "LightDisplay.h"
|
||||
#include "Skin.h"
|
||||
|
||||
#include <QskAnimator.h>
|
||||
#include <QskRgbValue.h>
|
||||
#include <QskSetup.h>
|
||||
#include <QskTextLabel.h>
|
||||
#include <QskQuick.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQuickWindow>
|
||||
#include <QQuickPaintedItem>
|
||||
#include <QPainter>
|
||||
#include <QRadialGradient>
|
||||
#include <QskEvent.h>
|
||||
|
||||
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"
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue