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