combo box improved

This commit is contained in:
Uwe Rathmann 2024-02-17 13:24:14 +01:00
parent 52fc83ea35
commit d8dd07d305
3 changed files with 33 additions and 5 deletions

View File

@ -236,14 +236,16 @@ void QskComboBox::openPopup()
auto menu = new QskMenu();
menu->setParent( this );
menu->setParentItem( window()->contentItem() );
menu->setPopupFlag( QskPopup::DeleteOnClose, true );
menu->setOrigin( mapToScene( cr.bottomLeft() ) );
menu->setWrapping( false );
menu->setOrigin( mapToScene( cr.topLeft() ) );
menu->setFixedWidth( cr.width() );
menu->setOptions( m_data->options );
menu->setCurrentIndex( currentIndex() );
menu->setParent( this );
menu->setParentItem( window()->contentItem() );
menu->setPopupFlag( QskPopup::DeleteOnClose, true );
connect( menu, &QskMenu::currentIndexChanged,
this, &QskComboBox::indexInPopupChanged );

View File

@ -53,6 +53,8 @@ class QskMenu::PrivateData
int triggeredIndex = -1;
int currentIndex = -1;
bool wrapping = true;
bool isPressed = false;
};
@ -105,6 +107,20 @@ QRectF QskMenu::clipRect() const
return Inherited::clipRect();
}
bool QskMenu::isWrapping() const
{
return m_data->wrapping;
}
void QskMenu::setWrapping( bool on )
{
if ( m_data->wrapping != on )
{
m_data->wrapping = on;
Q_EMIT wrappingChanged( on );
}
}
#if 1
// has no effect as we do not offer submenus yet. TODO ...
@ -422,6 +438,9 @@ void QskMenu::traverse( int steps )
int action1 = qskActionIndex( actions, m_data->currentIndex );
int action2 = action1 + steps;
if ( !m_data->wrapping )
action2 = qBound( 0, action2, count - 1 );
// when cycling we want to slide in
int index1;

View File

@ -23,6 +23,9 @@ class QSK_EXPORT QskMenu : public QskPopup
Q_PROPERTY( bool cascading READ isCascading WRITE setCascading
RESET resetCascading NOTIFY cascadingChanged )
Q_PROPERTY( bool wrapping READ isWrapping
WRITE setWrapping NOTIFY wrappingChanged )
Q_PROPERTY( QVector< QskLabelData > options READ options
WRITE setOptions NOTIFY optionsChanged )
@ -47,6 +50,9 @@ class QSK_EXPORT QskMenu : public QskPopup
void setCascading( bool );
void resetCascading();
bool isWrapping() const;
void setWrapping( bool );
void setOrigin( const QPointF& );
QPointF origin() const;
@ -87,6 +93,7 @@ class QSK_EXPORT QskMenu : public QskPopup
Q_INVOKABLE int exec();
Q_SIGNALS:
void wrappingChanged( bool );
void cascadingChanged( bool );
void originChanged( const QPointF& );