menu: support pressed state
This commit is contained in:
parent
f126a9007d
commit
e00c2f5335
@ -725,6 +725,7 @@ void Editor::setupMenuColors(
|
|||||||
setShadowColor( Q::Panel, theme.shadow.flyout.color );
|
setShadowColor( Q::Panel, theme.shadow.flyout.color );
|
||||||
|
|
||||||
setGradient( Q::Segment | Q::Hovered, pal.fillColor.subtle.secondary );
|
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 );
|
setGradient( Q::Segment | Q::Selected, pal.fillColor.subtle.secondary );
|
||||||
|
|
||||||
@ -739,9 +740,14 @@ void Editor::setupMenuColors(
|
|||||||
setBoxBorderColors( Q::Segment | Q::Selected,
|
setBoxBorderColors( Q::Segment | Q::Selected,
|
||||||
QskGradient( { { 0.25, c1 }, { 0.25, c2 }, { 0.75, c2 }, { 0.75, c1 } } ) );
|
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, pal.fillColor.text.primary );
|
||||||
|
setColor( Q::Text | Q::Selected | Q::Pressed, pal.fillColor.text.secondary );
|
||||||
|
|
||||||
setGraphicRole( Q::Icon, QskFluent2Skin::GraphicRoleFillColorTextPrimary );
|
setGraphicRole( Q::Icon, QskFluent2Skin::GraphicRoleFillColorTextPrimary );
|
||||||
|
setGraphicRole( Q::Icon | Q::Selected | Q::Pressed, QskFluent2Skin::GraphicRoleFillColorTextSecondary );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupPageIndicatorMetrics()
|
void Editor::setupPageIndicatorMetrics()
|
||||||
|
@ -361,6 +361,8 @@ void Editor::setupMenu()
|
|||||||
setGradient( Q::Segment | Q::Selected, m_pal.primary12 );
|
setGradient( Q::Segment | Q::Selected, m_pal.primary12 );
|
||||||
const auto hoverSelectedColor = flattenedColor( m_pal.onSurface, m_pal.primary12, m_pal.hoverOpacity );
|
const auto hoverSelectedColor = flattenedColor( m_pal.onSurface, m_pal.primary12, m_pal.hoverOpacity );
|
||||||
setGradient( Q::Segment | Q::Selected | Q::Hovered, hoverSelectedColor );
|
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 );
|
setPadding( Q::Icon, 7_dp );
|
||||||
setStrutSize( Q::Icon, 24_dp, 24_dp );
|
setStrutSize( Q::Icon, 24_dp, 24_dp );
|
||||||
|
@ -27,6 +27,7 @@ QSK_SUBCONTROL( QskMenu, Icon )
|
|||||||
QSK_SUBCONTROL( QskMenu, Separator )
|
QSK_SUBCONTROL( QskMenu, Separator )
|
||||||
|
|
||||||
QSK_SYSTEM_STATE( QskMenu, Selected, QskAspect::FirstSystemState << 2 )
|
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 )
|
static inline int qskActionIndex( const QVector< int >& actions, int index )
|
||||||
{
|
{
|
||||||
@ -309,7 +310,7 @@ void QskMenu::keyPressEvent( QKeyEvent* event )
|
|||||||
|
|
||||||
void QskMenu::keyReleaseEvent( QKeyEvent* )
|
void QskMenu::keyReleaseEvent( QKeyEvent* )
|
||||||
{
|
{
|
||||||
if( m_data->isPressed )
|
if( isPressed() )
|
||||||
{
|
{
|
||||||
m_data->isPressed = false;
|
m_data->isPressed = false;
|
||||||
|
|
||||||
@ -416,7 +417,7 @@ void QskMenu::mouseReleaseEvent( QMouseEvent* event )
|
|||||||
{
|
{
|
||||||
if ( event->button() == Qt::LeftButton )
|
if ( event->button() == Qt::LeftButton )
|
||||||
{
|
{
|
||||||
if( m_data->isPressed )
|
if( isPressed() )
|
||||||
{
|
{
|
||||||
m_data->isPressed = false;
|
m_data->isPressed = false;
|
||||||
|
|
||||||
@ -481,6 +482,11 @@ int QskMenu::indexAtPosition( const QPointF& pos ) const
|
|||||||
return m_data->actions.value( index, -1 );
|
return m_data->actions.value( index, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QskMenu::isPressed() const
|
||||||
|
{
|
||||||
|
return m_data->isPressed;
|
||||||
|
}
|
||||||
|
|
||||||
void QskMenu::trigger( int index )
|
void QskMenu::trigger( int index )
|
||||||
{
|
{
|
||||||
if ( index >= 0 && index < m_data->options.count() )
|
if ( index >= 0 && index < m_data->options.count() )
|
||||||
|
@ -38,7 +38,7 @@ class QSK_EXPORT QskMenu : public QskPopup
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Overlay, Panel, Segment, Cursor, Text, Icon, Separator )
|
QSK_SUBCONTROLS( Overlay, Panel, Segment, Cursor, Text, Icon, Separator )
|
||||||
QSK_STATES( Selected )
|
QSK_STATES( Selected, Pressed )
|
||||||
|
|
||||||
QskMenu( QQuickItem* parentItem = nullptr );
|
QskMenu( QQuickItem* parentItem = nullptr );
|
||||||
~QskMenu() override;
|
~QskMenu() override;
|
||||||
@ -79,6 +79,8 @@ class QSK_EXPORT QskMenu : public QskPopup
|
|||||||
QRectF cellRect( int index ) const;
|
QRectF cellRect( int index ) const;
|
||||||
int indexAtPosition( const QPointF& ) const;
|
int indexAtPosition( const QPointF& ) const;
|
||||||
|
|
||||||
|
bool isPressed() const;
|
||||||
|
|
||||||
Q_INVOKABLE int exec();
|
Q_INVOKABLE int exec();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
@ -394,7 +394,18 @@ QskAspect::States QskMenuSkinlet::sampleStates(
|
|||||||
const auto menu = static_cast< const QskMenu* >( skinnable );
|
const auto menu = static_cast< const QskMenu* >( skinnable );
|
||||||
|
|
||||||
if ( menu->currentIndex() == menu->actions()[ index ] )
|
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();
|
const auto cursorPos = menu->effectiveSkinHint( Q::Segment | Q::Hovered | A::Metric | A::Position ).toPointF();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user