combo box: Support pressed state
This commit is contained in:
parent
e00c2f5335
commit
b97bce2360
|
@ -514,7 +514,7 @@ void Editor::setupComboBoxColors(
|
|||
|
||||
const auto& pal = theme.palette;
|
||||
|
||||
for ( const auto state : { QskAspect::NoState, Q::Hovered, Q::Focused, Q::Disabled } )
|
||||
for ( const auto state : { QskAspect::NoState, Q::Hovered, Q::Focused, Q::Pressed, Q::Disabled } )
|
||||
{
|
||||
QRgb panelColor, borderColor1, borderColor2, textColor;
|
||||
|
||||
|
@ -535,12 +535,18 @@ void Editor::setupComboBoxColors(
|
|||
}
|
||||
else if ( state == Q::Focused )
|
||||
{
|
||||
|
||||
panelColor = pal.fillColor.control.inputActive;
|
||||
borderColor1 = pal.elevation.textControl.border[0];
|
||||
borderColor2 = pal.fillColor.accent.defaultColor;
|
||||
textColor = pal.fillColor.text.primary;
|
||||
}
|
||||
else if ( state == Q::Pressed )
|
||||
{
|
||||
panelColor = pal.fillColor.control.inputActive;
|
||||
borderColor1 = pal.elevation.textControl.border[0];
|
||||
borderColor2 = pal.fillColor.accent.defaultColor;
|
||||
textColor = pal.fillColor.text.secondary;
|
||||
}
|
||||
else if ( state == Q::Disabled )
|
||||
{
|
||||
panelColor = pal.fillColor.control.disabled;
|
||||
|
@ -565,6 +571,11 @@ void Editor::setupComboBoxColors(
|
|||
setGraphicRole( icon, W::GraphicRoleFillColorTextDisabled );
|
||||
setGraphicRole( indicator, W::GraphicRoleFillColorTextDisabled );
|
||||
}
|
||||
else if( state == Q::Pressed )
|
||||
{
|
||||
setGraphicRole( icon, W::GraphicRoleFillColorTextSecondary );
|
||||
setGraphicRole( indicator, W::GraphicRoleFillColorTextSecondary );
|
||||
}
|
||||
else
|
||||
{
|
||||
setGraphicRole( icon, W::GraphicRoleFillColorTextPrimary );
|
||||
|
|
|
@ -278,6 +278,10 @@ void Editor::setupComboBox()
|
|||
m_pal.surfaceVariant, m_pal.focusOpacity );
|
||||
setGradient( Q::Panel | Q::Focused, focusColor );
|
||||
|
||||
const auto pressedColor = flattenedColor( m_pal.onSurfaceVariant,
|
||||
m_pal.surfaceVariant, m_pal.pressedOpacity );
|
||||
setGradient( Q::Panel | Q::Pressed, pressedColor );
|
||||
|
||||
const auto activeColor = flattenedColor( m_pal.onSurfaceVariant,
|
||||
m_pal.surfaceVariant, m_pal.pressedOpacity );
|
||||
setGradient( Q::Panel | Q::PopupOpen, activeColor );
|
||||
|
|
|
@ -18,7 +18,8 @@ QSK_SUBCONTROL( QskComboBox, Icon )
|
|||
QSK_SUBCONTROL( QskComboBox, Text )
|
||||
QSK_SUBCONTROL( QskComboBox, StatusIndicator )
|
||||
|
||||
QSK_SYSTEM_STATE( QskComboBox, PopupOpen, QskAspect::FirstSystemState << 1 )
|
||||
QSK_SYSTEM_STATE( QskComboBox, Pressed, QskAspect::FirstSystemState << 1 )
|
||||
QSK_SYSTEM_STATE( QskComboBox, PopupOpen, QskAspect::FirstSystemState << 2 )
|
||||
|
||||
static inline void qskTraverseOptions( QskComboBox* comboBox, int steps )
|
||||
{
|
||||
|
@ -89,6 +90,25 @@ QskComboBox::~QskComboBox()
|
|||
{
|
||||
}
|
||||
|
||||
bool QskComboBox::isPressed() const
|
||||
{
|
||||
return hasSkinState( Pressed );
|
||||
}
|
||||
|
||||
void QskComboBox::setPressed( bool on )
|
||||
{
|
||||
if ( on == isPressed() )
|
||||
return;
|
||||
|
||||
setSkinStateFlag( Pressed, on );
|
||||
Q_EMIT pressedChanged( on );
|
||||
|
||||
if ( on )
|
||||
Q_EMIT pressed();
|
||||
else
|
||||
Q_EMIT released();
|
||||
}
|
||||
|
||||
void QskComboBox::setPopupOpen( bool on )
|
||||
{
|
||||
if ( on == isPopupOpen() )
|
||||
|
@ -246,11 +266,13 @@ void QskComboBox::closePopup()
|
|||
|
||||
void QskComboBox::mousePressEvent( QMouseEvent* )
|
||||
{
|
||||
setPressed( true );
|
||||
setPopupOpen( true );
|
||||
}
|
||||
|
||||
void QskComboBox::mouseReleaseEvent( QMouseEvent* )
|
||||
{
|
||||
setPressed( false );
|
||||
}
|
||||
|
||||
void QskComboBox::keyPressEvent( QKeyEvent* event )
|
||||
|
@ -259,6 +281,7 @@ void QskComboBox::keyPressEvent( QKeyEvent* event )
|
|||
{
|
||||
if ( !event->isAutoRepeat() )
|
||||
{
|
||||
setPressed( true );
|
||||
setPopupOpen( true );
|
||||
return;
|
||||
}
|
||||
|
@ -270,6 +293,7 @@ void QskComboBox::keyPressEvent( QKeyEvent* event )
|
|||
case Qt::Key_F4:
|
||||
{
|
||||
// QComboBox does this ???
|
||||
setPressed( true );
|
||||
setPopupOpen( true );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -34,16 +34,22 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||
Q_PROPERTY( int indexInPopup READ indexInPopup
|
||||
NOTIFY indexInPopupChanged )
|
||||
|
||||
Q_PROPERTY( bool pressed READ isPressed
|
||||
WRITE setPressed NOTIFY pressedChanged FINAL )
|
||||
|
||||
using Inherited = QskControl;
|
||||
|
||||
public:
|
||||
QSK_SUBCONTROLS( Panel, Icon, Text, StatusIndicator )
|
||||
QSK_STATES( PopupOpen )
|
||||
QSK_STATES( Pressed, PopupOpen )
|
||||
|
||||
QskComboBox( QQuickItem* parent = nullptr );
|
||||
|
||||
~QskComboBox() override;
|
||||
|
||||
void setPressed( bool on );
|
||||
bool isPressed() const;
|
||||
|
||||
void setPopupOpen( bool );
|
||||
bool isPopupOpen() const;
|
||||
|
||||
|
@ -78,6 +84,10 @@ class QSK_EXPORT QskComboBox : public QskControl
|
|||
void setCurrentIndex( int );
|
||||
|
||||
Q_SIGNALS:
|
||||
void pressed();
|
||||
void released();
|
||||
void pressedChanged( bool );
|
||||
|
||||
void currentIndexChanged( int );
|
||||
void indexInPopupChanged( int );
|
||||
|
||||
|
|
Loading…
Reference in New Issue