From e64e1b6cbb26b81f744db0a20f2d4985e3a105b9 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 15 May 2023 13:42:19 +0200 Subject: [PATCH] QskMenu implementation simplified --- src/common/QskLabelData.h | 7 +++++++ src/controls/QskMenuSkinlet.cpp | 34 ++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/common/QskLabelData.h b/src/common/QskLabelData.h index d4b12033..2ed156a6 100644 --- a/src/common/QskLabelData.h +++ b/src/common/QskLabelData.h @@ -42,6 +42,8 @@ class QSK_EXPORT QskLabelData void setIcon( const QskIcon& ); QskIcon icon() const noexcept; + bool isEmpty() const; + QskHashValue hash( QskHashValue ) const; private: @@ -71,6 +73,11 @@ inline bool QskLabelData::operator!=( const QskLabelData& other ) const noexcept return ( !( *this == other ) ); } +inline bool QskLabelData::isEmpty() const +{ + return m_text.isEmpty() && m_icon.isNull(); +} + QSK_EXPORT QVector< QskLabelData > qskCreateLabelData( const QStringList& ); #ifndef QT_NO_DEBUG_STREAM diff --git a/src/controls/QskMenuSkinlet.cpp b/src/controls/QskMenuSkinlet.cpp index 9198a955..ccced571 100644 --- a/src/controls/QskMenuSkinlet.cpp +++ b/src/controls/QskMenuSkinlet.cpp @@ -120,18 +120,16 @@ class QskMenuSkinlet::PrivateData const auto h = qMax( hint.height(), textHeight ); qreal maxW = 0.0; - for ( int i = 0; i < menu->count(); i++ ) + + const auto options = menu->options(); + for ( auto& option : options ) { - const auto sample = skinlet->sampleAt( menu, QskMenu::Icon, i ); - if ( sample.canConvert< QskGraphic >() ) + const auto graphic = option.icon().graphic(); + if ( !graphic.isNull() ) { - const auto graphic = sample.value< QskGraphic >(); - if ( !graphic.isNull() ) - { - const auto w = graphic.widthForHeight( h ); - if( w > maxW ) - maxW = w; - } + const auto w = graphic.widthForHeight( h ); + if( w > maxW ) + maxW = w; } } @@ -146,18 +144,14 @@ class QskMenuSkinlet::PrivateData auto maxWidth = 0.0; - for ( int i = 0; i < menu->count(); i++ ) + const auto options = menu->options(); + for ( auto& option : options ) { - const auto sample = skinlet->sampleAt( menu, QskMenu::Text, i ); - if ( sample.canConvert< QString >() ) + if( !option.text().isEmpty() ) { - const auto text = sample.toString(); - if( !text.isEmpty() ) - { - const auto w = qskHorizontalAdvance( fm, text ); - if( w > maxWidth ) - maxWidth = w; - } + const auto w = qskHorizontalAdvance( fm, option.text() ); + if( w > maxWidth ) + maxWidth = w; } }