diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index e757e5b5..907d50a5 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -428,6 +428,7 @@ void Editor::setupMenu() setMetric( Q::Separator | A::Size, 2_dp ); setSeparator( Q::Separator ); + setMargin( Q::Separator, 2 ); setPadding( Q::Segment, QskMargins( 2, 10, 2, 10 ) ); setSpacing( Q::Segment, 5 ); diff --git a/src/controls/QskMenu.cpp b/src/controls/QskMenu.cpp index 95e5b5ed..3e2c2cba 100644 --- a/src/controls/QskMenu.cpp +++ b/src/controls/QskMenu.cpp @@ -201,11 +201,6 @@ QskLabelData QskMenu::optionAt( int index ) const return m_data->options.value( index ); } -int QskMenu::optionsCount() const -{ - return m_data->options.count(); -} - void QskMenu::addSeparator() { addOption( QskLabelData() ); @@ -420,7 +415,10 @@ void QskMenu::aboutToShow() setGeometry( QRectF( m_data->origin, sizeConstraint() ) ); if ( m_data->currentIndex < 0 ) - setCurrentIndex( 0 ); + { + if ( !m_data->actions.isEmpty() ) + setCurrentIndex( m_data->actions.first() ); + } Inherited::aboutToShow(); } @@ -459,7 +457,7 @@ int QskMenu::indexAtPosition( const QPointF& pos ) const void QskMenu::trigger( int index ) { - if ( index >= 0 && index < m_data->options.count() ) + if ( index >= 0 && index < m_data->options.count() ) { m_data->triggeredIndex = index; Q_EMIT triggered( index ); diff --git a/src/controls/QskMenu.h b/src/controls/QskMenu.h index f01dd1a0..9a4e6624 100644 --- a/src/controls/QskMenu.h +++ b/src/controls/QskMenu.h @@ -26,8 +26,6 @@ class QSK_EXPORT QskMenu : public QskPopup Q_PROPERTY( QVector< QskLabelData > options READ options WRITE setOptions NOTIFY optionsChanged ) - Q_PROPERTY( int optionsCount READ optionsCount ) - Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged ) @@ -66,8 +64,6 @@ class QSK_EXPORT QskMenu : public QskPopup QVector< QskLabelData > options() const; QskLabelData optionAt( int ) const; - int optionsCount() const; - QVector< int > separators() const; QVector< int > actions() const; diff --git a/src/controls/QskMenuSkinlet.cpp b/src/controls/QskMenuSkinlet.cpp index 4babe21e..b5e9b8e3 100644 --- a/src/controls/QskMenuSkinlet.cpp +++ b/src/controls/QskMenuSkinlet.cpp @@ -31,6 +31,16 @@ static inline int qskActionIndex( const QskMenu* menu, int optionIndex ) return it - actions.constBegin(); } +static inline qreal qskPaddedSeparatorHeight( const QskMenu* menu ) +{ + using Q = QskMenu; + + const auto margins = menu->marginHint( Q::Separator ); + + return menu->metric( Q::Separator | QskAspect::Size ) + + margins.top() + margins.bottom(); +} + class QskMenuSkinlet::PrivateData { public: @@ -254,7 +264,6 @@ QRectF QskMenuSkinlet::subControlRect( const qreal pos = menu->positionHint( Q::Cursor ); - // separators TODO ... const int pos1 = qFloor( pos ); const int pos2 = qCeil( pos ); @@ -289,10 +298,7 @@ QRectF QskMenuSkinlet::sampleRect( auto dy = index * h; if ( const auto n = menu->actions()[ index ] - index ) - { - // spacing ??? - dy += n * menu->metric( Q::Separator | QskAspect::Size ); - } + dy += n * qskPaddedSeparatorHeight( menu ); const auto r = menu->subControlContentsRect( Q::Panel ); return QRectF( r.x(), r.y() + dy, r.width(), h ); @@ -332,17 +338,15 @@ QRectF QskMenuSkinlet::sampleRect( if ( index >= separators.count() ) return QRectF(); - const int pos = separators[ index ]; + const auto h = qskPaddedSeparatorHeight( menu ); - auto r = menu->subControlContentsRect( Q::Panel ); + auto y = index * h; - const auto segmentRect = sampleRect( skinnable, contentsRect, Q::Segment, pos ); - r.setBottom( segmentRect.top() ); // spacing ??? + if ( const auto n = qskActionIndex( menu, separators[ index ] ) ) + y += n * m_data->segmentHeight( menu ); - const qreal h = menu->metric( Q::Separator | QskAspect::Size ); - r.setTop( r.bottom() - h ); - - return r; + const auto r = menu->subControlContentsRect( Q::Panel ); + return QRectF( r.left(), y, r.width(), h ); } return Inherited::sampleRect( @@ -555,7 +559,7 @@ QSizeF QskMenuSkinlet::sizeHint( const QskSkinnable* skinnable, if ( const auto count = sampleCount( skinnable, Q::Separator ) ) { - h += count * menu->metric( Q::Separator | QskAspect::Size ); + h += count * qskPaddedSeparatorHeight( menu ); } auto hint = skinnable->outerBoxSize( QskMenu::Panel, QSizeF( w, h ) );