menu: support pressed state

This commit is contained in:
Peter Hartmann 2023-06-30 15:44:49 +02:00 committed by uwerat
parent f126a9007d
commit e00c2f5335
5 changed files with 31 additions and 4 deletions

View File

@ -725,6 +725,7 @@ void Editor::setupMenuColors(
setShadowColor( Q::Panel, theme.shadow.flyout.color );
setGradient( Q::Segment | Q::Hovered, pal.fillColor.subtle.secondary );
setGradient( Q::Segment | Q::Selected | Q::Pressed, pal.fillColor.subtle.tertiary );
setGradient( Q::Segment | Q::Selected, pal.fillColor.subtle.secondary );
@ -739,9 +740,14 @@ void Editor::setupMenuColors(
setBoxBorderColors( Q::Segment | Q::Selected,
QskGradient( { { 0.25, c1 }, { 0.25, c2 }, { 0.75, c2 }, { 0.75, c1 } } ) );
setBoxBorderColors( Q::Segment | Q::Selected | Q::Pressed,
QskGradient( { { 0.33, c1 }, { 0.33, c2 }, { 0.67, c2 }, { 0.67, c1 } } ) );
setColor( Q::Text, pal.fillColor.text.primary );
setColor( Q::Text | Q::Selected | Q::Pressed, pal.fillColor.text.secondary );
setGraphicRole( Q::Icon, QskFluent2Skin::GraphicRoleFillColorTextPrimary );
setGraphicRole( Q::Icon | Q::Selected | Q::Pressed, QskFluent2Skin::GraphicRoleFillColorTextSecondary );
}
void Editor::setupPageIndicatorMetrics()

View File

@ -361,6 +361,8 @@ void Editor::setupMenu()
setGradient( Q::Segment | Q::Selected, m_pal.primary12 );
const auto hoverSelectedColor = flattenedColor( m_pal.onSurface, m_pal.primary12, m_pal.hoverOpacity );
setGradient( Q::Segment | Q::Selected | Q::Hovered, hoverSelectedColor );
const auto pressedSelectedColor = flattenedColor( m_pal.onSurface, m_pal.primary12, m_pal.pressedOpacity );
setGradient( Q::Segment | Q::Pressed | Q::Selected, pressedSelectedColor );
setPadding( Q::Icon, 7_dp );
setStrutSize( Q::Icon, 24_dp, 24_dp );

View File

@ -27,6 +27,7 @@ QSK_SUBCONTROL( QskMenu, Icon )
QSK_SUBCONTROL( QskMenu, Separator )
QSK_SYSTEM_STATE( QskMenu, Selected, QskAspect::FirstSystemState << 2 )
QSK_SYSTEM_STATE( QskMenu, Pressed, QskAspect::FirstSystemState << 3 )
static inline int qskActionIndex( const QVector< int >& actions, int index )
{
@ -309,7 +310,7 @@ void QskMenu::keyPressEvent( QKeyEvent* event )
void QskMenu::keyReleaseEvent( QKeyEvent* )
{
if( m_data->isPressed )
if( isPressed() )
{
m_data->isPressed = false;
@ -416,7 +417,7 @@ void QskMenu::mouseReleaseEvent( QMouseEvent* event )
{
if ( event->button() == Qt::LeftButton )
{
if( m_data->isPressed )
if( isPressed() )
{
m_data->isPressed = false;
@ -481,6 +482,11 @@ int QskMenu::indexAtPosition( const QPointF& pos ) const
return m_data->actions.value( index, -1 );
}
bool QskMenu::isPressed() const
{
return m_data->isPressed;
}
void QskMenu::trigger( int index )
{
if ( index >= 0 && index < m_data->options.count() )

View File

@ -38,7 +38,7 @@ class QSK_EXPORT QskMenu : public QskPopup
public:
QSK_SUBCONTROLS( Overlay, Panel, Segment, Cursor, Text, Icon, Separator )
QSK_STATES( Selected )
QSK_STATES( Selected, Pressed )
QskMenu( QQuickItem* parentItem = nullptr );
~QskMenu() override;
@ -79,6 +79,8 @@ class QSK_EXPORT QskMenu : public QskPopup
QRectF cellRect( int index ) const;
int indexAtPosition( const QPointF& ) const;
bool isPressed() const;
Q_INVOKABLE int exec();
Q_SIGNALS:

View File

@ -394,7 +394,18 @@ QskAspect::States QskMenuSkinlet::sampleStates(
const auto menu = static_cast< const QskMenu* >( skinnable );
if ( menu->currentIndex() == menu->actions()[ index ] )
states |= QskMenu::Selected;
{
states |= Q::Selected;
if( menu->isPressed() )
{
states |= Q::Pressed;
}
else
{
states &= ~Q::Pressed;
}
}
const auto cursorPos = menu->effectiveSkinHint( Q::Segment | Q::Hovered | A::Metric | A::Position ).toPointF();