radio box: Support hovered state
This commit is contained in:
parent
9752cf9e57
commit
b9fa8b3b34
@ -24,6 +24,7 @@ class QskRadioBox::PrivateData
|
||||
QStringList options;
|
||||
|
||||
int selectedIndex = -1;
|
||||
int hoveredIndex = -1;
|
||||
int focusedIndex = -1;
|
||||
int pressedIndex = -1;
|
||||
};
|
||||
@ -38,6 +39,8 @@ QskRadioBox::QskRadioBox( QQuickItem* parent )
|
||||
setAcceptedMouseButtons( Qt::LeftButton );
|
||||
|
||||
setPositionHint( Ripple, -1 );
|
||||
|
||||
setAcceptHoverEvents( true );
|
||||
}
|
||||
|
||||
QskRadioBox::QskRadioBox( const QStringList& options, QQuickItem* parent )
|
||||
@ -223,6 +226,23 @@ void QskRadioBox::mouseReleaseEvent( QMouseEvent* event )
|
||||
update();
|
||||
}
|
||||
|
||||
void QskRadioBox::hoverEnterEvent( QHoverEvent* event )
|
||||
{
|
||||
const auto index = indexAt( qskHoverPosition( event ) );
|
||||
setHoveredIndex( index );
|
||||
}
|
||||
|
||||
void QskRadioBox::hoverMoveEvent( QHoverEvent* event )
|
||||
{
|
||||
const auto index = indexAt( qskHoverPosition( event ) );
|
||||
setHoveredIndex( index );
|
||||
}
|
||||
|
||||
void QskRadioBox::hoverLeaveEvent( QHoverEvent* )
|
||||
{
|
||||
setHoveredIndex( -1 );
|
||||
}
|
||||
|
||||
void QskRadioBox::focusInEvent( QFocusEvent* event )
|
||||
{
|
||||
if( event->reason() == Qt::TabFocusReason )
|
||||
@ -252,6 +272,17 @@ int QskRadioBox::indexAt( const QPointF& pos ) const
|
||||
contentsRect(), QskRadioBox::Button, pos );
|
||||
}
|
||||
|
||||
void QskRadioBox::setHoveredIndex( int index )
|
||||
{
|
||||
if ( m_data->hoveredIndex == index )
|
||||
return;
|
||||
|
||||
m_data->hoveredIndex = index;
|
||||
setPositionHint( Ripple | Hovered, index );
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void QskRadioBox::setFocusedIndex( int index )
|
||||
{
|
||||
if ( m_data->focusedIndex == index )
|
||||
|
@ -55,12 +55,17 @@ class QSK_EXPORT QskRadioBox : public QskControl
|
||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||
void mouseUngrabEvent() override;
|
||||
|
||||
void hoverEnterEvent( QHoverEvent* ) override;
|
||||
void hoverMoveEvent( QHoverEvent* ) override;
|
||||
void hoverLeaveEvent( QHoverEvent* ) override;
|
||||
|
||||
void focusInEvent( QFocusEvent* ) override;
|
||||
void focusOutEvent( QFocusEvent* ) override;
|
||||
|
||||
int indexAt( const QPointF& ) const;
|
||||
|
||||
private:
|
||||
void setHoveredIndex( int index );
|
||||
void setFocusedIndex( int index );
|
||||
|
||||
class PrivateData;
|
||||
|
@ -219,6 +219,11 @@ QskAspect::States QskRadioBoxSkinlet::sampleStates(
|
||||
states |= Q::Pressed;
|
||||
|
||||
#if 1
|
||||
if( radioBox->positionHint( Q::Ripple | Q::Hovered ) == index )
|
||||
states |= Q::Hovered;
|
||||
else
|
||||
states &= ~Q::Hovered;
|
||||
|
||||
if( radioBox->positionHint( Q::Ripple ) == index )
|
||||
states |= Q::Focused;
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user