From dd124afcf1fa2379dad565bbd8eca07123fcf4d3 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 26 Mar 2021 13:47:09 +0100 Subject: [PATCH] menu item states instead of own API --- examples/iot-dashboard/MenuBar.cpp | 21 +++------------------ examples/iot-dashboard/MenuBar.h | 3 +-- examples/iot-dashboard/Skin.cpp | 2 ++ 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/iot-dashboard/MenuBar.cpp b/examples/iot-dashboard/MenuBar.cpp index 6371a451..e124a2a2 100644 --- a/examples/iot-dashboard/MenuBar.cpp +++ b/examples/iot-dashboard/MenuBar.cpp @@ -12,6 +12,8 @@ QSK_SUBCONTROL( MenuBarGraphicLabel, Graphic ) QSK_SUBCONTROL( MenuBarLabel, Text ) QSK_SUBCONTROL( MenuItem, Panel ) +QSK_STATE( MenuItem, Active, ( QskAspect::FirstUserState << 1 ) ) + MenuItem::MenuItem( const QString& name, QQuickItem* parent ) : QskLinearBox( Qt::Horizontal, parent ), m_name( name ) { @@ -43,23 +45,6 @@ QskAspect::Subcontrol MenuItem::effectiveSubcontrol( QskAspect::Subcontrol subCo return subControl; } -void MenuItem::setActive( bool active ) -{ - QColor color; - - if( active ) - { - color = Qt::white; - color.setAlphaF( 0.14 ); - } - else - { - color = Qt::transparent; - } - - setBackgroundColor( color ); -} - QSK_SUBCONTROL( MenuBar, Panel ) @@ -85,7 +70,7 @@ MenuBar::MenuBar( QQuickItem* parent ) : QskLinearBox( Qt::Vertical, parent ) m_entries.append( entry ); } - m_entries.at( m_activeEntry )->setActive( true ); + m_entries.at( m_activeEntry )->setSkinState( MenuItem::Active ); addSpacer( 0, 1 ); // fill the space at the bottom diff --git a/examples/iot-dashboard/MenuBar.h b/examples/iot-dashboard/MenuBar.h index 90de1e16..b800e755 100644 --- a/examples/iot-dashboard/MenuBar.h +++ b/examples/iot-dashboard/MenuBar.h @@ -59,13 +59,12 @@ class MenuItem : public QskLinearBox public: QSK_SUBCONTROLS( Panel ) + QSK_STATES( Active ) MenuItem( const QString& name, QQuickItem* parent ); QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol subControl ) const override final; - void setActive( bool active ); - private: QString m_name; bool m_isActive = false; diff --git a/examples/iot-dashboard/Skin.cpp b/examples/iot-dashboard/Skin.cpp index 8eda19a9..ab1d7ee7 100644 --- a/examples/iot-dashboard/Skin.cpp +++ b/examples/iot-dashboard/Skin.cpp @@ -68,6 +68,8 @@ void Skin::initHints( const Palette& palette ) QColor color( Qt::white ); color.setAlphaF( 0.09 ); ed.setGradient( MenuItem::Panel | QskControl::Hovered, color ); + color.setAlphaF( 0.14 ); + ed.setGradient( MenuItem::Panel | MenuItem::Active, color ); ed.setColor( MenuBarLabel::Text, Qt::white ); ed.setFontRole( MenuBarLabel::Text, QskSkin::SmallFont );