label renamed to placeholderText ( taken from QComboBox ), minor
adjustments
This commit is contained in:
parent
69aa0903c5
commit
ed1a211e96
@ -72,7 +72,7 @@ void SelectorPage::populate()
|
|||||||
comboBoxBox->setExtraSpacingAt( Qt::BottomEdge );
|
comboBoxBox->setExtraSpacingAt( Qt::BottomEdge );
|
||||||
|
|
||||||
auto* comboBox1 = new QskComboBox( comboBoxBox );
|
auto* comboBox1 = new QskComboBox( comboBoxBox );
|
||||||
comboBox1->setLabel( "label" );
|
comboBox1->setPlaceholderText( "< options >" );
|
||||||
comboBox1->addOption( {}, "airport" );
|
comboBox1->addOption( {}, "airport" );
|
||||||
comboBox1->addOption( {}, "flight" );
|
comboBox1->addOption( {}, "flight" );
|
||||||
comboBox1->addOption( {}, "pizza" );
|
comboBox1->addOption( {}, "pizza" );
|
||||||
@ -83,6 +83,7 @@ void SelectorPage::populate()
|
|||||||
comboBox2->addOption( { "flight" }, "flight" );
|
comboBox2->addOption( { "flight" }, "flight" );
|
||||||
comboBox2->addOption( { "local_pizza" }, "pizza" );
|
comboBox2->addOption( { "local_pizza" }, "pizza" );
|
||||||
comboBox2->addOption( { "sports_soccer" }, "soccer" );
|
comboBox2->addOption( { "sports_soccer" }, "soccer" );
|
||||||
|
comboBox2->setCurrentIndex( 2 );
|
||||||
|
|
||||||
setStretchFactor( 0, 0 );
|
setStretchFactor( 0, 0 );
|
||||||
setStretchFactor( 1, 10 );
|
setStretchFactor( 1, 10 );
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include "QskMenu.h"
|
#include "QskMenu.h"
|
||||||
#include "QskTextOptions.h"
|
#include "QskTextOptions.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskComboBox, Panel )
|
QSK_SUBCONTROL( QskComboBox, Panel )
|
||||||
QSK_SUBCONTROL( QskComboBox, Graphic )
|
QSK_SUBCONTROL( QskComboBox, Graphic )
|
||||||
QSK_SUBCONTROL( QskComboBox, Text )
|
QSK_SUBCONTROL( QskComboBox, Text )
|
||||||
@ -27,10 +25,19 @@ class QskComboBox::PrivateData
|
|||||||
: menu( new QskMenu( box ) )
|
: menu( new QskMenu( box ) )
|
||||||
{
|
{
|
||||||
menu->setPopupFlag( QskPopup::DeleteOnClose, false );
|
menu->setPopupFlag( QskPopup::DeleteOnClose, false );
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
/*
|
||||||
|
CloseOnPressOutside catches all mouse events in the parent
|
||||||
|
what is the comboBox in our case. However we need to handle
|
||||||
|
events for the complete window to make the CloseOnPressOutside
|
||||||
|
work like expected. TODO ...
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QskMenu* const menu;
|
QskMenu* menu;
|
||||||
QString label;
|
QString placeholderText;
|
||||||
};
|
};
|
||||||
|
|
||||||
QskComboBox::QskComboBox( QQuickItem* parent )
|
QskComboBox::QskComboBox( QQuickItem* parent )
|
||||||
@ -47,10 +54,14 @@ QskComboBox::QskComboBox( QQuickItem* parent )
|
|||||||
|
|
||||||
setAcceptHoverEvents( true );
|
setAcceptHoverEvents( true );
|
||||||
|
|
||||||
connect( m_data->menu, &QskMenu::currentIndexChanged, this, &QskComboBox::currentIndexChanged );
|
connect( m_data->menu, &QskMenu::currentIndexChanged,
|
||||||
connect( m_data->menu, &QskMenu::currentIndexChanged, this, &QQuickItem::update );
|
this, &QskComboBox::currentIndexChanged );
|
||||||
|
|
||||||
connect( m_data->menu, &QskMenu::countChanged, this, &QskComboBox::countChanged );
|
connect( m_data->menu, &QskMenu::currentIndexChanged,
|
||||||
|
this, &QQuickItem::update );
|
||||||
|
|
||||||
|
connect( m_data->menu, &QskMenu::countChanged,
|
||||||
|
this, &QskComboBox::countChanged );
|
||||||
|
|
||||||
connect( this, &QskComboBox::currentIndexChanged,
|
connect( this, &QskComboBox::currentIndexChanged,
|
||||||
this, &QskControl::focusIndicatorRectChanged );
|
this, &QskControl::focusIndicatorRectChanged );
|
||||||
@ -109,17 +120,14 @@ bool QskComboBox::isPopupOpen() const
|
|||||||
|
|
||||||
QskGraphic QskComboBox::graphic() const
|
QskGraphic QskComboBox::graphic() const
|
||||||
{
|
{
|
||||||
const int index = m_data->menu->currentIndex();
|
const int index = currentIndex();
|
||||||
|
|
||||||
if( index >= 0 )
|
if( index >= 0 )
|
||||||
{
|
{
|
||||||
const auto option = m_data->menu->optionAt( index );
|
const auto option = m_data->menu->optionAt( index );
|
||||||
return option.at( 0 ).value< QskGraphic >();
|
return option.at( 0 ).value< QskGraphic >();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return QskGraphic();
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::setTextOptions( const QskTextOptions& textOptions )
|
void QskComboBox::setTextOptions( const QskTextOptions& textOptions )
|
||||||
@ -142,29 +150,36 @@ QVariantList QskComboBox::optionAt( int index ) const
|
|||||||
return m_data->menu->optionAt( index );
|
return m_data->menu->optionAt( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskComboBox::label() const
|
QString QskComboBox::placeholderText() const
|
||||||
{
|
{
|
||||||
return m_data->label;
|
return m_data->placeholderText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::setLabel( const QString& label )
|
void QskComboBox::setPlaceholderText( const QString& text )
|
||||||
{
|
{
|
||||||
m_data->label = label;
|
if ( m_data->placeholderText == text )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_data->placeholderText = text;
|
||||||
|
|
||||||
|
resetImplicitSize();
|
||||||
|
|
||||||
|
if ( currentIndex() < 0 )
|
||||||
|
update();
|
||||||
|
|
||||||
|
Q_EMIT placeholderTextChanged( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskComboBox::text() const
|
QString QskComboBox::text() const
|
||||||
{
|
{
|
||||||
const int index = m_data->menu->currentIndex();
|
const int index = currentIndex();
|
||||||
|
|
||||||
if( index >= 0 )
|
if( index >= 0 )
|
||||||
{
|
{
|
||||||
const auto option = m_data->menu->optionAt( index );
|
const auto option = optionAt( index );
|
||||||
return option.at( 1 ).toString();
|
return option.at( 1 ).toString();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return placeholderText();
|
||||||
return label();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::togglePopup()
|
void QskComboBox::togglePopup()
|
||||||
@ -192,15 +207,13 @@ void QskComboBox::updateLayout()
|
|||||||
m_data->menu->setFixedWidth( contentsRect().width() );
|
m_data->menu->setFixedWidth( contentsRect().width() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::mousePressEvent( QMouseEvent* event )
|
void QskComboBox::mousePressEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
Q_UNUSED( event )
|
|
||||||
setPressed( true );
|
setPressed( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::mouseReleaseEvent( QMouseEvent* event )
|
void QskComboBox::mouseReleaseEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
Q_UNUSED( event )
|
|
||||||
releaseButton();
|
releaseButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,12 +253,6 @@ void QskComboBox::clear()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskComboBox::click()
|
|
||||||
{
|
|
||||||
setPressed( true );
|
|
||||||
releaseButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskComboBox::setCurrentIndex( int index )
|
void QskComboBox::setCurrentIndex( int index )
|
||||||
{
|
{
|
||||||
m_data->menu->setCurrentIndex( index );
|
m_data->menu->setCurrentIndex( index );
|
||||||
|
@ -19,6 +19,9 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||||||
|
|
||||||
Q_PROPERTY( int count READ count NOTIFY countChanged )
|
Q_PROPERTY( int count READ count NOTIFY countChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( QString placeholderText READ placeholderText
|
||||||
|
WRITE setPlaceholderText NOTIFY placeholderTextChanged )
|
||||||
|
|
||||||
using Inherited = QskControl;
|
using Inherited = QskControl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -50,8 +53,8 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||||||
|
|
||||||
QVariantList optionAt( int ) const;
|
QVariantList optionAt( int ) const;
|
||||||
|
|
||||||
QString label() const;
|
QString placeholderText() const;
|
||||||
void setLabel( const QString& );
|
void setPlaceholderText( const QString& );
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
|
|
||||||
@ -60,7 +63,6 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||||||
virtual void openPopup();
|
virtual void openPopup();
|
||||||
virtual void closePopup();
|
virtual void closePopup();
|
||||||
|
|
||||||
void click();
|
|
||||||
void setCurrentIndex( int );
|
void setCurrentIndex( int );
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
@ -74,6 +76,8 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||||||
void pressedChanged( bool );
|
void pressedChanged( bool );
|
||||||
void popupOpenChanged( bool );
|
void popupOpenChanged( bool );
|
||||||
|
|
||||||
|
void placeholderTextChanged( const QString& );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void updateLayout() override;
|
virtual void updateLayout() override;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user