handling of menu separators fixed
This commit is contained in:
parent
78d3a9af9c
commit
51fd38eb01
|
@ -428,6 +428,7 @@ void Editor::setupMenu()
|
||||||
|
|
||||||
setMetric( Q::Separator | A::Size, 2_dp );
|
setMetric( Q::Separator | A::Size, 2_dp );
|
||||||
setSeparator( Q::Separator );
|
setSeparator( Q::Separator );
|
||||||
|
setMargin( Q::Separator, 2 );
|
||||||
|
|
||||||
setPadding( Q::Segment, QskMargins( 2, 10, 2, 10 ) );
|
setPadding( Q::Segment, QskMargins( 2, 10, 2, 10 ) );
|
||||||
setSpacing( Q::Segment, 5 );
|
setSpacing( Q::Segment, 5 );
|
||||||
|
|
|
@ -201,11 +201,6 @@ QskLabelData QskMenu::optionAt( int index ) const
|
||||||
return m_data->options.value( index );
|
return m_data->options.value( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskMenu::optionsCount() const
|
|
||||||
{
|
|
||||||
return m_data->options.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskMenu::addSeparator()
|
void QskMenu::addSeparator()
|
||||||
{
|
{
|
||||||
addOption( QskLabelData() );
|
addOption( QskLabelData() );
|
||||||
|
@ -420,7 +415,10 @@ void QskMenu::aboutToShow()
|
||||||
setGeometry( QRectF( m_data->origin, sizeConstraint() ) );
|
setGeometry( QRectF( m_data->origin, sizeConstraint() ) );
|
||||||
|
|
||||||
if ( m_data->currentIndex < 0 )
|
if ( m_data->currentIndex < 0 )
|
||||||
setCurrentIndex( 0 );
|
{
|
||||||
|
if ( !m_data->actions.isEmpty() )
|
||||||
|
setCurrentIndex( m_data->actions.first() );
|
||||||
|
}
|
||||||
|
|
||||||
Inherited::aboutToShow();
|
Inherited::aboutToShow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,6 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
Q_PROPERTY( QVector< QskLabelData > options READ options
|
Q_PROPERTY( QVector< QskLabelData > options READ options
|
||||||
WRITE setOptions NOTIFY optionsChanged )
|
WRITE setOptions NOTIFY optionsChanged )
|
||||||
|
|
||||||
Q_PROPERTY( int optionsCount READ optionsCount )
|
|
||||||
|
|
||||||
Q_PROPERTY( int currentIndex READ currentIndex
|
Q_PROPERTY( int currentIndex READ currentIndex
|
||||||
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
WRITE setCurrentIndex NOTIFY currentIndexChanged )
|
||||||
|
|
||||||
|
@ -66,8 +64,6 @@ class QSK_EXPORT QskMenu : public QskPopup
|
||||||
QVector< QskLabelData > options() const;
|
QVector< QskLabelData > options() const;
|
||||||
QskLabelData optionAt( int ) const;
|
QskLabelData optionAt( int ) const;
|
||||||
|
|
||||||
int optionsCount() const;
|
|
||||||
|
|
||||||
QVector< int > separators() const;
|
QVector< int > separators() const;
|
||||||
QVector< int > actions() const;
|
QVector< int > actions() const;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,16 @@ static inline int qskActionIndex( const QskMenu* menu, int optionIndex )
|
||||||
return it - actions.constBegin();
|
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
|
class QskMenuSkinlet::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -254,7 +264,6 @@ QRectF QskMenuSkinlet::subControlRect(
|
||||||
|
|
||||||
const qreal pos = menu->positionHint( Q::Cursor );
|
const qreal pos = menu->positionHint( Q::Cursor );
|
||||||
|
|
||||||
// separators TODO ...
|
|
||||||
const int pos1 = qFloor( pos );
|
const int pos1 = qFloor( pos );
|
||||||
const int pos2 = qCeil( pos );
|
const int pos2 = qCeil( pos );
|
||||||
|
|
||||||
|
@ -289,10 +298,7 @@ QRectF QskMenuSkinlet::sampleRect(
|
||||||
auto dy = index * h;
|
auto dy = index * h;
|
||||||
|
|
||||||
if ( const auto n = menu->actions()[ index ] - index )
|
if ( const auto n = menu->actions()[ index ] - index )
|
||||||
{
|
dy += n * qskPaddedSeparatorHeight( menu );
|
||||||
// spacing ???
|
|
||||||
dy += n * menu->metric( Q::Separator | QskAspect::Size );
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto r = menu->subControlContentsRect( Q::Panel );
|
const auto r = menu->subControlContentsRect( Q::Panel );
|
||||||
return QRectF( r.x(), r.y() + dy, r.width(), h );
|
return QRectF( r.x(), r.y() + dy, r.width(), h );
|
||||||
|
@ -332,17 +338,15 @@ QRectF QskMenuSkinlet::sampleRect(
|
||||||
if ( index >= separators.count() )
|
if ( index >= separators.count() )
|
||||||
return QRectF();
|
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 );
|
if ( const auto n = qskActionIndex( menu, separators[ index ] ) )
|
||||||
r.setBottom( segmentRect.top() ); // spacing ???
|
y += n * m_data->segmentHeight( menu );
|
||||||
|
|
||||||
const qreal h = menu->metric( Q::Separator | QskAspect::Size );
|
const auto r = menu->subControlContentsRect( Q::Panel );
|
||||||
r.setTop( r.bottom() - h );
|
return QRectF( r.left(), y, r.width(), h );
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Inherited::sampleRect(
|
return Inherited::sampleRect(
|
||||||
|
@ -555,7 +559,7 @@ QSizeF QskMenuSkinlet::sizeHint( const QskSkinnable* skinnable,
|
||||||
|
|
||||||
if ( const auto count = sampleCount( skinnable, Q::Separator ) )
|
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 ) );
|
auto hint = skinnable->outerBoxSize( QskMenu::Panel, QSizeF( w, h ) );
|
||||||
|
|
Loading…
Reference in New Issue