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