button: Add more states to cover different button types
This commit is contained in:
parent
a810739254
commit
e6b85e528b
@ -29,27 +29,36 @@ namespace
|
||||
private:
|
||||
void populate()
|
||||
{
|
||||
const char* texts[] = { "Press Me", "Check Me" };
|
||||
const char* texts[] = { "Press Me", "Check Me", "Outlined", "Text" };
|
||||
const char* graphics[] = { "diamond/khaki", "ellipse/sandybrown" };
|
||||
|
||||
for ( int i = 0; i < 6; i++ )
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
const int index = i % 2;
|
||||
|
||||
auto button = new QskPushButton( this );
|
||||
button->setCheckable( index != 0 );
|
||||
button->setCheckable( index != 0 && index < 6 );
|
||||
//button->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
|
||||
if ( i > 1 )
|
||||
if ( i > 1 && i < 6 )
|
||||
{
|
||||
auto src = QStringLiteral( "image://shapes/" ) + graphics[ index ];
|
||||
button->setGraphicSource( src );
|
||||
}
|
||||
|
||||
if ( i < 2 || i > 3 )
|
||||
if ( i < 2 || ( i > 3 && i < 6 ) )
|
||||
{
|
||||
button->setText( texts[ index ] );
|
||||
}
|
||||
else if( i == 6 )
|
||||
{
|
||||
button->setSkinStateFlag( QskAbstractButton::Outlined );
|
||||
button->setText( texts[ 2 ] );
|
||||
}
|
||||
else if( i == 7 )
|
||||
{
|
||||
button->setSkinStateFlag( QskAbstractButton::TextState );
|
||||
button->setText( texts[ 3 ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -423,24 +423,52 @@ void Editor::setupPushButton()
|
||||
|
||||
setBoxShape( Q::Panel, 100, Qt::RelativeSize );
|
||||
|
||||
setColor( Q::Text, m_pal.onPrimary );
|
||||
|
||||
QColor c2( m_pal.onSurface );
|
||||
c2.setAlphaF( 0.38 );
|
||||
setColor( Q::Text | Q::Disabled, c2 );
|
||||
setAlignment( Q::Graphic | A::Alignment, Qt::AlignLeft );
|
||||
setPadding( Q::Graphic, 5 );
|
||||
|
||||
setFontRole( Q::Text, QskMaterialSkin::M3LabelLarge );
|
||||
setAlignment( Q::Text, Qt::AlignCenter );
|
||||
|
||||
|
||||
// normal buttons (i.e. Filled):
|
||||
|
||||
setGradient( Q::Panel, m_pal.primary );
|
||||
|
||||
QColor c1( m_pal.onSurface );
|
||||
c1.setAlphaF( 0.12 );
|
||||
setGradient( Q::Panel | Q::Disabled, c1 );
|
||||
|
||||
setColor( Q::Text, m_pal.onPrimary );
|
||||
|
||||
QColor c2( m_pal.onSurface );
|
||||
c2.setAlphaF( 0.38 );
|
||||
setColor( Q::Text | Q::Disabled, c2 );
|
||||
|
||||
|
||||
// Outlined and Text:
|
||||
|
||||
const QskStateCombination combination( QskStateCombination::Combination, Q::Outlined | Q::TextState );
|
||||
setGradient( Q::Panel, Qt::transparent, combination );
|
||||
|
||||
setBoxBorderMetrics( Q::Panel, 1, { QskStateCombination::CombinationNoState, Q::Outlined } );
|
||||
setBoxBorderColors( Q::Panel | Q::Outlined, m_pal.outline );
|
||||
|
||||
setGradient( Q::Panel | Q::Disabled, Qt::transparent, combination );
|
||||
setBoxBorderColors( Q::Panel | Q::Outlined | Q::Disabled, c1 );
|
||||
|
||||
QColor primary08( m_pal.primary );
|
||||
primary08.setAlphaF( 0.08 );
|
||||
setGradient( Q::Panel | Q::Outlined, primary08,
|
||||
{ QskStateCombination::Combination,
|
||||
Q::Hovered | Q::Focused | Q::Pressed } );
|
||||
setGradient( Q::Panel | Q::TextState, primary08,
|
||||
{ QskStateCombination::Combination,
|
||||
Q::Hovered | Q::Focused | Q::Pressed } );
|
||||
|
||||
setColor( Q::Text, m_pal.primary, combination );
|
||||
|
||||
setColor( Q::Text | Q::Disabled, c1, combination );
|
||||
|
||||
setAlignment( Q::Graphic | A::Alignment, Qt::AlignLeft );
|
||||
setPadding( Q::Graphic, 5 );
|
||||
|
||||
setAnimation( Q::Panel | A::Color, qskDuration );
|
||||
setAnimation( Q::Panel | A::Metric, qskDuration );
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
// Flat is no state - we need to get rid of it. TODO ...
|
||||
QSK_SYSTEM_STATE( QskAbstractButton, Flat, QskAspect::FirstSystemState << 1 )
|
||||
QSK_SYSTEM_STATE( QskAbstractButton, Outlined, QskAspect::FirstSystemState << 2 )
|
||||
QSK_SYSTEM_STATE( QskAbstractButton, TextState, QskAspect::FirstSystemState << 3 )
|
||||
|
||||
QSK_SYSTEM_STATE( QskAbstractButton, Checked, QskAspect::LastSystemState >> 3 )
|
||||
QSK_SYSTEM_STATE( QskAbstractButton, Pressed, QskAspect::LastSystemState >> 2 )
|
||||
|
@ -33,7 +33,7 @@ class QSK_EXPORT QskAbstractButton : public QskControl
|
||||
using Inherited = QskControl;
|
||||
|
||||
public:
|
||||
QSK_STATES( Flat, Checked, Pressed )
|
||||
QSK_STATES( Flat, Outlined, TextState, Checked, Pressed )
|
||||
|
||||
QskAbstractButton( QQuickItem* parent = nullptr );
|
||||
~QskAbstractButton() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user